2004-01-07 11:35:06 +03:00
|
|
|
/*
|
2007-03-29 05:00:33 +04:00
|
|
|
* Copyright (c) 2004-2007 The Trustees of Indiana University and Indiana
|
2005-11-05 22:57:48 +03:00
|
|
|
* University Research and Technology
|
|
|
|
* Corporation. All rights reserved.
|
|
|
|
* Copyright (c) 2004-2005 The University of Tennessee and The University
|
|
|
|
* of Tennessee Research Foundation. All rights
|
|
|
|
* reserved.
|
2008-07-31 19:46:09 +04:00
|
|
|
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
|
2004-11-28 23:09:25 +03:00
|
|
|
* University of Stuttgart. All rights reserved.
|
2005-03-24 15:43:37 +03:00
|
|
|
* Copyright (c) 2004-2005 The Regents of the University of California.
|
|
|
|
* All rights reserved.
|
2007-04-20 19:31:26 +04:00
|
|
|
* Copyright (c) 2007 Los Alamos National Security, LLC.
|
|
|
|
* All rights reserved.
|
2007-08-01 16:08:11 +04:00
|
|
|
* Copyright (c) 2007 Voltaire. All rights reserved.
|
|
|
|
*
|
2004-11-22 04:38:40 +03:00
|
|
|
* $COPYRIGHT$
|
|
|
|
*
|
|
|
|
* Additional copyrights may follow
|
|
|
|
*
|
2004-01-07 11:35:06 +03:00
|
|
|
* $HEADER$
|
|
|
|
*/
|
|
|
|
|
2004-05-20 16:39:27 +04:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* Generic routines for "argv"-like handling. Helpful for creating
|
|
|
|
* arrays of strings, especially when creating command lines.
|
|
|
|
*/
|
|
|
|
|
2005-07-04 04:13:44 +04:00
|
|
|
#ifndef OPAL_ARGV_H
|
|
|
|
#define OPAL_ARGV_H
|
2006-02-12 04:33:29 +03:00
|
|
|
#include "opal_config.h"
|
2004-01-15 03:57:33 +03:00
|
|
|
|
2005-12-31 17:55:39 +03:00
|
|
|
#ifdef HAVE_SYS_TYPES_H
|
|
|
|
#include <sys/types.h>
|
|
|
|
#endif
|
|
|
|
|
Per the July technical meeting:
Standardize the handling of the orte launch agent option across PLMs. This has been a consistent complaint I have received - each PLM would register its own MCA param to get input on the launch agent for remote nodes (in fact, one or two didn't, but most did). This would then get handled in various and contradictory ways.
Some PLMs would accept only a one-word input. Others accepted multi-word args such as "valgrind orted", but then some would error by putting any prefix specified on the cmd line in front of the incorrect argument.
For example, while using the rsh launcher, if you specified "valgrind orted" as your launch agent and had "--prefix foo" on you cmd line, you would attempt to execute "ssh foo/valgrind orted" - which obviously wouldn't work.
This was all -very- confusing to users, who had to know which PLM was being used so they could even set the right mca param in the first place! And since we don't warn about non-recognized or non-used mca params, half of the time they would wind up not doing what they thought they were telling us to do.
To solve this problem, we did the following:
1. removed all mca params from the individual plms for the launch agent
2. added a new mca param "orte_launch_agent" for this purpose. To further simplify for users, this comes with a new cmd line option "--launch-agent" that can take a multi-word string argument. The value of the param defaults to "orted".
3. added a PLM base function that processes the orte_launch_agent value and adds the contents to a provided argv array. This can subsequently be harvested at-will to handle multi-word values
4. modified the PLMs to use this new function. All the PLMs except for the rsh PLM required very minor change - just called the function and moved on. The rsh PLM required much larger changes as - because of the rsh/ssh cmd line limitations - we had to correctly prepend any provided prefix to the correct argv entry.
5. added a new opal_argv_join_range function that allows the caller to "join" argv entries between two specified indices
Please let me know of any problems. I tried to make this as clean as possible, but cannot compile all PLMs to ensure all is correct.
This commit was SVN r19097.
2008-07-30 22:26:24 +04:00
|
|
|
BEGIN_C_DECLS
|
|
|
|
|
2004-05-20 16:39:27 +04:00
|
|
|
/**
|
|
|
|
* Append a string (by value) to an new or existing NULL-terminated
|
|
|
|
* argv array.
|
|
|
|
*
|
|
|
|
* @param argc Pointer to the length of the argv array. Must not be
|
|
|
|
* NULL.
|
|
|
|
* @param argv Pointer to an argv array.
|
|
|
|
* @param str Pointer to the string to append.
|
|
|
|
*
|
2006-02-12 04:33:29 +03:00
|
|
|
* @retval OPAL_SUCCESS On success
|
|
|
|
* @retval OPAL_ERROR On failure
|
2004-05-20 16:39:27 +04:00
|
|
|
*
|
|
|
|
* This function adds a string to an argv array of strings by value;
|
|
|
|
* it is permissable to pass a string on the stack as the str
|
|
|
|
* argument to this function.
|
|
|
|
*
|
|
|
|
* To add the first entry to an argv array, call this function with
|
|
|
|
* (*argv == NULL). This function will allocate an array of length
|
|
|
|
* 2; the first entry will point to a copy of the string passed in
|
|
|
|
* arg, the second entry will be set to NULL.
|
|
|
|
*
|
|
|
|
* If (*argv != NULL), it will be realloc'ed to be 1 (char*) larger,
|
|
|
|
* and the next-to-last entry will point to a copy of the string
|
|
|
|
* passed in arg. The last entry will be set to NULL.
|
|
|
|
*
|
|
|
|
* Just to reinforce what was stated above: the string is copied by
|
|
|
|
* value into the argv array; there is no need to keep the original
|
|
|
|
* string (i.e., the arg parameter) after invoking this function.
|
|
|
|
*/
|
2007-03-20 16:01:32 +03:00
|
|
|
OPAL_DECLSPEC int opal_argv_append(int *argc, char ***argv, const char *arg) __opal_attribute_nonnull__(1) __opal_attribute_nonnull__(3);
|
2005-08-04 01:14:40 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Append to an argv-style array, but ignore the size of the array.
|
|
|
|
*
|
|
|
|
* @param argv Pointer to an argv array.
|
|
|
|
* @param str Pointer to the string to append.
|
|
|
|
*
|
2006-02-12 04:33:29 +03:00
|
|
|
* @retval OPAL_SUCCESS On success
|
|
|
|
* @retval OPAL_ERROR On failure
|
2005-08-04 01:14:40 +04:00
|
|
|
*
|
|
|
|
* This function is identical to the opal_argv_append() function
|
|
|
|
* except that it does not take a pointer to an argc (integer
|
|
|
|
* representing the size of the array). This is handy for
|
|
|
|
* argv-style arrays that do not have integers that are actively
|
|
|
|
* maintaing their sizes.
|
|
|
|
*/
|
2006-08-20 19:54:04 +04:00
|
|
|
OPAL_DECLSPEC int opal_argv_append_nosize(char ***argv, const char *arg);
|
2004-05-20 16:39:27 +04:00
|
|
|
|
2010-06-24 19:52:36 +04:00
|
|
|
/**
|
|
|
|
* Insert the provided arg at the beginning of the array
|
|
|
|
*
|
|
|
|
* @param argv Pointer to an argv array
|
|
|
|
* @param str Pointer to the string to prepend
|
|
|
|
*
|
|
|
|
* @retval OPAL_SUCCESS On success
|
|
|
|
* @retval OPAL_ERROR On failure
|
|
|
|
*/
|
|
|
|
OPAL_DECLSPEC int opal_argv_prepend_nosize(char ***argv, const char *arg);
|
|
|
|
|
2009-01-15 21:11:50 +03:00
|
|
|
/**
|
|
|
|
* Append to an argv-style array, but only if the provided argument
|
|
|
|
* doesn't already exist somewhere in the array. Ignore the size of the array.
|
|
|
|
*
|
|
|
|
* @param argv Pointer to an argv array.
|
|
|
|
* @param str Pointer to the string to append.
|
2009-04-14 18:15:49 +04:00
|
|
|
* @param bool Whether or not to overwrite a matching value if found
|
2009-01-15 21:11:50 +03:00
|
|
|
*
|
|
|
|
* @retval OPAL_SUCCESS On success
|
|
|
|
* @retval OPAL_ERROR On failure
|
|
|
|
*
|
|
|
|
* This function is identical to the opal_argv_append_nosize() function
|
|
|
|
* except that it only appends the provided argument if it does not already
|
2009-04-14 18:15:49 +04:00
|
|
|
* exist in the provided array, or overwrites it if it is.
|
2009-01-15 21:11:50 +03:00
|
|
|
*/
|
2009-04-14 18:15:49 +04:00
|
|
|
OPAL_DECLSPEC int opal_argv_append_unique_nosize(char ***argv, const char *arg, bool overwrite);
|
2009-01-15 21:11:50 +03:00
|
|
|
|
|
|
|
/**
|
2004-05-20 16:39:27 +04:00
|
|
|
* Free a NULL-terminated argv array.
|
|
|
|
*
|
|
|
|
* @param argv Argv array to free.
|
|
|
|
*
|
|
|
|
* This function frees an argv array and all of the strings that it
|
|
|
|
* contains. Since the argv parameter is passed by value, it is not
|
|
|
|
* set to NULL in the caller's scope upon return.
|
|
|
|
*
|
|
|
|
* It is safe to invoke this function with a NULL pointer. It is
|
|
|
|
* not safe to invoke this function with a non-NULL-terminated argv
|
|
|
|
* array.
|
|
|
|
*/
|
2006-08-20 19:54:04 +04:00
|
|
|
OPAL_DECLSPEC void opal_argv_free(char **argv);
|
2004-05-20 16:39:27 +04:00
|
|
|
|
|
|
|
/**
|
2007-08-01 16:08:11 +04:00
|
|
|
* Split a string into a NULL-terminated argv array. Do not include empty
|
|
|
|
* strings in result array.
|
2004-05-20 16:39:27 +04:00
|
|
|
*
|
|
|
|
* @param src_string Input string.
|
|
|
|
* @param delimiter Delimiter character.
|
|
|
|
*
|
|
|
|
* @retval argv pointer to new argv array on success
|
|
|
|
* @retval NULL on error
|
|
|
|
*
|
|
|
|
* All strings are insertted into the argv array by value; the
|
|
|
|
* newly-allocated array makes no references to the src_string
|
|
|
|
* argument (i.e., it can be freed after calling this function
|
|
|
|
* without invalidating the output argv).
|
|
|
|
*/
|
2009-05-14 04:20:07 +04:00
|
|
|
OPAL_DECLSPEC char **opal_argv_split(const char *src_string, int delimiter) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__;
|
2004-05-20 16:39:27 +04:00
|
|
|
|
2007-08-01 16:08:11 +04:00
|
|
|
/**
|
|
|
|
* Split a string into a NULL-terminated argv array. Include empty
|
|
|
|
* strings in result array.
|
|
|
|
*
|
|
|
|
* @param src_string Input string.
|
|
|
|
* @param delimiter Delimiter character.
|
|
|
|
*
|
|
|
|
* @retval argv pointer to new argv array on success
|
|
|
|
* @retval NULL on error
|
|
|
|
*
|
|
|
|
* All strings are insertted into the argv array by value; the
|
|
|
|
* newly-allocated array makes no references to the src_string
|
|
|
|
* argument (i.e., it can be freed after calling this function
|
|
|
|
* without invalidating the output argv).
|
|
|
|
*/
|
2009-05-14 04:20:07 +04:00
|
|
|
OPAL_DECLSPEC char **opal_argv_split_with_empty(const char *src_string, int delimiter) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__;
|
2007-08-01 16:08:11 +04:00
|
|
|
|
2004-05-20 16:39:27 +04:00
|
|
|
/**
|
|
|
|
* Return the length of a NULL-terminated argv array.
|
|
|
|
*
|
|
|
|
* @param argv The input argv array.
|
|
|
|
*
|
|
|
|
* @retval 0 If NULL is passed as argv.
|
|
|
|
* @retval count Number of entries in the argv array.
|
|
|
|
*
|
|
|
|
* The argv array must be NULL-terminated.
|
|
|
|
*/
|
2006-08-20 19:54:04 +04:00
|
|
|
OPAL_DECLSPEC int opal_argv_count(char **argv);
|
2004-05-20 16:39:27 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Join all the elements of an argv array into a single
|
|
|
|
* newly-allocated string.
|
|
|
|
*
|
|
|
|
* @param argv The input argv array.
|
|
|
|
* @param delimiter Delimiter character placed between each argv string.
|
|
|
|
*
|
|
|
|
* @retval new_string Output string on success.
|
|
|
|
* @retval NULL On failure.
|
|
|
|
*
|
|
|
|
* Similar to the Perl join function, this function takes an input
|
|
|
|
* argv and joins them into into a single string separated by the
|
|
|
|
* delimiter character.
|
|
|
|
*
|
|
|
|
* It is the callers responsibility to free the returned string.
|
|
|
|
*/
|
2008-07-31 19:46:09 +04:00
|
|
|
OPAL_DECLSPEC char *opal_argv_join(char **argv, int delimiter) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__;
|
2004-05-20 16:39:27 +04:00
|
|
|
|
2009-05-14 04:20:07 +04:00
|
|
|
OPAL_DECLSPEC char *opal_argv_join_range(char **argv, size_t start, size_t end, int delimiter) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__;
|
Per the July technical meeting:
Standardize the handling of the orte launch agent option across PLMs. This has been a consistent complaint I have received - each PLM would register its own MCA param to get input on the launch agent for remote nodes (in fact, one or two didn't, but most did). This would then get handled in various and contradictory ways.
Some PLMs would accept only a one-word input. Others accepted multi-word args such as "valgrind orted", but then some would error by putting any prefix specified on the cmd line in front of the incorrect argument.
For example, while using the rsh launcher, if you specified "valgrind orted" as your launch agent and had "--prefix foo" on you cmd line, you would attempt to execute "ssh foo/valgrind orted" - which obviously wouldn't work.
This was all -very- confusing to users, who had to know which PLM was being used so they could even set the right mca param in the first place! And since we don't warn about non-recognized or non-used mca params, half of the time they would wind up not doing what they thought they were telling us to do.
To solve this problem, we did the following:
1. removed all mca params from the individual plms for the launch agent
2. added a new mca param "orte_launch_agent" for this purpose. To further simplify for users, this comes with a new cmd line option "--launch-agent" that can take a multi-word string argument. The value of the param defaults to "orted".
3. added a PLM base function that processes the orte_launch_agent value and adds the contents to a provided argv array. This can subsequently be harvested at-will to handle multi-word values
4. modified the PLMs to use this new function. All the PLMs except for the rsh PLM required very minor change - just called the function and moved on. The rsh PLM required much larger changes as - because of the rsh/ssh cmd line limitations - we had to correctly prepend any provided prefix to the correct argv entry.
5. added a new opal_argv_join_range function that allows the caller to "join" argv entries between two specified indices
Please let me know of any problems. I tried to make this as clean as possible, but cannot compile all PLMs to ensure all is correct.
This commit was SVN r19097.
2008-07-30 22:26:24 +04:00
|
|
|
|
2004-05-20 16:39:27 +04:00
|
|
|
/**
|
|
|
|
* Return the number of bytes consumed by an argv array.
|
|
|
|
*
|
|
|
|
* @param argv The input argv array.
|
|
|
|
*
|
|
|
|
* Count the number of bytes consumed by a NULL-terminated argv
|
|
|
|
* array. This includes the number of bytes used by each of the
|
|
|
|
* strings as well as the pointers used in the argv array.
|
|
|
|
*/
|
2006-08-20 19:54:04 +04:00
|
|
|
OPAL_DECLSPEC size_t opal_argv_len(char **argv);
|
2004-05-20 16:39:27 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy a NULL-terminated argv array.
|
|
|
|
*
|
|
|
|
* @param argv The input argv array.
|
|
|
|
*
|
|
|
|
* @retval argv Copied argv array on success.
|
|
|
|
* @retval NULL On failure.
|
|
|
|
*
|
|
|
|
* Copy an argv array, including copying all off its strings.
|
|
|
|
* Specifically, the output argv will be an array of the same length
|
|
|
|
* as the input argv, and strcmp(argv_in[i], argv_out[i]) will be 0.
|
|
|
|
*/
|
2008-07-31 19:46:09 +04:00
|
|
|
OPAL_DECLSPEC char **opal_argv_copy(char **argv) __opal_attribute_malloc__ __opal_attribute_warn_unused_result__;
|
2004-10-01 22:38:16 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Delete one or more tokens from the middle of an argv.
|
|
|
|
*
|
|
|
|
* @param argv The argv to delete from
|
|
|
|
* @param start The index of the first token to delete
|
|
|
|
* @param num_to_delete How many tokens to delete
|
|
|
|
*
|
2006-02-12 04:33:29 +03:00
|
|
|
* @retval OPAL_SUCCESS Always
|
2004-10-01 22:38:16 +04:00
|
|
|
*
|
|
|
|
* Delete some tokens from within an existing argv. The start
|
|
|
|
* parameter specifies the first token to delete, and will delete
|
2004-12-07 05:42:17 +03:00
|
|
|
* (num_to_delete-1) tokens following it. argv will be realloc()ed
|
|
|
|
* to *argc - num_deleted size.
|
2004-10-01 22:38:16 +04:00
|
|
|
*
|
|
|
|
* If start is beyond the end of the argv array, this function is
|
|
|
|
* a no-op.
|
|
|
|
*
|
|
|
|
* If num_to_delete runs beyond the end of the argv array, this
|
|
|
|
* function will delete all tokens starting with start to the end
|
|
|
|
* of the array.
|
|
|
|
*
|
|
|
|
* All deleted items in the argv array will have their contents
|
|
|
|
* free()ed (it is assumed that the argv "owns" the memory that
|
|
|
|
* the pointer points to).
|
|
|
|
*/
|
2006-08-20 19:54:04 +04:00
|
|
|
OPAL_DECLSPEC int opal_argv_delete(int *argc, char ***argv,
|
2004-12-07 05:42:17 +03:00
|
|
|
int start, int num_to_delete);
|
2004-10-01 22:38:16 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Insert one argv array into the middle of another
|
|
|
|
*
|
|
|
|
* @param target The argv to insert tokens into
|
|
|
|
* @param start Index where the first token will be placed in target
|
|
|
|
* @param source The argv to copy tokens from
|
|
|
|
*
|
2006-02-12 04:33:29 +03:00
|
|
|
* @retval OPAL_SUCCESS upon success
|
2007-03-29 05:00:33 +04:00
|
|
|
* @retval OPAL_BAD_PARAM if any parameters are non-sensical
|
2004-10-01 22:38:16 +04:00
|
|
|
*
|
|
|
|
* This function takes one arg and inserts it in the middle of
|
|
|
|
* another. The first token in source will be insertted at index
|
|
|
|
* start in the target argv; all other tokens will follow it.
|
2005-07-04 04:13:44 +04:00
|
|
|
* Similar to opal_argv_append(), the target may be realloc()'ed
|
2004-10-01 22:38:16 +04:00
|
|
|
* to accomodate the new storage requirements.
|
|
|
|
*
|
|
|
|
* The source array is left unaffected -- its contents are copied
|
|
|
|
* by value over to the target array (i.e., the strings that
|
|
|
|
* source points to are strdup'ed into the new locations in
|
|
|
|
* target).
|
|
|
|
*/
|
2006-08-20 19:54:04 +04:00
|
|
|
OPAL_DECLSPEC int opal_argv_insert(char ***target, int start, char **source);
|
Per the July technical meeting:
Standardize the handling of the orte launch agent option across PLMs. This has been a consistent complaint I have received - each PLM would register its own MCA param to get input on the launch agent for remote nodes (in fact, one or two didn't, but most did). This would then get handled in various and contradictory ways.
Some PLMs would accept only a one-word input. Others accepted multi-word args such as "valgrind orted", but then some would error by putting any prefix specified on the cmd line in front of the incorrect argument.
For example, while using the rsh launcher, if you specified "valgrind orted" as your launch agent and had "--prefix foo" on you cmd line, you would attempt to execute "ssh foo/valgrind orted" - which obviously wouldn't work.
This was all -very- confusing to users, who had to know which PLM was being used so they could even set the right mca param in the first place! And since we don't warn about non-recognized or non-used mca params, half of the time they would wind up not doing what they thought they were telling us to do.
To solve this problem, we did the following:
1. removed all mca params from the individual plms for the launch agent
2. added a new mca param "orte_launch_agent" for this purpose. To further simplify for users, this comes with a new cmd line option "--launch-agent" that can take a multi-word string argument. The value of the param defaults to "orted".
3. added a PLM base function that processes the orte_launch_agent value and adds the contents to a provided argv array. This can subsequently be harvested at-will to handle multi-word values
4. modified the PLMs to use this new function. All the PLMs except for the rsh PLM required very minor change - just called the function and moved on. The rsh PLM required much larger changes as - because of the rsh/ssh cmd line limitations - we had to correctly prepend any provided prefix to the correct argv entry.
5. added a new opal_argv_join_range function that allows the caller to "join" argv entries between two specified indices
Please let me know of any problems. I tried to make this as clean as possible, but cannot compile all PLMs to ensure all is correct.
This commit was SVN r19097.
2008-07-30 22:26:24 +04:00
|
|
|
|
|
|
|
END_C_DECLS
|
2004-01-07 11:35:06 +03:00
|
|
|
|
2005-07-04 04:13:44 +04:00
|
|
|
#endif /* OPAL_ARGV_H */
|