chiark / gitweb /
Use initalization instead of explicit zeroing
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sun, 24 Mar 2013 23:59:00 +0000 (19:59 -0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 5 Apr 2013 23:50:57 +0000 (19:50 -0400)
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.

49 files changed:
src/core/dbus-execute.c
src/core/dbus.c
src/core/device.c
src/core/execute.c
src/core/job.c
src/core/locale-setup.c
src/core/loopback-setup.c
src/core/main.c
src/core/manager.c
src/core/mount.c
src/core/service.c
src/core/swap.c
src/core/umount.c
src/core/unit.c
src/cryptsetup/cryptsetup.c
src/hostname/hostnamectl.c
src/journal/journald-server.c
src/journal/journald-stream.c
src/journal/journald-syslog.c
src/libsystemd-bus/bus-socket.c
src/libsystemd-bus/sd-bus.c
src/locale/localectl.c
src/locale/localed.c
src/login/loginctl.c
src/login/logind-inhibit.c
src/login/logind-session.c
src/login/logind.c
src/login/pam-module.c
src/nspawn/nspawn.c
src/python-systemd/_reader.c
src/readahead/readahead-collect.c
src/remount-fs/remount-fs.c
src/reply-password/reply-password.c
src/shared/ask-password-api.c
src/shared/dbus-loop.c
src/shared/install.c
src/shared/log.c
src/shared/util.c
src/shared/utmp-wtmp.c
src/shared/virt.c
src/shutdownd/shutdownd.c
src/stdio-bridge/stdio-bridge.c
src/systemctl/systemctl.c
src/timedate/timedatectl.c
src/tmpfiles/tmpfiles.c
src/tty-ask-password-agent/tty-ask-password-agent.c
src/udev/udev-builtin-net_id.c
src/update-utmp/update-utmp.c
src/vconsole/vconsole-setup.c

index 0a53207e590ca114a1a61f000f63ca8ca2d0b21d..2a8a0e1ac58610a31564959b21a8ee4756fae3ec 100644 (file)
@@ -160,9 +160,8 @@ int bus_execute_append_cpu_sched_priority(DBusMessageIter *i, const char *proper
         if (c->cpu_sched_set)
                 n = c->cpu_sched_priority;
         else {
-                struct sched_param p;
+                struct sched_param p = {};
 
-                zero(p);
                 if (sched_getparam(0, &p) >= 0)
                         n = p.sched_priority;
                 else
@@ -280,9 +279,8 @@ int bus_execute_append_rlimits(DBusMessageIter *i, const char *property, void *d
         if (c->rlimit[r])
                 u = (uint64_t) c->rlimit[r]->rlim_max;
         else {
-                struct rlimit rl;
+                struct rlimit rl = {};
 
-                zero(rl);
                 getrlimit(r, &rl);
 
                 u = (uint64_t) rl.rlim_max;
index b92c7d0b99923cc739f7d224fcc3f03fca3bd435..67ab1ae7f70ba85bf8a3e134fa9433ff7a06d2b1 100644 (file)
@@ -203,13 +203,11 @@ static void bus_toggle_watch(DBusWatch *bus_watch, void *data) {
 }
 
 static int bus_timeout_arm(Manager *m, Watch *w) {
-        struct itimerspec its;
+        struct itimerspec its = {};
 
         assert(m);
         assert(w);
 
-        zero(its);
-
         if (dbus_timeout_get_enabled(w->data.bus_timeout)) {
                 timespec_store(&its.it_value, dbus_timeout_get_interval(w->data.bus_timeout) * USEC_PER_MSEC);
                 its.it_interval = its.it_value;
index 0b01718ad4bc0ada8f79aa56f51b201319ba6c89..fb948688b66650875e37adb6baf3f290abd1fa2d 100644 (file)
@@ -477,7 +477,6 @@ static void device_shutdown(Manager *m) {
 }
 
 static int device_enumerate(Manager *m) {
-        struct epoll_event ev;
         int r;
         struct udev_enumerate *e = NULL;
         struct udev_list_entry *item = NULL, *first = NULL;
@@ -485,6 +484,8 @@ static int device_enumerate(Manager *m) {
         assert(m);
 
         if (!m->udev) {
+                struct epoll_event ev;
+
                 if (!(m->udev = udev_new()))
                         return -ENOMEM;
 
index 2c13d1f9f60e8a8c9d7f7e0e15844f33bebc7d2c..c51049767d9e25524a7032837b0ce9a20f3f69c9 100644 (file)
@@ -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);
index d5b7987a00734c62b8465efd993481c3342684a6..af5855b71d6a9c840c94b7cef7e55ee40d877c95 100644 (file)
@@ -858,10 +858,12 @@ finish:
 }
 
 int job_start_timer(Job *j) {
-        struct itimerspec its;
-        struct epoll_event ev;
+        struct itimerspec its = {};
+        struct epoll_event ev = {
+                .data.ptr = &j->timer_watch,
+                .events = EPOLLIN,
+        };
         int fd, r;
-        assert(j);
 
         if (j->unit->job_timeout <= 0 ||
             j->timer_watch.type == WATCH_JOB_TIMER)
@@ -874,7 +876,6 @@ int job_start_timer(Job *j) {
                 goto fail;
         }
 
-        zero(its);
         timespec_store(&its.it_value, j->unit->job_timeout);
 
         if (timerfd_settime(fd, 0, &its, NULL) < 0) {
@@ -882,10 +883,6 @@ int job_start_timer(Job *j) {
                 goto fail;
         }
 
-        zero(ev);
-        ev.data.ptr = &j->timer_watch;
-        ev.events = EPOLLIN;
-
         if (epoll_ctl(j->manager->epoll_fd, EPOLL_CTL_ADD, fd, &ev) < 0) {
                 r = -errno;
                 goto fail;
@@ -1064,15 +1061,14 @@ int job_deserialize(Job *j, FILE *f, FDSet *fds) {
 }
 
 int job_coldplug(Job *j) {
-        struct epoll_event ev;
+        struct epoll_event ev = {
+                .data.ptr = &j->timer_watch,
+                .events = EPOLLIN,
+        };
 
         if (j->timer_watch.type != WATCH_JOB_TIMER)
                 return 0;
 
-        zero(ev);
-        ev.data.ptr = &j->timer_watch;
-        ev.events = EPOLLIN;
-
         if (epoll_ctl(j->manager->epoll_fd, EPOLL_CTL_ADD, j->timer_watch.fd, &ev) < 0)
                 return -errno;
 
index eefb256ac5a90edfa93c32e96c7ea43877174279..d7113b9795695e6de0dc20cedd7a0691c09d8497 100644 (file)
@@ -68,11 +68,9 @@ static const char * const variable_names[_VARIABLE_MAX] = {
 };
 
 int locale_setup(void) {
-        char *variables[_VARIABLE_MAX];
+        char *variables[_VARIABLE_MAX] = {};
         int r = 0, i;
 
-        zero(variables);
-
         if (detect_container(NULL) <= 0) {
                 r = parse_env_file("/proc/cmdline", WHITESPACE,
                                    "locale.LANG",              &variables[VARIABLE_LANG],
index bfd0d93204573f463711290611d3f97a57bdc155..f98a29806e5cc377b8414df703330f261d2c725d 100644 (file)
@@ -88,25 +88,26 @@ static int add_adresses(int fd, int if_loopback, unsigned *requests) {
         union {
                 struct sockaddr sa;
                 struct sockaddr_nl nl;
-        } sa;
+        } sa = {
+                .nl.nl_family = AF_NETLINK,
+        };
+
         union {
                 struct nlmsghdr header;
                 uint8_t buf[NLMSG_ALIGN(sizeof(struct nlmsghdr)) +
                             NLMSG_ALIGN(sizeof(struct ifaddrmsg)) +
                             RTA_LENGTH(sizeof(struct in6_addr))];
-        } request;
+        } request = {
+                .header.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg)),
+                .header.nlmsg_type = RTM_NEWADDR,
+                .header.nlmsg_flags = NLM_F_REQUEST|NLM_F_CREATE|NLM_F_ACK,
+                .header.nlmsg_seq = *requests + 1,
+        };
 
         struct ifaddrmsg *ifaddrmsg;
         uint32_t ipv4_address = htonl(INADDR_LOOPBACK);
         int r;
 
-        zero(request);
-
-        request.header.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifaddrmsg));
-        request.header.nlmsg_type = RTM_NEWADDR;
-        request.header.nlmsg_flags = NLM_F_REQUEST|NLM_F_CREATE|NLM_F_ACK;
-        request.header.nlmsg_seq = *requests + 1;
-
         ifaddrmsg = NLMSG_DATA(&request.header);
         ifaddrmsg->ifa_family = AF_INET;
         ifaddrmsg->ifa_prefixlen = 8;
@@ -114,13 +115,11 @@ static int add_adresses(int fd, int if_loopback, unsigned *requests) {
         ifaddrmsg->ifa_scope = RT_SCOPE_HOST;
         ifaddrmsg->ifa_index = if_loopback;
 
-        r = add_rtattr(&request.header, sizeof(request), IFA_LOCAL, &ipv4_address, sizeof(ipv4_address));
+        r = add_rtattr(&request.header, sizeof(request), IFA_LOCAL,
+                       &ipv4_address, sizeof(ipv4_address));
         if (r < 0)
                 return r;
 
-        zero(sa);
-        sa.nl.nl_family = AF_NETLINK;
-
         if (sendto_loop(fd, &request, request.header.nlmsg_len, 0, &sa.sa, sizeof(sa)) < 0)
                 return -errno;
         (*requests)++;
@@ -134,7 +133,8 @@ static int add_adresses(int fd, int if_loopback, unsigned *requests) {
         ifaddrmsg->ifa_family = AF_INET6;
         ifaddrmsg->ifa_prefixlen = 128;
 
-        r = add_rtattr(&request.header, sizeof(request), IFA_LOCAL, &in6addr_loopback, sizeof(in6addr_loopback));
+        r = add_rtattr(&request.header, sizeof(request), IFA_LOCAL,
+                       &in6addr_loopback, sizeof(in6addr_loopback));
         if (r < 0)
                 return r;
 
@@ -149,31 +149,29 @@ static int start_interface(int fd, int if_loopback, unsigned *requests) {
         union {
                 struct sockaddr sa;
                 struct sockaddr_nl nl;
-        } sa;
+        } sa = {
+                .nl.nl_family = AF_NETLINK,
+        };
+
         union {
                 struct nlmsghdr header;
                 uint8_t buf[NLMSG_ALIGN(sizeof(struct nlmsghdr)) +
                             NLMSG_ALIGN(sizeof(struct ifinfomsg))];
-        } request;
+        } request = {
+                .header.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg)),
+                .header.nlmsg_type = RTM_NEWLINK,
+                .header.nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK,
+                .header.nlmsg_seq = *requests + 1,
+        };
 
         struct ifinfomsg *ifinfomsg;
 
-        zero(request);
-
-        request.header.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
-        request.header.nlmsg_type = RTM_NEWLINK;
-        request.header.nlmsg_flags = NLM_F_REQUEST|NLM_F_ACK;
-        request.header.nlmsg_seq = *requests + 1;
-
         ifinfomsg = NLMSG_DATA(&request.header);
         ifinfomsg->ifi_family = AF_UNSPEC;
         ifinfomsg->ifi_index = if_loopback;
         ifinfomsg->ifi_flags = IFF_UP;
         ifinfomsg->ifi_change = IFF_UP;
 
-        zero(sa);
-        sa.nl.nl_family = AF_NETLINK;
-
         if (sendto_loop(fd, &request, request.header.nlmsg_len, 0, &sa.sa, sizeof(sa)) < 0)
                 return -errno;
 
@@ -234,7 +232,10 @@ static int check_loopback(void) {
         union {
                 struct sockaddr sa;
                 struct sockaddr_in in;
-        } sa;
+        } sa = {
+                .in.sin_family = AF_INET,
+                .in.sin_addr.s_addr = INADDR_LOOPBACK,
+        };
 
         /* If we failed to set up the loop back device, check whether
          * it might already be set up */
@@ -243,10 +244,6 @@ static int check_loopback(void) {
         if (fd < 0)
                 return -errno;
 
-        zero(sa);
-        sa.in.sin_family = AF_INET;
-        sa.in.sin_addr.s_addr = INADDR_LOOPBACK;
-
         if (bind(fd, &sa.sa, sizeof(sa.in)) >= 0)
                 r = 1;
         else
@@ -260,7 +257,9 @@ int loopback_setup(void) {
         union {
                 struct sockaddr sa;
                 struct sockaddr_nl nl;
-        } sa;
+        } sa = {
+                .nl.nl_family = AF_NETLINK,
+        };
         unsigned requests = 0, i;
         int _cleanup_close_ fd = -1;
         bool eperm = false;
@@ -274,8 +273,6 @@ int loopback_setup(void) {
         if (fd < 0)
                 return -errno;
 
-        zero(sa);
-        sa.nl.nl_family = AF_NETLINK;
         if (bind(fd, &sa.sa, sizeof(sa)) < 0) {
                 r = -errno;
                 goto error;
index 92f066c7076bd0aae0b222e7ac4eacd8be7b26d6..4d21dd97a3e3873dd1d4cf431d0c8c650815a448 100644 (file)
@@ -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);
 }
index e26522a4dd0944460c9e3baca37ee05522eace40..549153e057493d2b9db7c06511f1f7bee0375c01 100644 (file)
@@ -93,12 +93,15 @@ static int manager_setup_notify(Manager *m) {
         union {
                 struct sockaddr sa;
                 struct sockaddr_un un;
-        } sa;
-        struct epoll_event ev;
+        } sa = {
+                .sa.sa_family = AF_UNIX,
+        };
+        struct epoll_event ev = {
+                .events = EPOLLIN,
+                .data.ptr = &m->notify_watch,
+        };
         int one = 1, r;
 
-        assert(m);
-
         m->notify_watch.type = WATCH_NOTIFY;
         m->notify_watch.fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
         if (m->notify_watch.fd < 0) {
@@ -106,9 +109,6 @@ static int manager_setup_notify(Manager *m) {
                 return -errno;
         }
 
-        zero(sa);
-        sa.sa.sa_family = AF_UNIX;
-
         if (getpid() != 1 || detect_container(NULL) > 0)
                 snprintf(sa.un.sun_path, sizeof(sa.un.sun_path), NOTIFY_SOCKET "/%llu", random_ull());
         else
@@ -129,10 +129,6 @@ static int manager_setup_notify(Manager *m) {
                 return -errno;
         }
 
-        zero(ev);
-        ev.events = EPOLLIN;
-        ev.data.ptr = &m->notify_watch;
-
         r = epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->notify_watch.fd, &ev);
         if (r < 0) {
                 log_error("Failed to add notification socket fd to epoll: %m");
@@ -150,16 +146,14 @@ static int manager_setup_notify(Manager *m) {
 }
 
 static int manager_jobs_in_progress_mod_timer(Manager *m) {
-        struct itimerspec its;
+        struct itimerspec its = {
+                .it_value.tv_sec = JOBS_IN_PROGRESS_WAIT_SEC,
+                .it_interval.tv_sec = JOBS_IN_PROGRESS_PERIOD_SEC,
+        };
 
         if (m->jobs_in_progress_watch.type != WATCH_JOBS_IN_PROGRESS)
                 return 0;
 
-        zero(its);
-
-        its.it_value.tv_sec = JOBS_IN_PROGRESS_WAIT_SEC;
-        its.it_interval.tv_sec = JOBS_IN_PROGRESS_PERIOD_SEC;
-
         if (timerfd_settime(m->jobs_in_progress_watch.fd, 0, &its, NULL) < 0)
                 return -errno;
 
@@ -167,11 +161,12 @@ static int manager_jobs_in_progress_mod_timer(Manager *m) {
 }
 
 static int manager_watch_jobs_in_progress(Manager *m) {
-        struct epoll_event ev;
+        struct epoll_event ev = {
+                .events = EPOLLIN,
+                .data.ptr = &m->jobs_in_progress_watch,
+        };
         int r;
 
-        assert(m);
-
         if (m->jobs_in_progress_watch.type != WATCH_INVALID)
                 return 0;
 
@@ -189,10 +184,6 @@ static int manager_watch_jobs_in_progress(Manager *m) {
                 goto err;
         }
 
-        zero(ev);
-        ev.events = EPOLLIN;
-        ev.data.ptr = &m->jobs_in_progress_watch;
-
         if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->jobs_in_progress_watch.fd, &ev) < 0) {
                 log_error("Failed to add jobs progress timer fd to epoll: %m");
                 r = -errno;
@@ -287,10 +278,18 @@ static void manager_print_jobs_in_progress(Manager *m) {
 }
 
 static int manager_setup_time_change(Manager *m) {
-        struct epoll_event ev;
-        struct itimerspec its;
+        struct epoll_event ev = {
+                .events = EPOLLIN,
+                .data.ptr = &m->time_change_watch,
+        };
+
+        /* We only care for the cancellation event, hence we set the
+         * timeout to the latest possible value. */
+        struct itimerspec its = {
+                .it_value.tv_sec = TIME_T_MAX,
+        };
+        assert_cc(sizeof(time_t) == sizeof(TIME_T_MAX));
 
-        assert(m);
         assert(m->time_change_watch.type == WATCH_INVALID);
 
         /* Uses TFD_TIMER_CANCEL_ON_SET to get notifications whenever
@@ -303,13 +302,6 @@ static int manager_setup_time_change(Manager *m) {
                 return -errno;
         }
 
-        zero(its);
-
-        /* We only care for the cancellation event, hence we set the
-         * timeout to the latest possible value. */
-        assert_cc(sizeof(time_t) == sizeof(TIME_T_MAX));
-        its.it_value.tv_sec = TIME_T_MAX;
-
         if (timerfd_settime(m->time_change_watch.fd, TFD_TIMER_ABSTIME|TFD_TIMER_CANCEL_ON_SET, &its, NULL) < 0) {
                 log_debug("Failed to set up TFD_TIMER_CANCEL_ON_SET, ignoring: %m");
                 close_nointr_nofail(m->time_change_watch.fd);
@@ -317,10 +309,6 @@ static int manager_setup_time_change(Manager *m) {
                 return 0;
         }
 
-        zero(ev);
-        ev.events = EPOLLIN;
-        ev.data.ptr = &m->time_change_watch;
-
         if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->time_change_watch.fd, &ev) < 0) {
                 log_error("Failed to add timer change fd to epoll: %m");
                 return -errno;
@@ -360,15 +348,18 @@ static int enable_special_signals(Manager *m) {
 
 static int manager_setup_signals(Manager *m) {
         sigset_t mask;
-        struct epoll_event ev;
-        struct sigaction sa;
+        struct epoll_event ev = {
+                .events = EPOLLIN,
+                .data.ptr = &m->signal_watch,
+        };
+        struct sigaction sa = {
+                .sa_handler = SIG_DFL,
+                .sa_flags = SA_NOCLDSTOP|SA_RESTART,
+        };
 
         assert(m);
 
         /* We are not interested in SIGSTOP and friends. */
-        zero(sa);
-        sa.sa_handler = SIG_DFL;
-        sa.sa_flags = SA_NOCLDSTOP|SA_RESTART;
         assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
 
         assert_se(sigemptyset(&mask) == 0);
@@ -410,10 +401,6 @@ static int manager_setup_signals(Manager *m) {
         if (m->signal_watch.fd < 0)
                 return -errno;
 
-        zero(ev);
-        ev.events = EPOLLIN;
-        ev.data.ptr = &m->signal_watch;
-
         if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->signal_watch.fd, &ev) < 0)
                 return -errno;
 
@@ -1184,30 +1171,29 @@ static int manager_process_notify_fd(Manager *m) {
 
         for (;;) {
                 char buf[4096];
-                struct msghdr msghdr;
-                struct iovec iovec;
-                struct ucred *ucred;
+                struct iovec iovec = {
+                        .iov_base = buf,
+                        .iov_len = sizeof(buf)-1,
+                };
+
                 union {
                         struct cmsghdr cmsghdr;
                         uint8_t buf[CMSG_SPACE(sizeof(struct ucred))];
-                } control;
+                } control = {};
+
+                struct msghdr msghdr = {
+                        .msg_iov = &iovec,
+                        .msg_iovlen = 1,
+                        .msg_control = &control,
+                        .msg_controllen = sizeof(control),
+                };
+                struct ucred *ucred;
                 Unit *u;
                 char _cleanup_strv_free_ **tags = NULL;
 
-                zero(iovec);
-                iovec.iov_base = buf;
-                iovec.iov_len = sizeof(buf)-1;
-
-                zero(control);
-                zero(msghdr);
-                msghdr.msg_iov = &iovec;
-                msghdr.msg_iovlen = 1;
-                msghdr.msg_control = &control;
-                msghdr.msg_controllen = sizeof(control);
-
                 n = recvmsg(m->notify_watch.fd, &msghdr, MSG_DONTWAIT);
                 if (n <= 0) {
-                        if (n >= 0)
+                        if (n == 0)
                                 return -EIO;
 
                         if (errno == EAGAIN || errno == EINTR)
@@ -1254,12 +1240,10 @@ static int manager_dispatch_sigchld(Manager *m) {
         assert(m);
 
         for (;;) {
-                siginfo_t si;
+                siginfo_t si = {};
                 Unit *u;
                 int r;
 
-                zero(si);
-
                 /* First we call waitd() for a PID and do not reap the
                  * zombie. That way we can still access /proc/$PID for
                  * it while it is a zombie. */
index 51a81a948870529d520e761f55456794800436c2..4f245555f225b15ac321292c774d8eb2b631fbbb 100644 (file)
@@ -293,7 +293,7 @@ static int mount_add_requires_mounts_links(Mount *m) {
 }
 
 static char* mount_test_option(const char *haystack, const char *needle) {
-        struct mntent me;
+        struct mntent me = { .mnt_opts = (char*) haystack };
 
         assert(needle);
 
@@ -303,9 +303,6 @@ static char* mount_test_option(const char *haystack, const char *needle) {
         if (!haystack)
                 return NULL;
 
-        zero(me);
-        me.mnt_opts = (char*) haystack;
-
         return hasmntopt(&me, needle);
 }
 
@@ -1706,10 +1703,14 @@ static void mount_shutdown(Manager *m) {
 
 static int mount_enumerate(Manager *m) {
         int r;
-        struct epoll_event ev;
         assert(m);
 
         if (!m->proc_self_mountinfo) {
+                struct epoll_event ev = {
+                        .events = EPOLLPRI,
+                        .data.ptr = &m->mount_watch,
+                };
+
                 m->proc_self_mountinfo = fopen("/proc/self/mountinfo", "re");
                 if (!m->proc_self_mountinfo)
                         return -errno;
@@ -1717,10 +1718,6 @@ static int mount_enumerate(Manager *m) {
                 m->mount_watch.type = WATCH_MOUNT;
                 m->mount_watch.fd = fileno(m->proc_self_mountinfo);
 
-                zero(ev);
-                ev.events = EPOLLPRI;
-                ev.data.ptr = &m->mount_watch;
-
                 if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->mount_watch.fd, &ev) < 0)
                         return -errno;
         }
index 98266a5a9034699a8071226cc2f4ab3e5346813a..a104b300c3724994bf3c5a9df6d832617fc2322b 100644 (file)
@@ -3446,7 +3446,7 @@ static int service_enumerate(Manager *m) {
         unsigned i;
         DIR _cleanup_closedir_ *d = NULL;
         char _cleanup_free_ *path = NULL, *fpath = NULL, *name = NULL;
-        Set *runlevel_services[ELEMENTSOF(rcnd_table)];
+        Set *runlevel_services[ELEMENTSOF(rcnd_table)] = {};
         Set _cleanup_set_free_ *shutdown_services = NULL;
         Unit *service;
         Iterator j;
@@ -3457,8 +3457,6 @@ static int service_enumerate(Manager *m) {
         if (m->running_as != SYSTEMD_SYSTEM)
                 return 0;
 
-        zero(runlevel_services);
-
         STRV_FOREACH(p, m->lookup_paths.sysvrcnd_path)
                 for (i = 0; i < ELEMENTSOF(rcnd_table); i ++) {
                         struct dirent *de;
index dc98f473871114cac7e5b558bc4111e988910c66..b363c5ec092b2814dfbfbbc91f4445eb967499c2 100644 (file)
@@ -1242,10 +1242,14 @@ static void swap_shutdown(Manager *m) {
 
 static int swap_enumerate(Manager *m) {
         int r;
-        struct epoll_event ev;
         assert(m);
 
         if (!m->proc_swaps) {
+                struct epoll_event ev = {
+                        .events = EPOLLPRI,
+                        .data.ptr = &m->swap_watch,
+                };
+
                 m->proc_swaps = fopen("/proc/swaps", "re");
                 if (!m->proc_swaps)
                         return (errno == ENOENT) ? 0 : -errno;
@@ -1253,10 +1257,6 @@ static int swap_enumerate(Manager *m) {
                 m->swap_watch.type = WATCH_SWAP;
                 m->swap_watch.fd = fileno(m->proc_swaps);
 
-                zero(ev);
-                ev.events = EPOLLPRI;
-                ev.data.ptr = &m->swap_watch;
-
                 if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->swap_watch.fd, &ev) < 0)
                         return -errno;
         }
index 95e47e3c5ac4a9a084dbb7621f7e2b84c7ce1f7d..8c69e74caf06d42c5d7a9caf37bf3c50fc6b1f84 100644 (file)
@@ -381,7 +381,13 @@ static int delete_loopback(const char *device) {
 static int delete_dm(dev_t devnum) {
         int _cleanup_close_ fd = -1;
         int r;
-        struct dm_ioctl dm;
+        struct dm_ioctl dm = {
+                .version = {DM_VERSION_MAJOR,
+                            DM_VERSION_MINOR,
+                            DM_VERSION_PATCHLEVEL},
+                .data_size = sizeof(dm),
+                .dev = devnum,
+        };
 
         assert(major(devnum) != 0);
 
@@ -389,14 +395,6 @@ static int delete_dm(dev_t devnum) {
         if (fd < 0)
                 return -errno;
 
-        zero(dm);
-        dm.version[0] = DM_VERSION_MAJOR;
-        dm.version[1] = DM_VERSION_MINOR;
-        dm.version[2] = DM_VERSION_PATCHLEVEL;
-
-        dm.data_size = sizeof(dm);
-        dm.dev = devnum;
-
         r = ioctl(fd, DM_DEV_REMOVE, &dm);
         return r >= 0 ? 0 : -errno;
 }
index dbb188296546489a221cc59ac1ea031d9686278c..63e42b23307d97fe68dc5276c04e4a1aa99bd0fb 100644 (file)
@@ -1520,17 +1520,16 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
 }
 
 int unit_watch_fd(Unit *u, int fd, uint32_t events, Watch *w) {
-        struct epoll_event ev;
+        struct epoll_event ev = {
+                .data.ptr = w,
+                .events = events,
+        };
 
         assert(u);
         assert(fd >= 0);
         assert(w);
         assert(w->type == WATCH_INVALID || (w->type == WATCH_FD && w->fd == fd && w->data.unit == u));
 
-        zero(ev);
-        ev.data.ptr = w;
-        ev.events = events;
-
         if (epoll_ctl(u->manager->epoll_fd,
                       w->type == WATCH_INVALID ? EPOLL_CTL_ADD : EPOLL_CTL_MOD,
                       fd,
@@ -1578,7 +1577,7 @@ void unit_unwatch_pid(Unit *u, pid_t pid) {
 }
 
 int unit_watch_timer(Unit *u, clockid_t clock_id, bool relative, usec_t usec, Watch *w) {
-        struct itimerspec its;
+        struct itimerspec its = {};
         int flags, fd;
         bool ours;
 
@@ -1603,8 +1602,6 @@ int unit_watch_timer(Unit *u, clockid_t clock_id, bool relative, usec_t usec, Wa
         } else
                 assert_not_reached("Invalid watch type");
 
-        zero(its);
-
         if (usec <= 0) {
                 /* Set absolute time in the past, but not 0, since we
                  * don't want to disarm the timer */
@@ -1622,11 +1619,10 @@ int unit_watch_timer(Unit *u, clockid_t clock_id, bool relative, usec_t usec, Wa
                 goto fail;
 
         if (w->type == WATCH_INVALID) {
-                struct epoll_event ev;
-
-                zero(ev);
-                ev.data.ptr = w;
-                ev.events = EPOLLIN;
+                struct epoll_event ev = {
+                        .data.ptr = w,
+                        .events = EPOLLIN,
+                };
 
                 if (epoll_ctl(u->manager->epoll_fd, EPOLL_CTL_ADD, fd, &ev) < 0)
                         goto fail;
index 51d4f99edc0bd513683051bb801cdaa3fcdc67c8..ae4aa8dba303335ceefaa03f4f8d44c473b3cbf2 100644 (file)
@@ -461,10 +461,7 @@ int main(int argc, char *argv[]) {
                                 k = crypt_load(cd, CRYPT_LUKS1, NULL);
 
                         if ((!opt_type && k < 0) || streq_ptr(opt_type, CRYPT_PLAIN)) {
-                                struct crypt_params_plain params;
-
-                                zero(params);
-                                params.hash = hash;
+                                struct crypt_params_plain params = { .hash = hash };
 
                                 /* for CRYPT_PLAIN limit reads
                                 * from keyfile to key length, and
index 917fac2466c940461f42ca6a3719b14a46838999..1c9043534a316c5a5afff4172cfbada675f7aa3b 100644 (file)
@@ -152,7 +152,7 @@ static int show_status(DBusConnection *bus, char **args, unsigned n) {
         const char *interface = "";
         int r;
         DBusMessageIter iter, sub, sub2, sub3;
-        StatusInfo info;
+        StatusInfo info = {};
 
         assert(args);
 
@@ -176,7 +176,6 @@ static int show_status(DBusConnection *bus, char **args, unsigned n) {
                 return -EIO;
         }
 
-        zero(info);
         dbus_message_iter_recurse(&iter, &sub);
 
         while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
index a9d7aa181d252887b4eee3d6a61203946cf54429..9a96689ee702b28ddace251bb82413c955bdf36b 100644 (file)
@@ -719,7 +719,7 @@ void server_driver_message(Server *s, sd_id128_t message_id, const char *format,
         struct iovec iovec[N_IOVEC_META_FIELDS + 4];
         int n = 0;
         va_list ap;
-        struct ucred ucred;
+        struct ucred ucred = {};
 
         assert(s);
         assert(format);
@@ -740,7 +740,6 @@ void server_driver_message(Server *s, sd_id128_t message_id, const char *format,
                 IOVEC_SET_STRING(iovec[n++], mid);
         }
 
-        zero(ucred);
         ucred.pid = getpid();
         ucred.uid = getuid();
         ucred.gid = getgid();
@@ -1356,17 +1355,16 @@ static int server_open_sync_timer(Server *s) {
 int server_schedule_sync(Server *s) {
         int r;
 
-        struct itimerspec sync_timer_enable;
-
         assert(s);
 
         if (s->sync_scheduled)
                 return 0;
 
         if (s->sync_interval_usec) {
-                zero(sync_timer_enable);
-                sync_timer_enable.it_value.tv_sec = s->sync_interval_usec / USEC_PER_SEC;
-                sync_timer_enable.it_value.tv_nsec = s->sync_interval_usec % MSEC_PER_SEC;
+                struct itimerspec sync_timer_enable = {
+                        .it_value.tv_sec = s->sync_interval_usec / USEC_PER_SEC,
+                        .it_value.tv_nsec = s->sync_interval_usec % MSEC_PER_SEC,
+                };
 
                 r = timerfd_settime(s->sync_timer_fd, 0, &sync_timer_enable, NULL);
                 if (r < 0)
index bdc2f49ef4eae71ca461add529af82b1bde7892f..6d51c29083505ef0c0486972b2a04faaee7eef3d 100644 (file)
@@ -412,13 +412,16 @@ fail:
 }
 
 int server_open_stdout_socket(Server *s) {
-        union sockaddr_union sa;
         int r;
         struct epoll_event ev;
 
         assert(s);
 
         if (s->stdout_fd < 0) {
+                union sockaddr_union sa = {
+                        .un.sun_family = AF_UNIX,
+                        .un.sun_path = "/run/systemd/journal/stdout",
+                };
 
                 s->stdout_fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
                 if (s->stdout_fd < 0) {
@@ -426,10 +429,6 @@ int server_open_stdout_socket(Server *s) {
                         return -errno;
                 }
 
-                zero(sa);
-                sa.un.sun_family = AF_UNIX;
-                strncpy(sa.un.sun_path, "/run/systemd/journal/stdout", sizeof(sa.un.sun_path));
-
                 unlink(sa.un.sun_path);
 
                 r = bind(s->stdout_fd, &sa.sa, offsetof(union sockaddr_union, un.sun_path) + strlen(sa.un.sun_path));
index afddca3630097162bc7c6677efaa3b309f1d263b..000f5acc100b8637c6d74de0578462ad65abebf5 100644 (file)
 #define WARN_FORWARD_SYSLOG_MISSED_USEC (30 * USEC_PER_SEC)
 
 static void forward_syslog_iovec(Server *s, const struct iovec *iovec, unsigned n_iovec, struct ucred *ucred, struct timeval *tv) {
-        struct msghdr msghdr;
+
+        union sockaddr_union sa = {
+                .un.sun_family = AF_UNIX,
+                .un.sun_path = "/run/systemd/journal/syslog",
+        };
+        struct msghdr msghdr = {
+                .msg_iov = (struct iovec *) iovec,
+                .msg_iovlen = n_iovec,
+                .msg_name = &sa,
+                .msg_namelen = offsetof(union sockaddr_union, un.sun_path)
+                               + sizeof("/run/systemd/journal/syslog") - 1,
+        };
         struct cmsghdr *cmsg;
         union {
                 struct cmsghdr cmsghdr;
                 uint8_t buf[CMSG_SPACE(sizeof(struct ucred))];
         } control;
-        union sockaddr_union sa;
 
         assert(s);
         assert(iovec);
         assert(n_iovec > 0);
 
-        zero(msghdr);
-        msghdr.msg_iov = (struct iovec*) iovec;
-        msghdr.msg_iovlen = n_iovec;
-
-        zero(sa);
-        sa.un.sun_family = AF_UNIX;
-        strncpy(sa.un.sun_path, "/run/systemd/journal/syslog", sizeof(sa.un.sun_path));
-        msghdr.msg_name = &sa;
-        msghdr.msg_namelen = offsetof(union sockaddr_union, un.sun_path) + strlen(sa.un.sun_path);
-
         if (ucred) {
                 zero(control);
                 msghdr.msg_control = &control;
@@ -412,13 +412,16 @@ void server_process_syslog_message(
 }
 
 int server_open_syslog_socket(Server *s) {
-        union sockaddr_union sa;
         int one, r;
         struct epoll_event ev;
 
         assert(s);
 
         if (s->syslog_fd < 0) {
+                union sockaddr_union sa = {
+                        .un.sun_family = AF_UNIX,
+                        .un.sun_path = "/dev/log",
+                };
 
                 s->syslog_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
                 if (s->syslog_fd < 0) {
@@ -426,10 +429,6 @@ int server_open_syslog_socket(Server *s) {
                         return -errno;
                 }
 
-                zero(sa);
-                sa.un.sun_family = AF_UNIX;
-                strncpy(sa.un.sun_path, "/dev/log", sizeof(sa.un.sun_path));
-
                 unlink(sa.un.sun_path);
 
                 r = bind(s->syslog_fd, &sa.sa, offsetof(union sockaddr_union, un.sun_path) + strlen(sa.un.sun_path));
index c68c7bca682791625b4adf05a50833fb75ad0f49..145f454d5d3cdcbe5d3c4e0eb7c556f8fa6a1a2a 100644 (file)
@@ -986,16 +986,14 @@ int bus_socket_read_message(sd_bus *bus, sd_bus_message **m) {
 int bus_socket_process_opening(sd_bus *b) {
         int error = 0;
         socklen_t slen = sizeof(error);
-        struct pollfd p;
+        struct pollfd p = {
+                .fd = b->output_fd,
+                .events = POLLOUT,
+        };
         int r;
 
-        assert(b);
         assert(b->state == BUS_OPENING);
 
-        zero(p);
-        p.fd = b->output_fd;
-        p.events = POLLOUT;
-
         r = poll(&p, 1, 0);
         if (r < 0)
                 return -errno;
index 6f8d444a660e1b0a401d550a96a2c5cae59220f8..2f084c26b3c073bf388509fbeb7ecf21054e4ef4 100644 (file)
@@ -436,8 +436,11 @@ static int parse_unix_address(sd_bus *b, const char **p, char **guid) {
 
 static int parse_tcp_address(sd_bus *b, const char **p, char **guid) {
         _cleanup_free_ char *host = NULL, *port = NULL, *family = NULL;
-        struct addrinfo hints, *result;
         int r;
+        struct addrinfo *result, hints = {
+                .ai_socktype = SOCK_STREAM,
+                .ai_flags = AI_ADDRCONFIG,
+        };
 
         assert(b);
         assert(p);
@@ -475,10 +478,6 @@ static int parse_tcp_address(sd_bus *b, const char **p, char **guid) {
         if (!host || !port)
                 return -EINVAL;
 
-        zero(hints);
-        hints.ai_socktype = SOCK_STREAM;
-        hints.ai_flags = AI_ADDRCONFIG;
-
         if (family) {
                 if (streq(family, "ipv4"))
                         hints.ai_family = AF_INET;
@@ -1937,7 +1936,7 @@ int sd_bus_process(sd_bus *bus, sd_bus_message **ret) {
 }
 
 static int bus_poll(sd_bus *bus, bool need_more, uint64_t timeout_usec) {
-        struct pollfd p[2];
+        struct pollfd p[2] = {};
         int r, e, n;
         struct timespec ts;
         usec_t until, m;
@@ -1968,9 +1967,7 @@ static int bus_poll(sd_bus *bus, bool need_more, uint64_t timeout_usec) {
         if (timeout_usec != (uint64_t) -1 && (m == (uint64_t) -1 || timeout_usec < m))
                 m = timeout_usec;
 
-        zero(p);
         p[0].fd = bus->input_fd;
-
         if (bus->output_fd == bus->input_fd) {
                 p[0].events = e;
                 n = 1;
index 5739a1dcdd1b79967c8d97ae37b715648457939c..5328ac41a5b704d289d40da338d5a81d35307602 100644 (file)
@@ -158,7 +158,7 @@ static int show_status(DBusConnection *bus, char **args, unsigned n) {
         const char *interface = "";
         int r;
         DBusMessageIter iter, sub, sub2, sub3;
-        StatusInfo info;
+        StatusInfo info = {};
 
         assert(args);
 
@@ -182,7 +182,6 @@ static int show_status(DBusConnection *bus, char **args, unsigned n) {
                 return -EIO;
         }
 
-        zero(info);
         dbus_message_iter_recurse(&iter, &sub);
 
         while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
index df812ee651ea1f71a36c3ecb48c85058665f94ce..23fbde0df13a84916c4994fa677509c61b16f9cd 100644 (file)
@@ -1011,7 +1011,7 @@ static DBusHandlerResult locale_message_handler(
                 dbus_bool_t interactive;
                 DBusMessageIter iter;
                 bool modified = false;
-                bool passed[_PROP_MAX];
+                bool passed[_PROP_MAX] = {};
                 int p;
 
                 if (!dbus_message_iter_init(message, &iter))
@@ -1033,8 +1033,6 @@ static DBusHandlerResult locale_message_handler(
 
                 dbus_message_iter_get_basic(&iter, &interactive);
 
-                zero(passed);
-
                 /* Check whether a variable changed and if so valid */
                 STRV_FOREACH(i, l) {
                         bool valid = false;
index 6c229c64e31cf646bcc32c4e8976dfeea00bdc29..36c65bc8d0769b087fd0b3bc2da738d1bbca3617 100644 (file)
@@ -834,17 +834,13 @@ static int show_one(const char *verb, DBusConnection *bus, const char *path, boo
         const char *interface = "";
         int r;
         DBusMessageIter iter, sub, sub2, sub3;
-        SessionStatusInfo session_info;
-        UserStatusInfo user_info;
-        SeatStatusInfo seat_info;
+        SessionStatusInfo session_info = {};
+        UserStatusInfo user_info = {};
+        SeatStatusInfo seat_info = {};
 
         assert(path);
         assert(new_line);
 
-        zero(session_info);
-        zero(user_info);
-        zero(seat_info);
-
         r = bus_method_call_with_reply(
                         bus,
                         "org.freedesktop.login1",
index c43ae23acf6adf8d76b4ccf4bbe1b0510c9352ee..e77088364aa5cb352cea667610879782030543d4 100644 (file)
@@ -292,7 +292,7 @@ int inhibitor_create_fifo(Inhibitor *i) {
 
         /* Open reading side */
         if (i->fifo_fd < 0) {
-                struct epoll_event ev;
+                struct epoll_event ev = {};
 
                 i->fifo_fd = open(i->fifo_path, O_RDONLY|O_CLOEXEC|O_NDELAY);
                 if (i->fifo_fd < 0)
@@ -302,7 +302,6 @@ int inhibitor_create_fifo(Inhibitor *i) {
                 if (r < 0)
                         return r;
 
-                zero(ev);
                 ev.events = 0;
                 ev.data.u32 = FD_OTHER_BASE + i->fifo_fd;
 
index 71c79127e9a57c96b0441445fb9952923a5e200d..97c24d094b66ef2ee97b5c9861c38c2a14848564 100644 (file)
@@ -898,7 +898,7 @@ int session_create_fifo(Session *s) {
 
         /* Open reading side */
         if (s->fifo_fd < 0) {
-                struct epoll_event ev;
+                struct epoll_event ev = {};
 
                 s->fifo_fd = open(s->fifo_path, O_RDONLY|O_CLOEXEC|O_NDELAY);
                 if (s->fifo_fd < 0)
@@ -908,7 +908,6 @@ int session_create_fifo(Session *s) {
                 if (r < 0)
                         return r;
 
-                zero(ev);
                 ev.events = 0;
                 ev.data.u32 = FD_OTHER_BASE + s->fifo_fd;
 
index f72aac5e61941bb49ea8e98a2f1d3cec99a578a4..c9e492fc4f5276757df60b5ef071d0fa79aff2af 100644 (file)
@@ -1174,7 +1174,10 @@ static void manager_dispatch_other(Manager *m, int fd) {
 static int manager_connect_bus(Manager *m) {
         DBusError error;
         int r;
-        struct epoll_event ev;
+        struct epoll_event ev = {
+                .events = EPOLLIN,
+                .data.u32 = FD_BUS,
+        };
 
         assert(m);
         assert(!m->bus);
@@ -1230,10 +1233,6 @@ static int manager_connect_bus(Manager *m) {
                 goto fail;
         }
 
-        zero(ev);
-        ev.events = EPOLLIN;
-        ev.data.u32 = FD_BUS;
-
         if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->bus_fd, &ev) < 0)
                 goto fail;
 
@@ -1246,7 +1245,10 @@ fail:
 }
 
 static int manager_connect_console(Manager *m) {
-        struct epoll_event ev;
+        struct epoll_event ev = {
+                .events = 0,
+                .data.u32 = FD_CONSOLE,
+        };
 
         assert(m);
         assert(m->console_active_fd < 0);
@@ -1271,10 +1273,6 @@ static int manager_connect_console(Manager *m) {
                 return -errno;
         }
 
-        zero(ev);
-        ev.events = 0;
-        ev.data.u32 = FD_CONSOLE;
-
         if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->console_active_fd, &ev) < 0)
                 return -errno;
 
@@ -1282,8 +1280,11 @@ static int manager_connect_console(Manager *m) {
 }
 
 static int manager_connect_udev(Manager *m) {
-        struct epoll_event ev;
         int r;
+        struct epoll_event ev = {
+                .events = EPOLLIN,
+                .data.u32 = FD_SEAT_UDEV,
+        };
 
         assert(m);
         assert(!m->udev_seat_monitor);
@@ -1304,9 +1305,6 @@ static int manager_connect_udev(Manager *m) {
 
         m->udev_seat_fd = udev_monitor_get_fd(m->udev_seat_monitor);
 
-        zero(ev);
-        ev.events = EPOLLIN;
-        ev.data.u32 = FD_SEAT_UDEV;
         if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->udev_seat_fd, &ev) < 0)
                 return -errno;
 
@@ -1447,7 +1445,7 @@ int manager_get_idle_hint(Manager *m, dual_timestamp *t) {
 
 int manager_dispatch_idle_action(Manager *m) {
         struct dual_timestamp since;
-        struct itimerspec its;
+        struct itimerspec its = {};
         int r;
         usec_t n;
 
@@ -1459,7 +1457,6 @@ int manager_dispatch_idle_action(Manager *m) {
                 goto finish;
         }
 
-        zero(its);
         n = now(CLOCK_MONOTONIC);
 
         r = manager_get_idle_hint(m, &since);
@@ -1482,7 +1479,10 @@ int manager_dispatch_idle_action(Manager *m) {
         }
 
         if (m->idle_action_fd < 0) {
-                struct epoll_event ev;
+                struct epoll_event ev = {
+                        .events = EPOLLIN,
+                        .data.u32 = FD_IDLE_ACTION,
+                };
 
                 m->idle_action_fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK|TFD_CLOEXEC);
                 if (m->idle_action_fd < 0) {
@@ -1491,10 +1491,6 @@ int manager_dispatch_idle_action(Manager *m) {
                         goto finish;
                 }
 
-                zero(ev);
-                ev.events = EPOLLIN;
-                ev.data.u32 = FD_IDLE_ACTION;
-
                 if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->idle_action_fd, &ev) < 0) {
                         log_error("Failed to add idle action timer to epoll: %m");
                         r = -errno;
index 0d4f7991e7a6617b247497744788156f62366ad8..c8f4dae77e1c9f25b46e2d86ad70a373091653bd 100644 (file)
@@ -256,13 +256,15 @@ static bool check_user_lists(
 }
 
 static int get_seat_from_display(const char *display, const char **seat, uint32_t *vtnr) {
-        char *p = NULL;
+        char _cleanup_free_ *p = NULL;
         int r;
-        int fd;
-        union sockaddr_union sa;
+        int _cleanup_close_ fd = -1;
+        union sockaddr_union sa = {
+                .un.sun_family = AF_UNIX,
+        };
         struct ucred ucred;
         socklen_t l;
-        char *tty;
+        char _cleanup_free_ *tty = NULL;
         int v;
 
         assert(display);
@@ -277,27 +279,17 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_
         r = socket_from_display(display, &p);
         if (r < 0)
                 return r;
+        strncpy(sa.un.sun_path, p, sizeof(sa.un.sun_path)-1);
 
         fd = socket(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC, 0);
-        if (fd < 0) {
-                free(p);
+        if (fd < 0)
                 return -errno;
-        }
-
-        zero(sa);
-        sa.un.sun_family = AF_UNIX;
-        strncpy(sa.un.sun_path, p, sizeof(sa.un.sun_path)-1);
-        free(p);
 
-        if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path)) < 0) {
-                close_nointr_nofail(fd);
+        if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path)) < 0)
                 return -errno;
-        }
 
         l = sizeof(ucred);
         r = getsockopt(fd, SOL_SOCKET, SO_PEERCRED, &ucred, &l);
-        close_nointr_nofail(fd);
-
         if (r < 0)
                 return -errno;
 
@@ -306,8 +298,6 @@ static int get_seat_from_display(const char *display, const char **seat, uint32_
                 return r;
 
         v = vtnr_from_tty(tty);
-        free(tty);
-
         if (v < 0)
                 return v;
         else if (v == 0)
index 01ef12bf67bbbf0dda4095bad7d2bb037988dd15..b90ccc53ef51fae8d4ffaf29cb7ce6463761a789 100644 (file)
@@ -674,8 +674,11 @@ static int setup_kmsg(const char *dest, int kmsg_socket) {
         union {
                 struct cmsghdr cmsghdr;
                 uint8_t buf[CMSG_SPACE(sizeof(int))];
-        } control;
-        struct msghdr mh;
+        } control = {};
+        struct msghdr mh = {
+                .msg_control = &control,
+                .msg_controllen = sizeof(control),
+        };
         struct cmsghdr *cmsg;
 
         assert(dest);
@@ -716,12 +719,6 @@ static int setup_kmsg(const char *dest, int kmsg_socket) {
                 return -errno;
         }
 
-        zero(mh);
-        zero(control);
-
-        mh.msg_control = &control;
-        mh.msg_controllen = sizeof(control);
-
         cmsg = CMSG_FIRSTHDR(&mh);
         cmsg->cmsg_level = SOL_SOCKET;
         cmsg->cmsg_type = SCM_RIGHTS;
index d1188a147a52df7de9bb12642ed74d77caf500e6..a49527fe4808fa07b7224792f216118b768e583e 100644 (file)
@@ -64,7 +64,7 @@ PyDoc_STRVAR(MonotonicType__doc__,
 static PyStructSequence_Field MonotonicType_fields[] = {
     {(char*) "timestamp", (char*) "Time"},
     {(char*) "bootid", (char*) "Unique identifier of the boot"},
-    {NULL, NULL}
+    {} /* Sentinel */
 };
 
 static PyStructSequence_Desc Monotonic_desc = {
@@ -898,7 +898,7 @@ static PyGetSetDef Reader_getsetters[] = {
      NULL,
      (char*) closed__doc__,
      NULL},
-    {NULL}
+    {} /* Sentinel */
 };
 
 static PyMethodDef Reader_methods[] = {
@@ -927,7 +927,7 @@ static PyMethodDef Reader_methods[] = {
     {"test_cursor",     (PyCFunction) Reader_test_cursor, METH_VARARGS, Reader_test_cursor__doc__},
     {"query_unique",    (PyCFunction) Reader_query_unique, METH_VARARGS, Reader_query_unique__doc__},
     {"get_catalog",     (PyCFunction) Reader_get_catalog, METH_NOARGS, Reader_get_catalog__doc__},
-    {NULL}  /* Sentinel */
+    {}  /* Sentinel */
 };
 
 static PyTypeObject ReaderType = {
index b2d0f6872646adc08e92000582c9361c006ca978..03583928a01108bc32d6714e51aac9102a5f02ad 100644 (file)
@@ -75,10 +75,7 @@ static usec_t starttime;
 #define PTR_TO_SECTOR(p) (PTR_TO_ULONG(p)-1)
 
 static int btrfs_defrag(int fd) {
-        struct btrfs_ioctl_vol_args data;
-
-        zero(data);
-        data.fd = fd;
+        struct btrfs_ioctl_vol_args data = { .fd = fd };
 
         return ioctl(fd, BTRFS_IOC_DEFRAG, &data);
 }
@@ -186,11 +183,10 @@ static unsigned long fd_first_block(int fd) {
         struct {
                 struct fiemap fiemap;
                 struct fiemap_extent extent;
-        } data;
-
-        zero(data);
-        data.fiemap.fm_length = ~0ULL;
-        data.fiemap.fm_extent_count = 1;
+        } data = {
+                .fiemap.fm_length = ~0ULL,
+                .fiemap.fm_extent_count = 1,
+        };
 
         if (ioctl(fd, FS_IOC_FIEMAP, &data) < 0)
                 return 0;
@@ -238,7 +234,7 @@ static int collect(const char *root) {
                 FD_INOTIFY,   /* We get notifications to quit early via this fd */
                 _FD_MAX
         };
-        struct pollfd pollfd[_FD_MAX];
+        struct pollfd pollfd[_FD_MAX] = {};
         int fanotify_fd = -1, signal_fd = -1, inotify_fd = -1, r = 0;
         pid_t my_pid;
         Hashmap *files = NULL;
@@ -314,7 +310,6 @@ static int collect(const char *root) {
 
         my_pid = getpid();
 
-        zero(pollfd);
         pollfd[FD_FANOTIFY].fd = fanotify_fd;
         pollfd[FD_FANOTIFY].events = POLLIN;
         pollfd[FD_SIGNAL].fd = signal_fd;
index b49d095cbb402ea0fbb25909663db45058a8e09c..f432718d6b9148d615fda958a88f90f4790318c3 100644 (file)
@@ -129,10 +129,9 @@ int main(int argc, char *argv[]) {
         }
 
         while (!hashmap_isempty(pids)) {
-                siginfo_t si;
+                siginfo_t si = {};
                 char *s;
 
-                zero(si);
                 if (waitid(P_ALL, 0, &si, WEXITED) < 0) {
 
                         if (errno == EINTR)
index a935d0f08401fe9794f0870083270b5ebdd273e3..2f168985b42f620b02693810a13714a108274857 100644 (file)
@@ -41,14 +41,14 @@ static int send_on_socket(int fd, const char *socket_name, const void *packet, s
         union {
                 struct sockaddr sa;
                 struct sockaddr_un un;
-        } sa;
+        } sa = {
+                .un.sun_family = AF_UNIX,
+        };
 
         assert(fd >= 0);
         assert(socket_name);
         assert(packet);
 
-        zero(sa);
-        sa.un.sun_family = AF_UNIX;
         strncpy(sa.un.sun_path, socket_name, sizeof(sa.un.sun_path));
 
         if (sendto(fd, packet, size, MSG_NOSIGNAL, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(socket_name)) < 0) {
index 277efd302ef60e3478f5a25c54e8fd9d98189ddc..4557155d45fc36a11afbbf2b75b373112372a7eb 100644 (file)
@@ -109,7 +109,6 @@ int ask_password_tty(
         }
 
         zero(pollfd);
-
         pollfd[POLL_TTY].fd = ttyfd >= 0 ? ttyfd : STDIN_FILENO;
         pollfd[POLL_TTY].events = POLLIN;
         pollfd[POLL_INOTIFY].fd = notify;
@@ -248,7 +247,9 @@ static int create_socket(char **name) {
         union {
                 struct sockaddr sa;
                 struct sockaddr_un un;
-        } sa;
+        } sa = {
+                .un.sun_family = AF_UNIX,
+        };
         int one = 1, r;
         char *c;
 
@@ -260,8 +261,6 @@ static int create_socket(char **name) {
                 return -errno;
         }
 
-        zero(sa);
-        sa.un.sun_family = AF_UNIX;
         snprintf(sa.un.sun_path, sizeof(sa.un.sun_path)-1, "/run/systemd/ask-password/sck.%llu", random_ull());
 
         RUN_WITH_UMASK(0177) {
index fec8998bc157f91d34014a626ce8bd7ca9cb76fe..b42ae14511764222d03cee871d4f7226b8a90545 100644 (file)
@@ -45,7 +45,7 @@ typedef struct EpollData {
 
 static dbus_bool_t add_watch(DBusWatch *watch, void *data) {
         EpollData _cleanup_free_ *e = NULL;
-        struct epoll_event ev;
+        struct epoll_event ev = { .data.ptr = e };
 
         assert(watch);
 
@@ -57,9 +57,7 @@ static dbus_bool_t add_watch(DBusWatch *watch, void *data) {
         e->object = watch;
         e->is_timeout = false;
 
-        zero(ev);
         ev.events = bus_flags_to_events(watch);
-        ev.data.ptr = e;
 
         if (epoll_ctl(PTR_TO_INT(data), EPOLL_CTL_ADD, e->fd, &ev) < 0) {
 
@@ -106,7 +104,7 @@ static void remove_watch(DBusWatch *watch, void *data) {
 
 static void toggle_watch(DBusWatch *watch, void *data) {
         EpollData *e;
-        struct epoll_event ev;
+        struct epoll_event ev = {};
 
         assert(watch);
 
@@ -114,21 +112,18 @@ static void toggle_watch(DBusWatch *watch, void *data) {
         if (!e)
                 return;
 
-        zero(ev);
-        ev.events = bus_flags_to_events(watch);
         ev.data.ptr = e;
+        ev.events = bus_flags_to_events(watch);
 
         assert_se(epoll_ctl(PTR_TO_INT(data), EPOLL_CTL_MOD, e->fd, &ev) == 0);
 }
 
 static int timeout_arm(EpollData *e) {
-        struct itimerspec its;
+        struct itimerspec its = {};
 
         assert(e);
         assert(e->is_timeout);
 
-        zero(its);
-
         if (dbus_timeout_get_enabled(e->object)) {
                 timespec_store(&its.it_value, dbus_timeout_get_interval(e->object) * USEC_PER_MSEC);
                 its.it_interval = its.it_value;
@@ -142,7 +137,7 @@ static int timeout_arm(EpollData *e) {
 
 static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data) {
         EpollData *e;
-        struct epoll_event ev;
+        struct epoll_event ev = {};
 
         assert(timeout);
 
@@ -160,7 +155,6 @@ static dbus_bool_t add_timeout(DBusTimeout *timeout, void *data) {
         if (timeout_arm(e) < 0)
                 goto fail;
 
-        zero(ev);
         ev.events = EPOLLIN;
         ev.data.ptr = e;
 
@@ -227,13 +221,11 @@ int bus_loop_open(DBusConnection *c) {
 
 int bus_loop_dispatch(int fd) {
         int n;
-        struct epoll_event event;
+        struct epoll_event event = {};
         EpollData *d;
 
         assert(fd >= 0);
 
-        zero(event);
-
         n = epoll_wait(fd, &event, 1, 0);
         if (n < 0)
                 return errno == EAGAIN || errno == EINTR ? 0 : -errno;
index 2555a36c0a9226c5cfa9f95631b408b717c937df..9e870392f232c0c620b429351793ba2c2e5deb28 100644 (file)
@@ -700,7 +700,7 @@ int unit_file_link(
                 UnitFileChange **changes,
                 unsigned *n_changes) {
 
-        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
+        LookupPaths _cleanup_lookup_paths_free_ paths = {};
         char **i;
         char _cleanup_free_ *config_path = NULL;
         int r, q;
@@ -1116,7 +1116,7 @@ static int unit_file_can_install(
                 const char *name,
                 bool allow_symlink) {
 
-        InstallContext _cleanup_install_context_done_ c = {NULL};
+        InstallContext _cleanup_install_context_done_ c = {};
         InstallInfo *i;
         int r;
 
@@ -1452,8 +1452,8 @@ int unit_file_enable(
                 UnitFileChange **changes,
                 unsigned *n_changes) {
 
-        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
-        InstallContext _cleanup_install_context_done_ c = {NULL};
+        LookupPaths _cleanup_lookup_paths_free_ paths = {};
+        InstallContext _cleanup_install_context_done_ c = {};
         char **i;
         char _cleanup_free_ *config_path = NULL;
         int r;
@@ -1491,8 +1491,8 @@ int unit_file_disable(
                 UnitFileChange **changes,
                 unsigned *n_changes) {
 
-        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
-        InstallContext _cleanup_install_context_done_ c = {NULL};
+        LookupPaths _cleanup_lookup_paths_free_ paths = {};
+        InstallContext _cleanup_install_context_done_ c = {};
         char **i;
         char _cleanup_free_ *config_path = NULL;
         Set _cleanup_set_free_free_ *remove_symlinks_to = NULL;
@@ -1533,8 +1533,8 @@ int unit_file_reenable(
                 UnitFileChange **changes,
                 unsigned *n_changes) {
 
-        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
-        InstallContext _cleanup_install_context_done_ c = {NULL};
+        LookupPaths _cleanup_lookup_paths_free_ paths = {};
+        InstallContext _cleanup_install_context_done_ c = {};
         char **i;
         char _cleanup_free_ *config_path = NULL;
         Set _cleanup_set_free_free_ *remove_symlinks_to = NULL;
@@ -1576,7 +1576,7 @@ UnitFileState unit_file_get_state(
                 const char *root_dir,
                 const char *name) {
 
-        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
+        LookupPaths _cleanup_lookup_paths_free_ paths = {};
         UnitFileState state = _UNIT_FILE_STATE_INVALID;
         char **i;
         char _cleanup_free_ *path = NULL;
@@ -1734,8 +1734,8 @@ int unit_file_preset(
                 UnitFileChange **changes,
                 unsigned *n_changes) {
 
-        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
-        InstallContext _cleanup_install_context_done_ plus = {NULL}, minus = {NULL};
+        LookupPaths _cleanup_lookup_paths_free_ paths = {};
+        InstallContext _cleanup_install_context_done_ plus = {}, minus = {NULL};
         char **i;
         char _cleanup_free_ *config_path = NULL;
         Set _cleanup_set_free_free_ *remove_symlinks_to = NULL;
@@ -1800,7 +1800,7 @@ int unit_file_get_list(
                 const char *root_dir,
                 Hashmap *h) {
 
-        LookupPaths _cleanup_lookup_paths_free_ paths = {NULL};
+        LookupPaths _cleanup_lookup_paths_free_ paths = {};
         char **i;
         char _cleanup_free_ *buf = NULL;
         DIR _cleanup_closedir_ *d = NULL;
index 0dd04bc51e65e73519cbaee52ddff58e6e415fdf..876f22dfc5535af48c10255c553324dc04302f5a 100644 (file)
@@ -129,16 +129,15 @@ static int create_log_socket(int type) {
 }
 
 static int log_open_syslog(void) {
-        union sockaddr_union sa;
         int r;
+        union sockaddr_union sa = {
+                .un.sun_family = AF_UNIX,
+                .un.sun_path = "/dev/log",
+        };
 
         if (syslog_fd >= 0)
                 return 0;
 
-        zero(sa);
-        sa.un.sun_family = AF_UNIX;
-        strncpy(sa.un.sun_path, "/dev/log", sizeof(sa.un.sun_path));
-
         syslog_fd = create_log_socket(SOCK_DGRAM);
         if (syslog_fd < 0) {
                 r = syslog_fd;
@@ -183,7 +182,10 @@ void log_close_journal(void) {
 }
 
 static int log_open_journal(void) {
-        union sockaddr_union sa;
+        union sockaddr_union sa = {
+                .un.sun_family = AF_UNIX,
+                .un.sun_path = "/run/systemd/journal/socket",
+        };
         int r;
 
         if (journal_fd >= 0)
@@ -195,10 +197,6 @@ static int log_open_journal(void) {
                 goto fail;
         }
 
-        zero(sa);
-        sa.un.sun_family = AF_UNIX;
-        strncpy(sa.un.sun_path, "/run/systemd/journal/socket", sizeof(sa.un.sun_path));
-
         if (connect(journal_fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path)) < 0) {
                 r = -errno;
                 goto fail;
@@ -313,7 +311,7 @@ static int write_to_console(
                 const char *buffer) {
 
         char location[64];
-        struct iovec iovec[5];
+        struct iovec iovec[5] = {};
         unsigned n = 0;
         bool highlight;
 
@@ -322,8 +320,6 @@ static int write_to_console(
 
         highlight = LOG_PRI(level) <= LOG_ERR && show_color;
 
-        zero(iovec);
-
         if (show_location) {
                 snprintf(location, sizeof(location), "(%s:%u) ", file, line);
                 char_array_0(location);
@@ -353,8 +349,11 @@ static int write_to_syslog(
         const char *buffer) {
 
         char header_priority[16], header_time[64], header_pid[16];
-        struct iovec iovec[5];
-        struct msghdr msghdr;
+        struct iovec iovec[5] = {};
+        struct msghdr msghdr = {
+                .msg_iov = iovec,
+                .msg_iovlen = ELEMENTSOF(iovec),
+        };
         time_t t;
         struct tm *tm;
 
@@ -375,7 +374,6 @@ static int write_to_syslog(
         snprintf(header_pid, sizeof(header_pid), "[%lu]: ", (unsigned long) getpid());
         char_array_0(header_pid);
 
-        zero(iovec);
         IOVEC_SET_STRING(iovec[0], header_priority);
         IOVEC_SET_STRING(iovec[1], header_time);
         IOVEC_SET_STRING(iovec[2], program_invocation_short_name);
@@ -386,10 +384,6 @@ static int write_to_syslog(
         if (syslog_is_stream)
                 iovec[4].iov_len++;
 
-        zero(msghdr);
-        msghdr.msg_iov = iovec;
-        msghdr.msg_iovlen = ELEMENTSOF(iovec);
-
         for (;;) {
                 ssize_t n;
 
@@ -417,7 +411,7 @@ static int write_to_kmsg(
         const char *buffer) {
 
         char header_priority[16], header_pid[16];
-        struct iovec iovec[5];
+        struct iovec iovec[5] = {};
 
         if (kmsg_fd < 0)
                 return 0;
@@ -428,7 +422,6 @@ static int write_to_kmsg(
         snprintf(header_pid, sizeof(header_pid), "[%lu]: ", (unsigned long) getpid());
         char_array_0(header_pid);
 
-        zero(iovec);
         IOVEC_SET_STRING(iovec[0], header_priority);
         IOVEC_SET_STRING(iovec[1], program_invocation_short_name);
         IOVEC_SET_STRING(iovec[2], header_pid);
@@ -482,8 +475,8 @@ static int write_to_journal(
         const char *buffer) {
 
         char header[LINE_MAX];
-        struct iovec iovec[4] = {{0}};
-        struct msghdr mh = {0};
+        struct iovec iovec[4] = {};
+        struct msghdr mh = {};
 
         if (journal_fd < 0)
                 return 0;
@@ -742,7 +735,7 @@ int log_struct_internal(
             journal_fd >= 0) {
 
                 char header[LINE_MAX];
-                struct iovec iovec[17] = {{0}};
+                struct iovec iovec[17] = {};
                 unsigned n = 0, i;
                 struct msghdr mh;
                 static const char nl = '\n';
index 1bffd84d1fa71610df46a445f405581241d8d271..2f66597de30c71e1ffda578a83a7cf1e98ef7c99 100644 (file)
@@ -889,15 +889,14 @@ int reset_all_signal_handlers(void) {
         int sig;
 
         for (sig = 1; sig < _NSIG; sig++) {
-                struct sigaction sa;
+                struct sigaction sa = {
+                        .sa_handler = SIG_DFL,
+                        .sa_flags = SA_RESTART,
+                };
 
                 if (sig == SIGKILL || sig == SIGSTOP)
                         continue;
 
-                zero(sa);
-                sa.sa_handler = SIG_DFL;
-                sa.sa_flags = SA_RESTART;
-
                 /* On Linux the first two RT signals are reserved by
                  * glibc, and sigaction() will return EINVAL for them. */
                 if ((sigaction(sig, &sa, NULL) < 0))
@@ -1858,11 +1857,10 @@ int open_terminal(const char *name, int mode) {
 }
 
 int flush_fd(int fd) {
-        struct pollfd pollfd;
-
-        zero(pollfd);
-        pollfd.fd = fd;
-        pollfd.events = POLLIN;
+        struct pollfd pollfd = {
+                .fd = fd,
+                .events = POLLIN,
+        };
 
         for (;;) {
                 char buf[LINE_MAX];
@@ -1903,7 +1901,6 @@ int acquire_terminal(
 
         int fd = -1, notify = -1, r = 0, wd = -1;
         usec_t ts = 0;
-        struct sigaction sa_old, sa_new;
 
         assert(name);
 
@@ -1938,6 +1935,11 @@ int acquire_terminal(
         }
 
         for (;;) {
+                struct sigaction sa_old, sa_new = {
+                        .sa_handler = SIG_IGN,
+                        .sa_flags = SA_RESTART,
+                };
+
                 if (notify >= 0) {
                         r = flush_fd(notify);
                         if (r < 0)
@@ -1953,9 +1955,6 @@ int acquire_terminal(
 
                 /* Temporarily ignore SIGHUP, so that we don't get SIGHUP'ed
                  * if we already own the tty. */
-                zero(sa_new);
-                sa_new.sa_handler = SIG_IGN;
-                sa_new.sa_flags = SA_RESTART;
                 assert_se(sigaction(SIGHUP, &sa_new, &sa_old) == 0);
 
                 /* First, try to get the tty */
@@ -2063,7 +2062,10 @@ fail:
 
 int release_terminal(void) {
         int r = 0;
-        struct sigaction sa_old, sa_new;
+        struct sigaction sa_old, sa_new = {
+                .sa_handler = SIG_IGN,
+                .sa_flags = SA_RESTART,
+        };
         int _cleanup_close_ fd;
 
         fd = open("/dev/tty", O_RDWR|O_NOCTTY|O_NDELAY|O_CLOEXEC);
@@ -2072,10 +2074,6 @@ int release_terminal(void) {
 
         /* Temporarily ignore SIGHUP, so that we don't get SIGHUP'ed
          * by our own TIOCNOTTY */
-
-        zero(sa_new);
-        sa_new.sa_handler = SIG_IGN;
-        sa_new.sa_flags = SA_RESTART;
         assert_se(sigaction(SIGHUP, &sa_new, &sa_old) == 0);
 
         if (ioctl(fd, TIOCNOTTY) < 0)
@@ -2100,13 +2098,13 @@ int sigaction_many(const struct sigaction *sa, ...) {
 }
 
 int ignore_signals(int sig, ...) {
-        struct sigaction sa;
+        struct sigaction sa = {
+                .sa_handler = SIG_IGN,
+                .sa_flags = SA_RESTART,
+        };
         va_list ap;
         int r = 0;
 
-        zero(sa);
-        sa.sa_handler = SIG_IGN;
-        sa.sa_flags = SA_RESTART;
 
         if (sigaction(sig, &sa, NULL) < 0)
                 r = -errno;
@@ -2121,14 +2119,13 @@ int ignore_signals(int sig, ...) {
 }
 
 int default_signals(int sig, ...) {
-        struct sigaction sa;
+        struct sigaction sa = {
+                .sa_handler = SIG_DFL,
+                .sa_flags = SA_RESTART,
+        };
         va_list ap;
         int r = 0;
 
-        zero(sa);
-        sa.sa_handler = SIG_DFL;
-        sa.sa_flags = SA_RESTART;
-
         if (sigaction(sig, &sa, NULL) < 0)
                 r = -errno;
 
@@ -2177,11 +2174,10 @@ ssize_t loop_read(int fd, void *buf, size_t nbytes, bool do_poll) {
                                 continue;
 
                         if (k < 0 && errno == EAGAIN && do_poll) {
-                                struct pollfd pollfd;
-
-                                zero(pollfd);
-                                pollfd.fd = fd;
-                                pollfd.events = POLLIN;
+                                struct pollfd pollfd = {
+                                        .fd = fd,
+                                        .events = POLLIN,
+                                };
 
                                 if (poll(&pollfd, 1, -1) < 0) {
                                         if (errno == EINTR)
@@ -2226,11 +2222,10 @@ ssize_t loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
                                 continue;
 
                         if (k < 0 && errno == EAGAIN && do_poll) {
-                                struct pollfd pollfd;
-
-                                zero(pollfd);
-                                pollfd.fd = fd;
-                                pollfd.events = POLLOUT;
+                                struct pollfd pollfd = {
+                                        .fd = fd,
+                                        .events = POLLOUT,
+                                };
 
                                 if (poll(&pollfd, 1, -1) < 0) {
                                         if (errno == EINTR)
@@ -2933,7 +2928,7 @@ int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char
         static const char status_indent[] = "         "; /* "[" STATUS "] " */
         _cleanup_free_ char *s = NULL;
         _cleanup_close_ int fd = -1;
-        struct iovec iovec[6];
+        struct iovec iovec[6] = {};
         int n = 0;
         static bool prev_ephemeral;
 
@@ -2971,8 +2966,6 @@ int status_vprintf(const char *status, bool ellipse, bool ephemeral, const char
                 }
         }
 
-        zero(iovec);
-
         if (prev_ephemeral)
                 IOVEC_SET_STRING(iovec[n++], "\r" ANSI_ERASE_TO_END_OF_LINE);
         prev_ephemeral = ephemeral;
@@ -3162,8 +3155,7 @@ char **replace_env_argv(char **argv, char **env) {
 }
 
 int fd_columns(int fd) {
-        struct winsize ws;
-        zero(ws);
+        struct winsize ws = {};
 
         if (ioctl(fd, TIOCGWINSZ, &ws) < 0)
                 return -errno;
@@ -3197,8 +3189,7 @@ unsigned columns(void) {
 }
 
 int fd_lines(int fd) {
-        struct winsize ws;
-        zero(ws);
+        struct winsize ws = {};
 
         if (ioctl(fd, TIOCGWINSZ, &ws) < 0)
                 return -errno;
@@ -3247,13 +3238,9 @@ bool on_tty(void) {
 }
 
 int running_in_chroot(void) {
-        struct stat a, b;
-
-        zero(a);
-        zero(b);
+        struct stat a = {}, b = {};
 
         /* Only works as root */
-
         if (stat("/proc/1/root", &a) < 0)
                 return -errno;
 
@@ -3731,10 +3718,9 @@ void execute_directory(const char *directory, DIR *d, char *argv[]) {
 
         while (!hashmap_isempty(pids)) {
                 pid_t pid = PTR_TO_UINT(hashmap_first_key(pids));
-                siginfo_t si;
+                siginfo_t si = {};
                 char *path;
 
-                zero(si);
                 if (waitid(P_PID, pid, &si, WEXITED) < 0) {
 
                         if (errno == EINTR)
@@ -3861,12 +3847,11 @@ char* hostname_cleanup(char *s) {
 }
 
 int pipe_eof(int fd) {
-        struct pollfd pollfd;
         int r;
-
-        zero(pollfd);
-        pollfd.fd = fd;
-        pollfd.events = POLLIN|POLLHUP;
+        struct pollfd pollfd = {
+                .fd = fd,
+                .events = POLLIN|POLLHUP,
+        };
 
         r = poll(&pollfd, 1, 0);
         if (r < 0)
@@ -3879,12 +3864,11 @@ int pipe_eof(int fd) {
 }
 
 int fd_wait_for_event(int fd, int event, usec_t t) {
-        struct pollfd pollfd;
         int r;
-
-        zero(pollfd);
-        pollfd.fd = fd;
-        pollfd.events = event;
+        struct pollfd pollfd = {
+                .fd = fd,
+                .events = event,
+        };
 
         r = poll(&pollfd, 1, t == (usec_t) -1 ? -1 : (int) (t / USEC_PER_MSEC));
         if (r < 0)
@@ -4343,7 +4327,6 @@ int glob_exists(const char *path) {
 
         assert(path);
 
-        zero(g);
         errno = 0;
         k = glob(path, GLOB_NOSORT|GLOB_BRACE, NULL, &g);
 
index 3494b569081ccd0e4ae5fd17123abc2e0d7752a6..5ee3d22e71e43ea083c876b63d065e14cbfe10df 100644 (file)
@@ -33,7 +33,7 @@
 #include "utmp-wtmp.h"
 
 int utmp_get_runlevel(int *runlevel, int *previous) {
-        struct utmpx lookup, *found;
+        struct utmpx *found, lookup = { .ut_type = RUN_LVL };
         int r;
         const char *e;
 
@@ -66,9 +66,6 @@ int utmp_get_runlevel(int *runlevel, int *previous) {
 
         setutxent();
 
-        zero(lookup);
-        lookup.ut_type = RUN_LVL;
-
         if (!(found = getutxid(&lookup)))
                 r = -errno;
         else {
@@ -102,14 +99,12 @@ static void init_timestamp(struct utmpx *store, usec_t t) {
 }
 
 static void init_entry(struct utmpx *store, usec_t t) {
-        struct utsname uts;
+        struct utsname uts = {};
 
         assert(store);
 
         init_timestamp(store, t);
 
-        zero(uts);
-
         if (uname(&uts) >= 0)
                 strncpy(store->ut_host, uts.release, sizeof(store->ut_host));
 
@@ -311,7 +306,10 @@ static int write_to_terminal(const char *tty, const char *message) {
 
         while (left > 0) {
                 ssize_t n;
-                struct pollfd pollfd;
+                struct pollfd pollfd = {
+                        .fd = fd,
+                        .events = POLLOUT,
+                };
                 usec_t t;
                 int k;
 
@@ -320,10 +318,6 @@ static int write_to_terminal(const char *tty, const char *message) {
                 if (t >= end)
                         return -ETIME;
 
-                zero(pollfd);
-                pollfd.fd = fd;
-                pollfd.events = POLLOUT;
-
                 k = poll(&pollfd, 1, (end - t) / USEC_PER_MSEC);
                 if (k < 0)
                         return -errno;
index 78016eec8927d3e3245141e9f11144dfd8566401..fddb45d6e832e1e4106eae3f3e065078d21304d9 100644 (file)
@@ -62,7 +62,7 @@ int detect_vm(const char **id) {
         union {
                 uint32_t sig32[3];
                 char text[13];
-        } sig;
+        } sig = {};
         unsigned i;
         const char *j, *k;
         bool hypervisor;
@@ -84,7 +84,6 @@ int detect_vm(const char **id) {
                 return r;
 
         /* http://lwn.net/Articles/301888/ */
-        zero(sig);
 
 #if defined (__i386__)
 #define REG_a "eax"
index ee2a328b4eb311807402ca859e65fffba59ee552..4c9c149a2dcbeef314d35ae532fb3e9151aa7899 100644 (file)
@@ -46,30 +46,29 @@ union shutdown_buffer {
 };
 
 static int read_packet(int fd, union shutdown_buffer *_b) {
-        struct msghdr msghdr;
-        struct iovec iovec;
         struct ucred *ucred;
+        ssize_t n;
+
+        union shutdown_buffer b; /* We maintain our own copy here, in
+                                  * order not to corrupt the last message */
+        struct iovec iovec = {
+                iovec.iov_base = &b,
+                iovec.iov_len = sizeof(b) - 1,
+        };
         union {
                 struct cmsghdr cmsghdr;
                 uint8_t buf[CMSG_SPACE(sizeof(struct ucred))];
-        } control;
-        ssize_t n;
-        union shutdown_buffer b; /* We maintain our own copy here, in order not to corrupt the last message */
+        } control = {};
+        struct msghdr msghdr = {
+                .msg_iov = &iovec,
+                msghdr.msg_iovlen = 1,
+                msghdr.msg_control = &control,
+                msghdr.msg_controllen = sizeof(control),
+        };
 
         assert(fd >= 0);
         assert(_b);
 
-        zero(iovec);
-        iovec.iov_base = &b;
-        iovec.iov_len = sizeof(b) - 1;
-
-        zero(control);
-        zero(msghdr);
-        msghdr.msg_iov = &iovec;
-        msghdr.msg_iovlen = 1;
-        msghdr.msg_control = &control;
-        msghdr.msg_controllen = sizeof(control);
-
         n = recvmsg(fd, &msghdr, MSG_DONTWAIT);
         if (n <= 0) {
                 if (n == 0) {
@@ -270,8 +269,8 @@ int main(int argc, char *argv[]) {
         };
 
         int r = EXIT_FAILURE, n_fds;
-        union shutdown_buffer b;
-        struct pollfd pollfd[_FD_MAX];
+        union shutdown_buffer b = {};
+        struct pollfd pollfd[_FD_MAX] = {};
         bool exec_shutdown = false, unlink_nologin = false;
         unsigned i;
 
@@ -302,9 +301,6 @@ int main(int argc, char *argv[]) {
                 return EXIT_FAILURE;
         }
 
-        zero(b);
-        zero(pollfd);
-
         pollfd[FD_SOCKET].fd = SD_LISTEN_FDS_START;
         pollfd[FD_SOCKET].events = POLLIN;
 
@@ -402,13 +398,12 @@ int main(int argc, char *argv[]) {
                 }
 
                 if (pollfd[FD_WALL_TIMER].revents) {
-                        struct itimerspec its;
+                        struct itimerspec its = {};
 
                         warn_wall(n, &b.command);
                         flush_fd(pollfd[FD_WALL_TIMER].fd);
 
                         /* Restart timer */
-                        zero(its);
                         timespec_store(&its.it_value, when_wall(n, b.command.usec));
                         if (timerfd_settime(pollfd[FD_WALL_TIMER].fd, TFD_TIMER_ABSTIME, &its, NULL) < 0) {
                                 log_error("timerfd_settime(): %m");
index 8667bbf9b6fb37e799c02f8355ebd3e89d44d1cb..a5bdb03416315e1f15fbd987cf796779e6deadd0 100644 (file)
@@ -124,7 +124,6 @@ int main(int argc, char *argv[]) {
 
         for (;;) {
                 _cleanup_bus_message_unref_ sd_bus_message *m = NULL;
-                struct pollfd p[3];
                 int events_a, events_b, fd;
                 uint64_t timeout_a, timeout_b, t;
                 struct timespec _ts, *ts;
@@ -211,15 +210,14 @@ int main(int argc, char *argv[]) {
                         ts = timespec_store(&_ts, t);
                 }
 
-                zero(p);
-                p[0].fd = fd;
-                p[0].events = events_a;
-                p[1].fd = STDIN_FILENO;
-                p[1].events = events_b & POLLIN;
-                p[2].fd = STDOUT_FILENO;
-                p[2].events = events_b & POLLOUT;
+                {
+                        struct pollfd p[3] = {
+                                {.fd = fd,            .events = events_a, },
+                                {.fd = STDIN_FILENO,  .events = events_b & POLLIN, },
+                                {.fd = STDOUT_FILENO, .events = events_b & POLLOUT, }};
 
-                r = ppoll(p, ELEMENTSOF(p), ts, NULL);
+                        r = ppoll(p, ELEMENTSOF(p), ts, NULL);
+                }
                 if (r < 0) {
                         log_error("ppoll() failed: %m");
                         goto finish;
index e445b50ab881cc2b14cffb5ce98dd1aaa2ae9127..fd9f580dc2e6438b4fe9222d44cee62c4ddd90c3 100644 (file)
@@ -1193,14 +1193,11 @@ static int enable_wait_for_jobs(DBusConnection *bus) {
 
 static int wait_for_jobs(DBusConnection *bus, Set *s) {
         int r = 0;
-        WaitData d;
+        WaitData d = { .set = s };
 
         assert(bus);
         assert(s);
 
-        zero(d);
-        d.set = s;
-
         if (!dbus_connection_add_filter(bus, wait_filter, &d, NULL))
                 return log_oom();
 
@@ -3021,9 +3018,8 @@ static int print_property(const char *name, DBusMessageIter *iter) {
 
                         dbus_message_iter_recurse(iter, &sub);
                         while (dbus_message_iter_get_arg_type(&sub) == DBUS_TYPE_STRUCT) {
-                                ExecStatusInfo info;
+                                ExecStatusInfo info = {};
 
-                                zero(info);
                                 if (exec_status_info_deserialize(&sub, &info) >= 0) {
                                         char timestamp1[FORMAT_TIMESTAMP_MAX], timestamp2[FORMAT_TIMESTAMP_MAX];
                                         char _cleanup_free_ *t;
@@ -3070,14 +3066,12 @@ static int show_one(const char *verb, DBusConnection *bus, const char *path, boo
         const char *interface = "";
         int r;
         DBusMessageIter iter, sub, sub2, sub3;
-        UnitStatusInfo info;
+        UnitStatusInfo info = {};
         ExecStatusInfo *p;
 
         assert(path);
         assert(new_line);
 
-        zero(info);
-
         r = bus_method_call_with_reply(
                         bus,
                         "org.freedesktop.systemd1",
@@ -3654,7 +3648,7 @@ static int enable_sysv_units(char **args) {
 #if defined(HAVE_SYSV_COMPAT) && defined(HAVE_CHKCONFIG)
         const char *verb = args[0];
         unsigned f = 1, t = 1;
-        LookupPaths paths;
+        LookupPaths paths = {};
 
         if (arg_scope != UNIT_FILE_SYSTEM)
                 return 0;
@@ -3667,7 +3661,6 @@ static int enable_sysv_units(char **args) {
         /* Processes all SysV units, and reshuffles the array so that
          * afterwards only the native units remain */
 
-        zero(paths);
         r = lookup_paths_init(&paths, SYSTEMD_SYSTEM, false, NULL, NULL, NULL);
         if (r < 0)
                 return r;
@@ -4716,7 +4709,7 @@ static int parse_time_spec(const char *t, usec_t *_u) {
         } else {
                 char *e = NULL;
                 long hour, minute;
-                struct tm tm;
+                struct tm tm = {};
                 time_t s;
                 usec_t n;
 
@@ -4732,7 +4725,6 @@ static int parse_time_spec(const char *t, usec_t *_u) {
                 n = now(CLOCK_REALTIME);
                 s = (time_t) (n / USEC_PER_SEC);
 
-                zero(tm);
                 assert_se(localtime_r(&s, &tm));
 
                 tm.tm_hour = (int) hour;
@@ -5134,7 +5126,7 @@ finish:
 }
 
 static int talk_initctl(void) {
-        struct init_request request = {0};
+        struct init_request request = {};
         int r;
         int _cleanup_close_ fd = -1;
         char rl;
@@ -5339,41 +5331,38 @@ static int systemctl_main(DBusConnection *bus, int argc, char *argv[], DBusError
 
 static int send_shutdownd(usec_t t, char mode, bool dry_run, bool warn, const char *message) {
         int _cleanup_close_ fd;
-        struct msghdr msghdr;
-        struct iovec iovec[2];
-        union sockaddr_union sockaddr;
-        struct sd_shutdown_command c;
+        struct sd_shutdown_command c = {
+                .usec = t,
+                .mode = mode,
+                .dry_run = dry_run,
+                .warn_wall = warn,
+        };
+        union sockaddr_union sockaddr = {
+                .un.sun_family = AF_UNIX,
+                .un.sun_path = "/run/systemd/shutdownd",
+        };
+        struct iovec iovec[2] = {
+                {.iov_base = (char*) &c,
+                 .iov_len = offsetof(struct sd_shutdown_command, wall_message),
+                }
+        };
+        struct msghdr msghdr = {
+                .msg_name = &sockaddr,
+                .msg_namelen = offsetof(struct sockaddr_un, sun_path)
+                               + sizeof("/run/systemd/shutdownd") - 1,
+                .msg_iov = iovec,
+                .msg_iovlen = 1,
+        };
 
         fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0);
         if (fd < 0)
                 return -errno;
 
-        zero(c);
-        c.usec = t;
-        c.mode = mode;
-        c.dry_run = dry_run;
-        c.warn_wall = warn;
-
-        zero(sockaddr);
-        sockaddr.sa.sa_family = AF_UNIX;
-        strncpy(sockaddr.un.sun_path, "/run/systemd/shutdownd", sizeof(sockaddr.un.sun_path));
-
-        zero(msghdr);
-        msghdr.msg_name = &sockaddr;
-        msghdr.msg_namelen = offsetof(struct sockaddr_un, sun_path) + sizeof("/run/systemd/shutdownd") - 1;
-
-        zero(iovec);
-        iovec[0].iov_base = (char*) &c;
-        iovec[0].iov_len = offsetof(struct sd_shutdown_command, wall_message);
-
-        if (isempty(message))
-                msghdr.msg_iovlen = 1;
-        else {
+        if (!isempty(message)) {
                 iovec[1].iov_base = (char*) message;
                 iovec[1].iov_len = strlen(message);
-                msghdr.msg_iovlen = 2;
+                msghdr.msg_iovlen++;
         }
-        msghdr.msg_iov = iovec;
 
         if (sendmsg(fd, &msghdr, MSG_NOSIGNAL) < 0)
                 return -errno;
index bcd935a6c0436e4656df3f5c15c60e5616f3cd7d..8d4e560b938239cede1fe287f7f1cb755c66611d 100644 (file)
@@ -72,9 +72,8 @@ typedef struct StatusInfo {
 } StatusInfo;
 
 static bool ntp_synced(void) {
-        struct timex txc;
+        struct timex txc = {};
 
-        zero(txc);
         if (adjtimex(&txc) < 0)
                 return false;
 
@@ -242,7 +241,7 @@ static int show_status(DBusConnection *bus, char **args, unsigned n) {
         const char *interface = "";
         int r;
         DBusMessageIter iter, sub, sub2, sub3;
-        StatusInfo info;
+        StatusInfo info = {};
 
         assert(args);
 
@@ -266,7 +265,6 @@ static int show_status(DBusConnection *bus, char **args, unsigned n) {
                 return -EIO;
         }
 
-        zero(info);
         dbus_message_iter_recurse(&iter, &sub);
 
         while (dbus_message_iter_get_arg_type(&sub) != DBUS_TYPE_INVALID) {
index 4e2519d1b543d2e5ff82e932c30c5441190ce97a..51827f01afdd77fb23c97b5f8e817c75ae1276ca 100644 (file)
@@ -601,11 +601,9 @@ static int recursive_relabel(Item *i, const char *path) {
 
 static int glob_item(Item *i, int (*action)(Item *, const char *)) {
         int r = 0, k;
-        glob_t g;
+        glob_t g = {};
         char **fn;
 
-        zero(g);
-
         errno = 0;
         if ((k = glob(i->path, GLOB_NOSORT|GLOB_BRACE, NULL, &g)) != 0) {
 
index 99a626c6c58ad960ccf1e762e0b5426182b08f83..3f5706ee3cd32deebee36ba835c233ccb6ca3d5a 100644 (file)
@@ -60,11 +60,11 @@ static int ask_password_plymouth(
                 char ***_passphrases) {
 
         int fd = -1, notify = -1;
-        union sockaddr_union sa;
+        union sockaddr_union sa = {};
         char *packet = NULL;
         ssize_t k;
         int r, n;
-        struct pollfd pollfd[2];
+        struct pollfd pollfd[2] = {};
         char buffer[LINE_MAX];
         size_t p = 0;
         enum {
@@ -91,7 +91,6 @@ static int ask_password_plymouth(
                 goto finish;
         }
 
-        zero(sa);
         sa.sa.sa_family = AF_UNIX;
         strncpy(sa.un.sun_path+1, "/org/freedesktop/plymouthd", sizeof(sa.un.sun_path)-1);
         if (connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(sa.un.sun_path+1)) < 0) {
@@ -116,7 +115,6 @@ static int ask_password_plymouth(
                 goto finish;
         }
 
-        zero(pollfd);
         pollfd[POLL_SOCKET].fd = fd;
         pollfd[POLL_SOCKET].events = POLLIN;
         pollfd[POLL_INOTIFY].fd = notify;
@@ -325,7 +323,7 @@ static int parse_password(const char *filename, char **wall) {
                 union {
                         struct sockaddr sa;
                         struct sockaddr_un un;
-                } sa;
+                } sa = {};
                 size_t packet_length = 0;
 
                 assert(arg_action == ACTION_QUERY ||
@@ -410,7 +408,6 @@ static int parse_password(const char *filename, char **wall) {
                         goto finish;
                 }
 
-                zero(sa);
                 sa.un.sun_family = AF_UNIX;
                 strncpy(sa.un.sun_path, socket_name, sizeof(sa.un.sun_path));
 
@@ -563,7 +560,7 @@ static int watch_passwords(void) {
         };
 
         int notify = -1, signal_fd = -1, tty_block_fd = -1;
-        struct pollfd pollfd[_FD_MAX];
+        struct pollfd pollfd[_FD_MAX] = {};
         sigset_t mask;
         int r;
 
@@ -591,7 +588,6 @@ static int watch_passwords(void) {
                 goto finish;
         }
 
-        zero(pollfd);
         pollfd[FD_INOTIFY].fd = notify;
         pollfd[FD_INOTIFY].events = POLLIN;
         pollfd[FD_SIGNAL].fd = signal_fd;
index fdbec5ae916872b7ba380355493f850cf41091b4..5719021e93bca5f0e6fe40e929b22880e3a743fc 100644 (file)
@@ -396,7 +396,7 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
         unsigned int i;
         const char *devtype;
         const char *prefix = "en";
-        struct netnames names;
+        struct netnames names = {};
         int err;
 
         /* handle only ARPHRD_ETHER devices */
@@ -425,7 +425,6 @@ static int builtin_net_id(struct udev_device *dev, int argc, char *argv[], bool
                         prefix = "ww";
         }
 
-        zero(names);
         err = names_mac(dev, &names);
         if (err >= 0 && names.mac_valid) {
                 char str[IFNAMSIZ];
index a311280c2792fc62777c7cfd878337a82bf14127..9184025554f03dc162c1096562aa1e81df496434 100644 (file)
@@ -313,11 +313,10 @@ static int on_runlevel(Context *c) {
 int main(int argc, char *argv[]) {
         int r;
         DBusError error;
-        Context c;
+        Context c = {};
 
         dbus_error_init(&error);
 
-        zero(c);
 #ifdef HAVE_AUDIT
         c.audit_fd = -1;
 #endif
index efeae909d9dede83fda56ef48349fbd21accbfdc..ee1f3ebdb088e7745dc155b473bcc4dfc085cc7d 100644 (file)
@@ -179,20 +179,18 @@ static int font_load(const char *vc, const char *font, const char *map, const ch
  * to apply a new font to all VTs.
  */
 static void font_copy_to_all_vcs(int fd) {
-        struct vt_stat vcs;
-        int i;
-        int r;
+        struct vt_stat vcs = {};
+        int i, r;
 
         /* get active, and 16 bit mask of used VT numbers */
-        zero(vcs);
         r = ioctl(fd, VT_GETSTATE, &vcs);
         if (r < 0)
                 return;
 
         for (i = 1; i <= 15; i++) {
                 char vcname[16];
-                struct console_font_op cfo;
                 int _cleanup_close_ vcfd = -1;
+                struct console_font_op cfo = {};
 
                 if (i == vcs.v_active)
                         continue;
@@ -208,7 +206,6 @@ static void font_copy_to_all_vcs(int fd) {
                         continue;
 
                 /* copy font from active VT, where the font was uploaded to */
-                zero(cfo);
                 cfo.op = KD_FONT_OP_COPY;
                 cfo.height = vcs.v_active-1; /* tty1 == index 0 */
                 ioctl(vcfd, KDFONTOP, &cfo);