mylsh

my own shell, based on brenns10's
Log | Files | Refs | Feed

commit d50d0a3075986d2b1067c81c61f2c8658e19883a
parent 726e4b738a335a22afea5dbae9ec353c337f3440
Author: Jenny Doe <tng@soykaf.me>
Date:   Tue, 19 Mar 2019 17:43:54 +0100

added: logging

Diffstat:
Mlsh.c | 26++++++++++++++++++++++++++
1 file changed, 26 insertions(+), 0 deletions(-)

diff --git a/lsh.c b/lsh.c @@ -14,6 +14,10 @@ #include <unistd.h> #include <sys/stat.h> #include <sys/param.h> +#include <signal.h> + +#include <syslog.h> +#include <stdarg.h> #include <wchar.h> #include <locale.h> @@ -26,6 +30,22 @@ wchar_t **lsh_split_line(wchar_t *); int lsh_launch(wchar_t * *); int lsh_execute(wchar_t * *); +void lsh_siginfo(int); + +/* + * when receiving a `kill -INFO`, lsh will output a bunch of internal values + */ + +void +lsh_siginfo(int __dummy) +{ + char buf[MAXPATHLEN]; + + syslog(LOG_INFO, "pwd=%s", getwd(&buf[0])); + + return; +} + int lsh_execute(wchar_t * *words) { @@ -168,6 +188,12 @@ main(void) */ umask(022); +#ifdef NDEBUG + setlogmask(LOG_UPTO(LOG_ERR)); +#endif + openlog("message from lsh", LOG_PERROR | LOG_PID, LOG_USER); + signal(SIGINFO, lsh_siginfo); + lsh_loop(); return (0);