On 3/3/2023 12:56 PM, Gregory Nutt wrote:
On 3/3/2023 12:36 PM, Nathan Hartman wrote:
On Fri, Mar 3, 2023 at 1:07 PM Tim Hardisty <t...@hardisty.co.uk> wrote:
The bug I thought I had in a driver I'm developing (well, one of
them!) appears to be related to file closing.
- I have a related example-type app I'm using to exercise and check
the driver. It opens 2 "files" (O-RDONLY) to read data from the
device driver
- I have enabled CONFIG_SIGKILL_ACTION to allow me to ctrl-c from
the console if the app is misbehaving or, I thought, just to exit it.
The behaviours I see are:
1) If I ctrl-c, the open files are not closed and if I re-run the
app, the system crashes. It is the very first printf statement of
the app that causes the crash, at the point the printf routine calls
lib_fflush (not looked further yet).
2) If I ensure the test app reads console input too, and map a
character received character (e.g. 'x') to a clean exit, I can then
re-run the app without issue.
I don't think I saw this behaviour with the previous driver I did,
so I have probably changed something via menuconfig, but I still
would have thought/hoped that this sort of behaviour wouldn't happen
regardless?
Anyone got any suggestions or hints (other than go back to school!)?
Have you tried installing signal handlers for SIGQUIT and SIGINT and
ensuring that the files are closed before the program is quit?
Nathan
SIGINT, SIGKILL, etc. don't do graceful shutdowns like exit() does.
They should behave as though _exit() were called which does an
immediate termination. However, _exit() is still required to close
all open file descriptor (Per Linux man page) and, if it does not,
that would be a bug.
SIGKILL can't be caught (again per the Linux man page)
https://man7.org/linux/man-pages/man2/exit.2.html
https://man7.org/linux/man-pages/man7/signal.7.html
"Closing" per se is probably not a the root of the problem when the file
descriptors are deallocated when the task group terminates, all of the
descriptors are freed. However, I suspect the there may be an open
reference count in the drivers which is not decrements and whcih could
subsequently in interfere with the correct behavior or a driver.