chiark / gitweb /
tree-wide: use IN_SET where possible
authorAndreas Rammhold <andreas@rammhold.de>
Thu, 28 Sep 2017 22:37:23 +0000 (00:37 +0200)
committerSven Eden <yamakuzure@gmx.net>
Thu, 28 Sep 2017 22:37:23 +0000 (00:37 +0200)
In addition to the changes from #6933 this handles cases that could be
matched with the included cocci file.

coccinelle/in_set.cocci [new file with mode: 0644]
src/basic/hashmap.c
src/basic/process-util.c
src/basic/signal-util.c
src/basic/socket-util.c
src/basic/terminal-util.c
src/basic/util.c
src/shared/clean-ipc.c
src/shared/utmp-wtmp.c

diff --git a/coccinelle/in_set.cocci b/coccinelle/in_set.cocci
new file mode 100644 (file)
index 0000000..f5ddd3d
--- /dev/null
@@ -0,0 +1,35 @@
+@@
+expression e;
+identifier n1, n2, n3, n4, n5, n6;
+statement s;
+@@
+- e == n1 || e == n2 || e == n3 || e == n4 || e == n5 || e == n6
++ IN_SET(e, n1, n2, n3, n4, n5, n6)
+@@
+expression e;
+identifier n1, n2, n3, n4, n5;
+statement s;
+@@
+- e == n1 || e == n2 || e == n3 || e == n4 || e == n5
++ IN_SET(e, n1, n2, n3, n4, n5)
+@@
+expression e;
+identifier n1, n2, n3, n4;
+statement s;
+@@
+- e == n1 || e == n2 || e == n3 || e == n4
++ IN_SET(e, n1, n2, n3, n4)
+@@
+expression e;
+identifier n1, n2, n3;
+statement s;
+@@
+- e == n1 || e == n2 || e == n3
++ IN_SET(e, n1, n2, n3)
+@@
+expression e;
+identifier n, p;
+statement s;
+@@
+- e == n || e == p
++ IN_SET(e, n, p)
index 86d648df0052c570db222aac2112cba0f6b4f449..51190b3816c4ea283136fde92c5d160ecc5d7560 100644 (file)
@@ -927,7 +927,7 @@ static bool hashmap_put_robin_hood(HashmapBase *h, unsigned idx,
 
         for (distance = 0; ; distance++) {
                 raw_dib = dibs[idx];
-                if (raw_dib == DIB_RAW_FREE || raw_dib == DIB_RAW_REHASH) {
+                if (IN_SET(raw_dib, DIB_RAW_FREE, DIB_RAW_REHASH)) {
                         if (raw_dib == DIB_RAW_REHASH)
                                 bucket_move_entry(h, swap, idx, IDX_TMP);
 
index 2b31cbb2b61fb5e29a10eefb61980b96daec7f7b..22d6f5059b22bd5256065b8a33fa8e7ca6f9d107 100644 (file)
@@ -692,8 +692,7 @@ int wait_for_terminate_and_warn(const char *name, pid_t pid, bool check_exit_cod
                         log_debug("%s succeeded.", name);
 
                 return status.si_status;
-        } else if (status.si_code == CLD_KILLED ||
-                   status.si_code == CLD_DUMPED) {
+        } else if (IN_SET(status.si_code, CLD_KILLED, CLD_DUMPED)) {
 
                 log_warning("%s terminated by signal %s.", name, signal_to_string(status.si_status));
                 return -EPROTO;
index 8e83bfcf0d960c433406fc9717bc49c8604a8d72..043c71466ce66ebc2fc528de920b0f46a8197351 100644 (file)
@@ -38,7 +38,7 @@ int reset_all_signal_handlers(void) {
         for (sig = 1; sig < _NSIG; sig++) {
 
                 /* These two cannot be caught... */
-                if (sig == SIGKILL || sig == SIGSTOP)
+                if (IN_SET(sig, SIGKILL, SIGSTOP))
                         continue;
 
                 /* On Linux the first two RT signals are reserved by
index 5487d1b05d2c6d61a492f30446dc11f62818a736..c32b8d3e102b8da9678de3ba0aa3232ba575567c 100644 (file)
@@ -364,8 +364,7 @@ bool socket_address_can_accept(const SocketAddress *a) {
         assert(a);
 
         return
-                a->type == SOCK_STREAM ||
-                a->type == SOCK_SEQPACKET;
+                IN_SET(a->type, SOCK_STREAM, SOCK_SEQPACKET);
 }
 
 bool socket_address_equal(const SocketAddress *a, const SocketAddress *b) {
@@ -1085,7 +1084,7 @@ ssize_t next_datagram_size_fd(int fd) {
 
         l = recv(fd, NULL, 0, MSG_PEEK|MSG_TRUNC);
         if (l < 0) {
-                if (errno == EOPNOTSUPP || errno == EFAULT)
+                if (IN_SET(errno, EOPNOTSUPP, EFAULT))
                         goto fallback;
 
                 return -errno;
index d580c6dac06d826424d8b9bb229cb2f16f130b3f..b83e778b2ef2dfe1839a3219cf29fdd324496b87 100644 (file)
@@ -479,7 +479,7 @@ int acquire_terminal(
 
                         l = read(notify, &buffer, sizeof(buffer));
                         if (l < 0) {
-                                if (errno == EINTR || errno == EAGAIN)
+                                if (IN_SET(errno, EINTR, EAGAIN))
                                         continue;
 
                                 r = -errno;
index 463f6fd129da56f9ab76161c54b98bd7d361190c..3dfe1ff657df8a549807e746481281bd6b116513 100644 (file)
@@ -383,7 +383,7 @@ int on_ac_power(void) {
 
                 device = openat(dirfd(d), de->d_name, O_DIRECTORY|O_RDONLY|O_CLOEXEC|O_NOCTTY);
                 if (device < 0) {
-                        if (errno == ENOENT || errno == ENOTDIR)
+                        if (IN_SET(errno, ENOENT, ENOTDIR))
                                 continue;
 
                         return -errno;
index 3b4231827725cda1c912e59dcc20a314d17b333f..3b1c2bd849ac7059b33d309c21e0487b1928a6a6 100644 (file)
@@ -95,7 +95,7 @@ static int clean_sysvipc_shm(uid_t delete_uid, gid_t delete_gid) {
                 if (shmctl(shmid, IPC_RMID, NULL) < 0) {
 
                         /* Ignore entries that are already deleted */
-                        if (errno == EIDRM || errno == EINVAL)
+                        if (IN_SET(errno, EIDRM, EINVAL))
                                 continue;
 
                         ret = log_warning_errno(errno,
@@ -147,7 +147,7 @@ static int clean_sysvipc_sem(uid_t delete_uid, gid_t delete_gid) {
                 if (semctl(semid, 0, IPC_RMID) < 0) {
 
                         /* Ignore entries that are already deleted */
-                        if (errno == EIDRM || errno == EINVAL)
+                        if (IN_SET(errno, EIDRM, EINVAL))
                                 continue;
 
                         ret = log_warning_errno(errno,
@@ -200,7 +200,7 @@ static int clean_sysvipc_msg(uid_t delete_uid, gid_t delete_gid) {
                 if (msgctl(msgid, IPC_RMID, NULL) < 0) {
 
                         /* Ignore entries that are already deleted */
-                        if (errno == EIDRM || errno == EINVAL)
+                        if (IN_SET(errno, EIDRM, EINVAL))
                                 continue;
 
                         ret = log_warning_errno(errno,
index 9750dcd81722f0ba25843e520784b7374f61d398..fc8548c5b3d6cf2641a6efee6b784882d9a6e4f5 100644 (file)
@@ -234,7 +234,7 @@ int utmp_put_init_process(const char *id, pid_t pid, pid_t sid, const char *line
         if (r < 0)
                 return r;
 
-        if (ut_type == LOGIN_PROCESS || ut_type == USER_PROCESS) {
+        if (IN_SET(ut_type, LOGIN_PROCESS, USER_PROCESS)) {
                 store.ut_type = LOGIN_PROCESS;
                 r = write_entry_both(&store);
                 if (r < 0)