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:
parent
1369aa9da9
commit
b9b697f2cb
|
@ -31,6 +31,18 @@ __BEGIN_DECLS
|
||||||
|
|
||||||
#define WNOHANG (1<<0)
|
#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
|
__END_DECLS
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -374,7 +374,7 @@ namespace Sortix
|
||||||
|
|
||||||
int exitstatus = zombie->exitstatus;
|
int exitstatus = zombie->exitstatus;
|
||||||
if ( exitstatus < 0 )
|
if ( exitstatus < 0 )
|
||||||
exitstatus = 0;
|
exitstatus = W_EXITCODE(128 + SIGKILL, SIGKILL);
|
||||||
|
|
||||||
// TODO: Validate that status is a valid user-space int!
|
// TODO: Validate that status is a valid user-space int!
|
||||||
if ( status )
|
if ( status )
|
||||||
|
@ -396,7 +396,7 @@ namespace Sortix
|
||||||
ScopedLock lock(&threadlock);
|
ScopedLock lock(&threadlock);
|
||||||
// Status codes can only contain 8 bits according to ISO C and POSIX.
|
// Status codes can only contain 8 bits according to ISO C and POSIX.
|
||||||
if ( exitstatus == -1 )
|
if ( exitstatus == -1 )
|
||||||
exitstatus = status % 256;
|
exitstatus = W_EXITCODE(status & 0xFF, 0);
|
||||||
|
|
||||||
// Broadcast SIGKILL to all our threads which will begin our long path
|
// 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
|
// of process termination. We simply can't stop the threads as they may
|
||||||
|
|
|
@ -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 < 0 ) { perror("fork"); exit(1); }
|
||||||
if ( childpid )
|
if ( childpid )
|
||||||
{
|
{
|
||||||
// TODO: Use the right WEXITSTATUS-ish macros here!
|
|
||||||
int status;
|
int status;
|
||||||
waitpid(childpid, &status, 0);
|
waitpid(childpid, &status, 0);
|
||||||
if ( !SetCurrentMode(prevmode) )
|
if ( !SetCurrentMode(prevmode) )
|
||||||
{
|
{
|
||||||
error(1, errno, "Unable to restore video mode: %s", prevmode);
|
error(1, errno, "Unable to restore video mode: %s", prevmode);
|
||||||
}
|
}
|
||||||
exit(status);
|
exit(WEXITSTATUS(status));
|
||||||
}
|
}
|
||||||
execvp(argv[1], argv + 1);
|
execvp(argv[1], argv + 1);
|
||||||
perror(argv[1]);
|
perror(argv[1]);
|
||||||
|
|
|
@ -50,7 +50,7 @@ int runsystem()
|
||||||
int status;
|
int status;
|
||||||
waitpid(childpid, &status, 0);
|
waitpid(childpid, &status, 0);
|
||||||
// TODO: Use the proper macro!
|
// 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");
|
printf("Looks like the system crashed, trying to bring it back up.\n");
|
||||||
return runsystem();
|
return runsystem();
|
||||||
|
|
|
@ -173,21 +173,26 @@ readcmd:
|
||||||
}
|
}
|
||||||
|
|
||||||
status = internalresult;
|
status = internalresult;
|
||||||
if ( !internal && waitpid(childpid, &status, 0) < 0 )
|
int exitstatus;
|
||||||
|
if ( !internal && waitpid(childpid, &exitstatus, 0) < 0 )
|
||||||
{
|
{
|
||||||
perror("waitpid");
|
perror("waitpid");
|
||||||
return 127;
|
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 )
|
if ( strcmp(execmode, ";") == 0 && tokens[cmdnext] && !lastcmd )
|
||||||
{
|
{
|
||||||
goto readcmd;
|
goto readcmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Hack, use the right macros!
|
|
||||||
if ( status == 128 + SIGINT )
|
|
||||||
printf("^C\n");
|
|
||||||
|
|
||||||
result = status;
|
result = status;
|
||||||
goto out;
|
goto out;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue