mirror of
https://github.com/systemd/systemd.git
synced 2025-02-21 05:57:34 +03:00
tree-wide: use structured initialization at various places
This commit is contained in:
parent
2efa5bc6fa
commit
41ab8c67eb
@ -1149,7 +1149,6 @@ static int subvol_remove_children(int fd, const char *subvolume, uint64_t subvol
|
||||
FOREACH_BTRFS_IOCTL_SEARCH_HEADER(i, sh, args) {
|
||||
_cleanup_free_ char *p = NULL;
|
||||
const struct btrfs_root_ref *ref;
|
||||
struct btrfs_ioctl_ino_lookup_args ino_args;
|
||||
|
||||
btrfs_ioctl_search_args_set(&args, sh);
|
||||
|
||||
@ -1164,9 +1163,10 @@ static int subvol_remove_children(int fd, const char *subvolume, uint64_t subvol
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
zero(ino_args);
|
||||
ino_args.treeid = subvol_id;
|
||||
ino_args.objectid = htole64(ref->dirid);
|
||||
struct btrfs_ioctl_ino_lookup_args ino_args = {
|
||||
.treeid = subvol_id,
|
||||
.objectid = htole64(ref->dirid),
|
||||
};
|
||||
|
||||
if (ioctl(fd, BTRFS_IOC_INO_LOOKUP, &ino_args) < 0)
|
||||
return -errno;
|
||||
@ -1504,7 +1504,6 @@ static int subvol_snapshot_children(
|
||||
|
||||
FOREACH_BTRFS_IOCTL_SEARCH_HEADER(i, sh, args) {
|
||||
_cleanup_free_ char *p = NULL, *c = NULL, *np = NULL;
|
||||
struct btrfs_ioctl_ino_lookup_args ino_args;
|
||||
const struct btrfs_root_ref *ref;
|
||||
_cleanup_close_ int old_child_fd = -1, new_child_fd = -1;
|
||||
|
||||
@ -1528,9 +1527,10 @@ static int subvol_snapshot_children(
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
zero(ino_args);
|
||||
ino_args.treeid = old_subvol_id;
|
||||
ino_args.objectid = htole64(ref->dirid);
|
||||
struct btrfs_ioctl_ino_lookup_args ino_args = {
|
||||
.treeid = old_subvol_id,
|
||||
.objectid = htole64(ref->dirid),
|
||||
};
|
||||
|
||||
if (ioctl(old_fd, BTRFS_IOC_INO_LOOKUP, &ino_args) < 0)
|
||||
return -errno;
|
||||
|
@ -246,9 +246,10 @@ static int server_init(Server *s, unsigned n_sockets) {
|
||||
assert(s);
|
||||
assert(n_sockets > 0);
|
||||
|
||||
zero(*s);
|
||||
*s = (struct Server) {
|
||||
.epoll_fd = epoll_create1(EPOLL_CLOEXEC),
|
||||
};
|
||||
|
||||
s->epoll_fd = epoll_create1(EPOLL_CLOEXEC);
|
||||
if (s->epoll_fd < 0) {
|
||||
r = log_error_errno(errno,
|
||||
"Failed to create epoll object: %m");
|
||||
@ -256,7 +257,6 @@ static int server_init(Server *s, unsigned n_sockets) {
|
||||
}
|
||||
|
||||
for (i = 0; i < n_sockets; i++) {
|
||||
struct epoll_event ev;
|
||||
Fifo *f;
|
||||
int fd;
|
||||
|
||||
@ -283,9 +283,11 @@ static int server_init(Server *s, unsigned n_sockets) {
|
||||
|
||||
f->fd = -1;
|
||||
|
||||
zero(ev);
|
||||
ev.events = EPOLLIN;
|
||||
ev.data.ptr = f;
|
||||
struct epoll_event ev = {
|
||||
.events = EPOLLIN,
|
||||
.data.ptr = f,
|
||||
};
|
||||
|
||||
if (epoll_ctl(s->epoll_fd, EPOLL_CTL_ADD, fd, &ev) < 0) {
|
||||
r = -errno;
|
||||
fifo_free(f);
|
||||
|
@ -1783,7 +1783,6 @@ static int setup_keys(void) {
|
||||
int fd = -1, r;
|
||||
sd_id128_t machine, boot;
|
||||
char *p = NULL, *k = NULL;
|
||||
struct FSSHeader h;
|
||||
uint64_t n;
|
||||
struct stat st;
|
||||
|
||||
@ -1873,15 +1872,17 @@ static int setup_keys(void) {
|
||||
if (r < 0)
|
||||
log_warning_errno(r, "Failed to set file attributes: %m");
|
||||
|
||||
zero(h);
|
||||
struct FSSHeader h = {
|
||||
.machine_id = machine,
|
||||
.boot_id = boot,
|
||||
.header_size = htole64(sizeof(h)),
|
||||
.start_usec = htole64(n * arg_interval),
|
||||
.interval_usec = htole64(arg_interval),
|
||||
.fsprg_secpar = htole16(FSPRG_RECOMMENDED_SECPAR),
|
||||
.fsprg_state_size = htole64(state_size),
|
||||
};
|
||||
|
||||
memcpy(h.signature, "KSHHRHLP", 8);
|
||||
h.machine_id = machine;
|
||||
h.boot_id = boot;
|
||||
h.header_size = htole64(sizeof(h));
|
||||
h.start_usec = htole64(n * arg_interval);
|
||||
h.interval_usec = htole64(arg_interval);
|
||||
h.fsprg_secpar = htole16(FSPRG_RECOMMENDED_SECPAR);
|
||||
h.fsprg_state_size = htole64(state_size);
|
||||
|
||||
r = loop_write(fd, &h, sizeof(h), false);
|
||||
if (r < 0) {
|
||||
|
@ -162,7 +162,7 @@ static Window *window_add(MMapCache *m, MMapFileDescriptor *f, int prot, bool ke
|
||||
if (!m->last_unused || m->n_windows <= WINDOWS_MIN) {
|
||||
|
||||
/* Allocate a new window */
|
||||
w = new0(Window, 1);
|
||||
w = new(Window, 1);
|
||||
if (!w)
|
||||
return NULL;
|
||||
m->n_windows++;
|
||||
@ -171,16 +171,17 @@ static Window *window_add(MMapCache *m, MMapFileDescriptor *f, int prot, bool ke
|
||||
/* Reuse an existing one */
|
||||
w = m->last_unused;
|
||||
window_unlink(w);
|
||||
zero(*w);
|
||||
}
|
||||
|
||||
w->cache = m;
|
||||
w->fd = f;
|
||||
w->prot = prot;
|
||||
w->keep_always = keep_always;
|
||||
w->offset = offset;
|
||||
w->size = size;
|
||||
w->ptr = ptr;
|
||||
*w = (Window) {
|
||||
.cache = m,
|
||||
.fd = f,
|
||||
.prot = prot,
|
||||
.keep_always = keep_always,
|
||||
.offset = offset,
|
||||
.size = size,
|
||||
.ptr = ptr,
|
||||
};
|
||||
|
||||
LIST_PREPEND(by_fd, f->windows, w);
|
||||
|
||||
|
@ -13,8 +13,9 @@
|
||||
int introspect_begin(struct introspect *i, bool trusted) {
|
||||
assert(i);
|
||||
|
||||
zero(*i);
|
||||
i->trusted = trusted;
|
||||
*i = (struct introspect) {
|
||||
.trusted = trusted,
|
||||
};
|
||||
|
||||
i->f = open_memstream_unlocked(&i->introspection, &i->size);
|
||||
if (!i->f)
|
||||
|
@ -136,11 +136,10 @@ static int bus_socket_write_auth(sd_bus *b) {
|
||||
if (b->prefer_writev)
|
||||
k = writev(b->output_fd, b->auth_iovec + b->auth_index, ELEMENTSOF(b->auth_iovec) - b->auth_index);
|
||||
else {
|
||||
struct msghdr mh;
|
||||
zero(mh);
|
||||
|
||||
mh.msg_iov = b->auth_iovec + b->auth_index;
|
||||
mh.msg_iovlen = ELEMENTSOF(b->auth_iovec) - b->auth_index;
|
||||
struct msghdr mh = {
|
||||
.msg_iov = b->auth_iovec + b->auth_index,
|
||||
.msg_iovlen = ELEMENTSOF(b->auth_iovec) - b->auth_index,
|
||||
};
|
||||
|
||||
k = sendmsg(b->output_fd, &mh, MSG_DONTWAIT|MSG_NOSIGNAL);
|
||||
if (k < 0 && errno == ENOTSOCK) {
|
||||
@ -551,11 +550,12 @@ static int bus_socket_read_auth(sd_bus *b) {
|
||||
if (b->prefer_readv)
|
||||
k = readv(b->input_fd, &iov, 1);
|
||||
else {
|
||||
zero(mh);
|
||||
mh.msg_iov = &iov;
|
||||
mh.msg_iovlen = 1;
|
||||
mh.msg_control = &control;
|
||||
mh.msg_controllen = sizeof(control);
|
||||
mh = (struct msghdr) {
|
||||
.msg_iov = &iov,
|
||||
.msg_iovlen = 1,
|
||||
.msg_control = &control,
|
||||
.msg_controllen = sizeof(control),
|
||||
};
|
||||
|
||||
k = recvmsg_safe(b->input_fd, &mh, MSG_DONTWAIT|MSG_CMSG_CLOEXEC);
|
||||
if (k == -ENOTSOCK) {
|
||||
@ -1194,11 +1194,12 @@ int bus_socket_read_message(sd_bus *bus) {
|
||||
if (bus->prefer_readv)
|
||||
k = readv(bus->input_fd, &iov, 1);
|
||||
else {
|
||||
zero(mh);
|
||||
mh.msg_iov = &iov;
|
||||
mh.msg_iovlen = 1;
|
||||
mh.msg_control = &control;
|
||||
mh.msg_controllen = sizeof(control);
|
||||
mh = (struct msghdr) {
|
||||
.msg_iov = &iov,
|
||||
.msg_iovlen = 1,
|
||||
.msg_control = &control,
|
||||
.msg_controllen = sizeof(control),
|
||||
};
|
||||
|
||||
k = recvmsg_safe(bus->input_fd, &mh, MSG_DONTWAIT|MSG_CMSG_CLOEXEC);
|
||||
if (k == -ENOTSOCK) {
|
||||
|
@ -860,7 +860,6 @@ int ask_password_agent(
|
||||
|
||||
for (;;) {
|
||||
char passphrase[LINE_MAX+1];
|
||||
struct msghdr msghdr;
|
||||
struct iovec iovec;
|
||||
struct ucred *ucred;
|
||||
union {
|
||||
@ -919,11 +918,12 @@ int ask_password_agent(
|
||||
iovec = IOVEC_MAKE(passphrase, sizeof(passphrase));
|
||||
|
||||
zero(control);
|
||||
zero(msghdr);
|
||||
msghdr.msg_iov = &iovec;
|
||||
msghdr.msg_iovlen = 1;
|
||||
msghdr.msg_control = &control;
|
||||
msghdr.msg_controllen = sizeof(control);
|
||||
struct msghdr msghdr = {
|
||||
.msg_iov = &iovec,
|
||||
.msg_iovlen = 1,
|
||||
.msg_control = &control,
|
||||
.msg_controllen = sizeof(control),
|
||||
};
|
||||
|
||||
n = recvmsg_safe(socket_fd, &msghdr, 0);
|
||||
if (IN_SET(n, -EAGAIN, -EINTR))
|
||||
|
@ -243,8 +243,9 @@ int socket_address_parse_netlink(SocketAddress *a, const char *s) {
|
||||
assert(a);
|
||||
assert(s);
|
||||
|
||||
zero(*a);
|
||||
a->type = SOCK_RAW;
|
||||
*a = (SocketAddress) {
|
||||
.type = SOCK_RAW,
|
||||
};
|
||||
|
||||
r = extract_first_word(&s, &word, NULL, 0);
|
||||
if (r < 0)
|
||||
|
Loading…
x
Reference in New Issue
Block a user