Fix save_cwd/restore_cwd error diagnostics.

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.
This commit is contained in:
Dmitry V. Levin 2015-12-23 21:43:21 +00:00 committed by James Youngman
parent 2135babdee
commit f4d77401d0
2 changed files with 9 additions and 3 deletions

View File

@ -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;

View File

@ -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);
}
}