move VALSTR_STRUCT to common.h
authorRobert Swiecki <robert@swiecki.net>
Sun, 8 Oct 2017 21:06:40 +0000 (23:06 +0200)
committerRobert Swiecki <robert@swiecki.net>
Sun, 8 Oct 2017 21:06:40 +0000 (23:06 +0200)
caps.c
common.h
mount.c
subproc.c
util.c

diff --git a/caps.c b/caps.c
index 04b47cc..0910830 100644 (file)
--- a/caps.c
+++ b/caps.c
 #include "log.h"
 #include "util.h"
 
-#define VALSTR_STRUCT(x) \
-       {                \
-               x, #x    \
-       }
-
 #if !defined(CAP_AUDIT_READ)
 #define CAP_AUDIT_READ 37
 #endif /* !defined(CAP_AUDIT_READ) */
@@ -44,44 +39,44 @@ static struct {
        const int val;
        const char* const name;
 } const capNames[] = {
-       VALSTR_STRUCT(CAP_CHOWN),
-       VALSTR_STRUCT(CAP_DAC_OVERRIDE),
-       VALSTR_STRUCT(CAP_DAC_READ_SEARCH),
-       VALSTR_STRUCT(CAP_FOWNER),
-       VALSTR_STRUCT(CAP_FSETID),
-       VALSTR_STRUCT(CAP_KILL),
-       VALSTR_STRUCT(CAP_SETGID),
-       VALSTR_STRUCT(CAP_SETUID),
-       VALSTR_STRUCT(CAP_SETPCAP),
-       VALSTR_STRUCT(CAP_LINUX_IMMUTABLE),
-       VALSTR_STRUCT(CAP_NET_BIND_SERVICE),
-       VALSTR_STRUCT(CAP_NET_BROADCAST),
-       VALSTR_STRUCT(CAP_NET_ADMIN),
-       VALSTR_STRUCT(CAP_NET_RAW),
-       VALSTR_STRUCT(CAP_IPC_LOCK),
-       VALSTR_STRUCT(CAP_IPC_OWNER),
-       VALSTR_STRUCT(CAP_SYS_MODULE),
-       VALSTR_STRUCT(CAP_SYS_RAWIO),
-       VALSTR_STRUCT(CAP_SYS_CHROOT),
-       VALSTR_STRUCT(CAP_SYS_PTRACE),
-       VALSTR_STRUCT(CAP_SYS_PACCT),
-       VALSTR_STRUCT(CAP_SYS_ADMIN),
-       VALSTR_STRUCT(CAP_SYS_BOOT),
-       VALSTR_STRUCT(CAP_SYS_NICE),
-       VALSTR_STRUCT(CAP_SYS_RESOURCE),
-       VALSTR_STRUCT(CAP_SYS_TIME),
-       VALSTR_STRUCT(CAP_SYS_TTY_CONFIG),
-       VALSTR_STRUCT(CAP_MKNOD),
-       VALSTR_STRUCT(CAP_LEASE),
-       VALSTR_STRUCT(CAP_AUDIT_WRITE),
-       VALSTR_STRUCT(CAP_AUDIT_CONTROL),
-       VALSTR_STRUCT(CAP_SETFCAP),
-       VALSTR_STRUCT(CAP_MAC_OVERRIDE),
-       VALSTR_STRUCT(CAP_MAC_ADMIN),
-       VALSTR_STRUCT(CAP_SYSLOG),
-       VALSTR_STRUCT(CAP_WAKE_ALARM),
-       VALSTR_STRUCT(CAP_BLOCK_SUSPEND),
-       VALSTR_STRUCT(CAP_AUDIT_READ),
+       NS_VALSTR_STRUCT(CAP_CHOWN),
+       NS_VALSTR_STRUCT(CAP_DAC_OVERRIDE),
+       NS_VALSTR_STRUCT(CAP_DAC_READ_SEARCH),
+       NS_VALSTR_STRUCT(CAP_FOWNER),
+       NS_VALSTR_STRUCT(CAP_FSETID),
+       NS_VALSTR_STRUCT(CAP_KILL),
+       NS_VALSTR_STRUCT(CAP_SETGID),
+       NS_VALSTR_STRUCT(CAP_SETUID),
+       NS_VALSTR_STRUCT(CAP_SETPCAP),
+       NS_VALSTR_STRUCT(CAP_LINUX_IMMUTABLE),
+       NS_VALSTR_STRUCT(CAP_NET_BIND_SERVICE),
+       NS_VALSTR_STRUCT(CAP_NET_BROADCAST),
+       NS_VALSTR_STRUCT(CAP_NET_ADMIN),
+       NS_VALSTR_STRUCT(CAP_NET_RAW),
+       NS_VALSTR_STRUCT(CAP_IPC_LOCK),
+       NS_VALSTR_STRUCT(CAP_IPC_OWNER),
+       NS_VALSTR_STRUCT(CAP_SYS_MODULE),
+       NS_VALSTR_STRUCT(CAP_SYS_RAWIO),
+       NS_VALSTR_STRUCT(CAP_SYS_CHROOT),
+       NS_VALSTR_STRUCT(CAP_SYS_PTRACE),
+       NS_VALSTR_STRUCT(CAP_SYS_PACCT),
+       NS_VALSTR_STRUCT(CAP_SYS_ADMIN),
+       NS_VALSTR_STRUCT(CAP_SYS_BOOT),
+       NS_VALSTR_STRUCT(CAP_SYS_NICE),
+       NS_VALSTR_STRUCT(CAP_SYS_RESOURCE),
+       NS_VALSTR_STRUCT(CAP_SYS_TIME),
+       NS_VALSTR_STRUCT(CAP_SYS_TTY_CONFIG),
+       NS_VALSTR_STRUCT(CAP_MKNOD),
+       NS_VALSTR_STRUCT(CAP_LEASE),
+       NS_VALSTR_STRUCT(CAP_AUDIT_WRITE),
+       NS_VALSTR_STRUCT(CAP_AUDIT_CONTROL),
+       NS_VALSTR_STRUCT(CAP_SETFCAP),
+       NS_VALSTR_STRUCT(CAP_MAC_OVERRIDE),
+       NS_VALSTR_STRUCT(CAP_MAC_ADMIN),
+       NS_VALSTR_STRUCT(CAP_SYSLOG),
+       NS_VALSTR_STRUCT(CAP_WAKE_ALARM),
+       NS_VALSTR_STRUCT(CAP_BLOCK_SUSPEND),
+       NS_VALSTR_STRUCT(CAP_AUDIT_READ),
 };
 
 int capsNameToVal(const char* name)
