Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 21 Jul 2002 17:02:11 -0700 (PDT)
From:      David Xu <bsddiy@yahoo.com>
To:        Julian Elischer <julian@elischer.org>
Cc:        freebsd-current@freebsd.org
Subject:   Re: signal handling bug in KSE MIII
Message-ID:  <20020722000211.55864.qmail@web20902.mail.yahoo.com>

next in thread | raw e-mail | index | archive | help

--- David Xu <bsddiy@yahoo.com> wrote:
> I found signal handling is still broken in CURRENT source.
> the following program demostrates the bug is still in kernel:
> 
> #include <stdio.h>
> #include <signal.h>
> 
> void handler(int sig)
> {
>      signal(SIGTSTP, SIG_DFL);
>      kill(getpid(), SIGTSTP);
> }
> 
> int main()
> {
>     char buf[64];
> 
>     signal(SIGTSTP, handler);
>     kill(getpid(), SIGTSTP);
>     printf("input foo:");
>     scanf("%63s", buf);
>     printf("you input:%s\n", buf);
>     return 0;
> }
> 
> when I press CTRL+Z, the program does not suspend and directly exits.
> ktrace indicates that the program directly exits in kernel without 
> calling exit() from program.
> I found SA_STOP handling is disabled in issignal(), delayed SIGTSTP
> is forgotten by kernel, this is the reason why SIGTSTP signal handling
> is broken. at least, one program is affected --- ftp, run ftp
> client program, when 'ftp>' prompt appears, pressing CTRL+Z, causes ftp 
> to exit and do not suspend. patch:
> 
> --- kern_sig.c.old	Sun Jul 21 15:38:00 2002
> +++ kern_sig.c	Sun Jul 21 16:31:02 2002
> @@ -1657,7 +1657,7 @@
>  #endif
>  				break;		/* == ignore */
>  			}
> -#if 0
> +
>  			/*
>  			 * If there is a pending stop signal to process
>  			 * with default action, stop here,
> @@ -1679,16 +1679,10 @@
>  				PROC_UNLOCK(p->p_pptr);
>  				mtx_lock_spin(&sched_lock);
>  				stop(p);
> -				PROC_UNLOCK(p);
> -				DROP_GIANT();
> -				p->p_stats->p_ru.ru_nivcsw++;
> -				mi_switch();
>  				mtx_unlock_spin(&sched_lock);
> -				PICKUP_GIANT();
> -				PROC_LOCK(p);
>  				break;
>  			} else
> -#endif
> +
>  			     if (prop & SA_IGNORE) {
>  				/*
>  				 * Except for SIGCONT, shouldn't get here.
> 
> David Xu
> 

OOPS, the extra kill() calling in main() should be removed 
in demo program, correct source code is:
 
#include <stdio.h>
#include <signal.h>

void handler(int sig)
{
     signal(SIGTSTP, SIG_DFL);
     kill(getpid(), SIGTSTP);
}

int main()
{
    char buf[64];

    signal(SIGTSTP, handler);
    printf("input foo:");
    scanf("%63s", buf);
    printf("you input:%s\n", buf);
    return 0;
}

David Xu



__________________________________________________
Do You Yahoo!?
Yahoo! Health - Feel better, live better
http://health.yahoo.com

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020722000211.55864.qmail>