Commit 4cd129da authored by Alessandro Rubini's avatar Alessandro Rubini Committed by Adam Wujek

general: allow puts to go to syslog

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent d91fec21
......@@ -151,6 +151,18 @@ config SYSLOG
The user (or init script) must use "syslog <ipaddr> <macaddr>"
to enable it. The special "off" ipaddr disables syslog.
config PUTS_SYSLOG
depends on SYSLOG
boolean "Sent puts (i.e. printf) to syslog too"
help
This allows logging the various warning and error messages
that normally go to the console alone, where nobody is looking
in a deployed system. Output from interactive commands is
not sent to syslog, but self-timed diagnostic (stat, gui, verbose)
will reach syslog anyways, if an interactive user enables them.
Unfortunately, "stat" will reach syslog as several short strings,
and "gui" is full of escape sequences.
config SNMP
depends on IP && !HOST_PROCESS
default y
......
......@@ -19,6 +19,7 @@ obj-$(CONFIG_WR_NODE) += \
dev/pps_gen.o
obj-$(CONFIG_WR_SWITCH) += dev/timer-wrs.o dev/ad9516.o
obj-$(CONFIG_PUTS_SYSLOG) += dev/puts-syslog.o
obj-$(CONFIG_LEGACY_EEPROM) += dev/eeprom.o
obj-$(CONFIG_SDB_STORAGE) += dev/sdb-storage.o
......
#include <wrc.h>
#include <string.h>
#include <uart.h>
#include <shell.h>
#include <lib/ipv4.h>
int puts(const char *s)
{
char new_s[CONFIG_PRINT_BUFSIZE + 4];
int l, ret;
ret = uart_write_string(s);
l = strlen(s);
/* avoid shell-interation stuff */
if (shell_is_interacting)
return ret;
if (l < 2 || s[0] == '\e')
return ret;
if (!strncmp(s, "wrc#", 4))
return ret;
/* if not terminating with newline, add a trailing "...\n" */
strcpy(new_s, s);
if (s[l-1] != '\n') {
new_s[l++] = '.';
new_s[l++] = '.';
new_s[l++] = '.';
new_s[l++] = '\n';
new_s[l++] = '\0';
}
syslog_report(new_s);
return ret;
}
......@@ -56,4 +56,4 @@ int uart_read_byte(void)
}
int puts(const char *s)
__attribute__((alias("uart_write_string")));
__attribute__((weak,alias("uart_write_string")));
......@@ -36,6 +36,7 @@ void env_init(void);
int shell_exec(const char *buf);
int shell_interactive(void);
extern int shell_is_interacting;
void shell_boot_script(void);
......
......@@ -42,6 +42,8 @@ static int cmd_pos = 0, cmd_len = 0;
static int state = SH_PROMPT;
static int current_key = 0;
int shell_is_interacting;
static int insert(char c)
{
if (cmd_len >= SH_MAX_LINE_LEN)
......@@ -116,9 +118,15 @@ static int _shell_exec(void)
int shell_exec(const char *cmd)
{
strncpy(cmd_buf, cmd, SH_MAX_LINE_LEN);
int i;
if (cmd != cmd_buf)
strncpy(cmd_buf, cmd, SH_MAX_LINE_LEN);
cmd_len = strlen(cmd_buf);
return _shell_exec();
shell_is_interacting = 1;
i = _shell_exec();
shell_is_interacting = 0;
return i;
}
void shell_init()
......@@ -130,6 +138,7 @@ void shell_init()
int shell_interactive()
{
int c;
switch (state) {
case SH_PROMPT:
pp_printf("wrc# ");
......@@ -285,7 +294,7 @@ void shell_boot_script(void)
if (!cmd_len)
break;
pp_printf("executing: %s\n", cmd_buf);
_shell_exec();
shell_exec(cmd_buf);
}
while (CONFIG_HAS_FLASH_INIT) {
......@@ -299,7 +308,7 @@ void shell_boot_script(void)
cmd_buf[cmd_len - 1] = 0;
pp_printf("executing: %s\n", cmd_buf);
_shell_exec();
shell_exec(cmd_buf);
next = 1;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment