Example #1
0
int main(int argc, char *argv[]) {
        int r = EXIT_SUCCESS;

        if (argc > 1 && argc != 4) {
                log_error("This program takes three or no arguments.");
                return EXIT_FAILURE;
        }

        if (argc > 1)
                arg_dest = argv[1];

        log_set_target(LOG_TARGET_SAFE);
        log_parse_environment();
        log_open();

        umask(0022);

        if (file_is_executable(RC_LOCAL_SCRIPT_PATH_START)) {
                log_debug("Automatically adding rc-local.service.");

                if (add_symlink("rc-local.service", "multi-user.target") < 0)
                        r = EXIT_FAILURE;
        }

        if (file_is_executable(RC_LOCAL_SCRIPT_PATH_STOP)) {
                log_debug("Automatically adding halt-local.service.");

                if (add_symlink("halt-local.service", "final.target") < 0)
                        r = EXIT_FAILURE;
        }

        return r;
}
Example #2
0
/* search (*PATHp) for an executable file;
 * return allocated string containing full path if found;
 *  PATHp points to the component after the one where it was found
 *  (or NULL),
 *  you may call find_executable again with this PATHp to continue
 *  (if it's not NULL).
 * return NULL otherwise; (PATHp is undefined)
 * in all cases (*PATHp) contents will be trashed (s/:/NUL/).
 */
char* FAST_FUNC find_executable(const char *filename, char **PATHp)
{
	/* About empty components in $PATH:
	 * http://pubs.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html
	 * 8.3 Other Environment Variables - PATH
	 * A zero-length prefix is a legacy feature that indicates the current
	 * working directory. It appears as two adjacent colons ( "::" ), as an
	 * initial colon preceding the rest of the list, or as a trailing colon
	 * following the rest of the list.
	 */
	char *p, *n;

	p = *PATHp;
	while (p) {
		n = strchr(p, ':');
		if (n)
			*n++ = '\0';
		p = concat_path_file(
			p[0] ? p : ".", /* handle "::" case */
			filename
		);
		if (file_is_executable(p)) {
			*PATHp = n;
			return p;
		}
		free(p);
		p = n;
	} /* on loop exit p == NULL */
	return p;
}
Example #3
0
int which_main(int argc UNUSED_PARAM, char **argv)
{
	const char *env_path;
	int status = 0;

	env_path = getenv("PATH");
	if (!env_path)
		env_path = bb_default_root_path;

	opt_complementary = "-1"; /* at least one argument */
	getopt32(argv, "a");
	argv += optind;

	do {
		int missing = 1;

		/* If file contains a slash don't use PATH */
		if (strchr(*argv, '/')) {
			if (file_is_executable(*argv)) {
				missing = 0;
				puts(*argv);
			}
		} else {
			char *path;
			char *tmp;
			char *p;

			path = tmp = xstrdup(env_path);
			while ((p = find_executable(*argv, &tmp)) != NULL) {
				missing = 0;
				puts(p);
				free(p);
				if (!option_mask32) /* -a not set */
					break;
			}
			free(path);
		}
		status |= missing;
	} while (*++argv);

	return status;
}