=/^G show total bytes now; document may not always work
[unix-history] / usr / src / sbin / savecore / savecore.c
index e1e272b..71292a3 100644 (file)
@@ -1,18 +1,29 @@
 /*
 /*
- * Copyright (c) 1980,1986 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * Copyright (c) 1980, 1986 The Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #ifndef lint
 char copyright[] =
  */
 
 #ifndef lint
 char copyright[] =
-"@(#) Copyright (c) 1980,1986 Regents of the University of California.\n\
+"@(#) Copyright (c) 1980, 1986 The Regents of the University of California.\n\
  All rights reserved.\n";
  All rights reserved.\n";
-#endif not lint
+#endif /* not lint */
 
 #ifndef lint
 
 #ifndef lint
-static char sccsid[] = "@(#)savecore.c 5.11 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)savecore.c 5.14 (Berkeley) %G%";
+#endif /* not lint */
 
 /*
  * savecore
 
 /*
  * savecore
@@ -91,6 +102,7 @@ off_t        lseek();
 off_t  Lseek();
 int    Verbose;
 int    force;
 off_t  Lseek();
 int    Verbose;
 int    force;
+int    clear;
 extern int errno;
 
 main(argc, argv)
 extern int errno;
 
 main(argc, argv)
@@ -111,6 +123,10 @@ main(argc, argv)
                        Verbose++;
                        break;
 
                        Verbose++;
                        break;
 
+               case 'c':
+                       clear++;
+                       break;
+
                default:
                usage:
                        fprintf(stderr,
                default:
                usage:
                        fprintf(stderr,
@@ -209,13 +225,13 @@ read_kmem()
         */
        for (i = 0; cursyms[i] != -1; i++)
                if (current_nl[cursyms[i]].n_value == 0) {
         */
        for (i = 0; cursyms[i] != -1; i++)
                if (current_nl[cursyms[i]].n_value == 0) {
-                       log(LOG_ERR, "/vmunix: %s not in namelist",
+                       log(LOG_ERR, "/vmunix: %s not in namelist\n",
                            current_nl[cursyms[i]].n_name);
                        exit(1);
                }
        for (i = 0; dumpsyms[i] != -1; i++)
                if (dump_nl[dumpsyms[i]].n_value == 0) {
                            current_nl[cursyms[i]].n_name);
                        exit(1);
                }
        for (i = 0; dumpsyms[i] != -1; i++)
                if (dump_nl[dumpsyms[i]].n_value == 0) {
-                       log(LOG_ERR, "%s: %s not in namelist", dump_sys,
+                       log(LOG_ERR, "%s: %s not in namelist\n", dump_sys,
                            dump_nl[dumpsyms[i]].n_name);
                        exit(1);
                }
                            dump_nl[dumpsyms[i]].n_name);
                        exit(1);
                }
@@ -230,7 +246,7 @@ read_kmem()
        ddname = find_dev(dumpdev, S_IFBLK);
        fp = fdopen(kmem, "r");
        if (fp == NULL) {
        ddname = find_dev(dumpdev, S_IFBLK);
        fp = fdopen(kmem, "r");
        if (fp == NULL) {
-               log(LOG_ERR, "Couldn't fdopen kmem");
+               log(LOG_ERR, "Couldn't fdopen kmem\n");
                exit(1);
        }
        if (system)
                exit(1);
        }
        if (system)
@@ -253,10 +269,11 @@ check_kmem()
        fseek(fp, (off_t)(dumplo+ok(dump_nl[X_VERSION].n_value)), L_SET);
        fgets(core_vers, sizeof (core_vers), fp);
        fclose(fp);
        fseek(fp, (off_t)(dumplo+ok(dump_nl[X_VERSION].n_value)), L_SET);
        fgets(core_vers, sizeof (core_vers), fp);
        fclose(fp);
-       if (!eq(vers, core_vers) && system == 0)
-               log(LOG_WARNING,
-                  "Warning: vmunix version mismatch:\n\t%sand\n\t%s",
-                  vers, core_vers);
+       if (!eq(vers, core_vers) && system == 0) {
+               log(LOG_WARNING, "Warning: vmunix version mismatch:\n");
+               log(LOG_WARNING, "\t%s\n", vers);
+               log(LOG_WARNING, "and\t%s\n", core_vers);
+       }
        fp = fopen(ddname, "r");
        fseek(fp, (off_t)(dumplo + ok(dump_nl[X_PANICSTR].n_value)), L_SET);
        fread((char *)&panicstr, sizeof (panicstr), 1, fp);
        fp = fopen(ddname, "r");
        fseek(fp, (off_t)(dumplo + ok(dump_nl[X_PANICSTR].n_value)), L_SET);
        fread((char *)&panicstr, sizeof (panicstr), 1, fp);
@@ -322,12 +339,12 @@ check_space()
        close(dfd);
        spacefree = freespace(&fs, fs.fs_minfree) * fs.fs_fsize / 1024;
        if (spacefree < read_number("minfree")) {
        close(dfd);
        spacefree = freespace(&fs, fs.fs_minfree) * fs.fs_fsize / 1024;
        if (spacefree < read_number("minfree")) {
-               log(LOG_WARNING, "Dump omitted, not enough space on device");
+               log(LOG_WARNING, "Dump omitted, not enough space on device\n");
                return (0);
        }
        if (freespace(&fs, fs.fs_minfree) < 0)
                log(LOG_WARNING,
                return (0);
        }
        if (freespace(&fs, fs.fs_minfree) < 0)
                log(LOG_WARNING,
-                   "Dump performed, but free space threshold crossed");
+                   "Dump performed, but free space threshold crossed\n");
        return (1);
 }
 
        return (1);
 }
 
@@ -371,7 +388,7 @@ save_core()
        ifd = Open(ddname, O_RDONLY);
        Lseek(ifd, (off_t)(dumplo + ok(dump_nl[X_DUMPSIZE].n_value)), L_SET);
        Read(ifd, (char *)&dumpsize, sizeof (dumpsize));
        ifd = Open(ddname, O_RDONLY);
        Lseek(ifd, (off_t)(dumplo + ok(dump_nl[X_DUMPSIZE].n_value)), L_SET);
        Read(ifd, (char *)&dumpsize, sizeof (dumpsize));
-       sprintf(cp, "vmcore.%d", bounds);
+       (void)sprintf(cp, "vmcore.%d", bounds);
        ofd = Create(path(cp), 0644);
        Lseek(ifd, (off_t)dumplo, L_SET);
        log(LOG_NOTICE, "Saving %d bytes of image in vmcore.%d\n",
        ofd = Create(path(cp), 0644);
        Lseek(ifd, (off_t)dumplo, L_SET);
        log(LOG_NOTICE, "Saving %d bytes of image in vmcore.%d\n",
@@ -380,7 +397,7 @@ save_core()
                n = Read(ifd, cp,
                    (dumpsize > BUFPAGES ? BUFPAGES : dumpsize) * NBPG);
                if (n == 0) {
                n = Read(ifd, cp,
                    (dumpsize > BUFPAGES ? BUFPAGES : dumpsize) * NBPG);
                if (n == 0) {
-                       log(LOG_WARNING, "WARNING: vmcore may be incomplete");
+                       log(LOG_WARNING, "WARNING: vmcore may be incomplete\n");
                        break;
                }
                Write(ofd, cp, n);
                        break;
                }
                Write(ofd, cp, n);