aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/builtin-help.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2017-06-27 09:52:57 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2017-06-27 09:52:57 -0400
commit881c362d34ef76600b859e3a034d4155139bad2c (patch)
treeca40b870b417b62141932e69f61aad85f9f7d555 /tools/perf/builtin-help.c
parent19508c048a2f90facb64624340bf1b7ee555442e (diff)
perf help: Introduce exec_failed() to avoid code duplication
The warning(str_error_r(errno)) pattern can be replaced with a function, do it. And while at it use pr_warning(), we have way too many error reporting facilities, time to drop some, starting with the one we got from the git sources. Cc: Adrian Hunter <adrian.hunter@intel.com> Cc: David Ahern <dsahern@gmail.com> Cc: Jiri Olsa <jolsa@kernel.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Wang Nan <wangnan0@huawei.com> Link: http://lkml.kernel.org/n/tip-lbak5npj1ri1uuvf1en3c0p0@git.kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/builtin-help.c')
-rw-r--r--tools/perf/builtin-help.c22
1 files changed, 9 insertions, 13 deletions
diff --git a/tools/perf/builtin-help.c b/tools/perf/builtin-help.c
index 492f8e14ab09..e82fa0d5866e 100644
--- a/tools/perf/builtin-help.c
+++ b/tools/perf/builtin-help.c
@@ -108,10 +108,14 @@ out:
108 return ret; 108 return ret;
109} 109}
110 110
111static void exec_woman_emacs(const char *path, const char *page) 111static void exec_failed(const char *cmd)
112{ 112{
113 char sbuf[STRERR_BUFSIZE]; 113 char sbuf[STRERR_BUFSIZE];
114 pr_warning("failed to exec '%s': %s", cmd, str_error_r(errno, sbuf, sizeof(sbuf)));
115}
114 116
117static void exec_woman_emacs(const char *path, const char *page)
118{
115 if (!check_emacsclient_version()) { 119 if (!check_emacsclient_version()) {
116 /* This works only with emacsclient version >= 22. */ 120 /* This works only with emacsclient version >= 22. */
117 char *man_page; 121 char *man_page;
@@ -122,8 +126,7 @@ static void exec_woman_emacs(const char *path, const char *page)
122 execlp(path, "emacsclient", "-e", man_page, NULL); 126 execlp(path, "emacsclient", "-e", man_page, NULL);
123 free(man_page); 127 free(man_page);
124 } 128 }
125 warning("failed to exec '%s': %s", path, 129 exec_failed(path);
126 str_error_r(errno, sbuf, sizeof(sbuf)));
127 } 130 }
128} 131}
129 132
@@ -134,7 +137,6 @@ static void exec_man_konqueror(const char *path, const char *page)
134 if (display && *display) { 137 if (display && *display) {
135 char *man_page; 138 char *man_page;
136 const char *filename = "kfmclient"; 139 const char *filename = "kfmclient";
137 char sbuf[STRERR_BUFSIZE];
138 140
139 /* It's simpler to launch konqueror using kfmclient. */ 141 /* It's simpler to launch konqueror using kfmclient. */
140 if (path) { 142 if (path) {
@@ -155,33 +157,27 @@ static void exec_man_konqueror(const char *path, const char *page)
155 execlp(path, filename, "newTab", man_page, NULL); 157 execlp(path, filename, "newTab", man_page, NULL);
156 free(man_page); 158 free(man_page);
157 } 159 }
158 warning("failed to exec '%s': %s", path, 160 exec_failed(path);
159 str_error_r(errno, sbuf, sizeof(sbuf)));
160 } 161 }
161} 162}
162 163
163static void exec_man_man(const char *path, const char *page) 164static void exec_man_man(const char *path, const char *page)
164{ 165{
165 char sbuf[STRERR_BUFSIZE];
166
167 if (!path) 166 if (!path)
168 path = "man"; 167 path = "man";
169 execlp(path, "man", page, NULL); 168 execlp(path, "man", page, NULL);
170 warning("failed to exec '%s': %s", path, 169 exec_failed(path);
171 str_error_r(errno, sbuf, sizeof(sbuf)));
172} 170}
173 171
174static void exec_man_cmd(const char *cmd, const char *page) 172static void exec_man_cmd(const char *cmd, const char *page)
175{ 173{
176 char sbuf[STRERR_BUFSIZE];
177 char *shell_cmd; 174 char *shell_cmd;
178 175
179 if (asprintf(&shell_cmd, "%s %s", cmd, page) > 0) { 176 if (asprintf(&shell_cmd, "%s %s", cmd, page) > 0) {
180 execl("/bin/sh", "sh", "-c", shell_cmd, NULL); 177 execl("/bin/sh", "sh", "-c", shell_cmd, NULL);
181 free(shell_cmd); 178 free(shell_cmd);
182 } 179 }
183 warning("failed to exec '%s': %s", cmd, 180 exec_failed(cmd);
184 str_error_r(errno, sbuf, sizeof(sbuf)));
185} 181}
186 182
187static void add_man_viewer(const char *name) 183static void add_man_viewer(const char *name)