summaryrefslogtreecommitdiff
path: root/os
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2017-02-12 09:35:21 -0800
committerAdam Jackson <ajax@redhat.com>2017-02-14 11:33:47 -0500
commit4c00609c370dab130b69207cb2684c2b92bd3084 (patch)
treed4b15dcb01a87eae4148f47596007cb321d5a73c /os
parent3f9507ed2f7246b2c8cf2bbc430cc99c5f35c92a (diff)
DetermineClientCmd: try using /proc/pid/cmdline on Solaris too
Solaris 11.3.5 introduced support for /proc/pid/cmdline, so try it first, and if we can't open it, then fallback to /proc/pid/psinfo as we did before. Reviewed-by: Adam Jackson <ajax@redhat.com> Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
Diffstat (limited to 'os')
-rw-r--r--os/client.c86
1 files changed, 47 insertions, 39 deletions
diff --git a/os/client.c b/os/client.c
index ef5e3935d..213492d6c 100644
--- a/os/client.c
+++ b/os/client.c
@@ -142,45 +142,7 @@ DetermineClientCmd(pid_t pid, const char **cmdname, const char **cmdargs)
if (pid == -1)
return;
-#ifdef __sun /* Solaris */
- /* Solaris does not support /proc/pid/cmdline, but makes information
- * similar to what ps shows available in a binary structure in the
- * /proc/pid/psinfo file. */
- if (snprintf(path, sizeof(path), "/proc/%d/psinfo", pid) < 0)
- return;
- fd = open(path, O_RDONLY);
- if (fd < 0) {
- ErrorF("Failed to open %s: %s\n", path, strerror(errno));
- return;
- }
- else {
- psinfo_t psinfo = { 0 };
- char *sp;
-
- totsize = read(fd, &psinfo, sizeof(psinfo_t));
- close(fd);
- if (totsize <= 0)
- return;
-
- /* pr_psargs is the first PRARGSZ (80) characters of the command
- * line string - assume up to the first space is the command name,
- * since it's not delimited. While there is also pr_fname, that's
- * more limited, giving only the first 16 chars of the basename of
- * the file that was exec'ed, thus cutting off many long gnome
- * command names, or returning "isapython2.6" for all python scripts.
- */
- psinfo.pr_psargs[PRARGSZ - 1] = '\0';
- sp = strchr(psinfo.pr_psargs, ' ');
- if (sp)
- *sp++ = '\0';
-
- if (cmdname)
- *cmdname = strdup(psinfo.pr_psargs);
-
- if (cmdargs && sp)
- *cmdargs = strdup(sp);
- }
-#elif defined(__OpenBSD__)
+#if defined(__OpenBSD__)
/* on OpenBSD use kvm_getargv() */
{
kvm_t *kd;
@@ -221,7 +183,11 @@ DetermineClientCmd(pid_t pid, const char **cmdname, const char **cmdargs)
return;
fd = open(path, O_RDONLY);
if (fd < 0)
+#ifdef __sun
+ goto fallback;
+#else
return;
+#endif
/* Read the contents of /proc/pid/cmdline. It should contain the
* process name and arguments. */
@@ -256,6 +222,48 @@ DetermineClientCmd(pid_t pid, const char **cmdname, const char **cmdargs)
*cmdargs = args;
}
}
+ return;
+#endif
+
+#ifdef __sun /* Solaris */
+ fallback:
+ /* Solaris prior to 11.3.5 does not support /proc/pid/cmdline, but
+ * makes information similar to what ps shows available in a binary
+ * structure in the /proc/pid/psinfo file. */
+ if (snprintf(path, sizeof(path), "/proc/%d/psinfo", pid) < 0)
+ return;
+ fd = open(path, O_RDONLY);
+ if (fd < 0) {
+ ErrorF("Failed to open %s: %s\n", path, strerror(errno));
+ return;
+ }
+ else {
+ psinfo_t psinfo = { 0 };
+ char *sp;
+
+ totsize = read(fd, &psinfo, sizeof(psinfo_t));
+ close(fd);
+ if (totsize <= 0)
+ return;
+
+ /* pr_psargs is the first PRARGSZ (80) characters of the command
+ * line string - assume up to the first space is the command name,
+ * since it's not delimited. While there is also pr_fname, that's
+ * more limited, giving only the first 16 chars of the basename of
+ * the file that was exec'ed, thus cutting off many long gnome
+ * command names, or returning "isapython2.6" for all python scripts.
+ */
+ psinfo.pr_psargs[PRARGSZ - 1] = '\0';
+ sp = strchr(psinfo.pr_psargs, ' ');
+ if (sp)
+ *sp++ = '\0';
+
+ if (cmdname)
+ *cmdname = strdup(psinfo.pr_psargs);
+
+ if (cmdargs && sp)
+ *cmdargs = strdup(sp);
+ }
#endif
}