/* Copyright (c) 1979 Regents of the University of California */
/* mwrite name ttystr ltime fmach fuser command time */
/* ttystr is the full name, e.g. /dev/tty0 */
/* command and time is optional */
long ltime
, otime
, timesent
, el
;
char buf
[BFS
*2],*s
,buf1
[BFS
];
if(errno
!= 100 && argv
[2][0] && argv
[2][8] != 'x'){
debug("argv3 %s",argv[3]);
sscanf(argv
[3],"%lo",<ime
);
file
= fopen("/etc/utmp","r");
if(file
== NULL
)error("bad utmp");
while(fread(&utmpstr
,1,sizeof utmpstr
,file
) == sizeof utmpstr
){
if(utmpstr
.ut_tty
== argv
[2][8]){
if(strcmp(utmpstr
.ut_line
,argv
[2]+5) == 0){
debug("ltime %lo otime %lo",ltime,otime);
if(otime
!= 0 && otime
== ltime
) {
sprintf(buf
,"%s",argv
[2]);
if(file
!= NULL
&& fstat(fileno(file
),&statbuf
) != -1
&& (statbuf
.st_mode
&02)){
fprintf(file
,"\nMessage from %s on %s machine ...\n",
argv
[5],longname(argv
[4][0]));
fprintf(file
,"(command: %s",argv
[6]);
timesent
=atol(argv
[7])+TIMEBASE
;
el
= gettime() - timesent
;
fprintf(file
,", sent %s, took %s",s
,comptime(el
));
while((n
= fread(buf
,1,512,stdin
)) > 0){
fprintf(file
,"------\n");
sprintf(buf
,"-%s",argv
[6]);
timesent
=atol(argv
[7])+TIMEBASE
;
sprintf(buf1
,"-%ld",timesent
);
mexecl(mailcmd
,"mmail",buf
,buf1
,argv
[5],
longname(argv
[4][0]), argv
[1], 0);
else mexecl(mailcmd
,"mmail",buf
,argv
[5],longname(argv
[4][0]),
else mexecl(mailcmd
,"mmail",argv
[5],longname(argv
[4][0]),argv
[1],0);
signal(SIGCLK
,SIG_IGN
); /* alarm off */
longjmp(env
,0); /* ugh */
/* returns number of bytes written, error returns WRITEFAIL (-3) */