From 7e0af3f4f04ae5c8a38fd09251d9f53bf427f56e Mon Sep 17 00:00:00 2001 From: Ralph Castain Date: Tue, 5 Jul 2016 09:31:06 -0700 Subject: [PATCH] Update pmix2x to track upstream changes --- opal/mca/pmix/pmix2x/pmix/VERSION | 4 +- .../pmix2x/pmix/config/pmix_setup_hwloc.m4 | 6 +- .../pmix2x/pmix/config/pmix_setup_libevent.m4 | 6 +- .../pmix2x/pmix/include/pmix/pmix_common.h | 12 +-- .../pmix/src/event/pmix_event_registration.c | 2 - .../pmix/pmix2x/pmix/src/server/pmix_server.c | 19 +++- .../pmix/src/server/pmix_server_listener.c | 93 ++++++++++++------- .../pmix2x/pmix/src/server/pmix_server_ops.c | 17 ++-- .../pmix2x/pmix/src/server/pmix_server_ops.h | 16 ++-- .../mca/pmix/pmix2x/pmix/src/tool/pmix_tool.c | 8 +- .../pmix2x/pmix/src/usock/usock_sendrecv.c | 2 +- .../mca/pmix/pmix2x/pmix/src/util/Makefile.am | 6 +- opal/mca/pmix/pmix2x/pmix/src/util/getid.c | 86 +++++++++++++++++ opal/mca/pmix/pmix2x/pmix/src/util/getid.h | 31 +++++++ .../pmix/pmix2x/pmix/test/simple/simptest.c | 14 +-- 15 files changed, 238 insertions(+), 84 deletions(-) mode change 100755 => 100644 opal/mca/pmix/pmix2x/pmix/src/server/pmix_server_ops.c create mode 100644 opal/mca/pmix/pmix2x/pmix/src/util/getid.c create mode 100644 opal/mca/pmix/pmix2x/pmix/src/util/getid.h diff --git a/opal/mca/pmix/pmix2x/pmix/VERSION b/opal/mca/pmix/pmix2x/pmix/VERSION index 70e4ea2375..ae4703b2a4 100644 --- a/opal/mca/pmix/pmix2x/pmix/VERSION +++ b/opal/mca/pmix/pmix2x/pmix/VERSION @@ -30,7 +30,7 @@ greek= # command, or with the date (if "git describe" fails) in the form of # "date". -repo_rev=git4940b48 +repo_rev=git92df386 # If tarball_version is not empty, it is used as the version string in # the tarball filename, regardless of all other versions listed in @@ -44,7 +44,7 @@ tarball_version= # The date when this release was created -date="Jun 29, 2016" +date="Jul 05, 2016" # The shared library version of each of PMIx's public libraries. # These versions are maintained in accordance with the "Library diff --git a/opal/mca/pmix/pmix2x/pmix/config/pmix_setup_hwloc.m4 b/opal/mca/pmix/pmix2x/pmix/config/pmix_setup_hwloc.m4 index f436e673a6..d67ecafa88 100755 --- a/opal/mca/pmix/pmix2x/pmix/config/pmix_setup_hwloc.m4 +++ b/opal/mca/pmix/pmix2x/pmix/config/pmix_setup_hwloc.m4 @@ -2,7 +2,7 @@ # # Copyright (c) 2009-2015 Cisco Systems, Inc. All rights reserved. # Copyright (c) 2013 Los Alamos National Security, LLC. All rights reserved. -# Copyright (c) 2013-2015 Intel, Inc. All rights reserved +# Copyright (c) 2013-2016 Intel, Inc. All rights reserved # $COPYRIGHT$ # # Additional copyrights may follow @@ -18,8 +18,8 @@ AC_DEFUN([PMIX_HWLOC_CONFIG],[ [The value that should be included in C files to include hwloc.h])]) AC_ARG_ENABLE([embedded-hwloc], - [AC_HELP_STRING([--enable-embedded-hwloc], - [Enable use of locally embedded hwloc])]) + [AC_HELP_STRING([--enable-embedded-hwloc], + [Enable use of locally embedded hwloc])]) pmix_hwloc_support=0 AS_IF([test "$enable_embedded_hwloc" = "yes"], diff --git a/opal/mca/pmix/pmix2x/pmix/config/pmix_setup_libevent.m4 b/opal/mca/pmix/pmix2x/pmix/config/pmix_setup_libevent.m4 index 882c9c9e41..2ea5e03434 100755 --- a/opal/mca/pmix/pmix2x/pmix/config/pmix_setup_libevent.m4 +++ b/opal/mca/pmix/pmix2x/pmix/config/pmix_setup_libevent.m4 @@ -2,7 +2,7 @@ # # Copyright (c) 2009-2015 Cisco Systems, Inc. All rights reserved. # Copyright (c) 2013 Los Alamos National Security, LLC. All rights reserved. -# Copyright (c) 2013-2015 Intel, Inc. All rights reserved +# Copyright (c) 2013-2016 Intel, Inc. All rights reserved # $COPYRIGHT$ # # Additional copyrights may follow @@ -18,8 +18,8 @@ AC_DEFUN([PMIX_LIBEVENT_CONFIG],[ [The value that should be included in C files to include event.h])]) AC_ARG_ENABLE([embedded-libevent], - [AC_HELP_STRING([--enable-embedded-libevent], - [Enable use of locally embedded libevent])]) + [AC_HELP_STRING([--enable-embedded-libevent], + [Enable use of locally embedded libevent])]) AS_IF([test "$enable_embedded_libevent" = "yes"], [_PMIX_LIBEVENT_EMBEDDED_MODE], diff --git a/opal/mca/pmix/pmix2x/pmix/include/pmix/pmix_common.h b/opal/mca/pmix/pmix2x/pmix/include/pmix/pmix_common.h index b28ccf8734..be5561b868 100644 --- a/opal/mca/pmix/pmix2x/pmix/include/pmix/pmix_common.h +++ b/opal/mca/pmix/pmix2x/pmix/include/pmix/pmix_common.h @@ -206,12 +206,12 @@ BEGIN_C_DECLS #define PMIX_EVENT_CUSTOM_RANGE "pmix.evrange" // (pmix_proc_t*) array of pmix_proc_t defining range of event notification #define PMIX_EVENT_AFFECTED_PROCS "pmix.evaffected" // (pmix_proc_t*) array of pmix_proc_t defining affected procs #define PMIX_EVENT_NON_DEFAULT "pmix.evnondef" // (bool) event is not to be delivered to default event handlers - /* fault tolerance-related events */ - #define PMIX_EVENT_TERMINATE_SESSION "pmix.evterm.sess" // (bool) RM intends to terminate session - #define PMIX_EVENT_TERMINATE_JOB "pmix.evterm.job" // (bool) RM intends to terminate this job - #define PMIX_EVENT_TERMINATE_NODE "pmix.evterm.node" // (bool) RM intends to terminate all procs on this node - #define PMIX_EVENT_TERMINATE_PROC "pmix.evterm.proc" // (bool) RM intends to terminate just this process - #define PMIX_EVENT_ACTION_TIMEOUT "pmix.evtimeout" // (int) time in sec before RM will execute error response +/* fault tolerance-related events */ +#define PMIX_EVENT_TERMINATE_SESSION "pmix.evterm.sess" // (bool) RM intends to terminate session +#define PMIX_EVENT_TERMINATE_JOB "pmix.evterm.job" // (bool) RM intends to terminate this job +#define PMIX_EVENT_TERMINATE_NODE "pmix.evterm.node" // (bool) RM intends to terminate all procs on this node +#define PMIX_EVENT_TERMINATE_PROC "pmix.evterm.proc" // (bool) RM intends to terminate just this process +#define PMIX_EVENT_ACTION_TIMEOUT "pmix.evtimeout" // (int) time in sec before RM will execute error response /* attributes used to describe "spawn" attributes */ #define PMIX_PERSONALITY "pmix.pers" // (char*) name of personality to use diff --git a/opal/mca/pmix/pmix2x/pmix/src/event/pmix_event_registration.c b/opal/mca/pmix/pmix2x/pmix/src/event/pmix_event_registration.c index ab97e3359c..17bdc2d898 100644 --- a/opal/mca/pmix/pmix2x/pmix/src/event/pmix_event_registration.c +++ b/opal/mca/pmix/pmix2x/pmix/src/event/pmix_event_registration.c @@ -1,8 +1,6 @@ /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2014-2016 Intel, Inc. All rights reserved. - * Copyright (c) 2016 Research Organization for Information Science - * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * * Additional copyrights may follow diff --git a/opal/mca/pmix/pmix2x/pmix/src/server/pmix_server.c b/opal/mca/pmix/pmix2x/pmix/src/server/pmix_server.c index 0533b38b1a..d91d4e2a00 100644 --- a/opal/mca/pmix/pmix2x/pmix/src/server/pmix_server.c +++ b/opal/mca/pmix/pmix2x/pmix/src/server/pmix_server.c @@ -1,7 +1,7 @@ /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2014-2016 Intel, Inc. All rights reserved. - * Copyright (c) 2014-2015 Research Organization for Information Science + * Copyright (c) 2014-2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2014-2015 Artem Y. Polyakov . * All rights reserved. @@ -227,7 +227,8 @@ PMIX_EXPORT pmix_status_t PMIx_server_init(pmix_server_module_t *module, size_t n, m; pmix_kval_t kv; pmix_listener_t *lt; - int myhostnamelen = 10; + bool need_listener; + int myhostnamelen = 30; char myhostname[myhostnamelen]; char *pmix_pid, *tdir; char **protected = NULL; @@ -291,8 +292,10 @@ PMIX_EXPORT pmix_status_t PMIx_server_init(pmix_server_module_t *module, pmix_listener_t *tl = PMIX_NEW(pmix_listener_t); tl -> address.sun_family = AF_UNIX; tl->protocol = PMIX_PROTOCOL_TOOL; - /* Get up to 10 chars of hostname.*/ + /* Get up to 30 chars of hostname.*/ gethostname(myhostname, myhostnamelen); + /* ensure it is NULL terminated */ + myhostname[myhostnamelen-1] = '\0'; /* need to put this in the global tmpdir as opposed to * where the server tmpdir might be */ if (NULL == (tdir = getenv("TMPDIR"))) { @@ -328,8 +331,15 @@ PMIX_EXPORT pmix_status_t PMIx_server_init(pmix_server_module_t *module, pmix_list_append(&pmix_usock_globals.posted_recvs, &req->super); /* start listening */ + need_listener = false; PMIX_LIST_FOREACH(lt, &pmix_server_globals.listeners, pmix_listener_t) { - if (PMIX_SUCCESS != pmix_start_listening(lt)) { + if (PMIX_SUCCESS != pmix_prepare_listening(lt, &need_listener)) { + PMIx_server_finalize(); + return PMIX_ERR_INIT; + } + } + if (need_listener) { + if (PMIX_SUCCESS != pmix_start_listening()) { PMIx_server_finalize(); return PMIX_ERR_INIT; } @@ -2007,6 +2017,7 @@ static void notifyerror_cbfunc (pmix_status_t status, void *cbdata) PMIX_RELEASE(cd); } + static void query_cbfunc(pmix_status_t status, pmix_info_t *info, size_t ninfo, void *cbdata, diff --git a/opal/mca/pmix/pmix2x/pmix/src/server/pmix_server_listener.c b/opal/mca/pmix/pmix2x/pmix/src/server/pmix_server_listener.c index 76c807b8ff..b4749b75ef 100755 --- a/opal/mca/pmix/pmix2x/pmix/src/server/pmix_server_listener.c +++ b/opal/mca/pmix/pmix2x/pmix/src/server/pmix_server_listener.c @@ -53,6 +53,7 @@ #include "src/util/argv.h" #include "src/util/error.h" #include "src/util/fd.h" +#include "src/util/getid.h" #include "src/util/output.h" #include "src/util/pmix_environ.h" #include "src/util/progress_threads.h" @@ -73,7 +74,7 @@ static pthread_t engine; /* * start listening on our rendezvous file */ -pmix_status_t pmix_start_listening(pmix_listener_t *lt) +pmix_status_t pmix_prepare_listening(pmix_listener_t *lt, bool *need_listener) { int flags; pmix_status_t rc; @@ -95,7 +96,6 @@ pmix_status_t pmix_start_listening(pmix_listener_t *lt) } - addrlen = sizeof(struct sockaddr_un); if (bind(lt->socket, (struct sockaddr*)address, addrlen) < 0) { printf("%s:%d bind() failed\n", __FILE__, __LINE__); @@ -137,16 +137,18 @@ pmix_status_t pmix_start_listening(pmix_listener_t *lt) goto sockerror; } - /* setup my version for validating connections - we - * only check the major version numbers */ - myversion = strdup(PMIX_VERSION); - /* find the first '.' */ - ptr = strchr(myversion, '.'); - if (NULL != ptr) { - ++ptr; - /* stop it at the second '.', if present */ - if (NULL != (ptr = strchr(ptr, '.'))) { - *ptr = '\0'; + if (NULL == myversion) { + /* setup my version for validating connections - we + * only check the major version numbers */ + myversion = strdup(PMIX_VERSION); + /* find the first '.' */ + ptr = strchr(myversion, '.'); + if (NULL != ptr) { + ++ptr; + /* stop it at the second '.', if present */ + if (NULL != (ptr = strchr(ptr, '.'))) { + *ptr = '\0'; + } } } @@ -157,27 +159,7 @@ pmix_status_t pmix_start_listening(pmix_listener_t *lt) } if (PMIX_SUCCESS != rc && !pmix_server_globals.listen_thread_active) { - /*** spawn internal listener thread */ - if (0 > pipe(pmix_server_globals.stop_thread)) { - PMIX_ERROR_LOG(PMIX_ERR_IN_ERRNO); - return PMIX_ERR_OUT_OF_RESOURCE; - } - /* Make sure the pipe FDs are set to close-on-exec so that - they don't leak into children */ - if (pmix_fd_set_cloexec(pmix_server_globals.stop_thread[0]) != PMIX_SUCCESS || - pmix_fd_set_cloexec(pmix_server_globals.stop_thread[1]) != PMIX_SUCCESS) { - PMIX_ERROR_LOG(PMIX_ERR_IN_ERRNO); - close(pmix_server_globals.stop_thread[0]); - close(pmix_server_globals.stop_thread[1]); - return PMIX_ERR_OUT_OF_RESOURCE; - } - /* fork off the listener thread */ - if (0 > pthread_create(&engine, NULL, listen_thread, NULL)) { - pmix_server_globals.listen_thread_active = false; - return PMIX_ERROR; - } else { - pmix_server_globals.listen_thread_active = true; - } + *need_listener = true; } return PMIX_SUCCESS; @@ -188,6 +170,31 @@ sockerror: return PMIX_ERROR; } +pmix_status_t pmix_start_listening(void) { + /*** spawn internal listener thread */ + if (0 > pipe(pmix_server_globals.stop_thread)) { + PMIX_ERROR_LOG(PMIX_ERR_IN_ERRNO); + return PMIX_ERR_OUT_OF_RESOURCE; + } + /* Make sure the pipe FDs are set to close-on-exec so that + they don't leak into children */ + if (pmix_fd_set_cloexec(pmix_server_globals.stop_thread[0]) != PMIX_SUCCESS || + pmix_fd_set_cloexec(pmix_server_globals.stop_thread[1]) != PMIX_SUCCESS) { + PMIX_ERROR_LOG(PMIX_ERR_IN_ERRNO); + close(pmix_server_globals.stop_thread[0]); + close(pmix_server_globals.stop_thread[1]); + return PMIX_ERR_OUT_OF_RESOURCE; + } + /* fork off the listener thread */ + pmix_server_globals.listen_thread_active = true; + if (0 > pthread_create(&engine, NULL, listen_thread, NULL)) { + pmix_server_globals.listen_thread_active = false; + return PMIX_ERROR; + } + + return PMIX_SUCCESS; +} + void pmix_stop_listening(void) { int i; @@ -533,6 +540,8 @@ static pmix_status_t pmix_server_authenticate(pmix_pending_connection_t *pnd, pmix_peer_t *psave = NULL; bool found; pmix_proc_t proc; + uid_t uid; + gid_t gid; pmix_output_verbose(2, pmix_globals.debug_output, "RECV CONNECT ACK FROM PEER ON SOCKET %d", @@ -720,9 +729,24 @@ static pmix_status_t pmix_server_authenticate(pmix_pending_connection_t *pnd, } } } else { + /* get the tool socket's uid and gid so we can pass them to + * the host RM for validation */ + if (PMIX_SUCCESS != (rc = pmix_util_getid(pnd->sd, &uid, &gid))) { + return rc; + } + /* we pass this info in an array of pmix_info_t structs, + * so set that up here */ + pnd->ninfo = 2; + PMIX_INFO_CREATE(pnd->info, pnd->ninfo); + (void)strncpy(pnd->info[0].key, PMIX_USERID, PMIX_MAX_KEYLEN); + pnd->info[0].value.type = PMIX_UINT32; + pnd->info[0].value.data.uint32 = uid; + (void)strncpy(pnd->info[1].key, PMIX_GRPID, PMIX_MAX_KEYLEN); + pnd->info[0].value.type = PMIX_UINT32; + pnd->info[0].value.data.uint32 = gid; /* request an nspace for this requestor - it will * automatically be assigned rank=0 */ - pmix_host_server.tool_connected(NULL, 0, cnct_cbfunc, pnd); + pmix_host_server.tool_connected(pnd->info, pnd->ninfo, cnct_cbfunc, pnd); return PMIX_ERR_OPERATION_IN_PROGRESS; } return rc; @@ -799,7 +823,6 @@ static void tool_handler(int sd, short flags, void* cbdata) /* initiate the authentication handshake */ if (PMIX_ERR_OPERATION_IN_PROGRESS != pmix_server_authenticate(pnd, NULL, NULL)) { - pmix_output(0, "SHOOT"); CLOSE_THE_SOCKET(pnd->sd); PMIX_RELEASE(pnd); } diff --git a/opal/mca/pmix/pmix2x/pmix/src/server/pmix_server_ops.c b/opal/mca/pmix/pmix2x/pmix/src/server/pmix_server_ops.c old mode 100755 new mode 100644 index 633ca71a6d..56944e9902 --- a/opal/mca/pmix/pmix2x/pmix/src/server/pmix_server_ops.c +++ b/opal/mca/pmix/pmix2x/pmix/src/server/pmix_server_ops.c @@ -1118,7 +1118,7 @@ pmix_status_t pmix_server_register_events(pmix_peer_t *peer, } } -cleanup: + cleanup: pmix_output_verbose(2, pmix_globals.debug_output, "server register events: ninfo =%lu rc =%d", ninfo, rc); /* be sure to execute the callback */ @@ -1175,7 +1175,8 @@ void pmix_server_deregister_events(pmix_peer_t *peer, { int32_t cnt; pmix_status_t rc, *codes = NULL, *cdptr, maxcode = PMIX_MAX_ERR_CONSTANT; - size_t ncodes, ncds, n; + pmix_info_t *info = NULL; + size_t ninfo=0, ncodes, ncds, n; pmix_regevents_info_t *reginfo = NULL; pmix_regevents_info_t *reginfo_next; pmix_peer_events_info_t *prev; @@ -1230,11 +1231,13 @@ void pmix_server_deregister_events(pmix_peer_t *peer, } } - cleanup: if (NULL != codes) { free(codes); } + if (NULL != info) { + PMIX_INFO_FREE(info, ninfo); + } return; } @@ -1384,7 +1387,6 @@ pmix_status_t pmix_server_query(pmix_peer_t *peer, - /***** INSTANCE SERVER LIBRARY CLASSES *****/ static void tcon(pmix_server_trkr_t *t) { @@ -1520,13 +1522,14 @@ PMIX_CLASS_INSTANCE(pmix_dmdx_local_t, static void pccon(pmix_pending_connection_t *p) { - p->msg = NULL; memset(p->nspace, 0, PMIX_MAX_NSLEN+1); + p->info = NULL; + p->ninfo = 0; } static void pcdes(pmix_pending_connection_t *p) { - if (NULL != p->msg) { - free(p->msg); + if (NULL != p->info) { + PMIX_INFO_FREE(p->info, p->ninfo); } } PMIX_CLASS_INSTANCE(pmix_pending_connection_t, diff --git a/opal/mca/pmix/pmix2x/pmix/src/server/pmix_server_ops.h b/opal/mca/pmix/pmix2x/pmix/src/server/pmix_server_ops.h index a1bcff3c63..963f353497 100644 --- a/opal/mca/pmix/pmix2x/pmix/src/server/pmix_server_ops.h +++ b/opal/mca/pmix/pmix2x/pmix/src/server/pmix_server_ops.h @@ -6,6 +6,8 @@ * Copyright (c) 2015 Mellanox Technologies, Inc. * All rights reserved. * Copyright (c) 2016 IBM Corporation. All rights reserved. + * Copyright (c) 2016 Research Organization for Information Science + * and Technology (RIST). All rights reserved. * $COPYRIGHT$ */ @@ -97,7 +99,8 @@ typedef struct { pmix_listener_protocol_t protocol; int sd; char nspace[PMIX_MAX_NSLEN+1]; - char *msg; + pmix_info_t *info; + size_t ninfo; pmix_status_t status; struct sockaddr_storage addr; } pmix_pending_connection_t; @@ -212,7 +215,8 @@ PMIX_CLASS_DECLARATION(pmix_usock_queue_t); event_active(&queue->ev, EV_WRITE, 1); \ } while (0) -pmix_status_t pmix_start_listening(pmix_listener_t *lt); +pmix_status_t pmix_prepare_listening(pmix_listener_t *lt, bool *need_listener); +pmix_status_t pmix_start_listening(void); void pmix_stop_listening(void); bool pmix_server_trk_update(pmix_server_trkr_t *trk); @@ -279,15 +283,15 @@ pmix_status_t pmix_server_register_events(pmix_peer_t *peer, void pmix_server_deregister_events(pmix_peer_t *peer, pmix_buffer_t *buf); -pmix_status_t pmix_server_event_recvd_from_client(pmix_peer_t *peer, - pmix_buffer_t *buf, - pmix_op_cbfunc_t cbfunc, - void *cbdata); pmix_status_t pmix_server_query(pmix_peer_t *peer, pmix_buffer_t *buf, pmix_info_cbfunc_t cbfunc, void *cbdata); +pmix_status_t pmix_server_event_recvd_from_client(pmix_peer_t *peer, + pmix_buffer_t *buf, + pmix_op_cbfunc_t cbfunc, + void *cbdata); void pmix_server_execute_collective(int sd, short args, void *cbdata); void pmix_server_queue_message(int fd, short args, void *cbdata); diff --git a/opal/mca/pmix/pmix2x/pmix/src/tool/pmix_tool.c b/opal/mca/pmix/pmix2x/pmix/src/tool/pmix_tool.c index 7e997bcd75..6739266e61 100755 --- a/opal/mca/pmix/pmix2x/pmix/src/tool/pmix_tool.c +++ b/opal/mca/pmix/pmix2x/pmix/src/tool/pmix_tool.c @@ -190,12 +190,11 @@ PMIX_EXPORT int PMIx_tool_init(pmix_proc_t *proc, pmix_status_t rc; pmix_nspace_t *nptr, *nsptr; int server_pid = -1; - int hostnamelen = 10; + int hostnamelen = 30; char hostname[hostnamelen]; DIR *cur_dirp = NULL; struct dirent * dir_entry; -pmix_output(0, "TOOL INIT"); if (NULL == proc) { return PMIX_ERR_BAD_PARAM; } @@ -260,8 +259,10 @@ pmix_output(0, "TOOL INIT"); /* setup the path to the daemon rendezvous point */ memset(&address, 0, sizeof(struct sockaddr_un)); address.sun_family = AF_UNIX; - /* Get first 10 char's of hostname to match what the server is doing */ + /* Get hostname to match what the server is doing */ gethostname(hostname, hostnamelen); + /* ensure it is NULL terminated */ + hostname[hostnamelen-1] = '\0'; /* if they gave us a specific pid, then look for that * particular server - otherwise, see if there is only @@ -787,7 +788,6 @@ static pmix_status_t recv_connect_ack(int sd) if (sockopt) { if (0 != setsockopt(sd, SOL_SOCKET, SO_RCVTIMEO, &save, sz)) { - pmix_output(0, "FAILURE"); return PMIX_ERR_UNREACH; } } diff --git a/opal/mca/pmix/pmix2x/pmix/src/usock/usock_sendrecv.c b/opal/mca/pmix/pmix2x/pmix/src/usock/usock_sendrecv.c index 139cb856df..5fb952c3a4 100644 --- a/opal/mca/pmix/pmix2x/pmix/src/usock/usock_sendrecv.c +++ b/opal/mca/pmix/pmix2x/pmix/src/usock/usock_sendrecv.c @@ -227,7 +227,7 @@ void pmix_usock_send_handler(int sd, short flags, void *cbdata) pmix_output_verbose(2, pmix_globals.debug_output, "sock:send_handler SENDING TO PEER %s:%d tag %d with %s msg", peer->info->nptr->nspace, peer->info->rank, - (NULL == msg) ? -1 : msg->hdr.tag, + (NULL == msg) ? UINT_MAX : msg->hdr.tag, (NULL == msg) ? "NULL" : "NON-NULL"); if (NULL != msg) { if (!msg->hdr_sent) { diff --git a/opal/mca/pmix/pmix2x/pmix/src/util/Makefile.am b/opal/mca/pmix/pmix2x/pmix/src/util/Makefile.am index 23616af853..40cec232a4 100644 --- a/opal/mca/pmix/pmix2x/pmix/src/util/Makefile.am +++ b/opal/mca/pmix/pmix2x/pmix/src/util/Makefile.am @@ -35,7 +35,8 @@ headers += \ src/util/os_path.h \ src/util/basename.h \ src/util/hash.h \ - src/util/strnlen.h + src/util/strnlen.h \ + src/util/getid.h sources += \ src/util/argv.c \ @@ -49,4 +50,5 @@ sources += \ src/util/timings.c \ src/util/os_path.c \ src/util/basename.c \ - src/util/hash.c + src/util/hash.c \ + src/util/getid.c diff --git a/opal/mca/pmix/pmix2x/pmix/src/util/getid.c b/opal/mca/pmix/pmix2x/pmix/src/util/getid.c new file mode 100644 index 0000000000..72b08c3573 --- /dev/null +++ b/opal/mca/pmix/pmix2x/pmix/src/util/getid.c @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana + * University Research and Technology + * Corporation. All rights reserved. + * Copyright (c) 2004-2013 The University of Tennessee and The University + * of Tennessee Research Foundation. All rights + * reserved. + * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart, + * University of Stuttgart. All rights reserved. + * Copyright (c) 2004-2005 The Regents of the University of California. + * All rights reserved. + * Copyright (c) 2007 Cisco Systems, Inc. All rights reserved. + * Copyright (c) 2015 Intel, Inc. All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +/* + * Buffer safe printf functions for portability to archaic platforms. + */ + +#include +#include "include/pmix/pmix_common.h" +#include "src/include/pmix_socket_errno.h" + +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +#include "src/include/pmix_globals.h" +#include "src/util/error.h" +#include "src/util/output.h" + +#include "src/util/getid.h" + +pmix_status_t pmix_util_getid(int sd, uid_t *uid, gid_t *gid) +{ +#if defined(SO_PEERCRED) +#ifdef HAVE_STRUCT_SOCKPEERCRED_UID +#define HAVE_STRUCT_UCRED_UID + struct sockpeercred ucred; +#else + struct ucred ucred; +#endif + socklen_t crlen = sizeof (ucred); +#endif + +#if defined(SO_PEERCRED) && (defined(HAVE_STRUCT_UCRED_UID) || defined(HAVE_STRUCT_UCRED_CR_UID)) + /* Ignore received 'cred' and validate ucred for socket instead. */ + pmix_output_verbose(2, pmix_globals.debug_output, + "getid: checking getsockopt for peer credentials"); + if (getsockopt(sd, SOL_SOCKET, SO_PEERCRED, &ucred, &crlen) < 0) { + pmix_output_verbose(2, pmix_globals.debug_output, + "getid: getsockopt SO_PEERCRED failed: %s", + strerror (pmix_socket_errno)); + return PMIX_ERR_INVALID_CRED; + } +#if defined(HAVE_STRUCT_UCRED_UID) + *uid = ucred.uid; + *gid = ucred.gid; +#else + *uid = ucred.cr_uid; + *gid = ucred.cr_gid; +#endif + +#elif defined(HAVE_GETPEEREID) + pmix_output_verbose(2, pmix_globals.debug_output, + "getid: checking getpeereid for peer credentials"); + if (0 != getpeereid(sd, uid, gid)) { + pmix_output_verbose(2, pmix_globals.debug_output, + "getid: getsockopt getpeereid failed: %s", + strerror (pmix_socket_errno)); + return PMIX_ERR_INVALID_CRED; + } +#else + return PMIX_ERR_NOT_SUPPORTED; +#endif + + return PMIX_SUCCESS; +} diff --git a/opal/mca/pmix/pmix2x/pmix/src/util/getid.h b/opal/mca/pmix/pmix2x/pmix/src/util/getid.h new file mode 100644 index 0000000000..f617f0a57b --- /dev/null +++ b/opal/mca/pmix/pmix2x/pmix/src/util/getid.h @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2016 Intel, Inc. All rights reserved. + * $COPYRIGHT$ + * + * Additional copyrights may follow + * + * $HEADER$ + */ + +#ifndef PMIX_GETID_H +#define PMIX_GETID_H + +#include +#include "include/pmix/pmix_common.h" + +#ifdef HAVE_UNISTD_H +#include +#endif +#ifdef HAVE_SYS_TYPES_H +#include +#endif + +BEGIN_C_DECLS + +/* lookup the effective uid and gid of a socket */ +pmix_status_t pmix_util_getid(int sd, uid_t *uid, gid_t *gid); + +END_C_DECLS + +#endif /* PMIX_PRINTF_H */ + diff --git a/opal/mca/pmix/pmix2x/pmix/test/simple/simptest.c b/opal/mca/pmix/pmix2x/pmix/test/simple/simptest.c index 78b39badf7..59951ca86b 100644 --- a/opal/mca/pmix/pmix2x/pmix/test/simple/simptest.c +++ b/opal/mca/pmix/pmix2x/pmix/test/simple/simptest.c @@ -83,8 +83,8 @@ static pmix_status_t disconnect_fn(const pmix_proc_t procs[], size_t nprocs, static pmix_status_t register_event_fn(pmix_status_t *codes, size_t ncodes, const pmix_info_t info[], size_t ninfo, pmix_op_cbfunc_t cbfunc, void *cbdata); -static pmix_status_t deregister_event_fn(pmix_status_t *codes, size_t ncodes, - pmix_op_cbfunc_t cbfunc, void *cbdata); +static pmix_status_t deregister_events(pmix_status_t *codes, size_t ncodes, + pmix_op_cbfunc_t cbfunc, void *cbdata); static pmix_status_t notify_event(pmix_status_t code, const pmix_proc_t *source, pmix_data_range_t range, @@ -112,7 +112,7 @@ static pmix_server_module_t mymodule = { .connect = connect_fn, .disconnect = disconnect_fn, .register_events = register_event_fn, - .deregister_events = deregister_event_fn, + .deregister_events = deregister_events, .notify_event = notify_event, .query = query_fn, .tool_connected = tool_connect_fn @@ -687,13 +687,9 @@ static pmix_status_t register_event_fn(pmix_status_t *codes, size_t ncodes, return PMIX_SUCCESS; } -static pmix_status_t deregister_event_fn(pmix_status_t *codes, size_t ncodes, - pmix_op_cbfunc_t cbfunc, void *cbdata) +static pmix_status_t deregister_events(pmix_status_t *codes, size_t ncodes, + pmix_op_cbfunc_t cbfunc, void *cbdata) { - pmix_output(0, "SERVER: DEREGISTER EVENT"); - if (NULL != cbfunc) { - cbfunc(PMIX_SUCCESS, cbdata); - } return PMIX_SUCCESS; }