summaryrefslogtreecommitdiff
path: root/src/core/main.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-03-24 19:59:00 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-04-05 19:50:57 -0400
commitb92bea5d2a9481de69bb627a7b442a9f58fca43d (patch)
treed43f5e340014d5c3ce723eabb60cd74e3dd20a18 /src/core/main.c
parent8c62ecf1a99ab4a3f69cb81be38715c504ef5723 (diff)
Use initalization instead of explicit zeroing
Before, we would initialize many fields twice: first by filling the structure with zeros, and then a second time with the real values. We can let the compiler do the job for us, avoiding one copy. A downside of this patch is that text gets slightly bigger. This is because all zero() calls are effectively inlined: $ size build/.libs/systemd text data bss dec hex filename before 897737 107300 2560 1007597 f5fed build/.libs/systemd after 897873 107300 2560 1007733 f6075 build/.libs/systemd … actually less than 1‰. A few asserts that the parameter is not null had to be removed. I don't think this changes much, because first, it is quite unlikely for the assert to fail, and second, an immediate SEGV is almost as good as an assert.
Diffstat (limited to 'src/core/main.c')
-rw-r--r--src/core/main.c29
1 files changed, 13 insertions, 16 deletions
diff --git a/src/core/main.c b/src/core/main.c
index 92f066c707..4d21dd97a3 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -107,13 +107,13 @@ _noreturn_ static void crash(int sig) {
if (!arg_dump_core)
log_error("Caught <%s>, not dumping core.", signal_to_string(sig));
else {
- struct sigaction sa;
+ struct sigaction sa = {
+ .sa_handler = nop_handler,
+ .sa_flags = SA_NOCLDSTOP|SA_RESTART,
+ };
pid_t pid;
/* We want to wait for the core process, hence let's enable SIGCHLD */
- zero(sa);
- sa.sa_handler = nop_handler;
- sa.sa_flags = SA_NOCLDSTOP|SA_RESTART;
assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
pid = fork();
@@ -121,7 +121,7 @@ _noreturn_ static void crash(int sig) {
log_error("Caught <%s>, cannot fork for core dump: %s", signal_to_string(sig), strerror(errno));
else if (pid == 0) {
- struct rlimit rl;
+ struct rlimit rl = {};
/* Enable default signal handler for core dump */
zero(sa);
@@ -129,7 +129,6 @@ _noreturn_ static void crash(int sig) {
assert_se(sigaction(sig, &sa, NULL) == 0);
/* Don't limit the core dump size */
- zero(rl);
rl.rlim_cur = RLIM_INFINITY;
rl.rlim_max = RLIM_INFINITY;
setrlimit(RLIMIT_CORE, &rl);
@@ -162,16 +161,16 @@ _noreturn_ static void crash(int sig) {
chvt(arg_crash_chvt);
if (arg_crash_shell) {
- struct sigaction sa;
+ struct sigaction sa = {
+ .sa_handler = SIG_IGN,
+ .sa_flags = SA_NOCLDSTOP|SA_NOCLDWAIT|SA_RESTART,
+ };
pid_t pid;
log_info("Executing crash shell in 10s...");
sleep(10);
/* Let the kernel reap children for us */
- zero(sa);
- sa.sa_handler = SIG_IGN;
- sa.sa_flags = SA_NOCLDSTOP|SA_NOCLDWAIT|SA_RESTART;
assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
pid = fork();
@@ -193,12 +192,10 @@ _noreturn_ static void crash(int sig) {
}
static void install_crash_handler(void) {
- struct sigaction sa;
-
- zero(sa);
-
- sa.sa_handler = crash;
- sa.sa_flags = SA_NODEFER;
+ struct sigaction sa = {
+ .sa_handler = crash,
+ .sa_flags = SA_NODEFER,
+ };
sigaction_many(&sa, SIGNALS_CRASH_HANDLER, -1);
}