Annotation of researchv10no/cmd/upas/send/notify.c, revision 1.1.1.1

1.1       root        1: #include <signal.h>
                      2: #include "mail.h"
                      3: #include "string.h"
                      4: #include "message.h"
                      5: #include <sys/stat.h>
                      6: #include <utmp.h>
                      7: 
                      8: SIGRETURN
                      9: ding(s)
                     10:        int s;
                     11: {
                     12:        signal(SIGALRM, ding);
                     13: }
                     14: 
                     15: /* output message to one terminal */
                     16: static void
                     17: tell(dev, sender, date)
                     18:        char *dev, *sender, *date;
                     19: {
                     20:        int fd;
                     21:        static string *msg=NULL;
                     22: 
                     23:        signal(SIGALRM, ding);
                     24:        alarm(30);
                     25:        if((fd = open(dev, 1))<0)
                     26:                return;
                     27:        if(msg==NULL)
                     28:                msg=s_new();
                     29:        s_append(s_restart(msg), "[\007From ");
                     30:        s_append(msg, sender);
                     31:        s_append(msg, " ");
                     32:        s_append(msg, date);
                     33:        s_append(msg, "\007]\n");
                     34:        write(fd, s_to_c(msg), strlen(s_to_c(msg)));
                     35:        alarm(0);
                     36:        close(fd);
                     37: }
                     38: 
                     39: /* loop through all logins */
                     40: notify(user, mp)
                     41:        char *user;
                     42:        message *mp;
                     43: {
                     44:        int fd;
                     45:        struct utmp u;
                     46:        char dev[128];
                     47:        struct stat sbuf;
                     48: 
                     49:        if((fd=open("/etc/utmp", 0))<0)
                     50:                return;
                     51:        while(read(fd, (char *)&u, sizeof(u))==sizeof(u)) {
                     52:                if (strncmp(u.ut_name, user, sizeof(u.ut_name))!=0)
                     53:                        continue;
                     54:                strcpy(dev, "/dev/");
                     55:                strncat(dev, u.ut_line, sizeof(u.ut_line));
                     56:                dev[sizeof(u.ut_line)+sizeof("/dev/")-1] = '\0';
                     57:                if (stat(dev, &sbuf)<0)
                     58:                        continue;
                     59:                if (sbuf.st_mode&S_IEXEC)
                     60:                        tell(dev, s_to_c(mp->sender), s_to_c(mp->date));
                     61:        }
                     62:        close(fd);
                     63: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.