kopia lustrzana https://gitlab.com/sane-project/backends
Added SIGPIPE handling, when compiled for pthread support.
rodzic
d63c6321a6
commit
bf9ea737d3
|
@ -165,7 +165,7 @@ local_thread( void *arg )
|
||||||
* star address of reader function
|
* star address of reader function
|
||||||
* args pointer to scanner data structure
|
* args pointer to scanner data structure
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
sanei_thread_begin( int (*func)(void *args), void* args )
|
sanei_thread_begin( int (*func)(void *args), void* args )
|
||||||
{
|
{
|
||||||
|
@ -214,6 +214,8 @@ sanei_thread_sendsig( int pid, int sig )
|
||||||
# define PTHREAD_CANCELED ((void *) -1)
|
# define PTHREAD_CANCELED ((void *) -1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
static void*
|
static void*
|
||||||
local_thread( void *arg )
|
local_thread( void *arg )
|
||||||
{
|
{
|
||||||
|
@ -233,6 +235,26 @@ local_thread( void *arg )
|
||||||
pthread_exit((void*)&status );
|
pthread_exit((void*)&status );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*/
|
||||||
|
static void
|
||||||
|
restore_sigpipe( void )
|
||||||
|
{
|
||||||
|
struct sigaction act;
|
||||||
|
|
||||||
|
if( sigaction( SIGPIPE, NULL, &act ) == 0 ) {
|
||||||
|
|
||||||
|
if( act.sa_handler == SIG_IGN ) {
|
||||||
|
sigemptyset( &act.sa_mask );
|
||||||
|
act.sa_flags = 0;
|
||||||
|
act.sa_handler = SIG_DFL;
|
||||||
|
|
||||||
|
DBG( 2, "restoring SIGPIPE to SIG_DFL\n" );
|
||||||
|
sigaction( SIGPIPE, &act, NULL );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#else /* the process stuff */
|
#else /* the process stuff */
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -264,8 +286,22 @@ sanei_thread_begin( int (func)(void *args), void* args )
|
||||||
{
|
{
|
||||||
int pid;
|
int pid;
|
||||||
#ifdef USE_PTHREAD
|
#ifdef USE_PTHREAD
|
||||||
|
struct sigaction act;
|
||||||
pthread_t thread;
|
pthread_t thread;
|
||||||
|
|
||||||
|
/* if signal handler for SIGPIPE is SIG_DFL, replace by SIG_IGN */
|
||||||
|
if( sigaction( SIGPIPE, NULL, &act ) == 0 ) {
|
||||||
|
|
||||||
|
if( act.sa_handler == SIG_DFL ) {
|
||||||
|
sigemptyset( &act.sa_mask );
|
||||||
|
act.sa_flags = 0;
|
||||||
|
act.sa_handler = SIG_IGN;
|
||||||
|
|
||||||
|
DBG( 2, "setting SIGPIPE to SIG_IGN\n" );
|
||||||
|
sigaction( SIGPIPE, &act, NULL );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
td.func = func;
|
td.func = func;
|
||||||
td.func_data = args;
|
td.func_data = args;
|
||||||
|
|
||||||
|
@ -328,9 +364,6 @@ sanei_thread_waitpid( int pid, int *status )
|
||||||
result = pthread_join((pthread_t)pid, (void*)&ls );
|
result = pthread_join((pthread_t)pid, (void*)&ls );
|
||||||
|
|
||||||
if( 0 == result ) {
|
if( 0 == result ) {
|
||||||
DBG(2, "* detaching thread\n" );
|
|
||||||
pthread_detach((pthread_t)pid );
|
|
||||||
|
|
||||||
if( PTHREAD_CANCELED == ls ) {
|
if( PTHREAD_CANCELED == ls ) {
|
||||||
DBG(2, "* thread has been canceled!\n" );
|
DBG(2, "* thread has been canceled!\n" );
|
||||||
stat = SANE_STATUS_GOOD;
|
stat = SANE_STATUS_GOOD;
|
||||||
|
@ -342,6 +375,8 @@ sanei_thread_waitpid( int pid, int *status )
|
||||||
if (status)
|
if (status)
|
||||||
*status = stat;
|
*status = stat;
|
||||||
|
|
||||||
|
restore_sigpipe();
|
||||||
|
|
||||||
/* should return pid */
|
/* should return pid */
|
||||||
return pid;
|
return pid;
|
||||||
#else
|
#else
|
||||||
|
|
Ładowanie…
Reference in New Issue