]>
git.wh0rd.org - sysvinit.git/blob - src/wall.c
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 (C) 1991-2000 Miquel van Smoorenburg.
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
35 char *Version
= "@(#) wall 2.79 12-Sep-2000 miquels@cistron.nl";
39 int main(int argc
, char **argv
)
51 if ((pwd
= getpwuid(getuid())) == NULL
) {
55 fprintf(stderr
, "You don't exist. Go away.\n");
59 whoami
= pwd
->pw_name
;
61 while((ch
= getopt(argc
, argv
, "n")) != EOF
)
65 * Undocumented option for suppressing
66 * banner from rpc.rwalld. Only works if
67 * we are root or if we're NOT setgid.
69 if (geteuid() != 0 && getgid() != getegid()) {
70 fprintf(stderr
, "wall -n: not priviliged\n");
76 fprintf(stderr
, "usage: wall [message]\n");
81 if ((argc
- optind
) > 0) {
82 for(f
= optind
; f
< argc
; f
++) {
83 len
+= strlen(argv
[f
]) + 1;
84 if (len
>= MAXLEN
-2) break;
86 if (f
< argc
-1) strcat(buf
, " ");
90 while(fgets(line
, 80, stdin
)) {
92 * Make sure that line ends in \r\n
94 for(p
= line
; *p
&& *p
!= '\r' && *p
!= '\n'; p
++)
98 if (len
>= MAXLEN
) break;
104 for (p
= buf
; *p
; p
++) {
105 if (*p
== '\n' && i
++ > MAXLINES
) {
111 openlog("wall", LOG_PID
, LOG_USER
);
112 syslog(LOG_INFO
, "wall: user %s broadcasted %d lines (%d chars)",
113 whoami
, i
, strlen(buf
));