summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-09-19 19:55:16 -0500
committerDan McGee <dan@archlinux.org>2011-09-20 10:23:10 -0500
commit95119d46d486168e7fddd5e8eece93be8e9ca719 (patch)
tree445b5fb5861c0aa4cfbc3ec4c22f7af9cdd224cd /src
parent288a81d8470b1fd2e8a8f0814abe4cbfed71497c (diff)
downloadpacman-95119d46d486168e7fddd5e8eece93be8e9ca719.tar.xz
Flip getcwd()/chdir() for open()/fchdir() in the frontend
Just like we did in libalpm in commit 288a81d8470b1. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/conf.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 6587be91..e8b34f7d 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -23,10 +23,12 @@
#include <errno.h>
#include <glob.h>
#include <limits.h>
+#include <fcntl.h> /* open */
#include <stdlib.h>
#include <stdio.h>
#include <string.h> /* strdup */
#include <sys/stat.h>
+#include <sys/types.h>
#include <sys/utsname.h> /* uname */
#include <unistd.h>
@@ -118,13 +120,11 @@ static char *get_tempfile(const char *path, const char *filename) {
/** External fetch callback */
static int download_with_xfercommand(const char *url, const char *localpath,
int force) {
- int ret = 0;
- int retval;
+ int ret = 0, retval;
int usepart = 0;
+ int cwdfd;
struct stat st;
char *parsedcmd,*tempcmd;
- char cwd[PATH_MAX];
- int restore_cwd = 0;
char *destfile, *tempfile, *filename;
if(!config->xfercommand) {
@@ -158,10 +158,11 @@ static int download_with_xfercommand(const char *url, const char *localpath,
free(tempcmd);
/* save the cwd so we can restore it later */
- if(getcwd(cwd, PATH_MAX) == NULL) {
+ do {
+ cwdfd = open(".", O_RDONLY);
+ } while(cwdfd == -1 && errno == EINTR);
+ if(cwdfd < 0) {
pm_printf(ALPM_LOG_ERROR, _("could not get current working directory\n"));
- } else {
- restore_cwd = 1;
}
/* cwd to the download directory */
@@ -196,9 +197,12 @@ static int download_with_xfercommand(const char *url, const char *localpath,
cleanup:
/* restore the old cwd if we have it */
- if(restore_cwd && chdir(cwd) != 0) {
- pm_printf(ALPM_LOG_ERROR, _("could not change directory to %s (%s)\n"),
- cwd, strerror(errno));
+ if(cwdfd >= 0) {
+ if(fchdir(cwdfd) != 0) {
+ pm_printf(ALPM_LOG_ERROR, _("could not restore working directory (%s)\n"),
+ strerror(errno));
+ }
+ close(cwdfd);
}
if(ret == -1) {