summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--sys/include/sys/spawn.h2
-rw-r--r--sys/kern/kern_spawn.c18
-rw-r--r--usr.bin/login/login.c3
-rw-r--r--usr.bin/osh/osh.c50
-rw-r--r--usr.sbin/init/main.c3
-rw-r--r--usr.sbin/install/install.c8
6 files changed, 40 insertions, 44 deletions
diff --git a/sys/include/sys/spawn.h b/sys/include/sys/spawn.h
index 0c54e4c..28dbe5b 100644
--- a/sys/include/sys/spawn.h
+++ b/sys/include/sys/spawn.h
@@ -33,8 +33,6 @@
#include <sys/types.h>
#include <sys/param.h>
-#define SPAWN_WAIT BIT(0)
-
#if !defined(_KERNEL)
pid_t spawn(const char *pathname, char **argv, char **envp, int flags);
#endif /* _KERNEL */
diff --git a/sys/kern/kern_spawn.c b/sys/kern/kern_spawn.c
index c1c0029..b9551f3 100644
--- a/sys/kern/kern_spawn.c
+++ b/sys/kern/kern_spawn.c
@@ -203,24 +203,6 @@ spawn(struct proc *cur, void(*func)(void), void *p, int flags, struct proc **new
signals_init(newproc);
sched_enqueue_td(newproc);
pid = newproc->pid;
-
- if (ISSET(flags, SPAWN_WAIT)) {
- cur->flags |= PROC_SLEEP;
-
- while (ISSET(cur->flags, PROC_SLEEP)) {
- sched_yield();
- }
- while (!ISSET(newproc->flags, PROC_ZOMB)) {
- sched_yield();
- }
-
- if (newproc->exit_status < 0) {
- pid = newproc->exit_status;
- }
-
- proc_reap(newproc);
- }
-
return pid;
}
diff --git a/usr.bin/login/login.c b/usr.bin/login/login.c
index 93b08ed..5b21303 100644
--- a/usr.bin/login/login.c
+++ b/usr.bin/login/login.c
@@ -104,6 +104,7 @@ check_user(char *alias, char *hash, char *entry)
short have_uid = 0;
short have_shell = 0;
uid_t uid = -1;
+ pid_t shell_pid;
if (alias == NULL || entry == NULL) {
return -EINVAL;
@@ -172,7 +173,7 @@ check_user(char *alias, char *hash, char *entry)
setuid(uid);
shell_argv[0] = shell_path;
- spawn(shell_argv[0], shell_argv, envp, SPAWN_WAIT);
+ shell_pid = spawn(shell_argv[0], shell_argv, envp, 0);
return 0;
}
diff --git a/usr.bin/osh/osh.c b/usr.bin/osh/osh.c
index 5bcd2e2..af0ba3a 100644
--- a/usr.bin/osh/osh.c
+++ b/usr.bin/osh/osh.c
@@ -31,6 +31,7 @@
#include <sys/cdefs.h>
#include <sys/reboot.h>
#include <sys/spawn.h>
+#include <sys/wait.h>
#include <fcntl.h>
#include <stddef.h>
#include <stdbool.h>
@@ -250,16 +251,11 @@ builtin_run(struct builtin_cmd *cmd, int argc, char *argv[])
}
static int
-cmd_run(const char *input, int argc, char *argv[], bool wait)
+cmd_run(const char *input, int argc, char *argv[])
{
char bin_path[512];
char *envp[1] = { NULL };
- int error, spawn_flags = 0;
-
- /* Should we wait or daemonize? */
- if (wait) {
- spawn_flags |= SPAWN_WAIT;
- }
+ pid_t child;
/*
* If we can access the raw input as a file, try to
@@ -268,11 +264,11 @@ cmd_run(const char *input, int argc, char *argv[], bool wait)
* path directly into the console.
*/
if (access(input, F_OK) == 0) {
- error = spawn(input, argv, envp, spawn_flags);
- if (error < 0) {
- return error;
+ child = spawn(input, argv, envp, 0);
+ if (child < 0) {
+ return child;
}
- return 0;
+ return child;
}
snprintf(bin_path, sizeof(bin_path), "/usr/bin/%s", input);
@@ -282,11 +278,11 @@ cmd_run(const char *input, int argc, char *argv[], bool wait)
return -1;
}
- if ((error = spawn(bin_path, argv, envp, spawn_flags)) < 0) {
- return error;
+ if ((child = spawn(bin_path, argv, envp, 0)) < 0) {
+ return child;
}
- return 0;
+ return child;
}
/*
@@ -295,27 +291,29 @@ cmd_run(const char *input, int argc, char *argv[], bool wait)
* @input: Command input
* @argc: Argument count
* @argv: Argument vector
- * @wait: If false, program will be daemonized
*/
-static void
-command_match(const char *input, int argc, char *argv[], bool wait)
+static int
+command_match(const char *input, int argc, char *argv[])
{
int found = 0;
int i;
+ pid_t child = -1;
for (i = 0; cmds[i].name != NULL; i++) {
if (strcmp(input, cmds[i].name) == 0) {
builtin_run(&cmds[i], argc, argv);
found = 1;
- break;
}
}
if (found == 0) {
- if (cmd_run(input, argc, argv, wait) < 0) {
+ if ((child = cmd_run(input, argc, argv)) < 0) {
puts("Unrecognized command");
+ return -1;
}
}
+
+ return child;
}
static void
@@ -335,6 +333,7 @@ open_script(const char *pathname)
int fd, argc, buf_i = 0;
char c, *input, *argv[16];
char buf[256];
+ pid_t child;
fd = open(pathname, O_RDONLY);
if (fd < 0) {
@@ -361,7 +360,11 @@ open_script(const char *pathname)
if (c == '\n') {
buf[buf_i] = '\0';
argc = parse_args(buf, argv, sizeof(argv));
- command_match(buf, argc, argv, true);
+
+ child = command_match(buf, argc, argv);
+ if (child > 0) {
+ waitpid(child, NULL, 0);
+ }
argv[0] = NULL;
argv[1] = NULL;
@@ -381,6 +384,7 @@ main(int argc, char **argv)
int stdout_fd;
char *input, *prog_argv[16], *p;
char c;
+ pid_t child;
if (argc > 1) {
return open_script(argv[1]);
@@ -406,7 +410,11 @@ main(int argc, char **argv)
continue;
}
- command_match(input, prog_argc, prog_argv, true);
+ child = command_match(input, prog_argc, prog_argv);
+ if (child > 0) {
+ waitpid(child, NULL, 0);
+ }
+
found = 0;
buf[0] = '\0';
}
diff --git a/usr.sbin/init/main.c b/usr.sbin/init/main.c
index b5c4fab..e1ee4d8 100644
--- a/usr.sbin/init/main.c
+++ b/usr.sbin/init/main.c
@@ -46,6 +46,7 @@ main(int argc, char **argv)
start_argv[1] = NULL;
/* Start the login manager */
- spawn(login_argv[0], login_argv, envp, SPAWN_WAIT);
+ spawn(login_argv[0], login_argv, envp, 0);
+ for (;;);
return 0;
}
diff --git a/usr.sbin/install/install.c b/usr.sbin/install/install.c
index 91f75df..803c864 100644
--- a/usr.sbin/install/install.c
+++ b/usr.sbin/install/install.c
@@ -32,6 +32,7 @@
#include <sys/fbdev.h>
#include <sys/reboot.h>
#include <sys/spawn.h>
+#include <sys/wait.h>
#include <sys/stat.h>
#include <sys/param.h>
#include <stdio.h>
@@ -85,6 +86,7 @@ pre_installer(void)
char *argv[] = { "/usr/bin/osh", NULL };
char *envp[] = { NULL };
char c;
+ pid_t child = -1;
puts("[S]hell/[I]nstall");
for (;;) {
@@ -92,13 +94,17 @@ pre_installer(void)
if (c == 's') {
puts("\033[0m");
installer_clearscr(0x000000, false);
- spawn(argv[0], argv, envp, SPAWN_WAIT);
+ child = spawn(argv[0], argv, envp, 0);
installer_clearscr(INSTALLER_BG, true);
break;
} else if (c == 'i') {
break;
}
}
+
+ if (child > 0) {
+ waitpid(child, NULL, 0);
+ }
}
static void