diff options
author | Jim Meyering <jim@meyering.net> | 2003-07-12 16:21:45 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2003-07-12 16:21:45 +0000 |
commit | c8f1cbc602c5208b52ce91a2f9f949e1535b5cb8 (patch) | |
tree | 98c8cc5fd78a76ac90ed37a676ecb69cea2f5200 /src/df.c | |
parent | 7e815d32f3b44c52f5ed05d59a2ce3db603c63cb (diff) | |
download | coreutils-c8f1cbc602c5208b52ce91a2f9f949e1535b5cb8.tar.xz |
(find_mount_point): Emit a diagnostic for each
failed syscall, rather than relying on caller to do that.
The caller couldn't do a good job, anyhow -- too many different
ways to fail (each with a different referent).
Give a diagnostic upon failed save_cwd, now that that function
no longer calls `error'.
(show_point): Don't diagnose find_mount_point's errors, now that
it handles them itself.
Diffstat (limited to 'src/df.c')
-rw-r--r-- | src/df.c | 43 |
1 files changed, 30 insertions, 13 deletions
@@ -434,7 +434,8 @@ show_dev (const char *disk, const char *mount_point, const char *fstype, /* Return the root mountpoint of the filesystem on which FILE exists, in malloced storage. FILE_STAT should be the result of stating FILE. - Return NULL if unable to determine the mount point. */ + Give a diagnostic and return NULL if unable to determine the mount point. + Exit if unable to restore current working directory. */ static char * find_mount_point (const char *file, const struct stat *file_stat) { @@ -443,29 +444,41 @@ find_mount_point (const char *file, const struct stat *file_stat) char *mp = 0; /* The malloced mount point path. */ if (save_cwd (&cwd)) - return NULL; + { + error (0, errno, _("cannot get current directory")); + return NULL; + } if (S_ISDIR (file_stat->st_mode)) /* FILE is a directory, so just chdir there directly. */ { last_stat = *file_stat; if (chdir (file) < 0) - return NULL; + { + error (0, errno, _("cannot change to directory %s"), quote (file)); + return NULL; + } } else - /* FILE is some other kind of file, we need to use its directory. */ + /* FILE is some other kind of file; use its directory. */ { - char *dir = dir_name (file); + char *xdir = dir_name (file); + char *dir; + ASSIGN_STRDUPA (dir, xdir); + free (xdir); + if (chdir (dir) < 0) { - int saved_errno = errno; - free (dir); - errno = saved_errno; + error (0, errno, _("cannot change to directory %s"), quote (dir)); return NULL; } if (stat (".", &last_stat) < 0) - goto done; + { + error (0, errno, _("cannot stat current directory (now %s)"), + quote (dir)); + goto done; + } } /* Now walk up FILE's parents until we find another filesystem or /, @@ -475,12 +488,18 @@ find_mount_point (const char *file, const struct stat *file_stat) { struct stat st; if (stat ("..", &st) < 0) - goto done; + { + error (0, errno, _("cannot stat %s"), quote ("..")); + goto done; + } if (st.st_dev != last_stat.st_dev || st.st_ino == last_stat.st_ino) /* cwd is the mount point. */ break; if (chdir ("..") < 0) - goto done; + { + error (0, errno, _("cannot change to directory %s"), quote ("..")); + goto done; + } last_stat = st; } @@ -634,8 +653,6 @@ show_point (const char *point, const struct stat *statp) show_dev (0, mp, 0, 0, 0); free (mp); } - else - error (0, errno, "%s", quote (point)); } return; |