git://scm.lunaixsky.com
/
lunaix-os.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
feat: kill(2) implementation
[lunaix-os.git]
/
lunaix-os
/
kernel
/
lxinit.c
diff --git
a/lunaix-os/kernel/lxinit.c
b/lunaix-os/kernel/lxinit.c
index 2de87c5900d59d773499f956123eaae871ba89fe..fa5ce38783fc301b35e5fa0e452fcc9522acc933 100644
(file)
--- a/
lunaix-os/kernel/lxinit.c
+++ b/
lunaix-os/kernel/lxinit.c
@@
-25,6
+25,14
@@
sigchild_handler(int signum)
kprintf(KINFO "SIGCHLD received\n");
}
kprintf(KINFO "SIGCHLD received\n");
}
+void __USER__
+sigsegv_handler(int signum)
+{
+ pid_t pid = getpid();
+ kprintf(KWARN "SIGSEGV received on process %d\n", pid);
+ _exit(signum);
+}
+
void __USER__
_lxinit_main()
{
void __USER__
_lxinit_main()
{
@@
-39,6
+47,7
@@
_lxinit_main()
#endif
signal(_SIGCHLD, sigchild_handler);
#endif
signal(_SIGCHLD, sigchild_handler);
+ signal(_SIGSEGV, sigsegv_handler);
int status;
#ifdef WAIT_DEMO
int status;
#ifdef WAIT_DEMO
@@
-67,9
+76,10
@@
_lxinit_main()
waitpid(-1, &status, WNOHANG);
waitpid(-1, &status, WNOHANG);
- for (size_t i = 0; i <
10
; i++) {
+ for (size_t i = 0; i <
5
; i++) {
pid_t pid = 0;
if (!(pid = fork())) {
pid_t pid = 0;
if (!(pid = fork())) {
+ signal(_SIGSEGV, sigsegv_handler);
sleep(i);
if (i == 3) {
i = *(int*)0xdeadc0de; // seg fault!
sleep(i);
if (i == 3) {
i = *(int*)0xdeadc0de; // seg fault!
@@
-83,7
+93,11
@@
_lxinit_main()
while ((p = wait(&status)) >= 0) {
short code = WEXITSTATUS(status);
while ((p = wait(&status)) >= 0) {
short code = WEXITSTATUS(status);
- if (WIFEXITED(status)) {
+ if (WIFSIGNALED(status)) {
+ kprintf(KINFO "Process %d terminated by signal, exit_code: %d\n",
+ p,
+ code);
+ } else if (WIFEXITED(status)) {
kprintf(KINFO "Process %d exited with code %d\n", p, code);
} else {
kprintf(KWARN "Process %d aborted with code %d\n", p, code);
kprintf(KINFO "Process %d exited with code %d\n", p, code);
} else {
kprintf(KWARN "Process %d aborted with code %d\n", p, code);