sysvinit/showconsole-1.15.dif

83 lines
1.9 KiB
Plaintext
Raw Normal View History

--- libconsole.c
+++ libconsole.c 2011-12-19 18:11:00.323146490 +0000
@@ -1154,14 +1154,45 @@ static dev_t fallback(const pid_t pid, c
static int checkdev(char ** retname, const dev_t dev, DIR * ddev)
{
- int found = 0;
- struct dirent * d;
- struct stat st;
+ int found = 0, fd;
+ struct dirent *d;
static int deep;
- memset(&st, 0, sizeof(struct stat));
- while ((d = readdir(ddev))) {
- char * name = d->d_name;
+ if (deep == 0) {
+
+ fd = dirfd(ddev);
+ rewinddir(ddev);
+
+ while ((d = readdir(ddev))) { /* First scan all devices direct in /dev/ of devtmpfs */
+ struct stat st;
+ char *name = d->d_name;
+ char path[PATH_MAX+1];
+
+ if (*name == '.')
+ continue;
+ if (fstatat(fd, name, &st, 0) < 0)
+ continue;
+ if (!S_ISCHR(st.st_mode))
+ continue;
+ if (dev != st.st_rdev)
+ continue;
+ if ((size_t)snprintf(path, sizeof(path), "/dev/%s", name) >= sizeof(path))
+ continue;
+ name = realpath(path, NULL);
+ if (!name)
+ break;
+ *retname = name;
+ found++;
+ break;
+ }
+ if (found)
+ goto out;
+ }
+
+ rewinddir(ddev);
+ while ((d = readdir(ddev))) { /* now allow also deeper entries of none devtmpfs */
+ struct stat st;
+ char *name = d->d_name;
if (*name == '.')
continue;
@@ -1306,7 +1337,7 @@ static int checkdev(char ** retname, con
*retname = name;
break;
}
-
+out:
return found;
}
@@ -1448,7 +1479,7 @@ char * fetchtty(const pid_t pid, const p
if (!(name = ttyname(0)) || !strcmp(name, "/dev/console"))
dev = fallback(pid, ppid);
else {
- name = strdup(name);
+ name = realpath(name, NULL);
if (!name)
error("fetchtty(): %m\n");
goto out;
--- showconsole.8
+++ showconsole.8 2011-09-08 15:13:48.000000000 +0000
@@ -8,7 +8,6 @@
.\"
.TH SHOWCONSOLE 8 "Nov 10, 2000" "Version 1.16" "The SuSE boot concept"
.UC 8
-.OS SuSE Linux
.SH NAME
Showconsole \- determines the real tty of stdin
.br