[Xfce4-commits] <xfce4-power-manager:master> Solaris-specific code for determining the start time of a process.

Nick Schermer noreply at xfce.org
Mon Mar 28 17:22:01 CEST 2011


Updating branch refs/heads/master
         to 47b7e20d7acd2cc64caf379eb6cd385705d3e90d (commit)
       from a34fd777e88be442d74f65c679fa4bb234ecf700 (commit)

commit 47b7e20d7acd2cc64caf379eb6cd385705d3e90d
Author: Guido Berhoerster <gber at openindiana.org>
Date:   Mon Mar 28 17:19:40 2011 +0200

    Solaris-specific code for determining the start time of a process.
    
    Solaris also allows to obtain this information through procfs,
    however design and implementation differ vastly from Linux.

 src/xfpm-polkit.c |   40 +++++++++++++++++++++++++++++++++++-----
 1 files changed, 35 insertions(+), 5 deletions(-)

diff --git a/src/xfpm-polkit.c b/src/xfpm-polkit.c
index a50c2db..29fcf7d 100644
--- a/src/xfpm-polkit.c
+++ b/src/xfpm-polkit.c
@@ -32,12 +32,15 @@
 
 #include <sys/types.h>
 
-#if defined(__FreeBSD__)
-#include <sys/stat.h>
-#else
+#if defined(__linux)
 #include <sys/param.h>
 #include <sys/sysctl.h>
 #include <sys/user.h>
+#elif defined(__FreeBSD__)
+#include <sys/stat.h>
+#elif defined(__SVR4) || defined(__sun)
+#include <fcntl.h>
+#include <procfs.h>
 #endif
 
 #include <errno.h>
@@ -115,7 +118,7 @@ static guint64
 get_start_time_for_pid (pid_t pid)
 {
     guint64 start_time;
-#if !defined(__FreeBSD__)
+#if defined(__linux)
     gchar *filename;
     gchar *contents;
     size_t length;
@@ -172,7 +175,7 @@ get_start_time_for_pid (pid_t pid)
     g_free (filename);
     g_free (contents);
     
-#else /*if !defined(__FreeBSD__)*/
+#elif defined(__FreeBSD__)
 
     struct kinfo_proc p;
     
@@ -189,6 +192,33 @@ get_start_time_for_pid (pid_t pid)
     start_time = (guint64) p.ki_start.tv_sec;
     
 out:
+#elif defined(__SVR4) || defined(__sun)
+
+    psinfo_t p;
+    gchar *filename;
+    int fd;
+
+    start_time = 0;
+
+    filename = g_strdup_printf ("/proc/%d/psinfo", (int) pid);
+    if ((fd = open(filename, O_RDONLY)) < 0)
+    {
+	g_warning ("Error opening %s (%s)",
+		   filename,
+		   g_strerror (errno));
+	goto out;
+    }
+    if (read(fd, &p, sizeof (p)) != sizeof (p))
+    {
+	g_warning ("Error reading %s",
+		   filename);
+	close(fd);
+	goto out;
+    }
+    start_time = (guint64) p.pr_start.tv_sec;
+    close(fd);
+out:
+    g_free (filename);
 #endif
     
     return start_time;



More information about the Xfce4-commits mailing list