From 443487e98929bf8e5e8bc7816f605a6f0924dfe7 Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Fri, 7 May 2010 09:29:17 +0100 Subject: [PATCH 1/2] Correctly initialise variables in run_in_dir. To: address@hidden * lib/dircallback.c (run_in_dir): Make sure that if the callback doesn't get run, the return value is nonzero. Make sure that if the directory save/restore fails, we don't overwrite errno with a random value (and hence report some unrelated and nonexistent error, instead of the real problem). Restore the previous current directory. Signed-off-by: James Youngman --- ChangeLog | 9 +++++++++ lib/dircallback.c | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletions(-) diff --git a/ChangeLog b/ChangeLog index 02bfaa0..8e6de22 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-05-07 Kamil Dudka + + * lib/dircallback.c (run_in_dir): Make sure that if the callback + doesn't get run, the return value is nonzero. Make sure that if + the directory save/restore fails, we don't overwrite errno with a + random value (and hence report some unrelated and nonexistent + error, instead of the real problem). Restore the previous current + directory. + 2010-05-04 James Youngman Bugfix: make sure make distdir works in VPATH directly after configure diff --git a/lib/dircallback.c b/lib/dircallback.c index 8497bee..c1e4088 100644 --- a/lib/dircallback.c +++ b/lib/dircallback.c @@ -37,7 +37,8 @@ int run_in_dir (const struct saved_cwd *there, int (*callback)(void*), void *usercontext) { - int err, saved_errno; + int err = -1; + int saved_errno = 0; struct saved_cwd here; if (0 == save_cwd (&here)) { @@ -50,6 +51,10 @@ run_in_dir (const struct saved_cwd *there, { openat_restore_fail (errno); } + + if (restore_cwd (&here) != 0) + openat_restore_fail (errno); + free_cwd (&here); } else -- 1.7.0