patches/ConsoleKit-07-sol-vt-major.diff
author Jon Tibble <meths@btinternet.com>
Sat, 06 Oct 2012 16:11:50 +0100
branchs11express-2010-11
changeset 22109 db10202d5f6d
parent 16911 31e2f6cba93e
permissions -rw-r--r--
Added tag oi_151a_prestable7 for changeset 25dee50cecca

commit 42a909bbc8ede5c27e3d40606a98ab1251511dfc
Author: Halton Huo <[email protected]>
Date:   Tue Nov 3 11:42:07 2009 +0800

    Identify major device number for vt rather than hard code as 15.
    Fixes bug http://defect.opensolaris.org/bz/show_bug.cgi?id=12322
    This is solaris only bug, won't affect other platform.

diff --git a/src/ck-sysdeps-solaris.c b/src/ck-sysdeps-solaris.c
index 607a3ae..335ab8b 100644
--- a/src/ck-sysdeps-solaris.c
+++ b/src/ck-sysdeps-solaris.c
@@ -124,6 +124,26 @@ ck_process_stat_get_tty (CkProcessStat *stat)
         return g_strdup (stat->tty_text);
 }
 
+#define VT0_FILE "/dev/vt/0"
+static int
+get_system_vt_major ()
+{
+        static      ret = -1;
+        struct stat st;
+        int         res;
+
+        if (ret >= 0)
+                return ret;
+
+        res = stat (VT0_FILE, &st);
+
+        if (res == 0) {
+                ret = major (st.st_rdev);
+        }
+        
+        return ret;
+}
+
 /* return 1 if it works, or 0 for failure */
 static gboolean
 stat2proc (pid_t        pid,
@@ -177,7 +197,7 @@ stat2proc (pid_t        pid,
 
         snprintf (P->tty_text, sizeof P->tty_text, "%3d,%-3d", tty_maj, tty_min);
 
-	if (tty_maj == 15) {
+	if (tty_maj == get_system_vt_major ()) {
 		snprintf (P->tty_text, sizeof P->tty_text, "/dev/vt/%u", tty_min);
         }
         if (P->tty == NO_TTY_VALUE) {