/* vi: set sw=4 ts=4: */
/*
 * Mini kill/killall implementation for busybox
 *
 * Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
 * Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.org>
 *
 * Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
 */

#include "busybox.h"
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <unistd.h>
#include <signal.h>
#include <ctype.h>
#include <string.h>
#include <unistd.h>

#define KILL 0
#define KILLALL 1

int kill_main(int argc, char **argv)
{
	int whichApp, signo = SIGTERM;
	const char *name;
	int errors = 0;

#ifdef CONFIG_KILLALL
	int quiet=0;
	/* Figure out what we are trying to do here */
	whichApp = (strcmp(bb_applet_name, "killall") == 0)? KILLALL : KILL;
#else
	whichApp = KILL;
#endif

	/* Parse any options */
	if (argc < 2)
		bb_show_usage();

	if(argv[1][0] != '-'){
		argv++;
		argc--;
		goto do_it_now;
	}

	/* The -l option, which prints out signal names. */
	if(argv[1][1]=='l' && argv[1][2]=='\0'){
		if(argc==2) {
			/* Print the whole signal list */
			int col = 0;
			for(signo=1; signo < NSIG; signo++) {
				name = u_signal_names(0, &signo, 1);
				if(name==NULL)  /* unnamed */
					continue;
				col += printf("%2d) %-16s", signo, name);
				if (col > 60) {
					printf("\n");
					col = 0;
				}
			}
			printf("\n");

		} else {
			for(argv++; *argv; argv++) {
				name = u_signal_names(*argv, &signo, -1);
				if(name!=NULL)
					printf("%s\n", name);
			}
		}
		/* If they specified -l, were all done */
		return EXIT_SUCCESS;
	}

#ifdef CONFIG_KILLALL
	/* The -q quiet option */
	if(whichApp != KILL && argv[1][1]=='q' && argv[1][2]=='\0'){
		quiet++;
		argv++;
		argc--;
		if(argc<2 || argv[1][0] != '-'){
			goto do_it_now;
		}
	}
#endif

	if(!u_signal_names(argv[1]+1, &signo, 0))
		bb_error_msg_and_die( "bad signal name '%s'", argv[1]+1);
	argv+=2;
	argc-=2;

do_it_now:

	/* Pid or name required */
	if (argc <= 0)
		bb_show_usage();

	if (whichApp == KILL) {
		/* Looks like they want to do a kill. Do that */
		while (--argc >= 0) {
			int pid;

			if (!isdigit(**argv) && **argv != '-')
				bb_error_msg_and_die( "Bad PID '%s'", *argv);
			pid = strtol(*argv, NULL, 0);
			if (kill(pid, signo) != 0) {
				bb_perror_msg( "Could not kill pid '%d'", pid);
				errors++;
			}
			argv++;
		}

	}
#ifdef CONFIG_KILLALL
	else {
		pid_t myPid=getpid();
		/* Looks like they want to do a killall.  Do that */
		while (--argc >= 0) {
			long* pidList;

			pidList = find_pid_by_name(*argv);
			if (!pidList || *pidList<=0) {
				errors++;
				if (quiet==0)
					bb_error_msg( "%s: no process killed", *argv);
			} else {
				long *pl;

				for(pl = pidList; *pl !=0 ; pl++) {
					if (*pl==myPid)
						continue;
					if (kill(*pl, signo) != 0) {
						errors++;
						if (quiet==0)
							bb_perror_msg( "Could not kill pid '%ld'", *pl);
					}
				}
			}
			free(pidList);
			argv++;
		}
	}
#endif
	return errors;
}
