Skip to content

Commit

Permalink
help: clean up kfmclient munging
Browse files Browse the repository at this point in the history
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 <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Jeff King authored and Junio C Hamano committed Oct 5, 2015
1 parent b26cb7c commit 4c9ac3b
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions builtin/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,17 +140,10 @@ static void exec_man_konqueror(const char *path, const char *page)

/* It's simpler to launch konqueror using kfmclient. */
if (path) {
const char *file = strrchr(path, '/');
if (file && !strcmp(file + 1, "konqueror")) {
char *new = xstrdup(path);
char *dest = strrchr(new, '/');

/* strlen("konqueror") == strlen("kfmclient") */
strcpy(dest + 1, "kfmclient");
path = new;
}
if (file)
filename = file;
size_t len;
if (strip_suffix(path, "/konqueror", &len))
path = xstrfmt("%.*s/kfmclient", (int)len, path);
filename = basename((char *)path);
} else
path = "kfmclient";
strbuf_addf(&man_page, "man:%s(1)", page);
Expand Down

0 comments on commit 4c9ac3b

Please sign in to comment.