BSD 4_4 release
[unix-history] / usr / src / sbin / dump / optr.c
index cefb630..afc9b8c 100644 (file)
@@ -1,22 +1,69 @@
-/*
- * Copyright (c) 1980, 1988 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+/*-
+ * Copyright (c) 1980, 1988, 1993
+ *     The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)optr.c     5.5 (Berkeley) %G%";
+static char sccsid[] = "@(#)optr.c     8.1 (Berkeley) 6/5/93";
 #endif /* not lint */
 
 #endif /* not lint */
 
-#include "dump.h"
+#include <sys/param.h>
 #include <sys/wait.h>
 #include <sys/wait.h>
+#include <sys/time.h>
+
 #include <errno.h>
 #include <errno.h>
+#include <fstab.h>
 #include <grp.h>
 #include <grp.h>
+#include <signal.h>
+#include <stdio.h>
+#ifdef __STDC__
+#include <stdlib.h>
+#include <string.h>
+#include <stdarg.h>
+#endif
+#include <tzfile.h>
+#ifdef __STDC__
+#include <unistd.h>
+#endif
+#include <utmp.h>
+#ifndef __STDC__
 #include <varargs.h>
 #include <varargs.h>
+#endif
+
+#include "dump.h"
 #include "pathnames.h"
 
 #include "pathnames.h"
 
-static void alarmcatch();
-static void sendmes();
+void   alarmcatch __P((/* int, int */));
+int    datesort __P((const void *, const void *));
+static void sendmes __P((char *, char *));
 
 /*
  *     Query the operator; This previously-fascist piece of code
 
 /*
  *     Query the operator; This previously-fascist piece of code
@@ -29,8 +76,8 @@ static void sendmes();
  *     Every 2 minutes we reprint the message, alerting others
  *     that dump needs attention.
  */
  *     Every 2 minutes we reprint the message, alerting others
  *     that dump needs attention.
  */
-int    timeout;
-char   *attnmessage;           /* attention message */
+static int timeout;
+static char *attnmessage;              /* attention message */
 
 int
 query(question)
 
 int
 query(question)
@@ -67,10 +114,10 @@ query(question)
        /*
         *      Turn off the alarm, and reset the signal to trap out..
         */
        /*
         *      Turn off the alarm, and reset the signal to trap out..
         */
-       alarm(0);
-       if (signal(SIGALRM, sigalrm) == SIG_IGN)
+       (void) alarm(0);
+       if (signal(SIGALRM, sig) == SIG_IGN)
                signal(SIGALRM, SIG_IGN);
                signal(SIGALRM, SIG_IGN);
-       fclose(mytty);
+       (void) fclose(mytty);
        return(back);
 }
 
        return(back);
 }
 
@@ -80,7 +127,7 @@ char lastmsg[100];
  *     Alert the console operator, and enable the alarm clock to
  *     sleep for 2 minutes in case nobody comes to satisfy dump
  */
  *     Alert the console operator, and enable the alarm clock to
  *     sleep for 2 minutes in case nobody comes to satisfy dump
  */
-static void
+void
 alarmcatch()
 {
        if (notify == 0) {
 alarmcatch()
 {
        if (notify == 0) {
@@ -99,7 +146,7 @@ alarmcatch()
                    attnmessage);
        }
        signal(SIGALRM, alarmcatch);
                    attnmessage);
        }
        signal(SIGALRM, alarmcatch);
-       alarm(120);
+       (void) alarm(120);
        timeout = 1;
 }
 
        timeout = 1;
 }
 
@@ -107,11 +154,12 @@ alarmcatch()
  *     Here if an inquisitive operator interrupts the dump program
  */
 void
  *     Here if an inquisitive operator interrupts the dump program
  */
 void
-interrupt()
+interrupt(signo)
+       int signo;
 {
        msg("Interrupt received.\n");
        if (query("Do you want to abort dump?"))
 {
        msg("Interrupt received.\n");
        if (query("Do you want to abort dump?"))
-               dumpabort();
+               dumpabort(0);
 }
 
 /*
 }
 
 /*
@@ -130,7 +178,7 @@ set_operators()
        if (!notify)            /*not going to notify*/
                return;
        gp = getgrnam(OPGRENT);
        if (!notify)            /*not going to notify*/
                return;
        gp = getgrnam(OPGRENT);
-       endgrent();
+       (void) endgrent();
        if (gp == NULL) {
                msg("No group entry for %s.\n", OPGRENT);
                notify = 0;
        if (gp == NULL) {
                msg("No group entry for %s.\n", OPGRENT);
                notify = 0;
@@ -138,7 +186,6 @@ set_operators()
        }
 }
 
        }
 }
 
