|
From: Dirk M. <dm...@me...> - 2004-04-30 04:08:56
|
I have attached the following sample program that demostrates some
behavior I'm having a problem with.
It shouldnt exit until the user sends a sigint, but when I run with
valgrind a spurious sigint (from the system() call?)
I've tried this with /lib/tls and without, to no effect.
gcc (GCC) 3.3.3 (Debian 20040321)
Linux gobbles 2.6.4 #3 SMP Tue Apr 6 11:59:31 PDT 2004 i686 GNU/Linux
Any ideas?
Am I missing something obvious?
-Dirk
code:
/* $Id: foo.c,v 1.00 2004/04/29 21:04:28 dmorris Exp $ */
/* gcc foo.c -o foo -lpthread */
#include <unistd.h>
#include <stdlib.h>
#include <pthread.h>
#include <semaphore.h>
#include <signal.h>
#include <stdio.h>
static sem_t exit_condition;
static void* _signal_watcher(void* arg)
{
int sig,n;
sigset_t _signal_set;
sigemptyset(&_signal_set);
sigaddset(&_signal_set,SIGINT);
sigprocmask(SIG_UNBLOCK,&_signal_set,NULL);
while (1) {
while ((n = sigwait(&_signal_set,&sig))!=0)
fprintf(stderr,"sigwait: %s\n",strerror(n));
if (sem_post(&exit_condition)<0)
perror("sem_post");
fprintf(stderr,"*************************
SIGINT*********************8\n");
}
return NULL;
}
int main()
{
pthread_t id;
if (sem_init(&exit_condition,0,0)<0) {
perror("sem_init");
exit(1);
}
if (pthread_create(&id,NULL,_signal_watcher,NULL))
perror("pthread_create");
if (system("/bin/true")<0)
perror("system");
printf("sem_waiting...\n");
fflush(stdout);
if (sem_wait(&exit_condition)<0)
perror("sem_wait");
}
|
|
From: Nicholas N. <nj...@ca...> - 2004-04-30 10:17:35
|
On Thu, 29 Apr 2004, Dirk Morris wrote: > I have attached the following sample program that demostrates some > behavior I'm having a problem with. > It shouldnt exit until the user sends a sigint, but when I run with > valgrind a spurious sigint (from the system() call?) > > I've tried this with /lib/tls and without, to no effect. > gcc (GCC) 3.3.3 (Debian 20040321) > Linux gobbles 2.6.4 #3 SMP Tue Apr 6 11:59:31 PDT 2004 i686 GNU/Linux > > Any ideas? > Am I missing something obvious? Looks like a Valgrind bug. Someone else who knows more about Valgrind's signal handling might be able to help you. It would be great if you could file a bug report about this. (valgrind.kde.org/bugs.html has instructions.) Thanks. N |
|
From: Dirk M. <dm...@me...> - 2004-04-30 16:49:59
|
Nicholas Nethercote wrote: >On Thu, 29 Apr 2004, Dirk Morris wrote: > > > >>I have attached the following sample program that demostrates some >>behavior I'm having a problem with. >>It shouldnt exit until the user sends a sigint, but when I run with >>valgrind a spurious sigint (from the system() call?) >> >>I've tried this with /lib/tls and without, to no effect. >>gcc (GCC) 3.3.3 (Debian 20040321) >>Linux gobbles 2.6.4 #3 SMP Tue Apr 6 11:59:31 PDT 2004 i686 GNU/Linux >> >>Any ideas? >>Am I missing something obvious? >> >> > >Looks like a Valgrind bug. Someone else who knows more about Valgrind's >signal handling might be able to help you. It would be great if you could >file a bug report about this. (valgrind.kde.org/bugs.html has >instructions.) Thanks. > > I'll file a bug. It seems as long as you don't make system calls from the main/parent thread everything works as expected. |