On Wed, Jul 20, 2011 at 3:06 PM, Jim Ramsay <[email protected]> wrote:
> This allows ^C to exit iscsid but only when it is running in foreground
> mode, which is useful for testing.
>
> Signed-off-by: Jim Ramsay <[email protected]>
> ---
>  usr/iscsid.c |    5 +++++
>  1 files changed, 5 insertions(+), 0 deletions(-)
>
> diff --git a/usr/iscsid.c b/usr/iscsid.c
> index 1a37347..9df6658 100644
> --- a/usr/iscsid.c
> +++ b/usr/iscsid.c
> @@ -304,6 +304,11 @@ static void iscsid_shutdown(void)
>  static void catch_signal(int signo)
>  {
>        log_debug(1, "pid %d caught signal %d", getpid(), signo);
> +
> +       /* In foreground mode, treat SIGINT like SIGTERM */
> +       if (!daemonize && signo == SIGINT)
> +               signo = SIGTERM;
> +
>        switch (signo) {
>        case SIGTERM:
>                iscsid_shutdown();

The signal handling approach in open-iscsi should be reconsidered.
catch_signal() is a signal handler and hence is not allowed to invoke
fprintf() - which is exactly what iscsid_shutdown() does. See also
IEEE Std 1003.1-2008, paragraph 2.4.3 Signal Actions. In that section
there is a list with functions which are safe to be invoked from a
signal handler. fprintf() is not in that list. The reason that
fprintf() is not in that list is because fprintf() performs locking.
So invoking fprintf() from a signal handler may trigger recursive
locking and hence a deadlock.

Bart.

-- 
You received this message because you are subscribed to the Google Groups 
"open-iscsi" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/open-iscsi?hl=en.

Reply via email to