static char *sccsid
= "@(#)comsat.c 4.5 82/12/23";
#define dprintf if (0) printf
#define MAXUTMP 100 /* down from init */
struct sockaddr_in sin
= { AF_INET
};
unsigned utmpmtime
; /* last modification time for utmp */
#define NAMLEN (sizeof (uts[0].ut_name) + 1)
sp
= getservbyname("biff", "udp");
fprintf(stderr
, "comsat: biff/udp: unknown service\n");
chdir("/usr/spool/mail");
if((uf
= open("/etc/utmp",0)) < 0)
perror("/etc/utmp"), exit(1);
s
= socket(AF_INET
, SOCK_DGRAM
, 0, 0);
sin
.sin_port
= sp
->s_port
;
if (bind(s
, &sin
, sizeof (sin
), 0) < 0) {
cc
= recv(s
, msgbuf
, sizeof (msgbuf
) - 1, 0);
if (statbf
.st_mtime
> utmpmtime
) {
utmpmtime
= statbf
.st_mtime
;
nutmp
= read(uf
,utmp
,sizeof(utmp
))/sizeof(struct utmp
);
register struct utmp
*utp
= &utmp
[nutmp
];
dprintf("mailfor %s\n", name
);
while (*cp
&& *cp
!= '@')
if (!strncmp(utp
->ut_name
, name
, sizeof(utmp
[0].ut_name
)))
signal(SIGALRM
, SIG_DFL
);
notify(utp
, offset
), exit(0);
while (wait3(0, WNOHANG
, 0) > 0)
register struct utmp
*utp
;
char name
[sizeof (utmp
[0].ut_name
) + 1];
strncat(tty
, utp
->ut_line
, sizeof(utp
->ut_line
));
dprintf("notify %s on %s\n", utp
->ut_name
, tty
);
if (stat(tty
, &stb
) == 0 && (stb
.st_mode
& 0100) == 0) {
if ((tp
= fopen(tty
,"w")) == 0) {
dprintf("fopen failed\n");
gtty(fileno(tp
),>tybuf
);
cr
= (gttybuf
.sg_flags
& CRMOD
) ? "" : "\r";
strncpy(name
, utp
->ut_name
, sizeof (utp
->ut_name
));
name
[sizeof (name
) - 1] = 0;
fprintf(tp
,"%s\n\007New mail for %s\007 has arrived:%s\n",
fprintf(tp
,"----%s\n", cr
);
jkfprintf(tp
, name
, offset
);
jkfprintf(tp
, name
, offset
)
register int linecnt
, charcnt
;
dprintf("HERE %s's mail starting at %d\n",
if ((fi
= fopen(name
,"r")) == NULL
) {
dprintf("Cant read the mail\n");
* print the first 7 lines or 560 characters of the new mail
* (whichever comes first)
if ((ch
= getc(fi
)) == EOF
) {
fprintf(tp
,"----%s\n", cr
);
fprintf(tp
,"...more...%s\n", cr
);
} else if(linecnt
<= 0) {
fprintf(tp
,"...more...%s\n", cr
);