diff options
author | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-03-24 19:59:00 -0400 |
---|---|---|
committer | Zbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl> | 2013-04-05 19:50:57 -0400 |
commit | b92bea5d2a9481de69bb627a7b442a9f58fca43d (patch) | |
tree | d43f5e340014d5c3ce723eabb60cd74e3dd20a18 /src/core/execute.c | |
parent | 8c62ecf1a99ab4a3f69cb81be38715c504ef5723 (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/execute.c')
-rw-r--r-- | src/core/execute.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/core/execute.c b/src/core/execute.c index 2c13d1f9f6..c51049767d 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -205,7 +205,10 @@ static int open_null_as(int flags, int nfd) { static int connect_logger_as(const ExecContext *context, ExecOutput output, const char *ident, const char *unit_id, int nfd) { int fd, r; - union sockaddr_union sa; + union sockaddr_union sa = { + .un.sun_family = AF_UNIX, + .un.sun_path = "/run/systemd/journal/stdout", + }; assert(context); assert(output < _EXEC_OUTPUT_MAX); @@ -216,10 +219,6 @@ static int connect_logger_as(const ExecContext *context, ExecOutput output, cons if (fd < 0) return -errno; - zero(sa); - sa.un.sun_family = AF_UNIX; - strncpy(sa.un.sun_path, "/run/systemd/journal/stdout", sizeof(sa.un.sun_path)); - r = connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path)); if (r < 0) { close_nointr_nofail(fd); @@ -938,7 +937,7 @@ static int apply_seccomp(uint32_t *syscall_filter) { int i; unsigned n; struct sock_filter *f; - struct sock_fprog prog; + struct sock_fprog prog = {}; assert(syscall_filter); @@ -970,7 +969,6 @@ static int apply_seccomp(uint32_t *syscall_filter) { memcpy(f + (ELEMENTSOF(header) + 2*n), footer, sizeof(footer)); /* Third: install the filter */ - zero(prog); prog.len = ELEMENTSOF(header) + ELEMENTSOF(footer) + 2*n; prog.filter = f; if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog) < 0) @@ -1210,10 +1208,9 @@ int exec_spawn(ExecCommand *command, } if (context->cpu_sched_set) { - struct sched_param param; - - zero(param); - param.sched_priority = context->cpu_sched_priority; + struct sched_param param = { + .sched_priority = context->cpu_sched_priority, + }; r = sched_setscheduler(0, context->cpu_sched_policy | @@ -1701,7 +1698,7 @@ int exec_context_load_environment(const ExecContext *c, char ***l) { int k; bool ignore = false; char **p; - glob_t pglob; + glob_t pglob = {}; int count, n; fn = *i; @@ -1721,7 +1718,6 @@ int exec_context_load_environment(const ExecContext *c, char ***l) { } /* Filename supports globbing, take all matching files */ - zero(pglob); errno = 0; if (glob(fn, 0, NULL, &pglob) != 0) { globfree(&pglob); |