Index: Makefile
===================================================================
RCS file: /NetBSD/pkgsrc/sysutils/consolekit/Makefile,v
retrieving revision 1.6
diff -u -3 -p -r1.6 Makefile
--- Makefile	10 Dec 2008 11:43:20 -0000	1.6
+++ Makefile	26 Dec 2008 06:28:14 -0000
@@ -4,7 +4,7 @@
 CONSOLEKIT_VER=		0.3.0
 DISTNAME=		ConsoleKit-${CONSOLEKIT_VER}
 PKGNAME=		consolekit-${CONSOLEKIT_VER}
-PKGREVISION=		2
+PKGREVISION=		3
 CATEGORIES=		sysutils
 MASTER_SITES=		http://people.freedesktop.org/~mccann/dist/
 EXTRACT_SUFX=		.tar.bz2
@@ -40,10 +40,19 @@ CONFIGURE_ARGS+=	--localstatedir=${VARBA
 #.include "../../mk/pam.buildlink3.mk"
 
 post-extract:
-	cp ${FILESDIR}/ck-sysdeps-netbsd.c ${WRKSRC}/src/
+	${CP} ${FILESDIR}/ck-sysdeps-netbsd.c ${WRKSRC}/src/
 
 pre-configure:
 	cd ${WRKSRC} && autoreconf -vi
+
+.include "../../mk/bsd.prefs.mk"
+.if ${OPSYS} == "FreeBSD" || ${OPSYS} == "DragonFly"
+post-install:
+	${CP} ${FILESDIR}/ck-get-x11-display-device.FreeBSD \
+		${DESTDIR}${PREFIX}/libexec/ck-get-x11-display-device
+	${CP} ${FILESDIR}/ck-get-x11-server-pid.FreeBSD \
+		${DESTDIR}${PREFIX}/libexec/ck-get-x11-server-pid
+.endif
 
 .include "../../devel/zlib/buildlink3.mk"
 .include "../../security/policykit/buildlink3.mk"
Index: distinfo
===================================================================
RCS file: /NetBSD/pkgsrc/sysutils/consolekit/distinfo,v
retrieving revision 1.5
diff -u -3 -p -r1.5 distinfo
--- distinfo	23 Dec 2008 21:46:14 -0000	1.5
+++ distinfo	26 Dec 2008 06:28:14 -0000
@@ -7,5 +7,7 @@ SHA1 (patch-aa) = a1589faf05d5358a0820da
 SHA1 (patch-ab) = 2e9fe9de1f27c635a4eefa77af8322cb8a02ab35
 SHA1 (patch-ac) = 0595a9cd1c4013eb4761e044b4b4b01b613f7d2b
 SHA1 (patch-ad) = a1c1a1d0452945550065da3eac2390318c1eb7be
-SHA1 (patch-ae) = 0b5bea5260b8595fc9dfef6340ff47b1545b0bec
-SHA1 (patch-af) = ad854bcde3f8defefb476ccec3f68e64d4c055ec
+SHA1 (patch-ae) = 8a9612cd35d1ec86240fd17dfa6963c20edc0ad0
+SHA1 (patch-af) = e86c63147798d61f7560cfe7547b0d06d18d5583
+SHA1 (patch-ag) = 724e2eb95f7ca78c5659fde1eec2f2c5c6bc5002
+SHA1 (patch-ah) = f62d8c661732a4ea47e29b99f883b539fb5c7468
Index: patches/patch-ae
===================================================================
RCS file: /NetBSD/pkgsrc/sysutils/consolekit/patches/patch-ae,v
retrieving revision 1.4
diff -u -3 -p -r1.4 patch-ae
--- patches/patch-ae	25 Nov 2008 13:40:05 -0000	1.4
+++ patches/patch-ae	26 Dec 2008 06:28:14 -0000
@@ -1,7 +1,7 @@
 $NetBSD: patch-ae,v 1.4 2008/11/25 13:40:05 hasso Exp $
 
---- src/ck-sysdeps-unix.c.orig	2008-01-23 16:30:44 +0200
-+++ src/ck-sysdeps-unix.c	2008-11-25 12:34:32 +0200
+--- src/ck-sysdeps-unix.c.orig	2008-11-27 05:10:25 +0200
++++ src/ck-sysdeps-unix.c	2008-11-27 05:09:59 +0200
 @@ -35,6 +35,11 @@
  #include <linux/kd.h>
  #endif
@@ -80,7 +80,23 @@ $NetBSD: patch-ae,v 1.4 2008/11/25 13:40
          kb_ok = (ioctl (fd, CONS_GETVERS, &vers) == 0);
  #else
          kb_ok = 1;
-@@ -184,6 +217,14 @@ ck_get_a_console_fd (void)
+@@ -172,6 +205,15 @@ ck_get_a_console_fd (void)
+ 
+         fd = -1;
+ 
++#if defined(__FreeBSD__) || defined(__DragonFly__)
++	/* On FreeBSD, try /dev/consolectl first as this will survive
++	 * /etc/ttys initialization. */
++	fd = open_a_console ("/dev/consolectl");
++	if (fd >= 0) {
++		goto done;
++	}
++#endif
++
+ #ifdef __sun
+         /* On Solaris, first try Sun VT device. */
+         fd = open_a_console ("/dev/vt/active");
+@@ -184,6 +226,14 @@ ck_get_a_console_fd (void)
          }
  #endif
  
