Implement signals, finally! #30
@ -328,7 +328,14 @@ int main()
|
||||
{
|
||||
if (service.pid.has_value() && service.pid.value() == child)
|
||||
{
|
||||
do_log("[init] service %s exited with status %d\n", service.name.chars(), WEXITSTATUS(status));
|
||||
if (WIFEXITED(status))
|
||||
{
|
||||
do_log("[init] service %s exited with status %d\n", service.name.chars(), WEXITSTATUS(status));
|
||||
}
|
||||
else
|
||||
{
|
||||
do_log("[init] service %s was terminated by signal %d\n", service.name.chars(), WTERMSIG(status));
|
||||
}
|
||||
|
||||
if (service.restart)
|
||||
{
|
||||
|
@ -62,7 +62,7 @@ Result<u64> sys_kill(Registers*, SyscallArgs args)
|
||||
if (target->is_kernel) return 0;
|
||||
if (signo == 0) return 0;
|
||||
|
||||
target->pending_signals |= 1 << (signo - 1);
|
||||
target->send_signal(signo);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -4,6 +4,7 @@
|
||||
#include "thread/Scheduler.h"
|
||||
#include <bits/atfile.h>
|
||||
#include <bits/open-flags.h>
|
||||
#include <bits/waitpid.h>
|
||||
#include <luna/Alloc.h>
|
||||
#include <luna/Atomic.h>
|
||||
#include <luna/PathParser.h>
|
||||
@ -70,7 +71,7 @@ Result<SharedPtr<VFS::Inode>> Thread::resolve_atfile(int dirfd, const String& pa
|
||||
return VFS::resolve_path(path.chars(), this->auth, descriptor->inode, follow_last_symlink);
|
||||
}
|
||||
|
||||
[[noreturn]] void Thread::exit_and_signal_parent(u8 _status)
|
||||
[[noreturn]] void Thread::exit_and_signal_parent(int _status)
|
||||
{
|
||||
if (this->id == 1) fail("the init process exited");
|
||||
if (is_kernel) state = ThreadState::Dying;
|
||||
@ -140,7 +141,8 @@ void Thread::process_pending_signals(Registers* current_regs)
|
||||
{
|
||||
case DefaultSignalAction::Ignore: return;
|
||||
// FIXME: Add signal exit codes.
|
||||
case DefaultSignalAction::Terminate: exit_and_signal_parent(255);
|
||||
case DefaultSignalAction::Terminate: exit_and_signal_parent(signo | _SIGBIT);
|
||||
default: return;
|
||||
}
|
||||
}
|
||||
// If we fail to deliver the signal (usually because there's not enough space on the stack), execute the
|
||||
@ -151,6 +153,12 @@ void Thread::process_pending_signals(Registers* current_regs)
|
||||
}
|
||||
}
|
||||
|
||||
void Thread::send_signal(int signo)
|
||||
{
|
||||
check(signo > 0 && signo <= NSIG);
|
||||
pending_signals |= 1 << (signo - 1);
|
||||
}
|
||||
|
||||
bool FileDescriptor::should_append()
|
||||
{
|
||||
return flags & O_APPEND;
|
||||
|
@ -91,7 +91,7 @@ struct Thread : public LinkedListNode<Thread>
|
||||
|
||||
bool is_kernel { true };
|
||||
|
||||
u8 status { 0 };
|
||||
int status { 0 };
|
||||
|
||||
mode_t umask { 0 };
|
||||
|
||||
@ -110,7 +110,7 @@ struct Thread : public LinkedListNode<Thread>
|
||||
|
||||
PageDirectory* active_directory { nullptr };
|
||||
|
||||
[[noreturn]] void exit_and_signal_parent(u8 status);
|
||||
[[noreturn]] void exit_and_signal_parent(int status);
|
||||
|
||||
bool is_idle()
|
||||
{
|
||||
@ -144,6 +144,8 @@ struct Thread : public LinkedListNode<Thread>
|
||||
Result<u64> push_mem_on_stack(const u8* mem, usize size);
|
||||
Result<u64> pop_mem_from_stack(u8* mem, usize size);
|
||||
|
||||
void send_signal(int signo);
|
||||
|
||||
static void init();
|
||||
};
|
||||
|
||||
|
@ -3,6 +3,8 @@
|
||||
#ifndef _BITS_WAITPID_H
|
||||
#define _BITS_WAITPID_H
|
||||
|
||||
#define _SIGBIT 0x100
|
||||
|
||||
#define WNOHANG 1
|
||||
|
||||
#endif
|
||||
|
@ -6,8 +6,10 @@
|
||||
#include <bits/waitpid.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#define WIFEXITED(ret) ((ret) | 0)
|
||||
#define WIFEXITED(ret) (((ret)&_SIGBIT) == 0)
|
||||
#define WEXITSTATUS(ret) ((ret)&0xff)
|
||||
#define WIFSIGNALED(ret) (((ret)&_SIGBIT) == _SIGBIT)
|
||||
#define WTERMSIG(ret) ((ret)&0xff)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
|
Loading…
Reference in New Issue
Block a user