Skip to content

nmsgtool -w leaves temporary file behind upon failed start - #196

Open
rafaelvanoni wants to merge 4 commits into
nextfrom
nmsgtool-w-file
Open

nmsgtool -w leaves temporary file behind upon failed start#196
rafaelvanoni wants to merge 4 commits into
nextfrom
nmsgtool-w-file

Conversation

@rafaelvanoni

@rafaelvanoni rafaelvanoni commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

This PR proposes a fix to keep nmsgtool(1) from leaving temporary files behind in case of a failed start. For example:

$ ./src/nmsgtool -w foo -C ch25
bind: Cannot assign requested address
$ file foo
foo: empty

The proposed fix moves the arg parsing of -w foo to after channel validation.

@rafaelvanoni rafaelvanoni self-assigned this Aug 6, 2026
Comment thread tests/test-no-output-on-failed-start.sh Outdated
@@ -0,0 +1,63 @@
#!/bin/sh

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can omit this test... the existing test scripts are much broader and don't test minor features/fixes/regressions

Comment thread src/process_args.c Outdated

#undef process_args_loop
#undef process_args_loop_mod
/* nmsg inputs and outputs */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

comment should probably be changed to something like "nmsg inputs and outputs that create files"

Comment thread Makefile.am
tests/test-daemon.sh \
tests/test-sample.sh
tests/test-sample.sh \
tests/test-no-output-on-failed-start.sh

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a dangling reference to an omitted test: Makefile.am changes need to be backed out.

Comment thread src/process_args.c

#undef process_args_loop
#undef process_args_loop_mod
/* nmsg inputs and outputs that create files */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/process_args.c
if (c->n_inputs == 0)
usage("no data sources specified (-h for more help)");

/* file outputs: deferred until inputs are validated */

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants