]>
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
32 #include <sys/types.h>
36 char *Version
= "@(#) wall 2.79 12-Sep-2000 miquels@cistron.nl";
40 int main(int argc
, char **argv
)
52 if ((pwd
= getpwuid(getuid())) == NULL
) {
56 fprintf(stderr
, "You don't exist. Go away.\n");
60 whoami
= pwd
->pw_name
;
62 while((ch
= getopt(argc
, argv
, "n")) != EOF
)
66 * Undocumented option for suppressing
67 * banner from rpc.rwalld. Only works if
68 * we are root or if we're NOT setgid.
70 if (geteuid() != 0 && getgid() != getegid()) {
71 fprintf(stderr
, "wall -n: not priviliged\n");
77 fprintf(stderr
, "usage: wall [message]\n");
82 if ((argc
- optind
) > 0) {
83 for(f
= optind
; f
< argc
; f
++) {
84 len
+= strlen(argv
[f
]) + 1;
85 if (len
>= MAXLEN
-2) break;
87 if (f
< argc
-1) strcat(buf
, " ");
91 while(fgets(line
, 80, stdin
)) {
93 * Make sure that line ends in \r\n
95 for(p
= line
; *p
&& *p
!= '\r' && *p
!= '\n'; p
++)
99 if (len
>= MAXLEN
) break;
105 for (p
= buf
; *p
; p
++) {
106 if (*p
== '\n' && ++i
>= MAXLINES
) {
112 openlog("wall", LOG_PID
, LOG_USER
);
113 syslog(LOG_INFO
, "wall: user %s broadcasted %d lines (%zu chars)",
114 whoami
, i
, strlen(buf
));