static char *sccsid
= "@(#)comsat.c 4.2 (Berkeley) 10/20/80";
#define dprintf if (0) printf
#define MAXUTMP 100 /* down from init */
unsigned utmpmtime
; /* last modification time for utmp */
#define NAMLEN (sizeof (uts[0].ut_name) + 1)
chdir("/usr/spool/mail");
if((uf
= open("/etc/utmp",0)) < 0)
perror("/etc/utmp"), exit(1);
xd
= mpx("/dev/mail", 0666);
while((cc
=read(xd
, buf
, BUFSIZ
)) >= 0) {
dprintf("0: got %d bytes\n", cc
);
#define skip(rp, c) ((struct rh *)(((char *)rp)+c))
dprintf("%d byte control message\n", rp
->ccount
);
control(rp
->index
, rp
+1, rp
->ccount
);
dprintf("%*.*s\n", rp
->count
, rp
->count
, rp
+1);
rp
= skip(rp
, rp
->count
);
dprintf("attach %x, uid %d\n", x
, *sp
);
dprintf("detach %x, uid %d\n", x
, *sp
);
dprintf("ioctl %x\n", x
);
or.data
= (char *) &ctp
.ctrlarg
;
write(xd
, &or, sizeof or);
dprintf("unknown command %d\n", cmd
);
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
);