From fe465daabb5cf756db323fcfc356c0c463d55b19 Mon Sep 17 00:00:00 2001 From: Alex Riesen Date: Thu, 10 Jul 2008 23:46:51 +0200 Subject: [PATCH] Autoconfigure maximum number of kernel consoles if sysfs is mounted, otherwise fallback to MAX_NR_CONSOLES. The consoles are counted by the existens of the entries under /sys/class/vc/vcs[0-9]. Strictly speaking, vcs0 is just the currently active console, but just to make the pattern a bit broader (in case kernel people will format it with a 0 prepended) 0 is included. Besides, modern kernels just creat vcs, vcs1, vcs2, and so on. AFAIK, the console-kit-daemon can even monitor changes to the consoles by setting an inotify watch for /sys/class/vc (not implemented in this patch) Signed-off-by: Alex Riesen --- src/ck-sysdeps-linux.c | 18 ++++++++++++++++-- 1 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/ck-sysdeps-linux.c b/src/ck-sysdeps-linux.c index 7dc99f7..9926cfc 100644 --- a/src/ck-sysdeps-linux.c +++ b/src/ck-sysdeps-linux.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -620,8 +621,21 @@ ck_unix_pid_get_ppid (pid_t pid) gboolean ck_get_max_num_consoles (guint *num) { - if (num != NULL) { - *num = MAX_NR_CONSOLES; + /* Try sysfs and fallback to MAX_NR_CONSOLES */ + DIR *dirp; + *num = MAX_NR_CONSOLES; + dirp = opendir("/sys/class/vc"); + if (dirp) { + struct dirent *ent; + guint c = 0; + while ((ent = readdir(dirp))) { + if (strncmp(ent->d_name, "vcs", 3) == 0 && + (ent->d_name[4] >= '0' && ent->d_name[4] <= '9')) + ++c; + } + closedir(dirp); + if (c) + *num = c; } return TRUE; -- 1.5.6.2.316.g998c8