I am trying to read source code to understand which process is reponsible for these mapping, but I can't still figure it out. Can anyone give me a hint about which code is relative to it ?
source code: agetty+login(util-linux project), systemd
I am trying to read source code to understand which process is reponsible for these mapping, but I can't still figure it out. Can anyone give me a hint about which code is relative to it ?
source code: agetty+login(util-linux project), systemd
No process is responsible for this mapping. This is a device driver function, part of the kernel, with ctrl-c as the default.
ctrl-c is mapped to SIGINT by the tty (or pty) device, and will be sent to the foreground processes for the controlling terminal.
Systemd connects agetty to the tty device and starts it, then agetty initializes the tty device (with the system call version of stty or tcsetattr) and waits for input, and eventually exec()s login.
If, for instance, tcsetattr is used, it applies the termios structure to the tty, which includes the c_cc array, which includes the special characters the tty maps to actions (including line editing and signals and other things), including VINTR which defaults to ctrl-c, and also sets mode flags that allow such characters to be interpreted by the tty.
Some time later, applications (like bash or vim or emacs) would also manipulate termios and change the mode bits to possibly disable the line editing characters (and then emulate them) or even disable some or all of the interrupt characters so that they can be read literally and used as the application desires.
I think that the default signal mapping is handled by Linux kernel, but not early processes (init, agetty, login or bash).
However, it can be set/get by associated termios libraries.
To verify my assumption, I wrote a simple test program (test.c) and made it as the first process invoked by kernel (just like init). The code as following:
/* test.c */
#include <stdio.h>
#include <unistd.h>
#include <termios.h>
int main(int argc, char **argv)
{
struct termios ts;
tcgetattr(STDIN_FILENO, &ts);
printf("INTR: %u\nSUSP: %u\n", ts.c_cc[VINTR], ts.c_cc[VSUSP]);
return 0;
}
Then made it as init and reboot system, the program would display :
INTR: 3
SUSP: 26
These two values respectively correspond to ^C and ^Z. Which means kernel do the job by default.