From 7c6b4d6a9970e997278398745373ec2670b794e0 Mon Sep 17 00:00:00 2001 From: Mattias Ellert Date: Sun, 18 Nov 2007 10:59:18 +0000 Subject: [PATCH] Fix handling of valid "negative" PIDs --- ChangeLog | 11 ++++++++++- backend/agfafocus.c | 6 +++--- backend/artec_eplus48u.c | 4 ++-- backend/avision.c | 8 ++++---- backend/coolscan.c | 8 ++++---- backend/hp3500.c | 6 +++--- backend/microtek2.c | 2 +- backend/mustek.c | 6 +++--- backend/pie.c | 4 ++-- backend/pixma.c | 8 ++++---- backend/plustek.c | 4 ++-- backend/plustek_pp.c | 4 ++-- backend/snapscan.c | 9 ++++++--- backend/sp15c.c | 9 ++++++--- backend/tamarack.c | 6 +++--- backend/test.c | 6 +++--- backend/u12.c | 4 ++-- backend/umax.c | 6 +++--- 18 files changed, 63 insertions(+), 48 deletions(-) diff --git a/ChangeLog b/ChangeLog index 41d1872bd..54f270490 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,13 @@ -2007-11-28 Alessandro Zummo +2007-11-18 Mattias Ellert + + * backend/agfafocus.c, backend/artec_eplus48u.c, backend/avision.c, + backend/coolscan.c, backend/hp3500.c, backend/microtek2.c, + backend/mustek.c, backend/pie.c, backend/pixma.c, backend/plustek.c, + backend/plustek_pp.c, backend/snapscan.c, backend/sp15c.c, + backend/tamarack.c, backend/test.c, backend/u12.c, backend/umax.c: + Fix handling of valid "negative" PIDs. + +2007-11-18 Alessandro Zummo * backend/epson2.c: removed quick-format option. it's the job of a frontend to provide such a commodity. diff --git a/backend/agfafocus.c b/backend/agfafocus.c index b2d27d0f9..98ead6b6a 100644 --- a/backend/agfafocus.c +++ b/backend/agfafocus.c @@ -947,14 +947,14 @@ do_cancel (AgfaFocus_Scanner * s) do_eof (s); - if (s->reader_pid > 0) + if (s->reader_pid != -1) { int exit_status; /* ensure child knows it's time to stop: */ sanei_thread_kill (s->reader_pid); sanei_thread_waitpid (s->reader_pid, &exit_status); - s->reader_pid = 0; + s->reader_pid = -1; } if (s->fd >= 0) @@ -2052,7 +2052,7 @@ sane_cancel (SANE_Handle handle) { AgfaFocus_Scanner *s = handle; - if (s->reader_pid > 0) + if (s->reader_pid != -1) sanei_thread_kill (s->reader_pid); s->scanning = SANE_FALSE; } diff --git a/backend/artec_eplus48u.c b/backend/artec_eplus48u.c index c245d756f..32db306c1 100644 --- a/backend/artec_eplus48u.c +++ b/backend/artec_eplus48u.c @@ -3483,7 +3483,7 @@ do_cancel (Artec48U_Scanner * s, SANE_Bool closepipe) s->scanning = SANE_FALSE; - if (s->reader_pid > 0) + if (s->reader_pid != -1) { /*parent */ XDBG ((1, "killing reader_process\n")); @@ -3507,7 +3507,7 @@ do_cancel (Artec48U_Scanner * s, SANE_Bool closepipe) { XDBG ((1, "sanei_thread_waitpid() failed !\n")); } - s->reader_pid = 0; + s->reader_pid = -1; XDBG ((1, "reader_process killed\n")); } if (SANE_TRUE == closepipe) diff --git a/backend/avision.c b/backend/avision.c index e198bc556..14cbf3744 100644 --- a/backend/avision.c +++ b/backend/avision.c @@ -5731,7 +5731,7 @@ do_eof (Avision_Scanner *s) /* join our processes - without a wait() you will produce defunct childs */ sanei_thread_waitpid (s->reader_pid, &exit_status); - s->reader_pid = 0; + s->reader_pid = -1; DBG (3, "do_eof: returning %d\n", exit_status); return (SANE_Status)exit_status; @@ -5746,13 +5746,13 @@ do_cancel (Avision_Scanner* s) s->duplex_rear_valid = SANE_FALSE; s->page = 0; - if (s->reader_pid > 0) { + if (s->reader_pid != -1) { int exit_status; /* ensure child knows it's time to stop: */ sanei_thread_kill (s->reader_pid); sanei_thread_waitpid (s->reader_pid, &exit_status); - s->reader_pid = 0; + s->reader_pid = -1; } return SANE_STATUS_CANCELLED; @@ -7889,7 +7889,7 @@ sane_start (SANE_Handle handle) s->read_fds = fds[0]; s->write_fds = fds[1]; - s->reader_pid = 0; /* the thread will be started uppon the first read */ + s->reader_pid = -1; /* the thread will be started upon the first read */ /* create reader routine as new process or thread */ DBG (3, "sane_start: starting thread\n"); diff --git a/backend/coolscan.c b/backend/coolscan.c index 68dce3c19..104ada69f 100644 --- a/backend/coolscan.c +++ b/backend/coolscan.c @@ -2027,7 +2027,7 @@ do_cancel (Coolscan_t * scanner) do_eof (scanner); /* close pipe and reposition scanner */ - if (scanner->reader_pid > 0) + if (scanner->reader_pid != -1) { int exit_status; @@ -2037,7 +2037,7 @@ do_cancel (Coolscan_t * scanner) sanei_thread_kill (scanner->reader_pid); while (sanei_thread_waitpid(scanner->reader_pid, &exit_status) != scanner->reader_pid ); - scanner->reader_pid = 0; + scanner->reader_pid = -1; } if (scanner->sfd >= 0) @@ -4150,11 +4150,11 @@ sane_cancel (SANE_Handle handle) { Coolscan_t *s = handle; - if (s->reader_pid > 0) + if (s->reader_pid != -1) { sanei_thread_kill ( s->reader_pid ); sanei_thread_waitpid( s->reader_pid, NULL ); - s->reader_pid = 0; + s->reader_pid = -1; } swap_res (s); s->scanning = SANE_FALSE; diff --git a/backend/hp3500.c b/backend/hp3500.c index 4a0d8336e..3ae834134 100644 --- a/backend/hp3500.c +++ b/backend/hp3500.c @@ -925,7 +925,7 @@ attachScanner (const char *devicename) dev->devicename = strdup (devicename); dev->sfd = -1; dev->last_scan = 0; - dev->reader_pid = 0; + dev->reader_pid = -1; dev->pipe_r = dev->pipe_w = -1; dev->sane.name = dev->devicename; @@ -1056,7 +1056,7 @@ do_reset (struct hp3500_data *scanner) static void do_cancel (struct hp3500_data *scanner) { - if (scanner->reader_pid > 0) + if (scanner->reader_pid != -1) { if (sanei_thread_kill (scanner->reader_pid) == 0) @@ -1065,7 +1065,7 @@ do_cancel (struct hp3500_data *scanner) sanei_thread_waitpid (scanner->reader_pid, &exit_status); } - scanner->reader_pid = 0; + scanner->reader_pid = -1; } if (scanner->pipe_r >= 0) { diff --git a/backend/microtek2.c b/backend/microtek2.c index 67dd39de3..7ecb4a031 100644 --- a/backend/microtek2.c +++ b/backend/microtek2.c @@ -908,7 +908,7 @@ cancel_scan(Microtek2_Scanner *ms) of material on a feeder, then pid may be already -1 and kill(-1, SIGTERM), i.e. killing all our processes, is not likely what we really want - --mj, 2001/Nov/19 */ - if (ms->pid > 1) + if (ms->pid != -1) { sanei_thread_kill(ms->pid); sanei_thread_waitpid(ms->pid, NULL); diff --git a/backend/mustek.c b/backend/mustek.c index 960675d3b..f13d8aa85 100644 --- a/backend/mustek.c +++ b/backend/mustek.c @@ -2946,7 +2946,7 @@ do_stop (Mustek_Scanner * s) s->scanning = SANE_FALSE; s->pass = 0; - if (s->reader_pid > 0) + if (s->reader_pid != -1) { SANE_Int exit_status; struct timeval now; @@ -2977,7 +2977,7 @@ do_stop (Mustek_Scanner * s) sanei_thread_kill (s->reader_pid); pid = sanei_thread_waitpid (s->reader_pid, &exit_status); - if (pid < 0) + if (pid == -1) { DBG (1, "do_stop: sanei_thread_waitpid failed, already terminated? (%s)\n", @@ -2992,7 +2992,7 @@ do_stop (Mustek_Scanner * s) status = exit_status; } - s->reader_pid = 0; + s->reader_pid = -1; } if (s->fd >= 0) diff --git a/backend/pie.c b/backend/pie.c index f0d2fb7cf..bbc568d30 100644 --- a/backend/pie.c +++ b/backend/pie.c @@ -2897,12 +2897,12 @@ do_cancel (Pie_Scanner * scanner) scanner->scanning = SANE_FALSE; - if (scanner->reader_pid > 0) + if (scanner->reader_pid != -1) { DBG (DBG_sane_info, "killing reader_process\n"); sanei_thread_kill (scanner->reader_pid); sanei_thread_waitpid (scanner->reader_pid, 0); - scanner->reader_pid = 0; + scanner->reader_pid = -1; DBG (DBG_sane_info, "reader_process killed\n"); } diff --git a/backend/pixma.c b/backend/pixma.c index a83433fe6..e6f1e2c82 100644 --- a/backend/pixma.c +++ b/backend/pixma.c @@ -810,7 +810,7 @@ terminate_reader_task (pixma_sane_t * ss, int *exit_code) int status = 0; pid = ss->reader_taskid; - if (pid <= 0) + if (pid == -1) return -1; if (sanei_thread_is_forked ()) { @@ -822,7 +822,7 @@ terminate_reader_task (pixma_sane_t * ss, int *exit_code) pixma_cancel (ss->s); } result = sanei_thread_waitpid (pid, &status); - ss->reader_taskid = 0; + ss->reader_taskid = -1; if (result == pid) { if (exit_code) @@ -852,7 +852,7 @@ start_reader_task (pixma_sane_t * ss) ss->rpipe = -1; ss->wpipe = -1; } - if (ss->reader_taskid > 0) + if (ss->reader_taskid != -1) { PDBG (pixma_dbg (1, "BUG:reader_taskid(%d) != 0\n", ss->reader_taskid)); terminate_reader_task (ss, NULL); @@ -893,7 +893,7 @@ start_reader_task (pixma_sane_t * ss) PDBG (pixma_dbg (3, "Reader task id=%d (%s)\n", pid, (is_forked) ? "forked" : "threaded")); ss->reader_taskid = pid; - return pid; + return 0; } static SANE_Status diff --git a/backend/plustek.c b/backend/plustek.c index 2006364af..3eb8088f1 100644 --- a/backend/plustek.c +++ b/backend/plustek.c @@ -570,7 +570,7 @@ do_cancel( Plustek_Scanner *scanner, SANE_Bool closepipe ) DBG( _DBG_PROC,"do_cancel\n" ); scanner->scanning = SANE_FALSE; - if( scanner->reader_pid > 0 ) { + if( scanner->reader_pid != -1 ) { DBG( _DBG_PROC, ">>>>>>>> killing reader_process <<<<<<<<\n" ); @@ -602,7 +602,7 @@ do_cancel( Plustek_Scanner *scanner, SANE_Bool closepipe ) #endif } - scanner->reader_pid = 0; + scanner->reader_pid = -1; DBG( _DBG_PROC,"reader_process killed\n"); #ifndef HAVE_SETITIMER usb_StartLampTimer( scanner->hw ); diff --git a/backend/plustek_pp.c b/backend/plustek_pp.c index 6d28a9b4b..3dafe3386 100644 --- a/backend/plustek_pp.c +++ b/backend/plustek_pp.c @@ -468,7 +468,7 @@ static SANE_Status do_cancel( Plustek_Scanner *scanner, SANE_Bool closepipe ) scanner->scanning = SANE_FALSE; - if( scanner->reader_pid > 0 ) { + if( scanner->reader_pid != -1 ) { DBG( _DBG_PROC, ">>>>>>>> killing reader_process <<<<<<<<\n" ); @@ -503,7 +503,7 @@ static SANE_Status do_cancel( Plustek_Scanner *scanner, SANE_Bool closepipe ) #endif } - scanner->reader_pid = 0; + scanner->reader_pid = -1; DBG( _DBG_PROC,"reader_process killed\n"); } diff --git a/backend/snapscan.c b/backend/snapscan.c index 365a1a61a..8b291865c 100644 --- a/backend/snapscan.c +++ b/backend/snapscan.c @@ -1765,7 +1765,7 @@ SANE_Status sane_read (SANE_Handle h, if (pss->psrc == NULL || pss->psrc->remaining(pss->psrc) == 0) { - if (pss->child > 0) + if (pss->child != -1) { sanei_thread_waitpid (pss->child, 0); /* ensure no zombies */ pss->child = -1; @@ -1825,7 +1825,7 @@ void sane_cancel (SANE_Handle h) /* signal a cancellation has occurred */ pss->state = ST_CANCEL_INIT; /* signal the reader, if any */ - if (pss->child > 0) + if (pss->child != -1) { DBG( DL_INFO, ">>>>>>>> killing reader_process <<<<<<<<\n" ); @@ -1934,7 +1934,10 @@ SANE_Status sane_get_select_fd (SANE_Handle h, SANE_Int * fd) /* * $Log$ - * Revision 1.69 2007/11/16 08:04:02 ellert-guest + * Revision 1.70 2007/11/18 10:59:18 ellert-guest + * Fix handling of valid "negative" PIDs + * + * Revision 1.69 2007-11-16 08:04:02 ellert-guest * Correct the test of the return value from sanei_thread_begin * * Revision 1.68 2006-09-03 10:00:11 oliver-guest diff --git a/backend/sp15c.c b/backend/sp15c.c index e1b0f3ecb..c79074b54 100644 --- a/backend/sp15c.c +++ b/backend/sp15c.c @@ -45,7 +45,10 @@ static const char RCSid[] = "$Header$"; /* * $Log$ - * Revision 1.14 2007/10/26 14:56:38 jblache + * Revision 1.15 2007/11/18 10:59:18 ellert-guest + * Fix handling of valid "negative" PIDs + * + * Revision 1.14 2007-10-26 14:56:38 jblache * OPT_NUM_OPTS must be of type SANE_TYPE_INT. * * Revision 1.13 2006/03/29 20:48:50 hmg-guest @@ -1747,7 +1750,7 @@ do_cancel (struct sp15c *scanner) do_eof (scanner); /* close pipe and reposition scanner */ - if (scanner->reader_pid > 0) + if (scanner->reader_pid != -1) { int exit_status; DBG (10, "do_cancel: kill reader_process\n"); @@ -1755,7 +1758,7 @@ do_cancel (struct sp15c *scanner) sanei_thread_kill (scanner->reader_pid); DBG (50, "wait for scanner to stop\n"); sanei_thread_waitpid (scanner->reader_pid, &exit_status); - scanner->reader_pid = 0; + scanner->reader_pid = -1; } if (scanner->sfd >= 0) diff --git a/backend/tamarack.c b/backend/tamarack.c index df11baee6..49780acc9 100644 --- a/backend/tamarack.c +++ b/backend/tamarack.c @@ -465,14 +465,14 @@ do_cancel (Tamarack_Scanner *s) do_eof (s); - if (s->reader_pid > 0) + if (s->reader_pid != -1) { int exit_status; /* ensure child knows it's time to stop: */ sanei_thread_kill (s->reader_pid); sanei_thread_waitpid (s->reader_pid, &exit_status); - s->reader_pid = 0; + s->reader_pid = -1; } if (s->fd >= 0) @@ -1435,7 +1435,7 @@ sane_cancel (SANE_Handle handle) { Tamarack_Scanner *s = handle; - if (s->reader_pid > 0) + if (s->reader_pid != -1) sanei_thread_kill (s->reader_pid); s->scanning = SANE_FALSE; } diff --git a/backend/test.c b/backend/test.c index 2c020a5b3..acd3ee283 100644 --- a/backend/test.c +++ b/backend/test.c @@ -1348,7 +1348,7 @@ finish_pass (Test_Device * test_device) DBG (2, "finish_pass: pipe closed\n"); test_device->pipe = -1; } - if (test_device->reader_pid > 0) + if (test_device->reader_pid != -1) { int status; int pid; @@ -1357,7 +1357,7 @@ finish_pass (Test_Device * test_device) test_device->reader_pid); sanei_thread_kill (test_device->reader_pid); pid = sanei_thread_waitpid (test_device->reader_pid, &status); - if (pid < 0) + if (pid == -1) { DBG (1, "finish_pass: sanei_thread_waitpid failed, already terminated? (%s)\n", @@ -1368,7 +1368,7 @@ finish_pass (Test_Device * test_device) DBG (2, "finish_pass: reader process terminated with status: %s\n", sane_strstatus (status)); } - test_device->reader_pid = 0; + test_device->reader_pid = -1; } /* this happens when running in thread context... */ if (test_device->reader_fds >= 0) diff --git a/backend/u12.c b/backend/u12.c index 7c386da5c..d04799eee 100644 --- a/backend/u12.c +++ b/backend/u12.c @@ -391,7 +391,7 @@ static SANE_Status do_cancel( U12_Scanner *scanner, SANE_Bool closepipe ) scanner->scanning = SANE_FALSE; - if( scanner->reader_pid > 0 ) { + if( scanner->reader_pid != -1 ) { DBG( _DBG_PROC, ">>>>>>>> killing reader_process <<<<<<<<\n" ); @@ -421,7 +421,7 @@ static SANE_Status do_cancel( U12_Scanner *scanner, SANE_Bool closepipe ) sanei_thread_sendsig( scanner->reader_pid, SIGKILL ); #endif } - scanner->reader_pid = 0; + scanner->reader_pid = -1; DBG( _DBG_PROC, "reader_process killed\n"); if( scanner->hw->fd >= 0 ) { diff --git a/backend/umax.c b/backend/umax.c index 8c72dde5e..20d968890 100644 --- a/backend/umax.c +++ b/backend/umax.c @@ -4668,14 +4668,14 @@ static SANE_Status do_cancel(Umax_Scanner *scanner) scanner->scanning = SANE_FALSE; - if (scanner->reader_pid > 0) + if (scanner->reader_pid != -1) { DBG(DBG_sane_info,"killing reader_process\n"); sanei_thread_kill(scanner->reader_pid); pid = sanei_thread_waitpid(scanner->reader_pid, &status); - if (pid < 0) + if (pid == -1) { DBG(DBG_sane_info, "do_cancel: sanei_thread_waitpid failed, already terminated ? (%s)\n", strerror(errno)); } @@ -4684,7 +4684,7 @@ static SANE_Status do_cancel(Umax_Scanner *scanner) DBG(DBG_sane_info, "do_cancel: reader_process terminated with status: %s\n", sane_strstatus(status)); } - scanner->reader_pid = 0; + scanner->reader_pid = -1; if (scanner->device->pixelbuffer != NULL) /* pixelbuffer exists? */ {