Page MenuHomeFreeBSD

truss: handle shm_open's special SHM_ANON value better.
ClosedPublic

Authored by munro_ip9.org on Oct 7 2018, 9:53 PM.

Details

Summary

The support for decoding shm_open(2) just added in D17457 causes truss to display shmopen("(null"), ...) if you use the special SHM_ANON value as a segment name. Maybe that's OK, but it'd be better to detect that value and show it properly.

Test Plan
$ cat test.c
#include <fcntl.h>
#include <sys/mman.h>
#include <sys/types.h>

int main(int argc, char *argv[])
{
    shm_open(SHM_ANON, O_RDWR | O_CREAT | O_EXCL, 0600);
    shm_open("/test-shm-segment", O_RDWR | O_CREAT | O_EXCL, 0600);
    shm_unlink("/test-shm-segment");
    return 0;
}
$ cc test.c
$ truss ./a.out

As of r339224 that shows:

shm_open("(null)",O_RDWR|O_CREAT|O_EXCL,0600)    = 3 (0x3)
shm_open("/test-shm-segment",O_RDWR|O_CREAT|O_EXCL,0600) = 4 (0x4)

With this patch it shows:

shm_open(SHM_ANON,O_RDWR|O_CREAT|O_EXCL,0600)    = 3 (0x3)
shm_open("/test-shm-segment",O_RDWR|O_CREAT|O_EXCL,0600) = 4 (0x4)

Diff Detail

Repository
rS FreeBSD src repository
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

munro_ip9.org created this revision.Oct 7 2018, 9:53 PM
allanjude added a reviewer: mjg.
jhb accepted this revision.Oct 8 2018, 4:03 PM
jhb added a subscriber: jhb.

Looks good apart from a sorting nit.

usr.bin/truss/syscall.h
43 ↗(On Diff #48875)

I think I probably haven't bothered updating the comment block of new types FWIW.

150 ↗(On Diff #48875)

These enum lists are sorted first by type and then alphabetically within each type.

This revision is now accepted and ready to land.Oct 8 2018, 4:03 PM
jhb added inline comments.Oct 8 2018, 4:04 PM
usr.bin/truss/syscalls.c
1599 ↗(On Diff #48875)

No space after cast in FreeBSD's style.

1603 ↗(On Diff #48875)

Best to use the style-mandated '/* FALLTHROUGH */' as it is also recognized by compilers and static analyzers.

Fixes for style feedback from jhb. Thanks!

This revision now requires review to proceed.Oct 8 2018, 8:35 PM
munro_ip9.org marked 2 inline comments as done.Oct 8 2018, 8:35 PM
jhb accepted this revision.Oct 8 2018, 9:09 PM
This revision is now accepted and ready to land.Oct 8 2018, 9:09 PM
mjg accepted this revision.Oct 16 2018, 3:20 AM
allanjude accepted this revision.Oct 16 2018, 3:26 AM

Approved By: allanjude

tuexen accepted this revision.Oct 16 2018, 9:55 AM
This revision was automatically updated to reflect the committed changes.