diff options
Diffstat (limited to 'tools/perf/util/run-command.c')
| -rw-r--r-- | tools/perf/util/run-command.c | 90 |
1 files changed, 0 insertions, 90 deletions
diff --git a/tools/perf/util/run-command.c b/tools/perf/util/run-command.c index 2b615acf94d7..da8e9b285f51 100644 --- a/tools/perf/util/run-command.c +++ b/tools/perf/util/run-command.c | |||
| @@ -212,93 +212,3 @@ int run_command_v_opt(const char **argv, int opt) | |||
| 212 | prepare_run_command_v_opt(&cmd, argv, opt); | 212 | prepare_run_command_v_opt(&cmd, argv, opt); |
| 213 | return run_command(&cmd); | 213 | return run_command(&cmd); |
| 214 | } | 214 | } |
| 215 | |||
| 216 | int run_command_v_opt_cd_env(const char **argv, int opt, const char *dir, const char *const *env) | ||
| 217 | { | ||
| 218 | struct child_process cmd; | ||
| 219 | prepare_run_command_v_opt(&cmd, argv, opt); | ||
| 220 | cmd.dir = dir; | ||
| 221 | cmd.env = env; | ||
| 222 | return run_command(&cmd); | ||
| 223 | } | ||
| 224 | |||
| 225 | int start_async(struct async *async) | ||
| 226 | { | ||
| 227 | int pipe_out[2]; | ||
| 228 | |||
| 229 | if (pipe(pipe_out) < 0) | ||
| 230 | return error("cannot create pipe: %s", strerror(errno)); | ||
| 231 | async->out = pipe_out[0]; | ||
| 232 | |||
| 233 | /* Flush stdio before fork() to avoid cloning buffers */ | ||
| 234 | fflush(NULL); | ||
| 235 | |||
| 236 | async->pid = fork(); | ||
| 237 | if (async->pid < 0) { | ||
| 238 | error("fork (async) failed: %s", strerror(errno)); | ||
| 239 | close_pair(pipe_out); | ||
| 240 | return -1; | ||
| 241 | } | ||
| 242 | if (!async->pid) { | ||
| 243 | close(pipe_out[0]); | ||
| 244 | exit(!!async->proc(pipe_out[1], async->data)); | ||
| 245 | } | ||
| 246 | close(pipe_out[1]); | ||
| 247 | |||
| 248 | return 0; | ||
| 249 | } | ||
| 250 | |||
| 251 | int finish_async(struct async *async) | ||
| 252 | { | ||
| 253 | int ret = 0; | ||
| 254 | |||
| 255 | if (wait_or_whine(async->pid)) | ||
| 256 | ret = error("waitpid (async) failed"); | ||
| 257 | |||
| 258 | return ret; | ||
| 259 | } | ||
| 260 | |||
| 261 | int run_hook(const char *index_file, const char *name, ...) | ||
| 262 | { | ||
| 263 | struct child_process hook; | ||
| 264 | const char **argv = NULL, *env[2]; | ||
| 265 | char idx[PATH_MAX]; | ||
| 266 | va_list args; | ||
| 267 | int ret; | ||
| 268 | size_t i = 0, alloc = 0; | ||
| 269 | |||
| 270 | if (access(perf_path("hooks/%s", name), X_OK) < 0) | ||
| 271 | return 0; | ||
| 272 | |||
| 273 | va_start(args, name); | ||
| 274 | ALLOC_GROW(argv, i + 1, alloc); | ||
| 275 | argv[i++] = perf_path("hooks/%s", name); | ||
| 276 | while (argv[i-1]) { | ||
| 277 | ALLOC_GROW(argv, i + 1, alloc); | ||
| 278 | argv[i++] = va_arg(args, const char *); | ||
| 279 | } | ||
| 280 | va_end(args); | ||
| 281 | |||
| 282 | memset(&hook, 0, sizeof(hook)); | ||
| 283 | hook.argv = argv; | ||
| 284 | hook.no_stdin = 1; | ||
| 285 | hook.stdout_to_stderr = 1; | ||
| 286 | if (index_file) { | ||
| 287 | snprintf(idx, sizeof(idx), "PERF_INDEX_FILE=%s", index_file); | ||
| 288 | env[0] = idx; | ||
| 289 | env[1] = NULL; | ||
| 290 | hook.env = env; | ||
| 291 | } | ||
| 292 | |||
| 293 | ret = start_command(&hook); | ||
| 294 | free(argv); | ||
| 295 | if (ret) { | ||
| 296 | warning("Could not spawn %s", argv[0]); | ||
| 297 | return ret; | ||
| 298 | } | ||
| 299 | ret = finish_command(&hook); | ||
| 300 | if (ret == -ERR_RUN_COMMAND_WAITPID_SIGNAL) | ||
| 301 | warning("%s exited due to uncaught signal", argv[0]); | ||
| 302 | |||
| 303 | return ret; | ||
| 304 | } | ||
