|
33 | 33 |
|
34 | 34 | #include "src/libdiod/diod_log.h" |
35 | 35 |
|
36 | | -#include "test.h" |
| 36 | +static inline void |
| 37 | +_lock (pthread_mutex_t *l) |
| 38 | +{ |
| 39 | + int n = pthread_mutex_lock (l); |
| 40 | + if (n) |
| 41 | + errn_exit (n, "_lock"); |
| 42 | +} |
| 43 | +static inline void |
| 44 | +_unlock (pthread_mutex_t *l) |
| 45 | +{ |
| 46 | + int n = pthread_mutex_unlock (l); |
| 47 | + if (n) |
| 48 | + errn_exit (n, "_unlock"); |
| 49 | +} |
| 50 | +static inline void |
| 51 | +_condsig (pthread_cond_t *c) |
| 52 | +{ |
| 53 | + int n = pthread_cond_signal (c); |
| 54 | + if (n) |
| 55 | + errn_exit (n, "_condsig"); |
| 56 | +} |
| 57 | +static inline void |
| 58 | +_condwait (pthread_cond_t *c, pthread_mutex_t *l) |
| 59 | +{ |
| 60 | + int n = pthread_cond_wait (c, l); |
| 61 | + if (n) |
| 62 | + errn_exit (n, "_condwait"); |
| 63 | +} |
| 64 | +static inline void |
| 65 | +_create (pthread_t *t, void *(f)(void *), void *a) |
| 66 | +{ |
| 67 | + int n = pthread_create (t, NULL, f, a); |
| 68 | + if (n) |
| 69 | + errn_exit (n,"_create"); |
| 70 | +} |
| 71 | +static inline void |
| 72 | +_join (pthread_t t, void **a) |
| 73 | +{ |
| 74 | + int n = pthread_join (t, a); |
| 75 | + if (n) |
| 76 | + errn_exit (n,"_join"); |
| 77 | +} |
| 78 | +static inline int |
| 79 | +_mkstemp (char *p) |
| 80 | +{ |
| 81 | + int fd = mkstemp (p); |
| 82 | + if (fd < 0) |
| 83 | + err_exit ("_mkstemp"); |
| 84 | + return fd; |
| 85 | +} |
| 86 | +static inline void |
| 87 | +_fstat (int fd, struct stat *sb) |
| 88 | +{ |
| 89 | + if (fstat (fd, sb) < 0) |
| 90 | + err_exit ("_fstat"); |
| 91 | +} |
| 92 | +static inline void |
| 93 | +_unlink (char *p) |
| 94 | +{ |
| 95 | + if (unlink (p) < 0) |
| 96 | + err_exit ("_unlink"); |
| 97 | +} |
| 98 | +static inline void |
| 99 | +_fchown (int fd, uid_t u, gid_t g) |
| 100 | +{ |
| 101 | + if (fchown (fd, u, g) < 0) |
| 102 | + err_exit ("_fchown"); |
| 103 | +} |
| 104 | +static inline void |
| 105 | +_fchmod (int fd, mode_t m) |
| 106 | +{ |
| 107 | + if (fchmod (fd, m) < 0) |
| 108 | + err_exit ("_fchmod"); |
| 109 | +} |
| 110 | +static inline void |
| 111 | +_setgroups (size_t s, gid_t *g) |
| 112 | +{ |
| 113 | + if (setgroups (s, g) < 0) |
| 114 | + err_exit ("_setgroups"); |
| 115 | +} |
| 116 | +static inline int |
| 117 | +_getgroups (size_t s, gid_t *g) |
| 118 | +{ |
| 119 | + int n = getgroups (s, g); |
| 120 | + if (n < 0) |
| 121 | + err_exit ("_getgroups"); |
| 122 | + return n; |
| 123 | +} |
| 124 | +static inline void |
| 125 | +_setreuid (uid_t r, uid_t u) |
| 126 | +{ |
| 127 | + if (setreuid (r, u) < 0) |
| 128 | + err_exit ("_setreuid"); |
| 129 | +} |
| 130 | +static inline void |
| 131 | +_setregid (gid_t r, gid_t g) |
| 132 | +{ |
| 133 | + if (setregid (r, g) < 0) |
| 134 | + err_exit ("_setregid"); |
| 135 | +} |
37 | 136 |
|
38 | 137 | int |
39 | 138 | main (int argc, char *argv[]) |
|
0 commit comments