Unverified Commit 542d0f26 by Stéphane Graber Committed by GitHub

Merge pull request #2499 from brauner/lxc/master

bugfixes
parents 01fc55d5 81f87066
......@@ -309,7 +309,11 @@ static int _real_caps_last_cap(void)
char *ptr;
int n;
if ((n = read(fd, buf, 31)) >= 0) {
again:
n = read(fd, buf, 31);
if (n < 0 && errno == EINTR) {
goto again;
} else if (n >= 0) {
buf[n] = '\0';
errno = 0;
......
......@@ -161,7 +161,7 @@ static int lxc_monitord_sock_handler(int fd, uint32_t events, void *data,
int rc;
char buf[4];
rc = read(fd, buf, sizeof(buf));
rc = lxc_read_nointr(fd, buf, sizeof(buf));
if (rc > 0 && !strncmp(buf, "quit", 4))
quit = LXC_MAINLOOP_CLOSE;
}
......@@ -305,14 +305,14 @@ static int lxc_monitord_fifo_handler(int fd, uint32_t events, void *data,
struct lxc_msg msglxc;
struct lxc_monitor *mon = data;
ret = read(fd, &msglxc, sizeof(msglxc));
ret = lxc_read_nointr(fd, &msglxc, sizeof(msglxc));
if (ret != sizeof(msglxc)) {
SYSERROR("Reading from fifo failed");
return LXC_MAINLOOP_CLOSE;
}
for (i = 0; i < mon->clientfds_cnt; i++) {
ret = write(mon->clientfds[i], &msglxc, sizeof(msglxc));
ret = lxc_write_nointr(mon->clientfds[i], &msglxc, sizeof(msglxc));
if (ret < 0)
SYSERROR("Failed to send message to client file descriptor %d",
mon->clientfds[i]);
......@@ -428,7 +428,7 @@ int main(int argc, char *argv[])
* if-empty-statement construct is to quiet the
* warn-unused-result warning.
*/
if (write(pipefd, "S", 1))
if (lxc_write_nointr(pipefd, "S", 1))
;
close(pipefd);
......
......@@ -303,8 +303,8 @@ int main(int argc, char *argv[])
int pid;
char *default_args[] = {"/bin/sh", NULL};
char buf[1];
int pipe1[2], /* child tells parent it has unshared */
pipe2[2]; /* parent tells child it is mapped and may proceed */
int pipe_fds1[2], /* child tells parent it has unshared */
pipe_fds2[2]; /* parent tells child it is mapped and may proceed */
lxc_log_fd = STDERR_FILENO;
......@@ -360,15 +360,15 @@ int main(int argc, char *argv[])
if (argc < 1)
argv = default_args;
if (pipe(pipe1) < 0 || pipe(pipe2) < 0) {
if (pipe2(pipe_fds1, O_CLOEXEC) < 0 || pipe2(pipe_fds2, O_CLOEXEC) < 0) {
perror("pipe");
exit(EXIT_FAILURE);
}
if ((pid = fork()) == 0) {
/* Child. */
close(pipe1[0]);
close(pipe2[1]);
close(pipe_fds1[0]);
close(pipe_fds2[1]);
opentty(ttyname0, 0);
opentty(ttyname1, 1);
opentty(ttyname2, 2);
......@@ -379,11 +379,11 @@ int main(int argc, char *argv[])
return 1;
}
buf[0] = '1';
if (write(pipe1[1], buf, 1) < 1) {
if (lxc_write_nointr(pipe_fds1[1], buf, 1) < 1) {
perror("write pipe");
exit(EXIT_FAILURE);
}
if (read(pipe2[0], buf, 1) < 1) {
if (lxc_read_nointr(pipe_fds2[0], buf, 1) < 1) {
perror("read pipe");
exit(EXIT_FAILURE);
}
......@@ -392,14 +392,14 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
close(pipe1[1]);
close(pipe2[0]);
close(pipe_fds1[1]);
close(pipe_fds2[0]);
return do_child((void*)argv);
}
close(pipe1[1]);
close(pipe2[0]);
if (read(pipe1[0], buf, 1) < 1) {
close(pipe_fds1[1]);
close(pipe_fds2[0]);
if (lxc_read_nointr(pipe_fds1[0], buf, 1) < 1) {
perror("read pipe");
exit(EXIT_FAILURE);
}
......@@ -409,7 +409,7 @@ int main(int argc, char *argv[])
if (lxc_map_ids(&active_map, pid))
fprintf(stderr, "error mapping child\n");
if (write(pipe2[1], buf, 1) < 0) {
if (lxc_write_nointr(pipe_fds2[1], buf, 1) < 0) {
perror("write to pipe");
exit(EXIT_FAILURE);
}
......
......@@ -4145,6 +4145,7 @@ struct userns_fn_data {
static int run_userns_fn(void *data)
{
int ret;
char c;
struct userns_fn_data *d = data;
......@@ -4154,14 +4155,14 @@ static int run_userns_fn(void *data)
/* Wait for parent to finish establishing a new mapping in the user
* namespace we are executing in.
*/
if (lxc_read_nointr(d->p[0], &c, 1) != 1)
return -1;
ret = lxc_read_nointr(d->p[0], &c, 1);
/* Close read end of the pipe. */
close(d->p[0]);
if (ret != 1)
return -1;
if (d->fn_name)
TRACE("calling function \"%s\"", d->fn_name);
TRACE("Calling function \"%s\"", d->fn_name);
/* Call function to run. */
return d->fn(d->arg);
......@@ -4383,7 +4384,7 @@ int userns_exec_1(struct lxc_conf *conf, int (*fn)(void *), void *data,
if (!idmap)
return -1;
ret = pipe(p);
ret = pipe2(p, O_CLOEXEC);
if (ret < 0) {
SYSERROR("Failed to create pipe");
return -1;
......@@ -4465,7 +4466,7 @@ int userns_exec_full(struct lxc_conf *conf, int (*fn)(void *), void *data,
if (!conf)
return -EINVAL;
ret = pipe(p);
ret = pipe2(p, O_CLOEXEC);
if (ret < 0) {
SYSERROR("opening pipe");
return -1;
......
......@@ -988,7 +988,7 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_
goto out_fini_handler;
}
if (pipe(pipes) < 0) {
if (pipe2(pipes, O_CLOEXEC) < 0) {
SYSERROR("pipe() failed");
goto out_fini_handler;
}
......@@ -1085,7 +1085,7 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_
if (WEXITSTATUS(status)) {
int n;
n = read(pipes[0], buf, sizeof(buf));
n = lxc_read_nointr(pipes[0], buf, sizeof(buf));
if (n < 0) {
SYSERROR("failed reading from criu stderr");
goto out_fini_handler;
......@@ -1129,7 +1129,7 @@ static void do_restore(struct lxc_container *c, int status_pipe, struct migrate_
close(pipes[0]);
ret = write(status_pipe, &status, sizeof(status));
ret = lxc_write_nointr(status_pipe, &status, sizeof(status));
close(status_pipe);
status_pipe = -1;
......@@ -1175,7 +1175,7 @@ out:
if (!status)
status = 1;
if (write(status_pipe, &status, sizeof(status)) != sizeof(status))
if (lxc_write_nointr(status_pipe, &status, sizeof(status)) != sizeof(status))
SYSERROR("writing status failed");
close(status_pipe);
}
......@@ -1313,7 +1313,7 @@ static bool do_dump(struct lxc_container *c, char *mode, struct migrate_opts *op
return false;
}
n = read(criuout[0], buf, sizeof(buf));
n = lxc_read_nointr(criuout[0], buf, sizeof(buf));
close(criuout[0]);
if (n < 0) {
SYSERROR("read");
......@@ -1416,7 +1416,7 @@ bool __criu_restore(struct lxc_container *c, struct migrate_opts *opts)
close(pipefd[1]);
free(criu_version);
nread = read(pipefd[0], &status, sizeof(status));
nread = lxc_read_nointr(pipefd[0], &status, sizeof(status));
close(pipefd[0]);
if (sizeof(status) != nread) {
ERROR("reading status from pipe failed");
......
......@@ -290,7 +290,8 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
{
char buffer[LXC_LOG_BUFFER_SIZE];
char date_time[LXC_LOG_TIME_SIZE];
int n, ret;
int n;
ssize_t ret;
int fd_to_use = -1;
const char *log_container_name = log_vmname;
......@@ -340,7 +341,12 @@ static int log_append_logfile(const struct lxc_log_appender *appender,
buffer[n] = '\n';
return write(fd_to_use, buffer, n + 1);
again:
ret = write(fd_to_use, buffer, n + 1);
if (ret < 0 && errno == EINTR)
goto again;
return ret;
}
static struct lxc_log_appender log_appender_syslog = {
......
......@@ -599,7 +599,7 @@ static bool file_is_yes(const char *path)
if (fd < 0)
return false;
rd = read(fd, buf, sizeof(buf));
rd = lxc_read_nointr(fd, buf, sizeof(buf));
close(fd);
return rd >= 4 && strncmp(buf, "yes\n", 4) == 0;
......
......@@ -2292,21 +2292,19 @@ static bool remove_from_array(char ***names, char *cname, int size)
return false;
}
static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
static char **do_lxcapi_get_interfaces(struct lxc_container *c)
{
pid_t pid;
int i, count = 0, pipefd[2];
char **interfaces = NULL;
char interface[IFNAMSIZ];
if(pipe(pipefd) < 0) {
SYSERROR("pipe failed");
if (pipe2(pipefd, O_CLOEXEC) < 0)
return NULL;
}
pid = fork();
if (pid < 0) {
SYSERROR("failed to fork task to get interfaces information");
SYSERROR("Failed to fork task to get interfaces information");
close(pipefd[0]);
close(pipefd[1]);
return NULL;
......@@ -2320,23 +2318,23 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
close(pipefd[0]);
if (!enter_net_ns(c)) {
SYSERROR("failed to enter namespace");
SYSERROR("Failed to enter network namespace");
goto out;
}
/* Grab the list of interfaces */
if (getifaddrs(&interfaceArray)) {
SYSERROR("failed to get interfaces list");
SYSERROR("Failed to get interfaces list");
goto out;
}
/* Iterate through the interfaces */
for (tempIfAddr = interfaceArray; tempIfAddr != NULL; tempIfAddr = tempIfAddr->ifa_next) {
nbytes = write(pipefd[1], tempIfAddr->ifa_name, IFNAMSIZ);
if (nbytes < 0) {
ERROR("write failed");
for (tempIfAddr = interfaceArray; tempIfAddr != NULL;
tempIfAddr = tempIfAddr->ifa_next) {
nbytes = lxc_write_nointr(pipefd[1], tempIfAddr->ifa_name, IFNAMSIZ);
if (nbytes < 0)
goto out;
}
count++;
}
......@@ -2354,20 +2352,20 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
/* close the write-end of the pipe */
close(pipefd[1]);
while (read(pipefd[0], &interface, IFNAMSIZ) == IFNAMSIZ) {
while (lxc_read_nointr(pipefd[0], &interface, IFNAMSIZ) == IFNAMSIZ) {
interface[IFNAMSIZ - 1] = '\0';
if (array_contains(&interfaces, interface, count))
continue;
continue;
if(!add_to_array(&interfaces, interface, count))
if (!add_to_array(&interfaces, interface, count))
ERROR("Failed to add \"%s\" to array", interface);
count++;
}
if (wait_for_pid(pid) != 0) {
for(i=0;i<count;i++)
for (i = 0; i < count; i++)
free(interfaces[i]);
free(interfaces);
......@@ -2378,7 +2376,7 @@ static char ** do_lxcapi_get_interfaces(struct lxc_container *c)
close(pipefd[0]);
/* Append NULL to the array */
if(interfaces)
if (interfaces)
interfaces = (char **)lxc_append_null_to_array((void **)interfaces, count);
return interfaces;
......@@ -2396,7 +2394,7 @@ static char **do_lxcapi_get_ips(struct lxc_container *c, const char *interface,
int count = 0;
char **addresses = NULL;
ret = pipe(pipefd);
ret = pipe2(pipefd, O_CLOEXEC);
if (ret < 0) {
SYSERROR("Failed to create pipe");
return NULL;
......@@ -3344,7 +3342,7 @@ static int copy_file(const char *old, const char *new)
}
while (1) {
len = read(in, buf, 8096);
len = lxc_read_nointr(in, buf, 8096);
if (len < 0) {
SYSERROR("Error reading old file %s", old);
goto err;
......@@ -3353,7 +3351,7 @@ static int copy_file(const char *old, const char *new)
if (len == 0)
break;
ret = write(out, buf, len);
ret = lxc_write_nointr(out, buf, len);
if (ret < len) { /* should we retry? */
SYSERROR("Error: write to new file %s was interrupted", new);
goto err;
......
......@@ -122,7 +122,7 @@ static void lxc_monitor_fifo_send(struct lxc_msg *msg, const char *lxcpath)
return;
}
ret = write(fd, msg, sizeof(*msg));
ret = lxc_write_nointr(fd, msg, sizeof(*msg));
if (ret != sizeof(*msg)) {
close(fd);
SYSERROR("Failed to write to monitor fifo \"%s\".", fifo_path);
......@@ -348,7 +348,7 @@ int lxc_monitord_spawn(const char *lxcpath)
* synced with the child process. the if-empty-statement
* construct is to quiet the warn-unused-result warning.
*/
if (read(pipefd[0], &c, 1))
if (lxc_read_nointr(pipefd[0], &c, 1))
;
close(pipefd[0]);
......
......@@ -1374,7 +1374,7 @@ static int proc_sys_net_write(const char *path, const char *value)
if (fd < 0)
return -errno;
if (write(fd, value, strlen(value)) < 0)
if (lxc_write_nointr(fd, value, strlen(value)) < 0)
err = -errno;
close(fd);
......@@ -2179,7 +2179,7 @@ static int lxc_create_network_unpriv_exec(const char *lxcpath, const char *lxcna
/* close the write-end of the pipe */
close(pipefd[1]);
bytes = read(pipefd[0], &buffer, MAXPATHLEN);
bytes = lxc_read_nointr(pipefd[0], &buffer, MAXPATHLEN);
if (bytes < 0) {
SYSERROR("Failed to read from pipe file descriptor");
close(pipefd[0]);
......@@ -2335,7 +2335,7 @@ static int lxc_delete_network_unpriv_exec(const char *lxcpath, const char *lxcna
close(pipefd[1]);
bytes = read(pipefd[0], &buffer, MAXPATHLEN);
bytes = lxc_read_nointr(pipefd[0], &buffer, MAXPATHLEN);
if (bytes < 0) {
SYSERROR("Failed to read from pipe file descriptor.");
close(pipefd[0]);
......
......@@ -31,6 +31,7 @@
#include "sync.h"
#include "log.h"
#include "start.h"
#include "utils.h"
lxc_log_define(sync, lxc);
......@@ -39,7 +40,7 @@ static int __sync_wait(int fd, int sequence)
int sync = -1;
ssize_t ret;
ret = read(fd, &sync, sizeof(sync));
ret = lxc_read_nointr(fd, &sync, sizeof(sync));
if (ret < 0) {
SYSERROR("Sync wait failure");
return -1;
......@@ -71,7 +72,7 @@ static int __sync_wake(int fd, int sequence)
{
int sync = sequence;
if (write(fd, &sync, sizeof(sync)) < 0) {
if (lxc_write_nointr(fd, &sync, sizeof(sync)) < 0) {
SYSERROR("Sync wake failure");
return -1;
}
......
......@@ -115,7 +115,7 @@ int lxc_terminal_signalfd_cb(int fd, uint32_t events, void *cbdata,
struct signalfd_siginfo siginfo;
struct lxc_terminal_state *ts = cbdata;
ret = read(fd, &siginfo, sizeof(siginfo));
ret = lxc_read_nointr(fd, &siginfo, sizeof(siginfo));
if (ret < 0 || (size_t)ret < sizeof(siginfo)) {
ERROR("Failed to read signal info");
return LXC_MAINLOOP_ERROR;
......
......@@ -233,14 +233,13 @@ static bool do_destroy_with_snapshots(struct lxc_container *c)
return false;
}
ret = read(fd, buf, fbuf.st_size);
ret = lxc_read_nointr(fd, buf, fbuf.st_size);
close(fd);
if (ret < 0) {
ERROR("Could not read %s", path);
close(fd);
free(buf);
return false;
}
close(fd);
lxc_iterate_parts(lxcpath, buf, "\n") {
c1 = lxc_container_new(lxcname, lxcpath);
......
......@@ -202,7 +202,7 @@ static int lxc_tool_monitord_spawn(const char *lxcpath)
* synced with the child process. the if-empty-statement
* construct is to quiet the warn-unused-result warning.
*/
if (read(pipefd[0], &c, 1))
if (lxc_read_nointr(pipefd[0], &c, 1))
;
close(pipefd[0]);
......@@ -276,7 +276,7 @@ int main(int argc, char *argv[])
continue;
}
if (write(fd, "quit", 4) < 0) {
if (lxc_write_nointr(fd, "quit", 4) < 0) {
SYSERROR("Unable to close monitor on path: %s", my_args.lxcpath[i]);
ret = EXIT_FAILURE;
close(fd);
......
......@@ -574,7 +574,7 @@ static int stdin_handler(int fd, uint32_t events, void *data,
if (events & EPOLLIN) {
int rc;
rc = read(fd, in_char, sizeof(*in_char));
rc = lxc_read_nointr(fd, in_char, sizeof(*in_char));
if (rc <= 0)
*in_char = '\0';
}
......
......@@ -271,7 +271,7 @@ static int do_start(void *arg)
if (start_arg->setuid) {
/* waiting until uid maps is set */
ret = read(start_arg->wait_fd, &wait_val, sizeof(wait_val));
ret = lxc_read_nointr(start_arg->wait_fd, &wait_val, sizeof(wait_val));
if (ret == -1) {
SYSERROR("Failed to read eventfd");
close(start_arg->wait_fd);
......@@ -418,7 +418,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
ret = write(start_arg.wait_fd, &wait_val, sizeof(wait_val));
ret = lxc_write_nointr(start_arg.wait_fd, &wait_val, sizeof(wait_val));
if (ret < 0) {
SYSERROR("Failed to write eventfd");
free_ifname_list();
......
......@@ -1090,14 +1090,14 @@ int lxc_read_from_file(const char *filename, void *buf, size_t count)
char buf2[100];
size_t count2 = 0;
while ((ret = read(fd, buf2, 100)) > 0)
while ((ret = lxc_read_nointr(fd, buf2, 100)) > 0)
count2 += ret;
if (ret >= 0)
ret = count2;
} else {
memset(buf, 0, count);
ret = read(fd, buf, count);
ret = lxc_read_nointr(fd, buf, count);
}
if (ret < 0)
......@@ -2414,7 +2414,7 @@ int run_command(char *buf, size_t buf_size, int (*child_fn)(void *), void *args)
close(pipefd[1]);
if (buf && buf_size > 0) {
bytes = read(pipefd[0], buf, buf_size - 1);
bytes = lxc_read_nointr(pipefd[0], buf, buf_size - 1);
if (bytes > 0)
buf[bytes - 1] = '\0';
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment