machine independent
authorBill Joy <root@ucbvax.Berkeley.EDU>
Mon, 15 Mar 1982 20:26:59 +0000 (12:26 -0800)
committerBill Joy <root@ucbvax.Berkeley.EDU>
Mon, 15 Mar 1982 20:26:59 +0000 (12:26 -0800)
SCCS-vsn: libexec/mail.local/mail.local.c 4.7
SCCS-vsn: usr.bin/wall/wall.c 4.6
SCCS-vsn: usr.bin/who/who.c 4.4
SCCS-vsn: usr.bin/write/write.c 4.5
SCCS-vsn: sbin/shutdown/shutdown.c 4.12
SCCS-vsn: sbin/shutdown/shutdown.c 4.13

usr/src/libexec/mail.local/mail.local.c
usr/src/sbin/shutdown/shutdown.c
usr/src/usr.bin/wall/wall.c
usr/src/usr.bin/who/who.c
usr/src/usr.bin/write/write.c

index fdae281..3bb4218 100644 (file)
@@ -6,10 +6,9 @@
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <setjmp.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <setjmp.h>
-#include <whoami.h>
 #include <sysexits.h>
 
 #include <sysexits.h>
 
-static char SccsId[] = "@(#)mail.local.c       4.6     %G%";
+static char SccsId[] = "@(#)mail.local.c       4.7     %G%";
 
 #define DELIVERMAIL    "/etc/delivermail"
 
 
 #define DELIVERMAIL    "/etc/delivermail"
 
@@ -24,13 +23,6 @@ static char SccsId[] = "@(#)mail.local.c     4.6     %G%";
 #define        LSIZE   256
 #define        MAXLET  300     /* maximum number of letters */
 #define        MAILMODE (~0644)                /* mode of created mail */
 #define        LSIZE   256
 #define        MAXLET  300     /* maximum number of letters */
 #define        MAILMODE (~0644)                /* mode of created mail */
-# ifndef DELIVERMAIL
-#define        RMAIL   "/usr/net/bin/sendberkmail"
-#define LOCNAM1        "csvax"
-#define LOCNAM2        "ucbvax"
-#define LOCNAM3        "vax"
-#define LOCNAM4        "v"
-# endif
 
 char   line[LSIZE];
 char   resp[LSIZE];
 
 char   line[LSIZE];
 char   resp[LSIZE];
@@ -47,7 +39,6 @@ char  lettmp[] = "/tmp/maXXXXX";
 char   maildir[] = "/usr/spool/mail/";
 char   mailfile[] = "/usr/spool/mail/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
 char   dead[] = "dead.letter";
 char   maildir[] = "/usr/spool/mail/";
 char   mailfile[] = "/usr/spool/mail/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
 char   dead[] = "dead.letter";
-char   *thissys = sysname;
 char   *netname = "vax";
 char   forwmsg[] = " forwarded\n";
 FILE   *tmpf;
 char   *netname = "vax";
 char   forwmsg[] = " forwarded\n";
 FILE   *tmpf;
@@ -373,9 +364,11 @@ copylet(n, f, type) FILE *f;
        k = let[n+1].adr - let[n].adr;
        while(k-- > 1 && (ch=fgetc(tmpf))!='\n')
                if(type!=ZAP) fputc(ch,f);
        k = let[n+1].adr - let[n].adr;
        while(k-- > 1 && (ch=fgetc(tmpf))!='\n')
                if(type!=ZAP) fputc(ch,f);
-       if(type==REMOTE)
-               fprintf(f, " remote from %s\n", thissys);
-       else if (type==FORWARD)
+       if(type==REMOTE) {
+               char hostname[32];
+               gethostname(hostname, sizeof (hostname));
+               fprintf(f, " remote from %s\n", hostname);
+       } else if (type==FORWARD)
                fprintf(f, forwmsg);
        else if(type==ORDINARY)
                fputc(ch,f);
                fprintf(f, forwmsg);
        else if(type==ORDINARY)
                fputc(ch,f);
@@ -403,7 +396,6 @@ char **argv;
        int first;
        register char *cp;
        int gaver = 0;
        int first;
        register char *cp;
        int gaver = 0;
-# ifdef DELIVERMAIL
        char *newargv[1000];
        register char **ap;
        register char **vp;
        char *newargv[1000];
        register char **ap;
        register char **vp;
@@ -430,7 +422,6 @@ char **argv;
                perror(DELIVERMAIL);
                exit(EX_UNAVAILABLE);
        }
                perror(DELIVERMAIL);
                exit(EX_UNAVAILABLE);
        }
-# endif DELIVERMAIL
 
        truename[0] = 0;
        line[0] = '\0';
 
        truename[0] = 0;
        line[0] = '\0';
@@ -468,10 +459,8 @@ char **argv;
                        argc--;
                        break;
 
                        argc--;
                        break;
 
-# ifdef DELIVERMAIL
                case 'd':
                        break;
                case 'd':
                        break;
-# endif DELIVERMAIL
                
                default:
                        usage();
                
                default:
                        usage();
@@ -603,30 +592,6 @@ skip:
        exit(0);
 }
 
        exit(0);
 }
 
-# ifndef DELIVERMAIL
-/*
- * Send mail on the Berkeley network.
- * Sorry Bill, sendrmt() is so awful we just gave up.
- */
-
-sendberkmail(n, name, fromaddr)
-       char name[];
-       char fromaddr[];
-{
-       char cmd[200];
-       register FILE *cmdf;
-
-       sprintf(cmd, "%s -h %d -f %s -t %s", RMAIL, hseqno, fromaddr, name);
-       if ((cmdf = popen(cmd, "w")) == NULL) {
-               perror(RMAIL);
-               return(0);
-       }
-       copylet(n, cmdf, ORDINARY);
-       pclose(cmdf);
-       return(9);
-}
-# endif
-
 usage()
 {
 
 usage()
 {
 
@@ -652,19 +617,6 @@ char *fromaddr;
        char buf[128];
        int f;
 
        char buf[128];
        int f;
 
-# ifndef DELIVERMAIL
-       stripfx(LOCNAM1, &name);
-       stripfx(LOCNAM2, &name);
-       stripfx(LOCNAM3, &name);
-       stripfx(LOCNAM4, &name);
-       if(*name == ':')name++;         /* skip colon in to-name */
-       for(p=name; *p!=':' && *p!='!' && *p!='^' &&*p!='\0'; p++);
-       /* if(*p == ':') return(sendrmt(n, name, RMAIL)); */
-       if (*p == ':')
-               return(sendberkmail(n, name, fromaddr));
-       else if (*p=='\0' && strcmp(name, "msgs") == 0)
-               return(sendrmt(n, "-s", "/usr/ucb/msgs"));
-# endif
        for(p=name; *p!='!'&&*p!='^' &&*p!='\0'; p++)
                ;
        if (*p == '!'|| *p=='^')
        for(p=name; *p!='!'&&*p!='^' &&*p!='\0'; p++)
                ;
        if (*p == '!'|| *p=='^')
@@ -836,23 +788,3 @@ register char *s, *p;
        *s = '\0';
        return(p);
 }
        *s = '\0';
        return(p);
 }
-# ifndef DELIVERMAIL
-/*
-       stripfx(prefix string, pointer to string)
-
-       takes a ptr to string and compares it to prefix string.
-       may be called multiple times
-*/
-stripfx(pfx, name)
-       char *pfx;
-       char **name;
-{
-       register char *cp = *name;
-
-       while (*pfx && (*cp == *pfx || *cp == toupper(*pfx)))
-               cp++, pfx++;
-       if (*cp != ':' || *pfx != 0)
-               return;
-       *name = cp;
-}
-# endif
index f9e7014..0eaec0a 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)shutdown.c  4.11 (Berkeley) 82/02/01";
+static char *sccsid = "@(#)shutdown.c  4.13 (Berkeley) 82/03/15";
 
 #include <stdio.h>
 #include <ctype.h>
 
 #include <stdio.h>
 #include <ctype.h>
@@ -6,7 +6,6 @@ static  char *sccsid = "@(#)shutdown.c  4.11 (Berkeley) 82/02/01";
 #include <utmp.h>
 #include <time.h>
 #include <sys/types.h>
 #include <utmp.h>
 #include <time.h>
 #include <sys/types.h>
-#include <whoami.h>
 /*
  *     /etc/shutdown when [messages]
  *
 /*
  *     /etc/shutdown when [messages]
  *
@@ -37,6 +36,8 @@ static        char *sccsid = "@(#)shutdown.c  4.11 (Berkeley) 82/02/01";
 #define        NOLOGTIME       5 MINUTES
 #define IGNOREUSER     "sleeper"
 
 #define        NOLOGTIME       5 MINUTES
 #define IGNOREUSER     "sleeper"
 
+char   hostname[32];
+
 int    do_nothing();
 time_t getsdt();
 
 int    do_nothing();
 time_t getsdt();
 
@@ -90,6 +91,7 @@ main(argc,argv)
        FILE *termf;
 
        shutter = getlogin();
        FILE *termf;
 
        shutter = getlogin();
+       gethostname(hostname, sizeof (hostname));
        argc--, argv++;
        while (argc > 0 && (f = argv[0], *f++ == '-')) {
                while (i = *f++) switch (i) {
        argc--, argv++;
        while (argc > 0 && (f = argv[0], *f++ == '-')) {
                while (i = *f++) switch (i) {
@@ -284,7 +286,7 @@ warn(term, sdt, nowtime)
        if (shutter)
                fprintf(term,
                    "\007\007*** System shutdown message from %s!%s ***\n",
        if (shutter)
                fprintf(term,
                    "\007\007*** System shutdown message from %s!%s ***\n",
-                   sysname,shutter);
+                   hostname,shutter);
        else
                fprintf(term,
                    "\007\007*** System shutdown message ***\n");
        else
                fprintf(term,
                    "\007\007*** System shutdown message ***\n");
@@ -361,7 +363,7 @@ time_t now;
        for (mess = nolog2; *mess; mess++)
                fprintf(fp, " %s", *mess);
        if (shutter)
        for (mess = nolog2; *mess; mess++)
                fprintf(fp, " %s", *mess);
        if (shutter)
-               fprintf(fp, " (by %s!%s)", sysname,shutter);
+               fprintf(fp, " (by %s!%s)", hostname,shutter);
        fputc('\n', fp);
        fclose(fp);
 }
        fputc('\n', fp);
        fclose(fp);
 }
index db9e9d3..f528eb6 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)wall.c      4.5 (Berkeley) 81/06/12";
+static char *sccsid = "@(#)wall.c      4.6 (Berkeley) 82/03/15";
 /*
  * wall.c - Broadcast a message to all users.
  *
 /*
  * wall.c - Broadcast a message to all users.
  *
@@ -9,11 +9,11 @@ static char *sccsid = "@(#)wall.c     4.5 (Berkeley) 81/06/12";
 #include <stdio.h>
 #include <utmp.h>
 #include <time.h>
 #include <stdio.h>
 #include <utmp.h>
 #include <time.h>
-#include <whoami.h>
 #include <signal.h>
 #define        USERS   128
 #define IGNOREUSER     "sleeper"
 
 #include <signal.h>
 #define        USERS   128
 #define IGNOREUSER     "sleeper"
 
+char   hostname[32];
 char   mesg[3000];
 int    msize,sline;
 struct utmp utmp[USERS];
 char   mesg[3000];
 int    msize,sline;
 struct utmp utmp[USERS];
@@ -33,6 +33,7 @@ char *argv[];
        FILE *f;
        FILE *mf;
 
        FILE *f;
        FILE *mf;
 
+       gethostname(hostname, sizeof (hostname));
        if((f = fopen("/etc/utmp", "r")) == NULL) {
                fprintf(stderr, "Cannot open /etc/utmp\n");
                exit(1);
        if((f = fopen("/etc/utmp", "r")) == NULL) {
                fprintf(stderr, "Cannot open /etc/utmp\n");
                exit(1);
@@ -65,9 +66,6 @@ char *argv[];
                if ((p->ut_name[0] == 0) ||
                    (strncmp (p->ut_name, IGNOREUSER, sizeof(p->ut_name)) == 0))
                        continue;
                if ((p->ut_name[0] == 0) ||
                    (strncmp (p->ut_name, IGNOREUSER, sizeof(p->ut_name)) == 0))
                        continue;
-       /***            this might be nice, but utmp gets so out of date !!
-               sleep(1);
-       ***/
                sendmes(p->ut_line);
        }
        exit(0);
                sendmes(p->ut_line);
        }
        exit(0);
@@ -82,13 +80,6 @@ char *tty;
        register int c, ch;
        FILE *f;
 
        register int c, ch;
        FILE *f;
 
-/***                   you can't do this with lots of users & MAXUPROC
-       i = fork();
-       if(i == -1) {
-               fprintf(stderr, "Try again\n");
-               return;
-       }
- ***/
        while ((i = fork()) == -1)
                if (wait((int *)0) == -1) {
                        fprintf(stderr, "Try again\n");
        while ((i = fork()) == -1)
                if (wait((int *)0) == -1) {
                        fprintf(stderr, "Try again\n");
@@ -109,7 +100,7 @@ char *tty;
        setbuf(f, buf);
        fprintf(f,
            "\n\a\a\aBroadcast Message from %s!%s (%.*s) at %d:%02d ...\r\n\n"
        setbuf(f, buf);
        fprintf(f,
            "\n\a\a\aBroadcast Message from %s!%s (%.*s) at %d:%02d ...\r\n\n"
-               , sysname
+               , hostname
                , who
                , sizeof(utmp[sline].ut_line)
                , utmp[sline].ut_line
                , who
                , sizeof(utmp[sline].ut_line)
                , utmp[sline].ut_line
index cb097f2..e49c616 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)who.c       4.3 (Berkeley) %G%";
+static char *sccsid = "@(#)who.c       4.4 (Berkeley) %G%";
 /*
  * who
  */
 /*
  * who
  */
@@ -6,19 +6,21 @@ static char *sccsid = "@(#)who.c      4.3 (Berkeley) %G%";
 #include <stdio.h>
 #include <utmp.h>
 #include <pwd.h>
 #include <stdio.h>
 #include <utmp.h>
 #include <pwd.h>
-#include <whoami.h>
 #include <ctype.h>
 
 #define NMAX sizeof(utmp.ut_name)
 #define LMAX sizeof(utmp.ut_line)
 
 #include <ctype.h>
 
 #define NMAX sizeof(utmp.ut_name)
 #define LMAX sizeof(utmp.ut_line)
 
-struct utmp utmp;
-struct passwd *pw;
-struct passwd *getpwuid();
+struct utmp utmp;
+struct passwd *pw;
+struct passwd *getpwuid();
+char   hostname[32];
+
+char   *ttyname(), *rindex(), *ctime(), *strcpy();
 
 
-char *ttyname(), *rindex(), *ctime(), *strcpy();
 main(argc, argv)
 main(argc, argv)
-char **argv;
+       int argc;
+       char **argv;
 {
        register char *tp, *s;
        register FILE *fi;
 {
        register char *tp, *s;
        register FILE *fi;
@@ -47,10 +49,10 @@ char **argv;
        }
        while (fread((char *)&utmp, sizeof(utmp), 1, fi) == 1) {
                if(argc==3) {
        }
        while (fread((char *)&utmp, sizeof(utmp), 1, fi) == 1) {
                if(argc==3) {
-                       static char myname[]=sysname;
+                       gethostname(hostname, sizeof (hostname));
                        if (strcmp(utmp.ut_line, tp))
                                continue;
                        if (strcmp(utmp.ut_line, tp))
                                continue;
-                       printf("%s!",myname);
+                       printf("%s!", hostname);
                        putline();
                        exit(0);
                }
                        putline();
                        exit(0);
                }
index c89d930..b246f2c 100644 (file)
@@ -1,4 +1,4 @@
-static char *sccsid = "@(#)write.c     4.4 (Berkeley) %G%";
+static char *sccsid = "@(#)write.c     4.5 %G%";
 /*
  * write to another user
  */
 /*
  * write to another user
  */
@@ -9,10 +9,9 @@ static char *sccsid = "@(#)write.c     4.4 (Berkeley) %G%";
 #include <signal.h>
 #include <utmp.h>
 #include <time.h>
 #include <signal.h>
 #include <utmp.h>
 #include <time.h>
-#include <whoami.h>
 
 
-#define NMAX sizeof(ubuf.ut_name)
-#define LMAX sizeof(ubuf.ut_line)
+#define        NMAX    sizeof(ubuf.ut_name)
+#define        LMAX    sizeof(ubuf.ut_line)
 
 char   *strcat();
 char   *strcpy();
 
 char   *strcat();
 char   *strcpy();
@@ -32,22 +31,23 @@ FILE        *tf;
 char   *getenv();
 
 main(argc, argv)
 char   *getenv();
 
 main(argc, argv)
-char *argv[];
+       int argc;
+       char *argv[];
 {
        struct stat stbuf;
        register i;
        register FILE *uf;
        int c1, c2;
 {
        struct stat stbuf;
        register i;
        register FILE *uf;
        int c1, c2;
-       long    clock = time( 0 );
+       long clock = time(0);
        struct tm *localtime();
        struct tm *localclock = localtime( &clock );
 
        struct tm *localtime();
        struct tm *localclock = localtime( &clock );
 
-       if(argc < 2) {
+       if (argc < 2) {
                printf("usage: write user [ttyname]\n");
                exit(1);
        }
        him = argv[1];
                printf("usage: write user [ttyname]\n");
                exit(1);
        }
        him = argv[1];
-       if(argc > 2)
+       if (argc > 2)
                histtya = argv[2];
        if ((uf = fopen("/etc/utmp", "r")) == NULL) {
                printf("cannot open /etc/utmp\n");
                histtya = argv[2];
        if ((uf = fopen("/etc/utmp", "r")) == NULL) {
                printf("cannot open /etc/utmp\n");
@@ -58,13 +58,13 @@ char *argv[];
                printf("Can't find your tty\n");
                exit(1);
        }
                printf("Can't find your tty\n");
                exit(1);
        }
-       if (stat (mytty, &stbuf) < 0) {
-               printf ("Can't stat your tty\n");
-               exit (1);
+       if (stat(mytty, &stbuf) < 0) {
+               printf("Can't stat your tty\n");
+               exit(1);
        }
        if ((stbuf.st_mode&02) == 0) {
        }
        if ((stbuf.st_mode&02) == 0) {
-               printf ("You have write permission turned off.\n");
-               exit (1);
+               printf("You have write permission turned off.\n");
+               exit(1);
        }
        mytty = rindex(mytty, '/') + 1;
        if (histtya) {
        }
        mytty = rindex(mytty, '/') + 1;
        if (histtya) {
@@ -75,23 +75,23 @@ char *argv[];
                if (ubuf.ut_name[0] == '\0')
                        continue;
                if (strcmp(ubuf.ut_line, mytty)==0) {
                if (ubuf.ut_name[0] == '\0')
                        continue;
                if (strcmp(ubuf.ut_line, mytty)==0) {
-                       for(i=0; i<NMAX; i++) {
+                       for (i=0; i<NMAX; i++) {
                                c1 = ubuf.ut_name[i];
                                c1 = ubuf.ut_name[i];
-                               if(c1 == ' ')
+                               if (c1 == ' ')
                                        c1 = 0;
                                me[i] = c1;
                                        c1 = 0;
                                me[i] = c1;
-                               if(c1 == 0)
+                               if (c1 == 0)
                                        break;
                        }
                }
                                        break;
                        }
                }
-               if(him[0] != '-' || him[1] != 0)
-               for(i=0; i<NMAX; i++) {
+               if (him[0] != '-' || him[1] != 0)
+               for (i=0; i<NMAX; i++) {
                        c1 = him[i];
                        c2 = ubuf.ut_name[i];
                        c1 = him[i];
                        c2 = ubuf.ut_name[i];
-                       if(c1 == 0)
-                               if(c2 == 0 || c2 == ' ')
+                       if (c1 == 0)
+                               if (c2 == 0 || c2 == ' ')
                                        break;
                                        break;
-                       if(c1 != c2)
+                       if (c1 != c2)
                                goto nomat;
                }
                logcnt++;
                                goto nomat;
                }
                logcnt++;
@@ -111,9 +111,9 @@ cont:
        if (histtya==0 && logcnt > 1) {
                printf("%s logged more than once\nwriting to %s\n", him, histty+5);
        }
        if (histtya==0 && logcnt > 1) {
                printf("%s logged more than once\nwriting to %s\n", him, histty+5);
        }
-       if(histty[0] == 0) {
+       if (histty[0] == 0) {
                printf(him);
                printf(him);
-               if(logcnt)
+               if (logcnt)
                        printf(" not on that tty\n"); else
                        printf(" not logged in\n");
                exit(1);
                        printf(" not on that tty\n"); else
                        printf(" not logged in\n");
                exit(1);
@@ -132,28 +132,27 @@ cont:
        if ((stbuf.st_mode&02) == 0)
                goto perm;
        sigs(eof);
        if ((stbuf.st_mode&02) == 0)
                goto perm;
        sigs(eof);
-       fprintf(tf, "\r\nMessage from ");
-#ifdef interdata
-       fprintf(tf, "(Interdata) " );
-#endif
-       fprintf(tf, "%s!%s on %s at %d:%02d ...\r\n\a\a\a"
-              , sysname , me, mytty , localclock -> tm_hour , localclock -> tm_min );
+       { char hostname[32];
+         gethostname(hostname, sizeof (hostname));
+         fprintf(tf, "\r\nMessage from ");
+         fprintf(tf, "%s!%s on %s at %d:%02d ...\r\n\a\a\a",
+             hostname, me, mytty, localclock->tm_hour, localclock->tm_min);
+       }
        fflush(tf);
        fflush(tf);
-       for(;;) {
+       for (;;) {
                char buf[128];
                i = read(0, buf, 128);
                char buf[128];
                i = read(0, buf, 128);
-               if(i <= 0)
+               if (i <= 0)
                        eof();
                        eof();
-               if(buf[0] == '!') {
+               if (buf[0] == '!') {
                        buf[i] = 0;
                        ex(buf);
                        continue;
                }
                write(fileno(tf), buf, i);
                        buf[i] = 0;
                        ex(buf);
                        continue;
                }
                write(fileno(tf), buf, i);
-               if ( buf[ i - 1 ] == '\n' )
-                   write( fileno( tf ) , "\r" , 1 );
+               if (buf[i-1] == '\n')
+                       write(fileno(tf), "\r", 1);
        }
        }
-
 perm:
        printf("Permission denied\n");
        exit(1);
 perm:
        printf("Permission denied\n");
        exit(1);
@@ -174,22 +173,23 @@ eof()
 }
 
 ex(bp)
 }
 
 ex(bp)
-char *bp;
+       char *bp;
 {
        register i;
 
        sigs(SIG_IGN);
        i = fork();
 {
        register i;
 
        sigs(SIG_IGN);
        i = fork();
-       if(i < 0) {
+       if (i < 0) {
                printf("Try again\n");
                goto out;
        }
                printf("Try again\n");
                goto out;
        }
-       if(i == 0) {
+       if (i == 0) {
                sigs((int (*)())0);
                sigs((int (*)())0);
-               execl(getenv("SHELL") ? getenv("SHELL") : "/bin/sh", "sh", "-c", bp+1, 0);
+               execl(getenv("SHELL") ?
+                   getenv("SHELL") : "/bin/sh", "sh", "-c", bp+1, 0);
                exit(0);
        }
                exit(0);
        }
-       while(wait((int *)NULL) != i)
+       while (wait((int *)NULL) != i)
                ;
        printf("!\n");
 out:
                ;
        printf("!\n");
 out:
@@ -197,10 +197,10 @@ out:
 }
 
 sigs(sig)
 }
 
 sigs(sig)
-int (*sig)();
+       int (*sig)();
 {
        register i;
 
 {
        register i;
 
-       for(i=0;signum[i];i++)
-               signal(signum[i],sig);
+       for (i=0; signum[i]; i++)
+               signal(signum[i], sig);
 }
 }