diff options
author | William Jon McCann <mccann@jhu.edu> | 2007-08-21 11:50:08 -0400 |
---|---|---|
committer | William Jon McCann <mccann@jhu.edu> | 2007-08-21 11:50:08 -0400 |
commit | de3718f03a6e1a83c1024dad0dea5b070b1b27b4 (patch) | |
tree | b3ce0494431812b23cd133b50c5f2c1b3e5fc9f9 | |
parent | 0145691112f14352ef15b49c1ea3079a8e80f6e8 (diff) |
abstract out the tty device basename stuff
-rw-r--r-- | src/ck-seat.c | 15 | ||||
-rw-r--r-- | src/ck-sysdeps-linux.c | 35 | ||||
-rw-r--r-- | src/ck-sysdeps-solaris.c | 35 | ||||
-rw-r--r-- | src/ck-sysdeps.h | 8 |
4 files changed, 80 insertions, 13 deletions
diff --git a/src/ck-seat.c b/src/ck-seat.c index fb2d288..e04b569 100644 --- a/src/ck-seat.c +++ b/src/ck-seat.c @@ -25,13 +25,6 @@ #include <fcntl.h> #include <unistd.h> #include <string.h> -#ifdef HAVE_PATHS_H -#include <paths.h> -#endif /* HAVE_PATHS_H */ - -#ifndef _PATH_TTY -#define _PATH_TTY "/dev/tty" -#endif #include <glib.h> #include <glib/gi18n.h> @@ -41,6 +34,8 @@ #include <dbus/dbus-glib.h> #include <dbus/dbus-glib-lowlevel.h> +#include "ck-sysdeps.h" + #include "ck-seat.h" #include "ck-seat-glue.h" #include "ck-marshal.h" @@ -173,6 +168,7 @@ _seat_activate_session (CkSeat *seat, CkSession *session, DBusGMethodInvocation *context) { + gboolean res; gboolean ret; guint num; char *device; @@ -206,7 +202,8 @@ _seat_activate_session (CkSeat *seat, ck_session_get_display_device (session, &device, NULL); - if (device == NULL || (sscanf (device, _PATH_TTY "%u", &num) != 1)) { + res = ck_get_console_num_from_device (device, &num); + if (! res) { GError *error; error = g_error_new (CK_SEAT_ERROR, CK_SEAT_ERROR_GENERAL, @@ -490,7 +487,7 @@ update_active_vt (CkSeat *seat, CkSession *session; char *device; - device = g_strdup_printf (_PATH_TTY "%u", num); + device = ck_get_console_device_for_num (num); g_debug ("Active device: %s", device); diff --git a/src/ck-sysdeps-linux.c b/src/ck-sysdeps-linux.c index 4b751d7..0ff0fe6 100644 --- a/src/ck-sysdeps-linux.c +++ b/src/ck-sysdeps-linux.c @@ -617,3 +617,38 @@ ck_get_max_num_consoles (guint *num) return TRUE; } + +char * +ck_get_console_device_for_num (guint num) +{ + char *device; + + device = g_strdup_printf (_PATH_TTY "%u", num); + + return device; +} + +gboolean +ck_get_console_num_from_device (const char *device, + guint *num) +{ + guint n; + gboolean ret; + + n = 0; + ret = FALSE; + + if (device == NULL) { + return FALSE; + } + + if (sscanf (device, _PATH_TTY "%u", &n) == 1) { + ret = TRUE; + } + + if (num != NULL) { + *num = n; + } + + return ret; +} diff --git a/src/ck-sysdeps-solaris.c b/src/ck-sysdeps-solaris.c index c1b1b64..ba7d5aa 100644 --- a/src/ck-sysdeps-solaris.c +++ b/src/ck-sysdeps-solaris.c @@ -379,3 +379,38 @@ ck_get_max_num_consoles (guint *num) return ret; } + +char * +ck_get_console_device_for_num (guint num) +{ + char *device; + + device = g_strdup_printf ("/dev/vt/%u", num); + + return device; +} + +gboolean +ck_get_console_num_from_device (const char *device, + guint *num) +{ + guint n; + gboolean ret; + + n = 0; + ret = FALSE; + + if (device == NULL) { + return FALSE; + } + + if (sscanf (device, "/dev/vt/%u", &n) == 1) { + ret = TRUE; + } + + if (num != NULL) { + *num = n; + } + + return ret; +} diff --git a/src/ck-sysdeps.h b/src/ck-sysdeps.h index 986018e..3ef7c14 100644 --- a/src/ck-sysdeps.h +++ b/src/ck-sysdeps.h @@ -25,10 +25,6 @@ #include <glib.h> -#ifdef HAVE_PATHS_H -#include <paths.h> -#endif /* HAVE_PATHS_H */ - G_BEGIN_DECLS typedef struct _CkProcessStat CkProcessStat; @@ -64,6 +60,10 @@ gboolean ck_is_root_user (void); gboolean ck_get_max_num_consoles (guint *num); +char * ck_get_console_device_for_num (guint num); +gboolean ck_get_console_num_from_device (const char *device, + guint *num); + G_END_DECLS #endif /* __CK_SYSDEPS_H */ |