/* vi: set sw=4 ts=4: */
/*
 * Mini start-stop-daemon implementation(s) for busybox
 *
 * Written by Marek Michalkiewicz <marekm@i17linuxb.ists.pwr.wroc.pl>,
 * Adapted for busybox David Kimdon <dwhedon@gordian.com>
 *
 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
 */

#include "busybox.h"
#include <getopt.h>

static int signal_nr = 15;
static int user_id = -1;
static int quiet;
static char *userspec;
static char *chuid;
static char *cmdname;
static char *execname;
static char *pidfile;

struct pid_list {
	struct pid_list *next;
	pid_t pid;
};

static struct pid_list *found = NULL;

static inline void push(pid_t pid)
{
	struct pid_list *p;

	p = xmalloc(sizeof(*p));
	p->next = found;
	p->pid = pid;
	found = p;
}

static int pid_is_exec(pid_t pid, const char *name)
{
	char buf[32], *execbuf;
	int equal;

	sprintf(buf, "/proc/%d/exe", pid);
	execbuf = xstrdup(name);
	readlink(buf, execbuf, strlen(name)+1);
	
	equal = ! strcmp(execbuf, name);
	if (ENABLE_FEATURE_CLEAN_UP)
		free(execbuf);
	return equal;
}

static int pid_is_user(int pid, int uid)
{
	struct stat sb;
	char buf[32];

	sprintf(buf, "/proc/%d", pid);
	if (stat(buf, &sb) != 0)
		return 0;
	return (sb.st_uid == uid);
}

static int pid_is_cmd(pid_t pid, const char *name)
{
	char buf[32];
	FILE *f;
	int c;

	sprintf(buf, "/proc/%d/stat", pid);
	f = fopen(buf, "r");
	if (!f)
		return 0;
	while ((c = getc(f)) != EOF && c != '(')
		;
	if (c != '(') {
		fclose(f);
		return 0;
	}
	/* this hopefully handles command names containing ')' */
	while ((c = getc(f)) != EOF && c == *name)
		name++;
	fclose(f);
	return (c == ')' && *name == '\0');
}


static void check(int pid)
{
	if (execname && !pid_is_exec(pid, execname)) {
		return;
	}
	if (userspec && !pid_is_user(pid, user_id)) {
		return;
	}
	if (cmdname && !pid_is_cmd(pid, cmdname)) {
		return;
	}
	push(pid);
}


static void do_pidfile(void)
{
	FILE *f;
	pid_t pid;

	f = fopen(pidfile, "r");
	if (f) {
		if (fscanf(f, "%d", &pid) == 1)
			check(pid);
		fclose(f);
	} else if (errno != ENOENT)
		bb_perror_msg_and_die("open pidfile %s", pidfile);

}

static void do_procinit(void)
{
	DIR *procdir;
	struct dirent *entry;
	int foundany, pid;

	if (pidfile) {
		do_pidfile();
		return;
	}

	procdir = xopendir("/proc");

	foundany = 0;
	while ((entry = readdir(procdir)) != NULL) {
		if (sscanf(entry->d_name, "%d", &pid) != 1)
			continue;
		foundany++;
		check(pid);
	}
	closedir(procdir);
	if (!foundany)
		bb_error_msg_and_die ("nothing in /proc - not mounted?");
}


static int do_stop(void)
{
	RESERVE_CONFIG_BUFFER(what, 1024);
	struct pid_list *p;
	int killed = 0;

	do_procinit();

	if (cmdname)
		strcpy(what, cmdname);
	else if (execname)
		strcpy(what, execname);
	else if (pidfile)
		sprintf(what, "process in pidfile `%.200s'", pidfile);
	else if (userspec)
		sprintf(what, "process(es) owned by `%s'", userspec);
	else
		bb_error_msg_and_die ("internal error, please report");

	if (!found) {
		if (!quiet)
			printf("no %s found; none killed.\n", what);
		if (ENABLE_FEATURE_CLEAN_UP)
			RELEASE_CONFIG_BUFFER(what);
		return -1;
	}
	for (p = found; p; p = p->next) {
		if (kill(p->pid, signal_nr) == 0) {
			p->pid = -p->pid;
			killed++;
		} else {
			bb_perror_msg("warning: failed to kill %d", p->pid);
		}
	}
	if (!quiet && killed) {
		printf("stopped %s (pid", what);
		for (p = found; p; p = p->next)
			if(p->pid < 0)
				printf(" %d", -p->pid);
		printf(").\n");
	}
	if (ENABLE_FEATURE_CLEAN_UP)
		RELEASE_CONFIG_BUFFER(what);
	return killed;
}

