skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

commit 16013c560e189bd0c4fb58e038c0f449542dba7a
parent 538fd727337959b1d7b8449a578a31fd9a9c62b4
Author: Laurent Bercot <ska-skaware@skarnet.org>
Date:   Sun, 16 Jul 2017 11:19:51 +0000

 Add egidingroups sysdeps, change fd_close() to void and saving errno, propagate changes

Diffstat:
Msrc/include/skalibs/djbunix.h | 2+-
Msrc/include/skalibs/unix-transactional.h | 2+-
Msrc/librandom/random_init.c | 2--
Msrc/libstddjb/cdb_mapfile.c | 3---
Msrc/libstddjb/child_spawn0.c | 4----
Msrc/libstddjb/child_spawn1_internal.c | 6------
Msrc/libstddjb/doublefork.c | 2--
Msrc/libstddjb/fd_close.c | 11++++-------
Msrc/libstddjb/fd_ensure_open.c | 2--
Msrc/libstddjb/fd_move.c | 4+++-
Msrc/libstddjb/fd_move2.c | 2--
Msrc/libstddjb/filecopy_unsafe.c | 23+++++++----------------
Msrc/libstddjb/iobufferk_finish.c | 5-----
Msrc/libstddjb/ipc_accept.c | 4+---
Msrc/libstddjb/openreadfileclose.c | 7+------
Msrc/libstddjb/openreadnclose.c | 2--
Msrc/libstddjb/openslurpclose.c | 4----
Msrc/libstddjb/pipe_internal.c | 3---
Msrc/libstddjb/socket_accept4.c | 2--
Msrc/libstddjb/socket_accept6.c | 2--
Msrc/libstddjb/socket_internal.c | 3---
Msrc/libstddjb/socket_tcp6.c | 4+---
Msrc/libstddjb/socket_udp6.c | 4+---
Msrc/libstddjb/socketpair_internal.c | 8++------
Msrc/libstddjb/touch.c | 11++++++-----
Msrc/libunixonacid/dd_cancel.c | 3---
Msrc/libunixonacid/dd_close.c | 4++--
Msrc/libunixonacid/open2_at.c | 22+++++++++-------------
Msrc/libunixonacid/open3_at.c | 22+++++++++-------------
Msrc/libunixonacid/opengetlnclose.c | 4----
Msrc/libunixonacid/opengetlnclose_at.c | 4----
Msrc/libunixonacid/openslurpclose_at.c | 3---
Msrc/libunixonacid/openwritenclose_at.c | 9+--------
Msrc/libunixonacid/openwritevnclose_at.c | 9+--------
Msrc/libunixonacid/skaclient_server_ack.c | 2--
Msrc/libunixonacid/skaclient_start_async.c | 2--
Msrc/libunixonacid/skaclient_startf_async.c | 4++--
Msrc/libunixonacid/stat_at.c | 5+----
Msrc/libunixonacid/unixmessage_drop.c | 3---
Msrc/libunixonacid/unixmessage_receive.c | 2--
Asrc/sysdeps/tryegidingroups.c | 39+++++++++++++++++++++++++++++++++++++++
41 files changed, 92 insertions(+), 167 deletions(-)

