MCPcopy Index your code
hub / github.com/F-Stack/f-stack / process_dup

Function process_dup

dpdk/app/test/process.h:72–200  ·  view source on GitHub ↗

* launches a second copy of the test process using the given argv parameters, * which should include argv[0] as the process name. To identify in the * subprocess the source of the call, the env_value parameter is set in the * environment as $RTE_TEST */

Source from the content-addressed store, hash-verified

70 * environment as $RTE_TEST
71 */
72static inline int
73process_dup(const char *const argv[], int numargs, const char *env_value)
74{
75 int num = 0;
76 char **argv_cpy;
77 int allow_num;
78 int argv_num;
79 int i, status;
80 char path[32];
81#ifdef RTE_LIB_PDUMP
82#ifdef RTE_NET_RING
83 rte_thread_t thread;
84 int rc;
85#endif
86#endif
87
88 pid_t pid = fork();
89 if (pid < 0)
90 return -1;
91 else if (pid == 0) {
92 allow_num = rte_devargs_type_count(RTE_DEVTYPE_ALLOWED);
93 argv_num = numargs + allow_num + 1;
94 argv_cpy = calloc(argv_num, sizeof(char *));
95 if (!argv_cpy)
96 rte_panic("Memory allocation failed\n");
97
98 /* make a copy of the arguments to be passed to exec */
99 for (i = 0; i < numargs; i++) {
100 argv_cpy[i] = strdup(argv[i]);
101 if (argv_cpy[i] == NULL)
102 rte_panic("Error dup args\n");
103 }
104 if (allow_num > 0)
105 num = add_parameter_allow(&argv_cpy[i], allow_num);
106 num += numargs;
107
108#ifdef RTE_EXEC_ENV_LINUX
109 {
110 const char *procdir = "/proc/" self "/fd/";
111 struct dirent *dirent;
112 char *endptr;
113 int fd, fdir;
114 DIR *dir;
115
116 /* close all open file descriptors, check /proc/self/fd
117 * to only call close on open fds. Exclude fds 0, 1 and
118 * 2
119 */
120 dir = opendir(procdir);
121 if (dir == NULL) {
122 rte_panic("Error opening %s: %s\n", procdir,
123 strerror(errno));
124 }
125
126 fdir = dirfd(dir);
127 if (fdir < 0) {
128 status = errno;
129 closedir(dir);

Callers

nothing calls this directly

Calls 14

rte_devargs_type_countFunction · 0.85
callocFunction · 0.85
strdupFunction · 0.85
add_parameter_allowFunction · 0.85
opendirFunction · 0.85
closedirFunction · 0.85
readdirFunction · 0.85
strcmpFunction · 0.85
strtolFunction · 0.85
printfFunction · 0.50
closeFunction · 0.50
strlcpyFunction · 0.50

Tested by

no test coverage detected