diff options
| author | Mattias Andrée <maandree@kth.se> | 2017-04-09 23:46:17 +0200 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2017-04-09 23:46:17 +0200 |
| commit | dac6950d9e556d5521ad7913d27a6cf83e2a90a1 (patch) | |
| tree | bb6a65d973337a0504117888d5534967cc51f479 /src/util | |
| parent | Clean up (diff) | |
| download | blind-dac6950d9e556d5521ad7913d27a6cf83e2a90a1.tar.gz blind-dac6950d9e556d5521ad7913d27a6cf83e2a90a1.tar.bz2 blind-dac6950d9e556d5521ad7913d27a6cf83e2a90a1.tar.xz | |
Clean up
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
| -rw-r--r-- | src/util.c | 7 | ||||
| -rw-r--r-- | src/util.h | 1 | ||||
| -rw-r--r-- | src/util/efunc.h | 74 | ||||
| -rw-r--r-- | src/util/io.h | 13 | ||||
| -rw-r--r-- | src/util/jobs.h | 9 |
5 files changed, 98 insertions, 6 deletions
@@ -1,9 +1,6 @@ /* See LICENSE file for copyright and license details. */ #include "util.h" -#if defined(HAVE_PRCTL) -# include <sys/prctl.h> -#endif #include <sys/wait.h> #include <ctype.h> #include <errno.h> @@ -200,9 +197,7 @@ enfork_jobs(int status, size_t *start, size_t *end, size_t jobs, pid_t **pids) for (j = 1; j < jobs; j++) { pid = enfork(status); if (!pid) { -#if defined(HAVE_PRCTL) && defined(PR_SET_PDEATHSIG) - prctl(PR_SET_PDEATHSIG, SIGKILL); -#endif + pdeath(SIGKILL); *start = n * (j + 0) / jobs + s; *end = n * (j + 1) / jobs + s; return 0; @@ -20,3 +20,4 @@ #include "util/io.h" #include "util/jobs.h" #include "util/endian.h" +#include "util/efunc.h" diff --git a/src/util/efunc.h b/src/util/efunc.h new file mode 100644 index 0000000..03d1609 --- /dev/null +++ b/src/util/efunc.h @@ -0,0 +1,74 @@ +/* See LICENSE file for copyright and license details. */ +#include <sys/wait.h> +#include <unistd.h> + +#define eexecvp(F, ...) (execvp(F, __VA_ARGS__), eprintf("exec %s:", F)) +#define eexeclp(F, ...) (execlp(F, __VA_ARGS__), eprintf("exec %s:", F)) + +static inline void +epipe(int fds[2]) +{ + if (pipe(fds)) + eprintf("pipe:"); +} + +static inline pid_t +efork(void) +{ + pid_t ret = fork(); + if (ret < 0) + eprintf("fork:"); + return ret; +} + +static inline void +edup2(int old, int new) +{ + if (dup2(old, new) < 0) + eprintf("dup2:"); +} + +static inline int +edup(int fd) +{ + int ret = dup(fd); + if (ret < 0) + eprintf("dup:"); + return ret; +} + +static inline pid_t +ewaitpid(pid_t pid, int *status, int flags) +{ + pid_t ret = waitpid(pid, status, flags); + if (ret < 0) + eprintf("waitpid:"); + return ret; +} + +static inline size_t +eread(int fd, void *buf, size_t n, const char *fname) +{ + ssize_t ret = read(fd, buf, n); + if (ret < 0) + eprintf("read %s:", fname); + return (size_t)ret; +} + +static inline size_t +epread(int fd, void *buf, size_t n, off_t off, const char *fname) +{ + ssize_t ret = pread(fd, buf, n, off); + if (ret < 0) + eprintf("pread %s:", fname); + return (size_t)ret; +} + +static inline off_t +elseek(int fd, off_t offset, int whence, const char *fname) +{ + off_t ret = lseek(fd, offset, whence); + if (ret < 0) + eprintf("lseek %s:", fname); + return ret; +} diff --git a/src/util/io.h b/src/util/io.h index 44e222d..8c646cb 100644 --- a/src/util/io.h +++ b/src/util/io.h @@ -1,4 +1,17 @@ /* See LICENSE file for copyright and license details. */ +#include <fcntl.h> + +#if defined(POSIX_FADV_SEQUENTIAL) +# define fadvise_sequential(...) posix_fadvise(__VA_ARGS__, POSIX_FADV_SEQUENTIAL) +#else +# define fadvise_sequential(...) +#endif + +#if defined(POSIX_FADV_RANDOM) +# define fadvise_random(...) posix_fadvise(__VA_ARGS__, POSIX_FADV_RANDOM) +#else +# define fadvise_random(...) +#endif #define ewriteall(...) enwriteall(1, __VA_ARGS__) #define ereadall(...) enreadall(1, __VA_ARGS__) diff --git a/src/util/jobs.h b/src/util/jobs.h index d45433c..9accf84 100644 --- a/src/util/jobs.h +++ b/src/util/jobs.h @@ -1,4 +1,13 @@ /* See LICENSE file for copyright and license details. */ +#if defined(HAVE_PRCTL) +# include <sys/prctl.h> +#endif + +#if defined(HAVE_PRCTL) && defined(PR_SET_PDEATHSIG) +# define pdeath(SIGNAL) prctl(PR_SET_PDEATHSIG, SIGNAL); +#else +# define pdeath(SIGNAL) +#endif #define efork_jobs(...) enfork_jobs(1, __VA_ARGS__) #define ejoin_jobs(...) enjoin_jobs(1, __VA_ARGS__) |
