Skip to content

Commit

Permalink
Set the current directory correctly when there's no root
Browse files Browse the repository at this point in the history
  • Loading branch information
tbodt committed Nov 15, 2017
1 parent bdb81f2 commit 6e85bf4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion app/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ - (int)startThings {
char *program = "/bin/login";
char *argv[] = {program, NULL};
char *envp[] = {NULL};
err = create_init_process(program, argv, envp);
err = sys_execve(program, argv, envp);
if (err < 0)
return err;
err = create_stdio(ios_tty_driver);
Expand Down
7 changes: 1 addition & 6 deletions kernel/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,7 @@ int mount_root(const struct fs_ops *fs, const char *source) {

static void nop_handler() {}

// this function parses command line arguments and initializes global
// data structures. thanks programming discussions discord server for the name.
// https://discord.gg/9zT7NHP
int create_init_process(const char *program, char *const argv[], char *const envp[]) {
void create_first_process() {
signal(SIGUSR1, nop_handler);

current = process_create();
Expand All @@ -36,8 +33,6 @@ int create_init_process(const char *program, char *const argv[], char *const env
current->umask = 0022;
current->thread = pthread_self();
sys_setsid();

return sys_execve(program, argv, envp);
}

int create_stdio(struct tty_driver driver) {
Expand Down
2 changes: 1 addition & 1 deletion kernel/init.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "fs/tty.h"

int mount_root(const struct fs_ops *fs, const char *source);
int create_init_process(const char *program, char *const argv[], char *const envp[]);
void create_first_process();
int create_stdio(struct tty_driver driver);

#endif
18 changes: 16 additions & 2 deletions xX_main_Xx.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,24 @@ static inline int xX_main_Xx(int argc, char *const argv[]) {
perror(root);
exit(1);
}
mount_root(&fakefs, root_realpath);
const struct fs_ops *fs;
if (strcmp(strrchr(root_realpath, '/') + 1, "data") == 0)
fs = &fakefs;
else
fs = &realfs;
mount_root(fs, root_realpath);

create_first_process();
if (!has_root) {
char cwd[MAX_PATH + 1];
getcwd(cwd, sizeof(cwd));
struct fd *pwd = generic_open(cwd, O_RDONLY_, 0);
fd_close(current->pwd);
current->pwd = pwd;
}

char *envp[] = {NULL};
int err = create_init_process(argv[optind], argv + optind, envp);
int err = sys_execve(argv[optind], argv + optind, envp);
if (err < 0)
return err;
err = create_stdio(real_tty_driver);
Expand Down

0 comments on commit 6e85bf4

Please sign in to comment.