mirror of
https://gitlab.com/sortix/sortix.git
synced 2023-02-13 20:55:38 -05:00
init(1) now restarts the shell upon crash.
This commit is contained in:
parent
10291fcb38
commit
a24e86e751
1 changed files with 22 additions and 11 deletions
|
@ -28,13 +28,6 @@
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int parent(pid_t childid)
|
|
||||||
{
|
|
||||||
int status;
|
|
||||||
waitpid(childid, &status, 0);
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
int child()
|
int child()
|
||||||
{
|
{
|
||||||
const char* programname = "sh";
|
const char* programname = "sh";
|
||||||
|
@ -46,6 +39,27 @@ int child()
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int runsystem()
|
||||||
|
{
|
||||||
|
pid_t childpid = fork();
|
||||||
|
if ( childpid < 0 ) { perror("fork"); return 2; }
|
||||||
|
|
||||||
|
if ( childpid )
|
||||||
|
{
|
||||||
|
int status;
|
||||||
|
waitpid(childpid, &status, 0);
|
||||||
|
// TODO: Use the proper macro!
|
||||||
|
if ( 128 <= status )
|
||||||
|
{
|
||||||
|
printf("Looks like the system crashed, trying to bring it back up.\n");
|
||||||
|
return runsystem();
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
return child();
|
||||||
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
if ( open("/dev/tty", O_RDONLY) != 0 ) { return 2; }
|
if ( open("/dev/tty", O_RDONLY) != 0 ) { return 2; }
|
||||||
|
@ -56,9 +70,6 @@ int main(int argc, char* argv[])
|
||||||
printf("\r\e[m\e[J");
|
printf("\r\e[m\e[J");
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
pid_t childpid = fork();
|
return runsystem();
|
||||||
if ( childpid < 0 ) { perror("fork"); return 2; }
|
|
||||||
|
|
||||||
return ( childpid == 0 ) ? child() : parent(childpid);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue