mirror of
https://github.com/Motorhead1991/qemu.git
synced 2025-08-03 07:43:54 -06:00
oslib-posix: Introduce qemu_socketpair()
qemu_socketpair() will create a pair of connected sockets with FD_CLOEXEC set Signed-off-by: Guoyi Tu <tugy@chinatelecom.cn> Reviewed-by: Christian Schoenebeck <qemu_oss@crudebyte.com> Reviewed-by: Marc-André Lureau <marcandre.lureau@redhat.com> Message-Id: <17fa1eff729eeabd9a001f4639abccb127ceec81.1661240709.git.tugy@chinatelecom.cn>
This commit is contained in:
parent
fc0c128531
commit
3c63b4e94a
2 changed files with 37 additions and 0 deletions
|
@ -253,6 +253,25 @@ void qemu_set_cloexec(int fd)
|
|||
assert(f != -1);
|
||||
}
|
||||
|
||||
int qemu_socketpair(int domain, int type, int protocol, int sv[2])
|
||||
{
|
||||
int ret;
|
||||
|
||||
#ifdef SOCK_CLOEXEC
|
||||
ret = socketpair(domain, type | SOCK_CLOEXEC, protocol, sv);
|
||||
if (ret != -1 || errno != EINVAL) {
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
ret = socketpair(domain, type, protocol, sv);;
|
||||
if (ret == 0) {
|
||||
qemu_set_cloexec(sv[0]);
|
||||
qemu_set_cloexec(sv[1]);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
char *
|
||||
qemu_get_local_state_dir(void)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue