vpelletier / python-functionfs

Pythonic API for linux's functionfs
GNU General Public License v3.0
40 stars 13 forks source link

Usbcat example (and things I've copied from it) won't run as a service or from rc.local #23

Closed richelam closed 2 years ago

richelam commented 2 years ago

Hi - things were looking pretty good for a project I was doing thanks to your code, but I've hit a wall. Everything works as intended when ssh to my raspberry pi and run my code from the command line, but that's the only way it works. When I run it as a service, it launches, and quickly ends without any reported error. Same when I run it from rc.local. Logging shows that it starts out fine, receiving onBind and onEnable events, but that's all. It seems to exit normally, with waitForever() returning.

Is there something I should be doing differently when running as a service?

vpelletier commented 2 years ago

At a general level, no there should not be anything needed to work as a service as opposed to from the command line.

About the usbcat example itself, the idea I get is that maybe the code is getting an EOF ? From console, it would be attached to the shell's stdin, so it would stay open, but in a service stdin will likely get closed on spawn. Then, sender() would raise EOFError, which would be caught in SubprocessCat.run and cause a clean exit. Then, the parent process would get SIGCHLD, telling it the function has exited, and it would itself do a clean exit.

It of course depends a lot on what was modified and whether you did any file redirection - especially around stdin.

On a more general level, strace --follow-forks --output some_file.strace may help: you will see which syscall happened, what they returned and which signals were received.

richelam commented 2 years ago

Thanks a lot -- that was a big help.

richelam commented 2 years ago

Should have been more specific, in case anyone else needs to know. It was stdin closing that was causing my issue. I didn't actually need to use stdin for my code; it was just something from the usbcat example that I hadn't gotten around to removing. Thanks again.