All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Vlasov <vsu@altlinux.ru>
To: "Luong Ngo" <luong.ngo@gmail.com>
Cc: "Parav K Pandit" <parav_pandit@mindtree.com>,
	"Robert Hancock" <hancockr@shaw.ca>,
	linux-kernel <linux-kernel@vger.kernel.org>,
	tglx@linutronix.de
Subject: Re: Sleeping thread not receive signal until it wakes up
Date: Sat, 10 Mar 2007 11:22:03 +0300	[thread overview]
Message-ID: <20070310112203.33c638ee.vsu@altlinux.ru> (raw)
In-Reply-To: <1b2aacd80703091610h9b5bc0ep1b5b58c53ca58e86@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1591 bytes --]

On Fri, 9 Mar 2007 16:10:29 -0800 Luong Ngo wrote:

> Thanks Parav, adding singal_allow(SIGALRM) wakeup the blocking
> interruptible_sleep_on and checking the signal_pending would return
> true now.

This means that there is also a bug in your userspace program -
somehow when it invokes ioctl(), it has SIGALRM blocked.  Use
sigprocmask() (or pthread_sigmask() if your program is multithreaded)
to ensure that SIGALRM is not blocked when you are expecting it to be
processed.  (Even if your program does not block SIGALRM, it may
inherit a blocked SIGALRM from another program which have started it,
so the safest way is to unblock SIGALRM explicitly.)

Using allow_signal() is needed only if you create a kernel thread and
want that thread to handle signals.

> But a quick question is when detecting signal_pending, I
> return -ERESTARTSYS, but the user process receive the return value of
> ioctl call is -1, shouldn't it be -4 for EINTR?

This is handled by syscall wrappers in libc - when the kernel returns
an error code from a syscall, the syscall wrapper function puts the
code into the per-thread errno variable and returns -1 to its caller.
Your userspace code should check errno for the actual error code when
it receives -1 from ioctl().

And the ERESTARTSYS error is really special - it never actually gets
returned to the userspace program; instead, the syscall return code in
the kernel catches it and either restarts the syscall after the signal
handler completes, or converts the error code to EINTR; one of these
actions is selected by the SA_RESTART flag to sigaction().

[-- Attachment #2: Type: application/pgp-signature, Size: 189 bytes --]

  reply	other threads:[~2007-03-10  8:22 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <fa.kb3wuhac4W+1DqK61+sKe9uZwto@ifi.uio.no>
     [not found] ` <fa.cyXmbtXvYymKHdI0rEXZCxyk+KE@ifi.uio.no>
     [not found]   ` <fa.zPDT1vfJF5MjVXXQH/l+YSaLl84@ifi.uio.no>
     [not found]     ` <fa.HmQN7RhZNBRsiJYADMOsY8DL67k@ifi.uio.no>
     [not found]       ` <fa.PDmHwxZ3arhmED5SLuEONyxUlz4@ifi.uio.no>
     [not found]         ` <fa.ygLhZcCLgDxnwAYYVse/Xshr9IE@ifi.uio.no>
2007-03-09  1:10           ` Sleeping thread not receive signal until it wakes up Robert Hancock
2007-03-09  3:24             ` Luong Ngo
2007-03-09  3:45               ` Parav K Pandit
2007-03-10  0:10                 ` Luong Ngo
2007-03-10  8:22                   ` Sergey Vlasov [this message]
2007-03-10 10:54                     ` Luong Ngo
2007-03-07  5:31 Luong Ngo
2007-03-07 13:19 ` linux-os (Dick Johnson)
2007-03-07 19:28   ` Luong Ngo
2007-03-07 20:08     ` linux-os (Dick Johnson)
2007-03-07 21:03       ` Lee Revell
2007-03-08  0:40         ` Luong Ngo
2007-03-08  0:28       ` Luong Ngo
2007-03-08 13:01         ` linux-os (Dick Johnson)
2007-03-08 13:53           ` Thomas Gleixner
2007-03-08 22:52             ` Luong Ngo
2007-03-09 14:58               ` Sergey Vlasov
2007-03-09 19:50                 ` Luong Ngo
2007-03-07 20:20   ` Jan Engelhardt
2007-03-07 18:09 ` Sergey Vlasov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070310112203.33c638ee.vsu@altlinux.ru \
    --to=vsu@altlinux.ru \
    --cc=hancockr@shaw.ca \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luong.ngo@gmail.com \
    --cc=parav_pandit@mindtree.com \
    --cc=tglx@linutronix.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.