77 lines
2.3 KiB
C
Executable File
77 lines
2.3 KiB
C
Executable File
#include <errno.h>
|
|
#include <dirent.h>
|
|
#include <sys/types.h>
|
|
|
|
#include "log_console.h"
|
|
#include "log_types.h"
|
|
#include "log_common.h"
|
|
|
|
#define LOG_CONF_COSOLE_FILE_NAME "log-console.conf"
|
|
|
|
#define LOG_REDIRECT_CONSOLE "/dev/console"
|
|
|
|
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\n", LOG_DEV_DIR, strerror(errno));
|
|
return -1;
|
|
}
|
|
|
|
struct dirent *ptr;
|
|
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\n", ptr->d_name);
|
|
continue;
|
|
}
|
|
|
|
if ((strstr(ptr->d_name, "ttyS") == NULL)) {
|
|
ULOG_DEBUG(g_log,"The file:[%s] isn't redirected\n", ptr->d_name);
|
|
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 (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;
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
|
|
static int config_log_console(const log_console_t *conf)
|
|
{
|
|
if (log_conf(conf->level, LOG_CONF_PATH, LOG_CONF_COSOLE_FILE_NAME, conf->module_name,
|
|
write_console_content, NULL) != 0) {
|
|
ULOG_ERR(g_log, "Log's console configure which is written is failure");
|
|
return -1;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
void rpc_conf_log_console(rpc_conn *conn, pointer input, int input_len, pointer data)
|
|
{
|
|
u32 need_len = sizeof(log_console_t);
|
|
if (input_len < need_len) {
|
|
ULOG_WARNING(g_log,
|
|
"The input paramter of rpc log console is needed length of %u, but the actual length is %u",
|
|
need_len, input_len);
|
|
return;
|
|
}
|
|
|
|
config_log_console((const log_console_t *)input);
|
|
}
|
|
|