[lxc-devel] [lxc/master] lxc-init: some enhancements
0x0916 on Github
lxc-bot at linuxcontainers.org
Wed Jul 5 04:16:28 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 301 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170705/32cd2ff0/attachment.bin>
-------------- next part --------------
From 55684fd82245e9b0a2c4436360b2b58a23a2472a Mon Sep 17 00:00:00 2001
From: Long Wang <w at laoqinren.net>
Date: Wed, 5 Jul 2017 10:53:02 +0800
Subject: [PATCH 1/4] lxc-init: add comment for exclude 32 and 33 signals
Signed-off-by: Long Wang <w at laoqinren.net>
---
src/lxc/tools/lxc_init.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/src/lxc/tools/lxc_init.c b/src/lxc/tools/lxc_init.c
index 07d8f1159..07ef69640 100644
--- a/src/lxc/tools/lxc_init.c
+++ b/src/lxc/tools/lxc_init.c
@@ -143,7 +143,8 @@ int main(int argc, char *argv[])
/* Exclude some signals: ILL, SEGV and BUS are likely to
* reveal a bug and we want a core. STOP and KILL cannot be
- * handled anyway: they're here for documentation.
+ * handled anyway: they're here for documentation. 32 and 33
+ * are not defined.
*/
if (i == SIGILL ||
i == SIGSEGV ||
From 1bfb12006f7127bec8138f3b75bc9c4e79dc389c Mon Sep 17 00:00:00 2001
From: Long Wang <w at laoqinren.net>
Date: Wed, 5 Jul 2017 10:57:14 +0800
Subject: [PATCH 2/4] lxc-init: non-functional changes
This patch mainly update the message format to:
* upper the first letter
* end without a dot
all changes are relate to `lxc-init`
Signed-off-by: Long Wang <w at laoqinren.net>
---
src/lxc/error.c | 4 ++--
src/lxc/initutils.c | 14 +++++++-------
src/lxc/tools/lxc_init.c | 24 +++++++++---------------
3 files changed, 18 insertions(+), 24 deletions(-)
diff --git a/src/lxc/error.c b/src/lxc/error.c
index b7fb687fe..81d6a376e 100644
--- a/src/lxc/error.c
+++ b/src/lxc/error.c
@@ -46,12 +46,12 @@ extern int lxc_error_set_and_log(int pid, int status)
if (WIFEXITED(status)) {
ret = WEXITSTATUS(status);
if (ret)
- INFO("Child <%d> ended on error (%d).", pid, ret);
+ INFO("Child <%d> ended on error (%d)", pid, ret);
}
if (WIFSIGNALED(status)) {
int signal = WTERMSIG(status);
- INFO("Child <%d> ended on signal (%d).", pid, signal);
+ INFO("Child <%d> ended on signal (%d)", pid, signal);
}
return ret;
diff --git a/src/lxc/initutils.c b/src/lxc/initutils.c
index 8d9016cd0..c190d6d50 100644
--- a/src/lxc/initutils.c
+++ b/src/lxc/initutils.c
@@ -30,10 +30,10 @@ static int mount_fs(const char *source, const char *target, const char *type)
{
/* the umount may fail */
if (umount(target))
- WARN("failed to unmount %s : %s", target, strerror(errno));
+ WARN("Failed to unmount %s : %s", target, strerror(errno));
if (mount(source, target, type, 0, NULL)) {
- ERROR("failed to mount %s : %s", target, strerror(errno));
+ ERROR("Failed to mount %s : %s", target, strerror(errno));
return -1;
}
@@ -45,26 +45,26 @@ static int mount_fs(const char *source, const char *target, const char *type)
extern void lxc_setup_fs(void)
{
if (mount_fs("proc", "/proc", "proc"))
- INFO("failed to remount proc");
+ INFO("Failed to remount proc");
/* if /dev has been populated by us, /dev/shm does not exist */
if (access("/dev/shm", F_OK) && mkdir("/dev/shm", 0777))
- INFO("failed to create /dev/shm");
+ INFO("Failed to create /dev/shm");
/* if we can't mount /dev/shm, continue anyway */
if (mount_fs("shmfs", "/dev/shm", "tmpfs"))
- INFO("failed to mount /dev/shm");
+ INFO("Failed to mount /dev/shm");
/* If we were able to mount /dev/shm, then /dev exists */
/* Sure, but it's read-only per config :) */
if (access("/dev/mqueue", F_OK) && mkdir("/dev/mqueue", 0666)) {
- DEBUG("failed to create '/dev/mqueue'");
+ DEBUG("Failed to create '/dev/mqueue'");
return;
}
/* continue even without posix message queue support */
if (mount_fs("mqueue", "/dev/mqueue", "mqueue"))
- INFO("failed to mount /dev/mqueue");
+ INFO("Failed to mount /dev/mqueue");
}
static char *copy_global_config_value(char *p)
diff --git a/src/lxc/tools/lxc_init.c b/src/lxc/tools/lxc_init.c
index 07ef69640..aeb1bba29 100644
--- a/src/lxc/tools/lxc_init.c
+++ b/src/lxc/tools/lxc_init.c
@@ -119,7 +119,7 @@ int main(int argc, char *argv[])
lxc_log_options_no_override();
if (!argv[optind]) {
- ERROR("missing command to launch");
+ ERROR("Missing command to launch");
exit(EXIT_FAILURE);
}
@@ -134,7 +134,7 @@ int main(int argc, char *argv[])
sigdelset(&mask, SIGSEGV) ||
sigdelset(&mask, SIGBUS) ||
sigprocmask(SIG_SETMASK, &mask, &omask)) {
- SYSERROR("failed to set signal mask");
+ SYSERROR("Failed to set signal mask");
exit(EXIT_FAILURE);
}
@@ -160,14 +160,14 @@ int main(int argc, char *argv[])
sigdelset(&act.sa_mask, SIGBUS) ||
sigdelset(&act.sa_mask, SIGSTOP) ||
sigdelset(&act.sa_mask, SIGKILL)) {
- ERROR("failed to set signal");
+ ERROR("Failed to set signal");
exit(EXIT_FAILURE);
}
act.sa_flags = 0;
act.sa_handler = interrupt_handler;
if (sigaction(i, &act, NULL) && errno != EINVAL) {
- SYSERROR("failed to sigaction");
+ SYSERROR("Failed to sigaction");
exit(EXIT_FAILURE);
}
}
@@ -175,32 +175,30 @@ int main(int argc, char *argv[])
lxc_setup_fs();
pid = fork();
-
if (pid < 0)
exit(EXIT_FAILURE);
if (!pid) {
-
/* restore default signal handlers */
for (i = 1; i < NSIG; i++)
signal(i, SIG_DFL);
if (sigprocmask(SIG_SETMASK, &omask, NULL)) {
- SYSERROR("failed to set signal mask");
+ SYSERROR("Failed to set signal mask");
exit(EXIT_FAILURE);
}
- NOTICE("about to exec '%s'", aargv[0]);
+ NOTICE("About to exec '%s'", aargv[0]);
execvp(aargv[0], aargv);
- ERROR("failed to exec: '%s' : %s", aargv[0], strerror(errno));
+ ERROR("Failed to exec: '%s' : %s", aargv[0], strerror(errno));
exit(err);
}
/* let's process the signals now */
if (sigdelset(&omask, SIGALRM) ||
sigprocmask(SIG_SETMASK, &omask, NULL)) {
- SYSERROR("failed to set signal mask");
+ SYSERROR("Failed to set signal mask");
exit(EXIT_FAILURE);
}
@@ -214,10 +212,8 @@ int main(int argc, char *argv[])
pid_t waited_pid;
switch (was_interrupted) {
-
case 0:
break;
-
case SIGPWR:
case SIGTERM:
if (!shutdown) {
@@ -226,11 +222,9 @@ int main(int argc, char *argv[])
alarm(1);
}
break;
-
case SIGALRM:
kill(-1, SIGKILL);
break;
-
default:
kill(pid, was_interrupted);
break;
@@ -244,7 +238,7 @@ int main(int argc, char *argv[])
if (errno == EINTR)
continue;
- ERROR("failed to wait child : %s",
+ ERROR("Failed to wait child : %s",
strerror(errno));
goto out;
}
From 1574fc24956f72f113b26a8f0778c679265059a5 Mon Sep 17 00:00:00 2001
From: Long Wang <w at laoqinren.net>
Date: Wed, 5 Jul 2017 11:54:25 +0800
Subject: [PATCH 3/4] lxc-init: adjust include statements
* Use `#include <lxc/lxccontaienr.h>` style for exported haeders.
* remove used header `caps.h`
Signed-off-by: Long Wang <w at laoqinren.net>
---
src/lxc/tools/lxc_init.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/src/lxc/tools/lxc_init.c b/src/lxc/tools/lxc_init.c
index aeb1bba29..8b29974b1 100644
--- a/src/lxc/tools/lxc_init.c
+++ b/src/lxc/tools/lxc_init.c
@@ -33,11 +33,11 @@
#include <sys/wait.h>
#include <getopt.h>
+#include <lxc/lxccontainer.h>
+
#include "log.h"
-#include "caps.h"
#include "error.h"
#include "initutils.h"
-#include "lxccontainer.h"
lxc_log_define(lxc_init, lxc);
From 16affc24a56303204baf1aa76f66a0a0546cebfb Mon Sep 17 00:00:00 2001
From: Long Wang <w at laoqinren.net>
Date: Wed, 5 Jul 2017 12:01:16 +0800
Subject: [PATCH 4/4] lxc-init: move initialization of act to outside of the
loop
Signed-off-by: Long Wang <w at laoqinren.net>
---
src/lxc/tools/lxc_init.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/src/lxc/tools/lxc_init.c b/src/lxc/tools/lxc_init.c
index 8b29974b1..6b2355be7 100644
--- a/src/lxc/tools/lxc_init.c
+++ b/src/lxc/tools/lxc_init.c
@@ -81,6 +81,7 @@ int main(int argc, char *argv[])
int err;
char **aargv;
sigset_t mask, omask;
+ struct sigaction act;
int i, have_status = 0, shutdown = 0;
int opt;
char *lxcpath = NULL, *name = NULL, *logpriority = NULL;
@@ -138,9 +139,19 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}
- for (i = 1; i < NSIG; i++) {
- struct sigaction act;
+ if (sigfillset(&act.sa_mask) ||
+ sigdelset(&act.sa_mask, SIGILL) ||
+ sigdelset(&act.sa_mask, SIGSEGV) ||
+ sigdelset(&act.sa_mask, SIGBUS) ||
+ sigdelset(&act.sa_mask, SIGSTOP) ||
+ sigdelset(&act.sa_mask, SIGKILL)) {
+ ERROR("Failed to set signal");
+ exit(EXIT_FAILURE);
+ }
+ act.sa_flags = 0;
+ act.sa_handler = interrupt_handler;
+ for (i = 1; i < NSIG; i++) {
/* Exclude some signals: ILL, SEGV and BUS are likely to
* reveal a bug and we want a core. STOP and KILL cannot be
* handled anyway: they're here for documentation. 32 and 33
@@ -154,18 +165,6 @@ int main(int argc, char *argv[])
i == 32 || i == 33)
continue;
- if (sigfillset(&act.sa_mask) ||
- sigdelset(&act.sa_mask, SIGILL) ||
- sigdelset(&act.sa_mask, SIGSEGV) ||
- sigdelset(&act.sa_mask, SIGBUS) ||
- sigdelset(&act.sa_mask, SIGSTOP) ||
- sigdelset(&act.sa_mask, SIGKILL)) {
- ERROR("Failed to set signal");
- exit(EXIT_FAILURE);
- }
-
- act.sa_flags = 0;
- act.sa_handler = interrupt_handler;
if (sigaction(i, &act, NULL) && errno != EINVAL) {
SYSERROR("Failed to sigaction");
exit(EXIT_FAILURE);
More information about the lxc-devel
mailing list