#if ENABLE_FEATURE_START_STOP_DAEMON_LONG_OPTIONS
static const struct option ssd_long_options[] = {
	{ "stop",			0,		NULL,		'K' },
	{ "start",			0,		NULL,		'S' },
	{ "background",		0,		NULL,		'b' },
	{ "quiet",			0,		NULL,		'q' },
	{ "make-pidfile",	0,		NULL,		'm' },
#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
	{ "oknodo",			0,		NULL,		'o' },
	{ "verbose",		0,		NULL,		'v' },
#endif
	{ "startas",		1,		NULL,		'a' },
	{ "name",			1,		NULL,		'n' },
	{ "signal",			1,		NULL,		's' },
	{ "user",			1,		NULL,		'u' },
	{ "chuid", 			1,		NULL,		'c' },
	{ "exec",			1,		NULL,		'x' },
	{ "pidfile",		1,		NULL,		'p' },
#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
	{ "retry",			1,		NULL,		'R' },
#endif
	{ 0,				0,		0,		0 }
};
#endif

#define SSD_CTX_STOP		1
#define SSD_CTX_START		2
#define SSD_OPT_BACKGROUND	4
#define SSD_OPT_QUIET		8
#define SSD_OPT_MAKEPID		16
#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
#define SSD_OPT_OKNODO		32
#define SSD_OPT_VERBOSE		64

#endif

int start_stop_daemon_main(int argc, char **argv)
{
	unsigned long opt;
	char *signame = NULL;
	char *startas = NULL;
#if ENABLE_FEATURE_START_STOP_DAEMON_FANCY
//	char *retry_arg = NULL;
//	int retries = -1;
#endif
#if ENABLE_FEATURE_START_STOP_DAEMON_LONG_OPTIONS
	bb_applet_long_options = ssd_long_options;
#endif

	/* Check required one context option was given */
	bb_opt_complementally = "K:S:?:K--S:S--K:m?p:K?xpun:S?xa";
	opt = bb_getopt_ulflags(argc, argv, "KSbqm"
//		USE_FEATURE_START_STOP_DAEMON_FANCY("ovR:")
		USE_FEATURE_START_STOP_DAEMON_FANCY("ov")
		"a:n:s:u:c:x:p:"
//		USE_FEATURE_START_STOP_DAEMON_FANCY(,&retry_arg)
		,&startas, &cmdname, &signame, &userspec, &chuid, &execname, &pidfile);

	quiet = (opt & SSD_OPT_QUIET)
			USE_FEATURE_START_STOP_DAEMON_FANCY(&& !(opt & SSD_OPT_VERBOSE));

	if (signame) {
		signal_nr = get_signum(signame);
		if (signal_nr < 0) bb_show_usage();
	}

	if (!startas)
		startas = execname;

//	USE_FEATURE_START_STOP_DAEMON_FANCY(
//		if (retry_arg)
//			retries = bb_xgetlarg(retry_arg, 10, 0, INT_MAX);
//	)
	argc -= optind;
	argv += optind;

	if (userspec && sscanf(userspec, "%d", &user_id) != 1)
		user_id = bb_xgetpwnam(userspec);

	if (opt & SSD_CTX_STOP) {
		int i = do_stop();
		return
			USE_FEATURE_START_STOP_DAEMON_FANCY((opt & SSD_OPT_OKNODO)
				? 0 :) !!(i<=0);
	}

	do_procinit();

	if (found) {
		if (!quiet)
			printf("%s already running.\n%d\n", execname ,found->pid);
		USE_FEATURE_START_STOP_DAEMON_FANCY(return !(opt & SSD_OPT_OKNODO);)
		SKIP_FEATURE_START_STOP_DAEMON_FANCY(return EXIT_FAILURE;)
	}
	*--argv = startas;
	if (opt & SSD_OPT_BACKGROUND) {
		xdaemon(0, 0);
		setsid();
	}
	if (opt & SSD_OPT_MAKEPID) {
		/* user wants _us_ to make the pidfile */
		FILE *pidf = xfopen(pidfile, "w");

		pid_t pidt = getpid();
		fprintf(pidf, "%d\n", pidt);
		fclose(pidf);
	}
	if(chuid) {
		if(sscanf(chuid, "%d", &user_id) != 1)
			user_id = bb_xgetpwnam(chuid);
		setuid(user_id);
	}
	execv(startas, argv);
	bb_perror_msg_and_die ("unable to start %s", startas);
}
