rwall.c revision 49e7ca4919cec3229f6fab9730bafc7cf24dab23
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* University Copyright- Copyright (c) 1982, 1986, 1988
* The Regents of the University of California
* All Rights Reserved
*
* University Acknowledgment- Portions of this document are derived from
* software developed by the University of California, Berkeley, and its
* contributors.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* rwall.c
* The client rwall program
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <thread.h>
#include <string.h>
#include <signal.h>
#include <pwd.h>
#include <netconfig.h>
#include <netdb.h>
#include <sys/resource.h>
static void init_who(void);
static void doall(void);
static void doit(char *);
static void *do_one(void *);
static void usage(void);
#define PATIENCE 10
#define MAX_THREADS 1024
static char *path;
static int qflag = 0; /* quiet: we don't care about errors */
int
{
int msize;
int i;
char hostname[256];
int hflag;
if (argc < 2)
usage();
}
init_who();
exit(1);
}
}
hflag = 1;
while (argc > 1) {
case 'h':
hflag = 1;
break;
case 'n':
hflag = 0;
break;
case 'q':
qflag = 1;
break;
default:
usage();
break;
}
argc--;
argv++;
continue;
}
if (hflag) {
} else {
if (machine)
else
doall();
}
(void) endnetgrent();
}
argc--;
argv++;
}
return (0);
}
static void
init_who(void)
{
char *wp;
else {
if (pwd)
}
}
/*
* Saw a wild card, so do everything
*/
static void
doall(void)
{
(void) mutex_lock(&tty);
(void) mutex_unlock(&tty);
}
/*
* Fire off a detached thread for each host in the list, if the thread
* create fails simply run synchronously.
*/
static void
{
char *thread_hostname;
(void) mutex_lock(&thr_mtx);
while (thread_count >= MAX_THREADS) {
(void) mutex_unlock(&thr_mtx);
(void) mutex_lock(&thr_mtx);
}
thread_count++;
(void) mutex_unlock(&thr_mtx);
if (thread_hostname == (char *)NULL) {
(void) mutex_lock(&tty);
(void) mutex_unlock(&tty);
exit(1);
}
THR_DETACHED, &tid) != 0) {
(void) do_one(thread_hostname);
}
}
static void *
{
#ifdef DEBUG
(void) mutex_lock(&tty);
(void) mutex_unlock(&tty);
return (0);
#endif
if (!qflag) {
(void) mutex_lock(&tty);
hostname);
(void) mutex_unlock(&tty);
}
goto errout;
}
if (!qflag) {
(void) mutex_lock(&tty);
(void) mutex_unlock(&tty);
}
}
(void) mutex_lock(&thr_mtx);
thread_count--;
(void) mutex_unlock(&thr_mtx);
return (0);
}
static void
usage(void)
{
"Usage: rwall [-q] host .... [-n netgroup ....] [-h host ...]\n");
exit(1);
}