diff options
author | Allan McRae <allan@archlinux.org> | 2010-06-27 12:32:11 +0200 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2010-07-01 07:14:59 +0200 |
commit | 5a3aae02fed68379b5ede7abc9c7675632ce403a (patch) | |
tree | 917972cda40804c22c076cd3f193e04b93e3630d /lib/libalpm/add.c | |
parent | 41724cbcdef11cb00fcd720c75d399288ea41fd0 (diff) | |
download | pacman-5a3aae02fed68379b5ede7abc9c7675632ce403a.tar.gz pacman-5a3aae02fed68379b5ede7abc9c7675632ce403a.tar.xz |
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 'lib/libalpm/add.c')
-rw-r--r-- | lib/libalpm/add.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c index f39a0ecf..cc0c4c13 100644 --- a/lib/libalpm/add.c +++ b/lib/libalpm/add.c @@ -556,6 +556,7 @@ static int commit_single_pkg(pmpkg_t *newpkg, int pkg_current, int pkg_count, struct archive *archive; struct archive_entry *entry; char cwd[PATH_MAX] = ""; + int restore_cwd = 0; _alpm_log(PM_LOG_DEBUG, "extracting files\n"); @@ -579,11 +580,16 @@ static int commit_single_pkg(pmpkg_t *newpkg, int pkg_current, int pkg_count, /* save the cwd so we can restore it later */ if(getcwd(cwd, PATH_MAX) == NULL) { _alpm_log(PM_LOG_ERROR, _("could not get current working directory\n")); - cwd[0] = 0; + } else { + restore_cwd = 1; } /* libarchive requires this for extracting hard links */ - chdir(handle->root); + if(chdir(handle->root) != 0) { + _alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), handle->root, strerror(errno)); + ret = -1; + goto cleanup; + } /* call PROGRESS once with 0 percent, as we sort-of skip that here */ if(is_upgrade) { @@ -629,9 +635,9 @@ static int commit_single_pkg(pmpkg_t *newpkg, int pkg_current, int pkg_count, } archive_read_finish(archive); - /* restore the old cwd is we have it */ - if(strlen(cwd)) { - chdir(cwd); + /* restore the old cwd if we have it */ + if(restore_cwd && chdir(cwd) != 0) { + _alpm_log(PM_LOG_ERROR, _("could not change directory to %s (%s)\n"), cwd, strerror(errno)); } if(errors) { |