Skip to content

Commit 4c9ac3b

Browse files
peffgitster
authored andcommitted
help: clean up kfmclient munging
When we are going to launch "/path/to/konqueror", we instead rewrite this into "/path/to/kfmclient" by duplicating the original string and writing over the ending bits. This can be done more obviously with strip_suffix and xstrfmt. Note that we also fix a subtle bug with the "filename" parameter, which is passed as argv[0] to the child. If the user has configured a program name with no directory component, we always pass the string "kfmclient", even if your program is called something else. But if you give a full path, we give the basename of that path. But more bizarrely, if we rewrite "konqueror" to "kfmclient", we still pass "konqueror". The history of this function doesn't reveal anything interesting, so it looks like just an oversight from combining the suffix-munging with the basename-finding. Let's just call basename on the munged path, which produces consistent results (if you gave a program, whether a full path or not, we pass its basename). Probably this doesn't matter at all in practice, but it makes the code slightly less confusing to read. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b26cb7c commit 4c9ac3b

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

builtin/help.c

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -140,17 +140,10 @@ static void exec_man_konqueror(const char *path, const char *page)
140140

141141
/* It's simpler to launch konqueror using kfmclient. */
142142
if (path) {
143-
const char *file = strrchr(path, '/');
144-
if (file && !strcmp(file + 1, "konqueror")) {
145-
char *new = xstrdup(path);
146-
char *dest = strrchr(new, '/');
147-
148-
/* strlen("konqueror") == strlen("kfmclient") */
149-
strcpy(dest + 1, "kfmclient");
150-
path = new;
151-
}
152-
if (file)
153-
filename = file;
143+
size_t len;
144+
if (strip_suffix(path, "/konqueror", &len))
145+
path = xstrfmt("%.*s/kfmclient", (int)len, path);
146+
filename = basename((char *)path);
154147
} else
155148
path = "kfmclient";
156149
strbuf_addf(&man_page, "man:%s(1)", page);

0 commit comments

Comments
 (0)