diff options
author | Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com> | 2014-08-13 22:22:36 -0400 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2014-08-15 09:58:35 -0400 |
commit | 6e81c74cbf4b64620170da14844f1dc8a9a5950f (patch) | |
tree | ce4d4d23f34959965a4cae5e48355de1b40f4063 /tools/perf/util/run-command.c | |
parent | 5f03cba41590b5e7db5b66d2b2aa3e146ff8a84f (diff) |
perf util: Replace strerror with strerror_r for thread-safety
Replaces all strerror with strerror_r in util for making the perf lib
thread-safe.
Signed-off-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Naohiro Aota <naota@elisp.net>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
Link: http://lkml.kernel.org/r/20140814022236.3545.3367.stgit@kbuild-fedora.novalocal
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util/run-command.c')
-rw-r--r-- | tools/perf/util/run-command.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/tools/perf/util/run-command.c b/tools/perf/util/run-command.c index da8e9b285f51..34622b53e733 100644 --- a/tools/perf/util/run-command.c +++ b/tools/perf/util/run-command.c | |||
@@ -1,6 +1,7 @@ | |||
1 | #include "cache.h" | 1 | #include "cache.h" |
2 | #include "run-command.h" | 2 | #include "run-command.h" |
3 | #include "exec_cmd.h" | 3 | #include "exec_cmd.h" |
4 | #include "debug.h" | ||
4 | 5 | ||
5 | static inline void close_pair(int fd[2]) | 6 | static inline void close_pair(int fd[2]) |
6 | { | 7 | { |
@@ -19,6 +20,7 @@ int start_command(struct child_process *cmd) | |||
19 | { | 20 | { |
20 | int need_in, need_out, need_err; | 21 | int need_in, need_out, need_err; |
21 | int fdin[2], fdout[2], fderr[2]; | 22 | int fdin[2], fdout[2], fderr[2]; |
23 | char sbuf[STRERR_BUFSIZE]; | ||
22 | 24 | ||
23 | /* | 25 | /* |
24 | * In case of errors we must keep the promise to close FDs | 26 | * In case of errors we must keep the promise to close FDs |
@@ -99,7 +101,7 @@ int start_command(struct child_process *cmd) | |||
99 | 101 | ||
100 | if (cmd->dir && chdir(cmd->dir)) | 102 | if (cmd->dir && chdir(cmd->dir)) |
101 | die("exec %s: cd to %s failed (%s)", cmd->argv[0], | 103 | die("exec %s: cd to %s failed (%s)", cmd->argv[0], |
102 | cmd->dir, strerror(errno)); | 104 | cmd->dir, strerror_r(errno, sbuf, sizeof(sbuf))); |
103 | if (cmd->env) { | 105 | if (cmd->env) { |
104 | for (; *cmd->env; cmd->env++) { | 106 | for (; *cmd->env; cmd->env++) { |
105 | if (strchr(*cmd->env, '=')) | 107 | if (strchr(*cmd->env, '=')) |
@@ -153,6 +155,8 @@ int start_command(struct child_process *cmd) | |||
153 | 155 | ||
154 | static int wait_or_whine(pid_t pid) | 156 | static int wait_or_whine(pid_t pid) |
155 | { | 157 | { |
158 | char sbuf[STRERR_BUFSIZE]; | ||
159 | |||
156 | for (;;) { | 160 | for (;;) { |
157 | int status, code; | 161 | int status, code; |
158 | pid_t waiting = waitpid(pid, &status, 0); | 162 | pid_t waiting = waitpid(pid, &status, 0); |
@@ -160,7 +164,8 @@ static int wait_or_whine(pid_t pid) | |||
160 | if (waiting < 0) { | 164 | if (waiting < 0) { |
161 | if (errno == EINTR) | 165 | if (errno == EINTR) |
162 | continue; | 166 | continue; |
163 | error("waitpid failed (%s)", strerror(errno)); | 167 | error("waitpid failed (%s)", |
168 | strerror_r(errno, sbuf, sizeof(sbuf))); | ||
164 | return -ERR_RUN_COMMAND_WAITPID; | 169 | return -ERR_RUN_COMMAND_WAITPID; |
165 | } | 170 | } |
166 | if (waiting != pid) | 171 | if (waiting != pid) |