1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-10-27 10:25:06 +03:00

bus: when getting a kdbus connection into a container wait first for child, then read message

There's no EOF generated for AF_UNIX/SOCK_DGRAM sockets, hence let's
wait for the child first to see if it succeeded, only then read the socket.
This commit is contained in:
Lennart Poettering 2013-12-23 19:10:11 +01:00
parent e7f7a1b022
commit fbadf04511
3 changed files with 23 additions and 23 deletions

View File

@ -205,6 +205,16 @@ int bus_container_connect_kernel(sd_bus *b) {
close_nointr_nofail(pair[1]);
pair[1] = -1;
r = wait_for_terminate(child, &si);
if (r < 0)
return r;
if (si.si_code != CLD_EXITED)
return -EIO;
if (si.si_status != EXIT_SUCCESS)
return -EIO;
if (recvmsg(pair[0], &mh, MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) < 0)
return -errno;
@ -224,16 +234,6 @@ int bus_container_connect_kernel(sd_bus *b) {
fd = fds[0];
}
r = wait_for_terminate(child, &si);
if (r < 0)
return r;
if (si.si_code != CLD_EXITED)
return -EIO;
if (si.si_status != EXIT_SUCCESS)
return -EIO;
b->input_fd = b->output_fd = fd;
fd = -1;

View File

@ -451,6 +451,15 @@ static int openpt_in_namespace(pid_t pid, int flags) {
close_nointr_nofail(pair[1]);
pair[1] = -1;
r = wait_for_terminate(child, &si);
if (r < 0 || si.si_code != CLD_EXITED || si.si_status != EXIT_SUCCESS || master < 0) {
if (master >= 0)
close_nointr_nofail(master);
return r < 0 ? r : -EIO;
}
if (recvmsg(pair[0], &mh, MSG_NOSIGNAL|MSG_CMSG_CLOEXEC) < 0)
return -errno;
@ -470,15 +479,6 @@ static int openpt_in_namespace(pid_t pid, int flags) {
master = fds[0];
}
r = wait_for_terminate(child, &si);
if (r < 0 || si.si_code != CLD_EXITED || si.si_status != EXIT_SUCCESS || master < 0) {
if (master >= 0)
close_nointr_nofail(master);
return r < 0 ? r : -EIO;
}
return master;
}

View File

@ -1174,14 +1174,14 @@ static int get_boot_id_for_machine(const char *machine, sd_id128_t *boot_id) {
close_nointr_nofail(pair[1]);
pair[1] = -1;
k = recv(pair[0], buf, 36, 0);
if (k != 36)
return -EIO;
r = wait_for_terminate(child, &si);
if (r < 0 || si.si_code != CLD_EXITED || si.si_status != EXIT_SUCCESS)
return r < 0 ? r : -EIO;
k = recv(pair[0], buf, 36, 0);
if (k != 36)
return -EIO;
buf[36] = 0;
r = sd_id128_from_string(buf, boot_id);
if (r < 0)