diff options
| author | Joe Marcus Clarke <marcus@FreeBSD.org> | 2007-08-29 10:10:17 -0400 | 
|---|---|---|
| committer | William Jon McCann <mccann@jhu.edu> | 2007-08-29 10:10:17 -0400 | 
| commit | 1c9456a82126f56f4bebca0e7b6671ca844db322 (patch) | |
| tree | 123ebfefb85fcf46a397a66aa05e6e1ab5e17a94 | |
| parent | b508cf9b49ecd1f4810f69e785ebf40a2e5d5677 (diff) | |
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.
| -rw-r--r-- | src/ck-sysdeps-freebsd.c | 22 | 
1 files changed, 14 insertions, 8 deletions
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:  | 
