]>
git.wh0rd.org - sysvinit.git/blob - src/consoles.c
2 * consoles.c Routines to detect the system consoles
4 * Copyright (c) 2011 SuSE LINUX Products GmbH, All rights reserved.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2, or (at your option)
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program (see the file COPYING); if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
21 * Author: Werner Fink <werner@suse.de>
28 #include <sys/types.h>
33 #if !defined(__STDC_VERSION__) || (__STDC_VERSION__ < 199901L)
35 # define typeof __typeof__
38 # define restrict __restrict__
42 #define alignof(type) ((sizeof(type)+(sizeof(void*)-1)) & ~(sizeof(void*)-1))
44 struct console
*consoles
;
46 static dev_t comparedev
;
47 static char* scandev(DIR *dir
)
49 char *name
= (char*)0;
55 while ((dent
= readdir(dir
))) {
58 if (fstatat(fd
, dent
->d_name
, &st
, 0) < 0)
60 if (!S_ISCHR(st
.st_mode
))
62 if (comparedev
!= st
.st_rdev
)
64 if ((size_t)snprintf(path
, sizeof(path
), "/dev/%s", dent
->d_name
) >= sizeof(path
))
66 name
= realpath(path
, NULL
);
72 void detect_consoles(void)
75 if ((fc
= fopen("/proc/consoles", "r"))) {
79 dir
= opendir("/dev");
82 while ((fscanf(fc
, "%*s %*s (%[^)]) %d:%d", &fbuf
[0], &maj
, &min
) == 3)) {
83 struct console
*restrict tail
;
86 if (!strchr(fbuf
, 'E'))
88 comparedev
= makedev(maj
, min
);
94 if (posix_memalign((void*)&tail
, sizeof(void*), alignof(typeof(struct console
))) != 0)
95 perror("memory allocation");
97 tail
->next
= (struct console
*)0;
103 consoles
->next
= tail
;