summaryrefslogtreecommitdiff
path: root/src/shared/fileio.c
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-07-19 04:02:50 -0400
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2013-07-26 12:16:57 -0400
commit68fee104e630eb19f04b8196a83c14c2c9c469e7 (patch)
tree61588d5747fd6ee0288fc2bf939d4d91a8a4eea0 /src/shared/fileio.c
parentcba38758b4d49c6fe7c2f0eea255e11ee9df23eb (diff)
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.
Diffstat (limited to 'src/shared/fileio.c')
-rw-r--r--src/shared/fileio.c29
1 files changed, 29 insertions, 0 deletions
diff --git a/src/shared/fileio.c b/src/shared/fileio.c
index dc13c9ee63..2b1dab8053 100644
--- a/src/shared/fileio.c
+++ b/src/shared/fileio.c
@@ -593,3 +593,32 @@ int write_env_file(const char *fname, char **l) {
return r;
}
+
+int executable_is_script(const char *path, char **interpreter) {
+ int r;
+ char _cleanup_free_ *line = NULL;
+ int len;
+ char *ans;
+
+ assert(path);
+
+ r = read_one_line_file(path, &line);
+ if (r < 0)
+ return r;
+
+ if (!startswith(line, "#!"))
+ return 0;
+
+ ans = strstrip(line + 2);
+ len = strcspn(ans, " \t");
+
+ if (len == 0)
+ return 0;
+
+ ans = strndup(ans, len);
+ if (!ans)
+ return -ENOMEM;
+
+ *interpreter = ans;
+ return 1;
+}