nmsgtool -w leaves temporary file behind upon failed start - #196
nmsgtool -w leaves temporary file behind upon failed start#196rafaelvanoni wants to merge 4 commits into
Conversation
ab67bf6 to
3805cbb
Compare
3805cbb to
ff1cb29
Compare
| @@ -0,0 +1,63 @@ | |||
| #!/bin/sh | |||
There was a problem hiding this comment.
We can omit this test... the existing test scripts are much broader and don't test minor features/fixes/regressions
|
|
||
| #undef process_args_loop | ||
| #undef process_args_loop_mod | ||
| /* nmsg inputs and outputs */ |
There was a problem hiding this comment.
comment should probably be changed to something like "nmsg inputs and outputs that create files"
| tests/test-daemon.sh \ | ||
| tests/test-sample.sh | ||
| tests/test-sample.sh \ | ||
| tests/test-no-output-on-failed-start.sh |
There was a problem hiding this comment.
This is a dangling reference to an omitted test: Makefile.am changes need to be backed out.
|
|
||
| #undef process_args_loop | ||
| #undef process_args_loop_mod | ||
| /* nmsg inputs and outputs that create files */ |
There was a problem hiding this comment.
The commentary in this diff chunk isn't quite correct. Of the process_args_loop invocations, only add_zsock_input and add_sock_output can create files (unix sockets, to be precise). The rest will only check for existing files or make network connections.
The comment should read /* nmsg inputs and outputs that do not create files */ and the zsock processing moved to the section after validation.
| if (c->n_inputs == 0) | ||
| usage("no data sources specified (-h for more help)"); | ||
|
|
||
| /* file outputs: deferred until inputs are validated */ |
There was a problem hiding this comment.
Comment references inputs, when various inputs, outputs, and modules are validated at this point. It should also be explicit that these file-creating outputs are deferred to avoid leaving stray files if another setup phase exits.
It's also worth noting that even this is only a partial solution: if you have multiple output files and one cannot be opened, the earlier output files will still be left behind. I don't think this bug can be fixed without saving the opened filenames (possibly in the nmsgtool context, maybe globally within src/io.c) and explicitly cleaning up before exit on startup failure.
That explicit cleanup would obviate most of this rearrangement.
This PR proposes a fix to keep
nmsgtool(1)from leaving temporary files behind in case of a failed start. For example:The proposed fix moves the arg parsing of
-w footo after channel validation.