<commit_before>/**
 * @file
 *
 * @brief
 *
 * @date 13.09.2011
 * @author <NAME>
 * @author <NAME>
 * 	- shell invocation
 */

#include <string.h>
#include <unistd.h>
#include <kernel/thread.h>
#include <kernel/sched.h>
#include <hal/context.h>
#include <cmd/shell.h>

extern void vfork_release_parent(void);

#define EXEC_LEN 16
static char exec_path[EXEC_LEN];

#if 0
#define EXEC_ARGC 8
static int  exec_argc;
static char exec_argv[EXEC_ARGC][EXEC_LEN];
#endif

static void exec_trampoline(void) {
	const struct shell *sh;
	const char *default_shells[] = { "/bin/sh", "sh", NULL };
	const char **shellp;
	const char *path = exec_path;
	int ecode;

	sched_unlock();

	vfork_release_parent();

	sh = shell_lookup(path);
	if (!sh) {
		for (shellp = default_shells; *shellp != NULL; shellp++) {
			if (!strcmp(*shellp, path)) {
				sh = shell_lookup("tish");
				break;
			}
		}
	}

	/* FIXME pass argv to shell_exec */
	ecode = sh ? shell_run(sh) : shell_exec(shell_any(), path);

	_exit(ecode);
}

int execv(const char *path, char *const argv[]) {
	struct context oldctx;
	struct thread *t;
<commit_msg>fork: exec sets task's module ptr to command, calls cmd_exec directry<commit_after>/**
 * @file
 *
 * @brief
 *
 * @date 13.09.2011
 * @author <NAME>
 * @author <NAME>
 * 	- shell invocation
 */

#include <string.h>
#include <unistd.h>
#include <kernel/thread.h>
#include <kernel/sched.h>
#include <hal/context.h>

#include <kernel/task/resource/module_ptr.h>
#include <framework/cmd/api.h>
#include <cmd/shell.h>

extern void vfork_release_parent(void);

#define EXEC_LEN 32
static char exec_path[EXEC_LEN];

#if 0
#define EXEC_ARGC 8
static int  exec_argc;
static char exec_argv[EXEC_ARGC][EXEC_LEN];
#endif

static void exec_trampoline(void) {
	const struct shell *sh;
	const char *default_shells[] = { "/bin/sh", "sh", NULL };
	const char **shellp;
	char *path = exec_path;
	int ecode;

	sched_unlock();

	vfork_release_parent();

	sh = shell_lookup(path);
	if (!sh) {
		for (shellp = default_shells; *shellp != NULL; shellp++) {
			if (!strcmp(*shellp, path)) {
				sh = shell_lookup("tish");
				break;
			}
		}
	}

	/* FIXME pass argv to shell_exec */
	if (sh) {
		ecode = shell_run(sh);
	} else {
		const struct cmd *cmd;

		cmd = cmd_lookup(path);

		if (cmd) {
			char *argv[] = { path, NULL };

			task_self_module_ptr_set(cmd2mod(cmd));
			ecode = cmd_exec(cmd, 1, argv);
		} else {
			ecode = ENOENT;
		}

	}

	_exit(ecode);
}

int execv(const char *path, char *const argv[]) {
	struct context oldctx;
	struct thread *t;

{'fraction_non_alphanumeric': 0.1543914927136668, 'fraction_numerical': 0.010240252067743205, 'mean_word_length': 3.9609375, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3489550', 'n_tokens_mistral': 1057, 'n_tokens_neox': 979, 'n_words': 249}