summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/core/dbus-execute.c6
-rw-r--r--src/core/dbus.c4
-rw-r--r--src/core/device.c3
-rw-r--r--src/core/execute.c22
-rw-r--r--src/core/job.c22
-rw-r--r--src/core/locale-setup.c4
-rw-r--r--src/core/loopback-setup.c65
-rw-r--r--src/core/main.c29
-rw-r--r--src/core/manager.c116
-rw-r--r--src/core/mount.c15
-rw-r--r--src/core/service.c4
-rw-r--r--src/core/swap.c10
-rw-r--r--src/core/umount.c16
-rw-r--r--src/core/unit.c22
-rw-r--r--src/cryptsetup/cryptsetup.c5
-rw-r--r--src/hostname/hostnamectl.c3
-rw-r--r--src/journal/journald-server.c12
-rw-r--r--src/journal/journald-stream.c9
-rw-r--r--src/journal/journald-syslog.c33
-rw-r--r--src/libsystemd-bus/bus-socket.c10
-rw-r--r--src/libsystemd-bus/sd-bus.c13
-rw-r--r--src/locale/localectl.c3
-rw-r--r--src/locale/localed.c4
-rw-r--r--src/login/loginctl.c10
-rw-r--r--src/login/logind-inhibit.c3
-rw-r--r--src/login/logind-session.c3
-rw-r--r--src/login/logind.c38
-rw-r--r--src/login/pam-module.c28
-rw-r--r--src/nspawn/nspawn.c13
-rw-r--r--src/python-systemd/_reader.c6
-rw-r--r--src/readahead/readahead-collect.c17
-rw-r--r--src/remount-fs/remount-fs.c3
-rw-r--r--src/reply-password/reply-password.c6
-rw-r--r--src/shared/ask-password-api.c7
-rw-r--r--src/shared/dbus-loop.c20
-rw-r--r--src/shared/install.c24
-rw-r--r--src/shared/log.c43
-rw-r--r--src/shared/util.c109
-rw-r--r--src/shared/utmp-wtmp.c18
-rw-r--r--src/shared/virt.c3
-rw-r--r--src/shutdownd/shutdownd.c41
-rw-r--r--src/stdio-bridge/stdio-bridge.c16
-rw-r--r--src/systemctl/systemctl.c71
-rw-r--r--src/timedate/timedatectl.c6
-rw-r--r--src/tmpfiles/tmpfiles.c4
-rw-r--r--src/tty-ask-password-agent/tty-ask-password-agent.c12
-rw-r--r--src/udev/udev-builtin-net_id.c3
-rw-r--r--src/update-utmp/update-utmp.c3
-rw-r--r--src/vconsole/vconsole-setup.c9
49 files changed, 392 insertions, 554 deletions
diff --git a/src/core/dbus-execute.c b/src/core/dbus-execute.c
index 0a53207e59..2a8a0e1ac5 100644
--- a/src/core/dbus-execute.c
+++ b/src/core/dbus-execute.c
@@ -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;
diff --git a/src/core/dbus.c b/src/core/dbus.c
index b92c7d0b99..67ab1ae7f7 100644
--- a/src/core/dbus.c
+++ b/src/core/dbus.c
@@ -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;
diff --git a/src/core/device.c b/src/core/device.c
index 0b01718ad4..fb948688b6 100644
--- a/src/core/device.c
+++ b/src/core/device.c
@@ -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;
diff --git a/src/core/execute.c b/src/core/execute.c
index 2c13d1f9f6..c51049767d 100644
--- a/src/core/execute.c
+++ b/src/core/execute.c
@@ -205,7 +205,10 @@ static int open_null_as(int flags, int nfd) {
static int connect_logger_as(const ExecContext *context, ExecOutput output, const char *ident, const char *unit_id, int nfd) {
int fd, r;
- union sockaddr_union sa;
+ union sockaddr_union sa = {
+ .un.sun_family = AF_UNIX,
+ .un.sun_path = "/run/systemd/journal/stdout",
+ };
assert(context);
assert(output < _EXEC_OUTPUT_MAX);
@@ -216,10 +219,6 @@ static int connect_logger_as(const ExecContext *context, ExecOutput output, cons
if (fd < 0)
return -errno;
- zero(sa);
- sa.un.sun_family = AF_UNIX;
- strncpy(sa.un.sun_path, "/run/systemd/journal/stdout", sizeof(sa.un.sun_path));
-
r = connect(fd, &sa.sa, offsetof(struct sockaddr_un, sun_path) + strlen(sa.un.sun_path));
if (r < 0) {
close_nointr_nofail(fd);
@@ -938,7 +937,7 @@ static int apply_seccomp(uint32_t *syscall_filter) {
int i;
unsigned n;
struct sock_filter *f;
- struct sock_fprog prog;
+ struct sock_fprog prog = {};
assert(syscall_filter);
@@ -970,7 +969,6 @@ static int apply_seccomp(uint32_t *syscall_filter) {
memcpy(f + (ELEMENTSOF(header) + 2*n), footer, sizeof(footer));
/* Third: install the filter */
- zero(prog);
prog.len = ELEMENTSOF(header) + ELEMENTSOF(footer) + 2*n;
prog.filter = f;
if (prctl(PR_SET_SECCOMP, SECCOMP_MODE_FILTER, &prog) < 0)
@@ -1210,10 +1208,9 @@ int exec_spawn(ExecCommand *command,
}
if (context->cpu_sched_set) {
- struct sched_param param;
-
- zero(param);
- param.sched_priority = context->cpu_sched_priority;
+ struct sched_param param = {
+ .sched_priority = context->cpu_sched_priority,
+ };
r = sched_setscheduler(0,
context->cpu_sched_policy |
@@ -1701,7 +1698,7 @@ int exec_context_load_environment(const ExecContext *c, char ***l) {
int k;
bool ignore = false;
char **p;
- glob_t pglob;
+ glob_t pglob = {};
int count, n;
fn = *i;
@@ -1721,7 +1718,6 @@ int exec_context_load_environment(const ExecContext *c, char ***l) {
}
/* Filename supports globbing, take all matching files */
- zero(pglob);
errno = 0;
if (glob(fn, 0, NULL, &pglob) != 0) {
globfree(&pglob);
diff --git a/src/core/job.c b/src/core/job.c
index d5b7987a00..af5855b71d 100644
--- a/src/core/job.c
+++ b/src/core/job.c
@@ -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;
diff --git a/src/core/locale-setup.c b/src/core/locale-setup.c
index eefb256ac5..d7113b9795 100644
--- a/src/core/locale-setup.c
+++ b/src/core/locale-setup.c
@@ -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],
diff --git a/src/core/loopback-setup.c b/src/core/loopback-setup.c
index bfd0d93204..f98a29806e 100644
--- a/src/core/loopback-setup.c
+++ b/src/core/loopback-setup.c
@@ -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;
diff --git a/src/core/main.c b/src/core/main.c
index 92f066c707..4d21dd97a3 100644
--- a/src/core/main.c
+++ b/src/core/main.c
@@ -107,13 +107,13 @@ _noreturn_ static void crash(int sig) {
if (!arg_dump_core)
log_error("Caught <%s>, not dumping core.", signal_to_string(sig));
else {
- struct sigaction sa;
+ struct sigaction sa = {
+ .sa_handler = nop_handler,
+ .sa_flags = SA_NOCLDSTOP|SA_RESTART,
+ };
pid_t pid;
/* We want to wait for the core process, hence let's enable SIGCHLD */
- zero(sa);
- sa.sa_handler = nop_handler;
- sa.sa_flags = SA_NOCLDSTOP|SA_RESTART;
assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
pid = fork();
@@ -121,7 +121,7 @@ _noreturn_ static void crash(int sig) {
log_error("Caught <%s>, cannot fork for core dump: %s", signal_to_string(sig), strerror(errno));
else if (pid == 0) {
- struct rlimit rl;
+ struct rlimit rl = {};
/* Enable default signal handler for core dump */
zero(sa);
@@ -129,7 +129,6 @@ _noreturn_ static void crash(int sig) {
assert_se(sigaction(sig, &sa, NULL) == 0);
/* Don't limit the core dump size */
- zero(rl);
rl.rlim_cur = RLIM_INFINITY;
rl.rlim_max = RLIM_INFINITY;
setrlimit(RLIMIT_CORE, &rl);
@@ -162,16 +161,16 @@ _noreturn_ static void crash(int sig) {
chvt(arg_crash_chvt);
if (arg_crash_shell) {
- struct sigaction sa;
+ struct sigaction sa = {
+ .sa_handler = SIG_IGN,
+ .sa_flags = SA_NOCLDSTOP|SA_NOCLDWAIT|SA_RESTART,
+ };
pid_t pid;
log_info("Executing crash shell in 10s...");
sleep(10);
/* Let the kernel reap children for us */
- zero(sa);
- sa.sa_handler = SIG_IGN;
- sa.sa_flags = SA_NOCLDSTOP|SA_NOCLDWAIT|SA_RESTART;
assert_se(sigaction(SIGCHLD, &sa, NULL) == 0);
pid = fork();
@@ -193,12 +192,10 @@ _noreturn_ static void crash(int sig) {
}
static void install_crash_handler(void) {
- struct sigaction sa;
-
- zero(sa);
-
- sa.sa_handler = crash;
- sa.sa_flags = SA_NODEFER;
+ struct sigaction sa = {
+ .sa_handler = crash,
+ .sa_flags = SA_NODEFER,
+ };
sigaction_many(&sa, SIGNALS_CRASH_HANDLER, -1);
}
diff --git a/src/core/manager.c b/src/core/manager.c
index e26522a4dd..549153e057 100644
--- a/src/core/manager.c
+++ b/src/core/manager.c
@@ -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. */
diff --git a/src/core/mount.c b/src/core/mount.c
index 51a81a9488..4f245555f2 100644
--- a/src/core/mount.c
+++ b/src/core/mount.c
@@ -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;
}
diff --git a/src/core/service.c b/src/core/service.c
index 98266a5a90..a104b300c3 100644
--- a/src/core/service.c
+++ b/src/core/service.c
@@ -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;
diff --git a/src/core/swap.c b/src/core/swap.c
index dc98f47387..b363c5ec09 100644
--- a/src/core/swap.c
+++ b/src/core/swap.c
@@ -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;
}
diff --git a/src/core/umount.c b/src/core/umount.c
index 95e47e3c5a..8c69e74caf 100644
--- a/src/core/umount.c
+++ b/src/core/umount.c
@@ -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;
}
diff --git a/src/core/unit.c b/src/core/unit.c
index dbb1882965..63e42b2330 100644
--- a/src/core/unit.c
+++ b/src/core/unit.c
@@ -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;
diff --git a/src/cryptsetup/cryptsetup.c b/src/cryptsetup/cryptsetup.c
index 51d4f99edc..ae4aa8dba3 100644
--- a/src/cryptsetup/cryptsetup.c
+++ b/src/cryptsetup/cryptsetup.c
@@ -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
diff --git a/src/hostname/hostnamectl.c b/src/hostname/hostnamectl.c
index 917fac2466..1c9043534a 100644
--- a/src/hostname/hostnamectl.c
+++ b/src/hostname/hostnamectl.c
@@ -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) {
diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c
index a9d7aa181d..9a96689ee7 100644
--- a/src/journal/journald-server.c
+++ b/src/journal/journald-server.c
@@ -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)
diff --git a/src/journal/journald-stream.c b/src/journal/journald-stream.c
index bdc2f49ef4..6d51c29083 100644
--- a/src/journal/journald-stream.c
+++ b/src/journal/journald-stream.c
@@ -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));
diff --git a/src/journal/journald-syslog.c b/src/journal/journald-syslog.c
index afddca3630..000f5acc10 100644
--- a/src/journal/journald-syslog.c
+++ b/src/journal/journald-syslog.c
@@ -34,28 +34,28 @@
#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));
diff --git a/src/libsystemd-bus/bus-socket.c b/src/libsystemd-bus/bus-socket.c
index c68c7bca68..145f454d5d 100644
--- a/src/libsystemd-bus/bus-socket.c
+++ b/src/libsystemd-bus/bus-socket.c
@@ -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;
diff --git a/src/libsystemd-bus/sd-bus.c b/src/libsystemd-bus/sd-bus.c
index 6f8d444a66..2f084c26b3 100644
--- a/src/libsystemd-bus/sd-bus.c
+++ b/src/libsystemd-bus/sd-bus.c
@@ -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;
diff --git a/src/locale/localectl.c b/src/locale/localectl.c
index 5739a1dcdd..5328ac41a5 100644
--- a/src/locale/localectl.c
+++ b/src/locale/localectl.c
@@ -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) {
diff --git a/src/locale/localed.c b/src/locale/localed.c
index df812ee651..23fbde0df1 100644
--- a/src/locale/localed.c
+++ b/src/locale/localed.c
@@ -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;
diff --git a/src/login/loginctl.c b/src/login/loginctl.c
index 6c229c64e3..36c65bc8d0 100644
--- a/src/login/loginctl.c
+++ b/src/login/loginctl.c
@@ -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",
diff --git a/src/login/logind-inhibit.c b/src/login/logind-inhibit.c
index c43ae23acf..e77088364a 100644
--- a/src/login/logind-inhibit.c
+++ b/src/login/logind-inhibit.c
@@ -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;
diff --git a/src/login/logind-session.c b/src/login/logind-session.c
index 71c79127e9..97c24d094b 100644
--- a/src/login/logind-session.c
+++ b/src/login/logind-session.c
@@ -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;
diff --git a/src/login/logind.c b/src/login/logind.c
index f72aac5e61..c9e492fc4f 100644
--- a/src/login/logind.c
+++ b/src/login/logind.c
@@ -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;
diff --git a/src/login/pam-module.c b/src/login/pam-module.c
index 0d4f7991e7..c8f4dae77e 100644
--- a/src/login/pam-module.c
+++ b/src/login/pam-module.c
@@ -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)
diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c
index 01ef12bf67..b90ccc53ef 100644
--- a/src/nspawn/nspawn.c
+++ b/src/nspawn/nspawn.c
@@ -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;
diff --git a/src/python-systemd/_reader.c b/src/python-systemd/_reader.c
index d1188a147a..a49527fe48 100644
--- a/src/python-systemd/_reader.c
+++ b/src/python-systemd/_reader.c
@@ -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 = {
diff --git a/src/readahead/readahead-collect.c b/src/readahead/readahead-collect.c
index b2d0f68726..03583928a0 100644
--- a/src/readahead/readahead-collect.c
+++ b/src/readahead/readahead-collect.c
@@ -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;
diff --git a/src/remount-fs/remount-fs.c b/src/remount-fs/remount-fs.c
index b49d095cbb..f432718d6b 100644
--- a/src/remount-fs/remount-fs.c
+++ b/src/remount-fs/remount-fs.c
@@ -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)
diff --git a/src/reply-password/reply-password.c b/src/reply-password/reply-password.c
index a935d0f084..2f168985b4 100644
--- a/src/reply-password/reply-password.c
+++ b/src/reply-password/reply-password.c
@@ -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) {
diff --git a/src/shared/ask-password-api.c b/src/shared/ask-password-api.c
index 277efd302e..4557155d45 100644
--- a/src/shared/ask-password-api.c
+++ b/src/shared/ask-password-api.c
@@ -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) {
diff --git a/src/shared/dbus-loop.c b/src/shared/dbus-loop.c
index fec8998bc1..b42ae14511 100644
--- a/src/shared/dbus-loop.c
+++ b/src/shared/dbus-loop.c
@@ -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;
diff --git a/src/shared/install.c b/src/shared/install.c
index 2555a36c0a..9e870392f2 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -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;
diff --git a/src/shared/log.c b/src/shared/log.c
index 0dd04bc51e..876f22dfc5 100644
--- a/src/shared/log.c
+++ b/src/shared/log.c
@@ -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';
diff --git a/src/shared/util.c b/src/shared/util.c
index 1bffd84d1f..2f66597de3 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -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);
diff --git a/src/shared/utmp-wtmp.c b/src/shared/utmp-wtmp.c
index 3494b56908..5ee3d22e71 100644
--- a/src/shared/utmp-wtmp.c
+++ b/src/shared/utmp-wtmp.c
@@ -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;
diff --git a/src/shared/virt.c b/src/shared/virt.c
index 78016eec89..fddb45d6e8 100644
--- a/src/shared/virt.c
+++ b/src/shared/virt.c
@@ -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"
diff --git a/src/shutdownd/shutdownd.c b/src/shutdownd/shutdownd.c
index ee2a328b4e..4c9c149a2d 100644
--- a/src/shutdownd/shutdownd.c
+++ b/src/shutdownd/shutdownd.c
@@ -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");
diff --git a/src/stdio-bridge/stdio-bridge.c b/src/stdio-bridge/stdio-bridge.c
index 8667bbf9b6..a5bdb03416 100644
--- a/src/stdio-bridge/stdio-bridge.c
+++ b/src/stdio-bridge/stdio-bridge.c
@@ -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;
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index e445b50ab8..fd9f580dc2 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -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;
diff --git a/src/timedate/timedatectl.c b/src/timedate/timedatectl.c
index bcd935a6c0..8d4e560b93 100644
--- a/src/timedate/timedatectl.c
+++ b/src/timedate/timedatectl.c
@@ -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) {
diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
index 4e2519d1b5..51827f01af 100644
--- a/src/tmpfiles/tmpfiles.c
+++ b/src/tmpfiles/tmpfiles.c
@@ -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) {
diff --git a/src/tty-ask-password-agent/tty-ask-password-agent.c b/src/tty-ask-password-agent/tty-ask-password-agent.c
index 99a626c6c5..3f5706ee3c 100644
--- a/src/tty-ask-password-agent/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent/tty-ask-password-agent.c
@@ -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;
diff --git a/src/udev/udev-builtin-net_id.c b/src/udev/udev-builtin-net_id.c
index fdbec5ae91..5719021e93 100644
--- a/src/udev/udev-builtin-net_id.c
+++ b/src/udev/udev-builtin-net_id.c
@@ -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];
diff --git a/src/update-utmp/update-utmp.c b/src/update-utmp/update-utmp.c
index a311280c27..9184025554 100644
--- a/src/update-utmp/update-utmp.c
+++ b/src/update-utmp/update-utmp.c
@@ -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
diff --git a/src/vconsole/vconsole-setup.c b/src/vconsole/vconsole-setup.c
index efeae909d9..ee1f3ebdb0 100644
--- a/src/vconsole/vconsole-setup.c
+++ b/src/vconsole/vconsole-setup.c
@@ -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);