Use lstat() when poking around in /dev. The routine is converting a
authorKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 3 Jan 1994 04:57:09 +0000 (20:57 -0800)
committerKeith Bostic <bostic@ucbvax.Berkeley.EDU>
Mon, 3 Jan 1994 04:57:09 +0000 (20:57 -0800)
device number to a name (seems like there are very few cases where stat()
is preferred over lstat()).  Exit with a nice message if dumpdev is NODEV,
for running diskless.
From: Craig Leres <leres@ee.lbl.gov>

SCCS-vsn: sbin/savecore/savecore.c 8.3

usr/src/sbin/savecore/savecore.c

index 2238bec..c7cd004 100644 (file)
@@ -12,7 +12,7 @@ static char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)savecore.c 8.2 (Berkeley) %G%";
+static char sccsid[] = "@(#)savecore.c 8.3 (Berkeley) %G%";
 #endif /* not lint */
 
 #include <sys/param.h>
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -183,6 +183,10 @@ kmem_setup()
        kmem = Open(_PATH_KMEM, O_RDONLY);
        Lseek(kmem, (off_t)current_nl[X_DUMPDEV].n_value, L_SET);
        (void)Read(kmem, &dumpdev, sizeof(dumpdev));
        kmem = Open(_PATH_KMEM, O_RDONLY);
        Lseek(kmem, (off_t)current_nl[X_DUMPDEV].n_value, L_SET);
        (void)Read(kmem, &dumpdev, sizeof(dumpdev));
+       if (dumpdev == NODEV) {
+               syslog(LOG_WARNING, "no core dump (no dumpdev)");
+               exit(1);
+       }
        Lseek(kmem, (off_t)current_nl[X_DUMPLO].n_value, L_SET);
        (void)Read(kmem, &dumplo, sizeof(dumplo));
        if (verbose)
        Lseek(kmem, (off_t)current_nl[X_DUMPLO].n_value, L_SET);
        (void)Read(kmem, &dumplo, sizeof(dumplo));
        if (verbose)
@@ -413,7 +417,7 @@ find_dev(dev, type)
        (void)strcpy(devname, _PATH_DEV);
        while ((dir = readdir(dfd))) {
                (void)strcpy(devname + sizeof(_PATH_DEV) - 1, dir->d_name);
        (void)strcpy(devname, _PATH_DEV);
        while ((dir = readdir(dfd))) {
                (void)strcpy(devname + sizeof(_PATH_DEV) - 1, dir->d_name);
-               if (stat(devname, &sb)) {
+               if (lstat(devname, &sb)) {
                        syslog(LOG_ERR, "%s: %s", devname, strerror(errno));
                        continue;
                }
                        syslog(LOG_ERR, "%s: %s", devname, strerror(errno));
                        continue;
                }