-struct tm *localtime();
 struct tm *localclock;
 
 /*
 struct tm *localclock;
 
 /*
@@ -152,7 +199,6 @@ broadcast(message)
        time_t          clock;
        FILE    *f_utmp;
        struct  utmp    utmp;
        time_t          clock;
        FILE    *f_utmp;
        struct  utmp    utmp;
-       int     nusers;
        char    **np;
        int     pid, s;
 
        char    **np;
        int     pid, s;
 
@@ -170,7 +216,7 @@ broadcast(message)
                return;
        }
 
                return;
        }
 
-       clock = time(0);
+       clock = time((time_t *)0);
        localclock = localtime(&clock);
 
        if ((f_utmp = fopen(_PATH_UTMP, "r")) == NULL) {
        localclock = localtime(&clock);
 
        if ((f_utmp = fopen(_PATH_UTMP, "r")) == NULL) {
@@ -178,13 +224,11 @@ broadcast(message)
                return;
        }
 
                return;
        }
 
-       nusers = 0;
        while (!feof(f_utmp)) {
        while (!feof(f_utmp)) {
-               if (fread(&utmp, sizeof (struct utmp), 1, f_utmp) != 1)
+               if (fread((char *) &utmp, sizeof (struct utmp), 1, f_utmp) != 1)
                        break;
                if (utmp.ut_name[0] == 0)
                        continue;
                        break;
                if (utmp.ut_name[0] == 0)
                        continue;
-               nusers++;
                for (np = gp->gr_mem; *np; np++) {
                        if (strncmp(*np, utmp.ut_name, sizeof(utmp.ut_name)) != 0)
                                continue;
                for (np = gp->gr_mem; *np; np++) {
                        if (strncmp(*np, utmp.ut_name, sizeof(utmp.ut_name)) != 0)
                                continue;
@@ -252,7 +296,7 @@ timeest()
 {
        time_t  tnow, deltat;
 
 {
        time_t  tnow, deltat;
 
-       time (&tnow);
+       (void) time((time_t *) &tnow);
        if (tnow >= tschedule) {
                tschedule = tnow + 300;
                if (blockswritten < 500)
        if (tnow >= tschedule) {
                tschedule = tnow + 300;
                if (blockswritten < 500)
@@ -266,93 +310,79 @@ timeest()
        }
 }
 
        }
 }
 
-/*
- *     tapesize: total number of blocks estimated over all reels
- *     blockswritten:  blocks actually written, over all reels
- *     etapes: estimated number of tapes to write
- *
- *     tsize:  blocks can write on this reel
- *     asize:  blocks written on this reel
- *     tapeno: number of tapes written so far
- */
-int
-blocksontape()
-{
-       if (tapeno == etapes)
-               return (tapesize - (etapes - 1) * tsize);
-       return (tsize);
-}
-
-#ifdef lint
-
-/* VARARGS1 */
-void msg(fmt) char *fmt; { strcpy(lastmsg, fmt); }
-
-/* VARARGS1 */
-void msgtail(fmt) char *fmt; { fmt = fmt; }
-
-void quit(fmt) char *fmt; { msg(fmt); dumpabort(); }
-
-#else /* lint */
-
 void
 void
-msg(va_alist)
+#if __STDC__
+msg(const char *fmt, ...)
+#else
+msg(fmt, va_alist)
+       char *fmt;
        va_dcl
        va_dcl
+#endif
 {
        va_list ap;
 {
        va_list ap;
-       char *fmt;
 
        (void) fprintf(stderr,"  DUMP: ");
 #ifdef TDEBUG
        (void) fprintf(stderr, "pid=%d ", getpid());
 #endif
 
        (void) fprintf(stderr,"  DUMP: ");
 #ifdef TDEBUG
        (void) fprintf(stderr, "pid=%d ", getpid());
 #endif
+#if __STDC__
+       va_start(ap, fmt);
+#else
        va_start(ap);
        va_start(ap);
-       fmt = va_arg(ap, char *);
+#endif
        (void) vfprintf(stderr, fmt, ap);
        (void) vfprintf(stderr, fmt, ap);
-       va_end(ap);
        (void) fflush(stdout);
        (void) fflush(stderr);
        (void) fflush(stdout);
        (void) fflush(stderr);
-       va_start(ap);
-       fmt = va_arg(ap, char *);
        (void) vsprintf(lastmsg, fmt, ap);
        va_end(ap);
 }
 
 void
        (void) vsprintf(lastmsg, fmt, ap);
        va_end(ap);
 }
 
 void
-msgtail(va_alist)
+#if __STDC__
+msgtail(const char *fmt, ...)
+#else
+msgtail(fmt, va_alist)
+       char *fmt;
        va_dcl
        va_dcl
+#endif
 {
        va_list ap;
 {
        va_list ap;
-       char *fmt;
-
+#if __STDC__
+       va_start(ap, fmt);
+#else
        va_start(ap);
        va_start(ap);
-       fmt = va_arg(ap, char *);
+#endif
        (void) vfprintf(stderr, fmt, ap);
        va_end(ap);
 }
 
 void
        (void) vfprintf(stderr, fmt, ap);
        va_end(ap);
 }
 
 void
-quit(va_alist)
+#if __STDC__
+quit(const char *fmt, ...)
+#else
+quit(fmt, va_alist)
+       char *fmt;
        va_dcl
        va_dcl
