flock: add more tests and a new option '--fd' - #4553
Conversation
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
In cases where users want to wrap the lock around the execution of a command with a known file descriptor number, the --fd option can be used to let flock(1) interpret the argument before the command as a number and not as file/directory name. Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
| {"fcntl", no_argument, NULL, OPT_FCNTL}, | ||
| {"start", required_argument, NULL, OPT_FCNTL_START}, | ||
| {"length", required_argument, NULL, OPT_FCNTL_LENGTH}, | ||
| {"fd", no_argument, NULL, OPT_FD}, |
There was a problem hiding this comment.
Why not required_argument ? It will make it more robust.
The current code looks like a pattern from schedutils, where we are fighting with --pid using no_argument. Nobody understands this.
There was a problem hiding this comment.
TBH, the usage syntax is not the friendliest. The way how the parsing logic is implemented; --command is treated independently from getopt long option parsing and complicates how the arguments for the target command are evaluated. I think I will refactor that logic a bit to make it easier to maintain all while keeping the current syntax intact.
|
Maybe a little bit improve the PR's title ;-) The PR is definitely not only about tests. |
|
Forgot to adapt the man page and usage info, I'll do it tomorrow morning. |
Review notes (by AI)Nice work on the Critical: missing
|
|
I agree with all points except for the I tested one workaround where we handle the error message output ourselves with something like this: default:
/* When getopt(3) detects an unknown option it increments
* optind by 1, conversely, it does not increment optind
* when it encounters a non-option argument. This holds
* true only because our @shortopts starts with a '+'.
*/
if (IS_COMMAND_OPT(argv[optind-1])) {
cmd_opt_given = true;
break;
}
printf(_("%s: unrecognized option '%s'\n"),
program_invocation_short_name, argv[optind - 1]);
errtryhelp(EX_USAGE);It might look ugly but TBH we have little room left given that the initial usage design requires the Another idea was to add |
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
Signed-off-by: Christian Goeschel Ndjomouo <cgoesc2@wgu.edu>
This brings
flock(1)to 100% test coverage 🎊