[lxc-devel] [PATCH] Fix compile warnings

Ryousei Takano takano-ryousei at aist.go.jp
Tue Mar 31 01:14:04 UTC 2009


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 <takano-ryousei at aist.go.jp>
---
 src/lxc/lxc_console.c |   15 ++++++++++++---
 src/lxc/restart.c     |   10 ++++++++--
 src/lxc/start.c       |    5 ++++-
 3 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/src/lxc/lxc_console.c b/src/lxc/lxc_console.c
index 6d5aef0..c838bd2 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 bc23293..7508cf0 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 051e70c..de355af 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);
 
-- 
1.5.6.3





More information about the lxc-devel mailing list