u413-284-si / webserv

This project is about setting up a http web server, providing a static website.
MIT License
0 stars 0 forks source link

CGI - signal handling #60

Closed gwolf-011235 closed 1 week ago

gwolf-011235 commented 2 months ago

Problem

For CGI functionality we will need to fork() - exec() the CGI bins. We will need to pay attention how signals are treated by child process.

In #57 basic signal handling is implemented: if a registered signal is caught perform a graceful shutdown. Right now registered signal is only SIGINT. If a second signal is caught perform non-graceful shutdown. The child will receive the signal sent by ctrl+c, since it belongs to the same process group. This would stop it (default behavior of SIGINT) - which means graceful shutdown is not possible for CGI-stuff.

Additional info

Fork() creates a copy of the process. The forked process also inherits a registered signal handler. From the man page:

fork() creates a child process that differs from the parent process only in its PID and PPID, and in the fact that resource utilizations are set to 0. File locks and pending signals are not inherited.

Exec() resets signals that are caught to their default action. From the man page (execve):

The dispositions of any signals that are being caught are reset to the default (signal(7)).

This means that signals that are ignored stay ignored (since they are not caught)

Interesting SO threads