diff options
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/af-list.c | 6 | ||||
-rw-r--r-- | src/basic/arphrd-list.c | 4 | ||||
-rw-r--r-- | src/basic/async.c | 4 | ||||
-rw-r--r-- | src/basic/calendarspec.c | 2 | ||||
-rw-r--r-- | src/basic/cap-list.c | 2 | ||||
-rw-r--r-- | src/basic/errno-list.c | 4 | ||||
-rw-r--r-- | src/basic/exit-status.c | 4 | ||||
-rw-r--r-- | src/basic/fd-util.h | 4 | ||||
-rw-r--r-- | src/basic/fdset.c | 6 | ||||
-rw-r--r-- | src/basic/fileio-label.c | 4 | ||||
-rw-r--r-- | src/basic/hashmap.c | 2 | ||||
-rw-r--r-- | src/basic/json.c | 2 | ||||
-rw-r--r-- | src/basic/label.c | 2 | ||||
-rw-r--r-- | src/basic/lockfile-util.c | 8 | ||||
-rw-r--r-- | src/basic/login-util.c | 2 | ||||
-rw-r--r-- | src/basic/mempool.c | 2 | ||||
-rw-r--r-- | src/basic/mkdir-label.c | 2 | ||||
-rw-r--r-- | src/basic/mkdir.c | 2 | ||||
-rw-r--r-- | src/basic/selinux-util.c | 6 | ||||
-rw-r--r-- | src/basic/sigbus.c | 2 | ||||
-rw-r--r-- | src/basic/siphash24.c | 109 | ||||
-rw-r--r-- | src/basic/siphash24.h | 16 | ||||
-rw-r--r-- | src/basic/strv.c | 2 | ||||
-rw-r--r-- | src/basic/strxcpyx.c | 1 | ||||
-rw-r--r-- | src/basic/user-util.c | 2 | ||||
-rw-r--r-- | src/basic/utf8.c | 4 | ||||
-rw-r--r-- | src/basic/util.c | 12 |
27 files changed, 113 insertions, 103 deletions
diff --git a/src/basic/af-list.c b/src/basic/af-list.c index f396115a34..07dfff6ad4 100644 --- a/src/basic/af-list.c +++ b/src/basic/af-list.c @@ -19,16 +19,16 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <sys/socket.h> #include <string.h> +#include <sys/socket.h> -#include "util.h" #include "af-list.h" +#include "util.h" static const struct af_name* lookup_af(register const char *str, register unsigned int len); -#include "af-to-name.h" #include "af-from-name.h" +#include "af-to-name.h" const char *af_to_name(int id) { diff --git a/src/basic/arphrd-list.c b/src/basic/arphrd-list.c index 284043cd90..03d8ad7403 100644 --- a/src/basic/arphrd-list.c +++ b/src/basic/arphrd-list.c @@ -22,13 +22,13 @@ #include <net/if_arp.h> #include <string.h> -#include "util.h" #include "arphrd-list.h" +#include "util.h" static const struct arphrd_name* lookup_arphrd(register const char *str, register unsigned int len); -#include "arphrd-to-name.h" #include "arphrd-from-name.h" +#include "arphrd-to-name.h" const char *arphrd_to_name(int id) { 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/calendarspec.c b/src/basic/calendarspec.c index 7151fc3d0c..157ae1fb74 100644 --- a/src/basic/calendarspec.c +++ b/src/basic/calendarspec.c @@ -23,9 +23,9 @@ #include <string.h> #include "alloc-util.h" -#include "string-util.h" #include "calendarspec.h" #include "fileio.h" +#include "string-util.h" #define BITS_WEEKDAYS 127 diff --git a/src/basic/cap-list.c b/src/basic/cap-list.c index 4d391510bc..f0974900cd 100644 --- a/src/basic/cap-list.c +++ b/src/basic/cap-list.c @@ -28,8 +28,8 @@ static const struct capability_name* lookup_capability(register const char *str, register unsigned int len); -#include "cap-to-name.h" #include "cap-from-name.h" +#include "cap-to-name.h" const char *capability_to_name(int id) { diff --git a/src/basic/errno-list.c b/src/basic/errno-list.c index 34d1331486..22869e4136 100644 --- a/src/basic/errno-list.c +++ b/src/basic/errno-list.c @@ -21,14 +21,14 @@ #include <string.h> -#include "util.h" #include "errno-list.h" +#include "util.h" static const struct errno_name* lookup_errno(register const char *str, register unsigned int len); -#include "errno-to-name.h" #include "errno-from-name.h" +#include "errno-to-name.h" const char *errno_to_name(int id) { diff --git a/src/basic/exit-status.c b/src/basic/exit-status.c index fcff753ada..4c83731540 100644 --- a/src/basic/exit-status.c +++ b/src/basic/exit-status.c @@ -19,12 +19,12 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <stdlib.h> #include <signal.h> +#include <stdlib.h> #include "exit-status.h" -#include "set.h" #include "macro.h" +#include "set.h" const char* exit_status_to_string(ExitStatus status, ExitStatusLevel level) { 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 42b0b2b98f..e5452f3bb0 100644 --- a/src/basic/fdset.c +++ b/src/basic/fdset.c @@ -19,8 +19,8 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <errno.h> #include <dirent.h> +#include <errno.h> #include <fcntl.h> #include "sd-daemon.h" @@ -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/fileio-label.c b/src/basic/fileio-label.c index f596f1d11f..0405822ce0 100644 --- a/src/basic/fileio-label.c +++ b/src/basic/fileio-label.c @@ -20,9 +20,9 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include "util.h" -#include "selinux-util.h" #include "fileio-label.h" +#include "selinux-util.h" +#include "util.h" int write_string_file_atomic_label(const char *fn, const char *line) { int r; diff --git a/src/basic/hashmap.c b/src/basic/hashmap.c index d88ceb40aa..6e501ef6ff 100644 --- a/src/basic/hashmap.c +++ b/src/basic/hashmap.c @@ -380,7 +380,7 @@ static unsigned base_bucket_hash(HashmapBase *h, const void *p) { h->hash_ops->hash(p, &state); - siphash24_finalize(&hash, &state); + hash = siphash24_finalize(&state); return (unsigned) (hash % n_buckets(h)); } diff --git a/src/basic/json.c b/src/basic/json.c index 716705e5ff..9d5dedb934 100644 --- a/src/basic/json.c +++ b/src/basic/json.c @@ -23,9 +23,9 @@ #include <sys/types.h> #include "alloc-util.h" +#include "hexdecoct.h" #include "json.h" #include "macro.h" -#include "hexdecoct.h" #include "string-util.h" #include "utf8.h" diff --git a/src/basic/label.c b/src/basic/label.c index 82f10b21bd..f33502f90f 100644 --- a/src/basic/label.c +++ b/src/basic/label.c @@ -19,10 +19,10 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ +#include "label.h" #include "selinux-util.h" #include "smack-util.h" #include "util.h" -#include "label.h" int label_fix(const char *path, bool ignore_enoent, bool ignore_erofs) { int r, q; diff --git a/src/basic/lockfile-util.c b/src/basic/lockfile-util.c index 87c3aef7af..0bdbae480b 100644 --- a/src/basic/lockfile-util.c +++ b/src/basic/lockfile-util.c @@ -19,12 +19,12 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <stdlib.h> -#include <stdbool.h> #include <errno.h> -#include <string.h> -#include <stdio.h> #include <limits.h> +#include <stdbool.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> #include <sys/file.h> #include "alloc-util.h" diff --git a/src/basic/login-util.c b/src/basic/login-util.c index 832f477bd2..41cef14e73 100644 --- a/src/basic/login-util.c +++ b/src/basic/login-util.c @@ -20,8 +20,8 @@ ***/ #include "def.h" -#include "string-util.h" #include "login-util.h" +#include "string-util.h" bool session_id_valid(const char *id) { diff --git a/src/basic/mempool.c b/src/basic/mempool.c index d5d98d8829..9ee6e6a76d 100644 --- a/src/basic/mempool.c +++ b/src/basic/mempool.c @@ -20,8 +20,8 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include "mempool.h" #include "macro.h" +#include "mempool.h" #include "util.h" struct pool { diff --git a/src/basic/mkdir-label.c b/src/basic/mkdir-label.c index 76bbc1edda..c241ef6064 100644 --- a/src/basic/mkdir-label.c +++ b/src/basic/mkdir-label.c @@ -20,8 +20,8 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <unistd.h> #include <stdio.h> +#include <unistd.h> #include "label.h" #include "mkdir.h" diff --git a/src/basic/mkdir.c b/src/basic/mkdir.c index 0214c4627e..5d7fb9a12d 100644 --- a/src/basic/mkdir.c +++ b/src/basic/mkdir.c @@ -19,8 +19,8 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <string.h> #include <errno.h> +#include <string.h> #include "fs-util.h" #include "mkdir.h" diff --git a/src/basic/selinux-util.c b/src/basic/selinux-util.c index a821a3d5bb..e8ce5cfd96 100644 --- a/src/basic/selinux-util.c +++ b/src/basic/selinux-util.c @@ -24,15 +24,15 @@ #include <sys/un.h> #ifdef HAVE_SELINUX -#include <selinux/selinux.h> -#include <selinux/label.h> #include <selinux/context.h> +#include <selinux/label.h> +#include <selinux/selinux.h> #endif #include "alloc-util.h" -#include "strv.h" #include "path-util.h" #include "selinux-util.h" +#include "strv.h" #ifdef HAVE_SELINUX DEFINE_TRIVIAL_CLEANUP_FUNC(security_context_t, freecon); diff --git a/src/basic/sigbus.c b/src/basic/sigbus.c index 0108603fe8..c535c89d52 100644 --- a/src/basic/sigbus.c +++ b/src/basic/sigbus.c @@ -23,8 +23,8 @@ #include <sys/mman.h> #include "macro.h" -#include "util.h" #include "sigbus.h" +#include "util.h" #define SIGBUS_QUEUE_MAX 64 diff --git a/src/basic/siphash24.c b/src/basic/siphash24.c index d7640d395d..10fc56da69 100644 --- a/src/basic/siphash24.c +++ b/src/basic/siphash24.c @@ -17,9 +17,8 @@ coding style) */ -#include "sparse-endian.h" - #include "siphash24.h" +#include "sparse-endian.h" #include "unaligned.h" #include "util.h" @@ -54,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 @@ -94,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); @@ -102,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); @@ -120,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; } } -void siphash24_finalize(uint64_t *out, struct siphash *state) { +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); @@ -170,14 +176,17 @@ void siphash24_finalize(uint64_t *out, struct siphash *state) { sipround(state); sipround(state); - *(le64_t*)out = htole64(state->v0 ^ state->v1 ^ state->v2 ^ state->v3); + return state->v0 ^ state->v1 ^ state->v2 ^ state->v3; } -/* SipHash-2-4 */ -void siphash24(uint64_t *out, 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_finalize(out, &state); + siphash24_compress(in, inlen, &state); + + return siphash24_finalize(&state); } diff --git a/src/basic/siphash24.h b/src/basic/siphash24.h index dc08077d53..ba4f7d01b6 100644 --- a/src/basic/siphash24.h +++ b/src/basic/siphash24.h @@ -4,16 +4,16 @@ #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]); void siphash24_compress(const void *in, size_t inlen, struct siphash *state); -void siphash24_finalize(uint64_t *out, struct siphash *state); +uint64_t siphash24_finalize(struct siphash *state); -void siphash24(uint64_t *out, 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]); diff --git a/src/basic/strv.c b/src/basic/strv.c index ba6df716a7..771781f9fc 100644 --- a/src/basic/strv.c +++ b/src/basic/strv.c @@ -27,8 +27,8 @@ #include "alloc-util.h" #include "escape.h" #include "string-util.h" -#include "util.h" #include "strv.h" +#include "util.h" char *strv_find(char **l, const char *name) { char **i; diff --git a/src/basic/strxcpyx.c b/src/basic/strxcpyx.c index 6542c0abf5..088ba53c29 100644 --- a/src/basic/strxcpyx.c +++ b/src/basic/strxcpyx.c @@ -27,6 +27,7 @@ #include <stdio.h> #include <string.h> + #include "strxcpyx.h" size_t strpcpy(char **dest, size_t size, const char *src) { diff --git a/src/basic/user-util.c b/src/basic/user-util.c index d6c936db37..397880b0b1 100644 --- a/src/basic/user-util.c +++ b/src/basic/user-util.c @@ -19,8 +19,8 @@ along with systemd; If not, see <http://www.gnu.org/licenses/>. ***/ -#include <pwd.h> #include <grp.h> +#include <pwd.h> #include "alloc-util.h" #include "fd-util.h" diff --git a/src/basic/utf8.c b/src/basic/utf8.c index 7600d99903..b4063a4cec 100644 --- a/src/basic/utf8.c +++ b/src/basic/utf8.c @@ -44,10 +44,10 @@ */ #include <errno.h> -#include <stdlib.h> #include <inttypes.h> -#include <string.h> #include <stdbool.h> +#include <stdlib.h> +#include <string.h> #include "alloc-util.h" #include "hexdecoct.h" diff --git a/src/basic/util.c b/src/basic/util.c index 08bdcd28f2..58617b354a 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -73,6 +73,7 @@ #include "build.h" #include "def.h" #include "device-nodes.h" +#include "dirent-util.h" #include "env-util.h" #include "escape.h" #include "exit-status.h" @@ -81,19 +82,20 @@ #include "formats-util.h" #include "gunicode.h" #include "hashmap.h" +#include "hexdecoct.h" #include "hostname-util.h" #include "ioprio.h" #include "log.h" #include "macro.h" #include "missing.h" #include "mkdir.h" -#include "hexdecoct.h" #include "parse-util.h" #include "path-util.h" #include "process-util.h" #include "random-util.h" #include "signal-util.h" #include "sparse-endian.h" +#include "stat-util.h" #include "string-table.h" #include "string-util.h" #include "strv.h" @@ -102,8 +104,6 @@ #include "utf8.h" #include "util.h" #include "virt.h" -#include "dirent-util.h" -#include "stat-util.h" /* Put this test here for a lack of better place */ assert_cc(EAGAIN == EWOULDBLOCK); @@ -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); |