4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
29 #pragma ident "%Z%%M% %I% %E% SMI"
37 #include <sys/types.h>
70 static int invoke_rm(char *);
72 # define START 0x1 /* -s seen */
73 # define KILL 0x2 /* -k seen */
74 # define ENABLE 0x4 /* -e seen */
75 # define DISABLE 0x8 /* -d seen */
76 # define PLIST 0x10 /* -l seen */
77 # define LIST 0x20 /* -L seen */
78 # define DBREAD 0x40 /* -x seen */
79 # define CONFIG 0x80 /* -G seen */
80 # define PCONFIG 0x100 /* -g seen */
81 # define ADD 0x200 /* -a or other required options seen */
82 # define REMOVE 0x400 /* -r seen */
85 * common error messages
88 # define NOTPRIV "User not privileged for operation"
89 # define SACERR "Can not contact SAC"
90 # define BADINP "Embedded newlines not allowed"
93 int Saferrno
; /* internal `errno' for exit */
97 * main - scan args for sacadm and call appropriate handling code
101 main(int argc
, char *argv
[])
103 int c
; /* option letter */
104 uid_t uid
; /* invoker's real uid */
105 int ret
; /* return code from check_version */
106 int flag
= 0; /* flag to record requested operations */
107 int errflg
= 0; /* error indicator */
108 int version
= -1; /* argument to -v */
109 int count
= 0; /* argument to -n */
110 int badcnt
= 0; /* count of bad args to -f */
111 int sawaflag
= 0; /* true if actually saw -a */
112 int conflag
= 0; /* true if output should be in condensed form */
113 long flags
= 0; /* arguments to -f */
114 FILE *fp
; /* scratch file pointer */
115 char *pmtag
= NULL
; /* argument to -p */
116 char *type
= NULL
; /* argument to -t */
117 char *script
= NULL
; /* argument to -z */
118 char *command
= NULL
; /* argument to -c */
119 char *comment
= " "; /* argument to -y */
120 char badargs
[BADFARGSIZE
]; /* place to hold bad args to -f */
121 char buf
[SIZE
]; /* scratch buffer */
122 register char *p
; /* scratch pointer */
126 while ((c
= getopt(argc
, argv
, "ac:def:GgkLln:p:rst:v:xy:z:")) != -1) {
134 if (strchr(optarg
, '\n')) {
135 Saferrno
= E_BADARGS
;
139 if (*command
!= '/') {
140 Saferrno
= E_BADARGS
;
141 error("command must be a full pathname");
161 if (badcnt
< (BADFARGSIZE
-1))
162 badargs
[badcnt
++] = *(optarg
- 1);
166 /* null terminate just in case anything is there */
167 badargs
[badcnt
] = '\0';
186 count
= atoi(optarg
);
188 Saferrno
= E_BADARGS
;
189 error("restart count can not be negative");
194 if (strchr(optarg
, '\n')) {
195 Saferrno
= E_BADARGS
;
198 if (strlen(pmtag
) > PMTAGSIZE
) {
199 pmtag
[PMTAGSIZE
] = '\0';
200 (void) fprintf(stderr
, "tag too long, truncated to <%s>\n", pmtag
);
202 for (p
= pmtag
; *p
; p
++) {
204 Saferrno
= E_BADARGS
;
205 error("port monitor tag must be alphanumeric");
217 if (strchr(optarg
, '\n')) {
218 Saferrno
= E_BADARGS
;
221 if (strlen(type
) > PMTYPESIZE
) {
222 type
[PMTYPESIZE
] = '\0';
223 (void) fprintf(stderr
, "type too long, truncated to <%s>\n", type
);
225 for (p
= type
; *p
; p
++) {
227 Saferrno
= E_BADARGS
;
228 error("port monitor type must be alphanumeric");
234 version
= atoi(optarg
);
236 Saferrno
= E_BADARGS
;
237 error("version number can not be negative");
245 if (strchr(optarg
, '\n')) {
246 Saferrno
= E_BADARGS
;
252 if (strchr(optarg
, '\n')) {
253 Saferrno
= E_BADARGS
;
262 if (errflg
|| (optind
< argc
))
266 /* bad flags were given to -f */
267 Saferrno
= E_BADARGS
;
269 "Invalid request, %s are not valid arguments for \"-f\"",
274 if ((ret
= check_version(VERSION
, SACTAB
)) == 1) {
276 error("_sactab version number is incorrect");
279 (void) sprintf(buf
, "could not open %s", SACTAB
);
284 (void) sprintf(buf
, "%s file is corrupt", SACTAB
);
295 if (!sawaflag
|| !pmtag
|| !type
|| !command
|| (version
< 0))
297 add_pm(pmtag
, type
, command
, version
, flags
, count
, script
, comment
);
304 if (!pmtag
|| type
|| script
)
313 if (!pmtag
|| type
|| script
)
322 if (!pmtag
|| type
|| script
)
331 if (!pmtag
|| type
|| script
)
340 if (!pmtag
|| type
|| script
)
348 if ((pmtag
&& type
) || script
)
350 list_pms(pmtag
, type
, conflag
);
368 (void) do_config(script
, "_sysconfig");
377 fp
= fopen(SACTAB
, "r");
380 error("Could not open _sactab");
382 if (!find_pm(fp
, pmtag
)) {
383 Saferrno
= E_NOEXIST
;
384 (void) sprintf(buf
, "Invalid request, %s does not exist", pmtag
);
388 (void) sprintf(buf
, "%s/_config", pmtag
);
389 (void) do_config(script
, buf
);
392 /* we only get here if more than one flag bit was set */
403 * usage - print out a usage message
405 * args: cmdname - the name command was invoked with
412 (void) fprintf(stderr
, "Usage:\t%s -a -p pmtag -t type -c cmd -v ver [ -f dx ] [ -n count ]\n", cmdname
);
413 (void) fprintf(stderr
, "\t\t[ -y comment ] [ -z script]\n");
414 (void) fprintf(stderr
, "\t%s -r -p pmtag\n", cmdname
);
415 (void) fprintf(stderr
, "\t%s -s -p pmtag\n", cmdname
);
416 (void) fprintf(stderr
, "\t%s -k -p pmtag\n", cmdname
);
417 (void) fprintf(stderr
, "\t%s -e -p pmtag\n", cmdname
);
418 (void) fprintf(stderr
, "\t%s -d -p pmtag\n", cmdname
);
419 (void) fprintf(stderr
, "\t%s -l [ -p pmtag | -t type ]\n", cmdname
);
420 (void) fprintf(stderr
, "\t%s -L [ -p pmtag | -t type ]\n", cmdname
);
421 (void) fprintf(stderr
, "\t%s -g -p pmtag [ -z script ]\n", cmdname
);
422 (void) fprintf(stderr
, "\t%s -G [ -z script ]\n", cmdname
);
423 (void) fprintf(stderr
, "\t%s -x [ -p pmtag ]\n", cmdname
);
424 Saferrno
= E_BADARGS
;
430 * add_pm - add a port monitor entry
432 * args: tag - port monitor's tag
433 * type - port monitor's type
434 * command - command string to invoke port monitor
435 * version - version number of port monitor's pmtab
436 * flags - port monitor flags
437 * count - restart count
438 * script - port monitor's configuration script
439 * comment - comment describing port monitor
443 add_pm(tag
, type
, command
, version
, flags
, count
, script
, comment
)
453 FILE *fp
; /* file pointer for _sactab */
454 int fd
; /* scratch file descriptor */
455 struct stat statbuf
; /* file status info */
456 char buf
[SIZE
]; /* scratch buffer */
457 char fname
[SIZE
]; /* scratch buffer for building names */
458 register int i
; /* scratch variable */
459 int retval
= 0; /* return value from invoke_rm() function */
461 fp
= fopen(SACTAB
, "r");
464 error("Could not open _sactab");
466 if (find_pm(fp
, tag
)) {
468 (void) sprintf(buf
, "Invalid request, %s already exists", tag
);
474 * create the directories for it if needed and put in initial files
475 * (/etc/saf and /var/saf)
478 for (i
= 0; i
< 2; i
++) {
479 /* i == 0 do /etc/saf i == 1 do /var/saf */
480 (void) sprintf(fname
, "%s/%s", (i
== 0 ) ? HOME
: ALTHOME
, tag
);
481 if (access(fname
, 0) == 0) {
482 /* something is there, find out what it is */
483 if (stat(fname
, &statbuf
) < 0) {
485 (void) sprintf(buf
, "could not stat <%s>", fname
);
488 if ((statbuf
.st_mode
& S_IFMT
) != S_IFDIR
) {
490 (void) sprintf(buf
, "<%s> exists and is not a directory", fname
);
493 /* note: this removes the directory too */
494 if ((retval
= invoke_rm(fname
)) != 0) {
496 if (snprintf(buf
, sizeof (buf
),
497 "could not remove files under <%s>",
498 fname
) >= sizeof (buf
)) {
499 snprintf(buf
, sizeof (buf
),
507 * create the directory
510 if (mkdir(fname
, 0755) < 0) {
512 (void) sprintf(buf
, "could not create directory <%s>", fname
);
519 * put in the config script, if specified
523 (void) sprintf(fname
, "%s/_config", tag
);
524 if (do_config(script
, fname
)) {
526 /* do_config put out any messages */
532 * create the communications pipe, but first make sure that the
533 * permissions we specify are what we get
537 (void) sprintf(fname
, "%s/%s/_pmpipe", HOME
, tag
);
538 if (mknod(fname
, S_IFIFO
| 0600, 0) < 0) {
541 error("could not create communications pipe");
545 * create the _pid file
548 (void) sprintf(fname
, "%s/%s/_pid", HOME
, tag
);
549 if ((fd
= creat(fname
, 0644)) < 0) {
552 error("could not create _pid file");
557 * create the _pmtab file
560 (void) sprintf(fname
, "%s/%s/_pmtab", HOME
, tag
);
561 if ((fd
= creat(fname
, 0644)) < 0) {
564 error("could not create _pmtab file");
566 (void) sprintf(buf
, "%s%d\n", VSTR
, version
);
567 if (write(fd
, buf
, (unsigned) strlen(buf
)) != strlen(buf
)) {
569 (void) unlink(fname
);
572 error("error initializing _pmtab");
577 * isolate the command name, but remember it since strtok() trashes it
580 if (strlcpy(buf
, command
, sizeof (buf
)) >= sizeof (buf
)) {
583 error("command string too long");
586 (void) strtok(command
, " \t");
589 * check out the command - let addition succeed if it doesn't exist (assume
590 * it will be added later); fail anything else
593 if (access(command
, 0) == 0) {
594 if (stat(command
, &statbuf
) < 0) {
596 (void) fprintf(stderr
, "Could not stat <%s>\n", command
);
600 if (!(statbuf
.st_mode
& 0111)) {
601 Saferrno
= E_BADARGS
;
602 (void) fprintf(stderr
, "%s not executable\n", command
);
606 if ((statbuf
.st_mode
& S_IFMT
) != S_IFREG
) {
607 Saferrno
= E_BADARGS
;
608 (void) fprintf(stderr
, "%s not a regular file\n", command
);
614 (void) fprintf(stderr
, "warning - %s does not exist\n", command
);
621 fp
= fopen(SACTAB
, "a");
625 error("Could not open _sactab");
627 (void) fprintf(fp
, "%s:%s:%s:%d:%s\t#%s\n", tag
, type
,
628 (flags
? pflags(flags
, FALSE
) : ""), count
, buf
,
629 (comment
? comment
: ""));
634 * tell the SAC to read _sactab if its there (i.e. single user)
644 * cleandirs - remove anything that might have been created (i.e. failed
645 * addition. Saferrno is set elsewhere; this is strictly an attempt
646 * to clean up what mess we've left, so don't check to see if the
649 * args: tag - tag of port monitor whose trees should be removed
656 char buf
[SIZE
]; /* scratch buffer */
658 /* note: this removes the directory too, first zap /etc/saf/<tag> */
659 if (snprintf(buf
, sizeof (buf
), "%s/%s", HOME
, tag
) >= sizeof (buf
))
660 (void) fprintf(stderr
, "tag too long\n");
662 (void) invoke_rm(buf
);
664 /* now remove /var/saf/<tag> */
665 if (snprintf(buf
, sizeof (buf
), "%s/%s", ALTHOME
, tag
) >= sizeof (buf
))
666 (void) fprintf(stderr
, "tag too long\n");
673 * rem_pm - remove a port monitor
675 * args: tag - tag of port monitor to be removed
682 FILE *fp
; /* file pointer for _sactab */
683 FILE *tfp
; /* file pointer for temp file */
684 int line
; /* line number entry is on */
685 char *tname
; /* temp file name */
686 char buf
[SIZE
]; /* scratch buffer */
688 fp
= fopen(SACTAB
, "r");
691 error("Could not open _sactab");
693 if ((line
= find_pm(fp
, tag
)) == 0) {
694 Saferrno
= E_NOEXIST
;
695 (void) sprintf(buf
, "Invalid request, %s does not exist", tag
);
698 tname
= make_tempname("_sactab");
699 tfp
= open_temp(tname
);
701 if (copy_file(fp
, tfp
, 1, line
- 1)) {
702 (void) unlink(tname
);
704 error("error accessing temp file");
707 if (copy_file(fp
, tfp
, line
+ 1, -1)) {
708 (void) unlink(tname
);
710 error("error accessing temp file");
713 if (fclose(tfp
) == EOF
) {
714 (void) unlink(tname
);
716 error("error closing tempfile");
718 /* note - replace only returns if successful */
719 replace("_sactab", tname
);
722 * tell the SAC to read _sactab if its there (i.e. single user)
732 * start_pm - start a particular port monitor
734 * args: tag - tag of port monitor to be started
741 struct admcmd cmd
; /* command structure */
742 register struct admcmd
*ap
= &cmd
; /* and a pointer to it */
744 ap
->ac_mtype
= AC_START
;
745 (void) strcpy(ap
->ac_tag
, tag
);
746 ap
->ac_pid
= getpid();
747 sendcmd(ap
, NULL
, tag
);
753 * kill_pm - stop a particular port monitor
755 * args: tag - tag of port monitor to be stopped
762 struct admcmd cmd
; /* command structure */
763 register struct admcmd
*ap
= &cmd
; /* and a pointer to it */
765 ap
->ac_mtype
= AC_KILL
;
766 (void) strcpy(ap
->ac_tag
, tag
);
767 ap
->ac_pid
= getpid();
768 sendcmd(ap
, NULL
, tag
);
774 * enable_pm - enable a particular port monitor
776 * args: tag - tag of port monitor to be enabled
783 struct admcmd cmd
; /* command structure */
784 register struct admcmd
*ap
= &cmd
; /* and a pointer to it */
786 ap
->ac_mtype
= AC_ENABLE
;
787 (void) strcpy(ap
->ac_tag
, tag
);
788 ap
->ac_pid
= getpid();
789 sendcmd(ap
, NULL
, tag
);
795 * disable_pm - disable a particular port monitor
797 * args: tag - tag of port monitor to be disabled
804 struct admcmd cmd
; /* command structure */
805 register struct admcmd
*ap
= &cmd
; /* and a pointer to it */
807 ap
->ac_mtype
= AC_DISABLE
;
808 (void) strcpy(ap
->ac_tag
, tag
);
809 ap
->ac_pid
= getpid();
810 sendcmd(ap
, NULL
, tag
);
816 * read_db - tell SAC or a port monitor to read its administrative file.
818 * args: tag - tag of port monitor that should read its administrative
819 * file. If NULL, it means SAC should.
826 struct admcmd cmd
; /* command structure */
827 register struct admcmd
*ap
= &cmd
; /* and a pointer to it */
829 ap
->ac_mtype
= (tag
) ? AC_PMREAD
: AC_SACREAD
;
831 (void) strcpy(ap
->ac_tag
, tag
);
832 ap
->ac_pid
= getpid();
833 sendcmd(ap
, NULL
, tag
);
839 * list_pms - request information about port monitors from SAC and output
842 * args: pmtag - tag of port monitor to be listed (may be null)
843 * pmtype - type of port monitors to be listed (may be null)
844 * oflag - true if output should be easily parseable
848 list_pms(pmtag
, pmtype
, oflag
)
853 struct admcmd acmd
; /* command structure */
854 register struct admcmd
*ap
= &acmd
; /* and a pointer to it */
855 int nprint
= 0; /* count # of PMs printed */
856 char *p
; /* scratch pointer */
857 char *tag
; /* returned tag */
858 char *type
; /* returned type */
859 char *flags
; /* returned flags */
860 char *rsmax
; /* returned restart count */
861 char *state
; /* returned state */
862 char *cmd
; /* returned command string */
863 char *comment
; /* returned comment string */
866 * if sac isn't there (single user), provide info direct from _sactab
867 * note: when this routine returns, the process exits, so there is no
868 * need to free up any memory
873 ap
->ac_mtype
= AC_STATUS
;
874 ap
->ac_tag
[0] = '\0';
875 ap
->ac_pid
= getpid();
876 sendcmd(ap
, &p
, NULL
);
883 * SAC sends back info in condensed form, we have to separate it out
884 * fields come in ':' separated, records are separated by newlines
888 tag
= getfield(&p
, ':'); /* PM tag */
889 type
= getfield(&p
, ':'); /* PM type */
890 flags
= getfield(&p
, ':'); /* flags */
891 rsmax
= getfield(&p
, ':'); /* restart count */
892 state
= pstate((unchar
) atoi(getfield(&p
, ':'))); /* state in nice output format */
893 cmd
= getfield(&p
, ':'); /* command */
894 comment
= getfield(&p
, '\n'); /* comment */
898 * print out if no selectors specified, else check to see if
902 if ((!pmtag
&& !pmtype
) || (pmtag
&& !strcmp(pmtag
, tag
)) || (pmtype
&& !strcmp(pmtype
, type
))) {
904 (void) printf("%s:%s:%s:%s:%s:%s#%s\n", tag
, type
, pflags(atol(flags
), FALSE
),
905 rsmax
, state
, cmd
, comment
);
909 (void) printf("PMTAG PMTYPE FLGS RCNT STATUS COMMAND\n");
911 (void) printf("%-14s %-14s %-4s %-4s %-10s %s #%s\n", tag
, type
, pflags(atol(flags
), TRUE
),
912 rsmax
, state
, cmd
, comment
);
918 * if we didn't find any valid ones, indicate an error (note: 1 and
919 * only 1 of the if statements should be true)
923 (void) fprintf(stderr
, "Invalid request, %s does not exist\n", pmtype
);
925 (void) fprintf(stderr
, "Invalid request, %s does not exist\n", pmtag
);
926 else if (!pmtag
&& !pmtype
)
927 (void) fprintf(stderr
, "No port monitors defined\n");
928 Saferrno
= E_NOEXIST
;
935 * getfield - retrieve and return a field from the sac "status" string (input
936 * argument is modified to point to next field as a side-effect)
938 * args: p - address of remaining portion of string
939 * sepchar - field terminator character
947 char *savep
; /* for saving argument */
950 *p
= strchr(*p
, sepchar
);
953 (void) fprintf(stderr
, "Improper message from SAC\n");
963 * single_print - print out _sactab if sac not at home (should only happen
964 * in single user mode
966 * args: p - address of pointer where formatted data should be
967 * placed (space allocated here)
974 FILE *fp
; /* file pointer for _sactab */
975 struct stat statbuf
; /* file status info */
976 register char *tp1
; /* scratch pointer */
977 register char *tp2
; /* scratch pointer */
978 struct sactab stab
; /* place to hold parsed info */
979 register struct sactab
*sp
= &stab
; /* and a pointer to it */
980 char buf
[SIZE
]; /* scratch buffer */
982 fp
= fopen(SACTAB
, "r");
985 error("Could not open _sactab");
987 if (fstat(fileno(fp
), &statbuf
) < 0) {
989 error("could not stat _sactab");
993 * allocate space to build return string, twice file size should be more
994 * than enough (and make sure it's zero'ed out)
997 tp1
= calloc(2 * statbuf
.st_size
, sizeof(char));
1000 error("could not allocate storage");
1004 * read the file and build the string
1007 while (fgets(buf
, SIZE
, fp
)) {
1012 (void) sprintf(buf
, "%s:%s:%d:%d:%d:%s:%s\n", sp
->sc_tag
, sp
->sc_type
,
1013 sp
->sc_flags
, sp
->sc_rsmax
, SSTATE
, sp
->sc_cmd
, sp
->sc_comment
);
1014 (void) strcat(tp1
, buf
);
1016 free(sp
->sc_comment
);
1019 Saferrno
= E_SYSERR
;
1020 error("error reading _sactab");
1025 * point at the just-built string
1034 * openpipe - open up command pipe to SAC
1040 int fd
; /* file descriptor associated with command pipe */
1042 fd
= open(CMDPIPE
, O_RDWR
);
1044 Saferrno
= E_SYSERR
;
1049 * lock pipe to insure serial access, lock will disappear if process dies
1052 if (lockf(fd
, F_LOCK
, 0) < 0) {
1053 Saferrno
= E_SYSERR
;
1054 error("unable to lock command pipe");
1061 * sendcmd - send a command to the SAC
1063 * args: ap - pointer to command to send
1064 * info - pointer to return information from the SAC
1065 * tag - tag of port monitor to which the command applies (may
1070 sendcmd(ap
, info
, tag
)
1075 int fd
; /* file descriptor of command pipe */
1078 if (write(fd
, ap
, sizeof(struct admcmd
)) < 0) {
1079 Saferrno
= E_SYSERR
;
1082 checkresp(fd
, info
, tag
);
1085 * unlock the command pipe - not really necessary since we're about to close
1088 (void) lockf(fd
, F_ULOCK
, 0);
1095 * checkresp - check the SAC's response to our command
1097 * args: fd - file descriptor of command pipe
1098 * info - pointer to return and info send along by SAC
1099 * tag - tag of port monitor that the command had been
1100 * for, only used for error reporting
1104 checkresp(fd
, info
, tag
)
1109 struct admack ack
; /* acknowledgment struct */
1110 register struct admack
*ak
= &ack
; /* and a pointer to it */
1111 pid_t pid
; /* my pid */
1112 struct sigaction sigact
; /* signal handler setup */
1115 * make sure this ack is meant for me, put an alarm around the read
1116 * so we don't hang out forever.
1120 sigact
.sa_flags
= 0;
1121 sigact
.sa_handler
= catch;
1122 (void) sigemptyset(&sigact
.sa_mask
);
1123 (void) sigaddset(&sigact
.sa_mask
, SIGALRM
);
1124 (void) sigaction(SIGALRM
, &sigact
, NULL
);
1127 if (read(fd
, ak
, sizeof(ack
)) != sizeof(ack
)) {
1128 Saferrno
= E_SACNOTRUN
;
1131 } while (pid
!= ak
->ak_pid
);
1135 * check out what happened
1138 switch (ak
->ak_resp
) {
1140 /* everything was A-OK */
1141 if (info
&& ak
->ak_size
) {
1142 /* there is return info and a place to put it */
1143 if ((*info
= malloc((unsigned) (ak
->ak_size
+ 1))) == NULL
) {
1144 Saferrno
= E_SYSERR
;
1145 error("could not allocate storage");
1147 if (read(fd
, *info
, (unsigned) ak
->ak_size
) != ak
->ak_size
) {
1148 Saferrno
= E_SYSERR
;
1151 /* make sure "string" is null-terminated */
1152 (*info
)[ak
->ak_size
] = '\0';
1155 /* something went wrong - see what */
1158 (void) fprintf(stderr
, "Port monitor, %s, is already running\n", tag
);
1161 Saferrno
= E_PMNOTRUN
;
1162 (void) fprintf(stderr
, "Port monitor, %s, is not running\n", tag
);
1165 Saferrno
= E_NOEXIST
;
1166 (void) fprintf(stderr
, "Invalid request, %s does not exist\n", tag
);
1169 Saferrno
= E_SAFERR
;
1170 (void) fprintf(stderr
, "Internal error - sent invalid command\n");
1173 Saferrno
= E_SAFERR
;
1174 (void) fprintf(stderr
, "Could not contact %s\n", tag
);
1177 Saferrno
= E_SAFERR
;
1178 (void) fprintf(stderr
, "Could not start %s - _pid file locked\n", tag
);
1181 Saferrno
= E_RECOVER
;
1182 (void) fprintf(stderr
, "Port monitor, %s, is in recovery\n", tag
);
1185 Saferrno
= E_SAFERR
;
1186 (void) fprintf(stderr
, "This request could not be completed - see sac log file for details\n");
1189 Saferrno
= E_SAFERR
;
1190 (void) fprintf(stderr
, "unknown response\n");
1197 * catch - catcher for SIGALRM, don't need to do anything
1207 * pflags - put port monitor flags into intelligible form for output
1209 * args: flags - binary representation of flags
1210 * dflag - true if a "-" should be returned if no flags
1214 pflags(flags
, dflag
)
1218 register int i
; /* scratch counter */
1219 static char buf
[SIZE
]; /* formatted flags */
1228 if (flags
& D_FLAG
) {
1232 if (flags
& X_FLAG
) {
1237 (void) fprintf(stderr
, "Bad information from SAC\n");
1246 * sac_home - returns true is sac has a lock on its logfile, false
1247 * otherwise (useful to avoid errors for administrative actions in
1254 int fd
; /* fd to sac logfile */
1256 fd
= open(LOGFILE
, O_RDONLY
);
1258 fprintf(stderr
, "warning - could not ascertain sac status\n");
1261 if (lockf(fd
, F_TEST
, 0) < 0) {
1262 /* everything is ok */
1274 * invoke_rm - deletes the argument directory and all its files/subdirectories
1277 invoke_rm(char *fname
)
1279 pid_t cpid
; /* process ID of the child process */
1280 int cstatus
; /* status of child process */
1288 if (posix_spawn(&cpid
, "/usr/bin/rm", NULL
, NULL
,
1289 (char *const *)argvec
, NULL
))
1291 if (waitpid(cpid
, &cstatus
, 0) == -1)
1294 return ((WIFEXITED(cstatus
) == 0) ? 99 : WEXITSTATUS(cstatus
));