char line[256], *tty, *split;
int i;
+ /* First, try console= on the kernel command line,
+ * then fallback to /sys/class/tty/console/active,
+ * which should work when linux,stdout-path (or equivalent)
+ * is in the device tree
+ */
tty = get_cmdline_val("console", line, sizeof(line));
+ if (tty == NULL) {
+ tty = get_active_console(line, sizeof(line));
+ }
if (tty != NULL) {
split = strchr(tty, ',');
if (split != NULL)
return true;
}
+char *get_active_console(char *out, int len)
+{
+ char line[CMDLINE_SIZE + 1];
+ int fd = open("/sys/class/tty/console/active", O_RDONLY);
+ ssize_t r = read(fd, line, sizeof(line) - 1);
+
+ close(fd);
+
+ if (r <= 0)
+ return NULL;
+
+ /* The active file is terminated by a newline which we need to strip */
+ char *newline = strtok(line, "\n");
+
+ if (newline != NULL) {
+ strncpy(out, newline, len);
+ return out;
+ }
+
+ return NULL;
+}
+
char* get_cmdline_val(const char* name, char* out, int len)
{
char line[CMDLINE_SIZE + 1], *c, *sptr;
bool blobmsg_list_equal(struct blobmsg_list *l1, struct blobmsg_list *l2);
void blobmsg_list_move(struct blobmsg_list *list, struct blobmsg_list *src);
char *get_cmdline_val(const char *name, char *out, int len);
+char *get_active_console(char *out, int len);
int patch_fd(const char *device, int fd, int flags);
int patch_stdio(const char *device);