Fix handling of valid "negative" PIDs

merge-requests/1/head
Mattias Ellert 2007-11-18 10:59:18 +00:00
rodzic 26e167cdec
commit 7c6b4d6a99
18 zmienionych plików z 63 dodań i 48 usunięć

Wyświetl plik

@ -1,4 +1,13 @@
2007-11-28 Alessandro Zummo <a.zummo@towertech.it>
2007-11-18 Mattias Ellert <mattias.ellert@tsl.uu.se>
* 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 <a.zummo@towertech.it>
* backend/epson2.c: removed quick-format option. it's
the job of a frontend to provide such a commodity.

Wyświetl plik

@ -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;
}

Wyświetl plik

@ -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)

Wyświetl plik

@ -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");

Wyświetl plik

@ -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;

Wyświetl plik

@ -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)
{

Wyświetl plik

@ -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);

Wyświetl plik

@ -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)

Wyświetl plik

@ -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");
}

Wyświetl plik

@ -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

Wyświetl plik

@ -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 );

Wyświetl plik

@ -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");
}

Wyświetl plik

@ -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

Wyświetl plik

@ -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)

Wyświetl plik

@ -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;
}

Wyświetl plik

@ -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)

Wyświetl plik

@ -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 ) {

Wyświetl plik

@ -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? */
{