home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
misc
/
volume18
/
upsd
/
patch03
/
Patch03
next >
Wrap
Text File
|
1991-04-20
|
16KB
|
593 lines
*** HISTORY.orig Mon Apr 15 23:25:28 1991
--- HISTORY Mon Apr 15 23:26:03 1991
***************
*** 1,3 ****
--- 1,4 ----
+
UPSD RELEASE HISTORY art@pilikia.pegasus.com
Date Release Patch Description
***************
*** 7,9 ****
--- 8,13 ----
added version stuff.
04/10/91 1.0 2 Added log file locking, only 1 upsd can be running
now. Also added date to version string.
+ 04/15/91 1.0 3 Added broadcast of power fail and restore messages,
+ defined message file names as new command line and
+ environment variable parameters. Also made man page.
*** MANIFEST.orig Mon Apr 15 23:25:28 1991
--- MANIFEST Mon Apr 15 23:26:03 1991
***************
*** 8,11 ****
--- 8,14 ----
funcs.c 1 Functions
main.c 1 Main program
ups 1 Init.d startup script
+ upsd.1 1 Upsd man page
+ upsfail 1 UPS failure message file
+ upsrest 1 UPS restore message file
version.h 1 Version control header
*** Makefile.orig Mon Apr 15 23:25:28 1991
--- Makefile Mon Apr 15 23:26:03 1991
***************
*** 11,24 ****
CC = cc
DEFS =
CFLAGS = -O $(DEFS)
CFILES = main.c funcs.c
OFILES = main.o funcs.o
HFILES = common.h
! LIBES =
DESTDIR = /etc
INITDIR = /etc/init.d
RC2DIR = /etc/rc2.d
RC2NUM = 22
upsd: $(OFILES)
$(CC) $(CFLAGS) $(OFILES) -o $@ $(LIBES)
--- 11,27 ----
CC = cc
DEFS =
CFLAGS = -O $(DEFS)
+ LIBES =
+
CFILES = main.c funcs.c
OFILES = main.o funcs.o
HFILES = common.h
!
DESTDIR = /etc
INITDIR = /etc/init.d
RC2DIR = /etc/rc2.d
RC2NUM = 22
+ MANDIR = /usr/catman/u_man/man1
upsd: $(OFILES)
$(CC) $(CFLAGS) $(OFILES) -o $@ $(LIBES)
***************
*** 31,37 ****
chgrp sys $(DESTDIR)/upsd
chmod 550 $(DESTDIR)/upsd
! install_rc: install
cp ups $(INITDIR)/ups
chown root $(INITDIR)/ups
chgrp sys $(INITDIR)/ups
--- 34,40 ----
chgrp sys $(DESTDIR)/upsd
chmod 550 $(DESTDIR)/upsd
! install_rc:
cp ups $(INITDIR)/ups
chown root $(INITDIR)/ups
chgrp sys $(INITDIR)/ups
***************
*** 38,43 ****
--- 41,57 ----
chmod 744 $(INITDIR)/ups
ln $(INITDIR)/ups $(RC2DIR)/S$(RC2NUM)ups
+ install_msg:
+ cp upsfail upsrest $(DESTDIR)
+ chown root $(DESTDIR)/upsfail $(DESTDIR)/upsrest
+ chgrp sys $(DESTDIR)/upsfail $(DESTDIR)/upsrest
+ chmod 644 $(DESTDIR)/upsfail $(DESTDIR)/upsrest
+
+ install_man:
+ rm -f $(MANDIR)/upsd.1.z
+ nroff -man upsd.1 > $(MANDIR)/upsd.1
+ pack $(MANDIR)/upsd.1
+
indent:
@for f in $(CFILES); do \
indent $$f; \
***************
*** 50,56 ****
rm -f upsd core *.o *.BAK Part*
clobber: clean
! rm -f $(DESTDIR)/upsd $(INITDIR)/ups $(RC2DIR)/S$(RC2NUM)ups
# dependencies
main.o: main.c $(HFILES)
--- 64,71 ----
rm -f upsd core *.o *.BAK Part*
clobber: clean
! rm -f $(DESTDIR)/upsd $(DESTDIR)/upsfail $(DESTDIR)/upsrest
! rm -f $(INITDIR)/ups $(RC2DIR)/S$(RC2NUM)ups
# dependencies
main.o: main.c $(HFILES)
*** README.orig Mon Apr 15 23:25:28 1991
--- README Mon Apr 15 23:26:03 1991
***************
*** 1,4 ****
! Tue Apr 02 23:24:20 HST 1991 art@pilikia.pegasus.com Pg. 1
INTRODUCTION
--- 1,4 ----
! upsd release 03/30/91 version 1.0 patchlevel 3 Pg. 1
INTRODUCTION
***************
*** 24,30 ****
in the /etc directory when the install target is made.
! Tue Apr 02 23:24:20 HST 1991 art@pilikia.pegasus.com Pg. 2
COMMAND LINE OPTIONS
--- 24,30 ----
in the /etc directory when the install target is made.
! upsd release 03/30/91 version 1.0 patchlevel 3 Pg. 2
COMMAND LINE OPTIONS
***************
*** 34,43 ****
take precedence to the environment variable settings, and are
as follows:
! usage: upsd [-d tty][-c cmd][-l log][-t min]
-d tty pathname of UPS device
-c cmd pathname of shutdown command
! -l log pathname of UPS log file
-t min delay time in minutes
The -d tty option must specify the full pathname (including the
--- 34,45 ----
take precedence to the environment variable settings, and are
as follows:
! usage: upsd [-d tty][-c cmd][-l file][-t min][-f file][-r file]
-d tty pathname of UPS device
-c cmd pathname of shutdown command
! -l file pathname of UPS log file
! -f file pathname of UPS fail message file
! -r file pathname of UPS restore message file
-t min delay time in minutes
The -d tty option must specify the full pathname (including the
***************
*** 53,61 ****
Example:
! upsd -d /dev/ttyFM00 -c "/etc/shutdown -y -g1 -i0"
! The -l option specified the logfile upsd will write it's event
messages to, these messages give the date and time that the UPS
daemon started, switched to battery, switched back to online,
executed the shutdown command, or was terminated via SIGTERM.
--- 55,63 ----
Example:
! upsd -c "/etc/shutdown -y -i0"
! The -l option specifies the logfile upsd will write it's event
messages to, these messages give the date and time that the UPS
daemon started, switched to battery, switched back to online,
executed the shutdown command, or was terminated via SIGTERM.
***************
*** 62,69 ****
Example:
! upsd -d /dev/ttyFM00 -c "/etc/shutdown -y -g1 -i0" -l /etc/upslog
Finally, the -t option specifies the number of minutes to allow
the UPS to be on battery backup before executing the shutdown
sequence. This number must be between 1 and 30. Be careful not
--- 64,91 ----
Example:
! upsd -l /etc/upslog
+ The -f option specifies the path name of the failure message file
+ to broadcast to all users in the event of a power failure. The
+ failure message file is simply an ASCII text file which you can
+ create with an editor such as vi(1). If the file is not found by
+ upsd, no message will be broadcast upon power failure.
+
+ Example:
+
+ upsd -f /etc/upsfail
+
+ The -r option specifies the path name of the restore message file
+ to broadcast to all users in the event of power restore. The
+ restore message file is simply an ASCII text file which you can
+ create with an editor such as vi(1). If the file is not found by
+ upsd, no message will be broadcast upon power restore.
+
+ Example:
+
+ upsd -f /etc/upsrest
+
Finally, the -t option specifies the number of minutes to allow
the UPS to be on battery backup before executing the shutdown
sequence. This number must be between 1 and 30. Be careful not
***************
*** 73,81 ****
Example:
! upsd -d /dev/ttyFM00 -c "/etc/shutdown -y -g1 -i0" -l /etc/upslog -t 10
! Tue Apr 02 23:24:20 HST 1991 art@pilikia.pegasus.com Pg. 3
ENVIRONMENT VARIABLES
--- 95,103 ----
Example:
! upsd -t 10
! upsd release 03/30/91 version 1.0 patchlevel 3 Pg. 3
ENVIRONMENT VARIABLES
***************
*** 88,95 ****
Environment Equivalent Default
Variable Command line option Value
UPSPORT -p /dev/ttyFM00
! UPSSHUT -c "/etc/shutdown -y -g1 -i0"
UPSLOG -l /etc/upslog
UPSTIME -t 10
Note that the compiled in default values can be altered in common.h
--- 110,119 ----
Environment Equivalent Default
Variable Command line option Value
UPSPORT -p /dev/ttyFM00
! UPSSHUT -c "/etc/shutdown -y -i0"
UPSLOG -l /etc/upslog
+ UPSFAIL -f /etc/upsfail
+ UPSREST -r /etc/upsrest
UPSTIME -t 10
Note that the compiled in default values can be altered in common.h
*** common.h.orig Mon Apr 15 23:25:28 1991
--- common.h Mon Apr 15 23:26:03 1991
***************
*** 22,39 ****
#define ERR -1 /* error return value */
#define SH "/bin/sh" /* shell to exec shutdown command */
! #define ROOT "/" /* root directory for chdir */
#define CONSOLE "/dev/console" /* console device */
#define SECS_PER_MIN 60 /* number of secs in a minute */
#define MAX_TIME 30 /* maximum delay time allowed */
- #define SHUT_PERMS 0500 /* shutdown command permissions mask */
#define LOG_PERMS 0600 /* logfile permissions on create */
#define LOG_FLAGS O_WRONLY | O_CREAT | O_APPEND /* logfile open flags */
/* default tuneable parameter values */
#define UPS_PORT "/dev/ttyFM00" /* UPS port device name */
! #define UPS_SHUT "/etc/shutdown -y -g0" /* shutdown command */
#define UPS_LOG "/etc/upslog" /* UPS log file pathname */
#define UPS_TIME 10 /* default delay time (minutes) */
/* environment variable names */
--- 22,41 ----
#define ERR -1 /* error return value */
#define SH "/bin/sh" /* shell to exec shutdown command */
! #define WALL "/etc/wall" /* utility to broadcast messages */
#define CONSOLE "/dev/console" /* console device */
+ #define ROOT "/" /* root directory for chdir */
#define SECS_PER_MIN 60 /* number of secs in a minute */
#define MAX_TIME 30 /* maximum delay time allowed */
#define LOG_PERMS 0600 /* logfile permissions on create */
#define LOG_FLAGS O_WRONLY | O_CREAT | O_APPEND /* logfile open flags */
/* default tuneable parameter values */
#define UPS_PORT "/dev/ttyFM00" /* UPS port device name */
! #define UPS_SHUT "/etc/shutdown -y -i0" /* shutdown command */
#define UPS_LOG "/etc/upslog" /* UPS log file pathname */
+ #define UPS_FAIL "/etc/upsfail" /* UPS fail message file name */
+ #define UPS_REST "/etc/upsrest" /* UPS restore message file name */
#define UPS_TIME 10 /* default delay time (minutes) */
/* environment variable names */
***************
*** 40,45 ****
--- 42,49 ----
#define UPSPORT "UPSPORT"
#define UPSSHUT "UPSSHUT"
#define UPSLOG "UPSLOG"
+ #define UPSFAIL "UPSFAIL"
+ #define UPSREST "UPSREST"
#define UPSTIME "UPSTIME"
/* UPS log messages */
***************
*** 54,59 ****
--- 58,65 ----
extern char *ups_port; /* UPS device name */
extern char *ups_shut; /* system shutdown command */
extern char *ups_log; /* UPS log file name */
+ extern char *ups_fail; /* UPS failure message file name */
+ extern char *ups_rest; /* UPS restore message file name */
extern int ups_time; /* delay time before shutdown */
extern int ups_fd; /* UPS port descriptor */
extern int log_fd; /* log file descriptor */
*** funcs.c.orig Mon Apr 15 23:25:28 1991
--- funcs.c Mon Apr 15 23:26:03 1991
***************
*** 26,31 ****
--- 26,35 ----
ups_shut = s;
if ((s = getenv(UPSLOG)) != NULL)
ups_log = s;
+ if ((s = getenv(UPSFAIL)) != NULL)
+ ups_fail = s;
+ if ((s = getenv(UPSREST)) != NULL)
+ ups_rest = s;
if ((s = getenv(UPSTIME)) != NULL)
ups_time = atoi(s);
}
***************
*** 52,58 ****
version(av[0]);
/* parse the command line */
! while ((c = getopt(ac, av, "d:c:l:t:")) != EOF)
switch (c) {
case 'd': /* device option */
ups_port = optarg;
--- 56,62 ----
version(av[0]);
/* parse the command line */
! while ((c = getopt(ac, av, "d:c:l:f:r:t:")) != EOF)
switch (c) {
case 'd': /* device option */
ups_port = optarg;
***************
*** 63,68 ****
--- 67,78 ----
case 'l': /* logfile option */
ups_log = optarg;
break;
+ case 'f': /* failure option */
+ ups_fail = optarg;
+ break;
+ case 'r': /* restore option */
+ ups_rest = optarg;
+ break;
case 't': /* time option */
ups_time = atoi(optarg);
break;
***************
*** 76,81 ****
--- 86,92 ----
** c h k o p t i o n s
**
** check runtime options
+ ** with various sanity tests
*/
void
chkoptions()
***************
*** 103,111 ****
perror(ups_shut);
exit(1);
}
! /* and must be readable/executable by owner */
! if (!(st.st_mode & SHUT_PERMS)) {
! fprintf(stderr, "%s must be readable/executable by owner\n", ups_port);
exit(1);
}
/* delay time must be > 0 and <= MAX_TIME */
--- 114,122 ----
perror(ups_shut);
exit(1);
}
! /* and must be a regular file */
! if ((st.st_mode & S_IFMT) != S_IFREG) {
! fprintf(stderr, "%s not regular\n", ups_port);
exit(1);
}
/* delay time must be > 0 and <= MAX_TIME */
***************
*** 127,132 ****
--- 138,144 ----
void sigcatch();
void writelog();
+ void writeall();
void shutdown();
if (!fork()) {
***************
*** 166,171 ****
--- 178,186 ----
}
writelog(BATTERY_MSG);
+ /* broadcast failure message */
+ writeall(ups_fail);
+
/* set the alarm clock */
alarm(ups_time * SECS_PER_MIN);
***************
*** 175,180 ****
--- 190,198 ----
writelog(ONLINE_MSG);
+ /* broadcast restore message */
+ writeall(ups_rest);
+
close(log_fd);
close(ups_fd);
***************
*** 191,198 ****
--- 209,218 ----
sigcatch()
{
writelog(TERM_MSG);
+
close(log_fd);
close(ups_fd);
+
exit(1);
}
***************
*** 221,226 ****
--- 241,275 ----
}
/*
+ ** w r i t e a l l
+ **
+ ** write to all users
+ */
+ void
+ writeall(fn)
+ char *fn;
+ {
+ struct stat st;
+ void attach();
+
+ /* message file must exist */
+ if (stat(fn, &st) == ERR)
+ return;
+
+ /* and must be a regular file */
+ if ((st.st_mode & S_IFMT) != S_IFREG)
+ return;
+
+ if (!fork()) {
+
+ attach(CONSOLE);
+
+ /* write message file to users */
+ execlp(WALL, WALL, fn, NULL);
+ }
+ }
+
+ /*
** s h u t d o w n
**
** shutdown the system
***************
*** 232,246 ****
writelog(SHUTDOWN_MSG);
! close(log_fd);
! close(ups_fd);
! attach(CONSOLE);
! chdir(ROOT);
! /* execute shutdown command */
! execlp(SH, SH, "-c", ups_shut, NULL);
}
/*
--- 281,298 ----
writelog(SHUTDOWN_MSG);
! close(ups_log);
! close(ups_port);
! if (!fork()) {
!
! attach(CONSOLE);
! chdir(ROOT);
! /* execute shutdown command */
! execlp(SH, SH, "-c", ups_shut, NULL);
! }
}
/*
***************
*** 314,323 ****
{
char *basename();
! fprintf(stderr, "usage: %s [-d tty][-c cmd][-l log][-t min][-v]\n",
! basename(s));
fprintf(stderr, "\t-d tty\t\tpathname of UPS device\n");
fprintf(stderr, "\t-c cmd\t\tpathname of shutdown command\n");
! fprintf(stderr, "\t-l log\t\tpathname of UPS log file\n");
fprintf(stderr, "\t-t min\t\tdelay time in minutes\n");
}
--- 366,376 ----
{
char *basename();
! fprintf(stderr, "usage: %s [-d tty][-c cmd][-l file][-f file][-r file][-t min]\n", basename(s));
fprintf(stderr, "\t-d tty\t\tpathname of UPS device\n");
fprintf(stderr, "\t-c cmd\t\tpathname of shutdown command\n");
! fprintf(stderr, "\t-l file\t\tpathname of UPS log file\n");
! fprintf(stderr, "\t-f file\t\tpathname of UPS fail message file\n");
! fprintf(stderr, "\t-r file\t\tpathname of UPS restore message file\n");
fprintf(stderr, "\t-t min\t\tdelay time in minutes\n");
}
*** main.c.orig Mon Apr 15 23:25:28 1991
--- main.c Mon Apr 15 23:26:03 1991
***************
*** 14,19 ****
--- 14,21 ----
char *ups_port = UPS_PORT;
char *ups_shut = UPS_SHUT;
char *ups_log = UPS_LOG;
+ char *ups_fail = UPS_FAIL;
+ char *ups_rest = UPS_REST;
int ups_time = UPS_TIME;
/* global descriptors */
*** version.h.orig Mon Apr 15 23:25:28 1991
--- version.h Mon Apr 15 23:26:03 1991
***************
*** 11,14 ****
#define RELEASE_DATE "03/30/91"
#define RELEASE 1
#define REVISION 0
! #define PATCHLEVEL 2
--- 11,14 ----
#define RELEASE_DATE "03/30/91"
#define RELEASE 1
#define REVISION 0
! #define PATCHLEVEL 3