From 5e0f4848e5bfd325840d405582bdedf3a27b98f8 Mon Sep 17 00:00:00 2001 From: William Jon McCann Date: Mon, 27 Aug 2007 16:34:45 -0400 Subject: move some of the freebsd specific stuff into sysdeps --- src/ck-sysdeps-unix.c | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) (limited to 'src/ck-sysdeps-unix.c') diff --git a/src/ck-sysdeps-unix.c b/src/ck-sysdeps-unix.c index 6c9b34c..2094e48 100644 --- a/src/ck-sysdeps-unix.c +++ b/src/ck-sysdeps-unix.c @@ -33,6 +33,7 @@ #ifdef __linux__ #include +#include #endif #ifdef __FreeBSD__ @@ -45,6 +46,10 @@ #include "ck-sysdeps.h" +#ifndef ERROR +#define ERROR -1 +#endif + /* Adapted from dbus-sysdeps-unix.c:_dbus_read_credentials_socket() */ gboolean ck_get_socket_peer_credentials (int socket_fd, @@ -234,3 +239,67 @@ ck_is_root_user (void) #endif return FALSE; } + +gboolean +ck_wait_for_active_console_num (int console_fd, + guint num) +{ + gboolean ret; + int res; + + g_assert (console_fd != -1); + + again: + ret = FALSE; + + g_debug ("VT_WAITACTIVE for vt %d", num); + errno = 0; + res = ioctl (console_fd, VT_WAITACTIVE, num); + + g_debug ("VT_WAITACTIVE for vt %d returned %d", num, ret); + + if (res == ERROR) { + const char *errmsg; + + errmsg = g_strerror (errno); + + if (errno == EINTR) { + g_debug ("Interrupted waiting for native console %d activation: %s", + num, + errmsg); + goto again; + } else { + g_warning ("Error waiting for native console %d activation: %s", + num, + errmsg); + } + goto out; + } + + ret = TRUE; + + out: + return ret; +} + +gboolean +ck_activate_console_num (int console_fd, + guint num) +{ + gboolean ret; + int res; + + g_assert (console_fd != -1); + + ret = FALSE; + + errno = 0; + res = ioctl (console_fd, VT_ACTIVATE, num); + if (res == 0) { + ret = TRUE; + } else { + g_warning ("Unable to activate console: %s", g_strerror (errno)); + } + + return ret; +} -- cgit