From 1c9456a82126f56f4bebca0e7b6671ca844db322 Mon Sep 17 00:00:00 2001 From: Joe Marcus Clarke Date: Wed, 29 Aug 2007 10:10:17 -0400 Subject: fix FreeBSD issues translating VT numbers to devices In FreeBSD the device number is always one less than the VT number (e.g. VT 1 is /dev/ttyv0). Account for this. Also, fix up reading console entries from /etc/ttys, and make sure the full TTY device name is returned for a given process stat. --- src/ck-sysdeps-freebsd.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'src/ck-sysdeps-freebsd.c') diff --git a/src/ck-sysdeps-freebsd.c b/src/ck-sysdeps-freebsd.c index d1760f8..d7c7c0c 100644 --- a/src/ck-sysdeps-freebsd.c +++ b/src/ck-sysdeps-freebsd.c @@ -182,11 +182,11 @@ stat2proc (pid_t pid, snprintf (P->tty_text, sizeof P->tty_text, "%3d,%-3d", tty_maj, tty_min); if (p.ki_tdev != NODEV && (ttname = devname (p.ki_tdev, S_IFCHR)) != NULL) { - memcpy (P->tty_text, ttname, 8); + memcpy (P->tty_text, ttname, sizeof P->tty_text); } if (p.ki_tdev == NODEV) { - memcpy (P->tty_text, " ? ", 8); + memcpy (P->tty_text, " ? ", sizeof P->tty_text); } if (P->pid != pid) { @@ -335,11 +335,12 @@ ck_get_max_num_consoles (guint *num) max_consoles++; } - if (errno == 0) { - ret = TRUE; - } else { - max_consoles = 0; - } + /* Increment one more so that all consoles are properly counted + * this is arguable a bug in vt_add_watches(). + */ + max_consoles++; + + ret = TRUE; endttyent (); @@ -356,6 +357,9 @@ ck_get_console_device_for_num (guint num) { char *device; + /* The device number is always one less than the VT number. */ + num--; + device = g_strdup_printf ("/dev/ttyv%u", num); return device; @@ -376,6 +380,8 @@ ck_get_console_num_from_device (const char *device, } if (sscanf (device, "/dev/ttyv%u", &n) == 1) { + /* The VT number is always one more than the device number. */ + n++; ret = TRUE; } @@ -405,7 +411,7 @@ ck_get_active_console_num (int console_fd, goto out; } - g_debug ("Active VT is: ttyv%d", active); + g_debug ("Active VT is: %d (ttyv%d)", active, active - 1); ret = TRUE; out: -- cgit