From: Ryousei Takano Date: Tue, 31 Mar 2009 01:14:04 +0000 (+0900) Subject: Fix compile warnings X-Git-Tag: lxc_0_6_2~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3f21c11481b50030bc073a279c8cbe8f03f57138;p=thirdparty%2Flxc.git Fix compile warnings This patch fixes compile warnings: ignoring return value of function, declared with attribute warn_unused_result, and adds error handling. Signed-off-by: Ryousei Takano Signed-off-by: Daniel Lezcano --- diff --git a/src/lxc/lxc_console.c b/src/lxc/lxc_console.c index 6d5aef0ae..c838bd268 100644 --- a/src/lxc/lxc_console.c +++ b/src/lxc/lxc_console.c @@ -133,7 +133,10 @@ int main(int argc, char *argv[]) /* read the "stdin" and write that to the master */ if (pfd[0].revents & POLLIN) { - read(0, &c, 1); + if (read(0, &c, 1) < 0) { + lxc_log_syserror("failed to read"); + goto out_err; + } /* we want to exit the console with Ctrl+a q */ if (c == 1) { @@ -145,7 +148,10 @@ int main(int argc, char *argv[]) goto out; wait4q = 0; - write(master, &c, 1); + if (write(master, &c, 1) < 0) { + lxc_log_syserror("failed to write"); + goto out_err; + } } /* other side has closed the connection */ @@ -154,7 +160,10 @@ int main(int argc, char *argv[]) /* read the master and write to "stdout" */ if (pfd[1].revents & POLLIN) { - read(master, &c, 1); + if (read(master, &c, 1) < 0) { + lxc_log_syserror("failed to read"); + goto out_err; + } printf("%c", c); fflush(stdout); } diff --git a/src/lxc/restart.c b/src/lxc/restart.c index bc2329312..7508cf042 100644 --- a/src/lxc/restart.c +++ b/src/lxc/restart.c @@ -164,8 +164,14 @@ int lxc_restart(const char *name, const char *statefile, goto err_child_failed; } - asprintf(&val, "%d\n", pid); - asprintf(&init, LXCPATH "/%s/init", name); + if (!asprintf(&val, "%d\n", pid)) { + lxc_log_syserror("failed to allocate memory"); + goto err_child_failed; + } + if (!asprintf(&init, LXCPATH "/%s/init", name)) { + lxc_log_syserror("failed to allocate memory"); + goto err_child_failed; + } fd = open(init, O_WRONLY|O_CREAT|O_TRUNC, S_IRUSR|S_IWUSR); if (fd < 0) { lxc_log_syserror("failed to open '%s'", init); diff --git a/src/lxc/start.c b/src/lxc/start.c index 051e70c24..de355af63 100644 --- a/src/lxc/start.c +++ b/src/lxc/start.c @@ -427,7 +427,10 @@ int lxc_start(const char *name, char *argv[]) goto err_child_failed; } - asprintf(&val, "%d\n", pid); + if (!asprintf(&val, "%d\n", pid)) { + lxc_log_syserror("failed to allocate memory"); + goto err_child_failed; + } snprintf(init, MAXPATHLEN, LXCPATH "/%s/init", name);