int signum
[] = {SIGHUP
, SIGINT
, SIGQUIT
, 0};
printf("usage: write user [ttyname]\n");
if ((uf
= fopen("/etc/utmp", "r")) == NULL
) {
printf("cannot open /etc/utmp\n");
printf("Can't find your tty\n");
mytty
= rindex(mytty
, '/') + 1;
while (fread((char *)&ubuf
, sizeof(ubuf
), 1, uf
) == 1) {
if (strcmp(ubuf
.ut_line
, mytty
)==0) {
if(him
[0] != '-' || him
[1] != 0)
strcat(histty
, ubuf
.ut_line
);
if (logcnt
==0 && histty
[0]=='\0') {
printf("%s not logged in.\n", him
);
if (histtya
==0 && logcnt
> 1) {
printf("%s logged more than once\nwriting to %s\n", him
, histty
+5);
printf(" not on that tty\n"); else
printf(" not logged in\n");
if (access(histty
, 0) < 0) {
if ((tf
= fopen(histty
, "w")) == NULL
)
if (fstat(fileno(tf
), &stbuf
) < 0)
if ((stbuf
.st_mode
&02) == 0)
fprintf(tf
, "Message from ");
fprintf(tf
, "(Interdata) " );
fprintf(tf
, "%s %s...\n\a\a\a", me
, mytty
);
write(fileno(tf
), buf
, i
);
printf("Permission denied\n");
printf("Timeout opening his tty\n");
execl("/bin/sh", "sh", "-c", bp
+1, 0);
while(wait((int *)NULL
) != i
)