From 1d38430e43606160ad16b7abeccc26ae8c018f5b Mon Sep 17 00:00:00 2001 From: Gilles Gouaillardet Date: Thu, 14 Jan 2016 10:34:44 +0900 Subject: [PATCH] opal: replace opal_convert_jobid_to_string with opal_snprintf_jobid --- .../mca/pmix/external/pmix_ext_server_north.c | 6 ++-- .../mca/pmix/external/pmix_ext_server_south.c | 14 ++++----- opal/mca/pmix/pmix112/pmix1_server_north.c | 6 ++-- opal/mca/pmix/pmix112/pmix1_server_south.c | 14 ++++----- opal/mca/pmix/pmix120/pmix120_server_north.c | 6 ++-- opal/mca/pmix/pmix120/pmix120_server_south.c | 14 ++++----- opal/util/proc.c | 9 +++--- opal/util/proc.h | 4 +-- orte/orted/pmix/pmix_server_dyn.c | 4 +-- orte/runtime/orte_init.c | 12 ++------ orte/util/name_fns.c | 30 +++++++++++++++---- orte/util/name_fns.h | 3 +- 12 files changed, 67 insertions(+), 55 deletions(-) diff --git a/opal/mca/pmix/external/pmix_ext_server_north.c b/opal/mca/pmix/external/pmix_ext_server_north.c index 0112eb5aa26..8b75dcf7013 100644 --- a/opal/mca/pmix/external/pmix_ext_server_north.c +++ b/opal/mca/pmix/external/pmix_ext_server_north.c @@ -1,7 +1,7 @@ /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2014-2015 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 Mellanox Technologies, Inc. * All rights reserved. @@ -415,7 +415,7 @@ static void opal_lkupcbfunc(int status, n=0; OPAL_LIST_FOREACH(p, data, opal_pmix_pdata_t) { /* convert the jobid */ - (void)snprintf(d[n].proc.nspace, PMIX_MAX_NSLEN, "%s", opal_convert_jobid_to_string(p->proc.jobid)); + (void)opal_snprintf_jobid(d[n].proc.nspace, PMIX_MAX_NSLEN, p->proc.jobid); d[n].proc.rank = p->proc.vpid; (void)strncpy(d[n].key, p->value.key, PMIX_MAX_KEYLEN); pmix1_value_load(&d[n].value, &p->value); @@ -534,7 +534,7 @@ static void opal_spncbfunc(int status, opal_jobid_t jobid, void *cbdata) if (NULL != opalcaddy->spwncbfunc) { rc = pmix1_convert_opalrc(status); /* convert the jobid */ - (void)snprintf(nspace, PMIX_MAX_NSLEN, "%s", opal_convert_jobid_to_string(jobid)); + (void)opal_snprintf_jobid(nspace, PMIX_MAX_NSLEN, jobid); opalcaddy->spwncbfunc(rc, nspace, opalcaddy->cbdata); } OBJ_RELEASE(opalcaddy); diff --git a/opal/mca/pmix/external/pmix_ext_server_south.c b/opal/mca/pmix/external/pmix_ext_server_south.c index 2462ec4a23b..2feed763098 100644 --- a/opal/mca/pmix/external/pmix_ext_server_south.c +++ b/opal/mca/pmix/external/pmix_ext_server_south.c @@ -1,7 +1,7 @@ /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2014-2015 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 Intel, Inc. All rights reserved. * Copyright (c) 2014 Mellanox Technologies, Inc. @@ -209,7 +209,7 @@ int pmix1_server_register_nspace(opal_jobid_t jobid, opal_pmix1_jobid_trkr_t *job; /* convert the jobid */ - (void)snprintf(nspace, PMIX_MAX_NSLEN, opal_convert_jobid_to_string(jobid)); + (void)opal_snprintf_jobid(nspace, PMIX_MAX_NSLEN, jobid); /* store this job in our list of known nspaces */ job = OBJ_NEW(opal_pmix1_jobid_trkr_t); @@ -295,7 +295,7 @@ int pmix1_server_register_client(const opal_process_name_t *proc, op->cbdata = cbdata; /* convert the jobid */ - (void)strncpy(op->p.nspace, opal_convert_jobid_to_string(proc->jobid), PMIX_MAX_NSLEN); + (void)opal_snprintf_jobid(op->p.nspace, PMIX_MAX_NSLEN, proc->jobid); op->p.rank = proc->vpid; rc = PMIx_server_register_client(&op->p, uid, gid, server_object, @@ -330,7 +330,7 @@ int pmix1_server_setup_fork(const opal_process_name_t *proc, char ***env) pmix_proc_t p; /* convert the jobid */ - (void)strncpy(p.nspace, opal_convert_jobid_to_string(proc->jobid), PMIX_MAX_NSLEN); + (void)opal_snprintf_jobid(p.nspace, PMIX_MAX_NSLEN, proc->jobid); p.rank = proc->vpid; rc = PMIx_server_setup_fork(&p, env); @@ -364,7 +364,7 @@ int pmix1_server_dmodex(const opal_process_name_t *proc, op->cbdata = cbdata; /* convert the jobid */ - (void)strncpy(op->p.nspace, opal_convert_jobid_to_string(proc->jobid), PMIX_MAX_NSLEN); + (void)opal_snprintf_jobid(op->p.nspace, PMIX_MAX_NSLEN, proc->jobid); op->p.rank = proc->vpid; /* find the internally-cached data for this proc */ @@ -395,7 +395,7 @@ int pmix1_server_notify_error(int status, PMIX_PROC_CREATE(ps, psz); n = 0; OPAL_LIST_FOREACH(nm, procs, opal_namelist_t) { - (void)snprintf(ps[n].nspace, PMIX_MAX_NSLEN, opal_convert_jobid_to_string(nm->name.jobid)); + (void)opal_snprintf_jobid(ps[n].nspace, PMIX_MAX_NSLEN, nm->name.jobid); ps[n].rank = (int)nm->name.vpid; ++n; } @@ -408,7 +408,7 @@ int pmix1_server_notify_error(int status, PMIX_PROC_CREATE(eps, esz); n = 0; OPAL_LIST_FOREACH(nm, error_procs, opal_namelist_t) { - (void)snprintf(eps[n].nspace, PMIX_MAX_NSLEN, opal_convert_jobid_to_string(nm->name.jobid)); + (void)opal_snprintf_jobid(eps[n].nspace, PMIX_MAX_NSLEN, nm->name.jobid); eps[n].rank = (int)nm->name.vpid; ++n; } diff --git a/opal/mca/pmix/pmix112/pmix1_server_north.c b/opal/mca/pmix/pmix112/pmix1_server_north.c index b4a95740d39..c2fbfc9a265 100644 --- a/opal/mca/pmix/pmix112/pmix1_server_north.c +++ b/opal/mca/pmix/pmix112/pmix1_server_north.c @@ -1,7 +1,7 @@ /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2014-2015 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 Mellanox Technologies, Inc. * All rights reserved. @@ -415,7 +415,7 @@ static void opal_lkupcbfunc(int status, n=0; OPAL_LIST_FOREACH(p, data, opal_pmix_pdata_t) { /* convert the jobid */ - (void)snprintf(d[n].proc.nspace, PMIX_MAX_NSLEN, "%s", opal_convert_jobid_to_string(p->proc.jobid)); + (void)opal_snprintf_jobid(d[n].proc.nspace, PMIX_MAX_NSLEN, p->proc.jobid); d[n].proc.rank = p->proc.vpid; (void)strncpy(d[n].key, p->value.key, PMIX_MAX_KEYLEN); pmix1_value_load(&d[n].value, &p->value); @@ -534,7 +534,7 @@ static void opal_spncbfunc(int status, opal_jobid_t jobid, void *cbdata) if (NULL != opalcaddy->spwncbfunc) { rc = pmix1_convert_opalrc(status); /* convert the jobid */ - (void)snprintf(nspace, PMIX_MAX_NSLEN, "%s", opal_convert_jobid_to_string(jobid)); + (void)opal_snprintf_jobid(nspace, PMIX_MAX_NSLEN, jobid); opalcaddy->spwncbfunc(rc, nspace, opalcaddy->cbdata); } OBJ_RELEASE(opalcaddy); diff --git a/opal/mca/pmix/pmix112/pmix1_server_south.c b/opal/mca/pmix/pmix112/pmix1_server_south.c index ba42d1defeb..efde1eab995 100644 --- a/opal/mca/pmix/pmix112/pmix1_server_south.c +++ b/opal/mca/pmix/pmix112/pmix1_server_south.c @@ -1,7 +1,7 @@ /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2014-2015 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 Mellanox Technologies, Inc. * All rights reserved. @@ -197,7 +197,7 @@ int pmix1_server_register_nspace(opal_jobid_t jobid, opal_pmix1_jobid_trkr_t *job; /* convert the jobid */ - (void)snprintf(nspace, PMIX_MAX_NSLEN, opal_convert_jobid_to_string(jobid)); + (void)opal_snprintf_jobid(nspace, PMIX_MAX_NSLEN, jobid); /* store this job in our list of known nspaces */ job = OBJ_NEW(opal_pmix1_jobid_trkr_t); @@ -283,7 +283,7 @@ int pmix1_server_register_client(const opal_process_name_t *proc, op->cbdata = cbdata; /* convert the jobid */ - (void)strncpy(op->p.nspace, opal_convert_jobid_to_string(proc->jobid), PMIX_MAX_NSLEN); + (void)opal_snprintf_jobid(op->p.nspace, PMIX_MAX_NSLEN, proc->jobid); op->p.rank = proc->vpid; rc = PMIx_server_register_client(&op->p, uid, gid, server_object, @@ -318,7 +318,7 @@ int pmix1_server_setup_fork(const opal_process_name_t *proc, char ***env) pmix_proc_t p; /* convert the jobid */ - (void)strncpy(p.nspace, opal_convert_jobid_to_string(proc->jobid), PMIX_MAX_NSLEN); + (void)opal_snprintf_jobid(p.nspace, PMIX_MAX_NSLEN, proc->jobid); p.rank = proc->vpid; rc = PMIx_server_setup_fork(&p, env); @@ -352,7 +352,7 @@ int pmix1_server_dmodex(const opal_process_name_t *proc, op->cbdata = cbdata; /* convert the jobid */ - (void)strncpy(op->p.nspace, opal_convert_jobid_to_string(proc->jobid), PMIX_MAX_NSLEN); + (void)opal_snprintf_jobid(op->p.nspace, PMIX_MAX_NSLEN, proc->jobid); op->p.rank = proc->vpid; /* find the internally-cached data for this proc */ @@ -383,7 +383,7 @@ int pmix1_server_notify_error(int status, PMIX_PROC_CREATE(ps, psz); n = 0; OPAL_LIST_FOREACH(nm, procs, opal_namelist_t) { - (void)snprintf(ps[n].nspace, PMIX_MAX_NSLEN, opal_convert_jobid_to_string(nm->name.jobid)); + (void)opal_snprintf_jobid(ps[n].nspace, PMIX_MAX_NSLEN, nm->name.jobid); ps[n].rank = (int)nm->name.vpid; ++n; } @@ -396,7 +396,7 @@ int pmix1_server_notify_error(int status, PMIX_PROC_CREATE(eps, esz); n = 0; OPAL_LIST_FOREACH(nm, error_procs, opal_namelist_t) { - (void)snprintf(eps[n].nspace, PMIX_MAX_NSLEN, opal_convert_jobid_to_string(nm->name.jobid)); + (void)opal_snprintf_jobid(eps[n].nspace, PMIX_MAX_NSLEN, nm->name.jobid); eps[n].rank = (int)nm->name.vpid; ++n; } diff --git a/opal/mca/pmix/pmix120/pmix120_server_north.c b/opal/mca/pmix/pmix120/pmix120_server_north.c index 6d2c0e27528..b484ab7da4a 100644 --- a/opal/mca/pmix/pmix120/pmix120_server_north.c +++ b/opal/mca/pmix/pmix120/pmix120_server_north.c @@ -1,7 +1,7 @@ /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2014-2015 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 Mellanox Technologies, Inc. * All rights reserved. @@ -415,7 +415,7 @@ static void opal_lkupcbfunc(int status, n=0; OPAL_LIST_FOREACH(p, data, opal_pmix_pdata_t) { /* convert the jobid */ - (void)snprintf(d[n].proc.nspace, PMIX_MAX_NSLEN, "%s", opal_convert_jobid_to_string(p->proc.jobid)); + (void)opal_snprintf_jobid(d[n].proc.nspace, PMIX_MAX_NSLEN, p->proc.jobid); d[n].proc.rank = p->proc.vpid; (void)strncpy(d[n].key, p->value.key, PMIX_MAX_KEYLEN); pmix120_value_load(&d[n].value, &p->value); @@ -534,7 +534,7 @@ static void opal_spncbfunc(int status, opal_jobid_t jobid, void *cbdata) if (NULL != opalcaddy->spwncbfunc) { rc = pmix120_convert_opalrc(status); /* convert the jobid */ - (void)snprintf(nspace, PMIX_MAX_NSLEN, "%s", opal_convert_jobid_to_string(jobid)); + (void)opal_snprintf_jobid(nspace, PMIX_MAX_NSLEN, jobid); opalcaddy->spwncbfunc(rc, nspace, opalcaddy->cbdata); } OBJ_RELEASE(opalcaddy); diff --git a/opal/mca/pmix/pmix120/pmix120_server_south.c b/opal/mca/pmix/pmix120/pmix120_server_south.c index fa8256ed82f..ab6aa893be2 100644 --- a/opal/mca/pmix/pmix120/pmix120_server_south.c +++ b/opal/mca/pmix/pmix120/pmix120_server_south.c @@ -1,7 +1,7 @@ /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil -*- */ /* * Copyright (c) 2014-2015 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 Mellanox Technologies, Inc. * All rights reserved. @@ -140,7 +140,7 @@ int pmix120_server_register_nspace(opal_jobid_t jobid, opal_pmix120_jobid_trkr_t *job; /* convert the jobid */ - (void)snprintf(nspace, PMIX_MAX_NSLEN, opal_convert_jobid_to_string(jobid)); + (void)opal_snprintf_jobid(nspace, PMIX_MAX_NSLEN, jobid); /* store this job in our list of known nspaces */ job = OBJ_NEW(opal_pmix120_jobid_trkr_t); @@ -226,7 +226,7 @@ int pmix120_server_register_client(const opal_process_name_t *proc, op->cbdata = cbdata; /* convert the jobid */ - (void)strncpy(op->p.nspace, opal_convert_jobid_to_string(proc->jobid), PMIX_MAX_NSLEN); + (void)opal_snprintf_jobid(op->p.nspace, PMIX_MAX_NSLEN, proc->jobid); op->p.rank = proc->vpid; rc = PMIx_server_register_client(&op->p, uid, gid, server_object, @@ -261,7 +261,7 @@ int pmix120_server_setup_fork(const opal_process_name_t *proc, char ***env) pmix_proc_t p; /* convert the jobid */ - (void)strncpy(p.nspace, opal_convert_jobid_to_string(proc->jobid), PMIX_MAX_NSLEN); + (void)opal_snprintf_jobid(p.nspace, PMIX_MAX_NSLEN, proc->jobid); p.rank = proc->vpid; rc = PMIx_server_setup_fork(&p, env); @@ -295,7 +295,7 @@ int pmix120_server_dmodex(const opal_process_name_t *proc, op->cbdata = cbdata; /* convert the jobid */ - (void)strncpy(op->p.nspace, opal_convert_jobid_to_string(proc->jobid), PMIX_MAX_NSLEN); + (void)opal_snprintf_jobid(op->p.nspace, PMIX_MAX_NSLEN, proc->jobid); op->p.rank = proc->vpid; /* find the internally-cached data for this proc */ @@ -326,7 +326,7 @@ int pmix120_server_notify_error(int status, PMIX_PROC_CREATE(ps, psz); n = 0; OPAL_LIST_FOREACH(nm, procs, opal_namelist_t) { - (void)snprintf(ps[n].nspace, PMIX_MAX_NSLEN, opal_convert_jobid_to_string(nm->name.jobid)); + (void)opal_snprintf_jobid(ps[n].nspace, PMIX_MAX_NSLEN, nm->name.jobid); ps[n].rank = (int)nm->name.vpid; ++n; } @@ -339,7 +339,7 @@ int pmix120_server_notify_error(int status, PMIX_PROC_CREATE(eps, esz); n = 0; OPAL_LIST_FOREACH(nm, error_procs, opal_namelist_t) { - (void)snprintf(eps[n].nspace, PMIX_MAX_NSLEN, opal_convert_jobid_to_string(nm->name.jobid)); + (void)opal_snprintf_jobid(eps[n].nspace, PMIX_MAX_NSLEN, nm->name.jobid); eps[n].rank = (int)nm->name.vpid; ++n; } diff --git a/opal/util/proc.c b/opal/util/proc.c index 5fba5fd6a36..94fd1f5551f 100644 --- a/opal/util/proc.c +++ b/opal/util/proc.c @@ -5,7 +5,7 @@ * reserved. * Copyright (c) 2013 Inria. All rights reserved. * Copyright (c) 2014-2015 Intel, Inc. All rights reserved. - * Copyright (c) 2014 Research Organization for Information Science + * Copyright (c) 2014-2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. * Copyright (c) 2015 Los Alamos National Security, LLC. All rights * reserved. @@ -154,10 +154,9 @@ static int opal_convert_process_name_to_string_should_never_be_called(char** nam return OPAL_ERR_NOT_SUPPORTED; } -static char* opal_convert_jobid_to_string_should_never_be_called(opal_jobid_t jobid) +static int opal_snprintf_jobid_should_never_be_called(char* name_string, size_t size, opal_jobid_t jobid) { - char *str = strdup("My JOBID"); - return str; + return strncpy(name_string, "My JOBID", size); } static int opal_convert_string_to_jobid_should_never_be_called(opal_jobid_t *jobid, const char *jobid_string) @@ -175,7 +174,7 @@ char* (*opal_vpid_print)(const opal_vpid_t) = opal_vpid_print_should_never_be_ca char* (*opal_jobid_print)(const opal_jobid_t) = opal_jobid_print_should_never_be_called; int (*opal_convert_string_to_process_name)(opal_process_name_t *name, const char* name_string) = opal_convert_string_to_process_name_should_never_be_called; int (*opal_convert_process_name_to_string)(char** name_string, const opal_process_name_t *name) = opal_convert_process_name_to_string_should_never_be_called; -char* (*opal_convert_jobid_to_string)(opal_jobid_t jobid) = opal_convert_jobid_to_string_should_never_be_called; +int (*opal_snprintf_jobid)(char* name_string, size_t size, opal_jobid_t jobid) = opal_snprintf_jobid_should_never_be_called; int (*opal_convert_string_to_jobid)(opal_jobid_t *jobid, const char *jobid_string) = opal_convert_string_to_jobid_should_never_be_called; struct opal_proc_t *(*opal_proc_for_name) (const opal_process_name_t name) = opal_proc_for_name_should_never_be_called; diff --git a/opal/util/proc.h b/opal/util/proc.h index 250430ba3cf..15d37a1063f 100644 --- a/opal/util/proc.h +++ b/opal/util/proc.h @@ -4,7 +4,7 @@ * reserved. * Copyright (c) 2013 Inria. All rights reserved. * Copyright (c) 2014-2015 Intel, Inc. All rights reserved. - * Copyright (c) 2014 Research Organization for Information Science + * Copyright (c) 2014-2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * @@ -133,7 +133,7 @@ OPAL_DECLSPEC extern int (*opal_convert_process_name_to_string)(char** name_stri const opal_process_name_t *name); OPAL_DECLSPEC extern char* (*opal_vpid_print)(const opal_vpid_t); OPAL_DECLSPEC extern char* (*opal_jobid_print)(const opal_jobid_t); -OPAL_DECLSPEC extern char* (*opal_convert_jobid_to_string)(opal_jobid_t jobid); +OPAL_DECLSPEC extern int (*opal_snprintf_jobid)(char* name_string, size_t size, opal_jobid_t jobid); OPAL_DECLSPEC extern int (*opal_convert_string_to_jobid)(opal_jobid_t *jobid, const char *jobid_string); /** diff --git a/orte/orted/pmix/pmix_server_dyn.c b/orte/orted/pmix/pmix_server_dyn.c index 985a3ed1623..134085fee89 100644 --- a/orte/orted/pmix/pmix_server_dyn.c +++ b/orte/orted/pmix/pmix_server_dyn.c @@ -16,7 +16,7 @@ * Copyright (c) 2013-2015 Intel, Inc. All rights reserved. * Copyright (c) 2014 Mellanox Technologies, Inc. * All rights reserved. - * Copyright (c) 2014 Research Organization for Information Science + * Copyright (c) 2014-2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * @@ -413,7 +413,7 @@ static void _cnct(int sd, short args, void *cbdata) } /* ask the global data server for the data - if we get it, * then we can complete the request */ - key = opal_convert_jobid_to_string(nm->name.jobid); + orte_util_convert_jobid_to_string(&key, nm->name.jobid); opal_argv_append_nosize(&keys, key); free(key); if (ORTE_SUCCESS != (rc = pmix_server_lookup_fn(&nm->name, keys, cd->info, _cnlk, cd))) { diff --git a/orte/runtime/orte_init.c b/orte/runtime/orte_init.c index 22815c30931..d4f56d81060 100644 --- a/orte/runtime/orte_init.c +++ b/orte/runtime/orte_init.c @@ -14,7 +14,7 @@ * Copyright (c) 2007-2012 Cisco Systems, Inc. All rights reserved. * Copyright (c) 2007-2008 Sun Microsystems, Inc. All rights reserved. * Copyright (c) 2014-2015 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$ @@ -97,14 +97,6 @@ static int _convert_process_name_to_string(char** name_string, return orte_util_convert_process_name_to_string(name_string, name); } -static char* -_convert_jobid_to_string(opal_jobid_t jobid) -{ - char *str; - orte_util_convert_jobid_to_string(&str, jobid); - return str; -} - static int _convert_string_to_jobid(opal_jobid_t *jobid, const char *jobid_string) { @@ -156,7 +148,7 @@ int orte_init(int* pargc, char*** pargv, orte_proc_type_t flags) opal_compare_proc = _process_name_compare; opal_convert_string_to_process_name = _convert_string_to_process_name; opal_convert_process_name_to_string = _convert_process_name_to_string; - opal_convert_jobid_to_string = _convert_jobid_to_string; + opal_snprintf_jobid = orte_util_snprintf_jobid; opal_convert_string_to_jobid = _convert_string_to_jobid; /* initialize the opal layer */ diff --git a/orte/util/name_fns.c b/orte/util/name_fns.c index 93ec6c7aecc..9674297f0ae 100644 --- a/orte/util/name_fns.c +++ b/orte/util/name_fns.c @@ -10,7 +10,7 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2014-2014 Research Organization for Information Science + * Copyright (c) 2014-2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * @@ -284,19 +284,39 @@ char* orte_util_print_vpids(const orte_vpid_t vpid) /*** STRING FUNCTIONS ***/ -int orte_util_convert_jobid_to_string(char **jobid_string, const orte_jobid_t jobid) + +int orte_util_snprintf_jobid(char *jobid_string, size_t size, const orte_jobid_t jobid) { + int rc; + /* check for wildcard value - handle appropriately */ if (ORTE_JOBID_WILDCARD == jobid) { - *jobid_string = strdup(ORTE_SCHEMA_WILDCARD_STRING); - return ORTE_SUCCESS; + return strncpy(jobid_string, ORTE_SCHEMA_WILDCARD_STRING, size); } - if (0 > asprintf(jobid_string, "%ld", (long) jobid)) { + rc = snprintf(jobid_string, size, "%ld", (long) jobid); + if (0 > rc) { ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); return ORTE_ERR_OUT_OF_RESOURCE; } + return rc; +} + +int orte_util_convert_jobid_to_string(char **jobid_string, const orte_jobid_t jobid) +{ + int rc; + char str[256]; + rc = orte_util_snprintf_jobid(str, 255, jobid); + if (0 > rc) { + *jobid_string = NULL; + return rc; + } + *jobid_string = strdup(str); + if (NULL == *jobid_string) { + ORTE_ERROR_LOG(ORTE_ERR_OUT_OF_RESOURCE); + return ORTE_ERR_OUT_OF_RESOURCE; + } return ORTE_SUCCESS; } diff --git a/orte/util/name_fns.h b/orte/util/name_fns.h index 68cf5d54c7b..3003aa9b3d0 100644 --- a/orte/util/name_fns.h +++ b/orte/util/name_fns.h @@ -10,7 +10,7 @@ * Copyright (c) 2004-2005 The Regents of the University of California. * All rights reserved. * Copyright (c) 2010 Oracle and/or its affiliates. All rights reserved. - * Copyright (c) 2014 Research Organization for Information Science + * Copyright (c) 2014-2016 Research Organization for Information Science * and Technology (RIST). All rights reserved. * $COPYRIGHT$ * @@ -114,6 +114,7 @@ typedef struct orte_namelist_t orte_namelist_t; ORTE_DECLSPEC OBJ_CLASS_DECLARATION(orte_namelist_t); +ORTE_DECLSPEC int orte_util_snprintf_jobid(char *jobid_string, size_t size, const orte_jobid_t jobid); ORTE_DECLSPEC int orte_util_convert_jobid_to_string(char **jobid_string, const orte_jobid_t jobid); ORTE_DECLSPEC int orte_util_convert_string_to_jobid(orte_jobid_t *jobid, const char* jobidstring); ORTE_DECLSPEC int orte_util_convert_vpid_to_string(char **vpid_string, const orte_vpid_t vpid);