#include <sys/types.h>
#include <sys/stat.h>
#include <sys/ioctl.h>
+#include <sys/ttydefaults.h>
#ifdef __linux__
# include <sys/vt.h>
# include <sys/kd.h>
#ifdef __linux__
/*
- * Read and determine active attribute for tty,
- * the caller has to free the result.
+ * Read and determine active attribute for tty below
+ * /sys/class/tty, the caller has to free the result.
*/
static
__attribute__((__malloc__))
return ret;
}
-/* Read and determine device attribute for tty */
+/*
+ * Read and determine device attribute for tty below
+ * /sys/class/tty.
+ */
static
dev_t devattr(const char *tty)
{
}
#endif /* __linux__ */
+/*
+ * Search below /dev for the characer device in
+ * the local `dev_t comparedev' variable.
+ */
static dev_t comparedev;
static
#ifdef __GNUC__
return name;
}
+/*
+ * Default control characters for an unknown terminal line.
+ */
static
struct chardata initcp = {
CERASE,
0
};
+/*
+ * Allocate an aligned `struct console' memory area,
+ * initialize its default values, and append it to
+ * the global linked list.
+ */
+
static int concount; /* Counter for console IDs */
static
consoles->next = tail;
}
-void detect_consoles(const char *device, int fallback)
+/*
+ * Try to detect the real device(s) used for the system console
+ * /dev/console if but only if /dev/console is used. On Linux
+ * this can be more than one device, e.g. a serial line as well
+ * as a virtual console as well as a simple printer.
+ *
+ * Returns 1 if stdout and stderr should be reconnected and 0
+ * otherwise.
+ */
+int detect_consoles(const char *device, int fallback)
{
- int fd;
+ int fd, ret = 0;
#ifdef __linux__
char *attrib, *cmdline;
FILE *fc;
#endif
if (!device || *device == '\0')
fd = dup(fallback);
- else fd = open(device, O_RDWR|O_NONBLOCK|O_NOCTTY|O_CLOEXEC);
+ else {
+ fd = open(device, O_RDWR|O_NONBLOCK|O_NOCTTY|O_CLOEXEC);
+ ret = 1;
+ }
if (fd >= 0) {
DIR *dir;
goto fallback;
}
comparedev = st.st_rdev;
+
+ if (ret && (fstat(fallback, &st) < 0 || comparedev != st.st_rdev))
+ dup2(fd, fallback);
#ifdef __linux__
/*
* Check if the device detection for Linux system console should be used.
closedir(dir);
if (!consoles)
goto fallback;
- return;
+ return ret;
}
#ifdef __linux__
console:
}
closedir(dir);
fclose(fc);
- return;
+ return ret;
}
/*
* Detection of devices used for Linux system console using
free(attrib);
if (!consoles)
goto fallback;
- return;
+ return ret;
}
/*
if (consoles) {
if (!device || *device == '\0')
consoles->fd = fallback;
- return;
+ return ret;
}
#endif
goto fallback;
}
- return;
+ return ret;
}
#endif /* __linux __ */
fallback:
if (consoles)
consoles->fd = fallback;
}
+ return ret;
}