2 * wall.c Write to all users logged in.
6 * Version: @(#)wall 2.79 12-Sep-2000 miquels@cistron.nl
8 * This file is part of the sysvinit suite,
9 * Copyright 1991-2000 Miquel van Smoorenburg.
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version
14 * 2 of the License, or (at your option) any later version.
25 char *Version
= "@(#) wall 2.79 12-Sep-2000 miquels@cistron.nl";
29 extern void wall(char *, int, int);
31 int main(int argc
, char **argv
)
43 if ((pwd
= getpwuid(getuid())) == NULL
) {
47 fprintf(stderr
, "You don't exist. Go away.\n");
51 whoami
= pwd
->pw_name
;
53 while((ch
= getopt(argc
, argv
, "n")) != EOF
)
57 * Undocumented option for suppressing
58 * banner from rpc.rwalld. Only works if
59 * we are root or if we're NOT setgid.
61 if (geteuid() != 0 && getgid() != getegid()) {
62 fprintf(stderr
, "wall -n: not priviliged\n");
68 fprintf(stderr
, "usage: wall [message]\n");
73 if ((argc
- optind
) > 0) {
74 for(f
= optind
; f
< argc
; f
++) {
75 len
+= strlen(argv
[f
]) + 1;
76 if (len
>= MAXLEN
-2) break;
78 if (f
< argc
-1) strcat(buf
, " ");
82 while(fgets(line
, 80, stdin
)) {
84 * Make sure that line ends in \r\n
86 for(p
= line
; *p
&& *p
!= '\r' && *p
!= '\n'; p
++)
90 if (len
>= MAXLEN
) break;
96 for (p
= buf
; *p
; p
++) {
97 if (*p
== '\n' && i
++ > MAXLINES
) {
103 openlog("wall", LOG_PID
, LOG_USER
);
104 syslog(LOG_INFO
, "wall: user %s broadcasted %d lines (%d chars)",
105 whoami
, i
, strlen(buf
));
109 wall(buf
, 0, remote
);