diff --git a/src/include/skalibs/djbunix.h b/src/include/skalibs/djbunix.h @@ -26,7 +26,7 @@ extern int fd_copy (int, int) ; extern int fd_copy2 (int, int, int, int) ; extern int fd_move (int, int) ; extern int fd_move2 (int, int, int, int) ; -extern int fd_close (int) ; +extern void fd_close (int) ; extern int fd_chmod (int, unsigned int) ; extern int fd_chown (int, uid_t, gid_t) ; extern int fd_sync (int) ; diff --git a/src/include/skalibs/unix-transactional.h b/src/include/skalibs/unix-transactional.h @@ -56,7 +56,7 @@ struct dirdescriptor_s extern int dd_open_read (dirdescriptor_t *, char const *) ; extern int dd_open_write (dirdescriptor_t *, char const *, unsigned int) ; -extern int dd_close (dirdescriptor_t *) ; /* after dd_open_read */ +extern void dd_close (dirdescriptor_t *) ; /* after dd_open_read */ extern void dd_cancel (dirdescriptor_t *) ; /* after dd_open_write */ extern int dd_commit (dirdescriptor_t *) ; /* after dd_open_write */ extern int dd_commit_devino (dirdescriptor_t *, dev_t *, ino_t *) ; /* after dd_open_write */ diff --git a/src/librandom/random_init.c b/src/librandom/random_init.c @@ -62,9 +62,7 @@ int random_init () if (fd < 0) return 0 ; if (coe(fd) < 0) { - int e = errno ; fd_close(fd) ; - errno = e ; return 0 ; } random_fd = fd ; diff --git a/src/libstddjb/cdb_mapfile.c b/src/libstddjb/cdb_mapfile.c @@ -1,6 +1,5 @@ /* ISC license. */ -#include <errno.h> #include <skalibs/djbunix.h> #include <skalibs/cdb.h> @@ -10,9 +9,7 @@ int cdb_mapfile (struct cdb *c, char const *file) if (fd < 0) return 0 ; if (!cdb_init_map(c, fd, 1)) { - int e = errno ; fd_close(fd) ; - errno = e ; return 0 ; } fd_close(fd) ; diff --git a/src/libstddjb/child_spawn0.c b/src/libstddjb/child_spawn0.c @@ -59,10 +59,8 @@ pid_t child_spawn0 (char const *prog, char const *const *argv, char const *const pid = fork() ; if (pid < 0) { - e = errno ; fd_close(p[1]) ; fd_close(p[0]) ; - errno = e ; return 0 ; } if (!pid) @@ -83,9 +81,7 @@ pid_t child_spawn0 (char const *prog, char const *const *argv, char const *const p[1] = fd_read(p[0], (char *)&e, sizeof(e)) ; if (p[1] < 0) { - e = errno ; fd_close(p[0]) ; - errno = e ; return 0 ; } fd_close(p[0]) ; diff --git a/src/libstddjb/child_spawn1_internal.c b/src/libstddjb/child_spawn1_internal.c @@ -77,21 +77,17 @@ pid_t child_spawn1_internal (char const *prog, char const *const *argv, char con pid_t pid ; if (coe(p[0]) < 0 || pipecoe(syncp) < 0) { - e = errno ; fd_close(p[1]) ; fd_close(p[0]) ; - errno = e ; return 0 ; } pid = fork() ; if (pid < 0) { - e = errno ; fd_close(syncp[1]) ; fd_close(syncp[0]) ; fd_close(p[1]) ; fd_close(p[0]) ; - errno = e ; return 0 ; } if (!pid) @@ -117,10 +113,8 @@ err: syncp[1] = fd_read(syncp[0], (char *)&e, sizeof(e)) ; if (syncp[1] < 0) { - e = errno ; fd_close(syncp[0]) ; fd_close(p[!(to & 1)]) ; - errno = e ; return 0 ; } fd_close(syncp[0]) ; diff --git a/src/libstddjb/doublefork.c b/src/libstddjb/doublefork.c @@ -18,10 +18,8 @@ pid_t doublefork () { case -1: { - int e = errno ; fd_close(fd[1]) ; fd_close(fd[0]) ; - errno = e ; return -1 ; } case 0: diff --git a/src/libstddjb/fd_close.c b/src/libstddjb/fd_close.c @@ -4,12 +4,9 @@ #include <errno.h> #include <skalibs/djbunix.h> -int fd_close (int fd) +void fd_close (int fd) { - for (;;) - { - if (!close(fd) || errno == EINPROGRESS) break ; - if (errno != EINTR) return -1 ; - } - return 0 ; + int e = errno ; + while (close(fd) < 0 && errno == EINTR) ; + errno = e ; } diff --git a/src/libstddjb/fd_ensure_open.c b/src/libstddjb/fd_ensure_open.c @@ -15,9 +15,7 @@ int fd_ensure_open (int fd, int w) if (newfd < 0) return 0 ; if (fd_move(fd, newfd) < 0) { - int e = errno ; fd_close(newfd) ; - errno = e ; return 0 ; } } diff --git a/src/libstddjb/fd_move.c b/src/libstddjb/fd_move.c @@ -11,5 +11,7 @@ int fd_move (int to, int from) do r = dup2(from, to) ; while ((r == -1) && (errno == EINTR)) ; - return (r == -1) ? -1 : fd_close(from) ; + if (r < 0) return r ; + fd_close(from) ; + return 0 ; } diff --git a/src/libstddjb/fd_move2.c b/src/libstddjb/fd_move2.c @@ -18,9 +18,7 @@ int fd_move2 (int to1, int from1, int to2, int from2) } if (fd_copy(to1, from1) == -1) { - int e = errno ; if (from2 != tmp) fd_close(tmp) ; - errno = e ; return -1 ; } if (fd_copy(to2, tmp) == -1) diff --git a/src/libstddjb/filecopy_unsafe.c b/src/libstddjb/filecopy_unsafe.c @@ -1,6 +1,5 @@ /* ISC license. */ -#include <errno.h> #include <fcntl.h> #include <skalibs/djbunix.h> @@ -10,23 +9,15 @@ int filecopy_unsafe (char const *src, char const *dst, unsigned int mode) int s = open2(src, O_RDONLY) ; if (s < 0) return 0 ; d = open3(dst, O_WRONLY | O_CREAT | O_TRUNC, mode) ; - if (d < 0) - { - int e = errno ; - fd_close(s) ; - errno = e ; - return 0 ; - } - if (fd_cat(s, d) < 0) - { - int e = errno ; - fd_close(d) ; - fd_close(s) ; - errno = e ; - return 0 ; - } + if (d < 0) goto errs ; + if (fd_cat(s, d) < 0) goto errd ; fd_close(d) ; fd_close(s) ; return 1 ; +errd: + fd_close(d) ; +errs: + fd_close(s) ; + return 0 ; } diff --git a/src/libstddjb/iobufferk_finish.c b/src/libstddjb/iobufferk_finish.c @@ -4,7 +4,6 @@ #ifdef SKALIBS_HASSPLICE -#include <errno.h> #include <skalibs/djbunix.h> #include <skalibs/iobuffer.h> @@ -15,17 +14,13 @@ static void iobufferk_nop (iobufferk *k) static void iobufferk_finish_0 (iobufferk *k) { - int e = errno ; fd_close(k->p[1]) ; - errno = e ; } static void iobufferk_finish_3 (iobufferk *k) { - int e = errno ; fd_close(k->p[1]) ; fd_close(k->p[0]) ; - errno = e ; } iobufferk_finish_func_t_ref const iobufferk_finish_f[4] = diff --git a/src/libstddjb/ipc_accept.c b/src/libstddjb/ipc_accept.c @@ -2,10 +2,10 @@ #include <skalibs/sysdeps.h> #include <skalibs/nonposix.h> -#include <errno.h> #include <sys/socket.h> #include <sys/un.h> #include <string.h> +#include <errno.h> #include <skalibs/bytestr.h> #include <skalibs/djbunix.h> #include <skalibs/webipc.h> @@ -28,9 +28,7 @@ int ipc_accept_internal (int s, char *p, size_t l, int *trunc, unsigned int opti if ((((options & DJBUNIX_FLAG_NB) ? ndelay_on(fd) : ndelay_off(fd)) < 0) || (((options & DJBUNIX_FLAG_COE) ? coe(fd) : uncoe(fd)) < 0)) { - int e = errno ; fd_close(fd) ; - errno = e ; return -1 ; } #endif diff --git a/src/libstddjb/openreadfileclose.c b/src/libstddjb/openreadfileclose.c @@ -1,7 +1,6 @@ /* ISC license. */ #include <sys/stat.h> -#include <errno.h> #include <skalibs/allreadwrite.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> @@ -27,10 +26,6 @@ int openreadfileclose (char const *file, stralloc *sa, size_t limit) return 1 ; err: - { - int e = errno ; - fd_close(fd) ; - errno = e ; - } + fd_close(fd) ; return 0 ; } diff --git a/src/libstddjb/openreadnclose.c b/src/libstddjb/openreadnclose.c @@ -12,9 +12,7 @@ static ssize_t readnclose (int fd, char *s, size_t n) r = allread(fd, s, n) ; if (errno) { - int e = errno ; fd_close(fd) ; - errno = e ; return -1 ; } fd_close(fd) ; diff --git a/src/libstddjb/openslurpclose.c b/src/libstddjb/openslurpclose.c @@ -1,18 +1,14 @@ /* ISC license. */ -#include <errno.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> int openslurpclose (stralloc *sa, char const *fn) { int r ; - int e ; int fd = open_readb(fn) ; if (fd == -1) return 0 ; r = slurp(sa, fd) ; - e = errno ; fd_close(fd) ; - errno = e ; return r ; } diff --git a/src/libstddjb/pipe_internal.c b/src/libstddjb/pipe_internal.c @@ -17,7 +17,6 @@ int pipe_internal (int *p, unsigned int flags) #else #include <unistd.h> -#include <errno.h> #include <skalibs/djbunix.h> int pipe_internal (int *p, unsigned int flags) @@ -32,10 +31,8 @@ int pipe_internal (int *p, unsigned int flags) return 0 ; err: { - int e = errno ; fd_close(pi[1]) ; fd_close(pi[0]) ; - errno = e ; } return -1 ; } diff --git a/src/libstddjb/socket_accept4.c b/src/libstddjb/socket_accept4.c @@ -27,9 +27,7 @@ int socket_accept4_internal (int s, char *ip, uint16_t *port, unsigned int optio if ((((options & DJBUNIX_FLAG_NB) ? ndelay_on(fd) : ndelay_off(fd)) < 0) || (((options & DJBUNIX_FLAG_COE) ? coe(fd) : uncoe(fd)) < 0)) { - int e = errno ; fd_close(fd) ; - errno = e ; return -1 ; } #endif diff --git a/src/libstddjb/socket_accept6.c b/src/libstddjb/socket_accept6.c @@ -30,9 +30,7 @@ int socket_accept6_internal (int s, char *ip6, uint16_t *port, unsigned int opti if ((((options & DJBUNIX_FLAG_NB) ? ndelay_on(fd) : ndelay_off(fd)) < 0) || (((options & DJBUNIX_FLAG_COE) ? coe(fd) : uncoe(fd)) < 0)) { - int e = errno ; fd_close(fd) ; - errno = e ; return -1 ; } #endif diff --git a/src/libstddjb/socket_internal.c b/src/libstddjb/socket_internal.c @@ -3,7 +3,6 @@ #include <skalibs/sysdeps.h> #include <skalibs/nonposix.h> #include <sys/socket.h> -#include <errno.h> #include <skalibs/djbunix.h> #ifdef SKALIBS_HASACCEPT4 @@ -22,9 +21,7 @@ int socket_internal (int domain, int type, int protocol, unsigned int flags) if ((((flags & DJBUNIX_FLAG_NB) ? ndelay_on(s) : ndelay_off(s)) < 0) || (((flags & DJBUNIX_FLAG_COE) ? coe(s) : uncoe(s)) < 0)) { - int e = errno ; fd_close(s) ; - errno = e ; return -1 ; } return s ; diff --git a/src/libstddjb/socket_tcp6.c b/src/libstddjb/socket_tcp6.c @@ -1,9 +1,9 @@ /* ISC license. */ #include <skalibs/nonposix.h> -#include <errno.h> #include <sys/socket.h> #include <netinet/in.h> +#include <errno.h> #include <skalibs/djbunix.h> #include <skalibs/ip46.h> #include <skalibs/socket.h> @@ -18,9 +18,7 @@ int socket_tcp6_internal (unsigned int flags) int option = 1 ; if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &option, sizeof(option)) < 0) { - int e = errno ; fd_close(fd) ; - errno = e ; return -1 ; } } diff --git a/src/libstddjb/socket_udp6.c b/src/libstddjb/socket_udp6.c @@ -1,9 +1,9 @@ /* ISC license. */ #include <skalibs/nonposix.h> -#include <errno.h> #include <sys/socket.h> #include <netinet/in.h> +#include <errno.h> #include <skalibs/djbunix.h> #include <skalibs/ip46.h> #include <skalibs/socket.h> @@ -18,9 +18,7 @@ int socket_udp6_internal (unsigned int flags) int option = 1 ; if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &option, sizeof(option)) < 0) { - int e = errno ; fd_close(fd) ; - errno = e ; return -1 ; } } diff --git a/src/libstddjb/socketpair_internal.c b/src/libstddjb/socketpair_internal.c @@ -44,12 +44,8 @@ int socketpair_internal (int domain, int type, int protocol, unsigned int flags, return 0 ; err: - { - int e = errno ; - fd_close(fd[1]) ; - fd_close(fd[0]) ; - errno = e ; - } + fd_close(fd[1]) ; + fd_close(fd[0]) ; return -1 ; } diff --git a/src/libstddjb/touch.c b/src/libstddjb/touch.c @@ -11,11 +11,12 @@ int touch (char const *file) { + int r ; int fd = open_create(file) ; if (fd < 0) return 0 ; - if (futimens(fd, 0) < 0) return 0 ; + r = futimens(fd, 0) >= 0 ; fd_close(fd) ; - return 1 ; + return r ; } #else @@ -27,9 +28,10 @@ int touch (char const *file) int touch (char const *file) { + int r ; int fd = open_create(file) ; if (fd < 0) return 0 ; - if (futimes(fd, 0) < 0) return 0 ; + r = futimes(fd, 0) >= 0 ; fd_close(fd) ; return 1 ; } @@ -44,8 +46,7 @@ int touch (char const *file) int fd = open_create(file) ; if (fd < 0) return 0 ; fd_close(fd) ; - if (utimes(file, 0) < 0) return 0 ; - return 1 ; + return utimes(file, 0) >= 0 ; } #endif diff --git a/src/libunixonacid/dd_cancel.c b/src/libunixonacid/dd_cancel.c @@ -1,6 +1,5 @@ /* ISC license. */ -#include <errno.h> #include <skalibs/stralloc.h> #include <skalibs/djbunix.h> #include <skalibs/unix-transactional.h> @@ -8,10 +7,8 @@ void dd_cancel (dirdescriptor_t *dd) { dirdescriptor_t zero = DIRDESCRIPTOR_ZERO ; - int e = errno ; fd_close(dd->fd) ; rm_rf_in_tmp(&dd->new, 0) ; stralloc_free(&dd->new) ; *dd = zero ; - errno = e ; } diff --git a/src/libunixonacid/dd_close.c b/src/libunixonacid/dd_close.c @@ -3,7 +3,7 @@ #include <skalibs/djbunix.h> #include <skalibs/unix-transactional.h> -int dd_close (dirdescriptor_t *dd) +void dd_close (dirdescriptor_t *dd) { - return (fd_close(dd->fd) >= 0) ; + fd_close(dd->fd) ; } diff --git a/src/libunixonacid/open2_at.c b/src/libunixonacid/open2_at.c @@ -30,30 +30,26 @@ int open2_at (int dirfd, char const *file, int flags) int fd ; int fdhere = open_read(".") ; if (fdhere < 0) return -1 ; - if (fd_chdir(dirfd) < 0) - { - int e = errno ; - fd_close(fdhere) ; - errno = e ; - return -1 ; - } + if (fd_chdir(dirfd) < 0) goto errclose ; fd = open2(file, flags) ; if (fd < 0) { int e = errno ; fd_chdir(fdhere) ; - fd_close(fdhere) ; errno = e ; - return -1 ; + goto errclose ; } if (fd_chdir(fdhere) < 0) { - int e = errno ; - fd_close(fdhere) ; - errno = e ; - return -1 ; + fd_close(fd) ; + goto errclose ; } + fd_close(fdhere) ; return fd ; + + errclose: + fd_close(fdhere) ; + return -1 ; } #endif diff --git a/src/libunixonacid/open3_at.c b/src/libunixonacid/open3_at.c @@ -30,30 +30,26 @@ int open3_at (int dirfd, char const *file, int flags, unsigned int mode) int fd ; int fdhere = open_read(".") ; if (fdhere < 0) return -1 ; - if (fd_chdir(dirfd) < 0) - { - int e = errno ; - fd_close(fdhere) ; - errno = e ; - return -1 ; - } + if (fd_chdir(dirfd) < 0) goto errclose ; fd = open3(file, flags, mode) ; if (fd < 0) { int e = errno ; fd_chdir(fdhere) ; - fd_close(fdhere) ; errno = e ; - return -1 ; + goto errclose ; } if (fd_chdir(fdhere) < 0) { - int e = errno ; - fd_close(fdhere) ; - errno = e ; - return -1 ; + fd_close(fd) ; + goto errclose ; } + fd_close(fdhere) ; return fd ; + + errclose: + fd_close(fdhere) ; + return -1 ; } #endif diff --git a/src/libunixonacid/opengetlnclose.c b/src/libunixonacid/opengetlnclose.c @@ -1,6 +1,5 @@ /* ISC license. */ -#include <errno.h> #include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> #include <skalibs/djbunix.h> @@ -12,13 +11,10 @@ int opengetlnclose (char const *fn, stralloc *sa, int sep) char buf[BUFFER_INSIZE] ; buffer b ; int r ; - int e ; int fd = open_readb(fn) ; if (fd < 0) return -1 ; buffer_init(&b, &fd_readv, fd, buf, BUFFER_INSIZE) ; r = skagetln(&b, sa, sep) ; - e = errno ; fd_close(fd) ; - errno = e ; return r ; } diff --git a/src/libunixonacid/opengetlnclose_at.c b/src/libunixonacid/opengetlnclose_at.c @@ -1,6 +1,5 @@ /* ISC license. */ -#include <errno.h> #include <skalibs/allreadwrite.h> #include <skalibs/buffer.h> #include <skalibs/djbunix.h> @@ -12,13 +11,10 @@ int opengetlnclose_at (int dirfd, char const *fn, stralloc *sa, int sep) char buf[BUFFER_INSIZE] ; buffer b ; int r ; - int e ; int fd = open_readatb(dirfd, fn) ; if (fd < 0) return -1 ; buffer_init(&b, &buffer_read, fd, buf, BUFFER_INSIZE) ; r = skagetln(&b, sa, sep) ; - e = errno ; fd_close(fd) ; - errno = e ; return r ; } diff --git a/src/libunixonacid/openslurpclose_at.c b/src/libunixonacid/openslurpclose_at.c @@ -1,6 +1,5 @@ /* ISC license. */ -#include <errno.h> #include <skalibs/djbunix.h> #include <skalibs/unix-transactional.h> @@ -10,9 +9,7 @@ int openslurpclose_at (int dirfd, char const *fn, stralloc *sa) if (fd < 0) return 0 ; if (!slurp(sa, fd)) { - int e = errno ; fd_close(fd) ; - errno = e ; return 0 ; } fd_close(fd) ; diff --git a/src/libunixonacid/openwritenclose_at.c b/src/libunixonacid/openwritenclose_at.c @@ -1,7 +1,6 @@ /* ISC license. */ #include <unistd.h> -#include <errno.h> #include <skalibs/allreadwrite.h> #include <skalibs/djbunix.h> #include <skalibs/unix-transactional.h> @@ -12,13 +11,7 @@ size_t openwritenclose_at (int dirfd, char const *file, char const *s, size_t n) int fd = open_truncatb(dirfd, file) ; if (fd < 0) return 0 ; r = allwrite(fd, s, n) ; - if ((r < n) || (fsync(fd) < 0)) - { - int e = errno ; - fd_close(fd) ; - errno = e ; - return r ; - } + if (r >= n) fsync(fd) ; fd_close(fd) ; return r ; } diff --git a/src/libunixonacid/openwritevnclose_at.c b/src/libunixonacid/openwritevnclose_at.c @@ -2,7 +2,6 @@ #include <sys/uio.h> #include <unistd.h> -#include <errno.h> #include <skalibs/allreadwrite.h> #include <skalibs/siovec.h> #include <skalibs/djbunix.h> @@ -14,13 +13,7 @@ size_t openwritevnclose_at (int dirfd, char const *file, struct iovec const *v, int fd = open_truncatb(dirfd, file) ; if (fd < 0) return 0 ; r = allwritev(fd, v, n) ; - if (r < siovec_len(v, n) || fsync(fd) < 0) - { - int e = errno ; - fd_close(fd) ; - errno = e ; - return r ; - } + if (r >= siovec_len(v, n)) fsync(fd) ; fd_close(fd) ; return r ; } diff --git a/src/libunixonacid/skaclient_server_ack.c b/src/libunixonacid/skaclient_server_ack.c @@ -20,10 +20,8 @@ int skaclient_server_ack (unixmessage_t const *clientmsg, unixmessage_sender_t * unixmessage_sender_init(asyncout, fd[1]) ; if (!unixmessage_put_and_close(out, &m, &bits)) { - int e = errno ; fd_close(fd[1]) ; fd_close(fd[0]) ; - errno = e ; return 0 ; } return 1 ; diff --git a/src/libunixonacid/skaclient_start_async.c b/src/libunixonacid/skaclient_start_async.c @@ -33,9 +33,7 @@ int skaclient_start_async ( if ((!ipc_connect(fd, path) && !error_isalready(errno)) || !skaclient_init(a, fd, bufss, bufsn, auxbufss, auxbufsn, bufas, bufan, auxbufas, auxbufan, q, qlen, before, beforelen)) { - int e = errno ; fd_close(fd) ; - errno = e ; return 0 ; } a->pid = 0 ; diff --git a/src/libunixonacid/skaclient_startf_async.c b/src/libunixonacid/skaclient_startf_async.c @@ -34,14 +34,14 @@ int skaclient_startf_async ( if (!pid) return 0 ; if (ndelay_on(fd) < 0 || !skaclient_init(a, fd, bufss, bufsn, auxbufss, auxbufsn, bufas, bufan, auxbufas, auxbufan, q, qlen, before, beforelen)) { - int e = errno ; fd_close(fd) ; if (options & SKACLIENT_OPTION_WAITPID) { + int e = errno ; int wstat ; waitpid_nointr(a->pid, &wstat, 0) ; + errno = e ; } - errno = e ; return 0 ; } a->pid = pid ; diff --git a/src/libunixonacid/stat_at.c b/src/libunixonacid/stat_at.c @@ -40,9 +40,7 @@ static int fstat_at (int dirfd, char const *file, struct stat *st, int (*dostat) if (fdhere < 0) return -1 ; if (fd_chdir(dirfd) < 0) { - int e = errno ; fd_close(fdhere) ; - errno = e ; return -1 ; } r = (*dostat)(file, st) ; @@ -56,11 +54,10 @@ static int fstat_at (int dirfd, char const *file, struct stat *st, int (*dostat) } if (fd_chdir(fdhere) < 0) { - int e = errno ; fd_close(fdhere) ; - errno = e ; return -1 ; } + fd_close(fdhere) ; return r ; } diff --git a/src/libunixonacid/unixmessage_drop.c b/src/libunixonacid/unixmessage_drop.c @@ -1,13 +1,10 @@ /* ISC license. */ -#include <errno.h> #include <skalibs/djbunix.h> #include <skalibs/unixmessage.h> void unixmessage_drop (unixmessage_t const *m) { - int e = errno ; unsigned int i = m->nfds ; while (i--) fd_close(m->fds[i]) ; - errno = e ; } diff --git a/src/libunixonacid/unixmessage_receive.c b/src/libunixonacid/unixmessage_receive.c @@ -84,10 +84,8 @@ static int unixmessage_receiver_fill (unixmessage_receiver_t *b) for (; i < auxlen / sizeof(int) ; i++) if (coe(((int *)CMSG_DATA(c))[i]) < 0) { - int e = errno ; i++ ; while (i--) fd_close(((int *)CMSG_DATA(c))[i]) ; - errno = e ; return -1 ; } } diff --git a/src/sysdeps/tryegidingroups.c b/src/sysdeps/tryegidingroups.c @@ -0,0 +1,39 @@ +/* ISC license. */ + +#undef _POSIX_C_SOURCE +#undef _XOPEN_SOURCE + +#ifndef _BSD_SOURCE +#define _BSD_SOURCE +#endif + +#ifndef _GNU_SOURCE +#define _GNU_SOURCE +#endif + +#ifndef _DEFAULT_SOURCE +#define _DEFAULT_SOURCE +#endif + +#ifndef _NETBSD_SOURCE +#define _NETBSD_SOURCE +#endif + +#ifndef __EXTENSIONS__ +#define __EXTENSIONS__ +#endif + +#include <sys/types.h> +#include <unistd.h> +#include <grp.h> + +int main (void) +{ + gid_t gid = getegid() ; + gid_t list[NGROUPS_MAX] ; + int i = 0 ; + int r = getgroups(NGROUPS_MAX, list) ; + if (r < 0) return 111 ; + for (; i < r ; i++) if (list[i] == gid) return 0 ; + return 1 ; +}