All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-core] syscall restart issue with SIGINFO handlers
@ 2010-03-31 17:23 Jan Kiszka
  2010-03-31 17:27 ` Gilles Chanteperdrix
  0 siblings, 1 reply; 3+ messages in thread
From: Jan Kiszka @ 2010-03-31 17:23 UTC (permalink / raw)
  To: Gilles Chanteperdrix; +Cc: xenomai-core

Hi Gilles,

here is a case so far uncaught by Xenomai syscall restart code:

#include <pthread.h>
#include <stdio.h>
#include <signal.h>
#include <unistd.h>
#include <sys/mman.h>
#include <native/task.h>
#include <native/mutex.h>

RT_MUTEX mutex;
pthread_t pthread;

void sighand1(int sig)
{
	printf("signal 1: %d\n", sig);
}

void sighand2(int sig, siginfo_t *si, void *context)
{
	printf("signal 2: %d\n", sig);
}

void thread(void *arg)
{
	int res1, res2;

	pthread = pthread_self();

	res1 = rt_mutex_acquire(&mutex, TM_INFINITE);

	res2 = rt_mutex_release(&mutex);

	printf("res = %d / %d\n", res1, res2);
}

int main()
{
	struct sigaction sa;
	RT_TASK task_main, task;

	mlockall(MCL_CURRENT|MCL_FUTURE);

	signal(SIGUSR1, sighand1);

	sigemptyset(&sa.sa_mask);
	sa.sa_sigaction = sighand2;
	sa.sa_flags = SA_SIGINFO;
	sigaction(SIGUSR2, &sa, NULL);

	rt_task_shadow(&task_main, "main", 1, 0);

	rt_mutex_create(&mutex, "mutex");
	rt_mutex_acquire(&mutex, TM_INFINITE);

	rt_task_spawn(&task, "thread", 0, 2, 0, thread, 0);

	sleep(1);
	pthread_kill(pthread, SIGUSR1);

	sleep(1);
	pthread_kill(pthread, SIGUSR2);

	rt_mutex_release(&mutex);

	rt_task_delete(&task);

	return 0;
}


Sending SIGUSR2 will make the blocked thread see -EINTR as result of its
rt_mutex acquire. Some different path must be taken by libc when
delivering SA_SIGINFO signals and returning to the application. Can you
confirm this?

Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Xenomai-core] syscall restart issue with SIGINFO handlers
  2010-03-31 17:23 [Xenomai-core] syscall restart issue with SIGINFO handlers Jan Kiszka
@ 2010-03-31 17:27 ` Gilles Chanteperdrix
  2010-03-31 17:43   ` Jan Kiszka
  0 siblings, 1 reply; 3+ messages in thread
From: Gilles Chanteperdrix @ 2010-03-31 17:27 UTC (permalink / raw)
  To: Jan Kiszka; +Cc: xenomai-core

Jan Kiszka wrote:
> Hi Gilles,
> 
> here is a case so far uncaught by Xenomai syscall restart code:
> 
> #include <pthread.h>
> #include <stdio.h>
> #include <signal.h>
> #include <unistd.h>
> #include <sys/mman.h>
> #include <native/task.h>
> #include <native/mutex.h>
> 
> RT_MUTEX mutex;
> pthread_t pthread;
> 
> void sighand1(int sig)
> {
> 	printf("signal 1: %d\n", sig);
> }
> 
> void sighand2(int sig, siginfo_t *si, void *context)
> {
> 	printf("signal 2: %d\n", sig);
> }
> 
> void thread(void *arg)
> {
> 	int res1, res2;
> 
> 	pthread = pthread_self();
> 
> 	res1 = rt_mutex_acquire(&mutex, TM_INFINITE);
> 
> 	res2 = rt_mutex_release(&mutex);
> 
> 	printf("res = %d / %d\n", res1, res2);
> }
> 
> int main()
> {
> 	struct sigaction sa;
> 	RT_TASK task_main, task;
> 
> 	mlockall(MCL_CURRENT|MCL_FUTURE);
> 
> 	signal(SIGUSR1, sighand1);
> 
> 	sigemptyset(&sa.sa_mask);
> 	sa.sa_sigaction = sighand2;
> 	sa.sa_flags = SA_SIGINFO;
> 	sigaction(SIGUSR2, &sa, NULL);
> 
> 	rt_task_shadow(&task_main, "main", 1, 0);
> 
> 	rt_mutex_create(&mutex, "mutex");
> 	rt_mutex_acquire(&mutex, TM_INFINITE);
> 
> 	rt_task_spawn(&task, "thread", 0, 2, 0, thread, 0);
> 
> 	sleep(1);
> 	pthread_kill(pthread, SIGUSR1);
> 
> 	sleep(1);
> 	pthread_kill(pthread, SIGUSR2);
> 
> 	rt_mutex_release(&mutex);
> 
> 	rt_task_delete(&task);
> 
> 	return 0;
> }
> 
> 
> Sending SIGUSR2 will make the blocked thread see -EINTR as result of its
> rt_mutex acquire. Some different path must be taken by libc when
> delivering SA_SIGINFO signals and returning to the application. Can you
> confirm this?

If you want syscalls to be automatically restarted, you should pass the
SA_RESTART flag to sigaction. It is unrelated to SA_SIGINFO unless I
missed something.

-- 
					    Gilles.


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [Xenomai-core] syscall restart issue with SIGINFO handlers
  2010-03-31 17:27 ` Gilles Chanteperdrix
