On Mon, Aug 11, 2025 at 11:18:52AM -0500, Andrew Wood wrote: > Hi all, > > Is it normal that a library will print errors/warnings in addition to setting > an error/errno value on functions whose purpose isn't printing? I've been > working with libprocstat lately and the program I'm writing is prone to > checking processes that no longer exist a lot of the time (but is built to > handle this), but I'm disappointed about the fact that I've seemingly got to > choose between having my stderr riddled with warnings and disabling my > ability to use the err/warn function suite (by calling err_set_file to set it > to /dev/null).
Yes, I've noticed this too. It's especially annoying because some of the warnings are effectively unavoidable. For instance, if one invokes "procstat -kka", procstat will first obtain a list of processes and then grab a stack for each one, but if one of the processes exits between these two steps, libprocstat will emit a warning. So if you run that command on a busy system there's a good chance it'll emit some noise to stderr. It's bad behaviour for a library for sure. > I'd much prefer if there were a separate function for finding out what an > error was, like perhaps a procstat_strerror function? It seems perfectly > doable given the state tracking that's already done in the procstat struct. > Are there any design considerations to explain why a data-fetching would > choose to print warnings without any request to, rather than let the > programmer decide whether it's worth printing anything? Is this something I > could change and make a PR for and just let any discussion over it happen > there, or is there some person or group I need to talk to about this? I think that makes sense on the surface, but how should the libprocstat consumer know whether an error is benign or not? Don't we also need some finer-grained mechanism which makes it easy to distinguish mostly-harmless errors (e.g., the target process exited) from something more likely to be fatal (e.g., failure to query a particular process for lack of permission)? Probably libprocstat should expose error codes as well? > Apologies if this isn't the right spot to vent about this, I'm not sure where > the proper place is.
