From f4d77401d08cfb4aa90143f1b5905546f7912992 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Wed, 23 Dec 2015 21:43:21 +0000 Subject: [PATCH] Fix save_cwd/restore_cwd error diagnostics. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Before this change, a pointer to struct saved_cwd was used in place of char*, leading to incorrect error diagnostics, e.g.: $ chmod a-x . && find / -maxdepth 0 -exec true \; find: Failed to change directory: ÿÿÿÿ: Permission denied find: failed to restore initial working directory: ÿÿÿÿ: Permission denied * find/exec.c (prep_child_for_exec): Fix error diagnostics. * find/util.c (record_initial_cwd, cleanup_initial_cwd): Likewise. --- find/exec.c | 4 +++- find/util.c | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/find/exec.c b/find/exec.c index a57b6d42..7b6ecf6e 100644 --- a/find/exec.c +++ b/find/exec.c @@ -282,7 +282,9 @@ prep_child_for_exec (bool close_stdin, const struct saved_cwd *wd) */ if (0 != restore_cwd (wd)) { - error (0, errno, _("Failed to change directory: %s"), wd); + error (0, errno, _("Failed to change directory%s%s"), + (wd->desc < 0 && wd->name) ? ": " : "", + (wd->desc < 0 && wd->name) ? wd->name : ""); ok = false; } return ok; diff --git a/find/util.c b/find/util.c index eb5efa2e..0560e631 100644 --- a/find/util.c +++ b/find/util.c @@ -456,7 +456,9 @@ record_initial_cwd (void) if (0 != save_cwd (initial_wd)) { error (EXIT_FAILURE, errno, - _("failed to save initial working directory: %s"), initial_wd); + _("Failed to save initial working directory%s%s"), + (initial_wd->desc < 0 && initial_wd->name) ? ": " : "", + (initial_wd->desc < 0 && initial_wd->name) ? initial_wd->name : ""); } } @@ -473,7 +475,9 @@ cleanup_initial_cwd (void) { /* since we may already be in atexit, die with _exit(). */ error (0, errno, - _("failed to restore initial working directory: %s"), initial_wd); + _("Failed to restore initial working directory%s%s"), + (initial_wd->desc < 0 && initial_wd->name) ? ": " : "", + (initial_wd->desc < 0 && initial_wd->name) ? initial_wd->name : ""); _exit (EXIT_FAILURE); } }