1099e92f5ee1881c1519211a0ff3d98c39585c3c
9 static const char *argv_exec_path
;
10 static const char *argv0_path
;
12 char *system_path(const char *path
)
14 static const char *prefix
= PREFIX
;
15 struct strbuf d
= STRBUF_INIT
;
17 if (is_absolute_path(path
))
20 strbuf_addf(&d
, "%s/%s", prefix
, path
);
21 path
= strbuf_detach(&d
, NULL
);
25 const char *perf_extract_argv0_path(const char *argv0
)
29 if (!argv0
|| !*argv0
)
31 slash
= argv0
+ strlen(argv0
);
33 while (argv0
<= slash
&& !is_dir_sep(*slash
))
37 argv0_path
= strndup(argv0
, slash
- argv0
);
38 return argv0_path
? slash
+ 1 : NULL
;
44 void perf_set_argv_exec_path(const char *exec_path
)
46 argv_exec_path
= exec_path
;
48 * Propagate this setting to external programs.
50 setenv(EXEC_PATH_ENVIRONMENT
, exec_path
, 1);
54 /* Returns the highest-priority, location to look for perf programs. */
55 char *perf_exec_path(void)
60 return strdup(argv_exec_path
);
62 env
= getenv(EXEC_PATH_ENVIRONMENT
);
66 return system_path(PERF_EXEC_PATH
);
69 static void add_path(struct strbuf
*out
, const char *path
)
72 if (is_absolute_path(path
))
73 strbuf_addstr(out
, path
);
75 strbuf_addstr(out
, make_nonrelative_path(path
));
77 strbuf_addch(out
, PATH_SEP
);
83 const char *old_path
= getenv("PATH");
84 struct strbuf new_path
= STRBUF_INIT
;
85 char *tmp
= perf_exec_path();
87 add_path(&new_path
, tmp
);
88 add_path(&new_path
, argv0_path
);
92 strbuf_addstr(&new_path
, old_path
);
94 strbuf_addstr(&new_path
, "/usr/local/bin:/usr/bin:/bin");
96 setenv("PATH", new_path
.buf
, 1);
98 strbuf_release(&new_path
);
101 static const char **prepare_perf_cmd(const char **argv
)
106 for (argc
= 0; argv
[argc
]; argc
++)
107 ; /* just counting */
108 nargv
= malloc(sizeof(*nargv
) * (argc
+ 2));
111 for (argc
= 0; argv
[argc
]; argc
++)
112 nargv
[argc
+ 1] = argv
[argc
];
113 nargv
[argc
+ 1] = NULL
;
117 int execv_perf_cmd(const char **argv
) {
118 const char **nargv
= prepare_perf_cmd(argv
);
120 /* execvp() can only ever return if it fails */
121 execvp("perf", (char **)nargv
);
128 int execl_perf_cmd(const char *cmd
,...)
131 const char *argv
[MAX_ARGS
+ 1];
135 va_start(param
, cmd
);
138 while (argc
< MAX_ARGS
) {
139 arg
= argv
[argc
++] = va_arg(param
, char *);
144 if (MAX_ARGS
<= argc
)
145 return error("too many args to run %s", cmd
);
148 return execv_perf_cmd(argv
);
This page took 0.033244 seconds and 4 git commands to generate.