pnmtops subprocesso interrompido quando chamado de um script scanadf

1

Estou feliz em usar o scanadf com o -S script --script-wait parâmetros por um par de anos.

Meu script, chamado scan_perpage , converte os dados da imagem em pdf, por meio de uma chamada para pnmtops , canalizada através de ps2pdf .

No entanto, recentemente (eu suspeito desde que eu atualizei do Fedora 17 para 19), o chamado script trava e, portanto, scanadf trava. O roteiro está pendurado no comando pnmtops . O comando pnmtops está esperando pela sua forke "child" pnmtops output filter para completar, e isso nunca acontece.

A execução do script scan_perpage diretamente na saída da página do scanner bruto funciona bem. Executar o comando pnmtops diretamente também funciona bem. É somente quando executar a partir de scanadf via -S que o script trava em pnmtops .

Versões:

# rpm -q --info sane-backends
Name        : sane-backends
Version     : 1.0.23
Release     : 13.fc19

# rpm -q --info sane-frontends
Name        : sane-frontends
Version     : 1.0.14
Release     : 16.fc19

# rpm -q --info netpbm
Name        : netpbm
Version     : 10.61.02
Release     : 5.fc19

Aqui está a saída do meu script scan , que chama scanadf -vv :

$ scan -o output.pdf
Scanning...
scanadf: value for --resolution is: 300
scanadf: scanning image of size 2544x3300 pixels at 1 bits/pixel
scanadf: acquiring gray frame
Started script '/usr/local/bin/scan_perpage' as pid=10902
Scanned document scan-0001
pnmtops: Input maxval is 1.  Postscript raster will have 1 bits per
sample, so maxval = 1
pnmtops: Image will be 610.56 points wide by 792.00 points high, left
edge 0.72 points from left edge of page, bottom edge 0.00 points from
bottom of page; NOT turned to landscape orientation
pnmtops: output filter spawned: pid 10904
pnmtops: Waiting for PID 10904 to exit
Scanned 1 pages
<the script hangs here>

Aqui está a árvore do processo no ponto de interrupção:

10897 32072 /bin/sh /usr/local/bin/scan -o output.pdf
10898 10897 scanadf -vvv -d fujitsu -S /usr/local/bin/scan_perpage
--script-wait --resolution 300 --mode Lineart -o scan-%04d
10902 10898 /bin/bash /usr/local/bin/scan_perpage scan-0001
10903 10902 pnmtops -verbose -imagewidth 8.5 -imageheight 11 scan-0001
10904 10903 pnmtops -verbose -imagewidth 8.5 -imageheight 11 scan-0001

O processo 10904 (o filtro de saída bifurcado pnmtops ") nunca é concluído. A strace indica que está aguardando uma "leitura".

Não consigo entender por que pnmtops trava quando chamado via scanadf , mas quando chamado diretamente no mesmo arquivo funciona perfeitamente bem.

Além disso, se o subprocesso pnmtops for eliminado manualmente, tudo continuará sem nenhum problema.

    
por Raman 03.10.2013 / 08:25

1 resposta

0

De Bryan Henderson, mantenedor do netpbm:

I found and fixed a bug that causes this symptom. [...] The fix is in Netpbm 10.64.02.

The difference in environment that causes Pnmtops sometimes to hang and sometimes not is the number of open files. If there are more than 10 open files when Pnmtops gets invoked, the hang happens.

In case you care what the pathology is: The child exits when the pipe feeding it signals EOF. That happens when every copy of the file descriptor for the sending end of the pipe closes. The only copy that's supposed to exist is the one the parent process is writing data to. But the child necessarily inherits copies of the file descriptors for both ends of the pipe. If the child doesn't close its copy of the sending end of the pipe, the child will never see EOF on the receiving end, so will wait forever.

That means the child must close its copy of the sending end of the pipe that is feeding it. To do this, and fix some other similar problems, the child attempts at startup to close every file descriptor besides the two it actually uses. But POSIX doesn't provide a way to know the list of open file descriptors, so the child just blindly closes 0-9 (excluding the two it needs), knowing that Pnmtops would not use more files than that. The mistake was that the program didn't account for file descriptors the process was born with. The fix is for Pnmtops to close file descriptors 0-9 when it starts up, so that any pipes it creates will have file descriptor numbers in the range 0-9 and thus get closed by the blind 0-9 close.

    
por 12.11.2013 / 18:17

Tags