1
0
Fork 0
mirror of https://gitlab.com/sortix/sortix.git synced 2023-02-13 20:55:38 -05:00

Implement proper W* error codes in sys/wait.h and kernel.

Note that signals can't really kill a process at this time.
This commit is contained in:
Jonas 'Sortie' Termansen 2012-09-09 12:21:39 +02:00
parent 1369aa9da9
commit b9b697f2cb
5 changed files with 26 additions and 10 deletions

View file

@ -31,6 +31,18 @@ __BEGIN_DECLS
#define WNOHANG (1<<0)
#define WEXITSTATUS(status) ((status >> 8) & 0xFF)
#define WTERMSIG(status) ((status >> 0) & 0x7F)
#define WSTOPSIG(status) WTERMSIG(status)
#define WIFEXITED(status) (WTERMSIG(status) == 0)
#define WIFSIGNALED(status) (WTERMSIG(status) != 0)
/*#define WIFCONTINUED(status) (WTERMSIG(status) == TODO)*/
/*#define WIFSTOPPED(status) (WTERMSIG(status) == TODO)*/
/*#define WIFCONTINUED(status) (WTERMSIG(status) == TODO)*/
#define W_EXITCODE(ret, sig) ((ret) << 8 | (sig))
#define W_STOPCODE(sig) ((sig) << 8 | 0x7f)
__END_DECLS
#endif

View file

@ -374,7 +374,7 @@ namespace Sortix
int exitstatus = zombie->exitstatus;
if ( exitstatus < 0 )
exitstatus = 0;
exitstatus = W_EXITCODE(128 + SIGKILL, SIGKILL);
// TODO: Validate that status is a valid user-space int!
if ( status )
@ -396,7 +396,7 @@ namespace Sortix
ScopedLock lock(&threadlock);
// Status codes can only contain 8 bits according to ISO C and POSIX.
if ( exitstatus == -1 )
exitstatus = status % 256;
exitstatus = W_EXITCODE(status & 0xFF, 0);
// Broadcast SIGKILL to all our threads which will begin our long path
// of process termination. We simply can't stop the threads as they may

View file

@ -365,14 +365,13 @@ Try make sure the desired driver is loaded and is configured correctly.\n");
if ( childpid < 0 ) { perror("fork"); exit(1); }
if ( childpid )
{
// TODO: Use the right WEXITSTATUS-ish macros here!
int status;
waitpid(childpid, &status, 0);
if ( !SetCurrentMode(prevmode) )
{
error(1, errno, "Unable to restore video mode: %s", prevmode);
}
exit(status);
exit(WEXITSTATUS(status));
}
execvp(argv[1], argv + 1);
perror(argv[1]);

View file

@ -50,7 +50,7 @@ int runsystem()
int status;
waitpid(childpid, &status, 0);
// TODO: Use the proper macro!
if ( 128 <= status )
if ( 128 <= WEXITSTATUS(status) || WIFSIGNALED(status) )
{
printf("Looks like the system crashed, trying to bring it back up.\n");
return runsystem();

View file

@ -173,21 +173,26 @@ readcmd:
}
status = internalresult;
if ( !internal && waitpid(childpid, &status, 0) < 0 )
int exitstatus;
if ( !internal && waitpid(childpid, &exitstatus, 0) < 0 )
{
perror("waitpid");
return 127;
}
// TODO: HACK: Most signals can't kill processes yet.
if ( WEXITSTATUS(exitstatus) == 128 + SIGINT )
printf("^C\n");
if ( WTERMSIG(status) == SIGKILL )
printf("Killed\n");
status = WEXITSTATUS(exitstatus);
if ( strcmp(execmode, ";") == 0 && tokens[cmdnext] && !lastcmd )
{
goto readcmd;
}
// TODO: Hack, use the right macros!
if ( status == 128 + SIGINT )
printf("^C\n");
result = status;
goto out;
}