diff options
author | Lennart Poettering <lennart@poettering.net> | 2018-10-15 19:21:37 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2018-10-15 19:40:51 +0200 |
commit | 6d5e65f6454212cd400d0ebda34978a9f20cc26a (patch) | |
tree | 844cd4d517956481a0963598edf586ae454524a0 /src/basic | |
parent | 8e8132c6b849a0aa34dbe8d97027beb50f71f1e3 (diff) | |
download | systemd-6d5e65f6454212cd400d0ebda34978a9f20cc26a.tar.gz |
tree-wide: add a single version of "static const int one = 1"
All over the place we define local variables for the various sockopts
that take a bool-like "int" value. Sometimes they are const, sometimes
static, sometimes both, sometimes neither.
Let's clean this up, introduce a common const variable "const_int_one"
(as well as one matching "const_int_zero") and use it everywhere, all
acorss the codebase.
Diffstat (limited to 'src/basic')
-rw-r--r-- | src/basic/socket-label.c | 14 | ||||
-rw-r--r-- | src/basic/util.c | 3 | ||||
-rw-r--r-- | src/basic/util.h | 3 |
3 files changed, 11 insertions, 9 deletions
diff --git a/src/basic/socket-label.c b/src/basic/socket-label.c index 35e14e567c..2698d59aea 100644 --- a/src/basic/socket-label.c +++ b/src/basic/socket-label.c @@ -35,7 +35,7 @@ int socket_address_listen( _cleanup_close_ int fd = -1; const char *p; - int r, one; + int r; assert(a); @@ -74,26 +74,22 @@ int socket_address_listen( return -errno; if (reuse_port) { - one = 1; - if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &one, sizeof(one)) < 0) + if (setsockopt(fd, SOL_SOCKET, SO_REUSEPORT, &const_int_one, sizeof(const_int_one)) < 0) log_warning_errno(errno, "SO_REUSEPORT failed: %m"); } if (free_bind) { - one = 1; - if (setsockopt(fd, IPPROTO_IP, IP_FREEBIND, &one, sizeof(one)) < 0) + if (setsockopt(fd, IPPROTO_IP, IP_FREEBIND, &const_int_one, sizeof(const_int_one)) < 0) log_warning_errno(errno, "IP_FREEBIND failed: %m"); } if (transparent) { - one = 1; - if (setsockopt(fd, IPPROTO_IP, IP_TRANSPARENT, &one, sizeof(one)) < 0) + if (setsockopt(fd, IPPROTO_IP, IP_TRANSPARENT, &const_int_one, sizeof(const_int_one)) < 0) log_warning_errno(errno, "IP_TRANSPARENT failed: %m"); } } - one = 1; - if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)) < 0) + if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &const_int_one, sizeof(const_int_one)) < 0) return -errno; p = socket_address_get_path(a); diff --git a/src/basic/util.c b/src/basic/util.c index 0da963f4af..c4c66cca53 100644 --- a/src/basic/util.c +++ b/src/basic/util.c @@ -51,6 +51,9 @@ int saved_argc = 0; char **saved_argv = NULL; static int saved_in_initrd = -1; +const int const_int_zero = 0; +const int const_int_one = 1; + size_t page_size(void) { static thread_local size_t pgsz = 0; long r; diff --git a/src/basic/util.h b/src/basic/util.h index 8cba4ed726..32d9380bd9 100644 --- a/src/basic/util.h +++ b/src/basic/util.h @@ -232,3 +232,6 @@ int version(void); int str_verscmp(const char *s1, const char *s2); void disable_coredumps(void); + +extern const int const_int_zero; +extern const int const_int_one; |