summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/include/skalibs/djbunix.h2
-rw-r--r--src/include/skalibs/unix-transactional.h2
-rw-r--r--src/librandom/random_init.c2
-rw-r--r--src/libstddjb/cdb_mapfile.c3
-rw-r--r--src/libstddjb/child_spawn0.c4
-rw-r--r--src/libstddjb/child_spawn1_internal.c6
-rw-r--r--src/libstddjb/doublefork.c2
-rw-r--r--src/libstddjb/fd_close.c11
-rw-r--r--src/libstddjb/fd_ensure_open.c2
-rw-r--r--src/libstddjb/fd_move.c4
-rw-r--r--src/libstddjb/fd_move2.c2
-rw-r--r--src/libstddjb/filecopy_unsafe.c23
-rw-r--r--src/libstddjb/iobufferk_finish.c5
-rw-r--r--src/libstddjb/ipc_accept.c4
-rw-r--r--src/libstddjb/openreadfileclose.c7
-rw-r--r--src/libstddjb/openreadnclose.c2
-rw-r--r--src/libstddjb/openslurpclose.c4
-rw-r--r--src/libstddjb/pipe_internal.c3
-rw-r--r--src/libstddjb/socket_accept4.c2
-rw-r--r--src/libstddjb/socket_accept6.c2
-rw-r--r--src/libstddjb/socket_internal.c3
-rw-r--r--src/libstddjb/socket_tcp6.c4
-rw-r--r--src/libstddjb/socket_udp6.c4
-rw-r--r--src/libstddjb/socketpair_internal.c8
-rw-r--r--src/libstddjb/touch.c11
-rw-r--r--src/libunixonacid/dd_cancel.c3
-rw-r--r--src/libunixonacid/dd_close.c4
-rw-r--r--src/libunixonacid/open2_at.c22
-rw-r--r--src/libunixonacid/open3_at.c22
-rw-r--r--src/libunixonacid/opengetlnclose.c4
-rw-r--r--src/libunixonacid/opengetlnclose_at.c4
-rw-r--r--src/libunixonacid/openslurpclose_at.c3
-rw-r--r--src/libunixonacid/openwritenclose_at.c9
-rw-r--r--src/libunixonacid/openwritevnclose_at.c9
-rw-r--r--src/libunixonacid/skaclient_server_ack.c2
-rw-r--r--src/libunixonacid/skaclient_start_async.c2
-rw-r--r--src/libunixonacid/skaclient_startf_async.c4
-rw-r--r--src/libunixonacid/stat_at.c5
-rw-r--r--src/libunixonacid/unixmessage_drop.c3
-rw-r--r--src/libunixonacid/unixmessage_receive.c2
-rw-r--r--src/sysdeps/tryegidingroups.c39
41 files changed, 92 insertions, 167 deletions
diff --git a/src/include/skalibs/djbunix.h b/src/include/skalibs/djbunix.h
index d7a1bd2..757852c 100644
--- 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
index 41b31b7..a2f56e8 100644
--- 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
index cf7ef32..e780cfa 100644
--- 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
index 1ffae19..f2c56bb 100644
--- 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
index f946515..a01739a 100644
--- 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
index feddbc8..eea4f09 100644
--- 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
index d75a017..da512f8 100644
--- 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
index cb52d4f..a3c7880 100644
--- 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
index 40548c1..c42c90e 100644
--- 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
index d84db80..af9769c 100644
--- 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
index e28c2cc..d80ef3e 100644
--- 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
index 68bcc5b..a6410c1 100644
--- 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
index 112174b..4e4a73c 100644
--- 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
index 5ff82d8..b0b44c3 100644
--- 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
index b636c89..baed267 100644
--- 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
index 57a9bdc..e765499 100644
--- 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
index 5f67d76..50d361e 100644
--- 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
index 48f182a..598ab9c 100644
--- 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
index c77d0e2..40dff91 100644
--- 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
index 6942997..5bd72b4 100644
--- 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
index f8b0a1f..848b156 100644
--- 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
index df6dd86..cc42f68 100644
--- 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
index c8f5928..6316861 100644
--- 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
index a1e64c5..a31228f 100644
--- 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
index d270251..f71a983 100644
--- 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
index f17525c..34b6014 100644
--- 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
index ffe8b1e..be5bdd9 100644
--- 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
index 6b581e4..023c038 100644
--- 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
index 22bbecd..d4234d4 100644
--- 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
index 19383b1..8c6e076 100644
--- 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
index 62fd5fd..cc2f86a 100644
--- 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
index f4e0615..bf6d3ab 100644
--- 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
index 3fea94c..015c0c8 100644
--- 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
index f5a9419..ba1e789 100644
--- 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
index 181559d..715e128 100644
--- 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
index 02ca421..d678a85 100644
--- 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
index 7ce85d8..305b2b6 100644
--- 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
index 2eb90a5..2d04d57 100644
--- 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
index e51a8d0..bf37df3 100644
--- 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
index 8ca8c0b..ec12e09 100644
--- 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
new file mode 100644
index 0000000..687740d
--- /dev/null
+++ 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 ;
+}