Page MenuHomeFreeBSD

libproc: Remove SIG2STR_MAX.
AbandonedPublic

Authored by des on Wed, May 14, 10:09 AM.

Details

Reviewers
None
Summary

This wasn't used anywhere, and POSIX 2024 says it lives in <signal.h>.

MFC after: 1 week

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Skipped
Unit
Tests Skipped
Build Status
Buildable 64182
Build 61066: arc lint + arc unit

Event Timeline

des requested review of this revision.Wed, May 14, 10:09 AM

Hmm, my grep found a few uses in cddl tools for dtrace:

cddl/contrib/opensolaris/cmd/dtrace/dtrace.c:   char name[SIG2STR_MAX];
cddl/contrib/opensolaris/cmd/plockstat/plockstat.c:     char name[SIG2STR_MAX];
lib/libproc/libproc.h:#define SIG2STR_MAX       8

Should it be moved to include/signal.h instead?

The dtrace use is under #ifdef illumos but that should probably be fixed to always be enabled as proc_signame() exists in libproc. The plockstat use is enabled on both FreeBSD and illumos (and is also for a call to proc_signame()).

There's a separate effort to add STR2SIG_MAX and the functions it was intended for to libc. This unused definition is in the way of that effort.

Note that proc_signame() actually calls strsignal() and 8 bytes is far too short for the strings it returns, so that use is incorrect.

(alternatively, proc_signame() is wrong to use strsignal(), but since libproc is completely undocumented, which is a bug in and of itself, I have no idea what it's actually intended to do.)

libproc is a Solaris interface, so I think it's documented there. proc_signame() is functionally equivalent to strsignal() AFAIK.

I'm surprised though that this diff compiles given the use in plockstat? Presumably the commit that adds SIG2STR_MAX to <signal.h> can just remove it from here as part of that commit which will keep the tree building?

I didn't try to build it as it didn't look like the macro was used anywhere.

Passing an eight-byte buffer to proc_signame() will not produce the expected result. The strings it returns are localized human-readable descriptions of the signals, like “Illegal instruction” or “Floating-point exception”. SIG2STR_MAX is intended for use with sig2str() which returns the name of the signal without the SIG prefix, like “ILL” or “FPE”.

It seems libproc's proc_signame() is just buggy in FreeBSD. illumos calls str2sig(): https://github.com/illumos/illumos-gate/blob/1b1703a43cdfe482965d40a4baae758d05844ac2/usr/src/lib/libproc/common/proc_names.c#L106

I'd rather not add an unnecessary diff to the upstream dtrace sources if we don't have to. I'm fine with keeping the existing truncation we have for now if you just move SIG2STR_MAX to <signal.h>. I assume you are adding str2sig() and once it exists some enterprising soul can fix proc_signame() to use that instead of strsignal() if desired?

It's being worked on by someone else, I'll ask them to fix libproc.