Page MenuHomeFreeBSD

posixshmcontrol(1), an utility to query and manipulate named posix shm objects
ClosedPublic

Authored by kib on May 14 2019, 12:19 PM.

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

kib created this revision.May 14 2019, 12:19 PM
kib updated this revision to Diff 57395.May 14 2019, 7:47 PM

Report refcount of the backing vm object as shm stat nlink. It is almost always equal to the number of mappings - 1.

tmunro added a subscriber: tmunro.May 14 2019, 10:57 PM

Thanks for working on this! I took it for a quick spin and have some initial feedback.

usr.bin/posixshmcontrol/posixshmcontrol.c
54 ↗(On Diff #57395)

Forgot to mention -p <path> for -t. Erm, why not get rid of the -p and the -z anyway? -c <path>, -t 1234 <path>

66 ↗(On Diff #57395)

Should be able to specify the mode too.

126 ↗(On Diff #57395)

Should we print the mode as eg --rwarwarwa like ipcs? Also it's a bit ugly to have the path unaligned, unlike ipcs's line up output.

161 ↗(On Diff #57395)

This loop is wrong, I'm only getting 4096 bytes out and a bogus "No error" warning. Also redirecting output to /dev/null gives me "Inappropriate ioctl for device", not sure what's happening there.

kib updated this revision to Diff 57528.May 18 2019, 10:59 AM

Change utility syntax to verbs.
Decode mode on ls.
Hopefully fix the dump.

kib added a reviewer: tmunro.May 18 2019, 11:00 AM
kib removed a subscriber: tmunro.
jilles added a subscriber: jilles.May 19 2019, 9:17 PM

I think it will be useful to have this. It fixes most of the drop in functionality when moving from System V shared memory to POSIX shared memory.

I mainly reviewed the userland part.

usr.bin/posixshmcontrol/posixshmcontrol.c
51–56 ↗(On Diff #57528)

I like the subcommand syntax but it would be more consistent with mkdir, mknod, truncate, etc. to take mode and newlen as options and allow multiple pathnames at a time.

83–84 ↗(On Diff #57528)

Should this exit with a non-zero status?

109 ↗(On Diff #57528)

This only returns shared memory objects that have names, not unlinked or SHM_ANON objects that are still open. In some way, that makes sense (comparing to ls), but objects without names still consume memory.

146–147 ↗(On Diff #57528)

%zd is not the correct formatting specifier for uint64_t on 32-bit systems.

210 ↗(On Diff #57528)

Perhaps %#o or shm_decode_mode are a bit clearer.

214 ↗(On Diff #57528)

%zd is not the correct formatting specifier for off_t on 32-bit systems.

215–218 ↗(On Diff #57528)

Perhaps we should print the nanoseconds part as well using .%09ld format?

kib marked 9 inline comments as done.May 20 2019, 4:02 PM
kib added inline comments.
usr.bin/posixshmcontrol/posixshmcontrol.c
109 ↗(On Diff #57528)

This was deliberate, I did considered handling them. This would require more extensive kernel changes to track such objects, which I do not want to do in the scope of this work.

One of the reasons which convinced me to not consider anon handling as required is that such objects do disappear when the process owning fd is killed. In other words, they are not too persistent (unlike SysV ipc objects or named posix shm).

kib updated this revision to Diff 57583.May 20 2019, 4:03 PM

Bug fixes and change to allow multi-path spec.

kib added a reviewer: jilles.May 20 2019, 4:04 PM
kib removed a subscriber: jilles.
tmunro added inline comments.May 20 2019, 10:23 PM
usr.bin/posixshmcontrol/posixshmcontrol.c
194 ↗(On Diff #57583)

I think we should show shm_uid and shm_guid too, otherwise mode is a bit meaningless in this list. I realise that you can get those with "posixshmcontrol stat", but ipcs shows OWNER and GROUP columns beside MODE.

kib updated this revision to Diff 57637.May 21 2019, 4:09 PM

More reasonable unconditional locking for shm_fill_kinfo().
List owner and group for 'ls'.
For 'ls' and 'stat' add -h and -n switches; -h makes sizes human-readable, -n prints uid/gid numerically.

kib marked an inline comment as done.May 21 2019, 4:09 PM
jilles accepted this revision.May 21 2019, 8:42 PM
This revision is now accepted and ready to land.May 21 2019, 8:42 PM
tmunro accepted this revision.May 22 2019, 2:30 AM
This revision was automatically updated to reflect the committed changes.