From 68fee104e630eb19f04b8196a83c14c2c9c469e7 Mon Sep 17 00:00:00 2001 From: Zbigniew Jędrzejewski-Szmek Date: Fri, 19 Jul 2013 04:02:50 -0400 Subject: journalctl: use _COMM= match for scripts In case of scripts, _EXE is set to the interpreter name, and _COMM is set based on the file name. Add a match for _COMM, and _EXE if the interpreter is not a link (e.g. for yum, the interpreter is /usr/bin/python, but it is a link to /usr/bin/python2, which in turn is a link to /usr/bin/python2.7, at least on Fedora, so we end up with _EXE=/usr/bin/python2.7). I don't think that such link chasing makes sense, because the final _EXE name is more likely to change. --- src/test/test-fileio.c | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) (limited to 'src/test/test-fileio.c') diff --git a/src/test/test-fileio.c b/src/test/test-fileio.c index d56f7cc856..b08e796b7d 100644 --- a/src/test/test-fileio.c +++ b/src/test/test-fileio.c @@ -139,7 +139,42 @@ static void test_parse_env_file(void) { unlink("/tmp/test-fileio"); } +static void test_executable_is_script(void) { + char t[] = "/tmp/test-executable-XXXXXX"; + int fd, r; + FILE *f; + char *command; + + fd = mkostemp(t, O_CLOEXEC); + assert_se(fd >= 0); + + f = fdopen(fd, "w"); + assert_se(f); + + fputs("#! /bin/script -a -b \ngoo goo", f); + fflush(f); + + r = executable_is_script(t, &command); + assert_se(r > 0); + assert_se(streq(command, "/bin/script")); + free(command); + + r = executable_is_script("/bin/sh", &command); + assert_se(r == 0); + + r = executable_is_script("/usr/bin/yum", &command); + assert_se(r > 0 || r == -ENOENT); + if (r > 0) { + assert_se(startswith(command, "/")); + free(command); + } + + fclose(f); + unlink(t); +} + int main(int argc, char *argv[]) { test_parse_env_file(); + test_executable_is_script(); return 0; } -- cgit v1.2.3-54-g00ecf