diff --git a/Platform/user/ulog/log-sched/log_console.c b/Platform/user/ulog/log-sched/log_console.c index 7ef36bfdd..17046c467 100755 --- a/Platform/user/ulog/log-sched/log_console.c +++ b/Platform/user/ulog/log-sched/log_console.c @@ -1,4 +1,5 @@ #include +#include #include #include @@ -9,46 +10,60 @@ #include "sev_sched.h" #define LOG_CONF_COSOLE_FILE_NAME "log-console.conf" - #define LOG_REDIRECT_CONSOLE "/dev/console" +#define PROC_SERIAL_INFO_PATH "/proc/tty/driver/serial" + +#define SERIAL_DRIVER_PREFIX "uart" +#define SERIAL_NO_DRIVER_KEY SERIAL_DRIVER_PREFIX":unknown" +#define SERIAL_PREFIX "ttyS" static int write_console_content(FILE *fp, const u8 level, const char *filter_mod, void *arg) { - DIR *dir; - - if ((dir = opendir(LOG_DEV_DIR)) == NULL) { - ULOG_ERR(g_log, "Open dir:[%s] is failure:%d", LOG_DEV_DIR, strerror(errno)); - return -1; + int ret = -1; + FILE *driver_fp = NULL; + driver_fp = fopen(PROC_SERIAL_INFO_PATH, "r"); + if (driver_fp == NULL) { + ULOG_ERR(g_log, "Opening file:%s is failure:%s", PROC_SERIAL_INFO_PATH, strerror(errno)); + return ret; } - struct dirent *ptr; + char *line = NULL; + size_t n; + int num; char path[MAX_PATH_SZ]; - while ((ptr = readdir(dir)) != NULL) { - if ((strcmp(ptr->d_name, ".") == 0) - || (strcmp(ptr->d_name, "..") == 0) - || (ptr->d_type == DT_DIR)) { ///current dir OR parrent dir - ULOG_DEBUG(g_log,"The file:[%s] or directory jump over", ptr->d_name); - continue; - } - - if ((strstr(ptr->d_name, "ttyS") == NULL)) { - ULOG_DEBUG(g_log,"The file:[%s] isn't redirected", ptr->d_name); + while ((n = getline(&line, &n, driver_fp)) != -1) { + ULOG_DEBUG(g_log, "Serial line:%s", line); + if (strstr(line, SERIAL_DRIVER_PREFIX) == NULL) { + ULOG_DEBUG(g_log, "%s isn't driver line", line); continue; } + + num = atoi(line); + if (strstr(line, SERIAL_NO_DRIVER_KEY) != NULL) { + ULOG_DEBUG(g_log, "%s%d don't have serial", SERIAL_PREFIX, num); + continue; + } - ULOG_DEBUG(g_log, "ttyS name:%s", ptr->d_name); - if (snprintf(path, sizeof(path), "%s%s", LOG_DEV_DIR, ptr->d_name) < 0) { - ULOG_ERR(g_log, "Setting %s of log console is failure", ptr->d_name); - return -1; + + if (snprintf(path, sizeof(path), "%s%s%d", LOG_DEV_DIR, SERIAL_PREFIX, num) < 0) { + ULOG_ERR(g_log, "Setting %s%d of log console is failure", SERIAL_PREFIX, num); + goto END; } + ULOG_DEBUG(g_log, "ttyS name:%s", path); if (write_conf_content_authorizing(fp, level, filter_mod, path) != 0) { ULOG_ERR(g_log, "Writing tty[module:%s] of log is failure", filter_mod); - return -1; + goto END; } - - } + } + + ret = 0; +END: + if (line != NULL) { + free(line); + } - return 0; + fclose(driver_fp); + return ret; }