diff options
| author | dautor <karlo98.m@gmail.com> | 2024-11-17 20:22:35 +0100 |
|---|---|---|
| committer | dautor <karlo98.m@gmail.com> | 2024-11-17 20:22:35 +0100 |
| commit | c22c6581ee39688785476fe56f2b759ae49ca04a (patch) | |
| tree | ef27183c28f4a0034e734cc9a794241c1c05c188 /src/lamina/main.c | |
| parent | 3c75d353ed3361e86792fb726e31111a0b4199a9 (diff) | |
Open shell on lamina recipe error
Diffstat (limited to 'src/lamina/main.c')
| -rw-r--r-- | src/lamina/main.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/lamina/main.c b/src/lamina/main.c index 2314019..f461058 100644 --- a/src/lamina/main.c +++ b/src/lamina/main.c @@ -528,6 +528,38 @@ Cleanup(void) if(MountsCleanup == true) unmount_all(); } +static int +Shell(void) +{ + pid_t PID = fork(); + if(PID == -1) + { + fprintf(stderr, "fork: %s\n", strerror(errno)); + return -1; + } + if(PID == 0) + { + close_all(); + if(chroot(Root) == -1) + { + fprintf(stderr, "chroot %s: %s\n", Root, strerror(errno)); + exit(-1); + } + if(chdir("/") == -1) + { + fprintf(stderr, "chdir /: %s\n", strerror(errno)); + exit(-1); + } + execlp("/bin/sh", "sh", NULL); + fprintf(stderr, "execlp /bin/sh: %s\n", strerror(errno)); + exit(-1); + } + int Exit; + waitpid(PID, &Exit, 0); + if(!WIFEXITED(Exit) || (WEXITSTATUS(Exit) != 0)) return -1; + return 0; +} + int main(int ArgCount, char **Arg) { @@ -567,6 +599,8 @@ main(int ArgCount, char **Arg) if(Execute(Line, (size_t)LineLength) == -1) { fprintf(stderr, "(line %zu)\n", LineAt); + fprintf(stderr, "starting a shell inside %s\n", Root); + Shell(); break; } } |