index 4bfe9f5..9a3a143 100644 (file)
--- a/common.h
+++ b/common.h
@@ -55,6 +55,11 @@ static void __attribute__ ((unused)) __clang_cleanup_func(void (^*dfunc) (void))
 #endif
 #endif
 
+#define NS_VALSTR_STRUCT(x) \
+       {                   \
+               x, #x       \
+       }
+
 struct pids_t {
        pid_t pid;
        time_t start;
diff --git a/mount.c b/mount.c
index bcc0c79..0b66f05 100644 (file)
--- a/mount.c
+++ b/mount.c
 #include "subproc.h"
 #include "util.h"
 
-#define VALSTR_STRUCT(x) \
-       {                \
-               x, #x    \
-       }
-
 #if !defined(MS_LAZYTIME)
 #define MS_LAZYTIME (1 << 25)
 #endif /* if !defined(MS_LAZYTIME) */
@@ -58,30 +53,30 @@ const char* mountFlagsToStr(uintptr_t flags)
                const uintptr_t flag;
                const char* const name;
        } const mountFlags[] = {
-               VALSTR_STRUCT(MS_RDONLY),
-               VALSTR_STRUCT(MS_NOSUID),
-               VALSTR_STRUCT(MS_NODEV),
-               VALSTR_STRUCT(MS_NOEXEC),
-               VALSTR_STRUCT(MS_SYNCHRONOUS),
-               VALSTR_STRUCT(MS_REMOUNT),
-               VALSTR_STRUCT(MS_MANDLOCK),
-               VALSTR_STRUCT(MS_DIRSYNC),
-               VALSTR_STRUCT(MS_NOATIME),
-               VALSTR_STRUCT(MS_NODIRATIME),
-               VALSTR_STRUCT(MS_BIND),
-               VALSTR_STRUCT(MS_MOVE),
-               VALSTR_STRUCT(MS_REC),
-               VALSTR_STRUCT(MS_SILENT),
-               VALSTR_STRUCT(MS_POSIXACL),
-               VALSTR_STRUCT(MS_UNBINDABLE),
-               VALSTR_STRUCT(MS_PRIVATE),
-               VALSTR_STRUCT(MS_SLAVE),
-               VALSTR_STRUCT(MS_SHARED),
-               VALSTR_STRUCT(MS_RELATIME),
-               VALSTR_STRUCT(MS_KERNMOUNT),
-               VALSTR_STRUCT(MS_I_VERSION),
-               VALSTR_STRUCT(MS_STRICTATIME),
-               VALSTR_STRUCT(MS_LAZYTIME),
+               NS_VALSTR_STRUCT(MS_RDONLY),
+               NS_VALSTR_STRUCT(MS_NOSUID),
+               NS_VALSTR_STRUCT(MS_NODEV),
+               NS_VALSTR_STRUCT(MS_NOEXEC),
+               NS_VALSTR_STRUCT(MS_SYNCHRONOUS),
+               NS_VALSTR_STRUCT(MS_REMOUNT),
+               NS_VALSTR_STRUCT(MS_MANDLOCK),
+               NS_VALSTR_STRUCT(MS_DIRSYNC),
+               NS_VALSTR_STRUCT(MS_NOATIME),
+               NS_VALSTR_STRUCT(MS_NODIRATIME),
+               NS_VALSTR_STRUCT(MS_BIND),
+               NS_VALSTR_STRUCT(MS_MOVE),
+               NS_VALSTR_STRUCT(MS_REC),
+               NS_VALSTR_STRUCT(MS_SILENT),
+               NS_VALSTR_STRUCT(MS_POSIXACL),
+               NS_VALSTR_STRUCT(MS_UNBINDABLE),
+               NS_VALSTR_STRUCT(MS_PRIVATE),
+               NS_VALSTR_STRUCT(MS_SLAVE),
+               NS_VALSTR_STRUCT(MS_SHARED),
+               NS_VALSTR_STRUCT(MS_RELATIME),
+               NS_VALSTR_STRUCT(MS_KERNMOUNT),
+               NS_VALSTR_STRUCT(MS_I_VERSION),
+               NS_VALSTR_STRUCT(MS_STRICTATIME),
+               NS_VALSTR_STRUCT(MS_LAZYTIME),
        };
 
        for (size_t i = 0; i < ARRAYSIZE(mountFlags); i++) {
index dd74722..cc7b4af 100644 (file)
--- a/subproc.c
+++ b/subproc.c
 
 static const char subprocDoneChar = 'D';
 
-#define VALSTR_STRUCT(x) \
-       {                \
-               x, #x    \
-       }
-
 #if !defined(CLONE_NEWCGROUP)
 #define CLONE_NEWCGROUP 0x02000000
 #endif /* !defined(CLONE_NEWCGROUP) */
@@ -70,29 +65,29 @@ static const char* subprocCloneFlagsToStr(uintptr_t flags)
                const uintptr_t flag;
                const char* const name;
        } const cloneFlags[] = {
-               VALSTR_STRUCT(CLONE_VM),
-               VALSTR_STRUCT(CLONE_FS),
-               VALSTR_STRUCT(CLONE_FILES),
-               VALSTR_STRUCT(CLONE_SIGHAND),
-               VALSTR_STRUCT(CLONE_PTRACE),
-               VALSTR_STRUCT(CLONE_VFORK),
-               VALSTR_STRUCT(CLONE_PARENT),
-               VALSTR_STRUCT(CLONE_THREAD),
-               VALSTR_STRUCT(CLONE_NEWNS),
-               VALSTR_STRUCT(CLONE_SYSVSEM),
-               VALSTR_STRUCT(CLONE_SETTLS),
-               VALSTR_STRUCT(CLONE_PARENT_SETTID),
-               VALSTR_STRUCT(CLONE_CHILD_CLEARTID),
-               VALSTR_STRUCT(CLONE_DETACHED),
-               VALSTR_STRUCT(CLONE_UNTRACED),
-               VALSTR_STRUCT(CLONE_CHILD_SETTID),
-               VALSTR_STRUCT(CLONE_NEWCGROUP),
-               VALSTR_STRUCT(CLONE_NEWUTS),
-               VALSTR_STRUCT(CLONE_NEWIPC),
-               VALSTR_STRUCT(CLONE_NEWUSER),
-               VALSTR_STRUCT(CLONE_NEWPID),
-               VALSTR_STRUCT(CLONE_NEWNET),
-               VALSTR_STRUCT(CLONE_IO),
+               NS_VALSTR_STRUCT(CLONE_VM),
+               NS_VALSTR_STRUCT(CLONE_FS),
+               NS_VALSTR_STRUCT(CLONE_FILES),
+               NS_VALSTR_STRUCT(CLONE_SIGHAND),
+               NS_VALSTR_STRUCT(CLONE_PTRACE),
+               NS_VALSTR_STRUCT(CLONE_VFORK),
+               NS_VALSTR_STRUCT(CLONE_PARENT),
+               NS_VALSTR_STRUCT(CLONE_THREAD),
+               NS_VALSTR_STRUCT(CLONE_NEWNS),
+               NS_VALSTR_STRUCT(CLONE_SYSVSEM),
+               NS_VALSTR_STRUCT(CLONE_SETTLS),
+               NS_VALSTR_STRUCT(CLONE_PARENT_SETTID),
+               NS_VALSTR_STRUCT(CLONE_CHILD_CLEARTID),
+               NS_VALSTR_STRUCT(CLONE_DETACHED),
+               NS_VALSTR_STRUCT(CLONE_UNTRACED),
+               NS_VALSTR_STRUCT(CLONE_CHILD_SETTID),
+               NS_VALSTR_STRUCT(CLONE_NEWCGROUP),
+               NS_VALSTR_STRUCT(CLONE_NEWUTS),
+               NS_VALSTR_STRUCT(CLONE_NEWIPC),
+               NS_VALSTR_STRUCT(CLONE_NEWUSER),
+               NS_VALSTR_STRUCT(CLONE_NEWPID),
+               NS_VALSTR_STRUCT(CLONE_NEWNET),
+               NS_VALSTR_STRUCT(CLONE_IO),
        };
 
        for (size_t i = 0; i < ARRAYSIZE(cloneFlags); i++) {
diff --git a/util.c b/util.c
index db0e80e..610e402 100644 (file)
--- a/util.c
+++ b/util.c
@@ -255,10 +255,6 @@ uint64_t utilRnd64(void)
        return rndX;
 }
 
