summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/util.c
diff options
context:
space:
mode:
authorDave Reisner <dreisner@archlinux.org>2013-07-04 02:33:19 +0200
committerAllan McRae <allan@archlinux.org>2013-07-05 06:32:23 +0200
commiteb19d41d5f85f169cee7570f783821cb705ad37a (patch)
tree245a12aa27e01a6f8ee74f5c1624d4e341551b81 /lib/libalpm/util.c
parent7b8f8753b15037bf4a88126ffde8195416432c72 (diff)
downloadpacman-eb19d41d5f85f169cee7570f783821cb705ad37a.tar.gz
pacman-eb19d41d5f85f169cee7570f783821cb705ad37a.tar.xz
do not check error from close(2)
On operating systems we support, the behavior is always such that the kernel will do the right thing as far as invalidating the file descriptor, regardless of the eventual return value. Therefore, potentially looping and calling close multiple times is wrong. At best, we call close again on an invalid FD and throw a spurious EBADF error. At worst, we might close an FD which doesn't belong to us when a multi-threaded application opens its own file descriptor between iterations of the loop. Signed-off-by: Dave Reisner <dreisner@archlinux.org> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'lib/libalpm/util.c')
-rw-r--r--lib/libalpm/util.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 15c1a67c..1e213627 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -186,10 +186,10 @@ int _alpm_copyfile(const char *src, const char *dest)
cleanup:
free(buf);
if(in >= 0) {
- CLOSE(in);
+ close(in);
}
if(out >= 0) {
- CLOSE(out);
+ close(out);
}
return ret;
}
@@ -275,7 +275,7 @@ error:
_alpm_archive_read_free(*archive);
*archive = NULL;
if(fd >= 0) {
- CLOSE(fd);
+ close(fd);
}
RET_ERR(handle, error, -1);
}
@@ -394,13 +394,13 @@ int _alpm_unpack(alpm_handle_t *handle, const char *path, const char *prefix,
cleanup:
umask(oldmask);
_alpm_archive_read_free(archive);
- CLOSE(fd);
+ close(fd);
if(cwdfd >= 0) {
if(fchdir(cwdfd) != 0) {
_alpm_log(handle, ALPM_LOG_ERROR,
_("could not restore working directory (%s)\n"), strerror(errno));
}
- CLOSE(cwdfd);
+ close(cwdfd);
}
return ret;
@@ -537,12 +537,12 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[])
if(pid == 0) {
/* this code runs for the child only (the actual chroot/exec) */
- CLOSE(1);
- CLOSE(2);
+ close(1);
+ close(2);
while(dup2(pipefd[1], 1) == -1 && errno == EINTR);
while(dup2(pipefd[1], 2) == -1 && errno == EINTR);
- CLOSE(pipefd[0]);
- CLOSE(pipefd[1]);
+ close(pipefd[0]);
+ close(pipefd[1]);
/* use fprintf instead of _alpm_log to send output through the parent */
if(chroot(handle->root) != 0) {
@@ -564,10 +564,10 @@ int _alpm_run_chroot(alpm_handle_t *handle, const char *cmd, char *const argv[])
int status;
FILE *pipe_file;
- CLOSE(pipefd[1]);
+ close(pipefd[1]);
pipe_file = fdopen(pipefd[0], "r");
if(pipe_file == NULL) {
- CLOSE(pipefd[0]);
+ close(pipefd[0]);
retval = 1;
} else {
while(!feof(pipe_file)) {
@@ -609,7 +609,7 @@ cleanup:
_alpm_log(handle, ALPM_LOG_ERROR,
_("could not restore working directory (%s)\n"), strerror(errno));
}
- CLOSE(cwdfd);
+ close(cwdfd);
}
return retval;
@@ -784,7 +784,7 @@ static int md5_file(const char *path, unsigned char output[16])
MD5_Update(&ctx, buf, n);
}
- CLOSE(fd);
+ close(fd);
free(buf);
if(n < 0) {
@@ -834,7 +834,7 @@ static int sha2_file(const char *path, unsigned char output[32], int is224)
}
}
- CLOSE(fd);
+ close(fd);
free(buf);
if(n < 0) {