/* vi: set sw=4 ts=4: */
/*
 * Mini run-parts implementation for busybox
 *
 * Copyright (C) 2007 Bernhard Fischer
 *
 * Based on a older version that was in busybox which was 1k big..
 *   Copyright (C) 2001 by Emanuele Aina <emanuele.aina@tiscali.it>
 *
 * Based on the Debian run-parts program, version 1.15
 *   Copyright (C) 1996 Jeff Noxon <jeff@router.patch.net>,
 *   Copyright (C) 1996-1999 Guy Maor <maor@debian.org>
 *
 *
 * Licensed under GPL v2 or later, see file LICENSE in this tarball for details.
 */

/* This is my first attempt to write a program in C (well, this is my first
 * attempt to write a program! :-) . */

/* This piece of code is heavily based on the original version of run-parts,
 * taken from debian-utils. I've only removed the long options and a the
 * report mode. As the original run-parts support only long options, I've
 * broken compatibility because the BusyBox policy doesn't allow them.
 * The supported options are:
 * -t			test. Print the name of the files to be executed, without
 *				execute them.
 * -a ARG		argument. Pass ARG as an argument the program executed. It can
 *				be repeated to pass multiple arguments.
 * -u MASK		umask. Set the umask of the program executed to MASK.
 */


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

#if ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS
static const struct option runparts_long_options[] = {
	{ "arg",        1,      NULL,   'a' },
	{ "umask",      1,      NULL,   'u' },
	{ "test",       0,      NULL,   't' },
#if ENABLE_FEATURE_RUN_PARTS_FANCY
	{ "list",       0,      NULL,   'l' },
//XXX:TODO:	{ "reverse",       0,      NULL,   'r' },
//XXX:TODO:	{ "verbose",       0,      NULL,   'v' },
#endif
	{ 0,            0,      0,      0   }
};
#endif

struct globals {
	smalluint mode;
	char *cmd[10]; /* merely arbitrary arg count */
};
#define G (*(struct globals*)&bb_common_bufsiz1)

/* valid_name */
/* True or false? Is this a valid filename (upper/lower alpha, digits,
 * underscores, and hyphens only?)
 */
static bool invalid_name(const char *c)
{
	const char *base_name = strrchr(c, '/');

	if (base_name)
		c = base_name + 1;

	while (*c && (isalnum(*c) || *c == '_' || *c == '-'))
		c++;

	return *c; /* TRUE (!0) if terminating NUL is not reached */
}

#define RUN_PARTS_OPT_a (1<<0)
#define RUN_PARTS_OPT_u (1<<1)
#define RUN_PARTS_OPT_t (1<<2)
#if ENABLE_FEATURE_RUN_PARTS_FANCY
#define RUN_PARTS_OPT_l (1<<3)
#endif

#define test_mode (G.mode & RUN_PARTS_OPT_t)
#if ENABLE_FEATURE_RUN_PARTS_FANCY
#define list_mode (G.mode & RUN_PARTS_OPT_l)
#else
#define list_mode (0)
#endif

static int act(const char *file, struct stat *statbuf, void *args, int depth)
{
	int ret;

	if (depth == 1)
		return TRUE;

	if (depth == 2 &&
		((!list_mode && access(file, X_OK)) ||
		 invalid_name(file) ||
		 !(statbuf->st_mode & (S_IFREG | S_IFLNK))) )
		return SKIP;

	if (test_mode || list_mode) {
		puts(file);
		return TRUE;
	}
	G.cmd[0] = (char*)file;
	ret = wait4pid(spawn(G.cmd));
	if (ret < 0) {
		bb_perror_msg("failed to exec %s", file);
	} else if (ret > 0) {
		bb_error_msg("%s exited with return code %d", file, ret);
	}
	return !ret;
}

int run_parts_main(int argc, char **argv);
int run_parts_main(int argc, char **argv)
{
	char *umask_p;
	llist_t *arg_list = NULL;
	unsigned tmp;

	umask(022);
	/* We require exactly one argument: the directory name */
	opt_complementary = "=1:a::";
#if ENABLE_FEATURE_RUN_PARTS_LONG_OPTIONS
	applet_long_options = runparts_long_options;
#endif
	tmp = getopt32(argc, argv, "a:u:t"USE_FEATURE_RUN_PARTS_FANCY("l"), &arg_list, &umask_p);
	G.mode = tmp &~ (RUN_PARTS_OPT_a|RUN_PARTS_OPT_u);
	if (tmp & RUN_PARTS_OPT_u) {
		/* Check and set the umask of the program executed.
		 * As stated in the original run-parts, the octal conversion in
		 * libc is not foolproof; it will take the 8 and 9 digits under
		 * some circumstances. We'll just have to live with it.
		 */
		umask(xstrtoul_range(umask_p, 8, 0, 07777));
	}
	for (tmp = 1; arg_list; arg_list = arg_list->link, tmp++)
		G.cmd[tmp] = arg_list->data;
	/* G.cmd[tmp] = NULL; - G is already zeroed out */
	if (!recursive_action(argv[argc - 1],
			ACTION_RECURSE|ACTION_FOLLOWLINKS,
			act,		/* file action */
			act,		/* dir action */
			NULL,		/* user data */
			1			/* depth */
			))
			return EXIT_FAILURE;
	return EXIT_SUCCESS;
}
