Signal Handling
Overview
Signal handling in Morinaga OS allows processes to communicate with the kernel to perform specific tasks, such as updating process priorities or reverting the file system to a previous state. This is integrated with Watson to provide seamless system control.
Implementing Signal Handlers
Custom Kernel Signals
Create custom signals or use existing ones (e.g., SIGUSR1
, SIGUSR2
) for inter-process communication:
// In the kernel module
static int signal_handler(struct notifier_block *nb, unsigned long code, void *_param) {
// Handle signal
if(code == SIGUSR1) {
// Perform action, e.g., revert file system
}
return NOTIFY_OK;
}
static struct notifier_block nb = {
.notifier_call = signal_handler,
};
int init_module(void) {
// Register signal handler
register_signal_notifier(&nb);
return 0;
}
User-Space Signal Sending
Watson or other user-space processes can send signals to the kernel:
kill(getpid(), SIGUSR1); // Send signal to self
Reverting the File System
Upon receiving a specific signal, the kernel can trigger a file system rollback using Btrfs snapshots:
# Create a snapshot
btrfs subvolume snapshot /path/to/subvolume /path/to/snapshot
# Rollback to snapshot
btrfs subvolume delete /path/to/subvolume
btrfs subvolume snapshot /path/to/snapshot /path/to/subvolume
Automate this process within the signal handler for immediate effect.
Security Considerations
- Ensure that only authorized processes can send critical signals.
- Implement proper permission checks and authentication mechanisms.