* Copyright (c) 1980 Regents of the University of California.
* All rights reserved. The Berkeley software License Agreement
* specifies the terms and conditions for redistribution.
"@(#) Copyright (c) 1980 Regents of the University of California.\n\
static char sccsid
[] = "@(#)wall.c 5.3 (Berkeley) %G%";
* wall.c - Broadcast a message to all users.
* This program is not related to David Wall, whose Stanford Ph.D. thesis
* is entitled "Mechanisms for Broadcast and Selective Broadcast".
#define IGNOREUSER "sleeper"
(void) gethostname(hostname
, sizeof (hostname
));
if ((f
= open("/etc/utmp", O_RDONLY
, 0)) < 0) {
fprintf(stderr
, "Cannot open /etc/utmp\n");
localclock
= localtime( &clock
);
sline
= ttyslot(); /* 'utmp' slot no. of sender */
utmp
= (struct utmp
*)malloc(statb
.st_size
);
c
= read(f
, (char *)utmp
, statb
.st_size
);
c
/= sizeof(struct utmp
);
strncpy(who
, utmp
[sline
].ut_name
, sizeof(utmp
[sline
].ut_name
));
"\n\007\007Broadcast Message from %s@%s (%.*s) at %d:%02d ...\r\n\n"
, sizeof(utmp
[sline
].ut_line
)
/* take message from unix file instead of standard input */
if (freopen(argv
[1], "r", stdin
) == NULL
) {
while ((i
= getchar()) != EOF
) {
if (msize
>= sizeof mesg
) {
fprintf(stderr
, "Message too long\n");
if (p
->ut_name
[0] == 0 ||
strncmp(p
->ut_name
, IGNOREUSER
, sizeof(p
->ut_name
)) == 0)
static char t
[50] = "/dev/";
if ((f
= open(t
, O_WRONLY
|O_NDELAY
)) < 0) {
if (errno
!= EWOULDBLOCK
)
if ((flags
= fcntl(f
, F_GETFL
, 0)) == -1) {
if (fcntl(f
, F_SETFL
, flags
| FNDELAY
) == -1)
i
= write(f
, mesg
, msize
);
(void) fcntl(f
, F_SETFL
, flags
);
while ((i
= fork()) == -1)
if (wait((int *)0) == -1) {
fprintf(stderr
, "Try again\n");
(void) write(f
, mesg
, msize
);