-#define VALSTR_STRUCT(x) \
-       {                \
-               x, #x    \
-       }
 const char* utilSigName(int signo)
 {
        static __thread char sigstr[32];
@@ -268,35 +264,35 @@ const char* utilSigName(int signo)
                const int signo;
                const char* const name;
        } const sigNames[] = {
-               VALSTR_STRUCT(SIGINT),
-               VALSTR_STRUCT(SIGILL),
-               VALSTR_STRUCT(SIGABRT),
-               VALSTR_STRUCT(SIGFPE),
-               VALSTR_STRUCT(SIGSEGV),
-               VALSTR_STRUCT(SIGTERM),
-               VALSTR_STRUCT(SIGHUP),
-               VALSTR_STRUCT(SIGQUIT),
-               VALSTR_STRUCT(SIGTRAP),
-               VALSTR_STRUCT(SIGKILL),
-               VALSTR_STRUCT(SIGBUS),
-               VALSTR_STRUCT(SIGSYS),
-               VALSTR_STRUCT(SIGPIPE),
-               VALSTR_STRUCT(SIGALRM),
-               VALSTR_STRUCT(SIGURG),
-               VALSTR_STRUCT(SIGSTOP),
-               VALSTR_STRUCT(SIGTSTP),
-               VALSTR_STRUCT(SIGCONT),
-               VALSTR_STRUCT(SIGCHLD),
-               VALSTR_STRUCT(SIGTTIN),
-               VALSTR_STRUCT(SIGTTOU),
-               VALSTR_STRUCT(SIGPOLL),
-               VALSTR_STRUCT(SIGXCPU),
-               VALSTR_STRUCT(SIGXFSZ),
-               VALSTR_STRUCT(SIGVTALRM),
-               VALSTR_STRUCT(SIGPROF),
-               VALSTR_STRUCT(SIGUSR1),
-               VALSTR_STRUCT(SIGUSR2),
-               VALSTR_STRUCT(SIGWINCH),
+               NS_VALSTR_STRUCT(SIGINT),
+               NS_VALSTR_STRUCT(SIGILL),
+               NS_VALSTR_STRUCT(SIGABRT),
+               NS_VALSTR_STRUCT(SIGFPE),
+               NS_VALSTR_STRUCT(SIGSEGV),
+               NS_VALSTR_STRUCT(SIGTERM),
+               NS_VALSTR_STRUCT(SIGHUP),
+               NS_VALSTR_STRUCT(SIGQUIT),
+               NS_VALSTR_STRUCT(SIGTRAP),
+               NS_VALSTR_STRUCT(SIGKILL),
+               NS_VALSTR_STRUCT(SIGBUS),
+               NS_VALSTR_STRUCT(SIGSYS),
+               NS_VALSTR_STRUCT(SIGPIPE),
+               NS_VALSTR_STRUCT(SIGALRM),
+               NS_VALSTR_STRUCT(SIGURG),
+               NS_VALSTR_STRUCT(SIGSTOP),
+               NS_VALSTR_STRUCT(SIGTSTP),
+               NS_VALSTR_STRUCT(SIGCONT),
+               NS_VALSTR_STRUCT(SIGCHLD),
+               NS_VALSTR_STRUCT(SIGTTIN),
+               NS_VALSTR_STRUCT(SIGTTOU),
+               NS_VALSTR_STRUCT(SIGPOLL),
+               NS_VALSTR_STRUCT(SIGXCPU),
+               NS_VALSTR_STRUCT(SIGXFSZ),
+               NS_VALSTR_STRUCT(SIGVTALRM),
+               NS_VALSTR_STRUCT(SIGPROF),
+               NS_VALSTR_STRUCT(SIGUSR1),
+               NS_VALSTR_STRUCT(SIGUSR2),
+               NS_VALSTR_STRUCT(SIGWINCH),
        };
 
        for (size_t i = 0; i < ARRAYSIZE(sigNames); i++) {