summaryrefslogtreecommitdiff
path: root/src/pacman
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2010-06-27 20:32:11 +1000
committerDan McGee <dan@archlinux.org>2010-07-01 00:14:59 -0500
commit5a3aae02fed68379b5ede7abc9c7675632ce403a (patch)
tree917972cda40804c22c076cd3f193e04b93e3630d /src/pacman
parent41724cbcdef11cb00fcd720c75d399288ea41fd0 (diff)
Check return value of chdir and getcwd
Prevents compiler warnings when building with -D_FORTIFY_SOURCE=2 Signed-off-by: Allan McRae <allan@archlinux.org> Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src/pacman')
-rw-r--r--src/pacman/pacman.c15
1 files changed, 13 insertions, 2 deletions
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index a1b726dc..049bc40b 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -676,6 +676,7 @@ int download_with_xfercommand(const char *url, const char *localpath,
struct stat st;
char *parsedcmd,*tempcmd;
char cwd[PATH_MAX];
+ int restore_cwd = 0;
char *destfile, *tempfile, *filename;
if(!config->xfercommand) {
@@ -708,8 +709,14 @@ int download_with_xfercommand(const char *url, const char *localpath,
parsedcmd = strreplace(tempcmd, "%u", url);
free(tempcmd);
+ /* save the cwd so we can restore it later */
+ if(getcwd(cwd, PATH_MAX) == NULL) {
+ pm_printf(PM_LOG_ERROR, _("could not get current working directory\n"));
+ } else {
+ restore_cwd = 1;
+ }
+
/* cwd to the download directory */
- getcwd(cwd, PATH_MAX);
if(chdir(localpath)) {
pm_printf(PM_LOG_WARNING, _("could not chdir to download directory %s\n"), localpath);
ret = -1;
@@ -736,7 +743,11 @@ int download_with_xfercommand(const char *url, const char *localpath,
}
cleanup:
- chdir(cwd);
+ /* restore the old cwd if we have it */
+ if(restore_cwd && chdir(cwd) != 0) {
+ pm_printf(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), cwd, strerror(errno));
+ }
+
if(ret == -1) {
/* hack to let an user the time to cancel a download */
sleep(2);