Closed janderholm closed 1 year ago
Thanks for the report. Good catch, I hadn't notice this restriction before! Did you hit this in the wild?
I think one option is to replace the inner String
with some stricter type that we introduce ad-hoc for that single usage. This is probably the most correct solution, but it doesn't look very ergonomic.
Another option would be to keep the enum as it is for the moment, and introduce some internal validation on the fdname. It should immediately help detecting such bugs without being too much invasive, but at the same time it could become a performance hit (I'm thinking watchdog continuous signaling, specifically).
I'm inclined to start doing the latter, but I'm open to suggestions.
I think I'd just document the restriction. We can't catch every mistake, and there's no readily available type we could use here.
@lucab no I didn't catch it in the wild. I just read the man sd_notify rather carefully when I couldn't get my example send_fds example working!
Can not "notify" be made to verify strings and return an error if something invalid is being sent? It seems to me that FDNAME would mostly be used with short descriptive names. So if an error is returned, the alternative would have been that it goes undetected which is probably worse.
Can not "notify" be made to verify strings and return an error if something invalid is being sent? It seems to me that FDNAME would mostly be used with short descriptive names. So if an error is returned, the alternative would have been that it goes undetected which is probably worse.
You mean returning an SdError("Invalid FDNAME") if the name's longer than 255 characters or contains any non-ASCII or control character?
Yes something like that. Either way there's going to be an error, just if no validation is performed it's a silent error.
Would you make a pull request?
https://www.freedesktop.org/software/systemd/man/sd_notify.html#FDNAME=%E2%80%A6
So while sending UTF-8 won't break things entirely, the name will be silently ignored which may be confusing and cause hard to find bugs.