diff options
author | Toomas Soome <tsoome@me.com> | 2022-03-27 19:29:25 +0300 |
---|---|---|
committer | Toomas Soome <tsoome@me.com> | 2022-05-17 00:38:35 +0300 |
commit | 3bb2c1567625e7b11f8c2a5335125224717af64a (patch) | |
tree | d0024ff545db4cf94b25ac072a00218156e8f894 | |
parent | 08ae0f1eeaa2952f05e6cc3e67da55db918f8e4a (diff) | |
download | illumos-joyent-3bb2c1567625e7b11f8c2a5335125224717af64a.tar.gz |
14602 ttymon: cleanup
Reviewed by: Jason King <jason.brian.king@gmail.com>
Reviewed by: Yuri Pankov <ypankov@tintri.com>
Approved by: Robert Mustacchi <rm@fingolfin.org>
26 files changed, 1635 insertions, 1863 deletions
diff --git a/usr/src/cmd/ttymon/Makefile b/usr/src/cmd/ttymon/Makefile index 3d28b74ce4..cb0cf26efb 100644 --- a/usr/src/cmd/ttymon/Makefile +++ b/usr/src/cmd/ttymon/Makefile @@ -43,7 +43,7 @@ TTYMONOBJ= ttymon.o tmglobal.o tmhandler.o tmpmtab.o tmttydefs.o \ TTYADMOBJ= ttyadm.o tmutil.o admutil.o STTYDEFSOBJ= sttydefs.o admutil.o tmttydefs.o tmparse.o sttytable.o \ - sttyparse.o + sttyparse.o tmglobal.o OBJS= $(STTYOBJ) $(XPG4STTYOBJ) $(TTYMONOBJ) $(TTYADMOBJ) $(STTYDEFSOBJ) STTYSRC= stty.c sttytable.c sttyparse.c @@ -73,14 +73,6 @@ $(XPG4STTYOBJ) := CPPFLAGS += -DEUC CFLAGS += $(CCVERBOSE) LDFLAGS += $(MAPFILE.NGB:%=-Wl,-M%) -CERRWARN += -_gcc=-Wno-parentheses -CERRWARN += -_gcc=-Wno-unused-variable -CERRWARN += $(CNOWARN_UNINIT) -CERRWARN += -_gcc=-Wno-extra - -# not linted -SMATCH=off - # # Message catalog # diff --git a/usr/src/cmd/ttymon/admutil.c b/usr/src/cmd/ttymon/admutil.c index 1a765aa4a5..6f6d789042 100644 --- a/usr/src/cmd/ttymon/admutil.c +++ b/usr/src/cmd/ttymon/admutil.c @@ -25,20 +25,17 @@ */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ +/* All Rights Reserved */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -# include <stdio.h> -# include <unistd.h> -# include <stdlib.h> -# include <string.h> -# include <sys/types.h> -# include <ctype.h> -# include <sys/stat.h> -# include "tmstruct.h" -# include "ttymon.h" +#include <stdio.h> +#include <unistd.h> +#include <stdlib.h> +#include <string.h> +#include <sys/types.h> +#include <ctype.h> +#include <sys/stat.h> +#include "tmstruct.h" +#include "ttymon.h" /* * find_label - return 1 if ttylabel already exists @@ -49,7 +46,7 @@ find_label(FILE *fp, char *ttylabel) { char *p; /* working pointer */ int line = 0; /* line number we found entry on */ - static char buf[BUFSIZ];/* scratch buffer */ + static char buf[BUFSIZ]; /* scratch buffer */ while (fgets(buf, BUFSIZ, fp)) { line++; @@ -57,13 +54,13 @@ find_label(FILE *fp, char *ttylabel) while (isspace(*p)) p++; if ((p = strtok(p, " :")) != NULL) { - if (!(strcmp(p, ttylabel))) - return(line); + if (strcmp(p, ttylabel) == 0) + return (line); } } if (!feof(fp)) { - (void)fprintf(stderr, "error reading \"%s\"\n", TTYDEFS); - return(0); + (void) fprintf(stderr, "error reading \"%s\"\n", TTYDEFS); + return (0); } - return(0); + return (0); } diff --git a/usr/src/cmd/ttymon/stty.c b/usr/src/cmd/ttymon/stty.c index 8ae976fdbd..66eb996b48 100644 --- a/usr/src/cmd/ttymon/stty.c +++ b/usr/src/cmd/ttymon/stty.c @@ -55,14 +55,7 @@ #include <getwidth.h> #endif /* EUC */ #include "stty.h" - -extern const char *not_supported[]; - -extern char *getenv(); -extern void exit(); -extern void perror(); -extern int get_ttymode(); -extern int set_ttymode(); +#include "tmextern.h" static char *STTY = "stty: "; static int pitt = 0; @@ -80,19 +73,19 @@ static ldterm_cs_data_user_t kcswp; /* Kernel side codeset width data */ static int invalid_ldterm_dat_file; #endif /* EUC */ -static void prmodes(); -static void pramodes(); +static void prmodes(void); +static void pramodes(void); static void pit(unsigned char what, char *itsname, char *sep); static void delay(int m, char *s); static void prspeed(char *c, int s); -static void prencode(); +static void prencode(void); int main(int argc, char *argv[]) { int i; int fd; - char *s_arg, *sttyparse(); /* s_arg: ptr to mode to be set */ + char *s_arg; /* s_arg: ptr to mode to be set */ #ifdef EUC char *lc; char tmps[PATH_MAX]; @@ -107,7 +100,7 @@ main(int argc, char *argv[]) #ifdef EUC lc = setlocale(LC_CTYPE, (const char *)NULL); if (lc) { - sprintf(tmps, _LDTERM_DAT_PATH, lc); + (void) sprintf(tmps, _LDTERM_DAT_PATH, lc); fd = open(tmps, O_RDONLY, 0); if (fd != -1) { @@ -159,8 +152,8 @@ main(int argc, char *argv[]) prmodes(); exit(0); } - if ((argc == 2) && (argv[1][0] == '-') && (argv[1][2] == '\0')) - switch (argv[1][1]) { + if ((argc == 2) && (argv[1][0] == '-') && (argv[1][2] == '\0')) { + switch (argv[1][1]) { case 'a': pramodes(); return (0); @@ -176,23 +169,28 @@ main(int argc, char *argv[]) (void) fprintf(stderr, gettext( " stty [modes]\n")); return (2); + } } - if ((argc == 3) && (argv[1][0] == '-') && (argv[1][2] == '\0') && - (argv[2][0] == '-') && (argv[2][1] == '-') && (argv[2][2] == '\0')) - switch (argv[1][1]) { - case 'a': - pramodes(); - return (0); - case 'g': - prencode(); - return (0); - default: - (void) fprintf(stderr, gettext( - "usage: stty [-a| -g]\n")); - (void) fprintf(stderr, gettext( - " stty [modes]\n")); - return (2); + if ((argc == 3) && (argv[1][0] == '-') && + (argv[1][2] == '\0') && + (argv[2][0] == '-') && + (argv[2][1] == '-') && + (argv[2][2] == '\0')) { + switch (argv[1][1]) { + case 'a': + pramodes(); + return (0); + case 'g': + prencode(); + return (0); + default: + (void) fprintf(stderr, gettext( + "usage: stty [-a| -g]\n")); + (void) fprintf(stderr, gettext( + " stty [modes]\n")); + return (2); + } } if ((argc >= 3) && (argv[1][0] == '-') && (argv[1][1] == '-') && (argv[1][2] == '\0')) { @@ -200,11 +198,13 @@ main(int argc, char *argv[]) --argc; ++argv; } - if (s_arg = sttyparse(argc, argv, term, &ocb, &cb, &termiox, &winsize #ifdef EUC - /* */, &wp, &kwp, &cswp, &kcswp + s_arg = sttyparse(argc, argv, term, &ocb, &cb, &termiox, &winsize, + &wp, &kwp, &cswp, &kcswp); +#else + s_arg = sttyparse(argc, argv, term, &ocb, &cb, &termiox, &winsize); #endif /* EUC */ - /* */)) { + if (s_arg != NULL) { char *s = s_arg; if (*s == '-') s++; for (i = 0; not_supported[i]; i++) { @@ -231,7 +231,7 @@ main(int argc, char *argv[]) return (0); } -void +static void prmodes(void) /* print modes, no options, argc is 1 */ { int m; @@ -399,11 +399,12 @@ prmodes(void) /* print modes, no options, argc is 1 */ (void) printf("onocr "); if (m&ONLRET) (void) printf("onlret "); - if (m&OFILL) + if (m&OFILL) { if (m&OFDEL) (void) printf("del-fill "); else (void) printf("nul-fill "); + } delay((m&CRDLY)/CR1, "cr"); delay((m&NLDLY)/NL1, "nl"); delay((m&TABDLY)/TAB1, "tab"); @@ -500,7 +501,7 @@ prmodes(void) /* print modes, no options, argc is 1 */ } } -void +static void pramodes(void) /* print all modes, -a option */ { int m; @@ -701,8 +702,8 @@ pit(unsigned char what, char *itsname, char *sep) pitt++; (void) printf("%s", itsname); - if ((term & TERMIOS) && what == _POSIX_VDISABLE || - !(term & TERMIOS) && what == 0200) { + if (((term & TERMIOS) && what == _POSIX_VDISABLE) || + (!(term & TERMIOS) && what == 0200)) { (void) printf(" = <undef>%s", sep); return; } @@ -747,7 +748,7 @@ prspeed(char *c, int scode) } /* print current settings for use with */ -void +static void prencode(void) /* another stty cmd, used for -g option */ { int i, last; @@ -784,7 +785,8 @@ prencode(void) /* another stty cmd, used for -g option */ if (*kcswp.locale_name == '\0') { (void) printf("00"); } else { - for (i = 0; kcswp.locale_name[i] && i < MAXNAMELEN; i++) + for (i = 0; i < MAXNAMELEN && + kcswp.locale_name[i] != '\0'; i++) (void) printf("%02x", kcswp.locale_name[i]); } for (i = 0; i < LDTERM_CS_MAX_CODESETS; i++) diff --git a/usr/src/cmd/ttymon/stty.h b/usr/src/cmd/ttymon/stty.h index 37bd09aff1..6d654ac191 100644 --- a/usr/src/cmd/ttymon/stty.h +++ b/usr/src/cmd/ttymon/stty.h @@ -33,8 +33,6 @@ #ifndef _STTY_H #define _STTY_H -#pragma ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.3 */ - #ifdef __cplusplus extern "C" { #endif diff --git a/usr/src/cmd/ttymon/sttydefs.c b/usr/src/cmd/ttymon/sttydefs.c index c6736c830c..dd19420c6a 100644 --- a/usr/src/cmd/ttymon/sttydefs.c +++ b/usr/src/cmd/ttymon/sttydefs.c @@ -24,11 +24,7 @@ * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - - -#pragma ident "%Z%%M% %I% %E% SMI" - +/* All Rights Reserved */ #include <stdio.h> #include <unistd.h> @@ -43,6 +39,7 @@ #include <stdarg.h> #include "tmstruct.h" +#include "tmextern.h" #include "ttymon.h" static int nflg = 0; /* -n seen */ @@ -50,36 +47,18 @@ static int iflg = 0; /* -i seen */ static int fflg = 0; /* -f seen */ static int lflg = 0; /* -l seen */ -struct Gdef Gdef[MAXDEFS]; /* array to hold entries in /etc/ttydefs */ -int Ndefs = 0; /* highest index to Gdef that was used */ -static struct Gdef DEFAULT = { /* default terminal settings */ - "default", - "9600", - "9600 sane", - 0, - /* - * next label is set to 4800 so we can start searching ttydefs. - * if 4800 is not in ttydefs, we will loop back to use DEFAULT - */ - "4800" -}; - - -static void usage(); -static void check_ref(); -static void add_entry(); -static void remove_entry(); -static int copy_file(); -static int verify(); -static FILE *open_temp(); -extern void read_ttydefs(); -extern int check_version(); -extern int find_label(); +static void usage(void); +static void check_ref(void); +static void add_entry(struct Gdef *) __NORETURN; +static void remove_entry(char *); +static int copy_file(FILE *, FILE *, int, int); +static int verify(char *, int); +static FILE *open_temp(char *); /* * sttydefs - add, remove or check entries in /etc/ttydefs * - * Usage: sttydefs -a ttylabel [-n nextlabel] [-i initail-flags] + * Usage: sttydefs -a ttylabel [-n nextlabel] [-i initail-flags] * [-f final-flags] [-b] * sttydefs -r ttylabel * sttydefs -l [ttylabel] @@ -94,22 +73,16 @@ main(int argc, char *argv[]) int aflg = 0; /* -a seen */ int bflg = 0; /* -b seen */ int ret; -#ifdef __STDC__ - const -#endif - char *argtmp; + const char *argtmp; char *nextlabel; struct Gdef ttydef, *ptr; - extern char *optarg; - extern int optind; - if (argc == 1) usage(); - /* Initialize ttydef structure */ - memset (&ttydef, 0, sizeof(ttydef)); - + /* Initialize ttydef structure */ + memset(&ttydef, 0, sizeof (ttydef)); + ptr = &ttydef; while ((c = getopt(argc, argv, "a:n:i:f:br:l")) != -1) { switch (c) { @@ -140,64 +113,67 @@ main(int argc, char *argv[]) break; case 'l': lflg = TRUE; - if (argc > 3) + if (argc > 3) usage(); if ((ret = check_version(TTYDEFS_VERS, TTYDEFS)) != 0) { if (ret != 2) { - (void)fprintf(stderr, "%s version number is incorrect or missing.\n",TTYDEFS); + (void) fprintf(stderr, + "%s version number is incorrect " + "or missing.\n", TTYDEFS); exit(1); } - (void)fprintf(stderr, "sttydefs: can't open %s.\n",TTYDEFS); + (void) fprintf(stderr, + "sttydefs: can't open %s.\n", TTYDEFS); exit(1); } if (argv[optind] == NULL) { - read_ttydefs(NULL,TRUE); + read_ttydefs(NULL, TRUE); printf("\n"); check_ref(); - } - else { + } else { if (argc == 3) { /* -l ttylabel */ - if (verify(argv[optind],0) != 0) { + if (verify(argv[optind], 0) != 0) { errflg++; break; } argtmp = argv[optind]; + } else { /* -lttylabel */ + argtmp = argv[optind] + 2; } - else { /* -lttylabel */ - argtmp = argv[optind]+2; - } - read_ttydefs(argtmp,TRUE); + read_ttydefs(argtmp, TRUE); if (Ndefs == 0) { - (void)fprintf(stderr, - "ttylabel <%s> not found.\n", argtmp); + (void) fprintf(stderr, + "ttylabel <%s> not found.\n", + argtmp); exit(1); } nextlabel = Gdef[--Ndefs].g_nextid; Ndefs = 0; - read_ttydefs(nextlabel,FALSE); + read_ttydefs(nextlabel, FALSE); if (Ndefs == 0) { - (void)printf("\nWarning -- nextlabel <%s> of <%s> does not reference any existing ttylabel.\n", - nextlabel, argtmp); + (void) printf("\nWarning -- nextlabel " + "<%s> of <%s> does not reference " + "any existing ttylabel.\n", + nextlabel, argtmp); } } exit(0); - break; /*NOTREACHED*/ case '?': errflg++; break; } /* end switch */ - if (errflg) + if (errflg) usage(); } /* end while */ - if (optind < argc) + if (optind < argc) usage(); if (aflg) { - add_entry(ptr); /* never return */ + add_entry(ptr); /* never return */ } - if ((iflg) || (fflg) || (bflg) || (nflg)) + if ((iflg) || (fflg) || (bflg) || (nflg)) usage(); - return (0); + return (0); } /* @@ -207,20 +183,19 @@ main(int argc, char *argv[]) * - return 0 if ok. Otherwise return -1 */ static int -verify(arg,maxarglen) -char *arg; -int maxarglen; +verify(char *arg, int maxarglen) { if (*arg == '-') { - (void)fprintf(stderr, "Invalid argument -- %s.\n", arg); - return(-1); + (void) fprintf(stderr, "Invalid argument -- %s.\n", arg); + return (-1); } if ((maxarglen) && ((int)strlen(arg) > maxarglen)) { arg[maxarglen] = '\0'; - (void)fprintf(stderr,"string too long, truncated to %s.\n",arg); - return(-1); + (void) fprintf(stderr, "string too long, truncated to %s.\n", + arg); + return (-1); } - return(0); + return (0); } /* @@ -228,11 +203,12 @@ int maxarglen; */ static void -usage() +usage(void) { - (void)fprintf(stderr, "Usage:\tsttydefs -a ttylabel [-n nextlabel] [-i initial-flags]\n\t\t [-f final-flags] [-b]\n"); - (void)fprintf(stderr, "\tsttydefs -r ttylabel\n"); - (void)fprintf(stderr, "\tsttydefs -l [ttylabel]\n"); + (void) fprintf(stderr, "Usage:\tsttydefs -a ttylabel [-n nextlabel] " + "[-i initial-flags]\n\t\t [-f final-flags] [-b]\n"); + (void) fprintf(stderr, "\tsttydefs -r ttylabel\n"); + (void) fprintf(stderr, "\tsttydefs -l [ttylabel]\n"); exit(2); } @@ -241,37 +217,36 @@ usage() */ static void -add_entry(ttydef) -struct Gdef *ttydef; +add_entry(struct Gdef *ttydef) { FILE *fp; int errflg = 0; char tbuf[BUFSIZ], *tp; int add_version = FALSE; - extern int check_flags(); if (getuid()) { - (void)fprintf(stderr, "User not privileged for operation.\n"); + (void) fprintf(stderr, "User not privileged for operation.\n"); exit(1); } tp = tbuf; *tp = '\0'; if ((fp = fopen(TTYDEFS, "r")) != NULL) { if (check_version(TTYDEFS_VERS, TTYDEFS) != 0) { - (void)fprintf(stderr, - "%s version number is incorrect or missing.\n",TTYDEFS); + (void) fprintf(stderr, + "%s version number is incorrect or missing.\n", + TTYDEFS); exit(1); } - if (find_label(fp,ttydef->g_id)) { - (void)fclose(fp); - (void)fprintf(stderr, - "Invalid request -- ttylabel <%s> already exists.\n", - ttydef->g_id); + if (find_label(fp, ttydef->g_id)) { + (void) fclose(fp); + (void) fprintf(stderr, + "Invalid request -- ttylabel <%s> already " + "exists.\n", + ttydef->g_id); exit(1); - } - (void)fclose(fp); - } - else { + } + (void) fclose(fp); + } else { add_version = TRUE; } if ((fp = fopen(TTYDEFS, "a+")) == NULL) { @@ -281,7 +256,7 @@ struct Gdef *ttydef; } if (add_version) { - (void)fprintf(fp,"# VERSION=%d\n", TTYDEFS_VERS); + (void) fprintf(fp, "# VERSION=%d\n", TTYDEFS_VERS); } @@ -289,12 +264,12 @@ struct Gdef *ttydef; if (!iflg) ttydef->g_iflags = DEFAULT.g_iflags; else - if (check_flags(ttydef->g_iflags) != 0 ) + if (check_flags(ttydef->g_iflags) != 0) errflg++; if (!fflg) ttydef->g_fflags = DEFAULT.g_fflags; else - if (check_flags(ttydef->g_fflags) != 0 ) + if (check_flags(ttydef->g_fflags) != 0) errflg++; if (errflg) exit(1); @@ -303,20 +278,18 @@ struct Gdef *ttydef; ttydef->g_nextid = ttydef->g_id; if (ttydef->g_autobaud & A_FLAG) { - (void)fprintf(fp,"%s:%s:%s:A:%s\n", ttydef->g_id, ttydef->g_iflags, - ttydef->g_fflags, ttydef->g_nextid); - } - else { - (void)fprintf(fp,"%s:%s:%s::%s\n", ttydef->g_id, ttydef->g_iflags, - ttydef->g_fflags, ttydef->g_nextid); + (void) fprintf(fp, "%s:%s:%s:A:%s\n", ttydef->g_id, + ttydef->g_iflags, ttydef->g_fflags, ttydef->g_nextid); + } else { + (void) fprintf(fp, "%s:%s:%s::%s\n", ttydef->g_id, + ttydef->g_iflags, ttydef->g_fflags, ttydef->g_nextid); } - (void)fclose(fp); + (void) fclose(fp); exit(0); } static void -remove_entry(ttylabel) -char *ttylabel; +remove_entry(char *ttylabel) { FILE *tfp; /* file pointer for temp file */ int line; /* line number entry is on */ @@ -324,7 +297,7 @@ char *ttylabel; char *tname = "/etc/.ttydefs"; if (getuid()) { - (void)fprintf(stderr, "User not privileged for operation.\n"); + (void) fprintf(stderr, "User not privileged for operation.\n"); exit(1); } fp = fopen(TTYDEFS, "r"); @@ -334,35 +307,36 @@ char *ttylabel; exit(1); } if (check_version(TTYDEFS_VERS, TTYDEFS) != 0) { - (void)fprintf(stderr, - "%s version number is incorrect or missing.\n",TTYDEFS); + (void) fprintf(stderr, + "%s version number is incorrect or missing.\n", TTYDEFS); exit(1); } if ((line = find_label(fp, ttylabel)) == 0) { - (void)fprintf(stderr, - "Invalid request, ttylabel <%s> does not exist.\n", ttylabel); + (void) fprintf(stderr, + "Invalid request, ttylabel <%s> does not exist.\n", + ttylabel); exit(1); } tfp = open_temp(tname); - if (line != 1) + if (line != 1) if (copy_file(fp, tfp, 1, line - 1)) { - (void)fprintf(stderr,"Error accessing temp file.\n"); + (void) fprintf(stderr, "Error accessing temp file.\n"); exit(1); } if (copy_file(fp, tfp, line + 1, -1)) { - (void)fprintf(stderr,"Error accessing temp file.\n"); + (void) fprintf(stderr, "Error accessing temp file.\n"); exit(1); } - (void)fclose(fp); + (void) fclose(fp); if (fclose(tfp) == EOF) { - (void)unlink(tname); - (void)fprintf(stderr,"Error closing temp file.\n"); + (void) unlink(tname); + (void) fprintf(stderr, "Error closing temp file.\n"); exit(1); } - (void)unlink(TTYDEFS); - if (rename(tname, TTYDEFS) != 0 ) { + (void) unlink(TTYDEFS); + if (rename(tname, TTYDEFS) != 0) { perror("Rename failed"); - (void)unlink(tname); + (void) unlink(tname); exit(1); } exit(0); @@ -375,8 +349,7 @@ char *ttylabel; */ static FILE * -open_temp(tname) -char *tname; +open_temp(char *tname) { FILE *fp; /* fp associated with tname */ struct sigaction sigact; /* for signal handling */ @@ -390,9 +363,9 @@ char *tname; (void) sigaction(SIGHUP, &sigact, NULL); (void) sigaction(SIGINT, &sigact, NULL); (void) sigaction(SIGQUIT, &sigact, NULL); - (void)umask(0333); + (void) umask(0333); if (access(tname, 0) != -1) { - (void)fprintf(stderr,"tempfile busy; try again later.\n"); + (void) fprintf(stderr, "tempfile busy; try again later.\n"); exit(1); } fp = fopen(tname, "w"); @@ -400,7 +373,7 @@ char *tname; perror("Cannot create tempfile"); exit(1); } - return(fp); + return (fp); } /* @@ -415,13 +388,9 @@ char *tname; static int -copy_file(fp, tfp, start, finish) -FILE *fp; -FILE *tfp; -register int start; -register int finish; +copy_file(FILE *fp, FILE *tfp, int start, int finish) { - register int i; /* loop variable */ + int i; /* loop variable */ char dummy[BUFSIZ]; /* scratch buffer */ /* @@ -437,7 +406,7 @@ register int finish; if (start != 1) { for (i = 1; i < start; i++) if (!fgets(dummy, BUFSIZ, fp)) - return(-1); + return (-1); } /* @@ -447,24 +416,23 @@ register int finish; if (finish != -1) { for (i = start; i <= finish; i++) { if (!fgets(dummy, BUFSIZ, fp)) - return(-1); + return (-1); if (fputs(dummy, tfp) == EOF) - return(-1); + return (-1); } - } - else { + } else { for (;;) { if (fgets(dummy, BUFSIZ, fp) == NULL) { if (feof(fp)) break; else - return(-1); + return (-1); } if (fputs(dummy, tfp) == EOF) - return(-1); + return (-1); } } - return(0); + return (0); } /* @@ -472,19 +440,19 @@ register int finish; * existing ttylabel */ static void -check_ref() +check_ref(void) { int i; struct Gdef *np; - extern struct Gdef *find_def(); + np = &Gdef[0]; for (i = 0; i < Ndefs; i++, np++) { if (find_def(np->g_nextid) == NULL) { - (void)printf("Warning -- nextlabel <%s> of <%s> does not reference any existing ttylabel.\n", - np->g_nextid, np->g_id); + (void) printf("Warning -- nextlabel <%s> of <%s> " + "does not reference any existing ttylabel.\n", + np->g_nextid, np->g_id); } } - return; } /* @@ -504,6 +472,6 @@ log(const char *msg, ...) va_start(ap, msg); (void) vfprintf(stderr, msg, ap); va_end(ap); - (void) fprintf(stderr,"\n"); + (void) fprintf(stderr, "\n"); } } diff --git a/usr/src/cmd/ttymon/tmautobaud.c b/usr/src/cmd/ttymon/tmautobaud.c index 9c16135f94..669f6ae703 100644 --- a/usr/src/cmd/ttymon/tmautobaud.c +++ b/usr/src/cmd/ttymon/tmautobaud.c @@ -25,10 +25,7 @@ */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - - -#pragma ident "%Z%%M% %I% %E% SMI" +/* All Rights Reserved */ #include <stdio.h> #include <errno.h> @@ -69,8 +66,6 @@ static struct autobaud { 0, 0 }; -extern struct strbuf *peek_ptr; - /* * auto_termio - set termio to allow autobaud * - the line is set to raw mode, with VMIN = 5, VTIME = 1 @@ -86,10 +81,10 @@ auto_termio(int fd) if (ioctl(fd, TCGETA, &termio) == -1) { log("auto_termio: ioctl TCGETA failed, fd = %d: %s", fd, strerror(errno)); - return(-1); + return (-1); } termio.c_iflag = 0; - termio.c_cflag &= ~(CBAUD|CSIZE|PARENB); + termio.c_cflag &= ~(CBAUD|CSIZE|PARENB); termio.c_cflag |= CREAD|HUPCL|(CS8&CSIZE)|(B2400&CBAUD); termio.c_lflag &= ~(ISIG|ICANON|ECHO|ECHOE|ECHOK); termio.c_oflag = 0; @@ -100,34 +95,34 @@ auto_termio(int fd) if (ioctl(fd, TCSETAF, &termio) == -1) { log("auto_termio: ioctl TCSETAF failed, fd = %d: %s", fd, strerror(errno)); - return(-1); + return (-1); } } else { termios.c_iflag &= 0xffff0000; - termios.c_cflag &= ~(CSIZE|PARENB); + termios.c_cflag &= ~(CSIZE|PARENB); termios.c_cflag |= CREAD|HUPCL|(CS8&CSIZE); termios.c_lflag &= ~(ISIG|ICANON|ECHO|ECHOE|ECHOK); termios.c_oflag &= 0xffff0000; termios.c_cc[VMIN] = 5; termios.c_cc[VTIME] = 1; - cfsetospeed(&termios, B2400); + (void) cfsetospeed(&termios, B2400); if (ioctl(fd, TCSETSF, &termios) == -1) { log("auto_termio: ioctl TCSETSF failed, fd = %d: %s", - fd, strerror(errno)); - return(-1); + fd, strerror(errno)); + return (-1); } } - return(0); + return (0); } /* * autobaud - determine the baudrate by reading data at 2400 baud rate - * - the program is anticipating <CR> + * - the program is anticipating <CR> * - the bit pattern is matched again an autobaud table * - if a match is found, the matched speed is returned - * - otherwise, NULL is returned + * - otherwise, NULL is returned */ char * @@ -135,49 +130,48 @@ autobaud(int fd, int timeout) { int i, k, count; static char buf[5]; - register char *cp = buf; + char *cp = buf; struct autobaud *tp; struct sigaction sigact; - extern void timedout(); - extern void flush_input(); #ifdef DEBUG debug("in autobaud"); #endif - auto_termio(fd); + (void) auto_termio(fd); sigact.sa_flags = 0; sigact.sa_handler = SIG_IGN; - (void)sigemptyset(&sigact.sa_mask); - (void)sigaction(SIGINT, &sigact, NULL); + (void) sigemptyset(&sigact.sa_mask); + (void) sigaction(SIGINT, &sigact, NULL); count = NTRY; while (count--) { if (timeout) { sigact.sa_flags = 0; sigact.sa_handler = timedout; - (void)sigemptyset(&sigact.sa_mask); - (void)sigaction(SIGALRM, &sigact, NULL); - (void)alarm((unsigned)timeout); + (void) sigemptyset(&sigact.sa_mask); + (void) sigaction(SIGALRM, &sigact, NULL); + (void) alarm((unsigned)timeout); } cp = &buf[1]; - if ( peek_ptr ) { - strncpy(cp, peek_ptr->buf, k=peek_ptr->len); + if (peek_ptr != NULL) { + k = peek_ptr->len; + (void) strncpy(cp, peek_ptr->buf, k); peek_ptr = NULL; - } else if ((k=read(fd, cp, 5)) < 0) { + } else if ((k = read(fd, cp, 5)) < 0) { fatal("autobaud: read failed: %s", strerror(errno)); } if (timeout) - (void)alarm((unsigned)0); + (void) alarm((unsigned)0); buf[0] = (char)k; for (tp = autob2400; tp->a_speed; tp++) { - for (i = 0;; i++) { + for (i = 0; ; i++) { if (buf[i] != tp->a_pattern[i]) break; if (i == buf[0]) { - return(tp->a_speed); + return (tp->a_speed); } } } flush_input(fd); } /* end while */ - return(NULL); /* autobaud failed */ + return (NULL); /* autobaud failed */ } diff --git a/usr/src/cmd/ttymon/tmchild.c b/usr/src/cmd/ttymon/tmchild.c index 8aa97ae170..a58099974b 100644 --- a/usr/src/cmd/ttymon/tmchild.c +++ b/usr/src/cmd/ttymon/tmchild.c @@ -24,7 +24,7 @@ */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ +/* All Rights Reserved */ #include <stdio.h> #include <stdlib.h> @@ -36,8 +36,8 @@ #include <signal.h> #include <poll.h> #include <unistd.h> -#include "sys/stropts.h" -#include <sys/resource.h> +#include "sys/stropts.h" +#include <sys/resource.h> #include "sac.h" #include "ttymon.h" #include "tmstruct.h" @@ -46,14 +46,11 @@ #include <sys/utsname.h> #endif -static void openline(); -static void invoke_service(); -static char *do_autobaud(); -static struct Gdef *next_speed(); -static int check_hup(); - -extern struct Gdef *get_speed(); -extern struct strbuf *peek_ptr, *do_peek(); +static void openline(struct pmtab *, struct Gdef *); +static void invoke_service(struct pmtab *); +static char *do_autobaud(struct pmtab *, struct Gdef *); +static struct Gdef *next_speed(struct Gdef *); +static int check_hup(int); /* * tmchild - process that handles peeking data, determine baud rate @@ -61,10 +58,9 @@ extern struct strbuf *peek_ptr, *do_peek(); * */ void -tmchild(pmtab) -struct pmtab *pmtab; +tmchild(struct pmtab *pmtab) { - register struct Gdef *speedef; + struct Gdef *speedef; char *auto_speed = ""; struct sigaction sigact; @@ -106,14 +102,16 @@ struct pmtab *pmtab; speedef = get_speed(pmtab->p_ttylabel); openline(pmtab, speedef); if (pmtab->p_ttyflags & (C_FLAG|B_FLAG)) { - if (pmtab->p_fd >= 0) { - if ((pmtab->p_modules != NULL)&&(*(pmtab->p_modules) != '\0')) { - if (push_linedisc(pmtab->p_fd, pmtab->p_modules, pmtab->p_device) == -1) { - (void) close(pmtab->p_fd); - return; - } + if (pmtab->p_fd >= 0) { + if ((pmtab->p_modules != NULL) && + (*(pmtab->p_modules) != '\0')) { + if (push_linedisc(pmtab->p_fd, + pmtab->p_modules, pmtab->p_device) == -1) { + (void) close(pmtab->p_fd); + return; + } + } } - } } if ((pmtab->p_ttyflags & C_FLAG) && (State != PM_DISABLED) && @@ -122,7 +120,8 @@ struct pmtab *pmtab; * if "c" flag is set, and the port is not disabled * invoke service immediately */ - if (set_termio(0, speedef->g_fflags, NULL,FALSE,CANON) == -1) { + if (set_termio(0, speedef->g_fflags, NULL, FALSE, + CANON) == -1) { log("set final termio failed"); exit(1); } @@ -146,9 +145,8 @@ struct pmtab *pmtab; (void) sigaction(SIGALRM, &sigact, NULL); (void) alarm((unsigned)pmtab->p_timeout); } - } - else if ((pmtab->p_ttyflags & (B_FLAG))) - write_prompt(pmtab->p_fd, pmtab, TRUE, TRUE); + } else if ((pmtab->p_ttyflags & (B_FLAG))) + write_prompt(pmtab->p_fd, pmtab, TRUE, TRUE); /* Loop until user is successful in invoking service. */ @@ -167,7 +165,8 @@ struct pmtab *pmtab; (void) sigemptyset(&sigact.sa_mask); (void) sigaction(SIGALRM, &sigact, NULL); } - if ((State == PM_DISABLED)||(pmtab->p_flags & X_FLAG)){ + if ((State == PM_DISABLED) || + (pmtab->p_flags & X_FLAG)) { write_prompt(1, pmtab, TRUE, FALSE); break; } @@ -190,8 +189,7 @@ struct pmtab *pmtab; exit(1); } auto_speed = do_autobaud(pmtab, speedef); - } - else { + } else { auto_speed = NULL; /* * this reset may fail if the speed is not @@ -229,9 +227,7 @@ struct pmtab *pmtab; } static void -openline(pmtab, speedef) -struct pmtab *pmtab; -struct Gdef *speedef; +openline(struct pmtab *pmtab, struct Gdef *speedef) { char buffer[5]; int rtn = 0; @@ -271,24 +267,25 @@ struct Gdef *speedef; * - if it is not, '\n' will not look like '\n' * and we will wait forever here */ - if (set_termio(0, speedef->g_fflags, NULL, TRUE, CANON) == -1) { + if (set_termio(0, speedef->g_fflags, NULL, TRUE, + CANON) == -1) { log("set final termio failed"); exit(1); } for (line_count = 0; line_count < pmtab->p_count; ) { - if (read(0, buffer, 1) < 0 - || *buffer == '\0' - || *buffer == '\004') { + if (read(0, buffer, 1) < 0 || + *buffer == '\0' || + *buffer == '\004') { (void) close(0); exit(0); } if (*buffer == '\n') line_count++; } - } - else { /* wait for 1 char */ + } else { /* wait for 1 char */ if (peek_ptr == NULL) { - if (set_termio(0, NULL, NULL,TRUE,RAW) == -1) { + if (set_termio(0, NULL, NULL, TRUE, + RAW) == -1) { log("set termio RAW failed"); exit(1); } @@ -307,7 +304,8 @@ struct Gdef *speedef; } peek_ptr = NULL; if (!(pmtab->p_ttyflags & A_FLAG)) { /* autobaud not enabled */ - if (set_termio(0, speedef->g_fflags, NULL, TRUE, CANON) == -1) { + if (set_termio(0, speedef->g_fflags, NULL, TRUE, + CANON) == -1) { log("set final termio failed"); exit(1); } @@ -327,7 +325,6 @@ struct Gdef *speedef; (void) fchown(0, ROOTUID, Tty_gid); (void) fchmod(0, 0620); } - return; } /* @@ -336,10 +333,7 @@ struct Gdef *speedef; * - if clear is set, write a new line */ void -write_prompt(fd, pmtab, flush, clear) -int fd; -struct pmtab *pmtab; -int flush, clear; +write_prompt(int fd, struct pmtab *pmtab, int flush, int clear) { #ifdef DEBUG @@ -355,17 +349,18 @@ int flush, clear; #endif /* Print prompt/disable message. */ if ((State == PM_DISABLED) || (pmtab->p_flags & X_FLAG)) - (void)write(fd, pmtab->p_dmsg, (unsigned)strlen(pmtab->p_dmsg)); + (void) write(fd, pmtab->p_dmsg, + (unsigned)strlen(pmtab->p_dmsg)); else (void) write(fd, pmtab->p_prompt, - (unsigned)strlen(pmtab->p_prompt)); + (unsigned)strlen(pmtab->p_prompt)); } /* * timedout - input period timed out */ void -timedout() +timedout(void) { exit(1); } @@ -376,8 +371,7 @@ timedout() * - print out /etc/issue file if it exists */ void -sys_name(fd) -int fd; +sys_name(int fd) { char *ptr, buffer[BUFSIZ]; FILE *fp; @@ -410,12 +404,11 @@ int fd; * - otherwise, it will set new termio and return */ static char * -do_autobaud(pmtab, speedef) -struct pmtab *pmtab; -struct Gdef *speedef; +do_autobaud(struct pmtab *pmtab, struct Gdef *speedef) { int done = FALSE; char *auto_speed; + #ifdef DEBUG debug("in do_autobaud"); #endif @@ -424,18 +417,16 @@ struct Gdef *speedef; speedef = next_speed(speedef); if (speedef->g_autobaud & A_FLAG) { continue; - } - else { + } else { if (set_termio(0, speedef->g_iflags, NULL, - TRUE, CANON) != 0) { + TRUE, CANON) != 0) { exit(1); } done = TRUE; } - } - else { + } else { if (set_termio(0, speedef->g_fflags, auto_speed, - TRUE, CANON) != 0) { + TRUE, CANON) != 0) { exit(1); } done = TRUE; @@ -448,14 +439,13 @@ struct Gdef *speedef; } /* - * next_speed(speedef) + * next_speed(speedef) * - find the next entry according to nextlabel. If "nextlabel" * is not valid, go back to the old ttylabel. */ static struct Gdef * -next_speed(speedef) -struct Gdef *speedef; +next_speed(struct Gdef *speedef) { struct Gdef *sp; @@ -479,8 +469,7 @@ struct Gdef *speedef; * inform_parent() - inform ttymon that tmchild is going to exec service */ static void -inform_parent(fd) -int fd; +inform_parent(int fd) { pid_t pid; @@ -488,8 +477,8 @@ int fd; (void) write(fd, &pid, sizeof (pid)); } -static char pbuf[BUFSIZ]; /* static buf for TTYPROMPT */ -static char hbuf[BUFSIZ]; /* static buf for HOME */ +static char pbuf[BUFSIZ]; /* static buf for TTYPROMPT */ +static char hbuf[BUFSIZ]; /* static buf for HOME */ static char tbuf[BUFSIZ]; /* static buf for TERM */ /* @@ -497,16 +486,14 @@ static char tbuf[BUFSIZ]; /* static buf for TERM */ */ static void -invoke_service(pmtab) -struct pmtab *pmtab; +invoke_service(struct pmtab *pmtab) { char *argvp[MAXARGS]; /* service cmd args */ int cnt = 0; /* arg counter */ - int i, fd; + int i; struct sigaction sigact; - extern struct rlimit Rlimit; -#ifdef DEBUG +#ifdef DEBUG debug("in invoke_service"); #endif @@ -566,8 +553,7 @@ struct pmtab *pmtab; if ((i = doconfig(0, pmtab->p_tag, 0)) != 0) { if (i < 0) { log("doconfig failed, system error"); - } - else { + } else { log("doconfig failed on line %d of script %s", i, pmtab->p_tag); } @@ -644,8 +630,7 @@ struct pmtab *pmtab; */ static int -check_hup(fd) -int fd; +check_hup(int fd) { int ret; struct pollfd pfd[1]; @@ -659,8 +644,7 @@ int fd; continue; log("check_hup: poll failed: %s", strerror(errno)); exit(1); - } - else if (ret > 0) { + } else if (ret > 0) { if (pfd[0].revents & POLLHUP) { return (1); } @@ -676,7 +660,7 @@ int fd; * Something must happen to ttymon. */ void -sigpoll() +sigpoll(int s __unused) { #ifdef DEBUG debug("tmchild got SIGPOLL, exiting"); diff --git a/usr/src/cmd/ttymon/tmexpress.c b/usr/src/cmd/ttymon/tmexpress.c index c01a67142e..345fdd1529 100644 --- a/usr/src/cmd/ttymon/tmexpress.c +++ b/usr/src/cmd/ttymon/tmexpress.c @@ -24,7 +24,7 @@ * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ +/* All Rights Reserved */ #include <stdio.h> #include <stdlib.h> @@ -43,6 +43,7 @@ #include <sys/stat.h> #include <sys/types.h> #include <sys/console.h> +#include <libdevinfo.h> #include "ttymon.h" #include "tmextern.h" #include "tmstruct.h" @@ -50,18 +51,11 @@ static char devbuf[BUFSIZ]; static char *devname; -static int parse_args(); -static void ttymon_options(); -static void getty_options(); -static void usage(); -static char *find_ttyname(); - -extern void tmchild(); -extern int vml(); - -void revokedevaccess(char *, uid_t, gid_t, mode_t); -/* cannot include libdevinfo.h */ -extern int di_devperm_logout(const char *); +static int parse_args(int, char **, struct pmtab *); +static void ttymon_options(int, char **, struct pmtab *); +static void getty_options(int, char **, struct pmtab *); +static void usage(void); +static char *find_ttyname(int); /* * ttymon_express - This is call when ttymon is invoked with args @@ -76,13 +70,7 @@ ttymon_express(int argc, char **argv) { struct pmtab *pmtab; struct sigaction sigact; - extern int Retry; - extern void open_device(); - extern void read_ttydefs(); - extern int checkut_line(); #ifdef DEBUG - extern FILE *Debugfp; - extern void opendebug(); #endif #ifdef DEBUG @@ -94,7 +82,7 @@ ttymon_express(int argc, char **argv) (void) sigemptyset(&sigact.sa_mask); (void) sigaction(SIGINT, &sigact, NULL); - if ((pmtab = ALLOC_PMTAB) == PNULL) { + if ((pmtab = ALLOC_PMTAB) == NULL) { log("ttymon_express: ALLOC_PMTAB failed"); exit(1); } @@ -108,7 +96,7 @@ ttymon_express(int argc, char **argv) if ((pmtab->p_device != NULL) && (*(pmtab->p_device) != '\0')) while (checkut_line(pmtab->p_device)) - sleep(15); + (void) sleep(15); if ((pmtab->p_device == NULL) || (*(pmtab->p_device) == '\0')) { devname = find_ttyname(0); @@ -141,7 +129,7 @@ ttymon_express(int argc, char **argv) } if (initial_termio(0, pmtab) == -1) exit(1); - di_devperm_logout((const char *)pmtab->p_device); + (void) di_devperm_logout((const char *)pmtab->p_device); } else { (void) setsid(); (void) close(0); @@ -161,8 +149,6 @@ static int parse_args(int argc, char **argv, struct pmtab *pmtab) { static char p_server[] = "/usr/bin/login"; - extern char *lastname(); - extern void getty_account(); static char termbuf[MAX_TERM_TYPE_LEN]; static struct cons_getterm cnterm = {sizeof (termbuf), termbuf}; @@ -225,24 +211,18 @@ parse_args(int argc, char **argv, struct pmtab *pmtab) /* - * ttymon_options - scan and check args for ttymon express + * ttymon_options - scan and check args for ttymon express */ static void ttymon_options(int argc, char **argv, struct pmtab *pmtab) { - int c; /* option letter */ - char *timeout; - int gflag = 0; /* -g seen */ + int c; /* option letter */ + char *timeout; + int gflag = 0; /* -g seen */ int size = 0; char tbuf[BUFSIZ]; - extern char *optarg; - extern int optind; - extern void copystr(); - extern char *strsave(); - extern char *getword(); - while ((c = getopt(argc, argv, "T:gd:ht:p:m:l:")) != -1) { switch (c) { case 'g': @@ -303,8 +283,8 @@ ttymon_options(int argc, char **argv, struct pmtab *pmtab) * usage - print out a usage message */ -static void -usage() +static void +usage(void) { char *umsg = "Usage: ttymon\n ttymon -g [-h] [-d device] " "[-l ttylabel] [-t timeout] [-p prompt] [-m modules]\n"; @@ -322,10 +302,7 @@ usage() * - modification is made to stuff args in pmtab */ static void -getty_options(argc, argv, pmtab) -int argc; -char **argv; -struct pmtab *pmtab; +getty_options(int argc, char **argv, struct pmtab *pmtab) { char *ptr; @@ -336,32 +313,36 @@ struct pmtab *pmtab; pmtab->p_ttyflags &= ~(H_FLAG); while (--argc && **++argv == '-') { - for (ptr = *argv + 1; *ptr; ptr++) - switch (*ptr) { - case 'h': - break; - case 't': - if (isdigit(*++ptr)) { - (void) sscanf(ptr, "%d", &(pmtab->p_timeout)); - while (isdigit(*++ptr)); - ptr--; - } else if (--argc) { - if (isdigit(*(ptr = *++argv))) + for (ptr = *argv + 1; *ptr; ptr++) { + switch (*ptr) { + case 'h': + break; + case 't': + if (isdigit(*++ptr)) { (void) sscanf(ptr, "%d", &(pmtab->p_timeout)); - else { - log("getty: timeout argument <%s> " - "invalid", *argv); - exit(1); + while (isdigit(*++ptr)) + ; + ptr--; + } else if (--argc) { + if (isdigit(*(ptr = *++argv))) + (void) sscanf(ptr, "%d", + &(pmtab->p_timeout)); + else { + log("getty: timeout argument " + "<%s> invalid", *argv); + exit(1); + } } + break; + + case 'c': + log("Use \"sttydefs -l\" to check " + "/etc/ttydefs."); + exit(0); + default: + break; } - break; - - case 'c': - log("Use \"sttydefs -l\" to check /etc/ttydefs."); - exit(0); - default: - break; } } @@ -385,7 +366,7 @@ struct pmtab *pmtab; } /* - * find_ttyname(fd) - find the name of device associated with fd. + * find_ttyname(fd) - find the name of device associated with fd. * - it first tries utmpx to see if an entry exists * - with my pid and ut_line is defined. If ut_line * - is defined, it will see if the major and minor @@ -393,8 +374,7 @@ struct pmtab *pmtab; * - If utmpx search fails, ttyname(fd) will be called. */ static char * -find_ttyname(fd) -int fd; +find_ttyname(int fd) { pid_t ownpid; struct utmpx *u; @@ -409,7 +389,7 @@ int fd; if (*(u->ut_line) != '/') { (void) strcpy(buf, "/dev/"); (void) strncat(buf, u->ut_line, - sizeof (u->ut_line)); + sizeof (u->ut_line)); } else { (void) strncat(buf, u->ut_line, sizeof (u->ut_line)); @@ -422,10 +402,10 @@ int fd; } endutxent(); if ((u != NULL) && - (fstat(fd, &statf) == 0) && - (stat(buf, &statu) == 0) && - (statf.st_dev == statu.st_dev) && - (statf.st_rdev == statu.st_rdev)) { + (fstat(fd, &statf) == 0) && + (stat(buf, &statu) == 0) && + (statf.st_dev == statu.st_dev) && + (statf.st_rdev == statu.st_rdev)) { #ifdef DEBUG debug("ttymon_express: find device name from utmpx."); #endif diff --git a/usr/src/cmd/ttymon/tmextern.h b/usr/src/cmd/ttymon/tmextern.h index c285b434eb..b08c59f04d 100644 --- a/usr/src/cmd/ttymon/tmextern.h +++ b/usr/src/cmd/ttymon/tmextern.h @@ -24,107 +24,157 @@ */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ +/* All Rights Reserved */ #ifndef _TMEXTERN_H #define _TMEXTERN_H +#include <stdio.h> +#include <unistd.h> +#include <sys/poll.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <termio.h> +#include <sys/stermio.h> +#include <sys/termiox.h> #include "tmstruct.h" #ifdef __cplusplus extern "C" { #endif - extern void setup_PCpipe(); +/* admutil.c */ + extern int find_label(FILE *, char *); + +/* sttytable.c */ + extern const char *not_supported[]; + +/* sttyparse.c */ +#ifdef EUC + extern char *sttyparse(int, char *[], int, struct termio *, + struct termios *, struct termiox *, struct winsize *, + eucwidth_t *, struct eucioc *, ldterm_cs_data_user_t *, + ldterm_cs_data_user_t *); + extern int get_ttymode(int, struct termio *, struct termios *, + struct stio *, struct termiox *, struct winsize *, + struct eucioc *, ldterm_cs_data_user_t *); + extern int set_ttymode(int, int, struct termio *, struct termios *, + struct stio *, struct termiox *, struct winsize *, + struct winsize *, struct eucioc *, ldterm_cs_data_user_t *, int); +#else + extern char *sttyparse(int, char *[], int, struct termio *, + struct termios *, struct termiox *, struct winsize *); + extern int get_ttymode(int, struct termio *, struct termios *, + struct stio *, struct termiox *, struct winsize *); + extern int set_ttymode(int, int, struct termio *, struct termios *, + struct stio *, struct termiox *, struct winsize *, + struct winsize *); +#endif /* tmautobaud.c */ - extern int auto_termio(); - extern char *autobaud(); - -/* tmchild.c */ - extern void write_prompt(); - extern void timedout(); - -/* tmexpress.c */ - extern void ttymon_express(); - -/* tmhandler.c */ - extern void do_poll(); - extern void sigterm(); - extern void sigchild(); - extern void state_change(); - extern void re_read(); - extern void got_carrier(); - -/* tmlock.c */ - extern int tm_checklock(); - extern int tm_lock(); - -/* tmlog.c */ - extern void log(const char *, ...); - extern void fatal(const char *, ...); + extern int auto_termio(int); + extern char *autobaud(int, int); + +/* tmchild.c */ + extern void write_prompt(int, struct pmtab *, int, int); + extern void timedout(void); + extern void tmchild(struct pmtab *); + extern void sigpoll(int); + +/* tmexpress.c */ + extern void ttymon_express(int, char **); + extern void revokedevaccess(char *, uid_t, gid_t, mode_t); + +/* tmhandler.c */ + extern void do_poll(struct pollfd *, int); + extern void sigalarm(int); + extern void sigterm(int); + extern void sigchild(int); + extern void sigpoll_catch(int); + extern void state_change(void); + extern void re_read(void); + extern void got_carrier(struct pmtab *); + +/* tmlock.c */ + extern int tm_checklock(int); + extern int tm_lock(int); + extern int check_session(int); + extern char *lastname(char *); + +/* tmlog.c */ + extern void log(const char *, ...); + extern void fatal(const char *, ...); extern void openttymonlog(void); -/* tmparse.c */ - extern char *getword(); - extern char quoted(); - -/* tmpeek.c */ - extern int poll_data(); - -/* tmpmtab.c */ - extern void read_pmtab(); - extern void purge(); - -/* tmsac.c */ - extern void openpid(); - extern void openpipes(); - extern void get_environ(); - extern void sacpoll(); - -/* tmsig.c */ - extern void catch_signals(); - extern void child_sigcatch(); - -/* tmterm.c */ - extern int push_linedisc(); - extern int set_termio(); - extern int initial_termio(); - extern int hang_up_line(); - extern void flush_input(); - -/* tmttydefs.c */ - extern void read_ttydefs(); - extern struct Gdef *find_def(); - extern char *getword(); - extern void mkargv(); - -/* tmutmp.c */ - extern int account(); - extern void cleanut(); - -/* tmutil.c */ - extern int check_device(); - extern int check_cmd(); +/* tmparse.c */ + extern char *getword(char *, int *, int); + extern char quoted(char *, int *); + +/* tmpeek.c */ + extern int poll_data(void); + extern void sigint(int); + +/* tmpmtab.c */ + extern void read_pmtab(void); + extern void purge(void); + +/* tmsac.c */ + extern void openpid(void); + extern void openpipes(void); + extern void get_environ(void); + extern void sacpoll(void); + +/* tmsig.c */ + extern void catch_signals(void); + extern void child_sigcatch(void); + +/* tmterm.c */ + extern int push_linedisc(int, char *, char *); + extern int set_termio(int, char *, char *, int, long); + extern int initial_termio(int, struct pmtab *); + extern int hang_up_line(int); + extern void flush_input(int); + +/* tmttydefs.c */ + extern void read_ttydefs(const char *, int); + extern struct Gdef *find_def(char *); + extern void mkargv(char *, char **, int *, int); + extern int check_flags(char *); + extern char *strsave(char *); + +/* tmutmp.c */ + extern int account(char *); + extern void cleanut(pid_t, int); + extern int checkut_line(char *line); + extern void getty_account(char *); + +/* tmutil.c */ + extern int check_device(char *); + extern int check_cmd(char *); extern void cons_printf(const char *, ...); + extern void copystr(char *, char *); + extern int strcheck(char *, int); + extern int vml(char *); /* misc sys call or lib function call */ - extern int check_version(); - extern int fchown(); - extern int fchmod(); + extern int check_version(int, char *); #ifdef SYS_NAME - extern void sys_name(); + extern void sys_name(int); #endif -/* tmglobal.c */ +/* tmglobal.c */ + extern struct Gdef DEFAULT; + extern int Retry; + extern struct rlimit Rlimit; extern struct pmtab *PMtab; + extern struct pollfd *Pollp; extern int Nentries; extern int Npollfd; - extern struct Gdef Gdef[]; + extern struct Gdef Gdef[]; extern int Ndefs; extern long Mtime; @@ -138,8 +188,8 @@ extern "C" { extern char *Tag; extern int Reread_flag; - extern int Maxfiles; - extern int Maxfds; + extern int Maxfiles; + extern int Maxfds; extern char **environ; extern char *optarg; @@ -171,6 +221,16 @@ extern "C" { extern int Logmaxsz; extern int Splflag; +/* ttymon.c */ + extern struct Gdef *get_speed(char *); + extern void open_device(struct pmtab *); + extern void set_softcar(struct pmtab *); + extern void setup_PCpipe(void); + +/* ulockf.c */ + extern int fd_cklock(int); + extern int fd_mklock(int); + #ifdef __cplusplus } #endif diff --git a/usr/src/cmd/ttymon/tmhandler.c b/usr/src/cmd/ttymon/tmhandler.c index bd7932f7b6..43ed4d2237 100644 --- a/usr/src/cmd/ttymon/tmhandler.c +++ b/usr/src/cmd/ttymon/tmhandler.c @@ -24,7 +24,7 @@ * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ +/* All Rights Reserved */ /* * Copyright (c) 2018, Joyent, Inc. */ @@ -47,21 +47,17 @@ #include "tmextern.h" #include "sac.h" -extern int Retry; -static struct pmtab *find_pid(); -static void kill_children(); +static struct pmtab *find_pid(pid_t); +static void kill_subprocesses(void); -static struct pmtab *find_fd(); -static void pcsync_close(); -extern void sigalarm(); -extern void tmchild(); +static struct pmtab *find_fd(int); +static void pcsync_close(int *, int *, int, int); /* * fork_tmchild - fork child on the device */ static void -fork_tmchild(pmptr) -struct pmtab *pmptr; +fork_tmchild(struct pmtab *pmptr) { pid_t pid; sigset_t cset; @@ -75,7 +71,7 @@ struct pmtab *pmptr; pmptr->p_inservice = FALSE; /* - * initialize pipe. + * initialize pipe. * Child has pcpipe[0] pipe fd for reading and writing * and closes pcpipe[1]. Parent has pcpipe[1] pipe fd for * reading and writing and closes pcpipe[0]. @@ -88,48 +84,46 @@ struct pmtab *pmptr; if (((p0 = pipe(pcpipe0)) == -1) || (pipe(pcpipe1) == -1)) { if (p0 == 0) { - close(pcpipe0[0]); - close(pcpipe0[1]); + (void) close(pcpipe0[0]); + (void) close(pcpipe0[1]); } log("pipe() failed: %s", strerror(errno)); pmptr->p_status = VALID; - pmptr->p_pid = 0; + pmptr->p_childpid = 0; Retry = TRUE; } /* protect following region from SIGCLD */ - (void)sigprocmask(SIG_SETMASK, NULL, &cset); + (void) sigprocmask(SIG_SETMASK, NULL, &cset); tset = cset; - (void)sigaddset(&tset, SIGCLD); - (void)sigprocmask(SIG_SETMASK, &tset, NULL); - if( (pid=fork()) == 0 ) { + (void) sigaddset(&tset, SIGCLD); + (void) sigprocmask(SIG_SETMASK, &tset, NULL); + if ((pid = fork()) == 0) { /* * Close all file descriptors except pmptr->p_fd * Wait for the parent process to close its fd */ pcsync_close(pcpipe0, pcpipe1, pid, pmptr->p_fd); - /* The CHILD */ - tmchild(pmptr); + /* The CHILD */ + tmchild(pmptr); /* tmchild should never return */ fatal("tmchild for <%s> returns unexpected", pmptr->p_device); - } - else if (pid < 0) { + } else if (pid < 0) { log("fork failed: %s", strerror(errno)); pmptr->p_status = VALID; - pmptr->p_pid = 0; + pmptr->p_childpid = 0; Retry = TRUE; - } - else { + } else { /* * The PARENT - store pid of child and close the device */ - pmptr->p_pid = pid; + pmptr->p_childpid = pid; } if (pmptr->p_fd > 0) { - (void)close(pmptr->p_fd); - pmptr->p_fd = 0; + (void) close(pmptr->p_fd); + pmptr->p_fd = 0; } - (void)sigprocmask(SIG_SETMASK, &cset, NULL); + (void) sigprocmask(SIG_SETMASK, &cset, NULL); /* * Wait for child to close file descriptors */ @@ -141,37 +135,32 @@ struct pmtab *pmptr; * - depends on the flags, different action is taken * - R_FLAG - wait for data * - C_FLAG - if port is not disabled, fork tmchild - * - A_FLAG - wait for data + * - A_FLAG - wait for data * - otherwise - write out prompt, then wait for data */ void -got_carrier(pmptr) -struct pmtab *pmptr; +got_carrier(struct pmtab *pmptr) { flush_input(pmptr->p_fd); if (pmptr->p_ttyflags & R_FLAG) { #ifdef DEBUG - debug("R_FLAG"); + debug("R_FLAG"); #endif return; - } - else if ((pmptr->p_ttyflags & (C_FLAG|B_FLAG)) && - (State != PM_DISABLED) && - (!(pmptr->p_flags & X_FLAG))) { + } else if ((pmptr->p_ttyflags & (C_FLAG|B_FLAG)) && + (State != PM_DISABLED) && + (!(pmptr->p_flags & X_FLAG))) { fork_tmchild(pmptr); - } - else if (pmptr->p_ttyflags & A_FLAG) { + } else if (pmptr->p_ttyflags & A_FLAG) { #ifdef DEBUG debug("A_FLAG"); #endif return; - } - else if (pmptr->p_timeout) { + } else if (pmptr->p_timeout) { fork_tmchild(pmptr); - } - else if ( ! (pmptr->p_ttyflags & X_FLAG) ) { - write_prompt(pmptr->p_fd,pmptr,TRUE,TRUE); + } else if (!(pmptr->p_ttyflags & X_FLAG)) { + write_prompt(pmptr->p_fd, pmptr, TRUE, TRUE); } } @@ -179,38 +168,36 @@ struct pmtab *pmptr; * got_data - data is detected on the stream, fork tmchild */ static void -got_data(pmptr) -struct pmtab *pmptr; +got_data(struct pmtab *pmptr) { struct sigaction sigact; if (tm_checklock(pmptr->p_fd) != 0) { pmptr->p_status = LOCKED; - (void)close(pmptr->p_fd); + (void) close(pmptr->p_fd); pmptr->p_fd = 0; Nlocked++; if (Nlocked == 1) { sigact.sa_flags = 0; sigact.sa_handler = sigalarm; - (void)sigemptyset(&sigact.sa_mask); - (void)sigaction(SIGALRM, &sigact, NULL); - (void)alarm(ALARMTIME); + (void) sigemptyset(&sigact.sa_mask); + (void) sigaction(SIGALRM, &sigact, NULL); + (void) alarm(ALARMTIME); } - } - else + } else { fork_tmchild(pmptr); + } } /* * got_hup - stream hangup is detected, close the device */ static void -got_hup(pmptr) -struct pmtab *pmptr; +got_hup(struct pmtab *pmptr) { #ifdef DEBUG debug("in got hup"); #endif - (void)close(pmptr->p_fd); + (void) close(pmptr->p_fd); pmptr->p_fd = 0; pmptr->p_inservice = 0; Retry = TRUE; @@ -223,11 +210,9 @@ struct pmtab *pmptr; * - if POLLIN received, fork tmchild. */ void -do_poll(fdp,nfds) -struct pollfd *fdp; -int nfds; +do_poll(struct pollfd *fdp, int nfds) { - int i,n; + int i, n; struct pmtab *pmptr; n = poll(fdp, (unsigned long)nfds, -1); /* blocked poll */ @@ -239,18 +224,16 @@ int nfds; return; fatal("do_poll: poll failed: %s", strerror(errno)); } - for (i = 0; (i < nfds)&&(n); i++,fdp++) { + for (i = 0; (i < nfds) && (n != 0); i++, fdp++) { if (fdp->revents != 0) { n--; if ((pmptr = find_fd(fdp->fd)) == NULL) { log("do_poll: cannot find fd %d in pmtab", fdp->fd); continue; - } - else if (fdp->revents & POLLHUP) { + } else if (fdp->revents & POLLHUP) { got_hup(pmptr); - } - else if (fdp->revents & POLLIN) { + } else if (fdp->revents & POLLIN) { #ifdef DEBUG debug("got POLLIN"); #endif @@ -269,15 +252,12 @@ int nfds; * - clean utmp if U_FLAG is set */ void -/*ARGSUSED*/ -sigchild(n) -int n; /* this is declared to make cc happy, but it is not used */ +sigchild(int n __unused) { struct pmtab *pmptr; - struct sigaction sigact; siginfo_t info; - int status; - pid_t pid; + int status; + pid_t pid; int rcode; #ifdef DEBUG @@ -322,7 +302,7 @@ int n; /* this is declared to make cc happy, but it is not used */ cleanut(pid, status); pmptr->p_status = VALID; pmptr->p_fd = 0; - pmptr->p_pid = 0; + pmptr->p_childpid = 0; pmptr->p_inservice = 0; Retry = TRUE; } @@ -333,7 +313,7 @@ int n; /* this is declared to make cc happy, but it is not used */ * sigterm - handler for SIGTERM */ void -sigterm() +sigterm(int _s __unused) { fatal("caught SIGTERM"); } @@ -343,7 +323,7 @@ sigterm() * its internal state between enabled and disabled */ void -state_change() +state_change(void) { struct pmtab *pmptr; @@ -351,12 +331,12 @@ state_change() debug("in state_change"); #endif - /* - * closing PCpipe will cause attached non-service children + /* + * closing PCpipe will cause attached non-service children * to get SIGPOLL and exit */ - (void)close(PCpipe[0]); - (void)close(PCpipe[1]); + (void) close(PCpipe[0]); + (void) close(PCpipe[1]); /* reopen PCpipe */ setup_PCpipe(); @@ -366,8 +346,8 @@ state_change() * with new internal state */ for (pmptr = PMtab; pmptr; pmptr = pmptr->p_next) { - if ((pmptr->p_fd > 0) && (pmptr->p_pid == 0)) { - (void)close(pmptr->p_fd); + if ((pmptr->p_fd > 0) && (pmptr->p_childpid == 0)) { + (void) close(pmptr->p_fd); pmptr->p_fd = 0; } } @@ -380,23 +360,22 @@ state_change() * - kill tmchild if entry changed */ void -re_read() +re_read(void) { - extern struct pollfd *Pollp; sigset_t cset; sigset_t tset; - (void)sigprocmask(SIG_SETMASK, NULL, &cset); + (void) sigprocmask(SIG_SETMASK, NULL, &cset); tset = cset; - (void)sigaddset(&tset, SIGCLD); - (void)sigprocmask(SIG_SETMASK, &tset, NULL); + (void) sigaddset(&tset, SIGCLD); + (void) sigprocmask(SIG_SETMASK, &tset, NULL); if (Nlocked > 0) { - alarm(0); + (void) alarm(0); Nlocked = 0; } read_pmtab(); - kill_children(); - (void)sigprocmask(SIG_SETMASK, &cset, NULL); + kill_subprocesses(); + (void) sigprocmask(SIG_SETMASK, &cset, NULL); purge(); if (Nentries > Npollfd) { @@ -404,13 +383,12 @@ re_read() debug("Nentries > Npollfd, reallocating pollfds"); #endif /* need to malloc more pollfd structure */ - free((char *)Pollp); + free(Pollp); Npollfd = Nentries + 10; if (Npollfd > Maxfds) Npollfd = Maxfds; - if ((Pollp = (struct pollfd *) - malloc((unsigned)(Npollfd * sizeof(struct pollfd)))) - == (struct pollfd *)NULL) + Pollp = malloc((unsigned)(Npollfd * sizeof (struct pollfd))); + if (Pollp == NULL) fatal("malloc for Pollp failed"); } Retry = TRUE; @@ -420,62 +398,59 @@ re_read() * find_pid(pid) - find the corresponding pmtab entry for the pid */ static struct pmtab * -find_pid(pid) -pid_t pid; +find_pid(pid_t pid) { struct pmtab *pmptr; for (pmptr = PMtab; pmptr; pmptr = pmptr->p_next) { - if (pmptr->p_pid == pid) { - return(pmptr); + if (pmptr->p_childpid == pid) { + return (pmptr); } } - return((struct pmtab *)NULL); + return (NULL); } /* * find_fd(fd) - find the corresponding pmtab entry for the fd */ static struct pmtab * -find_fd(fd) -int fd; +find_fd(int fd) { struct pmtab *pmptr; for (pmptr = PMtab; pmptr; pmptr = pmptr->p_next) { if (pmptr->p_fd == fd) { - return(pmptr); + return (pmptr); } } - return((struct pmtab *)NULL); + return (NULL); } /* - * kill_children() - if the pmtab entry has been changed, + * kill_subprocesses() - if the pmtab entry has been changed, * kill tmchild if it is not in service. * - close the device if there is no tmchild */ static void -kill_children() +kill_subprocesses(void) { struct pmtab *pmptr; + for (pmptr = PMtab; pmptr; pmptr = pmptr->p_next) { if (pmptr->p_status == VALID) continue; - if ((pmptr->p_fd > 0) && (pmptr->p_pid == 0)) { - (void)close(pmptr->p_fd); + if ((pmptr->p_fd > 0) && (pmptr->p_childpid == 0)) { + (void) close(pmptr->p_fd); pmptr->p_fd = 0; - } - else if ((pmptr->p_fd == 0) && (pmptr->p_pid > 0) - && (pmptr->p_inservice == FALSE)) { - (void)kill(pmptr->p_pid, SIGTERM); + } else if ((pmptr->p_fd == 0) && (pmptr->p_childpid > 0) && + (pmptr->p_inservice == FALSE)) { + (void) kill(pmptr->p_childpid, SIGTERM); } } } static void -mark_service(pid) -pid_t pid; +mark_service(pid_t pid) { struct pmtab *pmptr; #ifdef DEBUG @@ -486,30 +461,28 @@ pid_t pid; return; } pmptr->p_inservice = TRUE; - return; } /* * read_pid(fd) - read pid info from PCpipe */ static void -read_pid(fd) -int fd; +read_pid(int fd) { int ret; pid_t pid; for (;;) { - if ((ret = read(fd,&pid,sizeof(pid))) < 0) { + if ((ret = read(fd, &pid, sizeof (pid))) < 0) { if (errno == EINTR) continue; - if (errno == EAGAIN) + if (errno == EAGAIN) return; fatal("read PCpipe failed: %s", strerror(errno)); } if (ret == 0) return; - if (ret != sizeof(pid)) + if (ret != sizeof (pid)) fatal("read return size incorrect, ret = %d", ret); mark_service(pid); @@ -521,7 +494,7 @@ int fd; * - it will check both PCpipe and pmpipe */ void -sigpoll_catch() +sigpoll_catch(int s __unused) { int ret; struct pollfd pfd[2]; @@ -538,72 +511,68 @@ sigpoll_catch() fatal("sigpoll_catch: poll failed: %s", strerror(errno)); if (ret > 0) { - if (pfd[0].revents & POLLIN) + if (pfd[0].revents & POLLIN) read_pid(pfd[0].fd); if (pfd[1].revents & POLLIN) sacpoll(); } } -/*ARGSUSED*/ void -sigalarm(signo) -int signo; +sigalarm(int signo __unused) { struct pmtab *pmptr; struct sigaction sigact; int fd; - extern int check_session(); #ifdef DEBUG debug("in sigalarm, Nlocked = %d", Nlocked); #endif for (pmptr = PMtab; pmptr; pmptr = pmptr->p_next) { if ((pmptr->p_status == LOCKED) && (pmptr->p_fd == 0)) { - if ((fd=open(pmptr->p_device,O_RDWR|O_NONBLOCK)) == -1){ + fd = open(pmptr->p_device, O_RDWR | O_NONBLOCK); + if (fd == -1) { log("open (%s) failed: %s", pmptr->p_device, strerror(errno)); pmptr->p_status = VALID; Nlocked--; Retry = TRUE; - } - else { + } else { if (tm_checklock(fd) == 0) { Nlocked--; pmptr->p_fd = fd; Retry = TRUE; + } else { + (void) close(fd); } - else - (void)close(fd); } - } - else if ((pmptr->p_status == SESSION) && (pmptr->p_fd == 0)) { - if ((fd=open(pmptr->p_device,O_RDWR|O_NONBLOCK)) == -1){ + } else if ((pmptr->p_status == SESSION) && (pmptr->p_fd == 0)) { + fd = open(pmptr->p_device, O_RDWR | O_NONBLOCK); + if (fd == -1) { log("open (%s) failed: %s", pmptr->p_device, strerror(errno)); pmptr->p_status = VALID; Nlocked--; Retry = TRUE; - } - else { + } else { if (check_session(fd) == 0) { Nlocked--; pmptr->p_fd = fd; Retry = TRUE; + } else { + (void) close(fd); } - else - (void)close(fd); } - } - else if ((pmptr->p_status == UNACCESS) && (pmptr->p_fd == 0)) { - if ((fd=open(pmptr->p_device,O_RDWR|O_NONBLOCK)) == -1){ + } else if ((pmptr->p_status == UNACCESS) && + (pmptr->p_fd == 0)) { + fd = open(pmptr->p_device, O_RDWR | O_NONBLOCK); + if (fd == -1) { log("open (%s) failed: %s", pmptr->p_device, strerror(errno)); pmptr->p_status = VALID; Nlocked--; Retry = TRUE; - } - else { + } else { Nlocked--; pmptr->p_fd = fd; Retry = TRUE; @@ -613,15 +582,14 @@ int signo; if (Nlocked > 0) { sigact.sa_flags = 0; sigact.sa_handler = sigalarm; - (void)sigemptyset(&sigact.sa_mask); - (void)sigaction(SIGALRM, &sigact, NULL); - (void)alarm(ALARMTIME); - } - else { + (void) sigemptyset(&sigact.sa_mask); + (void) sigaction(SIGALRM, &sigact, NULL); + (void) alarm(ALARMTIME); + } else { sigact.sa_flags = 0; sigact.sa_handler = SIG_IGN; - (void)sigemptyset(&sigact.sa_mask); - (void)sigaction(SIGALRM, &sigact, NULL); + (void) sigemptyset(&sigact.sa_mask); + (void) sigaction(SIGALRM, &sigact, NULL); } } @@ -641,15 +609,19 @@ pcsync_close(int *p0, int *p1, int pid, int fd) struct pmtab *tp; for (tp = PMtab; tp; tp = tp->p_next) if ((tp->p_fd > 0) && (tp->p_fd != fd)) - close(tp->p_fd); - close(p0[1]); close(p1[0]); + (void) close(tp->p_fd); + (void) close(p0[1]); + (void) close(p1[0]); if (read(p0[0], &ch, 1) == 1) - write(p1[1], "a", 1); - close(p0[0]); close(p1[1]); + (void) write(p1[1], "a", 1); + (void) close(p0[0]); + (void) close(p1[1]); } else { /* Parent */ - close(p0[0]); close(p1[1]); + (void) close(p0[0]); + (void) close(p1[1]); if (write(p0[1], "a", 1) == 1) - read(p1[0], &ch, 1); - close(p0[1]); close(p1[0]); + (void) read(p1[0], &ch, 1); + (void) close(p0[1]); + (void) close(p1[0]); } } diff --git a/usr/src/cmd/ttymon/tmlock.c b/usr/src/cmd/ttymon/tmlock.c index a3aa3bbaf5..83d40ecaf9 100644 --- a/usr/src/cmd/ttymon/tmlock.c +++ b/usr/src/cmd/ttymon/tmlock.c @@ -25,15 +25,14 @@ */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - - -#pragma ident "%Z%%M% %I% %E% SMI" +/* All Rights Reserved */ #include <unistd.h> #include <string.h> #include <sys/termios.h> -/*--------------------------------------------------------- */ +#include "tmextern.h" + +/* -------------------------------------------------------- */ /* the follwing are here so we can use routines in ulockf.c */ int Debug = 0; char *Bnptr; @@ -42,17 +41,19 @@ char *Bnptr; /*ARGSUSED*/ void assert(char *s1, char *s2, int i1, char *s3, int i2) -{} +{ +} void -cleanup(){} +cleanup(void) +{ +} -/*ARGSUSED*/ void -logent(char *s1, char *s2) -{} /* so we can load ulockf() */ -/*---------------------------------------------------------- */ -extern int lockf(); +logent(char *s1 __unused, char *s2 __unused) +{ + /* so we can load ulockf() */ +} /* * lastname - If the path name starts with "/dev/", @@ -68,7 +69,7 @@ lastname(char *name) if (strncmp(sp, "/dev/", 5) == 0) sp += 5; else - while ((p = (char *)strchr(sp,'/')) != (char *)NULL) { + while ((p = (char *)strchr(sp, '/')) != NULL) { sp = ++p; } return (sp); @@ -80,17 +81,15 @@ lastname(char *name) int tm_lock(int fd) { - extern int fd_mklock(); return (fd_mklock(fd)); } /* - * tm_checklock - check if advisory lock is on + * tm_checklock - check if advisory lock is on */ int tm_checklock(int fd) { - extern int fd_cklock(); return (fd_cklock(fd)); } @@ -105,9 +104,9 @@ check_session(int fd) pid_t sid; if (ioctl(fd, TIOCGSID, &sid) == -1) - return(0); + return (0); else if (sid == 0) - return(0); + return (0); else - return(1); + return (1); } diff --git a/usr/src/cmd/ttymon/tmlog.c b/usr/src/cmd/ttymon/tmlog.c index 5144c5b7f9..bd2b89891c 100644 --- a/usr/src/cmd/ttymon/tmlog.c +++ b/usr/src/cmd/ttymon/tmlog.c @@ -25,10 +25,7 @@ */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - - -#pragma ident "%Z%%M% %I% %E% SMI" +/* All Rights Reserved */ /* * error/logging/cleanup functions for ttymon. @@ -51,10 +48,6 @@ #include "tmstruct.h" #include "tmextern.h" -# ifdef DEBUG -extern FILE *Debugfp; -# endif - const char *appname = "ttymon"; void @@ -62,15 +55,14 @@ openttymonlog(void) { int fd, ret; char logfile[MAXPATHLEN]; - extern char *Tag; /* the log file resides in /var/saf/pmtag/ */ (void) snprintf(logfile, sizeof (logfile), "%s%s/%s", LOGDIR, Tag, LOGFILE); Logfp = NULL; - (void)close(0); - if ((fd = open(logfile, O_WRONLY|O_CREAT|O_APPEND,0444)) != -1) + (void) close(0); + if ((fd = open(logfile, O_WRONLY | O_CREAT | O_APPEND, 0444)) != -1) if ((ret = fcntl(fd, F_DUPFD, 3)) == 3) { /* set close-on-exec flag */ if (fcntl(ret, F_SETFD, FD_CLOEXEC) == 0) { @@ -91,7 +83,7 @@ openttymonlog(void) } static void -roll_log() +roll_log(void) { char logf[MAXPATHLEN]; char ologf[MAXPATHLEN]; @@ -116,7 +108,7 @@ roll_log() if (!stat(tlogf, &buf) && rename(tlogf, ologf)) (void) fprintf(Logfp, "rename tmp to old file failed\n"); - } else if (nlogfp = fopen(logf, "w")) { + } else if ((nlogfp = fopen(logf, "w")) != NULL) { (void) fclose(Logfp); Logfp = nlogfp; /* reset close-on-exec */ @@ -215,11 +207,11 @@ fatal(const char *fmt, ...) exit(1); } -# ifdef DEBUG +#ifdef DEBUG /* * opendebug - open debugging file, sets global file pointer Debugfp - * arg: getty - if TRUE, ttymon is in getty_mode and use a different + * arg: getty - if TRUE, ttymon is in getty_mode and use a different * debug file */ @@ -228,23 +220,21 @@ opendebug(int getty_mode) { int fd, ret; char debugfile[BUFSIZ]; - extern char *Tag; if (!getty_mode) { - (void)strcpy(debugfile, LOGDIR); - (void)strcat(debugfile, Tag); - (void)strcat(debugfile, "/"); - (void)strcat(debugfile, DBGFILE); + (void) strcpy(debugfile, LOGDIR); + (void) strcat(debugfile, Tag); + (void) strcat(debugfile, "/"); + (void) strcat(debugfile, DBGFILE); if ((Debugfp = fopen(debugfile, "a+")) == NULL) fatal("open debug file failed"); - } - else { + } else { if ((fd = open(EX_DBG, O_WRONLY|O_APPEND|O_CREAT)) < 0) fatal("open %s failed: %s", EX_DBG, errno); - if (fd >= 3) + if (fd >= 3) { ret = fd; - else { + } else { if ((ret = fcntl(fd, F_DUPFD, 3)) < 0) fatal("F_DUPFD fcntl failed: %s", strerror(errno)); @@ -254,7 +244,7 @@ opendebug(int getty_mode) fatal("fdopen failed: %s", strerror(errno)); if (ret != fd) - (void)close(fd); + (void) close(fd); } /* set close-on-exec flag */ if (fcntl(fileno(Debugfp), F_SETFD, 1) == -1) diff --git a/usr/src/cmd/ttymon/tmparse.c b/usr/src/cmd/ttymon/tmparse.c index ccc2065832..8413ca81f0 100644 --- a/usr/src/cmd/ttymon/tmparse.c +++ b/usr/src/cmd/ttymon/tmparse.c @@ -20,27 +20,25 @@ * CDDL HEADER END */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ +/* All Rights Reserved */ +#include <stdio.h> +#include <ctype.h> -#ident "%Z%%M% %I% %E% SMI" /* SVr4.0 1.1 */ - -#include <stdio.h> -#include <ctype.h> +char quoted(char *, int *); /* * getword - extract one token from the string + * char *ptr; pointer to the string to be scanned + * int *size; *size = number of characters scanned + * int getall; if TRUE, get all char until ':' or '\0' * - token delimiter is white space if getall is FALSE * - token delimiter is ':' or '\0' if getall is TRUE */ char * -getword(ptr, size, getall) -register char *ptr; /* pointer to the string to be scanned */ -int *size; /* *size = number of characters scanned */ -int getall; /* if TRUE, get all char until ':' or '\0' */ +getword(char *ptr, int *size, int getall) { - register char *optr,c; - char quoted(); + char *optr, c; static char word[BUFSIZ]; int qsize; @@ -55,8 +53,8 @@ int getall; /* if TRUE, get all char until ':' or '\0' */ /* Put all characters from here to next white space or ':' or '\0' */ /* into the word, up to the size of the word. */ - for (optr= word,*optr='\0'; - *ptr != '\0' && *ptr != ':'; ptr++,(*size)++) { + for (optr = word, *optr = '\0'; + *ptr != '\0' && *ptr != ':'; ptr++, (*size)++) { if (!getall) { if (isspace(*ptr)) break; @@ -64,16 +62,17 @@ int getall; /* if TRUE, get all char until ':' or '\0' */ /* If the character is quoted, analyze it. */ if (*ptr == '\\') { - c = quoted(ptr,&qsize); + c = quoted(ptr, &qsize); (*size) += qsize; ptr += qsize; } else c = *ptr; /* If there is room, add this character to the word. */ - if (optr < &word[BUFSIZ] ) *optr++ = c; + if (optr < &word[BUFSIZ]) + *optr++ = c; } - /* skip trailing blanks if any*/ + /* skip trailing blanks if any */ while (isspace(*ptr)) { (*size)++; ptr++; @@ -81,23 +80,21 @@ int getall; /* if TRUE, get all char until ':' or '\0' */ /* Make sure the line is null terminated. */ *optr++ = '\0'; - return(word); + return (word); } /* "quoted" takes a quoted character, starting at the quote */ /* character, and returns a single character plus the size of */ /* the quote string. "quoted" recognizes the following as */ /* special, \n,\r,\v,\t,\b,\f as well as the \nnn notation. */ -char -quoted(ptr,qsize) -char *ptr; -int *qsize; +char +quoted(char *ptr, int *qsize) { - register char c,*rptr; - register int i; + char c, *rptr; + int i; rptr = ptr; - switch(*++rptr) { + switch (*++rptr) { case 'n': c = '\n'; break; @@ -124,9 +121,10 @@ int *qsize; /* If this is a numeric string, take up to three characters of */ /* it as the value of the quoted character. */ if (*rptr >= '0' && *rptr <= '7') { - for (i=0,c=0; i < 3;i++) { - c = c*8 + (*rptr - '0'); - if (*++rptr < '0' || *rptr > '7') break; + for (i = 0, c = 0; i < 3; i++) { + c = c * 8 + (*rptr - '0'); + if (*++rptr < '0' || *rptr > '7') + break; } rptr--; @@ -138,12 +136,13 @@ int *qsize; rptr--; /* In all other cases the quoting does nothing. */ - } else c = *rptr; + } else { + c = *rptr; + } break; } /* Compute the size of the quoted character. */ - (*qsize) = rptr - ptr; - return(c); + (*qsize) = rptr - ptr; + return (c); } - diff --git a/usr/src/cmd/ttymon/tmpeek.c b/usr/src/cmd/ttymon/tmpeek.c index bb960ca060..c9df956ed0 100644 --- a/usr/src/cmd/ttymon/tmpeek.c +++ b/usr/src/cmd/ttymon/tmpeek.c @@ -25,10 +25,7 @@ */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - - -#pragma ident "%Z%%M% %I% %E% SMI" +/* All Rights Reserved */ #include <stdio.h> #include <unistd.h> @@ -43,12 +40,11 @@ #include "tmstruct.h" #include "tmextern.h" -#define BRK 1 -#define DEL 2 +#define BRK 1 +#define DEL 2 -struct strbuf *do_peek(); -static int process(); -extern void sigint(); +struct strbuf *do_peek(int, int); +static int process(int, struct strbuf *); static int interrupt; @@ -60,7 +56,7 @@ static int interrupt; * - exit if hangup is received */ int -poll_data() +poll_data(void) { int j; struct strbuf *ptr; @@ -71,35 +67,35 @@ poll_data() debug("in poll_data"); #endif if (peek_ptr != NULL) { - for(j=0; j<peek_ptr->len; j++) peek_ptr->buf[j] &= 0x7F; - return(process(0,peek_ptr)); + for (j = 0; j < peek_ptr->len; j++) + peek_ptr->buf[j] &= 0x7F; + return (process(0, peek_ptr)); } fds[0].fd = 0; fds[0].events = POLLIN; sigact.sa_flags = 0; sigact.sa_handler = sigint; - (void)sigemptyset(&sigact.sa_mask); - (void)sigaddset(&sigact.sa_mask, SIGINT); - (void)sigaction(SIGINT, &sigact, NULL); + (void) sigemptyset(&sigact.sa_mask); + (void) sigaddset(&sigact.sa_mask, SIGINT); + (void) sigaction(SIGINT, &sigact, NULL); for (;;) { interrupt = 0; - if ((j = poll(fds,1,-1)) == -1) { + if ((j = poll(fds, 1, -1)) == -1) { if (interrupt == BRK) { - return(BADSPEED); + return (BADSPEED); } if (interrupt == DEL) { /* XXX revisit kmd */ - return(BADSPEED); + return (BADSPEED); } - } - else if (j > 0) { + } else if (j > 0) { if (fds[0].revents & POLLHUP) { - log( "POLLHUP received, about to exit"); + log("POLLHUP received, about to exit"); exit(1); } if (fds[0].revents & POLLIN) { ptr = do_peek(fds[0].fd, 255); if (ptr != NULL) { - return(process(fds[0].fd,ptr)); + return (process(fds[0].fd, ptr)); } } } @@ -107,17 +103,17 @@ poll_data() } /* - * process - process the data - * - return GOODNAME if it is a non-empty line + * process - process the data + * - return GOODNAME if it is a non-empty line * - return NONAME if a <CR> is received * - return BADNAME if zero byte is detected * - except the case of GOODNAME, data will be pulled out - * of the stream + * of the stream */ static int process( - int fd, /* fd to read data from if necessary */ - struct strbuf *ptr) /* ptr that holds data in ptr->buf */ + int fd, /* fd to read data from if necessary */ + struct strbuf *ptr) /* ptr that holds data in ptr->buf */ { unsigned i; char junk[BUFSIZ]; @@ -144,19 +140,19 @@ process( /* * do_peek - peek at the stream to get the data + * int fd; fd to do the ioctl on + * int n; maxlen of data to peek at * - this only called when POLLIN is detected, - * - so there should always be something there + * - so there should always be something there * - return a ptr to the buf that contains the data * - return NULL if nothing to peek at */ struct strbuf * -do_peek(fd,n) -int fd; /* fd to do the ioctl on */ -int n; /* maxlen of data to peek at */ +do_peek(int fd, int n) { int ret; - static struct strpeek peek; - register struct strpeek *peekp; + static struct strpeek peek; + struct strpeek *peekp; static char buf[BUFSIZ]; #ifdef DEBUG @@ -176,16 +172,16 @@ int n; /* maxlen of data to peek at */ exit(1); } if (ret == 0) { - return( (struct strbuf *)NULL ); + return (NULL); } - return(&(peekp->databuf)); + return (&(peekp->databuf)); } /* * sigint - this is called when SIGINT is caught */ void -sigint() +sigint(int s __unused) { struct strbuf *ptr; char junk[2]; @@ -196,13 +192,11 @@ sigint() ptr = do_peek(0, 1); if (ptr == NULL) { /* somebody type <del> */ interrupt = DEL; - } - else { + } else { if (ptr->buf[0] == '\0') { /* somebody type <brk> or frame error */ - (void)read(0,junk,1); + (void) read(0, junk, 1); interrupt = BRK; } } } - diff --git a/usr/src/cmd/ttymon/tmpmtab.c b/usr/src/cmd/ttymon/tmpmtab.c index 80a1f4a6cd..1bdddb946a 100644 --- a/usr/src/cmd/ttymon/tmpmtab.c +++ b/usr/src/cmd/ttymon/tmpmtab.c @@ -24,67 +24,58 @@ * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - - -#pragma ident "%Z%%M% %I% %E% SMI" - +/* All Rights Reserved */ #include <unistd.h> #include <stdlib.h> #include <sys/types.h> #include <ctype.h> #include <string.h> -#include <pwd.h> -#include <grp.h> +#include <pwd.h> +#include <grp.h> #include <signal.h> #include "ttymon.h" #include "tmstruct.h" #include "tmextern.h" -extern char *strsave(); -extern void set_softcar(); -extern int vml(); -void purge(); -static int get_flags(); -static int get_ttyflags(); -static int same_entry(); -static int check_pmtab(); -static void insert_pmtab(); -static void free_pmtab(); -static char *expand(); - -int check_identity(); +static int get_flags(char *, long *); +static int get_ttyflags(char *, long *); +static int same_entry(struct pmtab *, struct pmtab *); +static int check_pmtab(struct pmtab *); +static void insert_pmtab(struct pmtab *); +static void free_pmtab(struct pmtab *); +static char *expand(char *, char *); -int strcheck(); +int check_identity(struct pmtab *); /* - * read_pmtab() - * - read and parse pmtab + * read_pmtab() + * - read and parse pmtab * - store table in linked list pointed by global variable "PMtab" * - exit if file does not exist or error detected. */ void -read_pmtab() +read_pmtab(void) { - register struct pmtab *gptr; - register char *ptr, *wptr; - FILE *fp; - int input, state, size, rawc, field, linenum; - char oldc; - char line[BUFSIZ]; - char wbuf[BUFSIZ]; - static char *states[] = { - "","tag","flags","identity","reserved1","reserved2","reserved3", - "device","ttyflags","count","service", "timeout","ttylabel", - "modules","prompt","disable msg","terminal type","soft-carrier" + struct pmtab *gptr; + char *ptr, *wptr; + FILE *fp; + int input, state, size, rawc, field, linenum; + char oldc; + char line[BUFSIZ]; + char wbuf[BUFSIZ]; + static char *states[] = { + "", "tag", "flags", "identity", "reserved1", "reserved2", + "reserved3", "device", "ttyflags", "count", "service", "timeout", + "ttylabel", "modules", "prompt", "disable msg", "terminal type", + "soft-carrier" }; -# ifdef DEBUG +#ifdef DEBUG debug("in read_pmtab"); -# endif +#endif - if ((fp = fopen(PMTABFILE,"r")) == NULL) { + if ((fp = fopen(PMTABFILE, "r")) == NULL) { fatal("open pmtab (%s) failed", PMTABFILE); } @@ -97,7 +88,7 @@ read_pmtab() (gptr->p_status == LOCKED) || (gptr->p_status == UNACCESS)) { if (gptr->p_fd > 0) { - (void)close(gptr->p_fd); + (void) close(gptr->p_fd); gptr->p_fd = 0; } gptr->p_inservice = gptr->p_status; @@ -108,11 +99,13 @@ read_pmtab() wptr = wbuf; input = ACTIVE; linenum = 0; + field = FAILURE; do { linenum++; line[0] = '\0'; - for (ptr= line,oldc = '\0'; ptr < &line[sizeof(line)-1] && - (rawc=getc(fp))!= '\n' && rawc != EOF; ptr++,oldc=(char)rawc){ + for (ptr = line, oldc = '\0'; ptr < &line[sizeof (line) - 1] && + (rawc = getc(fp)) != '\n' && rawc != EOF; + ptr++, oldc = (char)rawc) { if ((rawc == '#') && (oldc != '\\')) break; *ptr = (char)rawc; @@ -121,21 +114,24 @@ read_pmtab() /* skip rest of the line */ if (rawc != EOF && rawc != '\n') { - if (rawc != '#') + if (rawc != '#') log("Entry too long.\n"); - while ((rawc = getc(fp)) != EOF && rawc != '\n') + while ((rawc = getc(fp)) != EOF && rawc != '\n') ; } if (rawc == EOF) { - if (ptr == line) break; - else input = FINISHED; + if (ptr == line) + break; + else + input = FINISHED; } /* if empty line, skip */ - for (ptr=line; *ptr != '\0' && isspace(*ptr); ptr++) + for (ptr = line; *ptr != '\0' && isspace(*ptr); ptr++) ; - if (*ptr == '\0') continue; + if (*ptr == '\0') + continue; #ifdef DEBUG debug("**** Next Entry ****\n%s", line); @@ -144,7 +140,7 @@ read_pmtab() /* Now we have the complete line */ - if ((gptr = ALLOC_PMTAB) == PNULL) + if ((gptr = ALLOC_PMTAB) == NULL) fatal("memory allocation failed"); /* set hangup flag, this is the default */ @@ -157,97 +153,109 @@ read_pmtab() gptr->p_termtype = ""; gptr->p_softcar = ""; - for (state=P_TAG,ptr=line;state !=FAILURE && state !=SUCCESS;) { - switch(state) { + for (state = P_TAG, ptr = line; state != FAILURE && + state != SUCCESS;) { + switch (state) { case P_TAG: - gptr->p_tag = strsave(getword(ptr,&size,0)); + gptr->p_tag = strsave(getword(ptr, &size, 0)); break; case P_FLAGS: - (void)strcpy(wptr, getword(ptr,&size,0)); + (void) strcpy(wptr, getword(ptr, &size, 0)); if ((get_flags(wptr, &gptr->p_flags)) != 0) { field = state; state = FAILURE; } break; case P_IDENTITY: - gptr->p_identity=strsave(getword(ptr,&size,0)); + gptr->p_identity = strsave( + getword(ptr, &size, 0)); break; case P_RES1: - gptr->p_res1=strsave(getword(ptr,&size,0)); + gptr->p_res1 = strsave(getword(ptr, &size, 0)); break; case P_RES2: - gptr->p_res2=strsave(getword(ptr,&size,0)); + gptr->p_res2 = strsave(getword(ptr, &size, 0)); break; case P_RES3: - gptr->p_res3=strsave(getword(ptr,&size,0)); + gptr->p_res3 = strsave(getword(ptr, &size, 0)); break; case P_DEVICE: - gptr->p_device = strsave(getword(ptr,&size,0)); + gptr->p_device = strsave( + getword(ptr, &size, 0)); break; case P_TTYFLAGS: - (void)strcpy(wptr, getword(ptr,&size,0)); - if ((get_ttyflags(wptr,&gptr->p_ttyflags))!=0) { + (void) strcpy(wptr, getword(ptr, &size, 0)); + if (get_ttyflags(wptr, + &gptr->p_ttyflags) != 0) { field = state; state = FAILURE; } break; case P_COUNT: - (void)strcpy(wptr, getword(ptr,&size,0)); + (void) strcpy(wptr, getword(ptr, &size, 0)); if (strcheck(wptr, NUM) != 0) { - log("wait_read count must be a positive number"); + log("wait_read count must be a " + "positive number"); field = state; state = FAILURE; + } else { + gptr->p_count = atoi(wptr); } - else - gptr->p_count = atoi(wptr); break; case P_SERVER: - gptr->p_server = - strsave(expand(getword(ptr,&size,1), - gptr->p_device)); + gptr->p_server = + strsave(expand(getword(ptr, &size, 1), + gptr->p_device)); break; case P_TIMEOUT: - (void)strcpy(wptr, getword(ptr,&size,0)); + (void) strcpy(wptr, getword(ptr, &size, 0)); if (strcheck(wptr, NUM) != 0) { - log("timeout value must be a positive number"); + log("timeout value must be a positive " + "number"); field = state; state = FAILURE; + } else { + gptr->p_timeout = atoi(wptr); } - else - gptr->p_timeout = atoi(wptr); break; case P_TTYLABEL: - gptr->p_ttylabel=strsave(getword(ptr,&size,0)); + gptr->p_ttylabel = strsave(getword(ptr, + &size, 0)); break; case P_MODULES: - gptr->p_modules = strsave(getword(ptr,&size,0)); + gptr->p_modules = strsave(getword(ptr, + &size, 0)); if (vml(gptr->p_modules) != 0) { field = state; state = FAILURE; } break; case P_PROMPT: - gptr->p_prompt = strsave(getword(ptr,&size,TRUE)); + gptr->p_prompt = strsave(getword(ptr, &size, + TRUE)); break; case P_DMSG: - gptr->p_dmsg = strsave(getword(ptr,&size,TRUE)); + gptr->p_dmsg = strsave(getword(ptr, &size, + TRUE)); break; case P_TERMTYPE: - gptr->p_termtype = strsave(getword(ptr,&size,TRUE)); + gptr->p_termtype = strsave(getword(ptr, + &size, TRUE)); break; case P_SOFTCAR: - gptr->p_softcar = strsave(getword(ptr,&size,TRUE)); + gptr->p_softcar = strsave(getword(ptr, + &size, TRUE)); break; } /* end switch */ ptr += size; - if (state == FAILURE) + if (state == FAILURE) break; if (*ptr == ':') { ptr++; /* Skip the ':' */ - state++ ; + state++; } else if (*ptr != '\0') { field = state; state = FAILURE; @@ -258,7 +266,7 @@ read_pmtab() * pmtab files. If Sun-added fields are * missing, this should not be an error. */ - if (state > P_DMSG) { + if (state > P_DMSG) { state = SUCCESS; } else { field = state; @@ -269,19 +277,19 @@ read_pmtab() if (state == SUCCESS) { if (check_pmtab(gptr) == 0) { - if (Nentries < Maxfds) + if (Nentries < Maxfds) { insert_pmtab(gptr); - else { + } else { log("can't add more entries to " "pmtab, Maxfds = %d", Maxfds); free_pmtab(gptr); - (void)fclose(fp); + (void) fclose(fp); return; } - } - else { + } else { log("Parsing failure for entry: \n%s", line); - log("-------------------------------------------"); + log("----------------------------------------" + "---"); free_pmtab(gptr); } } else { @@ -293,19 +301,16 @@ read_pmtab() } } while (input == ACTIVE); - (void)fclose(fp); - return; + (void) fclose(fp); } /* * get_flags - scan flags field to set U_FLAG and X_FLAG */ static int -get_flags(wptr, flags) -char *wptr; /* pointer to the input string */ -long *flags; /* pointer to the flag to set */ +get_flags(char *wptr, long *flags) { - register char *p; + char *p; for (p = wptr; *p; p++) { switch (*p) { case 'x': @@ -316,21 +321,21 @@ long *flags; /* pointer to the flag to set */ break; default: log("Invalid flag -- %c", *p); - return(-1); - } + return (-1); + } } - return(0); + return (0); } /* * get_ttyflags - scan ttyflags field to set corresponding flags + * char *wptr pointer to the input string + * long *ttyflags pointer to the flag to be set */ static int -get_ttyflags(wptr, ttyflags) -char *wptr; /* pointer to the input string */ -long *ttyflags; /* pointer to the flag to be set*/ +get_ttyflags(char *wptr, long *ttyflags) { - register char *p; + char *p; for (p = wptr; *p; p++) { switch (*p) { case 'c': @@ -350,26 +355,26 @@ long *ttyflags; /* pointer to the flag to be set*/ break; default: log("Invalid ttyflag -- %c", *p); - return(-1); - } + return (-1); + } } - return(0); + return (0); } -# ifdef DEBUG +#ifdef DEBUG /* * pflags - put service flags into intelligible form for output + * long flags - binary representation of the flags */ char * -pflags(flags) -long flags; /* binary representation of the flags */ +pflags(long flags) { - register int i; /* scratch counter */ + int i; /* scratch counter */ static char buf[BUFSIZ]; /* formatted flags */ if (flags == 0) - return("-"); + return ("-"); i = 0; if (flags & U_FLAG) { buf[i++] = 'u'; @@ -382,28 +387,28 @@ long flags; /* binary representation of the flags */ if (flags) log("Internal error in pflags"); buf[i] = '\0'; - return(buf); + return (buf); } /* * pttyflags - put ttyflags into intelligible form for output + * long flags - binary representation of ttyflags */ char * -pttyflags(flags) -long flags; /* binary representation of ttyflags */ +pttyflags(long flags) { - register int i; /* scratch counter */ + int i; /* scratch counter */ static char buf[BUFSIZ]; /* formatted flags */ if (flags == 0) - return("h"); + return ("h"); i = 0; if (flags & C_FLAG) { buf[i++] = 'c'; flags &= ~C_FLAG; } - if (flags & H_FLAG) + if (flags & H_FLAG) flags &= ~H_FLAG; else buf[i++] = 'h'; @@ -422,27 +427,27 @@ long flags; /* binary representation of ttyflags */ if (flags) log("Internal error in p_ttyflags"); buf[i] = '\0'; - return(buf); + return (buf); } void -dump_pmtab() +dump_pmtab(void) { struct pmtab *gptr; debug("in dump_pmtab"); log("********** dumping pmtab **********"); log(" "); - for (gptr=PMtab; gptr; gptr = gptr->p_next) { + for (gptr = PMtab; gptr != NULL; gptr = gptr->p_next) { log("-------------------------------------------"); log("tag:\t\t%s", gptr->p_tag); - log("flags:\t\t%s",pflags(gptr->p_flags)); + log("flags:\t\t%s", pflags(gptr->p_flags)); log("identity:\t%s", gptr->p_identity); log("reserved1:\t%s", gptr->p_res1); log("reserved2:\t%s", gptr->p_res2); log("reserved3:\t%s", gptr->p_res3); log("device:\t%s", gptr->p_device); - log("ttyflags:\t%s",pttyflags(gptr->p_ttyflags)); + log("ttyflags:\t%s", pttyflags(gptr->p_ttyflags)); log("count:\t\t%d", gptr->p_count); log("server:\t%s", gptr->p_server); log("timeout:\t%d", gptr->p_timeout); @@ -455,7 +460,7 @@ dump_pmtab() log("status:\t\t%d", gptr->p_status); log("inservice:\t%d", gptr->p_inservice); log("fd:\t\t%d", gptr->p_fd); - log("pid:\t\t%ld", gptr->p_pid); + log("pid:\t\t%ld", gptr->p_childpid); log("uid:\t\t%ld", gptr->p_uid); log("gid:\t\t%ld", gptr->p_gid); log("dir:\t%s", gptr->p_dir); @@ -463,61 +468,60 @@ dump_pmtab() } log("********** end dumping pmtab **********"); } -# endif +#endif /* * same_entry(e1,e2) - compare 2 entries of pmtab * if the fields are different, copy e2 to e1 - * return 1 if same, return 0 if different + * return 1 if same, return 0 if different */ static int -same_entry(e1,e2) -struct pmtab *e1,*e2; +same_entry(struct pmtab *e1, struct pmtab *e2) { if (strcmp(e1->p_identity, e2->p_identity) != 0) - return(0); + return (0); if (strcmp(e1->p_res1, e2->p_res1) != 0) - return(0); + return (0); if (strcmp(e1->p_res2, e2->p_res2) != 0) - return(0); + return (0); if (strcmp(e1->p_res3, e2->p_res3) != 0) - return(0); + return (0); if (strcmp(e1->p_device, e2->p_device) != 0) - return(0); + return (0); if (strcmp(e1->p_server, e2->p_server) != 0) - return(0); + return (0); if (strcmp(e1->p_ttylabel, e2->p_ttylabel) != 0) - return(0); + return (0); if (strcmp(e1->p_modules, e2->p_modules) != 0) - return(0); + return (0); if (strcmp(e1->p_prompt, e2->p_prompt) != 0) - return(0); + return (0); if (strcmp(e1->p_dmsg, e2->p_dmsg) != 0) - return(0); + return (0); if (strcmp(e1->p_termtype, e2->p_termtype) != 0) - return(0); + return (0); if (strcmp(e1->p_softcar, e2->p_softcar) != 0) - return(0); + return (0); if (e1->p_flags != e2->p_flags) - return(0); + return (0); /* - * compare lowest 4 bits only, + * compare lowest 4 bits only, * because A_FLAG is not part of original ttyflags */ if ((e1->p_ttyflags & ~A_FLAG) != (e2->p_ttyflags & ~A_FLAG)) - return(0); + return (0); if (e1->p_count != e2->p_count) - return(0); + return (0); if (e1->p_timeout != e2->p_timeout) - return(0); + return (0); if (e1->p_uid != e2->p_uid) - return(0); + return (0); if (e1->p_gid != e2->p_gid) - return(0); + return (0); if (strcmp(e1->p_dir, e2->p_dir) != 0) - return(0); - return(1); + return (0); + return (1); } @@ -526,15 +530,14 @@ struct pmtab *e1,*e2; */ static void -insert_pmtab(sp) -register struct pmtab *sp; /* ptr to entry to be inserted */ +insert_pmtab(struct pmtab *sp) { - register struct pmtab *tsp, *savtsp; /* scratch pointers */ + struct pmtab *tsp, *savtsp; /* scratch pointers */ int ret; /* strcmp return value */ -# ifdef DEBUG +#ifdef DEBUG debug("in insert_pmtab"); -# endif +#endif savtsp = tsp = PMtab; /* @@ -548,41 +551,38 @@ register struct pmtab *sp; /* ptr to entry to be inserted */ savtsp = tsp; tsp = tsp->p_next; continue; - } - else if (ret == 0) { + } else if (ret == 0) { if (tsp->p_status) { /* this is a duplicate entry, ignore it */ log("Ignoring duplicate entry for <%s>", tsp->p_tag); - } - else { - if (same_entry(tsp,sp)) { /* same entry */ + } else { + if (same_entry(tsp, sp)) { /* same entry */ tsp->p_status = VALID; - } - else { /* entry changed */ - if ((sp->p_flags & X_FLAG) && - ((sp->p_dmsg == NULL) || - (*(sp->p_dmsg) == '\0'))) { + } else { /* entry changed */ + if ((sp->p_flags & X_FLAG) && + ((sp->p_dmsg == NULL) || + (*(sp->p_dmsg) == '\0'))) { /* disabled entry */ tsp->p_status = NOTVALID; - } - else { -# ifdef DEBUG - debug("replacing <%s>", sp->p_tag); -# endif + } else { +#ifdef DEBUG + debug("replacing <%s>", + sp->p_tag); +#endif /* replace old entry */ sp->p_next = tsp->p_next; if (tsp == PMtab) { - PMtab = sp; - } - else { - savtsp->p_next = sp; + PMtab = sp; + } else { + savtsp->p_next = sp; } sp->p_status = CHANGED; sp->p_fd = tsp->p_fd; - sp->p_pid = tsp->p_pid; - sp->p_inservice = - tsp->p_inservice; + sp->p_childpid = + tsp->p_childpid; + sp->p_inservice = + tsp->p_inservice; sp = tsp; } } @@ -590,11 +590,10 @@ register struct pmtab *sp; /* ptr to entry to be inserted */ } free_pmtab(sp); return; - } - else { - if ((sp->p_flags & X_FLAG) && - ((sp->p_dmsg == NULL) || - (*(sp->p_dmsg) == '\0'))) { /* disabled entry */ + } else { + if ((sp->p_flags & X_FLAG) && + ((sp->p_dmsg == NULL) || + (*(sp->p_dmsg) == '\0'))) { /* disabled entry */ free_pmtab(sp); return; } @@ -611,14 +610,13 @@ register struct pmtab *sp; /* ptr to entry to be inserted */ if (tsp == PMtab) { sp->p_next = PMtab; PMtab = sp; - } - else { + } else { sp->p_next = savtsp->p_next; savtsp->p_next = sp; } -# ifdef DEBUG +#ifdef DEBUG debug("adding <%s>", sp->p_tag); -# endif +#endif Nentries++; /* this entry is "current" */ sp->p_status = VALID; @@ -630,9 +628,9 @@ register struct pmtab *sp; /* ptr to entry to be inserted */ * either an empty list or should put element at end of list */ - if ((sp->p_flags & X_FLAG) && - ((sp->p_dmsg == NULL) || - (*(sp->p_dmsg) == '\0'))) { /* disabled entry */ + if ((sp->p_flags & X_FLAG) && + ((sp->p_dmsg == NULL) || + (*(sp->p_dmsg) == '\0'))) { /* disabled entry */ free_pmtab(sp); /* do not poll this entry */ return; } @@ -649,9 +647,9 @@ register struct pmtab *sp; /* ptr to entry to be inserted */ PMtab = sp; else savtsp->p_next = sp; -# ifdef DEBUG +#ifdef DEBUG debug("adding <%s>", sp->p_tag); -# endif +#endif ++Nentries; /* this entry is "current" */ sp->p_status = VALID; @@ -661,37 +659,34 @@ register struct pmtab *sp; /* ptr to entry to be inserted */ /* * purge - purge linked list of "old" entries */ - - void -purge() +purge(void) { - register struct pmtab *sp; /* working pointer */ - register struct pmtab *savesp, *tsp; /* scratch pointers */ + struct pmtab *sp; /* working pointer */ + struct pmtab *savesp, *tsp; /* scratch pointers */ -# ifdef DEBUG +#ifdef DEBUG debug("in purge"); -# endif +#endif sp = savesp = PMtab; while (sp) { if (sp->p_status) { -# ifdef DEBUG +#ifdef DEBUG debug("p_status not 0"); -# endif +#endif savesp = sp; sp = sp->p_next; - } - else { + } else { tsp = sp; if (tsp == PMtab) { PMtab = sp->p_next; savesp = PMtab; - } - else + } else { savesp->p_next = sp->p_next; -# ifdef DEBUG + } +#ifdef DEBUG debug("purging <%s>", sp->p_tag); -# endif +#endif sp = sp->p_next; free_pmtab(tsp); } @@ -702,8 +697,7 @@ purge() * free_pmtab - free one pmtab entry */ static void -free_pmtab(p) -struct pmtab *p; +free_pmtab(struct pmtab *p) { #ifdef DEBUG debug("in free_pmtab"); @@ -721,8 +715,7 @@ struct pmtab *p; free(p->p_dmsg); free(p->p_termtype); free(p->p_softcar); - if (p->p_dir) - free(p->p_dir); + free(p->p_dir); free(p); } @@ -731,81 +724,73 @@ struct pmtab *p; * - return 0 if everything is ok * - return -1 if something is wrong */ - static int -check_pmtab(p) -struct pmtab *p; +check_pmtab(struct pmtab *p) { if (p == NULL) { log("pmtab ptr is NULL"); - return(-1); + return (-1); } /* check service tag */ if ((p->p_tag == NULL) || (*(p->p_tag) == '\0')) { log("port/service tag is missing"); - return(-1); + return (-1); } if (strlen(p->p_tag) > (size_t)(MAXID - 1)) { log("port/service tag <%s> is longer than %d", p->p_tag, MAXID-1); - return(-1); + return (-1); } if (strcheck(p->p_tag, ALNUM) != 0) { log("port/service tag <%s> is not alphanumeric", p->p_tag); - return(-1); + return (-1); } if (check_identity(p) != 0) { - return(-1); + return (-1); } if (check_device(p->p_device) != 0) - return(-1); + return (-1); if (check_cmd(p->p_server) != 0) - return(-1); - return(0); + return (-1); + return (0); } -extern struct passwd *getpwnam(); -extern void endpwent(); -extern struct group *getgrgid(); -extern void endgrent(); - /* - * check_identity - check to see if the identity is a valid user - * - log name in the passwd file, - * - and if its group id is a valid one - * - return 0 if everything is ok. Otherwise, return -1 + * check_identity - check to see if the identity is a valid user + * - log name in the passwd file, + * - and if its group id is a valid one + * - return 0 if everything is ok. Otherwise, return -1 */ int -check_identity(p) -struct pmtab *p; +check_identity(struct pmtab *p) { - register struct passwd *pwdp; + struct passwd *pwdp; if ((p->p_identity == NULL) || (*(p->p_identity) == '\0')) { log("identity field is missing"); - return(-1); + return (-1); } if ((pwdp = getpwnam(p->p_identity)) == NULL) { log("missing or bad passwd entry for <%s>", p->p_identity); endpwent(); - return(-1); + return (-1); } if (getgrgid(pwdp->pw_gid) == NULL) { log("no group entry for %ld", pwdp->pw_gid); endgrent(); endpwent(); - return(-1); + return (-1); } p->p_uid = pwdp->pw_uid; p->p_gid = pwdp->pw_gid; p->p_dir = strsave(pwdp->pw_dir); endgrent(); endpwent(); - return(0); + return (0); } /* @@ -814,11 +799,9 @@ struct pmtab *p; * - return the expanded string */ static char * -expand(cmdp,devp) -char *cmdp; /* ptr to cmd string */ -char *devp; /* ptr to device name */ +expand(char *cmdp, char *devp) { - register char *cp, *dp, *np; + char *cp, *dp, *np; static char buf[BUFSIZ]; cp = cmdp; np = buf; @@ -844,6 +827,5 @@ char *devp; /* ptr to device name */ } } *np = '\0'; - return(buf); + return (buf); } - diff --git a/usr/src/cmd/ttymon/tmsac.c b/usr/src/cmd/ttymon/tmsac.c index 7000203142..8b5524b1ec 100644 --- a/usr/src/cmd/ttymon/tmsac.c +++ b/usr/src/cmd/ttymon/tmsac.c @@ -24,11 +24,7 @@ * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - - -#pragma ident "%Z%%M% %I% %E% SMI" - +/* All Rights Reserved */ #include <stdlib.h> #include <stdio.h> @@ -37,33 +33,32 @@ #include <signal.h> #include <string.h> #include <unistd.h> -#include "ttymon.h" -#include "tmextern.h" -#include "sac.h" +#include "ttymon.h" +#include "tmextern.h" +#include "sac.h" /* * openpid - open the pid and put ttymon's pid in it - * - put an advisory lock on the file + * - put an advisory lock on the file * - to prevent another instance of ttymon in same directory * - SAC also makes use of the lock * - fd 0 is reserved for pid file */ void -openpid() +openpid(void) { - extern int Lckfd; char lockbuf[16]; /* large enough for a PID string */ - (void)close(0); - /* open for read first, otherwise, may delete the pid already there*/ + (void) close(0); + /* open for read first, otherwise, may delete the pid already there */ if ((Lckfd = open(PIDFILE, O_RDONLY)) != -1) { - if (lockf(Lckfd, F_TEST, 0L) == -1) + if (lockf(Lckfd, F_TEST, 0L) == -1) fatal("pid file is locked. ttymon may already be " "running!"); - (void)close(Lckfd); + (void) close(Lckfd); } - if ((Lckfd = open(PIDFILE, O_WRONLY|O_CREAT|O_TRUNC, 0644 )) != 0) + if ((Lckfd = open(PIDFILE, O_WRONLY|O_CREAT|O_TRUNC, 0644)) != 0) fatal("open pid file failed: %s", strerror(errno)); if (lockf(Lckfd, F_LOCK, 0L) == -1) @@ -82,21 +77,19 @@ openpid() */ void -openpipes() +openpipes(void) { - extern int Pfd, Sfd; - Sfd = open(SACPIPE, O_WRONLY); if (Sfd < 0) fatal("open sacpipe failed: %s", strerror(errno)); - Pfd = open(PMPIPE, O_RDWR|O_NONBLOCK); + Pfd = open(PMPIPE, O_RDWR|O_NONBLOCK); if (Pfd < 0) fatal("open pmpipe failed: %s", strerror(errno)); #ifdef DEBUG - log("fd(sacpipe)\t = %d",Sfd); - log("fd(pmpipe)\t = %d",Pfd); + log("fd(sacpipe)\t = %d", Sfd); + log("fd(pmpipe)\t = %d", Pfd); #endif } @@ -104,10 +97,8 @@ openpipes() * remove_env(env) - remove an environment variable from the environment */ static void -remove_env(env) -char *env; +remove_env(char *env) { - extern char **environ; char **p; char **rp = NULL; @@ -115,7 +106,7 @@ char *env; if (p == NULL) return; while (*p) { - if (strncmp(*p, env,strlen(env)) == 0) + if (strncmp(*p, env, strlen(env)) == 0) rp = p; p++; } @@ -131,17 +122,15 @@ char *env; */ void -get_environ() +get_environ(void) { - extern char State, *Istate, *Tag; - if ((Tag = getenv("PMTAG")) == NULL) - fatal("PMTAG is missing"); + fatal("PMTAG is missing"); - if ((Istate = getenv("ISTATE")) == NULL) + if ((Istate = getenv("ISTATE")) == NULL) fatal("ISTATE is missing"); - State = (!strcmp(Istate, "enabled")) ? PM_ENABLED : PM_DISABLED; + State = (strcmp(Istate, "enabled") == 0) ? PM_ENABLED : PM_DISABLED; /* * remove the environment variables so they will not @@ -155,12 +144,12 @@ get_environ() * sacpoll - the event handler when sac event is posted */ void -sacpoll() +sacpoll(void) { - int ret; + int ret; char oldState; - struct sacmsg sacmsg; - struct pmmsg pmmsg; + struct sacmsg sacmsg; + struct pmmsg pmmsg; sigset_t cset; sigset_t tset; @@ -169,10 +158,10 @@ sacpoll() #endif /* we don't want to be interrupted by sigchild now */ - (void)sigprocmask(SIG_SETMASK, NULL, &cset); + (void) sigprocmask(SIG_SETMASK, NULL, &cset); tset = cset; - (void)sigaddset(&tset, SIGCLD); - (void)sigprocmask(SIG_SETMASK, &tset, NULL); + (void) sigaddset(&tset, SIGCLD); + (void) sigprocmask(SIG_SETMASK, &tset, NULL); /* * read sac messages, one at a time until no message @@ -182,39 +171,37 @@ sacpoll() */ for (;;) { - ret = read(Pfd, &sacmsg, sizeof(sacmsg)); + ret = read(Pfd, &sacmsg, sizeof (sacmsg)); if (ret < 0) { - switch(errno) { + switch (errno) { case EAGAIN: /* no more data on the pipe */ - (void)sigprocmask(SIG_SETMASK, &cset, NULL); + (void) sigprocmask(SIG_SETMASK, &cset, NULL); return; case EINTR: break; - default: + default: fatal("pmpipe read failed: %s", strerror(errno)); break; /*NOTREACHED*/ } - } - else if (ret == 0) { + } else if (ret == 0) { /* no more data on the pipe */ - (void)sigprocmask(SIG_SETMASK, &cset, NULL); + (void) sigprocmask(SIG_SETMASK, &cset, NULL); return; - } - else { + } else { pmmsg.pm_size = 0; (void) strcpy(pmmsg.pm_tag, Tag); pmmsg.pm_maxclass = TM_MAXCLASS; pmmsg.pm_type = PM_STATUS; - switch(sacmsg.sc_type) { + switch (sacmsg.sc_type) { case SC_STATUS: break; case SC_ENABLE: log("Got SC_ENABLE message"); oldState = State; State = PM_ENABLED; - if (State != oldState) { + if (State != oldState) { #ifdef DEBUG debug("state changed to ENABLED"); #endif @@ -225,7 +212,7 @@ sacpoll() log("Got SC_DISABLE message"); oldState = State; State = PM_DISABLED; - if (State != oldState) { + if (State != oldState) { #ifdef DEBUG debug("state changed to DISABLED"); #endif @@ -243,7 +230,8 @@ sacpoll() } /* end switch */ pmmsg.pm_state = State; - while (write(Sfd, &pmmsg, sizeof(pmmsg)) != sizeof(pmmsg)) { + while (write(Sfd, &pmmsg, sizeof (pmmsg)) != + sizeof (pmmsg)) { if (errno == EINTR) continue; log("sanity response to SAC failed: %s", diff --git a/usr/src/cmd/ttymon/tmsig.c b/usr/src/cmd/ttymon/tmsig.c index f56dd6b929..18378bde3e 100644 --- a/usr/src/cmd/ttymon/tmsig.c +++ b/usr/src/cmd/ttymon/tmsig.c @@ -24,10 +24,7 @@ * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - - -#pragma ident "%Z%%M% %I% %E% SMI" +/* All Rights Reserved */ #include <stdio.h> #include <signal.h> @@ -43,54 +40,49 @@ * SIGCLD - tmchild died */ void -catch_signals() +catch_signals(void) { sigset_t cset; struct sigaction sigact; - extern void sigterm(); - extern void sigchild(); - extern void sigpoll_catch(); -#ifdef DEBUG - extern void dump_pmtab(); - extern void dump_ttydefs(); +#ifdef DEBUG debug("in catch_signals"); #endif cset = Origmask; - (void)sigdelset(&cset, SIGTERM); - (void)sigdelset(&cset, SIGCLD); - (void)sigdelset(&cset, SIGPOLL); + (void) sigdelset(&cset, SIGTERM); + (void) sigdelset(&cset, SIGCLD); + (void) sigdelset(&cset, SIGPOLL); #ifdef DEBUG - (void)sigdelset(&cset, SIGUSR1); - (void)sigdelset(&cset, SIGUSR2); + (void) sigdelset(&cset, SIGUSR1); + (void) sigdelset(&cset, SIGUSR2); #endif - (void)sigprocmask(SIG_SETMASK, &cset, NULL); + (void) sigprocmask(SIG_SETMASK, &cset, NULL); sigact.sa_flags = 0; sigact.sa_handler = sigterm; - (void)sigemptyset(&sigact.sa_mask); - (void)sigaddset(&sigact.sa_mask, SIGTERM); - (void)sigaction(SIGTERM, &sigact, NULL); + (void) sigemptyset(&sigact.sa_mask); + (void) sigaddset(&sigact.sa_mask, SIGTERM); + (void) sigaction(SIGTERM, &sigact, NULL); sigact.sa_flags = 0; sigact.sa_handler = sigchild; - (void)sigemptyset(&sigact.sa_mask); - (void)sigaction(SIGCLD, &sigact, NULL); + (void) sigemptyset(&sigact.sa_mask); + (void) sigaction(SIGCLD, &sigact, NULL); sigact.sa_flags = 0; sigact.sa_handler = sigpoll_catch; - (void)sigemptyset(&sigact.sa_mask); - (void)sigaddset(&sigact.sa_mask, SIGPOLL); - (void)sigaction(SIGPOLL, &sigact, NULL); + (void) sigemptyset(&sigact.sa_mask); + (void) sigaddset(&sigact.sa_mask, SIGPOLL); + (void) sigaction(SIGPOLL, &sigact, NULL); #ifdef DEBUG sigact.sa_flags = 0; sigact.sa_handler = dump_pmtab; - (void)sigemptyset(&sigact.sa_mask); - (void)sigaddset(&sigact.sa_mask, SIGUSR1); - (void)sigaction(SIGUSR1, &sigact, NULL); + (void) sigemptyset(&sigact.sa_mask); + (void) sigaddset(&sigact.sa_mask, SIGUSR1); + (void) sigaction(SIGUSR1, &sigact, NULL); sigact.sa_flags = 0; sigact.sa_handler = dump_ttydefs; - (void)sigemptyset(&sigact.sa_mask); - (void)sigaddset(&sigact.sa_mask, SIGUSR2); - (void)sigaction(SIGUSR2, &sigact, NULL); + (void) sigemptyset(&sigact.sa_mask); + (void) sigaddset(&sigact.sa_mask, SIGUSR2); + (void) sigaction(SIGUSR2, &sigact, NULL); #endif } @@ -99,25 +91,23 @@ catch_signals() * and need to reset them */ void -child_sigcatch() +child_sigcatch(void) { struct sigaction sigact; sigset_t cset; - extern void sigpoll(); - extern void sigint(); cset = Origmask; - (void)sigdelset(&cset, SIGINT); - (void)sigdelset(&cset, SIGPOLL); - (void)sigprocmask(SIG_SETMASK, &cset, NULL); + (void) sigdelset(&cset, SIGINT); + (void) sigdelset(&cset, SIGPOLL); + (void) sigprocmask(SIG_SETMASK, &cset, NULL); sigact.sa_flags = 0; sigact.sa_handler = sigpoll; - (void)sigemptyset(&sigact.sa_mask); - (void)sigaddset(&sigact.sa_mask, SIGPOLL); - (void)sigaction(SIGPOLL, &sigact, NULL); + (void) sigemptyset(&sigact.sa_mask); + (void) sigaddset(&sigact.sa_mask, SIGPOLL); + (void) sigaction(SIGPOLL, &sigact, NULL); sigact.sa_flags = 0; sigact.sa_handler = sigint; - (void)sigemptyset(&sigact.sa_mask); - (void)sigaddset(&sigact.sa_mask, SIGINT); - (void)sigaction(SIGINT, &sigact, NULL); + (void) sigemptyset(&sigact.sa_mask); + (void) sigaddset(&sigact.sa_mask, SIGINT); + (void) sigaction(SIGINT, &sigact, NULL); } diff --git a/usr/src/cmd/ttymon/tmstruct.h b/usr/src/cmd/ttymon/tmstruct.h index 38aea1063e..288c1ec122 100644 --- a/usr/src/cmd/ttymon/tmstruct.h +++ b/usr/src/cmd/ttymon/tmstruct.h @@ -24,7 +24,7 @@ */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ +/* All Rights Reserved */ #ifndef _TMSTRUCT_H @@ -34,10 +34,10 @@ * /etc/ttydefs structure */ struct Gdef { - char *g_id; /* id for modes & speeds */ - char *g_iflags; /* initial terminal flags */ - char *g_fflags; /* final terminal flags */ - short g_autobaud; /* autobaud indicator */ + char *g_id; /* id for modes & speeds */ + char *g_iflags; /* initial terminal flags */ + char *g_fflags; /* final terminal flags */ + short g_autobaud; /* autobaud indicator */ char *g_nextid; /* next id if this speed is wrong */ }; @@ -56,7 +56,7 @@ struct pmtab { long p_ttyflags; /* ttyflags */ int p_count; /* wait_read count */ char *p_server; /* full service cmd line */ - int p_timeout; /* timeout for input */ + int p_timeout; /* timeout for input */ char *p_ttylabel; /* ttylabel in /etc/ttydefs */ char *p_modules; /* modules to push */ char *p_prompt; /* prompt message */ @@ -65,10 +65,10 @@ struct pmtab { char *p_softcar; /* use softcarrier */ /* the following fields are for ttymon internal use */ - int p_status; /* status of entry */ + int p_status; /* status of entry */ int p_fd; /* fd for the open device */ - pid_t p_pid; /* pid of child on the device */ - int p_inservice; /* service invoked */ + pid_t p_childpid; /* pid of child on the device */ + int p_inservice; /* service invoked */ int p_respawn; /* respawn count in this series */ long p_time; /* start time of a series */ uid_t p_uid; /* uid of p_identity */ @@ -80,8 +80,8 @@ struct pmtab { /* * valid flags for p_flags field of pmtab */ -#define X_FLAG 0x1 /* port/service disabled */ -#define U_FLAG 0x2 /* create utmp entry for the service */ +#define X_FLAG 0x1 /* port/service disabled */ +#define U_FLAG 0x2 /* create utmp entry for the service */ /* * valid flags for p_ttyflags field of pmtab @@ -102,13 +102,11 @@ struct pmtab { */ #define NOTVALID 0 /* entry is not valid */ #define VALID 1 /* entry is valid */ -#define CHANGED 2 /* entry is valid but changed */ +#define CHANGED 2 /* entry is valid but changed */ #define GETTY 3 /* entry is for ttymon express */ #define ALLOC_PMTAB \ ((struct pmtab *)calloc((unsigned)1, \ (unsigned)sizeof (struct pmtab))) -#define PNULL ((struct pmtab *)NULL) - #endif /* _TMSTRUCT_H */ diff --git a/usr/src/cmd/ttymon/tmterm.c b/usr/src/cmd/ttymon/tmterm.c index 3c01bfed5e..96e63af2d3 100644 --- a/usr/src/cmd/ttymon/tmterm.c +++ b/usr/src/cmd/ttymon/tmterm.c @@ -25,11 +25,7 @@ */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - - -#pragma ident "%Z%%M% %I% %E% SMI" - +/* All Rights Reserved */ #include <stdlib.h> #include <stdio.h> @@ -43,56 +39,47 @@ #include <sys/types.h> #include "sys/stropts.h" #include "sys/signal.h" -#include "ttymon.h" -#include "tmstruct.h" -#include "tmextern.h" - -extern void mkargv(); +#include "ttymon.h" +#include "tmstruct.h" +#include "tmextern.h" /* - * set_termio - set termio on device + * set_termio - set termio on device * fd - fd for the device - * options - stty termio options - * aspeed - autobaud speed + * options - stty termio options + * aspeed - autobaud speed * clear - if TRUE, current flags will be set to some defaults - * before applying the options - * - if FALSE, current flags will not be cleared + * before applying the options + * - if FALSE, current flags will not be cleared * mode - terminal mode, CANON, RAW */ int -set_termio(fd,options,aspeed,clear,mode) -int fd; -char *options; -char *aspeed; -int clear; -long mode; +set_termio(int fd, char *options, char *aspeed, int clear, long mode) { - struct termio termio; - struct termios termios; - struct stio stermio; - struct termiox termiox; - struct winsize winsize; - struct winsize owinsize; + struct termio termio; + struct termios termios; + struct stio stermio; + struct termiox termiox; + struct winsize winsize; + struct winsize owinsize; int term; int cnt = 1; - char *uarg; + char *uarg; char *argvp[MAXARGS]; /* stty args */ static char *binstty = "/usr/bin/stty"; static char buf[BUFSIZ]; - extern int get_ttymode(), set_ttymode(); - extern char *sttyparse(); #ifdef DEBUG debug("in set_termio"); #endif - if ((term = get_ttymode(fd, &termio, &termios, &stermio, - &termiox, &winsize)) < 0) { + if ((term = get_ttymode(fd, &termio, &termios, &stermio, + &termiox, &winsize)) < 0) { log("set_termio: get_ttymode failed: %s", strerror(errno)); - return(-1); + return (-1); } owinsize = winsize; if (clear) { @@ -100,8 +87,7 @@ long mode; /* could have removed these too - rely on defaults */ termios.c_cc[VEOF] = CEOF; termios.c_cc[VEOL] = CNUL; - } - else { + } else { termios.c_lflag &= ECHO; termios.c_cc[VMIN] = 1; termios.c_cc[VTIME] = 0; @@ -112,27 +98,27 @@ long mode; if (options != NULL && *options != '\0') { /* just a place holder to make it look like invoking stty */ argvp[0] = binstty; - (void)strcpy(buf,options); - mkargv(buf,&argvp[1],&cnt,MAXARGS-1); + (void) strcpy(buf, options); + mkargv(buf, &argvp[1], &cnt, MAXARGS - 1); if (aspeed != NULL && *aspeed != '\0') { argvp[cnt++] = aspeed; } argvp[cnt] = (char *)0; - if ((uarg = sttyparse(cnt, argvp, term, &termio, &termios, - &termiox, &winsize)) != NULL) { + if ((uarg = sttyparse(cnt, argvp, term, &termio, &termios, + &termiox, &winsize)) != NULL) { log("sttyparse unknown mode: %s", uarg); - return(-1); + return (-1); } } - if (set_ttymode(fd, term, &termio, &termios, &stermio, - &termiox, &winsize, &owinsize) != 0) { + if (set_ttymode(fd, term, &termio, &termios, &stermio, + &termiox, &winsize, &owinsize) != 0) { log("set_termio: set_ttymode failed", strerror(errno)); - return(-1); + return (-1); } - return(0); + return (0); } #ifdef NOT_USE @@ -140,8 +126,7 @@ long mode; * turnon_canon - turn on canonical processing * - return 0 if succeeds, -1 if fails */ -turnon_canon(fd) -int fd; +turnon_canon(int fd) { struct termio termio; @@ -151,17 +136,17 @@ int fd; if (ioctl(fd, TCGETA, &termio) != 0) { log("turnon_canon: TCGETA failed, fd = %d: %s", fd, strerror(errno)); - return(-1); + return (-1); } - termio.c_lflag |= (ISIG|ICANON|ECHO|ECHOE|ECHOK); + termio.c_lflag |= (ISIG|ICANON|ECHO|ECHOE|ECHOK); termio.c_cc[VEOF] = CEOF; termio.c_cc[VEOL] = CNUL; if (ioctl(fd, TCSETA, &termio) != 0) { log("turnon_canon: TCSETA failed, fd = %d: %s", fd, strerror(errno)); - return(-1); + return (-1); } - return(0); + return (0); } #endif @@ -169,16 +154,13 @@ int fd; * flush_input - flush the input queue */ void -flush_input(fd) -int fd; +flush_input(int fd) { if (ioctl(fd, I_FLUSH, FLUSHR) == -1) log("flush_input failed, fd = %d: %s", fd, strerror(errno)); if (ioctl(fd, TCSBRK, 1) == -1) log("drain of ouput failed, fd = %d: %s", fd, strerror(errno)); - - return; } /* @@ -201,21 +183,20 @@ push_linedisc( * copy modules into buf so we won't mess up the original buffer * because strtok will chop the string */ - p = strcpy(buf,modules); + p = strcpy(buf, modules); - while(ioctl(fd, I_POP, 0) >= 0) /* pop everything */ + while (ioctl(fd, I_POP, 0) >= 0) /* pop everything */ ; - for (p=(char *)strtok(p,","); p!=(char *)NULL; - p=(char *)strtok(NULL,",")) { + for (p = strtok(p, ","); p != NULL; p = strtok(NULL, ",")) { for (tp = p + strlen(p) - 1; tp >= p && isspace(*tp); --tp) *tp = '\0'; if (ioctl(fd, I_PUSH, p) == -1) { log("push (%s) on %s failed: %s", p, device, strerror(errno)); - return(-1); - } + return (-1); + } } - return(0); + return (0); } /* @@ -230,27 +211,27 @@ hang_up_line(int fd) #ifdef DEBUG debug("in hang_up_line"); #endif - if (ioctl(fd,TCGETS,&termios) < 0) { - if (ioctl(fd,TCGETA,&termio) < 0) { - log("hang_up_line: TCGETA failed: %s", strerror(errno)); - return(-1); - } - termio.c_cflag &= ~CBAUD; - termio.c_cflag |= B0; + if (ioctl(fd, TCGETS, &termios) < 0) { + if (ioctl(fd, TCGETA, &termio) < 0) { + log("hang_up_line: TCGETA failed: %s", strerror(errno)); + return (-1); + } + termio.c_cflag &= ~CBAUD; + termio.c_cflag |= B0; - if (ioctl(fd,TCSETA,&termio) < 0) { - log("hang_up_line: TCSETA failed: %s", strerror(errno)); - return(-1); - } + if (ioctl(fd, TCSETA, &termio) < 0) { + log("hang_up_line: TCSETA failed: %s", strerror(errno)); + return (-1); + } } else { - cfsetospeed(&termios, B0); + (void) cfsetospeed(&termios, B0); - if (ioctl(fd,TCSETS,&termios) < 0) { - log("hang_up_line: TCSETS failed: %s", strerror(errno)); - return(-1); - } + if (ioctl(fd, TCSETS, &termios) < 0) { + log("hang_up_line: TCSETS failed: %s", strerror(errno)); + return (-1); + } } - return(0); + return (0); } /* @@ -258,35 +239,30 @@ hang_up_line(int fd) * - return 0 if successful, -1 if failed. */ int -initial_termio(fd,pmptr) -int fd; -struct pmtab *pmptr; +initial_termio(int fd, struct pmtab *pmptr) { int ret; struct Gdef *speedef; - struct Gdef *get_speed(); - extern int auto_termio(); speedef = get_speed(pmptr->p_ttylabel); if (speedef->g_autobaud & A_FLAG) { pmptr->p_ttyflags |= A_FLAG; if (auto_termio(fd) == -1) { - (void)close(fd); - return(-1); + (void) close(fd); + return (-1); } - } - else { + } else { if (pmptr->p_ttyflags & R_FLAG) - ret = set_termio(fd,speedef->g_iflags, - (char *)NULL, TRUE, (long)RAW); - else - ret = set_termio(fd,speedef->g_iflags, - (char *)NULL, TRUE, (long)CANON); + ret = set_termio(fd, speedef->g_iflags, + NULL, TRUE, (long)RAW); + else + ret = set_termio(fd, speedef->g_iflags, + NULL, TRUE, (long)CANON); if (ret == -1) { log("initial termio on (%s) failed", pmptr->p_device); - (void)close(fd); - return(-1); + (void) close(fd); + return (-1); } } - return(0); + return (0); } diff --git a/usr/src/cmd/ttymon/tmttydefs.c b/usr/src/cmd/ttymon/tmttydefs.c index 6118e08a39..b95ad29f6e 100644 --- a/usr/src/cmd/ttymon/tmttydefs.c +++ b/usr/src/cmd/ttymon/tmttydefs.c @@ -24,11 +24,7 @@ * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - - -#pragma ident "%Z%%M% %I% %E% SMI" - +/* All Rights Reserved */ #include <unistd.h> #include <stdlib.h> @@ -38,21 +34,15 @@ #include <sys/types.h> #include <sys/stat.h> #include <termio.h> -#include <sys/stermio.h> -#include <sys/termiox.h> +#include <sys/stermio.h> +#include <sys/termiox.h> #include "ttymon.h" #include "tmstruct.h" #include "tmextern.h" #include "stty.h" -static void insert_def(); -static void zero(); -int check_flags(); -void mkargv(); - -extern struct Gdef Gdef[]; -extern int Ndefs; -char *strsave(); +static void insert_def(struct Gdef *); +static void zero(char *, int); /* * read_ttydefs - read in the /etc/ttydefs and store in Gdef array @@ -60,30 +50,28 @@ char *strsave(); * - if check is TRUE, print out the entries */ void -read_ttydefs(id,check) -char *id; -int check; +read_ttydefs(const char *id, int check) { - FILE *fp; - static struct Gdef def; - register struct Gdef *gptr; - static char line[BUFSIZ]; - static char dbuf[BUFSIZ]; - register char *ptr; - int len; - int input,state,size,rawc,field; - char oldc; - static char d_id[MAXID+1], - d_nextid[MAXID+1], - d_autobaud[MAXID+1], - d_if[BUFSIZ], - d_ff[BUFSIZ]; - static char *states[] = { - "","tty label","Initial flags","Final flags","Autobaud","Next label" + FILE *fp; + static struct Gdef def; + struct Gdef *gptr; + static char line[BUFSIZ]; + static char dbuf[BUFSIZ]; + char *ptr; + int len; + int input, state, size, rawc, field; + char oldc; + static char d_id[MAXID+1], + d_nextid[MAXID+1], + d_autobaud[MAXID+1], + d_if[BUFSIZ], + d_ff[BUFSIZ]; + static char *states[] = { + "", "tty label", "Initial flags", "Final flags", "Autobaud", + "Next label" }; - extern char *getword(); - if ((fp = fopen(TTYDEFS,"r")) == NULL) { + if ((fp = fopen(TTYDEFS, "r")) == NULL) { log("can't open \"%s\".\n", TTYDEFS); return; } @@ -96,10 +84,12 @@ int check; /* Start searching for the line with the proper "id". */ input = ACTIVE; + field = FAILURE; do { line[0] = '\0'; - for (ptr= line,oldc = '\0'; ptr < &line[sizeof(line)-1] && - (rawc=getc(fp))!='\n' && rawc != EOF; ptr++,oldc=(char)rawc){ + for (ptr = line, oldc = '\0'; ptr < &line[sizeof (line) - 1] && + (rawc = getc(fp)) != '\n' && rawc != EOF; + ptr++, oldc = (char)rawc) { if ((rawc == '#') && (oldc != '\\')) break; *ptr = (char)rawc; @@ -108,31 +98,34 @@ int check; /* skip rest of the line */ if (rawc != EOF && rawc != '\n') { - if (check && rawc != '#') + if (check && rawc != '#') log("Entry too long."); - while ((rawc = getc(fp)) != EOF && rawc != '\n') + while ((rawc = getc(fp)) != EOF && rawc != '\n') ; } if (rawc == EOF) { - if (ptr == line) break; - else input = FINISHED; + if (ptr == line) + break; + else + input = FINISHED; } /* if empty line, skip */ - for (ptr=line; *ptr != '\0' && isspace(*ptr); ptr++) + for (ptr = line; *ptr != '\0' && isspace(*ptr); ptr++) ; - if (*ptr == '\0') continue; + if (*ptr == '\0') + continue; /* Now we have the complete line */ /* Initialize "def" and "gptr". */ gptr = &def; - zero((char *)gptr, sizeof(struct Gdef)); + zero((char *)gptr, sizeof (struct Gdef)); ptr = line; state = T_TTYLABEL; - (void)strncpy(d_id,getword(ptr,&size,0),MAXID); + (void) strncpy(d_id, getword(ptr, &size, 0), MAXID); gptr->g_id = d_id; ptr += size; if (*ptr != ':') { @@ -140,11 +133,11 @@ int check; state = FAILURE; } else { ptr++; /* Skip the ':' */ - state++ ; + state++; } /* If "id" != NULL, and it does not match, go to next entry */ - if ((id != NULL) && (strcmp(id,gptr->g_id) != 0)) + if ((id != NULL) && (strcmp(id, gptr->g_id) != 0)) continue; if (check) { @@ -157,37 +150,40 @@ int check; } - for (; state != FAILURE && state != SUCCESS;) { - switch(state) { + for (; state != FAILURE && state != SUCCESS; ) { + switch (state) { case T_IFLAGS: - (void)strncpy(d_if,getword(ptr,&size,1),BUFSIZ); + (void) strncpy(d_if, getword(ptr, &size, 1), + BUFSIZ); gptr->g_iflags = d_if; ptr += size; if ((*ptr != ':') || (check_flags(d_if) != 0)) { field = state; state = FAILURE; } else { - ptr++; - state++ ; + ptr++; + state++; } break; case T_FFLAGS: - (void)strncpy(d_ff,getword(ptr,&size,1),BUFSIZ); + (void) strncpy(d_ff, getword(ptr, &size, 1), + BUFSIZ); gptr->g_fflags = d_ff; ptr += size; if ((*ptr != ':') || (check_flags(d_ff) != 0)) { field = state; state = FAILURE; } else { - ptr++; - state++ ; + ptr++; + state++; } break; case T_AUTOBAUD: - (void)strncpy(d_autobaud,getword(ptr,&size,0),MAXID); + (void) strncpy(d_autobaud, + getword(ptr, &size, 0), MAXID); if (size > 1) { ptr += size; field = state; @@ -195,9 +191,9 @@ int check; break; } if (size == 1) { - if (*d_autobaud == 'A') + if (*d_autobaud == 'A') { gptr->g_autobaud |= A_FLAG; - else { + } else { ptr += size; field = state; state = FAILURE; @@ -210,18 +206,21 @@ int check; state = FAILURE; } else { ptr++; /* Skip the ':' */ - state++ ; + state++; } break; case T_NEXTLABEL: - (void)strncpy(d_nextid,getword(ptr,&size,0),MAXID); + (void) strncpy(d_nextid, + getword(ptr, &size, 0), MAXID); gptr->g_nextid = d_nextid; ptr += size; if (*ptr != '\0') { field = state; state = FAILURE; - } else state = SUCCESS; + } else { + state = SUCCESS; + } break; } /* end switch */ @@ -233,66 +232,64 @@ int check; log("ttylabel:\t%s", gptr->g_id); log("initial flags:\t%s", gptr->g_iflags); log("final flags:\t%s", gptr->g_fflags); - if (gptr->g_autobaud & A_FLAG) + if (gptr->g_autobaud & A_FLAG) log("autobaud:\tyes"); else log("autobaud:\tno"); log("nextlabel:\t%s", gptr->g_nextid); } - if (Ndefs < MAXDEFS) + if (Ndefs < MAXDEFS) { insert_def(gptr); - else { + } else { log("can't add more entries to ttydefs table, " - " Maximum entries = %d", MAXDEFS); - (void)fclose(fp); + " Maximum entries = %d", MAXDEFS); + (void) fclose(fp); return; } if (id != NULL) { return; } - } - else { + } else { *++ptr = '\0'; log("Parsing failure in the \"%s\" field\n" - "%s<--error detected here\n", states[field],line); + "%s<--error detected here\n", states[field], line); } } while (input == ACTIVE); - (void)fclose(fp); - return; + (void) fclose(fp); } /* * zero - zero out the buffer */ static void -zero(adr,size) -register char *adr; -register int size; +zero(char *adr, int size) { - if (adr != NULL) - while (size--) *adr++ = '\0'; + if (adr != NULL) { + while (size--) + *adr++ = '\0'; + } } /* * find_def(ttylabel) * - scan Gdef table for an entry with requested "ttylabel". - * - return a Gdef ptr if entry with "ttylabel" is found + * - return a Gdef ptr if entry with "ttylabel" is found * - return NULL if no entry with matching "ttylabel" */ struct Gdef * -find_def(ttylabel) -char *ttylabel; +find_def(char *ttylabel) { int i; struct Gdef *tp; + tp = &Gdef[0]; - for (i = 0; i < Ndefs; i++,tp++) { + for (i = 0; i < Ndefs; i++, tp++) { if (strcmp(ttylabel, tp->g_id) == 0) { - return(tp); + return (tp); } } - return(NULL); + return (NULL); } /* @@ -301,26 +298,24 @@ char *ttylabel; * - return 0 if no error. Otherwise return -1 */ int -check_flags(flags) -char *flags; +check_flags(char *flags) { - struct termio termio; - struct termios termios; - struct termiox termiox; - struct winsize winsize; + struct termio termio; + struct termios termios; + struct termiox termiox; + struct winsize winsize; int term; int cnt = 1; char *argvp[MAXARGS]; /* stty args */ static char *binstty = "/usr/bin/stty"; static char buf[BUFSIZ]; - extern char *sttyparse(); char *s_arg; /* this will point to invalid option */ /* put flags into buf, because strtok will break up buffer */ - (void)strcpy(buf,flags); + (void) strcpy(buf, flags); argvp[0] = binstty; /* just a place holder */ - mkargv(buf,&argvp[1],&cnt,MAXARGS-1); - argvp[cnt] = (char *)0; + mkargv(buf, &argvp[1], &cnt, MAXARGS - 1); + argvp[cnt] = NULL; /* * because we don't know what type of terminal we have now, @@ -328,23 +323,21 @@ char *flags; * are accepted */ term = ASYNC|TERMIOS|FLOW; - if ((s_arg = sttyparse(cnt, argvp, term, &termio, &termios, - &termiox, &winsize)) != NULL) { + if ((s_arg = sttyparse(cnt, argvp, term, &termio, &termios, + &termiox, &winsize)) != NULL) { log("invalid mode: %s", s_arg); - return(-1); + return (-1); } - return(0); + return (0); } /* * insert_def - insert one entry into Gdef table */ static void -insert_def(gptr) -struct Gdef *gptr; +insert_def(struct Gdef *gptr) { struct Gdef *tp; - extern struct Gdef *find_def(); if (find_def(gptr->g_id) != NULL) { log("Warning -- duplicate entry <%s>, ignored", gptr->g_id); @@ -357,7 +350,6 @@ struct Gdef *gptr; tp->g_autobaud = gptr->g_autobaud; tp->g_nextid = strsave(gptr->g_nextid); Ndefs++; - return; } /* @@ -365,31 +357,33 @@ struct Gdef *gptr; */ void -mkargv(string,args,cnt,maxargs) -char *string, **args; -int *cnt, maxargs; +mkargv(char *string, char **args, int *cnt, int maxargs) { - register char *ptrin,*ptrout; - register int i; + char *ptrin, *ptrout; + int i; int qsize; - extern char quoted(); - for (i=0; i < maxargs; i++) args[i] = (char *)NULL; - for (ptrin = ptrout = string,i=0; *ptrin != '\0' && i < maxargs; i++) { + for (i = 0; i < maxargs; i++) + args[i] = NULL; + + ptrin = ptrout = string; + for (i = 0; *ptrin != '\0' && i < maxargs; i++) { /* Skip excess white spaces between arguments. */ - while(*ptrin == ' ' || *ptrin == '\t') { + while (*ptrin == ' ' || *ptrin == '\t') { ptrin++; ptrout++; } /* Save the address of argument if there is something there. */ - if (*ptrin == '\0') break; - else args[i] = ptrout; + if (*ptrin == '\0') + break; + else + args[i] = ptrout; /* Span the argument itself. The '\' character causes quoting */ /* of the next character to take place (except for '\0'). */ while (*ptrin != '\0') { if (*ptrin == '\\') { - *ptrout++ = quoted(ptrin,&qsize); + *ptrout++ = quoted(ptrin, &qsize); ptrin += qsize; /* Is this the end of the argument? If so quit loop. */ @@ -412,20 +406,21 @@ int *cnt, maxargs; * dump_ttydefs - dump Gdef table to log file */ void -dump_ttydefs() +dump_ttydefs(void) { int i; struct Gdef *gptr; + gptr = &Gdef[0]; log("********** dumping ttydefs table **********"); log("Ndefs = %d", Ndefs); log(" "); - for (i = 0; i < Ndefs; i++,gptr++) { + for (i = 0; i < Ndefs; i++, gptr++) { log("----------------------------------------"); log("ttylabel:\t%s", gptr->g_id); log("initial flags:\t%s", gptr->g_iflags); log("final flags:\t%s", gptr->g_fflags); - if (gptr->g_autobaud & A_FLAG) + if (gptr->g_autobaud & A_FLAG) log("autobaud:\tyes"); else log("Autobaud:\tno"); @@ -433,7 +428,6 @@ dump_ttydefs() log(" "); } log("********** end dumping ttydefs table **********"); - return; } #endif @@ -443,24 +437,22 @@ dump_ttydefs() * and is modified that if malloc fails, it will exit */ char * -strsave(str) -register char *str; +strsave(char *str) { - register char *rval; + char *rval; if (str == NULL) { - if ((rval = (char *)malloc(1)) == NULL) { + if ((rval = malloc(1)) == NULL) { log("strsave: malloc failed"); exit(1); } *rval = '\0'; - } - else { - if ((rval = (char *)malloc(strlen(str) + 1)) == NULL) { + } else { + if ((rval = malloc(strlen(str) + 1)) == NULL) { log("strsave: malloc failed"); exit(1); } - (void)strcpy(rval, str); + (void) strcpy(rval, str); } - return(rval); + return (rval); } diff --git a/usr/src/cmd/ttymon/tmutil.c b/usr/src/cmd/ttymon/tmutil.c index 17bd2e0d1f..b16904cd0a 100644 --- a/usr/src/cmd/ttymon/tmutil.c +++ b/usr/src/cmd/ttymon/tmutil.c @@ -25,10 +25,7 @@ */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - - -#pragma ident "%Z%%M% %I% %E% SMI" +/* All Rights Reserved */ #include <unistd.h> #include <stdarg.h> @@ -47,7 +44,7 @@ #include "tmextern.h" #define NSTRPUSH 9 /* should agree with the tunable in */ - /* /etc/master.d/kernel */ + /* /etc/master.d/kernel */ /* * check_device - check to see if the device exists, @@ -61,28 +58,27 @@ check_device(char *device) if ((device == NULL) || (*device == '\0')) { log("error -- device field is missing"); - return(-1); + return (-1); } if (*device != '/') { log("error -- must specify full path name for \"%s\".", device); - return(-1); + return (-1); } if (access(device, 0) == 0) { - if (stat(device,&statbuf) < 0) { + if (stat(device, &statbuf) < 0) { log("stat(%s) failed: %s", device, strerror(errno)); - return(-1); + return (-1); } if ((statbuf.st_mode & S_IFMT) != S_IFCHR) { log("error -- \"%s\" not character special device", device); - return(-1); + return (-1); } - } - else { + } else { log("error -- device \"%s\" does not exist", device); - return(-1); + return (-1); } - return(0); + return (0); } /* @@ -99,33 +95,32 @@ check_cmd(char *cmd) if ((cmd == NULL) || (*cmd == '\0')) { log("error -- server command is missing"); - return(-1); + return (-1); } - (void)strcpy(tp,cmd); - (void)strtok(tp, " \t"); + (void) strcpy(tp, cmd); + (void) strtok(tp, " \t"); if (*tp != '/') { log("error -- must specify full path name for \"%s\".", tp); - return(-1); + return (-1); } if (access(tp, 0) == 0) { - if (stat(tp,&statbuf) < 0) { + if (stat(tp, &statbuf) < 0) { log("stat(%s) failed.", tp); - return(-1); + return (-1); } if (!(statbuf.st_mode & 0111)) { log("error -- \"%s\" not executable\n", tp); - return(-1); + return (-1); } if ((statbuf.st_mode & S_IFMT) != S_IFREG) { log("error -- \"%s\" not a regular file", tp); - return(-1); + return (-1); } - } - else { + } else { log("error -- \"%s\" does not exist", tp); - return(-1); + return (-1); } - return(0); + return (0); } /* @@ -137,26 +132,24 @@ check_cmd(char *cmd) * - return 0 if successful, -1 if failed. */ int -strcheck(sp, flag) -char *sp; /* string ptr */ -int flag; /* either NUM or ALNUM */ +strcheck(char *sp, int flag) { - register char *cp; + char *cp; + if (flag == NUM) { for (cp = sp; *cp; cp++) { if (!isdigit(*cp)) { - return(-1); + return (-1); } } - } - else { /* (flag == ALNUM) */ + } else { /* (flag == ALNUM) */ for (cp = sp; *cp; cp++) { if (!isalnum(*cp)) { - return(-1); + return (-1); } } } - return(0); + return (0); } /* @@ -164,8 +157,7 @@ int flag; /* either NUM or ALNUM */ * - return 0 if successful, -1 if failed */ int -vml(modules) -char *modules; +vml(char *modules) { char *modp, *svmodp; int i, fd; @@ -173,7 +165,7 @@ char *modules; struct str_list newlist; /* modules to be pushed */ if ((modules == NULL) || (*modules == '\0')) - return(0); + return (0); newlist.sl_modlist = newmods; newlist.sl_nmods = NSTRPUSH; @@ -182,19 +174,18 @@ char *modules; return (-1); }; svmodp = modp; - (void)strcpy(modp, modules); + (void) strcpy(modp, modules); /* * pull mod names out of comma-separated list */ - for ( i = 0, modp = strtok(modp, ","); - modp != NULL; i++, modp = strtok(NULL, ",") ) { - if ( i >= NSTRPUSH) { + for (i = 0, modp = strtok(modp, ","); + modp != NULL; i++, modp = strtok(NULL, ",")) { + if (i >= NSTRPUSH) { log("too many modules in <%s>", modules); i = -1; break; } - (void)strncpy(newlist.sl_modlist[i].l_name, - modp, FMNAMESZ); + (void) strncpy(newlist.sl_modlist[i].l_name, modp, FMNAMESZ); newlist.sl_modlist[i].l_name[FMNAMESZ] = '\0'; } free(svmodp); @@ -207,25 +198,26 @@ char *modules; */ if ((fd = open(USERDEV, O_RDWR)) == -1) { if (errno == EBUSY) { - log("Warning - can't validate module list, /dev/sad/user busy"); - return(0); + log("Warning - can't validate module list, " + "/dev/sad/user busy"); + return (0); } log("open /dev/sad/user failed: %s", strerror(errno)); - return(-1); + return (-1); } - if ( (i = ioctl(fd, SAD_VML, &newlist)) < 0 ) { + if ((i = ioctl(fd, SAD_VML, &newlist)) < 0) { log("Validate modules ioctl failed, modules = <%s>: %s", modules, strerror(errno)); - (void)close(fd); - return(-1); + (void) close(fd); + return (-1); } - if ( i != 0 ) { + if (i != 0) { log("Error - invalid STREAMS module list <%s>.", modules); - (void)close(fd); - return(-1); + (void) close(fd); + return (-1); } - (void)close(fd); - return(0); + (void) close(fd); + return (0); } /* @@ -233,8 +225,7 @@ char *modules; * - also put '\' in front of ':' */ void -copystr(s1,s2) -char *s1, *s2; +copystr(char *s1, char *s2) { while (*s2) { if (*s2 == ':') { diff --git a/usr/src/cmd/ttymon/tmutmp.c b/usr/src/cmd/ttymon/tmutmp.c index a59d9eec02..d4cfaf9c87 100644 --- a/usr/src/cmd/ttymon/tmutmp.c +++ b/usr/src/cmd/ttymon/tmutmp.c @@ -24,7 +24,7 @@ */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ +/* All Rights Reserved */ /* * University Copyright- Copyright (c) 1982, 1986, 1988 @@ -36,8 +36,6 @@ * contributors. */ -#pragma ident "%Z%%M% %I% %E% SMI" - #include <unistd.h> #include <stdlib.h> #include <stdio.h> @@ -52,16 +50,13 @@ #include "sac.h" #include "tmextern.h" -extern char *lastname(); - /* * account - create a utmpx record for service * */ int -account(line) -char *line; +account(char *line) { struct utmpx utmpx; /* prototype utmpx entry */ struct utmpx *up = &utmpx; /* and a pointer to it */ @@ -104,7 +99,8 @@ checkut_line(char *line) while ((u = getutxent()) != NULL) { if (u->ut_pid == ownpid) { if (u->ut_type == USER_PROCESS) { - strncpy(ttyn, u->ut_line, sizeof (u->ut_line)); + (void) strncpy(ttyn, u->ut_line, + sizeof (u->ut_line)); ttyn[sizeof (u->ut_line)] = '\0'; if (strcmp(buf, ttyn) == 0) { rvalue = 1; @@ -120,32 +116,30 @@ checkut_line(char *line) void -cleanut(pid, status) - pid_t pid; - int status; +cleanut(pid_t pid, int status) { pam_handle_t *pamh; struct utmpx *up; - struct utmpx ut; char user[33], ttyn[33], rhost[258]; setutxent(); - while (up = getutxent()) { + while ((up = getutxent())) { if (up->ut_pid == pid) { if (up->ut_type == DEAD_PROCESS) { /* Cleaned up elsewhere. */ break; } - strncpy(user, up->ut_user, sizeof (up->ut_user)); + (void) strncpy(user, up->ut_user, sizeof (up->ut_user)); user[sizeof (up->ut_user)] = '\0'; - strncpy(ttyn, up->ut_line, sizeof (up->ut_line)); + (void) strncpy(ttyn, up->ut_line, sizeof (up->ut_line)); ttyn[sizeof (up->ut_line)] = '\0'; - strncpy(rhost, up->ut_host, sizeof (up->ut_host)); + (void) strncpy(rhost, up->ut_host, + sizeof (up->ut_host)); rhost[sizeof (up->ut_host)] = '\0'; - if (pam_start("ttymon", user, NULL, &pamh) - == PAM_SUCCESS) { + if (pam_start("ttymon", user, NULL, &pamh) == + PAM_SUCCESS) { (void) pam_set_item(pamh, PAM_TTY, ttyn); (void) pam_set_item(pamh, PAM_RHOST, rhost); (void) pam_close_session(pamh, 0); @@ -180,8 +174,7 @@ cleanut(pid, status) * - and change it to LOGIN_PROCESS */ void -getty_account(line) -char *line; +getty_account(char *line) { pid_t ownpid; struct utmpx *u; @@ -193,9 +186,9 @@ char *line; if (u->ut_type == INIT_PROCESS && u->ut_pid == ownpid) { (void) strncpy(u->ut_line, lastname(line), - sizeof (u->ut_line)); + sizeof (u->ut_line)); (void) strncpy(u->ut_user, "LOGIN", - sizeof (u->ut_user)); + sizeof (u->ut_user)); u->ut_type = LOGIN_PROCESS; /* Write out the updated entry. */ diff --git a/usr/src/cmd/ttymon/ttyadm.c b/usr/src/cmd/ttymon/ttyadm.c index 9b1b7b9a0d..6d677f131a 100644 --- a/usr/src/cmd/ttymon/ttyadm.c +++ b/usr/src/cmd/ttymon/ttyadm.c @@ -24,11 +24,7 @@ * Use is subject to license terms. */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ - - -#pragma ident "%Z%%M% %I% %E% SMI" - +/* All Rights Reserved */ #include <stdio.h> #include <unistd.h> @@ -39,15 +35,16 @@ #include <sys/stat.h> #include <stdarg.h> #include "tmstruct.h" +#include "tmextern.h" #include "ttymon.h" /* - * ttyadm - format ttymon specific information and + * ttyadm - format ttymon specific information and * print it to stdout * - * Usage: ttyadm [options] -d device -s service -l ttylabel + * Usage: ttyadm [options] -d device -s service -l ttylabel * ttyadm -V - * + * * valid options are: * -c * -h @@ -62,12 +59,8 @@ * -i msg */ -static void usage(); -static int check_label(); - -extern int check_device(); -extern int check_cmd(); -extern int vml(); +static void usage(void); +static int check_label(char *); int main(int argc, char *argv[]) @@ -87,15 +80,10 @@ main(int argc, char *argv[]) int lflag = 0; /* -l seen */ int mflag = 0; /* -m seen */ - extern void copystr(); - extern char *optarg; - extern int optind; - extern int strcheck(); - if (argc == 1) usage(); - if ((ptr = ALLOC_PMTAB) == PNULL) { - (void)fprintf(stderr, "calloc failed\n"); + if ((ptr = ALLOC_PMTAB) == NULL) { + (void) fprintf(stderr, "calloc failed\n"); exit(1); } ptr->p_modules = ""; @@ -110,7 +98,7 @@ main(int argc, char *argv[]) case 'V': if ((argc > 2) || (optind < argc)) usage(); - (void)fprintf(stdout,"%d\n", PMTAB_VERS); + (void) fprintf(stdout, "%d\n", PMTAB_VERS); exit(0); break; /*NOTREACHED*/ case 'd': @@ -118,22 +106,22 @@ main(int argc, char *argv[]) dflag = 1; break; case 'c': - tf = strcat(tf,"c"); + tf = strcat(tf, "c"); break; case 'h': - tf = strcat(tf,"h"); + tf = strcat(tf, "h"); break; case 'b': - tf = strcat(tf,"b"); + tf = strcat(tf, "b"); break; case 'I': - tf = strcat(tf,"I"); + tf = strcat(tf, "I"); break; case 'r': - tf = strcat(tf,"r"); + tf = strcat(tf, "r"); count = optarg; - if (strcheck(optarg,NUM) != 0) { - (void)fprintf(stderr, + if (strcheck(optarg, NUM) != 0) { + (void) fprintf(stderr, "Invalid argument for \"-r\" -- positive number expected.\n"); usage(); } @@ -161,8 +149,8 @@ main(int argc, char *argv[]) break; case 't': timeout = optarg; - if (strcheck(optarg,NUM) != 0) { - (void)fprintf(stderr, + if (strcheck(optarg, NUM) != 0) { + (void) fprintf(stderr, "Invalid argument for \"-t\" -- positive number expected.\n"); usage(); } @@ -177,11 +165,11 @@ main(int argc, char *argv[]) break; case 'p': ptr->p_prompt = prompt; - copystr(ptr->p_prompt,optarg); + copystr(ptr->p_prompt, optarg); break; case 'i': ptr->p_dmsg = dmsg; - copystr(ptr->p_dmsg,optarg); + copystr(ptr->p_dmsg, optarg); break; case '?': usage(); @@ -204,11 +192,11 @@ main(int argc, char *argv[]) errflg++; if (errflg) exit(1); - (void)fprintf(stdout, "%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:", - ptr->p_device, ttyflags, count, ptr->p_server, - timeout, ptr->p_ttylabel, ptr->p_modules, - ptr->p_prompt, ptr->p_dmsg, ptr->p_termtype, - ptr->p_softcar); + (void) fprintf(stdout, "%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:%s:", + ptr->p_device, ttyflags, count, ptr->p_server, + timeout, ptr->p_ttylabel, ptr->p_modules, + ptr->p_prompt, ptr->p_dmsg, ptr->p_termtype, + ptr->p_softcar); return (0); } @@ -217,22 +205,23 @@ main(int argc, char *argv[]) */ static void -usage() +usage(void) { - (void)fprintf(stderr, "Usage:\tttyadm [ options ] -d device -s service -l ttylabel\n"); - (void)fprintf(stderr, "\tttyadm -V\n"); - (void)fprintf(stderr, "\n\tValid options are:\n"); - (void)fprintf(stderr, "\t-c\n"); - (void)fprintf(stderr, "\t-h\n"); - (void)fprintf(stderr, "\t-b\n"); - (void)fprintf(stderr, "\t-I\n"); - (void)fprintf(stderr, "\t-S y|n\n"); - (void)fprintf(stderr, "\t-T term\n"); - (void)fprintf(stderr, "\t-r count\n"); - (void)fprintf(stderr, "\t-t timeout\n"); - (void)fprintf(stderr, "\t-p prompt\n"); - (void)fprintf(stderr, "\t-m modules\n"); - (void)fprintf(stderr, "\t-i msg\n"); + (void) fprintf(stderr, + "Usage:\tttyadm [ options ] -d device -s service -l ttylabel\n"); + (void) fprintf(stderr, "\tttyadm -V\n"); + (void) fprintf(stderr, "\n\tValid options are:\n"); + (void) fprintf(stderr, "\t-c\n"); + (void) fprintf(stderr, "\t-h\n"); + (void) fprintf(stderr, "\t-b\n"); + (void) fprintf(stderr, "\t-I\n"); + (void) fprintf(stderr, "\t-S y|n\n"); + (void) fprintf(stderr, "\t-T term\n"); + (void) fprintf(stderr, "\t-r count\n"); + (void) fprintf(stderr, "\t-t timeout\n"); + (void) fprintf(stderr, "\t-p prompt\n"); + (void) fprintf(stderr, "\t-m modules\n"); + (void) fprintf(stderr, "\t-i msg\n"); exit(1); } @@ -242,28 +231,27 @@ usage() */ static int -check_label(ttylabel) -char *ttylabel; +check_label(char *ttylabel) { FILE *fp; - extern int find_label(); if ((ttylabel == NULL) || (*ttylabel == '\0')) { - (void)fprintf(stderr, "error -- ttylabel is missing"); - return(-1); + (void) fprintf(stderr, "error -- ttylabel is missing"); + return (-1); } if ((fp = fopen(TTYDEFS, "r")) == NULL) { - (void)fprintf(stderr, "error -- \"%s\" does not exist, can't verify ttylabel <%s>\n", TTYDEFS, ttylabel); - return(-1); + (void) fprintf(stderr, "error -- \"%s\" does not exist, " + "can't verify ttylabel <%s>\n", TTYDEFS, ttylabel); + return (-1); + } + if (find_label(fp, ttylabel)) { + (void) fclose(fp); + return (0); } - if (find_label(fp,ttylabel)) { - (void)fclose(fp); - return(0); - } - (void)fclose(fp); - (void)fprintf(stderr,"error -- can't find ttylabel <%s> in \"%s\"\n", - ttylabel, TTYDEFS); - return(-1); + (void) fclose(fp); + (void) fprintf(stderr, "error -- can't find ttylabel <%s> in \"%s\"\n", + ttylabel, TTYDEFS); + return (-1); } /* diff --git a/usr/src/cmd/ttymon/ttymon.c b/usr/src/cmd/ttymon/ttymon.c index b0555612d3..03ff520059 100644 --- a/usr/src/cmd/ttymon/ttymon.c +++ b/usr/src/cmd/ttymon/ttymon.c @@ -24,7 +24,7 @@ */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ +/* All Rights Reserved */ #include <stdio_ext.h> #include <stdlib.h> @@ -42,6 +42,7 @@ #include <grp.h> #include <unistd.h> #include <ulimit.h> +#include <libdevinfo.h> #include "sac.h" #include "ttymon.h" @@ -50,25 +51,17 @@ static int Initialized; -extern int Retry; -extern struct pollfd *Pollp; -static void initialize(); -static void open_all(); -static int set_poll(); -static int check_spawnlimit(); -static int mod_ttydefs(); +static void initialize(void); +static void open_all(void); +static int set_poll(struct pollfd *); +static int check_spawnlimit(struct pmtab *); +static int mod_ttydefs(void); -void open_device(); -void set_softcar(); - -extern int check_session(); -extern void sigalarm(); -extern void revokedevaccess(char *, uid_t, gid_t, mode_t); -/* can't include libdevinfo.h */ -extern int di_devperm_logout(const char *); +void open_device(struct pmtab *); +void set_softcar(struct pmtab *); /* - * ttymon - a port monitor under SAC + * ttymon - a port monitor under SAC * - monitor ports, set terminal modes, baud rate * and line discipline for the port * - invoke service on port if connection request received @@ -91,7 +84,6 @@ int main(int argc, char *argv[]) { int nfds; - extern char *lastname(); /* * Only the superuser should execute this command. @@ -149,19 +141,13 @@ main(int argc, char *argv[]) } static void -initialize() +initialize(void) { struct pmtab *tp; - register struct passwd *pwdp; - register struct group *gp; + struct passwd *pwdp; + struct group *gp; struct rlimit rlimit; - extern struct rlimit Rlimit; - extern uid_t Uucp_uid; - extern gid_t Tty_gid; -#ifdef DEBUG - extern opendebug(); -#endif Initialized = FALSE; /* * get_environ() must be called first, @@ -177,7 +163,7 @@ initialize() log("Starting state: %s", (State == PM_ENABLED) ? "enabled" : "disabled"); -#ifdef DEBUG +#ifdef DEBUG opendebug(FALSE); debug("***** ttymon in initialize *****"); log("debug mode is \t on"); @@ -214,7 +200,7 @@ initialize() /* * setup poll array - * - we allocate 10 extra pollfd so that + * - we allocate 10 extra pollfd so that * we do not have to re-malloc when there is * minor fluctuation in Nentries */ @@ -253,7 +239,8 @@ initialize() Retry = FALSE; for (tp = PMtab; tp; tp = tp->p_next) { if ((tp->p_status > 0) && (tp->p_fd == 0) && - (tp->p_pid == 0) && !(tp->p_ttyflags & I_FLAG) && + (tp->p_childpid == 0) && + !(tp->p_ttyflags & I_FLAG) && (!((State == PM_DISABLED) && ((tp->p_dmsg == NULL)||(*(tp->p_dmsg) == '\0'))))) { open_device(tp); @@ -265,14 +252,14 @@ initialize() Initialized = TRUE; } -static void free_defs(); +static void free_defs(void); /* * open_all - open devices in pmtab if the entry is * - valid, fd = 0, and pid = 0 */ static void -open_all() +open_all(void) { struct pmtab *tp; int check_modtime; @@ -286,7 +273,7 @@ open_all() for (tp = PMtab; tp; tp = tp->p_next) { if ((tp->p_status > 0) && (tp->p_fd == 0) && - (tp->p_pid == 0) && + (tp->p_childpid == 0) && !(tp->p_ttyflags & I_FLAG) && (!((State == PM_DISABLED) && ((tp->p_dmsg == NULL)||(*(tp->p_dmsg) == '\0'))))) { /* @@ -337,8 +324,7 @@ open_all() } void -set_softcar(pmptr) -struct pmtab *pmptr; +set_softcar(struct pmtab *pmptr) { int fd, val = 0; @@ -365,7 +351,7 @@ struct pmtab *pmptr; log("set soft-carrier (%s) failed: %s", pmptr->p_device, strerror(errno)); - close(fd); + (void) close(fd); } @@ -378,8 +364,7 @@ struct pmtab *pmptr; */ void -open_device(pmptr) -struct pmtab *pmptr; +open_device(struct pmtab *pmptr) { int fd, tmpfd; struct sigaction sigact; @@ -413,11 +398,12 @@ struct pmtab *pmptr; pmptr->p_status = UNACCESS; Nlocked++; if (Nlocked == 1) { - sigact.sa_flags = 0; - sigact.sa_handler = sigalarm; - (void) sigemptyset(&sigact.sa_mask); - (void) sigaction(SIGALRM, &sigact, NULL); - (void) alarm(ALARMTIME); + sigact.sa_flags = 0; + sigact.sa_handler = sigalarm; + (void) sigemptyset(&sigact.sa_mask); + (void) sigaction(SIGALRM, &sigact, + NULL); + (void) alarm(ALARMTIME); } } else Retry = TRUE; @@ -515,7 +501,7 @@ struct pmtab *pmptr; return; } - di_devperm_logout((const char *)pmptr->p_device); + (void) di_devperm_logout((const char *)pmptr->p_device); pmptr->p_fd = fd; } @@ -526,11 +512,10 @@ struct pmtab *pmptr; */ static int -set_poll(fdp) -struct pollfd *fdp; +set_poll(struct pollfd *fdp) { struct pmtab *tp; - int nfd = 0; + int nfd = 0; for (tp = PMtab; tp; tp = tp->p_next) { if (tp->p_fd > 0) { @@ -548,8 +533,7 @@ struct pollfd *fdp; * - otherwise return -1 */ static int -check_spawnlimit(pmptr) -struct pmtab *pmptr; +check_spawnlimit(struct pmtab *pmptr) { time_t now; @@ -575,10 +559,10 @@ struct pmtab *pmptr; * - otherwise, return FALSE */ static int -mod_ttydefs() +mod_ttydefs(void) { struct stat statbuf; - extern long Mtime; + if (stat(TTYDEFS, &statbuf) == -1) { /* if stat failed, don't bother reread ttydefs */ return (FALSE); @@ -594,7 +578,7 @@ mod_ttydefs() * free_defs - free the Gdef table */ static void -free_defs() +free_defs(void) { int i; struct Gdef *tp; @@ -623,8 +607,7 @@ free_defs() struct Gdef * get_speed(char *ttylabel) { - register struct Gdef *sp; - extern struct Gdef DEFAULT; + struct Gdef *sp; if ((ttylabel != NULL) && (*ttylabel != '\0')) { if ((sp = find_def(ttylabel)) == NULL) { @@ -644,7 +627,7 @@ get_speed(char *ttylabel) * to detect failure of ttymon */ void -setup_PCpipe() +setup_PCpipe(void) { int flag = 0; @@ -674,7 +657,7 @@ setup_PCpipe() if (ioctl(PCpipe[0], I_SETSIG, S_INPUT) == -1) fatal("I_SETSIG S_INPUT failed: %s", strerror(errno)); -#ifdef DEBUG +#ifdef DEBUG log("PCpipe[0]\t = %d", PCpipe[0]); log("PCpipe[1]\t = %d", PCpipe[1]); #endif diff --git a/usr/src/cmd/ttymon/ulockf.c b/usr/src/cmd/ttymon/ulockf.c index f4c916ab76..75b34fbf54 100644 --- a/usr/src/cmd/ttymon/ulockf.c +++ b/usr/src/cmd/ttymon/ulockf.c @@ -20,15 +20,12 @@ * CDDL HEADER END */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ +/* All Rights Reserved */ /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ - -#pragma ident "%Z%%M% %I% %E% SMI" - #include "uucp.h" #include <unistd.h> @@ -38,12 +35,8 @@ static struct stat _st_buf; static char lockname[BUFSIZ]; -#ifdef V7 -#define O_RDONLY 0 -#endif - -static void stlock(); -static int onelock(); +static void stlock(char *); +static int onelock(char *, char *, char *); /* * make a lock file with given 'name' @@ -59,8 +52,7 @@ static int onelock(); */ GLOBAL int -mklock(name) -register char *name; +mklock(char *name) { static char pid[SIZEOFPID+2] = { '\0' }; /* +2 for '\n' and NULL */ static char tempfile[MAXNAMESIZE]; @@ -70,32 +62,33 @@ register char *name; #endif if (pid[0] == '\0') { - (void) sprintf(pid, "%*ld\n", SIZEOFPID, (long) getpid()); - (void) sprintf(tempfile, "%s/LTMP.%ld", X_LOCKDIR, (long) getpid()); + (void) sprintf(pid, "%*ld\n", SIZEOFPID, (long)getpid()); + (void) sprintf(tempfile, "%s/LTMP.%ld", X_LOCKDIR, + (long)getpid()); } #ifdef V8 /* this wouldn't be a problem if we used lock directories */ /* some day the truncation of system names will bite us */ cp = rindex(name, '/'); if (cp++ != CNULL) - if (strlen(cp) > MAXBASENAME) - *(cp+MAXBASENAME) = NULLCHAR; + if (strlen(cp) > MAXBASENAME) + *(cp+MAXBASENAME) = NULLCHAR; #endif /* V8 */ if (onelock(pid, tempfile, name) == -1) { (void) unlink(tempfile); - if (cklock(name)) - return(FAIL); - else { - if (onelock(pid, tempfile, name)) { - (void) unlink(tempfile); - DEBUG(4,"ulockf failed in onelock()\n%s", ""); - return(FAIL); - } + if (cklock(name)) { + return (FAIL); + } else { + if (onelock(pid, tempfile, name)) { + (void) unlink(tempfile); + DEBUG(4, "ulockf failed in onelock()\n%s", ""); + return (FAIL); + } } } stlock(name); - return(0); + return (0); } /* @@ -107,10 +100,9 @@ register char *name; * FAIL -> lock file still active */ GLOBAL int -cklock(name) -register char *name; +cklock(char *name) { - register int ret; + int ret; pid_t lpid = -1; char alpid[SIZEOFPID+2]; /* +2 for '\n' and NULL */ int fd; @@ -118,38 +110,39 @@ register char *name; fd = open(name, O_RDONLY); DEBUG(4, "ulockf name %s\n", name); if (fd == -1) { - if (errno == ENOENT) /* file does not exist -- OK */ - return(0); - DEBUG(4,"Lock File--can't read (errno %d) --remove it!\n", errno); - goto unlk; + if (errno == ENOENT) /* file does not exist -- OK */ + return (0); + DEBUG(4, "Lock File--can't read (errno %d) --remove it!\n", + errno); + goto unlk; } - ret = read(fd, (char *) alpid, SIZEOFPID+1); /* +1 for '\n' */ + ret = read(fd, (char *)alpid, SIZEOFPID + 1); /* +1 for '\n' */ (void) close(fd); if (ret != (SIZEOFPID+1)) { - DEBUG(4, "Lock File--bad format--remove it!\n%s", ""); - goto unlk; - } - lpid = (pid_t) strtol(alpid, (char **) NULL, 10); - if ((ret=kill(lpid, 0)) == 0 || errno == EPERM) { - DEBUG(4, "Lock File--process still active--not removed\n%s", ""); - return(FAIL); + DEBUG(4, "Lock File--bad format--remove it!\n%s", ""); + goto unlk; } - else { /* process no longer active */ - DEBUG(4, "kill pid (%ld), ", (long) lpid); - DEBUG(4, "returned %d", ret); - DEBUG(4, "--ok to remove lock file (%s)\n", name); + lpid = (pid_t)strtol(alpid, NULL, 10); + if ((ret = kill(lpid, 0)) == 0 || errno == EPERM) { + DEBUG(4, "Lock File--process still active--not removed\n%s", + ""); + return (FAIL); + } else { /* process no longer active */ + DEBUG(4, "kill pid (%ld), ", (long)lpid); + DEBUG(4, "returned %d", ret); + DEBUG(4, "--ok to remove lock file (%s)\n", name); } unlk: if (unlink(name) != 0) { - DEBUG(4,"ulockf failed in unlink()\n%s", ""); - return(FAIL); + DEBUG(4, "ulockf failed in unlink()\n%s", ""); + return (FAIL); } - return(0); + return (0); } -#define MAXLOCKS 10 /* maximum number of lock files */ +#define MAXLOCKS 10 /* maximum number of lock files */ static char *Lockfile[MAXLOCKS]; GLOBAL int Nlocks = 0; @@ -159,10 +152,9 @@ GLOBAL int Nlocks = 0; * none */ static void -stlock(name) -char *name; +stlock(char *name) { - register int i; + int i; char *p; for (i = 0; i < Nlocks; i++) { @@ -172,11 +164,10 @@ char *name; ASSERT(i < MAXLOCKS, "TOO MANY LOCKS", "", i); if (i >= Nlocks) i = Nlocks++; - p = (char*) calloc((unsigned) strlen(name) + 1, sizeof (char)); + p = calloc((unsigned)strlen(name) + 1, sizeof (char)); ASSERT(p != NULL, "CAN NOT ALLOCATE FOR", name, 0); (void) strcpy(p, name); Lockfile[i] = p; - return; } /* @@ -186,17 +177,16 @@ char *name; * none */ GLOBAL void -rmlock(name) -register char *name; +rmlock(char *name) { - register int i; + int i; #ifdef V8 char *cp; cp = rindex(name, '/'); if (cp++ != CNULL) - if (strlen(cp) > MAXBASENAME) - *(cp+MAXBASENAME) = NULLCHAR; + if (strlen(cp) > MAXBASENAME) + *(cp+MAXBASENAME) = NULLCHAR; #endif /* V8 */ @@ -209,7 +199,6 @@ register char *name; Lockfile[i] = NULL; } } - return; } @@ -227,16 +216,13 @@ register char *name; * none */ GLOBAL void -delock(pre, s) -char * pre; -char *s; +delock(char *pre, char *s) { char ln[MAXNAMESIZE]; (void) sprintf(ln, "%s.%s", pre, s); BASENAME(ln, '/')[MAXBASENAME] = '\0'; rmlock(ln); - return; } @@ -254,19 +240,17 @@ char *s; * FAIL -> failure */ GLOBAL int -mlock(pre, name) -char * pre; -char *name; +mlock(char *pre, char *name) { char lname[MAXNAMESIZE]; /* * if name has a '/' in it, then it's a device name and it's * not in /dev (i.e., it's a remotely-mounted device or it's - * in a subdirectory of /dev). in either case, creating our normal + * in a subdirectory of /dev). in either case, creating our normal * lockfile (/var/spool/locks/LCK..<dev>) is going to bomb if - * <dev> is "/remote/dev/term/14" or "/dev/net/foo/clone", so never - * mind. since we're using advisory filelocks on the devices + * <dev> is "/remote/dev/term/14" or "/dev/net/foo/clone", so never + * mind. since we're using advisory filelocks on the devices * themselves, it'll be safe. * * of course, programs and people who are used to looking at the @@ -275,11 +259,11 @@ char *name; * to accomodate devices in directories other than /dev ... maybe in * the next release. */ - if ( strchr(name, '/') != NULL ) - return(0); + if (strchr(name, '/') != NULL) + return (0); (void) sprintf(lname, "%s.%s", pre, BASENAME(name, '/')); BASENAME(lname, '/')[MAXBASENAME] = '\0'; - return(mklock(lname)); + return (mklock(lname)); } /* @@ -293,46 +277,44 @@ char *name; * 0 - lock made successfully */ static int -onelock(pid,tempfile,name) -char *pid; -char *tempfile, *name; -{ - register int fd; +onelock(char *pid, char *tempfile, char *name) +{ + int fd; char cb[100]; - fd=creat(tempfile, (mode_t) 0444); - if(fd < 0){ - (void) sprintf(cb, "%s %s %d",tempfile, name, errno); + fd = creat(tempfile, (mode_t)0444); + if (fd < 0) { + (void) sprintf(cb, "%s %s %d", tempfile, name, errno); logent("ULOCKC", cb); - if((errno == EMFILE) || (errno == ENFILE)) + if ((errno == EMFILE) || (errno == ENFILE)) (void) unlink(tempfile); - return(-1); + return (-1); } /* +1 for '\n' */ - if (write(fd, pid, SIZEOFPID+1) != (SIZEOFPID+1)) { - (void) sprintf(cb, "%s %s %d",tempfile, name, errno); + if (write(fd, pid, SIZEOFPID + 1) != (SIZEOFPID + 1)) { + (void) sprintf(cb, "%s %s %d", tempfile, name, errno); logent("ULOCKW", cb); (void) unlink(tempfile); return (-1); } - (void) chmod(tempfile, (mode_t) 0444); + (void) chmod(tempfile, (mode_t)0444); (void) chown(tempfile, UUCPUID, UUCPGID); (void) close(fd); - if(link(tempfile,name)<0){ + if (link(tempfile, name) < 0) { DEBUG(4, "%s: ", strerror(errno)); DEBUG(4, "link(%s, ", tempfile); DEBUG(4, "%s)\n", name); - if(unlink(tempfile)< 0){ + if (unlink(tempfile) < 0) { (void) sprintf(cb, "ULK err %s %d", tempfile, errno); logent("ULOCKLNK", cb); } - return(-1); + return (-1); } - if(unlink(tempfile)<0){ - (void) sprintf(cb, "%s %d",tempfile,errno); + if (unlink(tempfile) < 0) { + (void) sprintf(cb, "%s %d", tempfile, errno); logent("ULOCKF", cb); } - return(0); + return (0); } /* @@ -344,33 +326,32 @@ char *tempfile, *name; */ GLOBAL int -fd_mklock(fd) -int fd; +fd_mklock(int fd) { - int tries = 0; + int tries = 0; - if ( fstat(fd, &_st_buf) != 0 ) - return(FAIL); + if (fstat(fd, &_st_buf) != 0) + return (FAIL); - (void) sprintf(lockname, "%s.%3.3lu.%3.3lu.%3.3lu", L_LOCK, - (unsigned long) major(_st_buf.st_dev), - (unsigned long) major(_st_buf.st_rdev), - (unsigned long) minor(_st_buf.st_rdev)); + (void) sprintf(lockname, "%s.%3.3lu.%3.3lu.%3.3lu", L_LOCK, + (unsigned long) major(_st_buf.st_dev), + (unsigned long) major(_st_buf.st_rdev), + (unsigned long) minor(_st_buf.st_rdev)); - if ( mklock(lockname) == FAIL ) - return(FAIL); + if (mklock(lockname) == FAIL) + return (FAIL); - while ( lockf(fd, F_TLOCK, 0L) != 0 ) { - DEBUG(7, "fd_mklock: lockf returns %d\n", errno); - if ( (++tries >= MAX_LOCKTRY) || (errno != EAGAIN) ) { - rmlock(lockname); - logent("fd_mklock","lockf failed"); - return(FAIL); + while (lockf(fd, F_TLOCK, 0L) != 0) { + DEBUG(7, "fd_mklock: lockf returns %d\n", errno); + if ((++tries >= MAX_LOCKTRY) || (errno != EAGAIN)) { + rmlock(lockname); + logent("fd_mklock", "lockf failed"); + return (FAIL); + } + (void) sleep(2); } - (void)sleep(2); - } - DEBUG(7, "fd_mklock: ok\n%s", ""); - return(SUCCESS); + DEBUG(7, "fd_mklock: ok\n%s", ""); + return (SUCCESS); } /* @@ -382,21 +363,20 @@ int fd; */ GLOBAL int -fn_cklock(name) -char *name; +fn_cklock(char *name) { - /* we temporarily use lockname to hold full path name */ - (void) sprintf(lockname, "%s%s", (*name == '/' ? "" : "/dev/"), name); + /* we temporarily use lockname to hold full path name */ + (void) sprintf(lockname, "%s%s", (*name == '/' ? "" : "/dev/"), name); - if ( stat(lockname, &_st_buf) != 0 ) - return(FAIL); + if (stat(lockname, &_st_buf) != 0) + return (FAIL); - (void) sprintf(lockname, "%s.%3.3lu.%3.3lu.%3.3lu", L_LOCK, - (unsigned long) major(_st_buf.st_dev), - (unsigned long) major(_st_buf.st_rdev), - (unsigned long) minor(_st_buf.st_rdev)); + (void) sprintf(lockname, "%s.%3.3lu.%3.3lu.%3.3lu", L_LOCK, + (unsigned long) major(_st_buf.st_dev), + (unsigned long) major(_st_buf.st_rdev), + (unsigned long) minor(_st_buf.st_rdev)); - return(cklock(lockname)); + return (cklock(lockname)); } /* @@ -408,21 +388,20 @@ char *name; */ GLOBAL int -fd_cklock(fd) -int fd; +fd_cklock(int fd) { - if ( fstat(fd, &_st_buf) != 0 ) - return(FAIL); - - (void) sprintf(lockname, "%s.%3.3lu.%3.3lu.%3.3lu", L_LOCK, - (unsigned long) major(_st_buf.st_dev), - (unsigned long) major(_st_buf.st_rdev), - (unsigned long) minor(_st_buf.st_rdev)); - - if ( cklock(lockname) == FAIL ) - return(FAIL); - else - return( lockf(fd, F_TEST, 0L) ); + if (fstat(fd, &_st_buf) != 0) + return (FAIL); + + (void) sprintf(lockname, "%s.%3.3lu.%3.3lu.%3.3lu", L_LOCK, + (unsigned long) major(_st_buf.st_dev), + (unsigned long) major(_st_buf.st_rdev), + (unsigned long) minor(_st_buf.st_rdev)); + + if (cklock(lockname) == FAIL) + return (FAIL); + else + return (lockf(fd, F_TEST, 0L)); } /* @@ -430,20 +409,18 @@ int fd; * * return - * SUCCESS - both BNU lock file and advisory locks removed - * FAIL - + * FAIL - */ GLOBAL void -fd_rmlock(fd) -int fd; +fd_rmlock(int fd) { - if ( fstat(fd, &_st_buf) == 0 ) { - (void) sprintf(lockname, "%s.%3.3lu.%3.3lu.%3.3lu", L_LOCK, - (unsigned long) major(_st_buf.st_dev), - (unsigned long) major(_st_buf.st_rdev), - (unsigned long) minor(_st_buf.st_rdev)); - rmlock(lockname); - } - (void) lockf(fd, F_ULOCK, 0L); - return; + if (fstat(fd, &_st_buf) == 0) { + (void) sprintf(lockname, "%s.%3.3lu.%3.3lu.%3.3lu", L_LOCK, + (unsigned long) major(_st_buf.st_dev), + (unsigned long) major(_st_buf.st_rdev), + (unsigned long) minor(_st_buf.st_rdev)); + rmlock(lockname); + } + (void) lockf(fd, F_ULOCK, 0L); } diff --git a/usr/src/cmd/ttymon/uucp.h b/usr/src/cmd/ttymon/uucp.h index b05bbdc6a0..8cfbc00ee2 100644 --- a/usr/src/cmd/ttymon/uucp.h +++ b/usr/src/cmd/ttymon/uucp.h @@ -20,7 +20,7 @@ * CDDL HEADER END */ /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ -/* All Rights Reserved */ +/* All Rights Reserved */ /* * Copyright 2005 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. @@ -28,9 +28,7 @@ #ifndef _UUCP_H -#define _UUCP_H - -#pragma ident "%Z%%M% %I% %E% SMI" +#define _UUCP_H #ifdef __cplusplus extern "C" { @@ -42,15 +40,15 @@ extern "C" { #include "parms.h" #ifdef DIAL -#define EXTERN static -#define GLOBAL static +#define EXTERN static +#define GLOBAL static #else -#define EXTERN extern -#define GLOBAL +#define EXTERN extern +#define GLOBAL #endif #ifdef BSD4_2 -#define V7 +#define V7 #undef NONAP #undef FASTTIMER #endif /* BSD4_2 */ @@ -60,7 +58,7 @@ extern "C" { #endif #ifdef V8 -#define V7 +#define V7 #endif /* V8 */ #include <stdio.h> @@ -107,35 +105,36 @@ extern "C" { /* what mode should user files be allowed to have upon creation? */ /* NOTE: This does not allow setuid or execute bits on transfer. */ -#define LEGALMODE (mode_t) 0666 +#define LEGALMODE (mode_t)0666 /* what mode should public files have upon creation? */ -#define PUB_FILEMODE (mode_t) 0666 +#define PUB_FILEMODE (mode_t)0666 /* what mode should log files have upon creation? */ -#define LOGFILEMODE (mode_t) 0644 +#define LOGFILEMODE (mode_t)0644 /* what mode should C. files have upon creation? */ -#define CFILEMODE (mode_t) 0644 +#define CFILEMODE (mode_t)0644 /* what mode should D. files have upon creation? */ -#define DFILEMODE (mode_t) 0600 +#define DFILEMODE (mode_t)0600 /* define the value of PUBMASK, used for creating "public" directories */ -#define PUBMASK (mode_t) 0000 +#define PUBMASK (mode_t)0000 /* what mode should public directories have upon creation? */ -#define PUB_DIRMODE (mode_t) 0777 +#define PUB_DIRMODE (mode_t)0777 /* define the value of DIRMASK, used for creating "system" subdirectories */ -#define DIRMASK (mode_t) 0022 +#define DIRMASK (mode_t)0022 -#define MAXSTART 300 /* how long to wait on startup */ +#define MAXSTART 300 /* how long to wait on startup */ /* define the last characters for ACU (used for 801/212 dialers) */ -#define ACULAST "<" +#define ACULAST "<" -/* caution - the fillowing names are also in Makefile +/* + * caution - the following names are also in Makefile * any changes here have to also be made there * * it's a good idea to make directories .foo, since this ensures @@ -146,129 +145,131 @@ extern "C" { * LOGDIR=/var/uucp/.Log * SEQDIR=/var/uucp/.Sequence * STATDIR=/var/uucp/.Status - * + * */ /* where to put the STST. files? */ -#define STATDIR "/var/uucp/.Status" +#define STATDIR "/var/uucp/.Status" /* where should logfiles be kept? */ -#define LOGUUX "/var/uucp/.Log/uux" -#define LOGUUXQT "/var/uucp/.Log/uuxqt" -#define LOGUUCP "/var/uucp/.Log/uucp" -#define LOGCICO "/var/uucp/.Log/uucico" -#define CORRUPTDIR "/var/uucp/.Corrupt" +#define LOGUUX "/var/uucp/.Log/uux" +#define LOGUUXQT "/var/uucp/.Log/uuxqt" +#define LOGUUCP "/var/uucp/.Log/uucp" +#define LOGCICO "/var/uucp/.Log/uucico" +#define CORRUPTDIR "/var/uucp/.Corrupt" /* some sites use /var/uucp/.XQTDIR here */ /* use caution since things are linked into there */ -#define XQTDIR "/var/uucp/.Xqtdir" +#define XQTDIR "/var/uucp/.Xqtdir" /* how much of a system name can we print in a [CX]. file? */ /* MAXBASENAME - 1 (pre) - 1 ('.') - 1 (grade) - 4 (sequence number) */ -#define SYSNSIZE (MAXBASENAME - 7) +#define SYSNSIZE (MAXBASENAME - 7) #ifdef USRSPOOLLOCKS -#define LOCKPRE "/var/spool/locks/LCK." +#define LOCKPRE "/var/spool/locks/LCK." #else -#define LOCKPRE "/var/spool/uucp/LCK." +#define LOCKPRE "/var/spool/uucp/LCK." #endif /* USRSPOOLLOCKS */ -#define SQFILE "/etc/uucp/SQFILE" -#define SQTMP "/etc/uucp/SQTMP" -#define SLCKTIME 5400 /* system/device timeout (LCK.. files) */ -#define DIALCODES "/etc/uucp/Dialcodes" -#define PERMISSIONS "/etc/uucp/Permissions" +#define SQFILE "/etc/uucp/SQFILE" +#define SQTMP "/etc/uucp/SQTMP" +#define SLCKTIME 5400 /* system/device timeout (LCK.. files) */ +#define DIALCODES "/etc/uucp/Dialcodes" +#define PERMISSIONS "/etc/uucp/Permissions" -#define SPOOL "/var/spool/uucp" -#define SEQDIR "/var/uucp/.Sequence" +#define SPOOL "/var/spool/uucp" +#define SEQDIR "/var/uucp/.Sequence" -#define X_LOCKTIME 3600 +#define X_LOCKTIME 3600 #ifdef USRSPOOLLOCKS -#define SEQLOCK "/var/spool/locks/LCK.SQ." -#define SQLOCK "/var/spool/locks/LCK.SQ" -#define X_LOCK "/var/spool/locks/LCK.X" -#define S_LOCK "/var/spool/locks/LCK.S" -#define L_LOCK "/var/spool/locks/LK" -#define X_LOCKDIR "/var/spool/locks" /* must be dir part of above */ +#define SEQLOCK "/var/spool/locks/LCK.SQ." +#define SQLOCK "/var/spool/locks/LCK.SQ" +#define X_LOCK "/var/spool/locks/LCK.X" +#define S_LOCK "/var/spool/locks/LCK.S" +#define L_LOCK "/var/spool/locks/LK" +#define X_LOCKDIR "/var/spool/locks" /* must be dir part of above */ #else -#define SEQLOCK "/var/spool/uucp/LCK.SQ." -#define SQLOCK "/var/spool/uucp/LCK.SQ" -#define X_LOCK "/var/spool/uucp/LCK.X" -#define S_LOCK "/var/spool/uucp/LCK.S" -#define L_LOCK "/var/spool/uucp/LK" -#define X_LOCKDIR "/var/spool/uucp" /* must be dir part of above */ +#define SEQLOCK "/var/spool/uucp/LCK.SQ." +#define SQLOCK "/var/spool/uucp/LCK.SQ" +#define X_LOCK "/var/spool/uucp/LCK.X" +#define S_LOCK "/var/spool/uucp/LCK.S" +#define L_LOCK "/var/spool/uucp/LK" +#define X_LOCKDIR "/var/spool/uucp" /* must be dir part of above */ #endif /* USRSPOOLLOCKS */ -#define X_LOCKPRE "LCK.X" /* must be last part of above */ - -#define PUBDIR "/var/spool/uucppublic" -#define ADMIN "/var/uucp/.Admin" -#define ERRLOG "/var/uucp/.Admin/errors" -#define SYSLOG "/var/uucp/.Admin/xferstats" -#define RMTDEBUG "/var/uucp/.Admin/audit" -#define CLEANUPLOGFILE "/var/uucp/.Admin/uucleanup" -#define CMDLOG "/var/uucp/.Admin/command" -#define PERFLOG "/var/uucp/.Admin/perflog" -#define ACCOUNT "/var/uucp/.Admin/account" -#define SECURITY "/var/uucp/.Admin/security" +#define X_LOCKPRE "LCK.X" /* must be last part of above */ + +#define PUBDIR "/var/spool/uucppublic" +#define ADMIN "/var/uucp/.Admin" +#define ERRLOG "/var/uucp/.Admin/errors" +#define SYSLOG "/var/uucp/.Admin/xferstats" +#define RMTDEBUG "/var/uucp/.Admin/audit" +#define CLEANUPLOGFILE "/var/uucp/.Admin/uucleanup" +#define CMDLOG "/var/uucp/.Admin/command" +#define PERFLOG "/var/uucp/.Admin/perflog" +#define ACCOUNT "/var/uucp/.Admin/account" +#define SECURITY "/var/uucp/.Admin/security" #define WORKSPACE "/var/uucp/.Workspace" -#define SQTIME 60 -#define TRYCALLS 2 /* number of tries to dial call */ -#define MINULIMIT (1L<<11) /* minimum reasonable ulimit */ +#define SQTIME 60 +#define TRYCALLS 2 /* number of tries to dial call */ +#define MINULIMIT (1L<<11) /* minimum reasonable ulimit */ #define MAX_LOCKTRY 5 /* number of attempts to lock device */ /* - * CDEBUG is for communication line debugging - * DEBUG is for program debugging + * CDEBUG is for communication line debugging + * DEBUG is for program debugging * #define SMALL to compile without the DEBUG code */ #ifndef DIAL -#define CDEBUG(l, f, s) if (Debug >= l) (void)fprintf(stderr, f, s) +#define CDEBUG(l, f, s) if (Debug >= l) (void)fprintf(stderr, f, s) #else -#define CDEBUG(l, f, s) -#define SMALL +#define CDEBUG(l, f, s) +#define SMALL #endif #ifndef SMALL -#define DEBUG(l, f, s) if (Debug >= l) (void)fprintf(stderr, f, s) +#define DEBUG(l, f, s) if (Debug >= l) (void)fprintf(stderr, f, s) #else -#define DEBUG(l, f, s) +#define DEBUG(l, f, s) #endif /* SMALL */ /* * VERBOSE is used by cu and ct to inform the user of progress * In other programs, the Value of Verbose is always 0. */ -#define VERBOSE(f, s) { if (Verbose > 0) (void)fprintf(stderr, f, s); } - -#define PREFIX(pre, str) (strncmp((pre), (str), strlen(pre)) == SAME) -#define BASENAME(str, c) ((Bnptr = strrchr((str), c)) ? (Bnptr + 1) : (str)) -#define EQUALS(a,b) ((a != CNULL) && (b != CNULL) && (strcmp((a),(b))==SAME)) -#define EQUALSN(a,b,n) ((a != CNULL) && (b != CNULL) && (strncmp((a),(b),(n))==SAME)) -#define LASTCHAR(s) (s+strlen(s)-1) - -#define SAME 0 -#define ANYREAD 04 -#define ANYWRITE 02 -#define FAIL -1 -#define SUCCESS 0 -#define NULLCHAR '\0' -#define CNULL (char *) 0 -#define STBNULL (struct sgttyb *) 0 -#define MASTER 1 -#define SLAVE 0 -#define MAXBASENAME 14 /* should be DIRSIZ but that is now fs dependent */ -#define MAXFULLNAME BUFSIZ -#define MAXNAMESIZE 64 /* /var/spool/uucp/<14 chars>/<14 chars>+slop */ -#define CONNECTTIME 30 -#define EXPECTTIME 45 -#define MSGTIME 60 -#define NAMESIZE MAXBASENAME+1 +#define VERBOSE(f, s) { if (Verbose > 0) (void)fprintf(stderr, f, s); } + +#define PREFIX(pre, str) (strncmp((pre), (str), strlen(pre)) == SAME) +#define BASENAME(str, c) ((Bnptr = strrchr((str), c)) ? (Bnptr + 1) : (str)) +#define EQUALS(a, b) \ + ((a != CNULL) && (b != CNULL) && (strcmp((a), (b)) == SAME)) +#define EQUALSN(a, b, n) \ + ((a != CNULL) && (b != CNULL) && (strncmp((a), (b), (n)) == SAME)) +#define LASTCHAR(s) (s + strlen(s) - 1) + +#define SAME 0 +#define ANYREAD 04 +#define ANYWRITE 02 +#define FAIL -1 +#define SUCCESS 0 +#define NULLCHAR '\0' +#define CNULL NULL +#define STBNULL NULL +#define MASTER 1 +#define SLAVE 0 +#define MAXBASENAME 14 /* should be DIRSIZ but that is now fs dependent */ +#define MAXFULLNAME BUFSIZ +#define MAXNAMESIZE 64 /* /var/spool/uucp/<14 chars>/<14 chars>+slop */ +#define CONNECTTIME 30 +#define EXPECTTIME 45 +#define MSGTIME 60 +#define NAMESIZE MAXBASENAME+1 #define SIZEOFPID 10 /* maximum number of digits in a pid */ -#define EOTMSG "\004\n\004\n" -#define CALLBACK 1 +#define EOTMSG "\004\n\004\n" +#define CALLBACK 1 /* manifests for sysfiles.c's sysaccess() */ /* check file access for REAL user id */ @@ -281,51 +282,51 @@ extern "C" { #define EACCESS_DIALERS 6 /* manifest for chkpth flag */ -#define CK_READ 0 -#define CK_WRITE 1 +#define CK_READ 0 +#define CK_WRITE 1 /* * commands */ -#define SHELL "/usr/bin/sh" -#define MAIL "mail" -#define UUCICO "/usr/lib/uucp/uucico" -#define UUXQT "/usr/lib/uucp/uuxqt" -#define UUX "/usr/bin/uux" -#define UUCP "/usr/bin/uucp" +#define SHELL "/usr/bin/sh" +#define MAIL "mail" +#define UUCICO "/usr/lib/uucp/uucico" +#define UUXQT "/usr/lib/uucp/uuxqt" +#define UUX "/usr/bin/uux" +#define UUCP "/usr/bin/uucp" /* system status stuff */ -#define SS_OK 0 -#define SS_NO_DEVICE 1 -#define SS_TIME_WRONG 2 -#define SS_INPROGRESS 3 -#define SS_CONVERSATION 4 -#define SS_SEQBAD 5 -#define SS_LOGIN_FAILED 6 -#define SS_DIAL_FAILED 7 -#define SS_BAD_LOG_MCH 8 -#define SS_LOCKED_DEVICE 9 -#define SS_ASSERT_ERROR 10 -#define SS_BADSYSTEM 11 -#define SS_CANT_ACCESS_DEVICE 12 -#define SS_DEVICE_FAILED 13 /* used for interface failure */ -#define SS_WRONG_MCH 14 -#define SS_CALLBACK 15 -#define SS_RLOCKED 16 -#define SS_RUNKNOWN 17 -#define SS_RLOGIN 18 -#define SS_UNKNOWN_RESPONSE 19 -#define SS_STARTUP 20 -#define SS_CHAT_FAILED 21 -#define SS_CALLBACK_LOOP 22 - -#define MAXPH 60 /* maximum phone string size */ +#define SS_OK 0 +#define SS_NO_DEVICE 1 +#define SS_TIME_WRONG 2 +#define SS_INPROGRESS 3 +#define SS_CONVERSATION 4 +#define SS_SEQBAD 5 +#define SS_LOGIN_FAILED 6 +#define SS_DIAL_FAILED 7 +#define SS_BAD_LOG_MCH 8 +#define SS_LOCKED_DEVICE 9 +#define SS_ASSERT_ERROR 10 +#define SS_BADSYSTEM 11 +#define SS_CANT_ACCESS_DEVICE 12 +#define SS_DEVICE_FAILED 13 /* used for interface failure */ +#define SS_WRONG_MCH 14 +#define SS_CALLBACK 15 +#define SS_RLOCKED 16 +#define SS_RUNKNOWN 17 +#define SS_RLOGIN 18 +#define SS_UNKNOWN_RESPONSE 19 +#define SS_STARTUP 20 +#define SS_CHAT_FAILED 21 +#define SS_CALLBACK_LOOP 22 + +#define MAXPH 60 /* maximum phone string size */ #define MAXC BUFSIZ #define TRUE 1 #define FALSE 0 -#define NAMEBUF 32 +#define NAMEBUF 32 /* The call structure is used by ct.c, cu.c, and dial.c. */ @@ -337,52 +338,52 @@ struct call { }; /* structure of an Systems file line */ -#define F_MAX 50 /* max number of fields in Systems file line */ -#define F_NAME 0 -#define F_TIME 1 -#define F_TYPE 2 -#define F_CLASS 3 /* an optional prefix and the speed */ -#define F_PHONE 4 -#define F_LOGIN 5 +#define F_MAX 50 /* max number of fields in Systems file line */ +#define F_NAME 0 +#define F_TIME 1 +#define F_TYPE 2 +#define F_CLASS 3 /* an optional prefix and the speed */ +#define F_PHONE 4 +#define F_LOGIN 5 /* structure of an Devices file line */ -#define D_TYPE 0 -#define D_LINE 1 -#define D_CALLDEV 2 -#define D_CLASS 3 -#define D_CALLER 4 -#define D_ARG 5 -#define D_MAX 50 /* max number of fields in Devices file line */ +#define D_TYPE 0 +#define D_LINE 1 +#define D_CALLDEV 2 +#define D_CLASS 3 +#define D_CALLER 4 +#define D_ARG 5 +#define D_MAX 50 /* max number of fields in Devices file line */ -#define D_ACU 1 -#define D_DIRECT 2 -#define D_PROT 4 +#define D_ACU 1 +#define D_DIRECT 2 +#define D_PROT 4 -#define GRADES "/etc/uucp/Grades" +#define GRADES "/etc/uucp/Grades" #define D_QUEUE 'Z' /* default queue */ /* past here, local changes are not recommended */ -#define CMDPRE 'C' -#define DATAPRE 'D' -#define XQTPRE 'X' +#define CMDPRE 'C' +#define DATAPRE 'D' +#define XQTPRE 'X' /* * stuff for command execution */ -#define X_RQDFILE 'F' -#define X_STDIN 'I' -#define X_STDOUT 'O' -#define X_STDERR 'E' -#define X_CMD 'C' -#define X_USER 'U' -#define X_BRINGBACK 'B' -#define X_MAILF 'M' -#define X_RETADDR 'R' -#define X_COMMENT '#' -#define X_NONZERO 'Z' -#define X_SENDNOTHING 'N' -#define X_SENDZERO 'n' +#define X_RQDFILE 'F' +#define X_STDIN 'I' +#define X_STDOUT 'O' +#define X_STDERR 'E' +#define X_CMD 'C' +#define X_USER 'U' +#define X_BRINGBACK 'B' +#define X_MAILF 'M' +#define X_RETADDR 'R' +#define X_COMMENT '#' +#define X_NONZERO 'Z' +#define X_SENDNOTHING 'N' +#define X_SENDZERO 'n' /* This structure describes call routines */ @@ -415,15 +416,15 @@ struct nstat { time_t t_tacu; /* acu time */ time_t t_tlog; /* login time */ time_t t_sftp; /* start file transfer protocol */ - time_t t_sxf; /* start xfer */ - time_t t_exf; /* end xfer */ + time_t t_sxf; /* start xfer */ + time_t t_exf; /* end xfer */ time_t t_eftp; /* end file transfer protocol */ time_t t_qtime; /* time file queued */ int t_ndial; /* # of dials */ int t_nlogs; /* # of login trys */ struct tms t_tbb; /* start execution times */ struct tms t_txfs; /* xfer start times */ - struct tms t_txfe; /* xfer end times */ + struct tms t_txfe; /* xfer end times */ struct tms t_tga; /* garbage execution times */ }; @@ -437,11 +438,7 @@ struct limits { /* external declarations */ EXTERN int (*Read)(), (*Write)(); -#if defined(__STDC__) -EXTERN int (*Ioctl)(int,int,...); -#else -EXTERN int (*Ioctl)(); -#endif +EXTERN int (*Ioctl)(int, int, ...); EXTERN int Ifn, Ofn; EXTERN int Debug, Verbose; EXTERN uid_t Uid, Euid; /* user-id and effective-uid */ @@ -456,7 +453,7 @@ EXTERN struct nstat Nstat; EXTERN char Dc[]; /* line name */ EXTERN int Seqn; /* sequence # */ EXTERN int Role; -EXTERN int Sgrades; /* flag for administrator defined service grades */ +EXTERN int Sgrades; /* flag for administrator defined service grades */ EXTERN char Grade; EXTERN char Logfile[]; EXTERN char Rmtname[]; @@ -477,44 +474,32 @@ EXTERN char Jobid[]; /* Jobid of current C. file */ EXTERN int Uerror; /* global error code */ EXTERN char *UerrorText[]; /* text for error code */ -#define UERRORTEXT UerrorText[Uerror] -#define UTEXT(x) UerrorText[x] +#define UERRORTEXT UerrorText[Uerror] +#define UTEXT(x) UerrorText[x] /* things get kind of tricky beyond this point -- please stay out */ #ifdef ATTSV -#define index strchr -#define rindex strrchr -#define vfork fork -#define ATTSVKILL -#define UNAME +#define index strchr +#define rindex strrchr +#define vfork fork +#define ATTSVKILL +#define UNAME #else -#define strchr index -#define strrchr rindex +#define strchr index +#define strrchr rindex #endif EXTERN struct stat __s_; -#define READANY(f) ((stat((f),&__s_)==0) && ((__s_.st_mode&(0004))!=0) ) -#define READSOME(f) ((stat((f),&__s_)==0) && ((__s_.st_mode&(0444))!=0) ) - -#define WRITEANY(f) ((stat((f),&__s_)==0) && ((__s_.st_mode&(0002))!=0) ) -#define DIRECTORY(f) ((stat((f),&__s_)==0) && ((__s_.st_mode&(S_IFMT))==S_IFDIR) ) -#define NOTEMPTY(f) ((stat((f),&__s_)==0) && (__s_.st_size!=0) ) - -/* standard functions used */ - -extern char *strcat(), *strcpy(), *strncpy(), *strrchr(); -extern char *strchr(), *strpbrk(); -extern char *index(), *rindex(), *getlogin(), *ttyname(); /*, *malloc(); -extern char *calloc(); */ -extern long atol(); -extern time_t time(); -extern int pipe(), close(), getopt(); -extern struct tm *localtime(); -extern FILE *popen(); -#ifdef BSD4_2 -extern char *sprintf(); -#endif /* BSD4_2 */ +#define READANY(f) \ + ((stat((f), &__s_) == 0) && ((__s_.st_mode & (0004)) != 0)) +#define READSOME(f) \ + ((stat((f), &__s_) == 0) && ((__s_.st_mode & (0444)) != 0)) +#define WRITEANY(f) \ + ((stat((f), &__s_) == 0) && ((__s_.st_mode & (0002)) != 0)) +#define DIRECTORY(f) \ + ((stat((f), &__s_) == 0) && ((__s_.st_mode & (S_IFMT)) == S_IFDIR)) +#define NOTEMPTY(f) ((stat((f), &__s_) == 0) && (__s_.st_size != 0)) /* uucp functions and subroutine */ EXTERN void (*genbrk)(); @@ -537,7 +522,7 @@ extern void commandlog(); /* logent.c */ extern time_t millitick(); /* logent.c */ extern unsigned long getfilesize(); /* statlog.c */ -extern void putfilesize(); /* statlog.c */ +extern void putfilesize(); /* statlog.c */ EXTERN char *protoString(); /* permission.c */ extern int logFind(), mchFind(); /* permission.c */ @@ -561,9 +546,9 @@ extern int versys(); /* versys.c */ extern void xuuxqt(), xuucico(); /* xqt.c */ EXTERN void cleanup(); /* misc main.c */ -#define ASSERT(e, s1, s2, i1) if (!(e)) {\ +#define ASSERT(e, s1, s2, i1) if (!(e)) {\ assert(s1, s2, i1, __FILE__, __LINE__);\ - cleanup(FAIL);}; + cleanup(FAIL); }; #ifdef ATTSV unsigned sleep(); |