Implement signals, finally! #30
10
apps/sh.cpp
10
apps/sh.cpp
@ -6,6 +6,7 @@
|
||||
#include <os/FileSystem.h>
|
||||
#include <os/Process.h>
|
||||
#include <pwd.h>
|
||||
#include <signal.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
@ -117,7 +118,14 @@ Result<int> luna_main(int argc, char** argv)
|
||||
|
||||
if (child == 0) { TRY(execute_command(cmd.view())); }
|
||||
|
||||
TRY(os::Process::wait(child, nullptr));
|
||||
int status;
|
||||
TRY(os::Process::wait(child, &status));
|
||||
|
||||
if (WIFSIGNALED(status))
|
||||
{
|
||||
int sig = WTERMSIG(status);
|
||||
if (sig != SIGINT && sig != SIGQUIT) os::println("[sh] Process %d exited: %s", child, strsignal(sig));
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -62,6 +62,9 @@ extern "C"
|
||||
/* Return the human-readable description of an error number. */
|
||||
char* strerror(int errnum);
|
||||
|
||||
/* Return the human-readable description of a signal number. */
|
||||
char* strsignal(int signo);
|
||||
|
||||
/* Return the length of the initial segment of str which consists only of bytes in accept. */
|
||||
size_t strspn(const char* str, const char* accept);
|
||||
|
||||
|
@ -1,3 +1,4 @@
|
||||
#include <bits/signal.h>
|
||||
#include <luna/SystemError.h>
|
||||
#include <string.h>
|
||||
|
||||
@ -12,4 +13,32 @@ extern "C"
|
||||
{
|
||||
return const_cast<char*>(error_string(errnum));
|
||||
}
|
||||
|
||||
static const char* __internal_strsignal(int signo)
|
||||
{
|
||||
switch (signo)
|
||||
{
|
||||
case SIGHUP: return "Hangup";
|
||||
case SIGINT: return "Terminal interrupt";
|
||||
case SIGQUIT: return "Terminal quit";
|
||||
case SIGILL: return "Invalid opcode";
|
||||
case SIGTRAP: return "Breakpoint trap";
|
||||
case SIGABRT: return "Aborted";
|
||||
case SIGCHLD: return "Child stopped or exited";
|
||||
case SIGFPE: return "Floating point exception";
|
||||
case SIGKILL: return "Killed";
|
||||
case SIGSTOP: return "Stopped";
|
||||
case SIGSEGV: return "Segmentation fault";
|
||||
case SIGCONT: return "Continued";
|
||||
case SIGPIPE: return "Broken pipe";
|
||||
case SIGALRM: return "Alarm signal";
|
||||
case SIGTERM: return "Terminated";
|
||||
default: return "Unknown signal";
|
||||
}
|
||||
}
|
||||
|
||||
char* strsignal(int signo)
|
||||
{
|
||||
return const_cast<char*>(__internal_strsignal(signo));
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user