>From: Nathan Hartman <hartman.nat...@gmail.com> >Sent: 03 March 2023 18:36 >To: dev@nuttx.apache.org >Subject: Re: Help me understand file open/close behaviours? > >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? >
CONFIG_SIGKILL_ACTION covers SIGQUIT and SIGINT, so yes. Also SIGKILL and SIGTERM as it happens. When I trap for the 'x' from the console, the test app does close both files, but ctrl-c to abort the app doesn't run the code in the app to close the files of course, so a close would have to be handled by the NuttX system itself, I think?