libosmocore 1.10.0.58-6cd7a
Osmocom core library
|
#include "config.h"
#include <unistd.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <dirent.h>
#include <sys/types.h>
#include <pwd.h>
#include <osmocom/core/logging.h>
#include <osmocom/core/utils.h>
#include <osmocom/core/exec.h>
Macros | |
#define | _GNU_SOURCE |
Functions | |
static bool | str_in_list (const char **list, const char *key) |
int | osmo_environment_filter (char **out, size_t out_len, char **in, const char **whitelist) |
filtered a process environment by whitelist; only copying pointers, no actual strings. More... | |
int | osmo_environment_append (char **out, size_t out_len, char **in) |
append one environment to another; only copying pointers, not actual strings. More... | |
int | osmo_close_all_fds_above (int last_fd_to_keep) |
int | osmo_system_nowait2 (const char *command, const char **env_whitelist, char **addl_env, const char *user) |
call an external shell command as 'user' without waiting for it. More... | |
int | osmo_system_nowait (const char *command, const char **env_whitelist, char **addl_env) |
call an external shell command without waiting for it. More... | |
Variables | |
const char * | osmo_environment_whitelist [] |
suggested list of environment variables to pass (if they exist) to a sub-process/script More... | |
char ** | environ |
#define _GNU_SOURCE |
int osmo_close_all_fds_above | ( | int | last_fd_to_keep | ) |
References DLGLOBAL, LOGL_ERROR, and LOGP.
Referenced by osmo_system_nowait2().
int osmo_environment_append | ( | char ** | out, |
size_t | out_len, | ||
char ** | in | ||
) |
append one environment to another; only copying pointers, not actual strings.
This function is useful if you'd like to append soem entries to an environment befoer passing it to exec*e() functions.
It will append all entries from 'in' to the environment in 'out', as long as 'out' has space (determined by 'out_len').
Constraints: If the same key exists in 'out' and 'in', duplicate keys are generated. It is a simple append, without any duplicate checks.
[out] | out | caller-allocated array of pointers for the generated output |
[in] | out_len | size of out (number of pointers) |
[in] | in | input environment (NULL-terminated list of pointers like **environ) |
References OSMO_ASSERT.
Referenced by osmo_system_nowait2().
int osmo_environment_filter | ( | char ** | out, |
size_t | out_len, | ||
char ** | in, | ||
const char ** | whitelist | ||
) |
filtered a process environment by whitelist; only copying pointers, no actual strings.
This function is useful if you'd like to generate an environment to pass exec*e() functions. It will create a new environment containing only those entries whose keys (as per environment convention KEY=VALUE) are contained in the whitelist. The function will not copy the actual strings, but just create a new pointer array, pointing to the same memory as the input strings.
Constraints: Keys up to a maximum length of 255 characters are supported.
[out] | out | caller-allocated array of pointers for the generated output |
[in] | out_len | size of out (number of pointers) |
[in] | in | input environment (NULL-terminated list of pointers like **environ) |
[in] | whitelist | whitelist of permitted keys in environment (like **environ) |
References ARRAY_SIZE, OSMO_ASSERT, and str_in_list().
Referenced by osmo_system_nowait2().
int osmo_system_nowait | ( | const char * | command, |
const char ** | env_whitelist, | ||
char ** | addl_env | ||
) |
call an external shell command without waiting for it.
This mimics the behavior of system(3), with the following differences:
[in] | command | the shell command to be executed, see system(3) |
[in] | env_whitelist | A white-list of keys for environment variables |
[in] | addl_env | any additional environment variables to be appended |
References osmo_system_nowait2().
int osmo_system_nowait2 | ( | const char * | command, |
const char ** | env_whitelist, | ||
char ** | addl_env, | ||
const char * | user | ||
) |
call an external shell command as 'user' without waiting for it.
This mimics the behavior of system(3), with the following differences:
[in] | command | the shell command to be executed, see system(3) |
[in] | env_whitelist | A white-list of keys for environment variables |
[in] | addl_env | any additional environment variables to be appended |
[in] | user | name of the user to which we should switch before executing the command |
References ARRAY_SIZE, DLGLOBAL, environ, LOGL_ERROR, LOGP, osmo_close_all_fds_above(), osmo_environment_append(), and osmo_environment_filter().
Referenced by osmo_system_nowait().
|
static |
References list.
Referenced by osmo_environment_filter().
|
extern |
Referenced by osmo_system_nowait2().
const char* osmo_environment_whitelist[] |
suggested list of environment variables to pass (if they exist) to a sub-process/script