[lxc-devel] [lxc/master] lxccontainer: minor fixes

brauner on Github lxc-bot at linuxcontainers.org
Wed Aug 15 22:21:34 UTC 2018


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 364 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20180815/015f330e/attachment.bin>
-------------- next part --------------
From 2d8e841830bd9cdb3c968c3f6b4d7a5775ae1617 Mon Sep 17 00:00:00 2001
From: Christian Brauner <christian.brauner at ubuntu.com>
Date: Thu, 16 Aug 2018 00:20:46 +0200
Subject: [PATCH] lxccontainer: minor fixes

Signed-off-by: Christian Brauner <christian.brauner at ubuntu.com>
---
 src/lxc/lxccontainer.c | 33 ++++++++++++++++++---------------
 1 file changed, 18 insertions(+), 15 deletions(-)

diff --git a/src/lxc/lxccontainer.c b/src/lxc/lxccontainer.c
index 5f1e7330c..3e76d045b 100644
--- a/src/lxc/lxccontainer.c
+++ b/src/lxc/lxccontainer.c
@@ -970,10 +970,15 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
 		/* We don't really care if this doesn't print all the
 		 * characters. All that it means is that the proctitle will be
 		 * ugly. Similarly, we also don't care if setproctitle() fails.
-		 * */
-		(void)snprintf(title, sizeof(title), "[lxc monitor] %s %s", c->config_path, c->name);
-		INFO("Attempting to set proc title to %s", title);
-		(void)setproctitle(title);
+		 */
+		ret = snprintf(title, sizeof(title), "[lxc monitor] %s %s", c->config_path, c->name);
+		if (ret > 0) {
+			ret = setproctitle(title);
+			if (ret < 0)
+				INFO("Failed to set process title to %s", title);
+			else
+				INFO("Set proc title to %s", title);
+		}
 
 		/* We fork() a second time to be reparented to init. Like
 		 * POSIX's daemon() function we change to "/" and redirect
@@ -1020,17 +1025,15 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
 		ret = setsid();
 		if (ret < 0)
 			TRACE("Process %d is already process group leader", lxc_raw_getpid());
-	} else {
-		if (!am_single_threaded()) {
-			ERROR("Cannot start non-daemonized container when threaded");
-			free_init_cmd(init_cmd);
-			lxc_free_handler(handler);
-			return false;
-		}
+	} else if (!am_single_threaded()) {
+		ERROR("Cannot start non-daemonized container when threaded");
+		free_init_cmd(init_cmd);
+		lxc_free_handler(handler);
+		return false;
 	}
 
-	/* We need to write PID file after daemonize, so we always
-	 * write the right PID.
+	/* We need to write PID file after daemonize, so we always write the
+	 * right PID.
 	 */
 	if (c->pidfile) {
 		int ret, w;
@@ -1054,7 +1057,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
 			free_init_cmd(init_cmd);
 			lxc_free_handler(handler);
 
-			SYSERROR("Failed to write '%s'", c->pidfile);
+			SYSERROR("Failed to write monitor pid to \"%s\"", c->pidfile);
 
 			if (c->daemonize)
 				_exit(EXIT_FAILURE);
@@ -1069,7 +1072,7 @@ static bool do_lxcapi_start(struct lxc_container *c, int useinit, char * const a
 	if (conf->monitor_unshare) {
 		ret = unshare(CLONE_NEWNS);
 		if (ret < 0) {
-			SYSERROR("failed to unshare mount namespace");
+			SYSERROR("Failed to unshare mount namespace");
 			lxc_free_handler(handler);
 			ret = 1;
 			goto on_error;


More information about the lxc-devel mailing list