Index: patches/patch-af
===================================================================
RCS file: /NetBSD/pkgsrc/sysutils/consolekit/patches/patch-af,v
retrieving revision 1.1
diff -u -3 -p -r1.1 patch-af
--- patches/patch-af	25 Nov 2008 13:40:05 -0000	1.1
+++ patches/patch-af	26 Dec 2008 06:28:14 -0000
@@ -1,8 +1,16 @@
 $NetBSD: patch-af,v 1.1 2008/11/25 13:40:05 hasso Exp $
 
---- src/ck-sysdeps-freebsd.c.orig	2008-11-25 14:43:51 +0200
-+++ src/ck-sysdeps-freebsd.c	2008-11-25 14:50:24 +0200
-@@ -151,14 +151,38 @@ stat2proc (pid_t        pid,
+--- src/ck-sysdeps-freebsd.c.orig	2008-11-27 05:12:41 +0200
++++ src/ck-sysdeps-freebsd.c	2008-11-27 05:08:28 +0200
+@@ -27,6 +27,7 @@
+ #include <unistd.h>
+ #include <string.h>
+ #include <errno.h>
++#include <glob.h>
+ #include <paths.h>
+ #include <ttyent.h>
+ #include <kvm.h>
+@@ -151,14 +152,38 @@ stat2proc (pid_t        pid,
                  return FALSE;
          }
  
@@ -41,7 +49,7 @@ $NetBSD: patch-af,v 1.1 2008/11/25 13:40
          P->pid        = p.ki_pid;
          P->ppid       = p.ki_ppid;
          P->pgrp       = p.ki_pgid;
-@@ -173,19 +197,33 @@ stat2proc (pid_t        pid,
+@@ -173,19 +198,33 @@ stat2proc (pid_t        pid,
          P->tpgid      = p.ki_tpgid;
          P->processor  = p.ki_oncpu;
          P->nlwp       = p.ki_numthreads;
@@ -75,7 +83,23 @@ $NetBSD: patch-af,v 1.1 2008/11/25 13:40
                  memcpy (P->tty_text, "   ?   ", sizeof P->tty_text);
          }
  
-@@ -308,7 +346,11 @@ ck_unix_pid_get_uid (pid_t pid)
+@@ -202,7 +241,6 @@ ck_process_stat_new_for_unix_pid (pid_t 
+                                   GError        **error)
+ {
+         gboolean       res;
+-        GError        *local_error;
+         CkProcessStat *proc;
+ 
+         g_return_val_if_fail (pid > 1, FALSE);
+@@ -217,7 +255,6 @@ ck_process_stat_new_for_unix_pid (pid_t 
+         if (res) {
+                 *stat = proc;
+         } else {
+-                g_propagate_error (error, local_error);
+                 *stat = NULL;
+         }
+ 
+@@ -308,7 +345,11 @@ ck_unix_pid_get_uid (pid_t pid)
          res = get_kinfo_proc (pid, &p);
  
          if (res) {
@@ -87,3 +111,119 @@ $NetBSD: patch-af,v 1.1 2008/11/25 13:40
          }
  
          return uid;
+@@ -327,38 +368,40 @@ gboolean
+ ck_get_max_num_consoles (guint *num)
+ {
+         int      max_consoles;
+-        int      res;
+-        gboolean ret;
+-        struct ttyent *t;
++        int      i;
++        glob_t   g;
+ 
+-        ret = FALSE;
+         max_consoles = 0;
+ 
+-        res = setttyent ();
+-        if (res == 0) {
+-                goto done;
+-        }
+-
+-        while ((t = getttyent ()) != NULL) {
+-                if (t->ty_status & TTY_ON && strncmp (t->ty_name, "ttyv", 4) == 0)
++        g.gl_offs = 0;
++        glob ("/dev/ttyv*", GLOB_DOOFFS, NULL, &g);
++        for (i = 0; i < g.gl_pathc && g.gl_pathv[i] != NULL; i++) {
++                int fd;
++                char *cdev;
++
++                cdev = g.gl_pathv[i];
++                fd = open (cdev, O_RDONLY | O_NOCTTY);
++                if (fd > -1) {
++                        close (fd);
+                         max_consoles++;
++                } else {
++                        break;
++                }
+         }
+ 
+-        /* Increment one more so that all consoles are properly counted
++        globfree (&g);
++
++        /*
++         * Increment one more so that all consoles are properly counted
+          * this is arguable a bug in vt_add_watches().
+          */
+         max_consoles++;
+ 
+-        ret = TRUE;
+-
+-        endttyent ();
+-
+-done:
+         if (num != NULL) {
+                 *num = max_consoles;
+         }
+ 
+-        return ret;
++        return TRUE;
+ }
+ 
+ char *
+@@ -369,7 +412,12 @@ ck_get_console_device_for_num (guint num
+         /* The device number is always one less than the VT number. */
+         num--;
+ 
+-        device = g_strdup_printf ("/dev/ttyv%u", num);
++        if (num < 10)
++                device = g_strdup_printf ("/dev/ttyv%i", num);
++        else if (num < 32)
++                device = g_strdup_printf ("/dev/ttyv%c", num - 10 + 'a');
++        else
++                device = NULL;
+ 
+         return device;
+ }
+@@ -379,6 +427,7 @@ ck_get_console_num_from_device (const ch
+                                 guint      *num)
+ {
+         guint    n;
++        char     c;
+         gboolean ret;
+ 
+         n = 0;
+@@ -388,7 +437,11 @@ ck_get_console_num_from_device (const ch
+                 return FALSE;
+         }
+ 
+-        if (sscanf (device, "/dev/ttyv%u", &n) == 1) {
++        if (sscanf (device, "/dev/ttyv%c", &c) == 1) {
++                if (c < 58)
++                        n = c - 48;
++                else
++                        n = c - 'a' + 10;
+                 /* The VT number is always one more than the device number. */
+                 n++;
+                 ret = TRUE;
+@@ -408,6 +461,7 @@ ck_get_active_console_num (int    consol
+         gboolean ret;
+         int      res;
+         int      active;
++        char      ttyn;
+ 
+         g_assert (console_fd != -1);
+ 
+@@ -420,7 +474,12 @@ ck_get_active_console_num (int    consol
+                 goto out;
+         }
+ 
+-        g_debug ("Active VT is: %d (ttyv%d)", active, active - 1);
++        if (active - 1 < 10)
++                ttyn = active - 1 + '0';
++        else
++                ttyn = active - 11 + 'a';
++
++        g_debug ("Active VT is: %d (ttyv%c)", active, ttyn);
+         ret = TRUE;
+ 
+  out:
--- /dev/null	2008-12-26 07:13:48 +0200
+++ patches/patch-ag	2008-11-27 08:54:07 +0200
@@ -0,0 +1,15 @@
+$NetBSD$
+
+https://bugs.freedesktop.org/show_bug.cgi?id=18330
+
+--- src/ck-session.c.orig	2008-11-27 05:49:11 +0200
++++ src/ck-session.c	2008-11-27 08:51:37 +0200
+@@ -1100,6 +1100,8 @@ ck_session_finalize (GObject *object)
+ 
+         session_remove_activity_watch (session);
+ 
++        g_object_unref (session->priv->bus_proxy);
++
+         g_free (session->priv->id);
+         g_free (session->priv->cookie);
+         g_free (session->priv->seat_id);
--- /dev/null	2008-12-26 07:13:48 +0200
+++ patches/patch-ah	2008-11-27 08:53:36 +0200
@@ -0,0 +1,14 @@
+$NetBSD$
+
+https://bugs.freedesktop.org/show_bug.cgi?id=17893
+
+--- src/ck-run-programs.c.orig	2008-11-27 08:52:06 +0200
++++ src/ck-run-programs.c	2008-11-27 08:52:40 +0200
+@@ -225,6 +225,7 @@ ck_run_programs (const char *dirpath,
+         out_loop:
+                 g_free (child_argv[0]);
+         }
++        g_dir_close (dir);
+ out:
+         g_strfreev (env_for_child);
+ }
--- /dev/null	2008-12-26 07:13:48 +0200
+++ files/ck-get-x11-display-device.FreeBSD	2008-11-26 19:36:25 +0200
@@ -0,0 +1,35 @@
+#!/bin/sh
+
+FSTAT="/usr/bin/fstat"
+GREP="/usr/bin/grep"
+AWK="/usr/bin/awk"
+SED="/usr/bin/sed"
+CAT="/bin/cat"
+HEAD="/usr/bin/head"
+
+dispnum=0
+if [ x"$1" = x"--display" ]; then
+    if [ $# != 2 ]; then
+	echo "usage: $0 [--display DISPLAY]"
+	exit 1
+    fi
+    DISPLAY=$2
+fi
+if [ ! -z "${DISPLAY}" ]; then
+    dispnum=$(echo ${DISPLAY} | ${SED} -E -e 's|:([0-9]+).*|\1|')
+fi
+
+if [ ! -f "/tmp/.X${dispnum}-lock" ]; then
+    echo "ERROR: Failed to find X lock file for display ${dispnum}"
+    exit 1
+fi
+pid=$(${CAT} "/tmp/.X${dispnum}-lock")
+
+device=$(${FSTAT} -p ${pid} | ${GREP} ttyv | ${HEAD} -1 | ${AWK} '{print $8}')
+
+if [ -z "${device}" ]; then
+    echo "ERROR: Failed to find TTY device for X server on display ${dispnum}"
+    exit 1
+fi
+
+echo "/dev/${device}"
--- /dev/null	2008-12-26 07:13:48 +0200
+++ files/ck-get-x11-server-pid.FreeBSD	2008-11-26 19:39:05 +0200
@@ -0,0 +1,17 @@
+#!/bin/sh
+
+SED="/usr/bin/sed"
+CAT="/bin/cat"
+
+dispnum=0
+if [ ! -z "${DISPLAY}" ]; then
+    dispnum=$(echo ${DISPLAY} | ${SED} -E -e 's|:([0-9]+).*|\1|')
+fi
+
+if [ ! -f "/tmp/.X${dispnum}-lock" ]; then
+    echo "ERROR: Failed to find X lock file for display ${dispnum}"
+    exit 1
+fi
+pid=$(${CAT} "/tmp/.X${dispnum}-lock")
+
+echo ${pid}
