Execute a program in a child process

Overview

Routines to execute a program in a child process

Copyright (C) 2019-2022 OKTET Labs Ltd. More…

// typedefs

typedef enum te_sched_param_type te_sched_param_type;
typedef struct te_sched_param te_sched_param;
typedef struct te_sched_affinity_param te_sched_affinity_param;
typedef struct te_sched_priority_param te_sched_priority_param;

// enums

enum te_sched_param_type;

// structs

struct te_sched_affinity_param;
struct te_sched_param;
struct te_sched_priority_param;

// global functions

pid_t te_exec_child(const char* file, char*const argv[], char*const envp[], uid_t uid, int* in_fd, int* out_fd, int* err_fd, const te_sched_param* sched_param);

// macros

#define TE_EXEC_CHILD_DEV_NULL_FD

Detailed Documentation

Routines to execute a program in a child process

Copyright (C) 2019-2022 OKTET Labs Ltd. All rights reserved.

Typedefs

typedef enum te_sched_param_type te_sched_param_type

Type of scheduling

typedef struct te_sched_param te_sched_param

This structure describes type of scheduling

typedef struct te_sched_affinity_param te_sched_affinity_param

Data specific for CPU affinity type (TE_SCHED_AFFINITY)

typedef struct te_sched_priority_param te_sched_priority_param

Data specific for priority type (TE_SCHED_PRIORITY)

Global Functions

pid_t te_exec_child(const char* file, char*const argv[], char*const envp[], uid_t uid, int* in_fd, int* out_fd, int* err_fd, const te_sched_param* sched_param)

Function to base system()-like and popen()-like functions on it. You MUST use uid parameter instead of “su - user -c”, because su makes one more fork, and you do not know how to kill this grandchild process.

The function: 1) creates pipes (if necessary) to communicate with a child process; 2) fork()’s the child process; 3) modifies standard file descriptors of the child process according to in_fd out_fd err_fd; 4) executes specified program in the child process;

if a file descriptor location is NULL, copy of the respective standard file descriptor will be inherited by the child; if a file descriptor location is TE_EXEC_CHILD_DEV_NULL_FD, the respective standard file descriptor of the child will be redirected to /dev/null

If you use this fuction from agent, this process SHOULD be catched by ta_waitpid() or killed by ta_kill_death().

Parameters:

file

file to execute

argv

command line arguments terminated by NULL; MUST NOT be NULL

envp

environment variables terminated by NULL; use NULL to keep the current environment

uid

user id to execute the file; use -1 for default

in_fd

location to store file descriptor of pipe to stdin of the process; see note

out_fd

location to store file descriptor of pipe to stdout of the process; see note

out_fd

location to store file descriptor of pipe to stderr of the process; see note

sched_param

Array of scheduling parameters. The last element must have the type TE_SCHED_END and data pointer to NULL. May be NULL.

Returns:

pid value, positive on success, negative on failure