+#endif
 {
        va_list ap;
 {
        va_list ap;
-       char *fmt;
 
        (void) fprintf(stderr,"  DUMP: ");
 #ifdef TDEBUG
        (void) fprintf(stderr, "pid=%d ", getpid());
 #endif
 
        (void) fprintf(stderr,"  DUMP: ");
 #ifdef TDEBUG
        (void) fprintf(stderr, "pid=%d ", getpid());
 #endif
+#if __STDC__
+       va_start(ap, fmt);
+#else
        va_start(ap);
        va_start(ap);
-       fmt = va_arg(ap, char *);
-       vfprintf(stderr, fmt, ap);
+#endif
+       (void) vfprintf(stderr, fmt, ap);
        va_end(ap);
        (void) fflush(stdout);
        (void) fflush(stderr);
        va_end(ap);
        (void) fflush(stdout);
        (void) fflush(stderr);
-       dumpabort();
+       dumpabort(0);
 }
 
 }
 
-#endif /* lint */
-
 /*
  *     Tell the operator what has to be done;
  *     we don't actually do it
 /*
  *     Tell the operator what has to be done;
  *     we don't actually do it
@@ -393,7 +423,7 @@ getfstab()
                    _PATH_FSTAB, strerror(errno));
                return;
        }
                    _PATH_FSTAB, strerror(errno));
                return;
        }
-       while (fs = getfsent()) {
+       while ((fs = getfsent()) != NULL) {
                if (strcmp(fs->fs_type, FSTAB_RW) &&
                    strcmp(fs->fs_type, FSTAB_RO) &&
                    strcmp(fs->fs_type, FSTAB_RQ))
                if (strcmp(fs->fs_type, FSTAB_RW) &&
                    strcmp(fs->fs_type, FSTAB_RO) &&
                    strcmp(fs->fs_type, FSTAB_RQ))
@@ -405,7 +435,7 @@ getfstab()
                pf->pf_next = table;
                table = pf;
        }
                pf->pf_next = table;
                table = pf;
        }
-       endfsent();
+       (void) endfsent();
 }
 
 /*
 }
 
 /*
@@ -425,7 +455,6 @@ fstabsearch(key)
 {
        register struct pfstab *pf;
        register struct fstab *fs;
 {
        register struct pfstab *pf;
        register struct fstab *fs;
-       char *rawname();
 
        for (pf = table; pf != NULL; pf = pf->pf_next) {
                fs = pf->pf_fstab;
 
        for (pf = table; pf != NULL; pf = pf->pf_next) {
                fs = pf->pf_fstab;
@@ -456,13 +485,13 @@ lastdump(arg)
        register struct fstab *dt;
        register struct dumpdates *dtwalk;
        char *lastname, *date;
        register struct fstab *dt;
        register struct dumpdates *dtwalk;
        char *lastname, *date;
-       int dumpme, datesort();
+       int dumpme;
        time_t tnow;
 
        time_t tnow;
 
-       time(&tnow);
+       (void) time(&tnow);
        getfstab();             /* /etc/fstab input */
        initdumptimes();        /* /etc/dumpdates input */
        getfstab();             /* /etc/fstab input */
        initdumptimes();        /* /etc/dumpdates input */
-       qsort(ddatev, nddates, sizeof(struct dumpdates *), datesort);
+       qsort((char *) ddatev, nddates, sizeof(struct dumpdates *), datesort);
 
        if (arg == 'w')
                (void) printf("Dump these file systems:\n");
 
        if (arg == 'w')
                (void) printf("Dump these file systems:\n");
@@ -479,7 +508,7 @@ lastdump(arg)
                dt = fstabsearch(dtwalk->dd_name);
                dumpme = (dt != NULL &&
                    dt->fs_freq != 0 &&
                dt = fstabsearch(dtwalk->dd_name);
                dumpme = (dt != NULL &&
                    dt->fs_freq != 0 &&
-                   dtwalk->dd_ddate < tnow - (dt->fs_freq * DAY));
+                   dtwalk->dd_ddate < tnow - (dt->fs_freq * SECSPERDAY));
                if (arg != 'w' || dumpme)
                        (void) printf(
                            "%c %8s\t(%6s) Last dump: Level %c, Date %s\n",
                if (arg != 'w' || dumpme)
                        (void) printf(
                            "%c %8s\t(%6s) Last dump: Level %c, Date %s\n",
@@ -493,7 +522,7 @@ lastdump(arg)
 
 int
 datesort(a1, a2)
 
 int
 datesort(a1, a2)
-       void *a1, *a2;
+       const void *a1, *a2;
 {
        struct dumpdates *d1 = *(struct dumpdates **)a1;
        struct dumpdates *d2 = *(struct dumpdates **)a2;
 {
        struct dumpdates *d1 = *(struct dumpdates **)a1;
        struct dumpdates *d2 = *(struct dumpdates **)a2;
@@ -504,14 +533,3 @@ datesort(a1, a2)
                return (d2->dd_ddate - d1->dd_ddate);
        return (diff);
 }
                return (d2->dd_ddate - d1->dd_ddate);
        return (diff);
 }
-
-int max(a, b)
-       int a, b;
-{
-       return (a > b ? a : b);
-}
-int min(a, b)
-       int a, b;
-{
-       return (a < b ? a : b);
-}