4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
25 /* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
26 /* All Rights Reserved */
28 * University Copyright- Copyright (c) 1982, 1986, 1988
29 * The Regents of the University of California
32 * University Acknowledgment- Portions of this document are derived from
33 * software developed by the University of California, Berkeley, and its
37 #pragma ident "%Z%%M% %I% %E% SMI"
41 * The client rwall program
45 #include <stdio_ext.h>
46 #include <sys/types.h>
54 #include <rpcsvc/rwall.h>
55 #include <netconfig.h>
58 #include <sys/resource.h>
60 static void init_who(void);
61 static void doall(void);
62 static void doit(char *);
63 static void *do_one(void *);
64 static void usage(void);
67 #define MAX_THREADS 1024
69 static mutex_t tty
= DEFAULTMUTEX
;
70 static char who
[9] = "???";
72 static mutex_t thr_mtx
= DEFAULTMUTEX
;
73 static int thread_count
= 8; /* fudge factor for system threads/fds */
74 static int qflag
= 0; /* quiet: we don't care about errors */
77 main(int argc
, char *argv
[])
89 if (getrlimit(RLIMIT_NOFILE
, &rl
) == 0) {
90 rl
.rlim_cur
= (rl
.rlim_max
< MAX_THREADS
?
91 rl
.rlim_max
: MAX_THREADS
);
92 (void) setrlimit(RLIMIT_NOFILE
, &rl
);
93 (void) enable_extended_FILE_stdio(-1, -1);
96 (void) gethostname(hostname
, sizeof (hostname
));
100 msize
= snprintf(buf
, sizeof (buf
), "From %s@%s: ", who
, hostname
);
101 while ((i
= getchar()) != EOF
) {
102 if (msize
>= (sizeof (buf
) - 1)) {
103 (void) fprintf(stderr
, "Message too long\n");
112 if (argv
[1][0] == '-') {
113 switch (argv
[1][1]) {
134 char *machine
, *user
, *domain
;
136 (void) setnetgrent(argv
[1]);
137 while (getnetgrent(&machine
, &user
, &domain
)) {
143 (void) endnetgrent();
161 (void) strncpy(who
, wp
, sizeof (who
));
163 pwd
= getpwuid(getuid());
165 (void) strncpy(who
, pwd
->pw_name
, sizeof (who
));
171 * Saw a wild card, so do everything
176 (void) mutex_lock(&tty
);
177 (void) fprintf(stderr
, "writing to everyone not supported\n");
178 (void) mutex_unlock(&tty
);
182 * Fire off a detached thread for each host in the list, if the thread
183 * create fails simply run synchronously.
189 char *thread_hostname
;
191 (void) mutex_lock(&thr_mtx
);
192 while (thread_count
>= MAX_THREADS
) {
193 (void) mutex_unlock(&thr_mtx
);
194 (void) sleep(PATIENCE
/2);
195 (void) mutex_lock(&thr_mtx
);
199 (void) mutex_unlock(&thr_mtx
);
201 thread_hostname
= strdup(hostname
);
202 if (thread_hostname
== (char *)NULL
) {
203 (void) mutex_lock(&tty
);
204 (void) fprintf(stderr
, "Ran out of memory\n");
205 (void) mutex_unlock(&tty
);
209 if (thr_create(NULL
, 0, do_one
, thread_hostname
,
210 THR_DETACHED
, &tid
) != 0) {
211 (void) do_one(thread_hostname
);
218 char *hostname
= arg
;
224 (void) mutex_lock(&tty
);
225 (void) fprintf(stderr
, "sending message to %s\n%s\n", hostname
, path
);
226 (void) mutex_unlock(&tty
);
229 tp
.tv_sec
= PATIENCE
;
231 clnt
= clnt_create_timed(
232 hostname
, WALLPROG
, WALLVERS
, "datagram_v", &tp
);
235 (void) mutex_lock(&tty
);
236 (void) fprintf(stderr
, "rwall: Can't send to %s\n",
238 clnt_pcreateerror(hostname
);
239 (void) mutex_unlock(&tty
);
244 if (wallproc_wall_1(&path
, vp
, clnt
) != RPC_SUCCESS
) {
246 (void) mutex_lock(&tty
);
247 clnt_perror(clnt
, hostname
);
248 (void) mutex_unlock(&tty
);
253 (void) mutex_lock(&thr_mtx
);
255 (void) mutex_unlock(&thr_mtx
);
263 (void) fprintf(stderr
,
264 "Usage: rwall [-q] host .... [-n netgroup ....] [-h host ...]\n");