Properly set exit code for killed processed.
This commit is contained in:
@@ -4,10 +4,10 @@
|
||||
/// See LICENSE.md for details.
|
||||
|
||||
// Setup the logging for this file (do this before any other include).
|
||||
#include "sys/kernel_levels.h" // Include kernel log levels.
|
||||
#define __DEBUG_HEADER__ "[SCHED ]" ///< Change header.
|
||||
#define __DEBUG_LEVEL__ LOGLEVEL_NOTICE ///< Set log level.
|
||||
#include "io/debug.h" // Include debugging functions.
|
||||
#include "sys/kernel_levels.h" // Include kernel log levels.
|
||||
#define __DEBUG_HEADER__ "[SCHED ]" ///< Change header.
|
||||
#define __DEBUG_LEVEL__ LOGLEVEL_DEBUG ///< Set log level.
|
||||
#include "io/debug.h" // Include debugging functions.
|
||||
|
||||
#include "process/scheduler_feedback.h"
|
||||
#include "process/scheduler.h"
|
||||
@@ -119,7 +119,7 @@ void scheduler_dequeue_task(task_struct *process)
|
||||
--runqueue.num_active;
|
||||
if (process->se.is_periodic)
|
||||
runqueue.num_periodic--;
|
||||
|
||||
|
||||
#ifdef ENABLE_SCHEDULER_FEEDBACK
|
||||
scheduler_feedback_task_remove(process->pid);
|
||||
#endif
|
||||
@@ -485,8 +485,9 @@ pid_t sys_waitpid(pid_t pid, int *status, int options)
|
||||
// Save the pid to return.
|
||||
pid_t ppid = entry->pid;
|
||||
// Save the state (TODO: Improve status set).
|
||||
if (status)
|
||||
(*status) = entry->state;
|
||||
if (status) {
|
||||
(*status) = entry->exit_code;
|
||||
}
|
||||
// Finalize the VFS structures.
|
||||
vfs_destroy_task(entry);
|
||||
// Remove entry from children of parent.
|
||||
@@ -515,7 +516,7 @@ void sys_exit(int exit_code)
|
||||
}
|
||||
|
||||
// Set the termination code of the process.
|
||||
runqueue.curr->exit_code = (exit_code << 8) & 0xFF00;
|
||||
runqueue.curr->exit_code = exit_code;
|
||||
// Set the state of the process to zombie.
|
||||
runqueue.curr->state = EXIT_ZOMBIE;
|
||||
// Send a SIGCHLD to the parent process.
|
||||
|
||||
+25
-13
@@ -19,6 +19,8 @@
|
||||
#include "klib/irqflags.h"
|
||||
#include "klib/stack_helper.h"
|
||||
|
||||
#define GET_EXIT_STATUS(status) (((status)&0x00FF) << 8)
|
||||
|
||||
/// SLAB caches for signal bits.
|
||||
static kmem_cache_t *sigqueue_cachep;
|
||||
|
||||
@@ -477,28 +479,38 @@ int do_signal(struct pt_regs *f)
|
||||
|
||||
continue;
|
||||
case SIGQUIT:
|
||||
sys_exit(GET_EXIT_STATUS(1));
|
||||
continue;
|
||||
case SIGILL:
|
||||
sys_exit(GET_EXIT_STATUS(132));
|
||||
continue;
|
||||
case SIGTRAP:
|
||||
|
||||
sys_exit(GET_EXIT_STATUS(133));
|
||||
continue;
|
||||
case SIGABRT:
|
||||
sys_exit(3);
|
||||
|
||||
sys_exit(GET_EXIT_STATUS(134));
|
||||
continue;
|
||||
case SIGFPE:
|
||||
case SIGSEGV:
|
||||
sys_exit(GET_EXIT_STATUS(136) | signr);
|
||||
__unlock_task_sighand(current_process);
|
||||
return 1;
|
||||
case SIGBUS:
|
||||
case SIGSYS:
|
||||
sys_exit(GET_EXIT_STATUS(138) | signr);
|
||||
__unlock_task_sighand(current_process);
|
||||
return 1;
|
||||
case SIGSEGV:
|
||||
sys_exit(GET_EXIT_STATUS(139) | signr);
|
||||
__unlock_task_sighand(current_process);
|
||||
return 1;
|
||||
case SIGXCPU:
|
||||
sys_exit(GET_EXIT_STATUS(158) | signr);
|
||||
__unlock_task_sighand(current_process);
|
||||
case SIGXFSZ:
|
||||
#if 0
|
||||
if (do_coredump(signr, f))
|
||||
exit_code |= 0x80;
|
||||
#endif
|
||||
sys_exit(GET_EXIT_STATUS(159) | signr);
|
||||
__unlock_task_sighand(current_process);
|
||||
case SIGSYS:
|
||||
default:
|
||||
#if 0
|
||||
current_process->flags |= PF_SIGNALED;
|
||||
#endif
|
||||
sys_exit(exit_code);
|
||||
sys_exit(GET_EXIT_STATUS(exit_code) | signr);
|
||||
__unlock_task_sighand(current_process);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -766,6 +766,11 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
if (blocking) {
|
||||
waitpid(cpid, &status, 0);
|
||||
if (WIFSIGNALED(status)) {
|
||||
printf(FG_RED "\nExit status %d, killed by signal %d\n" FG_RESET, WEXITSTATUS(status), WTERMSIG(status));
|
||||
} else if (WIFSTOPPED(status)) {
|
||||
printf(FG_YELLOW "\nExit status %d, stopped by signal %d\n" FG_RESET, WEXITSTATUS(status), WSTOPSIG(status));
|
||||
}
|
||||
}
|
||||
}
|
||||
// Free up the memory reserved for the arguments.
|
||||
|
||||
@@ -40,8 +40,7 @@ int main(int argc, char *argv[])
|
||||
}
|
||||
// Print the message.
|
||||
printf("Data read from memory: %s (%p)\n", str, str);
|
||||
strcpy(str, "Hello!");
|
||||
// printf("Data read from memory: %s (%p)\n", str, str);
|
||||
str[0] = 'H';
|
||||
// Detatch the shared memory.
|
||||
if (shmdt(str) < 0) {
|
||||
perror("shmdt");
|
||||
|
||||
Reference in New Issue
Block a user