@ 2010-03-31 17:43   ` Jan Kiszka
  0 siblings, 0 replies; 3+ messages in thread
From: Jan Kiszka @ 2010-03-31 17:43 UTC (permalink / raw)
  To: Gilles Chanteperdrix; +Cc: xenomai-core

Gilles Chanteperdrix wrote:
> Jan Kiszka wrote:
>> Hi Gilles,
>>
>> here is a case so far uncaught by Xenomai syscall restart code:
>>
>> #include <pthread.h>
>> #include <stdio.h>
>> #include <signal.h>
>> #include <unistd.h>
>> #include <sys/mman.h>
>> #include <native/task.h>
>> #include <native/mutex.h>
>>
>> RT_MUTEX mutex;
>> pthread_t pthread;
>>
>> void sighand1(int sig)
>> {
>> 	printf("signal 1: %d\n", sig);
>> }
>>
>> void sighand2(int sig, siginfo_t *si, void *context)
>> {
>> 	printf("signal 2: %d\n", sig);
>> }
>>
>> void thread(void *arg)
>> {
>> 	int res1, res2;
>>
>> 	pthread = pthread_self();
>>
>> 	res1 = rt_mutex_acquire(&mutex, TM_INFINITE);
>>
>> 	res2 = rt_mutex_release(&mutex);
>>
>> 	printf("res = %d / %d\n", res1, res2);
>> }
>>
>> int main()
>> {
>> 	struct sigaction sa;
>> 	RT_TASK task_main, task;
>>
>> 	mlockall(MCL_CURRENT|MCL_FUTURE);
>>
>> 	signal(SIGUSR1, sighand1);
>>
>> 	sigemptyset(&sa.sa_mask);
>> 	sa.sa_sigaction = sighand2;
>> 	sa.sa_flags = SA_SIGINFO;
>> 	sigaction(SIGUSR2, &sa, NULL);
>>
>> 	rt_task_shadow(&task_main, "main", 1, 0);
>>
>> 	rt_mutex_create(&mutex, "mutex");
>> 	rt_mutex_acquire(&mutex, TM_INFINITE);
>>
>> 	rt_task_spawn(&task, "thread", 0, 2, 0, thread, 0);
>>
>> 	sleep(1);
>> 	pthread_kill(pthread, SIGUSR1);
>>
>> 	sleep(1);
>> 	pthread_kill(pthread, SIGUSR2);
>>
>> 	rt_mutex_release(&mutex);
>>
>> 	rt_task_delete(&task);
>>
>> 	return 0;
>> }
>>
>>
>> Sending SIGUSR2 will make the blocked thread see -EINTR as result of its
>> rt_mutex acquire. Some different path must be taken by libc when
>> delivering SA_SIGINFO signals and returning to the application. Can you
>> confirm this?
> 
> If you want syscalls to be automatically restarted, you should pass the
> SA_RESTART flag to sigaction. It is unrelated to SA_SIGINFO unless I
> missed something.

Oh, indeed, that works. Should explain the issue in the field, my
colleagues likely missed that too.

Thanks,
Jan

-- 
Siemens AG, Corporate Technology, CT T DE IT 1
Corporate Competence Center Embedded Linux


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-03-31 17:43 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-03-31 17:23 [Xenomai-core] syscall restart issue with SIGINFO handlers Jan Kiszka
2010-03-31 17:27 ` Gilles Chanteperdrix
2010-03-31 17:43   ` Jan Kiszka

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.