I write my own shell (source code is listed below) and set user's default shell to it.
I login with this user and type ctrl-C, and this shell is killed even though this signal is catched. However, I run this shell directly from bash
, it works as I expect. What makes the difference.
Result
Login with user whose default shell is set to my own shell:
BMC login:
BMC login: naroot
Password:
BMC > signal = 2
BMC login:
Directly run it under bash
:
~# /tmp/systemshell
BMC > signal = 2
BMC > signal = 2
BMC > signal = 2
BMC >
source code
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <getopt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <readline/readline.h>
#include <readline/history.h>
#include <signal.h> // sigaction(), sigsuspend(), sig*()
void signalHandler(int signum) {
signal(SIGINT, signalHandler);
signal(SIGTSTP, signalHandler);
signal(SIGQUIT, SIG_IGN);
signal(SIGTTIN, SIG_IGN);
signal(SIGTTOU, SIG_IGN);
signal(SIGCHLD, SIG_IGN);
printf("signal = %d\n", signum);
}
int main()
{
signal(SIGINT, signalHandler);
signal(SIGTSTP, signalHandler);
signal(SIGQUIT, SIG_IGN);
signal(SIGTTIN, SIG_IGN);
signal(SIGTTOU, SIG_IGN);
signal(SIGCHLD, SIG_IGN);
char *input;
while (1) {
input = readline("BMC > ");
if (input) {
printf("%s\n", input);
free(input);
}
}
return 0;
}