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.orgSigned-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 19508c04
...@@ -108,10 +108,14 @@ static int check_emacsclient_version(void) ...@@ -108,10 +108,14 @@ static int check_emacsclient_version(void)
return ret; return ret;
} }
static void exec_woman_emacs(const char *path, const char *page) static void exec_failed(const char *cmd)
{ {
char sbuf[STRERR_BUFSIZE]; char sbuf[STRERR_BUFSIZE];
pr_warning("failed to exec '%s': %s", cmd, str_error_r(errno, sbuf, sizeof(sbuf)));
}
static void exec_woman_emacs(const char *path, const char *page)
{
if (!check_emacsclient_version()) { if (!check_emacsclient_version()) {
/* This works only with emacsclient version >= 22. */ /* This works only with emacsclient version >= 22. */
char *man_page; char *man_page;
...@@ -122,8 +126,7 @@ static void exec_woman_emacs(const char *path, const char *page) ...@@ -122,8 +126,7 @@ static void exec_woman_emacs(const char *path, const char *page)
execlp(path, "emacsclient", "-e", man_page, NULL); execlp(path, "emacsclient", "-e", man_page, NULL);
free(man_page); free(man_page);
} }
warning("failed to exec '%s': %s", path, exec_failed(path);
str_error_r(errno, sbuf, sizeof(sbuf)));
} }
} }
...@@ -134,7 +137,6 @@ static void exec_man_konqueror(const char *path, const char *page) ...@@ -134,7 +137,6 @@ static void exec_man_konqueror(const char *path, const char *page)
if (display && *display) { if (display && *display) {
char *man_page; char *man_page;
const char *filename = "kfmclient"; const char *filename = "kfmclient";
char sbuf[STRERR_BUFSIZE];
/* It's simpler to launch konqueror using kfmclient. */ /* It's simpler to launch konqueror using kfmclient. */
if (path) { if (path) {
...@@ -155,33 +157,27 @@ static void exec_man_konqueror(const char *path, const char *page) ...@@ -155,33 +157,27 @@ static void exec_man_konqueror(const char *path, const char *page)
execlp(path, filename, "newTab", man_page, NULL); execlp(path, filename, "newTab", man_page, NULL);
free(man_page); free(man_page);
} }
warning("failed to exec '%s': %s", path, exec_failed(path);
str_error_r(errno, sbuf, sizeof(sbuf)));
} }
} }
static void exec_man_man(const char *path, const char *page) static void exec_man_man(const char *path, const char *page)
{ {
char sbuf[STRERR_BUFSIZE];
if (!path) if (!path)
path = "man"; path = "man";
execlp(path, "man", page, NULL); execlp(path, "man", page, NULL);
warning("failed to exec '%s': %s", path, exec_failed(path);
str_error_r(errno, sbuf, sizeof(sbuf)));
} }
static void exec_man_cmd(const char *cmd, const char *page) static void exec_man_cmd(const char *cmd, const char *page)
{ {
char sbuf[STRERR_BUFSIZE];
char *shell_cmd; char *shell_cmd;
if (asprintf(&shell_cmd, "%s %s", cmd, page) > 0) { if (asprintf(&shell_cmd, "%s %s", cmd, page) > 0) {
execl("/bin/sh", "sh", "-c", shell_cmd, NULL); execl("/bin/sh", "sh", "-c", shell_cmd, NULL);
free(shell_cmd); free(shell_cmd);
} }
warning("failed to exec '%s': %s", cmd, exec_failed(cmd);
str_error_r(errno, sbuf, sizeof(sbuf)));
} }
static void add_man_viewer(const char *name) static void add_man_viewer(const char *name)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment