mirror of
https://github.com/apache/nuttx.git
synced 2026-06-06 16:50:55 +08:00
binfmt/ and libs/libc: Make exepath_*() more common:
1. Move exepath_*() related code to libc/misc 1. Rename exepath_ to envpath_ 2. Rename BINFMT_EXEPATH to LIB_ENVPATH libs/libc/modlib: Add pre module library symbol table support
This commit is contained in:
@@ -58,14 +58,6 @@
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* EXEPATH_HANDLE is an opaque handle used to traverse the absolute paths
|
||||
* assigned to the PATH environment variable.
|
||||
*/
|
||||
|
||||
#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
|
||||
typedef FAR void *EXEPATH_HANDLE;
|
||||
#endif
|
||||
|
||||
/* The type of one C++ constructor or destructor */
|
||||
|
||||
typedef FAR void (*binfmt_ctor_t)(void);
|
||||
@@ -74,7 +66,7 @@ typedef FAR void (*binfmt_dtor_t)(void);
|
||||
/* This describes the file to be loaded.
|
||||
*
|
||||
* NOTE 1: The 'filename' must be the full, absolute path to the file to be
|
||||
* executed unless CONFIG_BINFMT_EXEPATH is defined. In that case,
|
||||
* executed unless CONFIG_LIB_ENVPATH is defined. In that case,
|
||||
* 'filename' may be a relative path; a set of candidate absolute paths
|
||||
* will be generated using the PATH environment variable and load_module()
|
||||
* will attempt to load each file that is found at those absolute paths.
|
||||
@@ -300,7 +292,7 @@ int exec_module(FAR const struct binary_s *bin);
|
||||
*
|
||||
* Input Parameters:
|
||||
* filename - The path to the program to be executed. If
|
||||
* CONFIG_BINFMT_EXEPATH is defined in the configuration, then
|
||||
* CONFIG_LIB_ENVPATH is defined in the configuration, then
|
||||
* this may be a relative path from the current working
|
||||
* directory. Otherwise, path must be the absolute path to the
|
||||
* program.
|
||||
@@ -345,89 +337,6 @@ int exec(FAR const char *filename, FAR char * const *argv,
|
||||
int binfmt_exit(FAR struct binary_s *bin);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exepath_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize for the traversal of each value in the PATH variable. The
|
||||
* usage is sequence is as follows:
|
||||
*
|
||||
* 1) Call exepath_init() to initialize for the traversal. exepath_init()
|
||||
* will return an opaque handle that can then be provided to
|
||||
* exepath_next() and exepath_release().
|
||||
* 2) Call exepath_next() repeatedly to examine every file that lies
|
||||
* in the directories of the PATH variable
|
||||
* 3) Call exepath_release() to free resources set aside by exepath_init().
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, exepath_init() return a non-NULL, opaque handle that may
|
||||
* subsequently be used in calls to exepath_next() and exepath_release().
|
||||
* On error, a NULL handle value will be returned. The most likely cause
|
||||
* of an error would be that there is no value associated with the PATH
|
||||
* variable.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
|
||||
EXEPATH_HANDLE exepath_init(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exepath_next
|
||||
*
|
||||
* Description:
|
||||
* Traverse all possible values in the PATH variable in attempt to find
|
||||
* the full path to an executable file when only a relative path is
|
||||
* provided.
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The handle value returned by exepath_init
|
||||
* relpath - The relative path to the file to be found.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, a non-NULL pointer to a null-terminated string is provided.
|
||||
* This is the full path to a file that exists in the file system. This
|
||||
* function will verify that the file exists (but will not verify that it
|
||||
* is marked executable).
|
||||
*
|
||||
* NOTE: The string pointer return in the success case points to allocated
|
||||
* memory. This memory must be freed by the called by calling kmm_free().
|
||||
*
|
||||
* NULL is returned if no path is found to any file with the provided
|
||||
* 'relpath' from any absolute path in the PATH variable. In this case,
|
||||
* there is no point in calling exepath_next() further; exepath_release()
|
||||
* must be called to release resources set aside by expath_init().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
|
||||
FAR char *exepath_next(EXEPATH_HANDLE handle, FAR const char *relpath);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: exepath_release
|
||||
*
|
||||
* Description:
|
||||
* Release all resources set aside by exepath_init() when the handle value
|
||||
* was created. The handle value is invalid on return from this function.
|
||||
* Attempts to all exepath_next() or exepath_release() with such a 'stale'
|
||||
* handle will result in undefined (i.e., not good) behavior.
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The handle value returned by exepath_init
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#if !defined(CONFIG_BINFMT_DISABLE) && defined(CONFIG_BINFMT_EXEPATH)
|
||||
void exepath_release(EXEPATH_HANDLE handle);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#if defined(__cplusplus)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,159 @@
|
||||
/****************************************************************************
|
||||
* include/nuttx/envpath.h
|
||||
*
|
||||
* Copyright (C) 2018 Gregory Nutt. All rights reserved.
|
||||
* Author: Gregory Nutt <gnutt@nuttx.org>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
* the documentation and/or other materials provided with the
|
||||
* distribution.
|
||||
* 3. Neither the name NuttX nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
||||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
||||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
||||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
||||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
||||
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __INCLUDE_NUTTX_ENVPATH_H
|
||||
#define __INCLUDE_NUTTX_ENVPATH_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#ifdef CONFIG_LIB_ENVPATH
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* ENVPATH_HANDLE is an opaque handle used to traverse the absolute paths
|
||||
* assigned to the PATH environment variable.
|
||||
*/
|
||||
|
||||
typedef FAR void *ENVPATH_HANDLE;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: envpath_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize for the traversal of each value in the PATH variable. The
|
||||
* usage is sequence is as follows:
|
||||
*
|
||||
* Input Parameters:
|
||||
* name - The variable name of environment to searches path list.
|
||||
*
|
||||
* 1) Call envpath_init() to initialize for the traversal. envpath_init()
|
||||
* will return an opaque handle that can then be provided to
|
||||
* envpath_next() and envpath_release().
|
||||
* 2) Call envpath_next() repeatedly to examine every file that lies
|
||||
* in the directories of the PATH variable
|
||||
* 3) Call envpath_release() to free resources set aside by envpath_init().
|
||||
*
|
||||
* Input Parameters:
|
||||
* None
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, envpath_init() return a non-NULL, opaque handle that may
|
||||
* subsequently be used in calls to envpath_next() and envpath_release().
|
||||
* On error, a NULL handle value will be returned. The most likely cause
|
||||
* of an error would be that there is no value associated with the PATH
|
||||
* variable.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
ENVPATH_HANDLE envpath_init(FAR const char *name);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: envpath_next
|
||||
*
|
||||
* Description:
|
||||
* Traverse all possible values in the PATH variable in attempt to find
|
||||
* the full path to an executable file when only a relative path is
|
||||
* provided.
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The handle value returned by envpath_init
|
||||
* relpath - The relative path to the file to be found.
|
||||
*
|
||||
* Returned Value:
|
||||
* On success, a non-NULL pointer to a null-terminated string is provided.
|
||||
* This is the full path to a file that exists in the file system. This
|
||||
* function will verify that the file exists (but will not verify that it
|
||||
* is marked executable).
|
||||
*
|
||||
* NOTE: The string pointer return in the success case points to allocated
|
||||
* memory. This memory must be freed by the called by calling kmm_free().
|
||||
*
|
||||
* NULL is returned if no path is found to any file with the provided
|
||||
* 'relpath' from any absolute path in the PATH variable. In this case,
|
||||
* there is no point in calling envpath_next() further; envpath_release()
|
||||
* must be called to release resources set aside by expath_init().
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
FAR char *envpath_next(ENVPATH_HANDLE handle, FAR const char *relpath);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: envpath_release
|
||||
*
|
||||
* Description:
|
||||
* Release all resources set aside by envpath_init() when the handle value
|
||||
* was created. The handle value is invalid on return from this function.
|
||||
* Attempts to all envpath_next() or envpath_release() with such a 'stale'
|
||||
* handle will result in undefined (i.e., not good) behavior.
|
||||
*
|
||||
* Input Parameters:
|
||||
* handle - The handle value returned by envpath_init
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
void envpath_release(ENVPATH_HANDLE handle);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* CONFIG_LIB_ENVPATH */
|
||||
#endif /* INCLUDE_NUTTX_ENVPATH_H */
|
||||
@@ -222,8 +222,6 @@ struct mod_loadinfo_s
|
||||
****************************************************************************/
|
||||
|
||||
struct symtab_s;
|
||||
FAR const struct symtab_s *g_modlib_symtab;
|
||||
FAR int g_modlib_nsymbols;
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
|
||||
+1
-1
@@ -137,7 +137,7 @@ extern "C"
|
||||
* file system at 'path'
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_BINFMT_EXEPATH
|
||||
#ifdef CONFIG_LIB_ENVPATH
|
||||
int posix_spawnp(FAR pid_t *pid, FAR const char *path,
|
||||
FAR const posix_spawn_file_actions_t *file_actions,
|
||||
FAR const posix_spawnattr_t *attr,
|
||||
|
||||
@@ -200,7 +200,7 @@
|
||||
# define __SYS_posix_spawn __SYS_exec
|
||||
# endif
|
||||
# ifdef CONFIG_LIBC_EXECFUNCS
|
||||
# ifdef CONFIG_BINFMT_EXEPATH
|
||||
# ifdef CONFIG_LIB_ENVPATH
|
||||
# define SYS_posix_spawnp __SYS_posix_spawn
|
||||
# else
|
||||
# define SYS_posix_spawn __SYS_posix_spawn
|
||||
|
||||
Reference in New Issue
Block a user