diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/basic/async.c | 4 | ||||
-rw-r--r-- | src/basic/fd-util.h | 4 | ||||
-rw-r--r-- | src/basic/fdset.c | 4 | ||||
-rw-r--r-- | src/basic/siphash24.c | 99 | ||||
-rw-r--r-- | src/basic/siphash24.h | 12 | ||||
-rw-r--r-- | src/basic/util.c | 6 | ||||
-rw-r--r-- | src/bus-proxyd/bus-xml-policy.c | 14 | ||||
-rw-r--r-- | src/core/cgroup.c | 24 | ||||
-rw-r--r-- | src/import/curl-util.c | 18 | ||||
-rw-r--r-- | src/journal/coredump-vacuum.c | 15 | ||||
-rw-r--r-- | src/journal/journalctl.c | 3 | ||||
-rw-r--r-- | src/journal/journald-server.c | 10 | ||||
-rw-r--r-- | src/journal/mmap-cache.c | 13 | ||||
-rw-r--r-- | src/libsystemd-network/sd-ipv4ll.c | 4 | ||||
-rw-r--r-- | src/libsystemd/sd-event/sd-event.c | 7 | ||||
-rw-r--r-- | src/login/pam_systemd.c | 2 | ||||
-rw-r--r-- | src/machine/machine.c | 5 | ||||
-rw-r--r-- | src/machine/machined-dbus.c | 2 | ||||
-rw-r--r-- | src/nspawn/nspawn.c | 6 | ||||
-rw-r--r-- | src/remount-fs/remount-fs.c | 66 | ||||
-rw-r--r-- | src/udev/udevd.c | 8 |
21 files changed, 162 insertions, 164 deletions
diff --git a/src/basic/async.c b/src/basic/async.c index c3135f0efe..cfc5d224e1 100644 --- a/src/basic/async.c +++ b/src/basic/async.c @@ -68,7 +68,7 @@ int asynchronous_sync(void) { } static void *close_thread(void *p) { - assert_se(close_nointr(PTR_TO_INT(p)) != -EBADF); + assert_se(close_nointr(PTR_TO_FD(p)) != -EBADF); return NULL; } @@ -84,7 +84,7 @@ int asynchronous_close(int fd) { if (fd >= 0) { PROTECT_ERRNO; - r = asynchronous_job(close_thread, INT_TO_PTR(fd)); + r = asynchronous_job(close_thread, FD_TO_PTR(fd)); if (r < 0) assert_se(close_nointr(fd) != -EBADF); } diff --git a/src/basic/fd-util.h b/src/basic/fd-util.h index 1ca10f0383..0e9182d75b 100644 --- a/src/basic/fd-util.h +++ b/src/basic/fd-util.h @@ -28,6 +28,10 @@ #include "macro.h" +/* Make sure we can distinguish fd 0 and NULL */ +#define FD_TO_PTR(fd) INT_TO_PTR((fd)+1) +#define PTR_TO_FD(p) (PTR_TO_INT(p)-1) + int close_nointr(int fd); int safe_close(int fd); void safe_close_pair(int p[]); diff --git a/src/basic/fdset.c b/src/basic/fdset.c index fd2e1149f5..e5452f3bb0 100644 --- a/src/basic/fdset.c +++ b/src/basic/fdset.c @@ -36,10 +36,6 @@ #define MAKE_SET(s) ((Set*) s) #define MAKE_FDSET(s) ((FDSet*) s) -/* Make sure we can distinguish fd 0 and NULL */ -#define FD_TO_PTR(fd) INT_TO_PTR((fd)+1) -#define PTR_TO_FD(p) (PTR_TO_INT(p)-1) - FDSet *fdset_new(void) { return MAKE_FDSET(set_new(NULL)); } diff --git a/src/basic/siphash24.c b/src/basic/siphash24.c index d2e4077f8a..10fc56da69 100644 --- a/src/basic/siphash24.c +++ b/src/basic/siphash24.c @@ -53,37 +53,40 @@ void siphash24_init(struct siphash *state, const uint8_t k[16]) { assert(state); assert(k); - k0 = le64toh(*(le64_t*) k); - k1 = le64toh(*(le64_t*) (k + 8)); - - /* "somepseudorandomlygeneratedbytes" */ - state->v0 = 0x736f6d6570736575ULL ^ k0; - state->v1 = 0x646f72616e646f6dULL ^ k1; - state->v2 = 0x6c7967656e657261ULL ^ k0; - state->v3 = 0x7465646279746573ULL ^ k1; - state->padding = 0; - state->inlen = 0; + k0 = unaligned_read_le64(k); + k1 = unaligned_read_le64(k + 8); + + *state = (struct siphash) { + /* "somepseudorandomlygeneratedbytes" */ + .v0 = 0x736f6d6570736575ULL ^ k0, + .v1 = 0x646f72616e646f6dULL ^ k1, + .v2 = 0x6c7967656e657261ULL ^ k0, + .v3 = 0x7465646279746573ULL ^ k1, + .padding = 0, + .inlen = 0, + }; } void siphash24_compress(const void *_in, size_t inlen, struct siphash *state) { - uint64_t m; + const uint8_t *in = _in; const uint8_t *end = in + inlen; - unsigned left = state->inlen & 7; + size_t left = state->inlen & 7; + uint64_t m; assert(in); assert(state); - /* update total length */ + /* Update total length */ state->inlen += inlen; - /* if padding exists, fill it out */ + /* If padding exists, fill it out */ if (left > 0) { - for ( ; in < end && left < 8; in ++, left ++ ) - state->padding |= ( ( uint64_t )*in ) << (left * 8); + for ( ; in < end && left < 8; in ++, left ++) + state->padding |= ((uint64_t) *in) << (left * 8); if (in == end && left < 8) - /* we did not have enough input to fill out the padding completely */ + /* We did not have enough input to fill out the padding completely */ return; #ifdef DEBUG @@ -93,6 +96,7 @@ void siphash24_compress(const void *_in, size_t inlen, struct siphash *state) { printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t) state->v3); printf("(%3zu) compress padding %08x %08x\n", state->inlen, (uint32_t) (state->padding >> 32), (uint32_t)state->padding); #endif + state->v3 ^= state->padding; sipround(state); sipround(state); @@ -101,9 +105,9 @@ void siphash24_compress(const void *_in, size_t inlen, struct siphash *state) { state->padding = 0; } - end -= ( state->inlen % sizeof (uint64_t) ); + end -= (state->inlen % sizeof(uint64_t)); - for ( ; in < end; in += 8 ) { + for ( ; in < end; in += 8) { m = unaligned_read_le64(in); #ifdef DEBUG printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0); @@ -119,38 +123,41 @@ void siphash24_compress(const void *_in, size_t inlen, struct siphash *state) { } left = state->inlen & 7; - - switch(left) - { - case 7: state->padding |= ((uint64_t) in[6]) << 48; - - case 6: state->padding |= ((uint64_t) in[5]) << 40; - - case 5: state->padding |= ((uint64_t) in[4]) << 32; - - case 4: state->padding |= ((uint64_t) in[3]) << 24; - - case 3: state->padding |= ((uint64_t) in[2]) << 16; - - case 2: state->padding |= ((uint64_t) in[1]) << 8; - - case 1: state->padding |= ((uint64_t) in[0]); break; - - case 0: break; + switch (left) { + case 7: + state->padding |= ((uint64_t) in[6]) << 48; + case 6: + state->padding |= ((uint64_t) in[5]) << 40; + case 5: + state->padding |= ((uint64_t) in[4]) << 32; + case 4: + state->padding |= ((uint64_t) in[3]) << 24; + case 3: + state->padding |= ((uint64_t) in[2]) << 16; + case 2: + state->padding |= ((uint64_t) in[1]) << 8; + case 1: + state->padding |= ((uint64_t) in[0]); + case 0: + break; } } uint64_t siphash24_finalize(struct siphash *state) { uint64_t b; - b = state->padding | (( ( uint64_t )state->inlen ) << 56); + assert(state); + + b = state->padding | (((uint64_t) state->inlen) << 56); + #ifdef DEBUG - printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t)state->v0); - printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t)state->v1); - printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t)state->v2); - printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t)state->v3); + printf("(%3zu) v0 %08x %08x\n", state->inlen, (uint32_t) (state->v0 >> 32), (uint32_t) state->v0); + printf("(%3zu) v1 %08x %08x\n", state->inlen, (uint32_t) (state->v1 >> 32), (uint32_t) state->v1); + printf("(%3zu) v2 %08x %08x\n", state->inlen, (uint32_t) (state->v2 >> 32), (uint32_t) state->v2); + printf("(%3zu) v3 %08x %08x\n", state->inlen, (uint32_t) (state->v3 >> 32), (uint32_t) state->v3); printf("(%3zu) padding %08x %08x\n", state->inlen, (uint32_t) (state->padding >> 32), (uint32_t) state->padding); #endif + state->v3 ^= b; sipround(state); sipround(state); @@ -172,12 +179,14 @@ uint64_t siphash24_finalize(struct siphash *state) { return state->v0 ^ state->v1 ^ state->v2 ^ state->v3; } -/* SipHash-2-4 */ -uint64_t siphash24(const void *_in, size_t inlen, const uint8_t k[16]) { +uint64_t siphash24(const void *in, size_t inlen, const uint8_t k[16]) { struct siphash state; + assert(in); + assert(k); + siphash24_init(&state, k); - siphash24_compress(_in, inlen, &state); + siphash24_compress(in, inlen, &state); return siphash24_finalize(&state); } diff --git a/src/basic/siphash24.h b/src/basic/siphash24.h index 0e072eba36..ba4f7d01b6 100644 --- a/src/basic/siphash24.h +++ b/src/basic/siphash24.h @@ -4,12 +4,12 @@ #include <sys/types.h> struct siphash { - uint64_t v0; - uint64_t v1; - uint64_t v2; - uint64_t v3; - uint64_t padding; - size_t inlen; + uint64_t v0; + uint64_t v1; + uint64_t v2; + uint64_t v3; + uint64_t padding; + size_t inlen; }; void siphash24_init(struct siphash *state, const uint8_t k[16]); diff --git a/src/basic/util.c b/src/basic/util.c index 3e4ec42a28..58617b354a 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -206,7 +206,7 @@ static int do_execute(char **directories, usec_t timeout, char *argv[]) { log_debug("Spawned %s as " PID_FMT ".", path, pid); - r = hashmap_put(pids, UINT_TO_PTR(pid), path); + r = hashmap_put(pids, PID_TO_PTR(pid), path); if (r < 0) return log_oom(); path = NULL; @@ -224,10 +224,10 @@ static int do_execute(char **directories, usec_t timeout, char *argv[]) { _cleanup_free_ char *path = NULL; pid_t pid; - pid = PTR_TO_UINT(hashmap_first_key(pids)); + pid = PTR_TO_PID(hashmap_first_key(pids)); assert(pid > 0); - path = hashmap_remove(pids, UINT_TO_PTR(pid)); + path = hashmap_remove(pids, PID_TO_PTR(pid)); assert(path); wait_for_terminate_and_warn(path, pid, true); diff --git a/src/bus-proxyd/bus-xml-policy.c b/src/bus-proxyd/bus-xml-policy.c index f0834e9525..debd58ce8b 100644 --- a/src/bus-proxyd/bus-xml-policy.c +++ b/src/bus-proxyd/bus-xml-policy.c @@ -392,11 +392,11 @@ static int file_load(Policy *p, const char *path) { } else { PolicyItem *first; - first = hashmap_get(p->user_items, UINT32_TO_PTR(i->uid)); + first = hashmap_get(p->user_items, UID_TO_PTR(i->uid)); item_append(i, &first); i->uid_valid = true; - r = hashmap_replace(p->user_items, UINT32_TO_PTR(i->uid), first); + r = hashmap_replace(p->user_items, UID_TO_PTR(i->uid), first); if (r < 0) { LIST_REMOVE(items, first, i); return log_oom(); @@ -424,11 +424,11 @@ static int file_load(Policy *p, const char *path) { } else { PolicyItem *first; - first = hashmap_get(p->group_items, UINT32_TO_PTR(i->gid)); + first = hashmap_get(p->group_items, GID_TO_PTR(i->gid)); item_append(i, &first); i->gid_valid = true; - r = hashmap_replace(p->group_items, UINT32_TO_PTR(i->gid), first); + r = hashmap_replace(p->group_items, GID_TO_PTR(i->gid), first); if (r < 0) { LIST_REMOVE(items, first, i); return log_oom(); @@ -787,7 +787,7 @@ static int policy_check(Policy *p, const struct policy_check_filter *filter) { verdict = check_policy_items(p->default_items, filter); if (filter->gid != GID_INVALID) { - items = hashmap_get(p->group_items, UINT32_TO_PTR(filter->gid)); + items = hashmap_get(p->group_items, GID_TO_PTR(filter->gid)); if (items) { v = check_policy_items(items, filter); if (v != DUNNO) @@ -796,7 +796,7 @@ static int policy_check(Policy *p, const struct policy_check_filter *filter) { } if (filter->uid != UID_INVALID) { - items = hashmap_get(p->user_items, UINT32_TO_PTR(filter->uid)); + items = hashmap_get(p->user_items, UID_TO_PTR(filter->uid)); if (items) { v = check_policy_items(items, filter); if (v != DUNNO) @@ -1155,7 +1155,7 @@ static void dump_hashmap_items(Hashmap *h) { void *k; HASHMAP_FOREACH_KEY(i, k, h, j) { - printf("\t%s Item for %u:\n", draw_special_char(DRAW_ARROW), PTR_TO_UINT(k)); + printf("\t%s Item for " UID_FMT ":\n", draw_special_char(DRAW_ARROW), PTR_TO_UID(k)); dump_items(i, "\t\t"); } } diff --git a/src/core/cgroup.c b/src/core/cgroup.c index bed01fde21..d122175417 100644 --- a/src/core/cgroup.c +++ b/src/core/cgroup.c @@ -217,7 +217,7 @@ static int whitelist_device(const char *path, const char *node, const char *acc) r = cg_set_attribute("devices", path, "devices.allow", buf); if (r < 0) - log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EINVAL) ? LOG_DEBUG : LOG_WARNING, r, + log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EINVAL, -EACCES) ? LOG_DEBUG : LOG_WARNING, r, "Failed to set devices.allow on %s: %m", path); return r; @@ -288,7 +288,7 @@ static int whitelist_major(const char *path, const char *name, char type, const r = cg_set_attribute("devices", path, "devices.allow", buf); if (r < 0) - log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EINVAL) ? LOG_DEBUG : LOG_WARNING, r, + log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EINVAL, -EACCES) ? LOG_DEBUG : LOG_WARNING, r, "Failed to set devices.allow on %s: %m", path); } @@ -328,13 +328,13 @@ void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, u c->cpu_shares != CGROUP_CPU_SHARES_INVALID ? c->cpu_shares : CGROUP_CPU_SHARES_DEFAULT); r = cg_set_attribute("cpu", path, "cpu.shares", buf); if (r < 0) - log_full_errno(IN_SET(r, -ENOENT, -EROFS) ? LOG_DEBUG : LOG_WARNING, r, + log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EACCES) ? LOG_DEBUG : LOG_WARNING, r, "Failed to set cpu.shares on %s: %m", path); sprintf(buf, USEC_FMT "\n", CGROUP_CPU_QUOTA_PERIOD_USEC); r = cg_set_attribute("cpu", path, "cpu.cfs_period_us", buf); if (r < 0) - log_full_errno(IN_SET(r, -ENOENT, -EROFS) ? LOG_DEBUG : LOG_WARNING, r, + log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EACCES) ? LOG_DEBUG : LOG_WARNING, r, "Failed to set cpu.cfs_period_us on %s: %m", path); if (c->cpu_quota_per_sec_usec != USEC_INFINITY) { @@ -343,7 +343,7 @@ void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, u } else r = cg_set_attribute("cpu", path, "cpu.cfs_quota_us", "-1"); if (r < 0) - log_full_errno(IN_SET(r, -ENOENT, -EROFS) ? LOG_DEBUG : LOG_WARNING, r, + log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EACCES) ? LOG_DEBUG : LOG_WARNING, r, "Failed to set cpu.cfs_quota_us on %s: %m", path); } @@ -359,7 +359,7 @@ void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, u c->blockio_weight != CGROUP_BLKIO_WEIGHT_INVALID ? c->blockio_weight : CGROUP_BLKIO_WEIGHT_DEFAULT); r = cg_set_attribute("blkio", path, "blkio.weight", buf); if (r < 0) - log_full_errno(IN_SET(r, -ENOENT, -EROFS) ? LOG_DEBUG : LOG_WARNING, r, + log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EACCES) ? LOG_DEBUG : LOG_WARNING, r, "Failed to set blkio.weight on %s: %m", path); /* FIXME: no way to reset this list */ @@ -373,7 +373,7 @@ void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, u sprintf(buf, "%u:%u %" PRIu64 "\n", major(dev), minor(dev), w->weight); r = cg_set_attribute("blkio", path, "blkio.weight_device", buf); if (r < 0) - log_full_errno(IN_SET(r, -ENOENT, -EROFS) ? LOG_DEBUG : LOG_WARNING, r, + log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EACCES) ? LOG_DEBUG : LOG_WARNING, r, "Failed to set blkio.weight_device on %s: %m", path); } } @@ -392,7 +392,7 @@ void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, u sprintf(buf, "%u:%u %" PRIu64 "\n", major(dev), minor(dev), b->bandwidth); r = cg_set_attribute("blkio", path, a, buf); if (r < 0) - log_full_errno(IN_SET(r, -ENOENT, -EROFS) ? LOG_DEBUG : LOG_WARNING, r, + log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EACCES) ? LOG_DEBUG : LOG_WARNING, r, "Failed to set %s on %s: %m", a, path); } } @@ -416,7 +416,7 @@ void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, u } if (r < 0) - log_full_errno(IN_SET(r, -ENOENT, -EROFS) ? LOG_DEBUG : LOG_WARNING, r, + log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EACCES) ? LOG_DEBUG : LOG_WARNING, r, "Failed to set memory.limit_in_bytes/memory.max on %s: %m", path); } @@ -432,7 +432,7 @@ void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, u else r = cg_set_attribute("devices", path, "devices.allow", "a"); if (r < 0) - log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EINVAL) ? LOG_DEBUG : LOG_WARNING, r, + log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EINVAL, -EACCES) ? LOG_DEBUG : LOG_WARNING, r, "Failed to reset devices.list on %s: %m", path); if (c->device_policy == CGROUP_CLOSED || @@ -494,7 +494,7 @@ void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, u r = cg_set_attribute("pids", path, "pids.max", "max"); if (r < 0) - log_full_errno(IN_SET(r, -ENOENT, -EROFS) ? LOG_DEBUG : LOG_WARNING, r, + log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EACCES) ? LOG_DEBUG : LOG_WARNING, r, "Failed to set pids.max on %s: %m", path); } @@ -505,7 +505,7 @@ void cgroup_context_apply(CGroupContext *c, CGroupMask mask, const char *path, u r = cg_set_attribute("net_cls", path, "net_cls.classid", buf); if (r < 0) - log_full_errno(IN_SET(r, -ENOENT, -EROFS) ? LOG_DEBUG : LOG_WARNING, r, + log_full_errno(IN_SET(r, -ENOENT, -EROFS, -EACCES) ? LOG_DEBUG : LOG_WARNING, r, "Failed to set net_cls.classid on %s: %m", path); } } diff --git a/src/import/curl-util.c b/src/import/curl-util.c index 4278466df1..8e531a64fa 100644 --- a/src/import/curl-util.c +++ b/src/import/curl-util.c @@ -48,9 +48,7 @@ static int curl_glue_on_io(sd_event_source *s, int fd, uint32_t revents, void *u assert(s); assert(g); - translated_fd = PTR_TO_INT(hashmap_get(g->translate_fds, INT_TO_PTR(fd+1))); - assert(translated_fd > 0); - translated_fd--; + translated_fd = PTR_TO_FD(hashmap_get(g->translate_fds, FD_TO_PTR(fd))); if ((revents & (EPOLLIN|EPOLLOUT)) == (EPOLLIN|EPOLLOUT)) action = CURL_POLL_INOUT; @@ -79,7 +77,7 @@ static int curl_glue_socket_callback(CURLM *curl, curl_socket_t s, int action, v assert(curl); assert(g); - io = hashmap_get(g->ios, INT_TO_PTR(s+1)); + io = hashmap_get(g->ios, FD_TO_PTR(s)); if (action == CURL_POLL_REMOVE) { if (io) { @@ -91,8 +89,8 @@ static int curl_glue_socket_callback(CURLM *curl, curl_socket_t s, int action, v sd_event_source_set_enabled(io, SD_EVENT_OFF); sd_event_source_unref(io); - hashmap_remove(g->ios, INT_TO_PTR(s+1)); - hashmap_remove(g->translate_fds, INT_TO_PTR(fd+1)); + hashmap_remove(g->ios, FD_TO_PTR(s)); + hashmap_remove(g->translate_fds, FD_TO_PTR(fd)); safe_close(fd); } @@ -143,17 +141,17 @@ static int curl_glue_socket_callback(CURLM *curl, curl_socket_t s, int action, v sd_event_source_set_description(io, "curl-io"); - r = hashmap_put(g->ios, INT_TO_PTR(s+1), io); + r = hashmap_put(g->ios, FD_TO_PTR(s), io); if (r < 0) { log_oom(); sd_event_source_unref(io); return -1; } - r = hashmap_put(g->translate_fds, INT_TO_PTR(fd+1), INT_TO_PTR(s+1)); + r = hashmap_put(g->translate_fds, FD_TO_PTR(fd), FD_TO_PTR(s)); if (r < 0) { log_oom(); - hashmap_remove(g->ios, INT_TO_PTR(s+1)); + hashmap_remove(g->ios, FD_TO_PTR(s)); sd_event_source_unref(io); return -1; } @@ -229,7 +227,7 @@ CurlGlue *curl_glue_unref(CurlGlue *g) { fd = sd_event_source_get_io_fd(io); assert(fd >= 0); - hashmap_remove(g->translate_fds, INT_TO_PTR(fd+1)); + hashmap_remove(g->translate_fds, FD_TO_PTR(fd)); safe_close(fd); sd_event_source_unref(io); diff --git a/src/journal/coredump-vacuum.c b/src/journal/coredump-vacuum.c index 39bc2e4270..09ab60c6c4 100644 --- a/src/journal/coredump-vacuum.c +++ b/src/journal/coredump-vacuum.c @@ -157,8 +157,7 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) { if (errno == ENOENT) return 0; - log_error_errno(errno, "Can't open coredump directory: %m"); - return -errno; + return log_error_errno(errno, "Can't open coredump directory: %m"); } for (;;) { @@ -183,7 +182,7 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) { if (errno == ENOENT) continue; - log_warning("Failed to stat /var/lib/systemd/coredump/%s", de->d_name); + log_warning_errno(errno, "Failed to stat /var/lib/systemd/coredump/%s: %m", de->d_name); continue; } @@ -201,7 +200,7 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) { t = timespec_load(&st.st_mtim); - c = hashmap_get(h, UINT32_TO_PTR(uid)); + c = hashmap_get(h, UID_TO_PTR(uid)); if (c) { if (t < c->oldest_mtime) { @@ -229,7 +228,7 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) { n->oldest_mtime = t; - r = hashmap_put(h, UINT32_TO_PTR(uid), n); + r = hashmap_put(h, UID_TO_PTR(uid), n); if (r < 0) return log_oom(); @@ -259,8 +258,7 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) { if (errno == ENOENT) continue; - log_error_errno(errno, "Failed to remove file %s: %m", worst->oldest_file); - return -errno; + return log_error_errno(errno, "Failed to remove file %s: %m", worst->oldest_file); } else log_info("Removed old coredump %s.", worst->oldest_file); } @@ -268,6 +266,5 @@ int coredump_vacuum(int exclude_fd, uint64_t keep_free, uint64_t max_use) { return 0; fail: - log_error_errno(errno, "Failed to read directory: %m"); - return -errno; + return log_error_errno(errno, "Failed to read directory: %m"); } diff --git a/src/journal/journalctl.c b/src/journal/journalctl.c index 75a48c761c..d9a8063d31 100644 --- a/src/journal/journalctl.c +++ b/src/journal/journalctl.c @@ -2247,7 +2247,8 @@ int main(int argc, char *argv[]) { if (arg_follow) need_seek = true; else { - printf("-- No entries --\n"); + if (!arg_quiet) + printf("-- No entries --\n"); goto finish; } } diff --git a/src/journal/journald-server.c b/src/journal/journald-server.c index be913d26ef..7d11a568aa 100644 --- a/src/journal/journald-server.c +++ b/src/journal/journald-server.c @@ -69,6 +69,7 @@ #include "socket-util.h" #include "string-table.h" #include "string-util.h" +#include "user-util.h" #define USER_JOURNALS_MAX 1024 @@ -281,7 +282,7 @@ static JournalFile* find_journal(Server *s, uid_t uid) { if (r < 0) return s->system_journal; - f = ordered_hashmap_get(s->user_journals, UINT32_TO_PTR(uid)); + f = ordered_hashmap_get(s->user_journals, UID_TO_PTR(uid)); if (f) return f; @@ -302,7 +303,7 @@ static JournalFile* find_journal(Server *s, uid_t uid) { server_fix_perms(s, f, uid); - r = ordered_hashmap_put(s->user_journals, UINT32_TO_PTR(uid), f); + r = ordered_hashmap_put(s->user_journals, UID_TO_PTR(uid), f); if (r < 0) { journal_file_close(f); return s->system_journal; @@ -348,7 +349,7 @@ void server_rotate(Server *s) { (void) do_rotate(s, &s->system_journal, "system", s->seal, 0); ORDERED_HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) { - r = do_rotate(s, &f, "user", s->seal, PTR_TO_UINT32(k)); + r = do_rotate(s, &f, "user", s->seal, PTR_TO_UID(k)); if (r >= 0) ordered_hashmap_replace(s->user_journals, k, f); else if (!f) @@ -359,7 +360,6 @@ void server_rotate(Server *s) { void server_sync(Server *s) { JournalFile *f; - void *k; Iterator i; int r; @@ -369,7 +369,7 @@ void server_sync(Server *s) { log_warning_errno(r, "Failed to sync system journal, ignoring: %m"); } - ORDERED_HASHMAP_FOREACH_KEY(f, k, s->user_journals, i) { + ORDERED_HASHMAP_FOREACH(f, s->user_journals, i) { r = journal_file_set_offline(f); if (r < 0) log_warning_errno(r, "Failed to sync user journal, ignoring: %m"); diff --git a/src/journal/mmap-cache.c b/src/journal/mmap-cache.c index 9540257895..5a07ddda76 100644 --- a/src/journal/mmap-cache.c +++ b/src/journal/mmap-cache.c @@ -24,6 +24,7 @@ #include <sys/mman.h> #include "alloc-util.h" +#include "fd-util.h" #include "hashmap.h" #include "list.h" #include "log.h" @@ -289,7 +290,7 @@ static void fd_free(FileDescriptor *f) { window_free(f->windows); if (f->cache) - assert_se(hashmap_remove(f->cache->fds, INT_TO_PTR(f->fd + 1))); + assert_se(hashmap_remove(f->cache->fds, FD_TO_PTR(f->fd))); free(f); } @@ -301,7 +302,7 @@ static FileDescriptor* fd_add(MMapCache *m, int fd) { assert(m); assert(fd >= 0); - f = hashmap_get(m->fds, INT_TO_PTR(fd + 1)); + f = hashmap_get(m->fds, FD_TO_PTR(fd)); if (f) return f; @@ -316,7 +317,7 @@ static FileDescriptor* fd_add(MMapCache *m, int fd) { f->cache = m; f->fd = fd; - r = hashmap_put(m->fds, UINT_TO_PTR(fd + 1), f); + r = hashmap_put(m->fds, FD_TO_PTR(fd), f); if (r < 0) { free(f); return NULL; @@ -429,7 +430,7 @@ static int find_mmap( assert(fd >= 0); assert(size > 0); - f = hashmap_get(m->fds, INT_TO_PTR(fd + 1)); + f = hashmap_get(m->fds, FD_TO_PTR(fd)); if (!f) return 0; @@ -679,7 +680,7 @@ bool mmap_cache_got_sigbus(MMapCache *m, int fd) { mmap_cache_process_sigbus(m); - f = hashmap_get(m->fds, INT_TO_PTR(fd + 1)); + f = hashmap_get(m->fds, FD_TO_PTR(fd)); if (!f) return false; @@ -698,7 +699,7 @@ void mmap_cache_close_fd(MMapCache *m, int fd) { mmap_cache_process_sigbus(m); - f = hashmap_get(m->fds, INT_TO_PTR(fd + 1)); + f = hashmap_get(m->fds, FD_TO_PTR(fd)); if (!f) return; diff --git a/src/libsystemd-network/sd-ipv4ll.c b/src/libsystemd-network/sd-ipv4ll.c index 006db6feee..30a7ef5785 100644 --- a/src/libsystemd-network/sd-ipv4ll.c +++ b/src/libsystemd-network/sd-ipv4ll.c @@ -101,6 +101,8 @@ int sd_ipv4ll_new(sd_ipv4ll **ret) { if (!ll) return -ENOMEM; + ll->n_ref = 1; + r = sd_ipv4acd_new(&ll->acd); if (r < 0) return r; @@ -109,8 +111,6 @@ int sd_ipv4ll_new(sd_ipv4ll **ret) { if (r < 0) return r; - ll->n_ref = 1; - *ret = ll; ll = NULL; diff --git a/src/libsystemd/sd-event/sd-event.c b/src/libsystemd/sd-event/sd-event.c index ee4886700e..700ac691b5 100644 --- a/src/libsystemd/sd-event/sd-event.c +++ b/src/libsystemd/sd-event/sd-event.c @@ -34,6 +34,7 @@ #include "macro.h" #include "missing.h" #include "prioq.h" +#include "process-util.h" #include "set.h" #include "signal-util.h" #include "string-util.h" @@ -808,7 +809,7 @@ static void source_disconnect(sd_event_source *s) { s->event->n_enabled_child_sources--; } - (void) hashmap_remove(s->event->child_sources, INT_TO_PTR(s->child.pid)); + (void) hashmap_remove(s->event->child_sources, PID_TO_PTR(s->child.pid)); event_gc_signal_data(s->event, &s->priority, SIGCHLD); } @@ -1188,7 +1189,7 @@ _public_ int sd_event_add_child( if (r < 0) return r; - if (hashmap_contains(e->child_sources, INT_TO_PTR(pid))) + if (hashmap_contains(e->child_sources, PID_TO_PTR(pid))) return -EBUSY; s = source_new(e, !ret, SOURCE_CHILD); @@ -1201,7 +1202,7 @@ _public_ int sd_event_add_child( s->userdata = userdata; s->enabled = SD_EVENT_ONESHOT; - r = hashmap_put(e->child_sources, INT_TO_PTR(pid), s); + r = hashmap_put(e->child_sources, PID_TO_PTR(pid), s); if (r < 0) { source_free(s); return r; diff --git a/src/login/pam_systemd.c b/src/login/pam_systemd.c index 3f7cbb78df..ed4f7c726f 100644 --- a/src/login/pam_systemd.c +++ b/src/login/pam_systemd.c @@ -493,7 +493,7 @@ _public_ PAM_EXTERN int pam_sm_open_session( return PAM_SESSION_ERR; } - r = pam_set_data(handle, "systemd.session-fd", INT_TO_PTR(session_fd+1), NULL); + r = pam_set_data(handle, "systemd.session-fd", FD_TO_PTR(session_fd), NULL); if (r != PAM_SUCCESS) { pam_syslog(handle, LOG_ERR, "Failed to install session fd."); safe_close(session_fd); diff --git a/src/machine/machine.c b/src/machine/machine.c index 282079f228..6b1fae2769 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -38,6 +38,7 @@ #include "machine.h" #include "mkdir.h" #include "parse-util.h" +#include "process-util.h" #include "special.h" #include "string-table.h" #include "terminal-util.h" @@ -105,7 +106,7 @@ void machine_free(Machine *m) { m->manager->host_machine = NULL; if (m->leader > 0) - (void) hashmap_remove_value(m->manager->machine_leaders, UINT_TO_PTR(m->leader), m); + (void) hashmap_remove_value(m->manager->machine_leaders, PID_TO_PTR(m->leader), m); sd_bus_message_unref(m->create_message); @@ -401,7 +402,7 @@ int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error) { if (m->started) return 0; - r = hashmap_put(m->manager->machine_leaders, UINT_TO_PTR(m->leader), m); + r = hashmap_put(m->manager->machine_leaders, PID_TO_PTR(m->leader), m); if (r < 0) return r; diff --git a/src/machine/machined-dbus.c b/src/machine/machined-dbus.c index 4ec6baaa1f..961767c4a9 100644 --- a/src/machine/machined-dbus.c +++ b/src/machine/machined-dbus.c @@ -1508,7 +1508,7 @@ int manager_get_machine_by_pid(Manager *m, pid_t pid, Machine **machine) { assert(pid >= 1); assert(machine); - mm = hashmap_get(m->machine_leaders, UINT_TO_PTR(pid)); + mm = hashmap_get(m->machine_leaders, PID_TO_PTR(pid)); if (!mm) { _cleanup_free_ char *unit = NULL; diff --git a/src/nspawn/nspawn.c b/src/nspawn/nspawn.c index d2ce731c72..f6a2c0386e 100644 --- a/src/nspawn/nspawn.c +++ b/src/nspawn/nspawn.c @@ -2283,7 +2283,7 @@ static int wait_for_container(pid_t pid, ContainerStatus *container) { static int on_orderly_shutdown(sd_event_source *s, const struct signalfd_siginfo *si, void *userdata) { pid_t pid; - pid = PTR_TO_UINT32(userdata); + pid = PTR_TO_PID(userdata); if (pid > 0) { if (kill(pid, arg_kill_signal) >= 0) { log_info("Trying to halt container. Send SIGTERM again to trigger immediate termination."); @@ -3510,8 +3510,8 @@ int main(int argc, char *argv[]) { if (arg_kill_signal > 0) { /* Try to kill the init system on SIGINT or SIGTERM */ - sd_event_add_signal(event, NULL, SIGINT, on_orderly_shutdown, UINT32_TO_PTR(pid)); - sd_event_add_signal(event, NULL, SIGTERM, on_orderly_shutdown, UINT32_TO_PTR(pid)); + sd_event_add_signal(event, NULL, SIGINT, on_orderly_shutdown, PID_TO_PTR(pid)); + sd_event_add_signal(event, NULL, SIGTERM, on_orderly_shutdown, PID_TO_PTR(pid)); } else { /* Immediately exit */ sd_event_add_signal(event, NULL, SIGINT, NULL, NULL); diff --git a/src/remount-fs/remount-fs.c b/src/remount-fs/remount-fs.c index b155f991bb..9fc56284d2 100644 --- a/src/remount-fs/remount-fs.c +++ b/src/remount-fs/remount-fs.c @@ -22,6 +22,7 @@ #include <errno.h> #include <mntent.h> #include <string.h> +#include <sys/prctl.h> #include <sys/stat.h> #include <sys/wait.h> #include <unistd.h> @@ -31,7 +32,9 @@ #include "mount-setup.h" #include "mount-util.h" #include "path-util.h" +#include "process-util.h" #include "signal-util.h" +#include "strv.h" #include "util.h" /* Goes through /etc/fstab and remounts all API file systems, applying @@ -39,10 +42,10 @@ * respected */ int main(int argc, char *argv[]) { - int ret = EXIT_FAILURE; + _cleanup_hashmap_free_free_ Hashmap *pids = NULL; _cleanup_endmntent_ FILE *f = NULL; struct mntent* me; - Hashmap *pids = NULL; + int r; if (argc > 1) { log_error("This program takes no argument."); @@ -57,21 +60,21 @@ int main(int argc, char *argv[]) { f = setmntent("/etc/fstab", "r"); if (!f) { - if (errno == ENOENT) - return EXIT_SUCCESS; + if (errno == ENOENT) { + r = 0; + goto finish; + } - log_error_errno(errno, "Failed to open /etc/fstab: %m"); - return EXIT_FAILURE; + r = log_error_errno(errno, "Failed to open /etc/fstab: %m"); + goto finish; } pids = hashmap_new(NULL); if (!pids) { - log_error("Failed to allocate set"); + r = log_oom(); goto finish; } - ret = EXIT_SUCCESS; - while ((me = getmntent(f))) { pid_t pid; int k; @@ -87,25 +90,18 @@ int main(int argc, char *argv[]) { pid = fork(); if (pid < 0) { - log_error_errno(errno, "Failed to fork: %m"); - ret = EXIT_FAILURE; - continue; + r = log_error_errno(errno, "Failed to fork: %m"); + goto finish; } if (pid == 0) { - const char *arguments[5]; /* Child */ (void) reset_all_signal_handlers(); (void) reset_signal_mask(); + (void) prctl(PR_SET_PDEATHSIG, SIGTERM); - arguments[0] = MOUNT_PATH; - arguments[1] = me->mnt_dir; - arguments[2] = "-o"; - arguments[3] = "remount"; - arguments[4] = NULL; - - execv(MOUNT_PATH, (char **) arguments); + execv(MOUNT_PATH, STRV_MAKE(MOUNT_PATH, me->mnt_dir, "-o", "remount")); log_error_errno(errno, "Failed to execute " MOUNT_PATH ": %m"); _exit(EXIT_FAILURE); @@ -115,20 +111,19 @@ int main(int argc, char *argv[]) { s = strdup(me->mnt_dir); if (!s) { - log_oom(); - ret = EXIT_FAILURE; - continue; + r = log_oom(); + goto finish; } - - k = hashmap_put(pids, UINT_TO_PTR(pid), s); + k = hashmap_put(pids, PID_TO_PTR(pid), s); if (k < 0) { - log_error_errno(k, "Failed to add PID to set: %m"); - ret = EXIT_FAILURE; - continue; + free(s); + r = log_oom(); + goto finish; } } + r = 0; while (!hashmap_isempty(pids)) { siginfo_t si = {}; char *s; @@ -138,12 +133,11 @@ int main(int argc, char *argv[]) { if (errno == EINTR) continue; - log_error_errno(errno, "waitid() failed: %m"); - ret = EXIT_FAILURE; - break; + r = log_error_errno(errno, "waitid() failed: %m"); + goto finish; } - s = hashmap_remove(pids, UINT_TO_PTR(si.si_pid)); + s = hashmap_remove(pids, PID_TO_PTR(si.si_pid)); if (s) { if (!is_clean_exit(si.si_code, si.si_status, NULL)) { if (si.si_code == CLD_EXITED) @@ -151,7 +145,7 @@ int main(int argc, char *argv[]) { else log_error(MOUNT_PATH " for %s terminated by signal %s.", s, signal_to_string(si.si_status)); - ret = EXIT_FAILURE; + r = -ENOEXEC; } free(s); @@ -159,9 +153,5 @@ int main(int argc, char *argv[]) { } finish: - - if (pids) - hashmap_free_free(pids); - - return ret; + return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS; } diff --git a/src/udev/udevd.c b/src/udev/udevd.c index 5364b92a57..6d9d765153 100644 --- a/src/udev/udevd.c +++ b/src/udev/udevd.c @@ -191,7 +191,7 @@ static void worker_free(struct worker *worker) { assert(worker->manager); - hashmap_remove(worker->manager->workers, UINT_TO_PTR(worker->pid)); + hashmap_remove(worker->manager->workers, PID_TO_PTR(worker->pid)); udev_monitor_unref(worker->monitor); event_free(worker->event); @@ -234,7 +234,7 @@ static int worker_new(struct worker **ret, Manager *manager, struct udev_monitor if (r < 0) return r; - r = hashmap_put(manager->workers, UINT_TO_PTR(pid), worker); + r = hashmap_put(manager->workers, PID_TO_PTR(pid), worker); if (r < 0) return r; @@ -891,7 +891,7 @@ static int on_worker(sd_event_source *s, int fd, uint32_t revents, void *userdat } /* lookup worker who sent the signal */ - worker = hashmap_get(manager->workers, UINT_TO_PTR(ucred->pid)); + worker = hashmap_get(manager->workers, PID_TO_PTR(ucred->pid)); if (!worker) { log_debug("worker ["PID_FMT"] returned, but is no longer tracked", ucred->pid); continue; @@ -1195,7 +1195,7 @@ static int on_sigchld(sd_event_source *s, const struct signalfd_siginfo *si, voi if (pid <= 0) break; - worker = hashmap_get(manager->workers, UINT_TO_PTR(pid)); + worker = hashmap_get(manager->workers, PID_TO_PTR(pid)); if (!worker) { log_warning("worker ["PID_FMT"] is unknown, ignoring", pid); continue; |