Reading this, I'd say the problem here is not getopt itself, it's using it although its generic command-line "model" doesn't match the one required for the traditional kill syntax. That's just stupid of course ...
Side note, I never used it myself as I want to also target systems that don't provide it anyways.
Reading this, I'd say the problem here is not getopt itself, it's using it although its generic command-line "model" doesn't match the one required for the traditional kill syntax. That's just stupid of course ...
GNU coreutils has a rather amusing solution for this model mismatch: it uses getopt_long, but it actually handles all of -0 through -9 and -A through -Z as valid short options that can take optional arguments.
(-L is handled differently, since procps decided that should do the same thing as -l for some reason — but this is not an issue since no signal names start with L.)
util-linux's kill and Bash's kill builtin just parse the arguments manually... which seems entirely sensible for this utility.
Yes, the article says so. Though getopt() isn't great either, and its implicit global state and gotchas helped these bugs happen in the first place (multiple times; and to live for that long). Bug #4 is my favourite one, because it's a result of misusing the brittle interface of getopt() and the batshit-insane atoi().
View all comments
5
u/8d8n4mbo28026ulk 24d ago
A hilarious decade-long journey at failing to parse
argvby forcefully trying to usegetopt(). I now feel a little better that I rolled my own!