home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume18 / upsd / patch03 / Patch03 next >
Text File  |  1991-04-20  |  16KB  |  593 lines

  1. *** HISTORY.orig    Mon Apr 15 23:25:28 1991
  2. --- HISTORY    Mon Apr 15 23:26:03 1991
  3. ***************
  4. *** 1,3 ****
  5. --- 1,4 ----
  6.   UPSD RELEASE HISTORY    art@pilikia.pegasus.com
  7.   
  8.   Date      Release  Patch  Description
  9. ***************
  10. *** 7,9 ****
  11. --- 8,13 ----
  12.                             added version stuff.
  13.   04/10/91  1.0      2      Added log file locking, only 1 upsd can be running
  14.                             now.  Also added date to version string.
  15. + 04/15/91  1.0      3      Added broadcast of power fail and restore messages,
  16. +                           defined message file names as new command line and
  17. +                           environment variable parameters.  Also made man page.
  18. *** MANIFEST.orig    Mon Apr 15 23:25:28 1991
  19. --- MANIFEST    Mon Apr 15 23:26:03 1991
  20. ***************
  21. *** 8,11 ****
  22. --- 8,14 ----
  23.    funcs.c                    1    Functions 
  24.    main.c                     1    Main program
  25.    ups                        1    Init.d startup script
  26. +  upsd.1                     1    Upsd man page
  27. +  upsfail                    1    UPS failure message file
  28. +  upsrest                    1    UPS restore message file
  29.    version.h                  1    Version control header
  30. *** Makefile.orig    Mon Apr 15 23:25:28 1991
  31. --- Makefile    Mon Apr 15 23:26:03 1991
  32. ***************
  33. *** 11,24 ****
  34.   CC = cc
  35.   DEFS =
  36.   CFLAGS = -O $(DEFS)
  37.   CFILES = main.c funcs.c
  38.   OFILES = main.o funcs.o
  39.   HFILES = common.h
  40. ! LIBES =
  41.   DESTDIR = /etc
  42.   INITDIR = /etc/init.d
  43.   RC2DIR = /etc/rc2.d
  44.   RC2NUM = 22
  45.   
  46.   upsd: $(OFILES)
  47.       $(CC) $(CFLAGS) $(OFILES) -o $@ $(LIBES)
  48. --- 11,27 ----
  49.   CC = cc
  50.   DEFS =
  51.   CFLAGS = -O $(DEFS)
  52. + LIBES =
  53.   CFILES = main.c funcs.c
  54.   OFILES = main.o funcs.o
  55.   HFILES = common.h
  56.   DESTDIR = /etc
  57.   INITDIR = /etc/init.d
  58.   RC2DIR = /etc/rc2.d
  59.   RC2NUM = 22
  60. + MANDIR = /usr/catman/u_man/man1
  61.   
  62.   upsd: $(OFILES)
  63.       $(CC) $(CFLAGS) $(OFILES) -o $@ $(LIBES)
  64. ***************
  65. *** 31,37 ****
  66.       chgrp sys $(DESTDIR)/upsd
  67.       chmod 550 $(DESTDIR)/upsd
  68.   
  69. ! install_rc: install
  70.       cp ups $(INITDIR)/ups
  71.       chown root $(INITDIR)/ups
  72.       chgrp sys $(INITDIR)/ups
  73. --- 34,40 ----
  74.       chgrp sys $(DESTDIR)/upsd
  75.       chmod 550 $(DESTDIR)/upsd
  76.   
  77. ! install_rc:
  78.       cp ups $(INITDIR)/ups
  79.       chown root $(INITDIR)/ups
  80.       chgrp sys $(INITDIR)/ups
  81. ***************
  82. *** 38,43 ****
  83. --- 41,57 ----
  84.       chmod 744 $(INITDIR)/ups
  85.       ln $(INITDIR)/ups $(RC2DIR)/S$(RC2NUM)ups
  86.   
  87. + install_msg:
  88. +     cp upsfail upsrest $(DESTDIR)
  89. +     chown root $(DESTDIR)/upsfail $(DESTDIR)/upsrest
  90. +     chgrp sys $(DESTDIR)/upsfail $(DESTDIR)/upsrest
  91. +     chmod 644 $(DESTDIR)/upsfail $(DESTDIR)/upsrest
  92. + install_man:
  93. +     rm -f $(MANDIR)/upsd.1.z
  94. +     nroff -man upsd.1 > $(MANDIR)/upsd.1
  95. +     pack $(MANDIR)/upsd.1
  96.   indent:
  97.       @for f in $(CFILES); do \
  98.           indent $$f; \
  99. ***************
  100. *** 50,56 ****
  101.       rm -f upsd core *.o *.BAK Part*
  102.   
  103.   clobber: clean
  104. !     rm -f $(DESTDIR)/upsd $(INITDIR)/ups $(RC2DIR)/S$(RC2NUM)ups
  105.   
  106.   # dependencies
  107.   main.o:        main.c $(HFILES)
  108. --- 64,71 ----
  109.       rm -f upsd core *.o *.BAK Part*
  110.   
  111.   clobber: clean
  112. !     rm -f $(DESTDIR)/upsd $(DESTDIR)/upsfail $(DESTDIR)/upsrest
  113. !     rm -f $(INITDIR)/ups $(RC2DIR)/S$(RC2NUM)ups
  114.   
  115.   # dependencies
  116.   main.o:        main.c $(HFILES)
  117. *** README.orig    Mon Apr 15 23:25:28 1991
  118. --- README    Mon Apr 15 23:26:03 1991
  119. ***************
  120. *** 1,4 ****
  121. !      Tue Apr 02 23:24:20 HST 1991    art@pilikia.pegasus.com        Pg. 1
  122.    
  123.   
  124.       INTRODUCTION
  125. --- 1,4 ----
  126. !      upsd release 03/30/91 version 1.0 patchlevel 3            Pg. 1
  127.    
  128.   
  129.       INTRODUCTION
  130. ***************
  131. *** 24,30 ****
  132.       in the /etc directory when the install target is made.  
  133.   
  134.   
  135. !      Tue Apr 02 23:24:20 HST 1991    art@pilikia.pegasus.com        Pg. 2
  136.   
  137.   
  138.       COMMAND LINE OPTIONS
  139. --- 24,30 ----
  140.       in the /etc directory when the install target is made.  
  141.   
  142.   
  143. !      upsd release 03/30/91 version 1.0 patchlevel 3            Pg. 2
  144.   
  145.   
  146.       COMMAND LINE OPTIONS
  147. ***************
  148. *** 34,43 ****
  149.       take precedence to the environment variable settings, and are
  150.       as follows:
  151.   
  152. !     usage: upsd [-d tty][-c cmd][-l log][-t min]
  153.           -d tty        pathname of UPS device
  154.           -c cmd        pathname of shutdown command
  155. !         -l log        pathname of UPS log file
  156.           -t min        delay time in minutes
  157.   
  158.       The -d tty option must specify the full pathname (including the
  159. --- 34,45 ----
  160.       take precedence to the environment variable settings, and are
  161.       as follows:
  162.   
  163. !     usage: upsd [-d tty][-c cmd][-l file][-t min][-f file][-r file]
  164.           -d tty        pathname of UPS device
  165.           -c cmd        pathname of shutdown command
  166. !         -l file        pathname of UPS log file
  167. !         -f file        pathname of UPS fail message file
  168. !         -r file        pathname of UPS restore message file
  169.           -t min        delay time in minutes
  170.   
  171.       The -d tty option must specify the full pathname (including the
  172. ***************
  173. *** 53,61 ****
  174.   
  175.       Example:
  176.   
  177. !     upsd -d /dev/ttyFM00 -c "/etc/shutdown -y -g1 -i0"
  178.   
  179. !     The -l option specified the logfile upsd will write it's event
  180.       messages to, these messages give the date and time that the UPS
  181.       daemon started, switched to battery, switched back to online,
  182.       executed the shutdown command, or was terminated via SIGTERM.
  183. --- 55,63 ----
  184.   
  185.       Example:
  186.   
  187. !     upsd -c "/etc/shutdown -y -i0"
  188.   
  189. !     The -l option specifies the logfile upsd will write it's event
  190.       messages to, these messages give the date and time that the UPS
  191.       daemon started, switched to battery, switched back to online,
  192.       executed the shutdown command, or was terminated via SIGTERM.
  193. ***************
  194. *** 62,69 ****
  195.   
  196.       Example:
  197.   
  198. !     upsd -d /dev/ttyFM00 -c "/etc/shutdown -y -g1 -i0" -l /etc/upslog
  199.   
  200.       Finally, the -t option specifies the number of minutes to allow
  201.       the UPS to be on battery backup before executing the shutdown
  202.       sequence.  This number must be between 1 and 30.  Be careful not
  203. --- 64,91 ----
  204.   
  205.       Example:
  206.   
  207. !     upsd -l /etc/upslog
  208.   
  209. +     The -f option specifies the path name of the failure message file
  210. +     to broadcast to all users in the event of a power failure.  The
  211. +     failure message file is simply an ASCII text file which you can
  212. +     create with an editor such as vi(1). If the file is not found by
  213. +     upsd, no message will be broadcast upon power failure.
  214. +     Example:
  215. +     upsd -f /etc/upsfail
  216. +     The -r option specifies the path name of the restore message file
  217. +     to broadcast to all users in the event of power restore.  The
  218. +     restore message file is simply an ASCII text file which you can
  219. +     create with an editor such as vi(1). If the file is not found by
  220. +     upsd, no message will be broadcast upon power restore.
  221. +     Example:
  222. +     upsd -f /etc/upsrest
  223.       Finally, the -t option specifies the number of minutes to allow
  224.       the UPS to be on battery backup before executing the shutdown
  225.       sequence.  This number must be between 1 and 30.  Be careful not
  226. ***************
  227. *** 73,81 ****
  228.   
  229.       Example:
  230.   
  231. !     upsd -d /dev/ttyFM00 -c "/etc/shutdown -y -g1 -i0" -l /etc/upslog -t 10
  232.       
  233. !      Tue Apr 02 23:24:20 HST 1991    art@pilikia.pegasus.com        Pg. 3
  234.   
  235.   
  236.       ENVIRONMENT VARIABLES
  237. --- 95,103 ----
  238.   
  239.       Example:
  240.   
  241. !     upsd -t 10
  242.       
  243. !      upsd release 03/30/91 version 1.0 patchlevel 3            Pg. 3
  244.   
  245.   
  246.       ENVIRONMENT VARIABLES
  247. ***************
  248. *** 88,95 ****
  249.       Environment    Equivalent        Default
  250.       Variable    Command line option    Value
  251.       UPSPORT            -p        /dev/ttyFM00
  252. !     UPSSHUT            -c        "/etc/shutdown -y -g1 -i0"
  253.       UPSLOG            -l        /etc/upslog
  254.       UPSTIME            -t        10
  255.   
  256.       Note that the compiled in default values can be altered in common.h
  257. --- 110,119 ----
  258.       Environment    Equivalent        Default
  259.       Variable    Command line option    Value
  260.       UPSPORT            -p        /dev/ttyFM00
  261. !     UPSSHUT            -c        "/etc/shutdown -y -i0"
  262.       UPSLOG            -l        /etc/upslog
  263. +     UPSFAIL            -f        /etc/upsfail
  264. +     UPSREST            -r        /etc/upsrest
  265.       UPSTIME            -t        10
  266.   
  267.       Note that the compiled in default values can be altered in common.h
  268. *** common.h.orig    Mon Apr 15 23:25:28 1991
  269. --- common.h    Mon Apr 15 23:26:03 1991
  270. ***************
  271. *** 22,39 ****
  272.   
  273.   #define ERR        -1        /* error return value */
  274.   #define SH        "/bin/sh"    /* shell to exec shutdown command */
  275. ! #define ROOT        "/"        /* root directory for chdir */
  276.   #define CONSOLE        "/dev/console"    /* console device */
  277.   #define SECS_PER_MIN    60        /* number of secs in a minute */
  278.   #define MAX_TIME    30        /* maximum delay time allowed */
  279. - #define SHUT_PERMS    0500        /* shutdown command permissions mask */
  280.   #define LOG_PERMS    0600        /* logfile permissions on create */
  281.   #define LOG_FLAGS    O_WRONLY | O_CREAT | O_APPEND    /* logfile open flags */
  282.   
  283.   /* default tuneable parameter values */
  284.   #define UPS_PORT    "/dev/ttyFM00"    /* UPS port device name */
  285. ! #define UPS_SHUT    "/etc/shutdown -y -g0"    /* shutdown command */
  286.   #define UPS_LOG        "/etc/upslog"    /* UPS log file pathname */
  287.   #define UPS_TIME    10        /* default delay time (minutes) */
  288.   
  289.   /* environment variable names */
  290. --- 22,41 ----
  291.   
  292.   #define ERR        -1        /* error return value */
  293.   #define SH        "/bin/sh"    /* shell to exec shutdown command */
  294. ! #define WALL        "/etc/wall"    /* utility to broadcast messages */
  295.   #define CONSOLE        "/dev/console"    /* console device */
  296. + #define ROOT        "/"        /* root directory for chdir */
  297.   #define SECS_PER_MIN    60        /* number of secs in a minute */
  298.   #define MAX_TIME    30        /* maximum delay time allowed */
  299.   #define LOG_PERMS    0600        /* logfile permissions on create */
  300.   #define LOG_FLAGS    O_WRONLY | O_CREAT | O_APPEND    /* logfile open flags */
  301.   
  302.   /* default tuneable parameter values */
  303.   #define UPS_PORT    "/dev/ttyFM00"    /* UPS port device name */
  304. ! #define UPS_SHUT    "/etc/shutdown -y -i0"    /* shutdown command */
  305.   #define UPS_LOG        "/etc/upslog"    /* UPS log file pathname */
  306. + #define UPS_FAIL    "/etc/upsfail"    /* UPS fail message file name */
  307. + #define UPS_REST    "/etc/upsrest"    /* UPS restore message file name */
  308.   #define UPS_TIME    10        /* default delay time (minutes) */
  309.   
  310.   /* environment variable names */
  311. ***************
  312. *** 40,45 ****
  313. --- 42,49 ----
  314.   #define UPSPORT        "UPSPORT"
  315.   #define UPSSHUT        "UPSSHUT"
  316.   #define UPSLOG        "UPSLOG"
  317. + #define UPSFAIL        "UPSFAIL"
  318. + #define UPSREST        "UPSREST"
  319.   #define UPSTIME        "UPSTIME"
  320.   
  321.   /* UPS log messages */
  322. ***************
  323. *** 54,59 ****
  324. --- 58,65 ----
  325.   extern char   *ups_port;        /* UPS device name */
  326.   extern char   *ups_shut;        /* system shutdown command */
  327.   extern char   *ups_log;            /* UPS log file name */
  328. + extern char   *ups_fail;        /* UPS failure message file name */
  329. + extern char   *ups_rest;        /* UPS restore message file name */
  330.   extern int     ups_time;        /* delay time before shutdown */
  331.   extern int     ups_fd;            /* UPS port descriptor */
  332.   extern int     log_fd;            /* log file descriptor */
  333. *** funcs.c.orig    Mon Apr 15 23:25:28 1991
  334. --- funcs.c    Mon Apr 15 23:26:03 1991
  335. ***************
  336. *** 26,31 ****
  337. --- 26,35 ----
  338.           ups_shut = s;
  339.       if ((s = getenv(UPSLOG)) != NULL)
  340.           ups_log = s;
  341. +     if ((s = getenv(UPSFAIL)) != NULL)
  342. +         ups_fail = s;
  343. +     if ((s = getenv(UPSREST)) != NULL)
  344. +         ups_rest = s;
  345.       if ((s = getenv(UPSTIME)) != NULL)
  346.           ups_time = atoi(s);
  347.   }
  348. ***************
  349. *** 52,58 ****
  350.       version(av[0]);
  351.   
  352.       /* parse the command line */
  353. !     while ((c = getopt(ac, av, "d:c:l:t:")) != EOF)
  354.           switch (c) {
  355.           case 'd':    /* device option */
  356.               ups_port = optarg;
  357. --- 56,62 ----
  358.       version(av[0]);
  359.   
  360.       /* parse the command line */
  361. !     while ((c = getopt(ac, av, "d:c:l:f:r:t:")) != EOF)
  362.           switch (c) {
  363.           case 'd':    /* device option */
  364.               ups_port = optarg;
  365. ***************
  366. *** 63,68 ****
  367. --- 67,78 ----
  368.           case 'l':    /* logfile option */
  369.               ups_log = optarg;
  370.               break;
  371. +         case 'f':    /* failure option */
  372. +             ups_fail = optarg;
  373. +             break;
  374. +         case 'r':    /* restore option */
  375. +             ups_rest = optarg;
  376. +             break;
  377.           case 't':    /* time option */
  378.               ups_time = atoi(optarg);
  379.               break;
  380. ***************
  381. *** 76,81 ****
  382. --- 86,92 ----
  383.   **    c h k o p t i o n s
  384.   **
  385.   **    check runtime options
  386. + **    with various sanity tests
  387.   */
  388.   void
  389.   chkoptions()
  390. ***************
  391. *** 103,111 ****
  392.           perror(ups_shut);
  393.           exit(1);
  394.       }
  395. !     /* and must be readable/executable by owner */
  396. !     if (!(st.st_mode & SHUT_PERMS)) {
  397. !         fprintf(stderr, "%s must be readable/executable by owner\n", ups_port);
  398.           exit(1);
  399.       }
  400.       /* delay time must be > 0 and <= MAX_TIME */
  401. --- 114,122 ----
  402.           perror(ups_shut);
  403.           exit(1);
  404.       }
  405. !     /* and must be a regular file */
  406. !     if ((st.st_mode & S_IFMT) != S_IFREG) {
  407. !         fprintf(stderr, "%s not regular\n", ups_port);
  408.           exit(1);
  409.       }
  410.       /* delay time must be > 0 and <= MAX_TIME */
  411. ***************
  412. *** 127,132 ****
  413. --- 138,144 ----
  414.   
  415.       void    sigcatch();
  416.       void    writelog();
  417. +     void    writeall();
  418.       void    shutdown();
  419.   
  420.       if (!fork()) {
  421. ***************
  422. *** 166,171 ****
  423. --- 178,186 ----
  424.           }
  425.           writelog(BATTERY_MSG);
  426.   
  427. +         /* broadcast failure message */
  428. +         writeall(ups_fail);
  429.           /* set the alarm clock */
  430.           alarm(ups_time * SECS_PER_MIN);
  431.   
  432. ***************
  433. *** 175,180 ****
  434. --- 190,198 ----
  435.   
  436.           writelog(ONLINE_MSG);
  437.   
  438. +         /* broadcast restore message */
  439. +         writeall(ups_rest);
  440.           close(log_fd);
  441.           close(ups_fd);
  442.   
  443. ***************
  444. *** 191,198 ****
  445. --- 209,218 ----
  446.   sigcatch()
  447.   {
  448.       writelog(TERM_MSG);
  449.       close(log_fd);
  450.       close(ups_fd);
  451.       exit(1);
  452.   }
  453.   
  454. ***************
  455. *** 221,226 ****
  456. --- 241,275 ----
  457.   }
  458.   
  459.   /*
  460. + **    w r i t e a l l
  461. + **
  462. + **    write to all users
  463. + */
  464. + void
  465. + writeall(fn)
  466. + char   *fn;
  467. + {
  468. +     struct stat st;
  469. +     void    attach();
  470. +     /* message file must exist */
  471. +     if (stat(fn, &st) == ERR)
  472. +         return;
  473. +     /* and must be a regular file */
  474. +     if ((st.st_mode & S_IFMT) != S_IFREG)
  475. +         return;
  476. +     if (!fork()) {
  477. +         attach(CONSOLE);
  478. +         /* write message file to users */
  479. +         execlp(WALL, WALL, fn, NULL);
  480. +     }
  481. + }
  482. + /*
  483.   **    s h u t d o w n
  484.   **
  485.   **    shutdown the system
  486. ***************
  487. *** 232,246 ****
  488.   
  489.       writelog(SHUTDOWN_MSG);
  490.   
  491. !     close(log_fd);
  492. !     close(ups_fd);
  493.   
  494. !     attach(CONSOLE);
  495.   
  496. !     chdir(ROOT);
  497.   
  498. !     /* execute shutdown command */
  499. !     execlp(SH, SH, "-c", ups_shut, NULL);
  500.   }
  501.   
  502.   /*
  503. --- 281,298 ----
  504.   
  505.       writelog(SHUTDOWN_MSG);
  506.   
  507. !     close(ups_log);
  508. !     close(ups_port);
  509.   
  510. !     if (!fork()) {
  511. !         attach(CONSOLE);
  512.   
  513. !         chdir(ROOT);
  514.   
  515. !         /* execute shutdown command */
  516. !         execlp(SH, SH, "-c", ups_shut, NULL);
  517. !     }
  518.   }
  519.   
  520.   /*
  521. ***************
  522. *** 314,323 ****
  523.   {
  524.       char   *basename();
  525.   
  526. !     fprintf(stderr, "usage: %s [-d tty][-c cmd][-l log][-t min][-v]\n",
  527. !         basename(s));
  528.       fprintf(stderr, "\t-d tty\t\tpathname of UPS device\n");
  529.       fprintf(stderr, "\t-c cmd\t\tpathname of shutdown command\n");
  530. !     fprintf(stderr, "\t-l log\t\tpathname of UPS log file\n");
  531.       fprintf(stderr, "\t-t min\t\tdelay time in minutes\n");
  532.   }
  533. --- 366,376 ----
  534.   {
  535.       char   *basename();
  536.   
  537. !     fprintf(stderr, "usage: %s [-d tty][-c cmd][-l file][-f file][-r file][-t min]\n", basename(s));
  538.       fprintf(stderr, "\t-d tty\t\tpathname of UPS device\n");
  539.       fprintf(stderr, "\t-c cmd\t\tpathname of shutdown command\n");
  540. !     fprintf(stderr, "\t-l file\t\tpathname of UPS log file\n");
  541. !     fprintf(stderr, "\t-f file\t\tpathname of UPS fail message file\n");
  542. !     fprintf(stderr, "\t-r file\t\tpathname of UPS restore message file\n");
  543.       fprintf(stderr, "\t-t min\t\tdelay time in minutes\n");
  544.   }
  545. *** main.c.orig    Mon Apr 15 23:25:28 1991
  546. --- main.c    Mon Apr 15 23:26:03 1991
  547. ***************
  548. *** 14,19 ****
  549. --- 14,21 ----
  550.   char   *ups_port = UPS_PORT;
  551.   char   *ups_shut = UPS_SHUT;
  552.   char   *ups_log = UPS_LOG;
  553. + char   *ups_fail = UPS_FAIL;
  554. + char   *ups_rest = UPS_REST;
  555.   int     ups_time = UPS_TIME;
  556.   
  557.   /* global descriptors */
  558. *** version.h.orig    Mon Apr 15 23:25:28 1991
  559. --- version.h    Mon Apr 15 23:26:03 1991
  560. ***************
  561. *** 11,14 ****
  562.   #define RELEASE_DATE    "03/30/91"
  563.   #define RELEASE        1
  564.   #define REVISION    0
  565. ! #define PATCHLEVEL    2
  566. --- 11,14 ----
  567.   #define RELEASE_DATE    "03/30/91"
  568.   #define RELEASE        1
  569.   #define REVISION    0
  570. ! #define PATCHLEVEL    3
  571.