/*
 * $Copyright:	$
 * Copyright (c) 1984, 1985, 1986, 1987, 1988, 1989, 1990 
 * Sequent Computer Systems, Inc.   All rights reserved.
 *  
 * This software is furnished under a license and may be used
 * only in accordance with the terms of that license and with the
 * inclusion of the above copyright notice.   This software may not
 * be provided or otherwise made available to, or used by, any
 * other person.  No title to or ownership of the software is
 * hereby transferred.
 *
 */

/*	Copyright (c) 1984 AT&T	*/
/*	  All Rights Reserved  	*/

/*	THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF AT&T	*/
/*	The copyright notice above does not evidence any   	*/
/*	actual or intended publication of such source code.	*/

#ident "$Header: kill.c 1.5 89/11/14 $@(#)kill:kill.c	1.2"
/*
**	kill - send signal to process
*/

#include	<stdio.h>
#include	<signal.h>
#include	<sys/errno.h>

extern void exit();

main(argc, argv)
char **argv;
{
	register signo, pid, res;
	int	errlev = 0, neg = 0, zero = 0;
	extern	errno;
	char	*msg;
	extern 	char	*gettxt();

	if (argc <= 1)
		usage();
	if (*argv[1] == '-') {
		signo = atoi(argv[1]+1);
		argc--;
		argv++;
	} else
		signo = SIGTERM;
	argv++;
	while (argc > 1) {
		if (**argv == '-') neg++;
		if (**argv == '0') zero++;
		pid = atoi(*argv);
		if (	((pid == 0) && !zero)
		     || ((pid < 0) && !neg)
		     || (pid > 32000)
		     || (pid < -32000)
		      ) usage();
		res = kill(pid, signo);
		if (res<0) {
			if(pid <= 0) {
				pid = abs(pid);
				msg = gettxt("kill:1",
				    "not a killable process group");
			}
			else if (errno == EPERM)
				msg = gettxt("kill:2", "permission denied");
			else if (errno == EINVAL)
				msg = gettxt("kill:3", "invalid signal");
			else msg = gettxt("kill:4", "no such process");
			fprintf(stderr, gettxt("colon:28", "kill: %d: %s\n"),
				pid, msg);
			errlev = 2;
		}
		argc--;
		argv++;
		neg = zero = 0;
	}
	return(errlev);
}
usage()
{
	fprintf(stderr, gettxt("kill:5", "usage: kill [ -signo ] pid ...\n"));
	exit(2);
}
