libksane seems to break QProcess::start calls

Thiago Macieira thiago at kde.org
Fri Mar 4 17:02:37 GMT 2022


On Thursday, 3 March 2022 23:32:11 PST Tobias Leupold wrote:
> I did it like this. I created one strace for the scanner not causing
> problems and scanned two pages. This resulted in 27,096 lines of output.
> 
> Then I created one for the scanner causing the issue, also scanning two
> pages. This yielded a solid 270,807 lines :-O
> 
> To be honest, I don't have a clue for what I search in those files ...
> would you be so kind to have a look? Or can I lessen the output, so this
> becomes more readable?
> 
> I uploaded the traces here:
> https://l3u.de/tmp/strace_brscan.txt.xz
> https://l3u.de/tmp/strace_plustek.txt.xz
> 
> Thanks again for all help!

I'll take a look. Let's see... the brscan trace doesn't have any use of PIDFD. 
Having *zero* uses means usually means it isn't QProcess because QProcess 
(forkfd) always tries it at least once, to determine if the support is there. 
But it certainly looks like QProcess:

[pid 20386] pipe2([12, 17], O_CLOEXEC)  = 0
[pid 20386] write(5, "\1\0\0\0\0\0\0\0", 8) = 8
[pid 20386] write(5, "\1\0\0\0\0\0\0\0", 8) = 8
[pid 20386] pipe2([18, 19], O_CLOEXEC)  = 0
[pid 20386] write(5, "\1\0\0\0\0\0\0\0", 8) = 8
[pid 20386] pipe2([20, 21], O_CLOEXEC)  = 0
[pid 20386] write(5, "\1\0\0\0\0\0\0\0", 8) = 8
[pid 20386] pipe2([22, 23], O_CLOEXEC)  = 0
[pid 20386] write(5, "\1\0\0\0\0\0\0\0", 8) = 8

That's four pipes with a write of 64-bit value 1 interspersed. That's really 
QProcess and the writes are the QSocketNotifier creations (the write() are 
telling the event loop that something has changed, so it can't go to sleep).

And here's forkfd:

[pid 20386] pipe2([24, 25], O_CLOEXEC)  = 0
[pid 20386] eventfd2(0, EFD_CLOEXEC)    = 26
[pid 20386] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|
CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7f5cce3eea90) = 20425
[pid 20386] write(26, "*\0\0\0\0\0\0\0", 8 <unfinished ...>

This is very distinctive: one more pipe, one eventfd and writing of value 42 
into it (the answer to life, the universe and everything). Making the code 
sequence unique pays off (I can fingerprint it in straces).

So the question is why this brscan didn't even attempt to use pidfd. There's 
some code in Qt5's QProcess to attempt to detect whether you've subclassed 
QProcess and skip using the pidfd feature:

    if (typeid(*q) != typeid(QProcess))
        ffdflags |= FFD_USE_FORK;

https://code.qt.io/cgit/qt/qtbase.git/tree/src/corelib/io/qprocess_unix.cpp?
h=5.15#n462

-- 
Thiago Macieira - thiago (AT) macieira.info - thiago (AT) kde.org
   Software Architect - Intel DPG Cloud Engineering





More information about the kde-devel mailing list