summaryrefslogtreecommitdiff
path: root/src/libunixonacid
diff options
context:
space:
mode:
Diffstat (limited to 'src/libunixonacid')
-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
15 files changed, 25 insertions, 73 deletions
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 ;
}
}