From afd555af4fba0acbf16c174dd9dece24181a1a38 Mon Sep 17 00:00:00 2001 From: Garrett D'Amore Date: Thu, 3 May 2018 14:28:44 -0700 Subject: fixes #383 Would like peerid for IPC We offer uid, gid, process id, and even zone id where we have them. Docs and tests are provided. --- src/platform/posix/posix_ipc.c | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'src/platform/posix/posix_ipc.c') diff --git a/src/platform/posix/posix_ipc.c b/src/platform/posix/posix_ipc.c index c1bb9292..5ba3c8fb 100644 --- a/src/platform/posix/posix_ipc.c +++ b/src/platform/posix/posix_ipc.c @@ -183,4 +183,68 @@ nni_plat_ipc_pipe_recv(nni_plat_ipc_pipe *p, nni_aio *aio) nni_posix_pipedesc_recv((void *) p, aio); } +int +nni_plat_ipc_pipe_get_peer_uid(nni_plat_ipc_pipe *p, uint64_t *uid) +{ + int rv; + uint64_t ignore; + + if ((rv = nni_posix_pipedesc_get_peerid( + (void *) p, uid, &ignore, &ignore, &ignore)) != 0) { + return (rv); + } + return (0); +} + +int +nni_plat_ipc_pipe_get_peer_gid(nni_plat_ipc_pipe *p, uint64_t *gid) +{ + int rv; + uint64_t ignore; + + if ((rv = nni_posix_pipedesc_get_peerid( + (void *) p, &ignore, gid, &ignore, &ignore)) != 0) { + return (rv); + } + return (0); +} + +int +nni_plat_ipc_pipe_get_peer_zoneid(nni_plat_ipc_pipe *p, uint64_t *zid) +{ + int rv; + uint64_t ignore; + uint64_t id; + + if ((rv = nni_posix_pipedesc_get_peerid( + (void *) p, &ignore, &ignore, &ignore, &id)) != 0) { + return (rv); + } + if (id == (uint64_t) -1) { + // NB: -1 is not a legal zone id (illumos/Solaris) + return (NNG_ENOTSUP); + } + *zid = id; + return (0); +} + +int +nni_plat_ipc_pipe_get_peer_pid(nni_plat_ipc_pipe *p, uint64_t *pid) +{ + int rv; + uint64_t ignore; + uint64_t id; + + if ((rv = nni_posix_pipedesc_get_peerid( + (void *) p, &ignore, &ignore, &id, &ignore)) != 0) { + return (rv); + } + if (id == (uint64_t) -1) { + // NB: -1 is not a legal process id + return (NNG_ENOTSUP); + } + *pid = id; + return (0); +} + #endif // NNG_PLATFORM_POSIX -- cgit v1.2.3-70-g09d2