From d464faf987ffe80ee015d33056bf999564699577 Mon Sep 17 00:00:00 2001 From: Ben Gras Date: Mon, 3 Apr 2006 15:03:07 +0000 Subject: [PATCH] updated syslog(), added setenv() --- lib/other/Makefile.in | 1 + lib/other/setenv.c | 25 +++++++++++++++++++++++++ lib/other/syslog.c | 17 ++++++----------- 3 files changed, 32 insertions(+), 11 deletions(-) create mode 100755 lib/other/setenv.c diff --git a/lib/other/Makefile.in b/lib/other/Makefile.in index e94157397..d0b802560 100644 --- a/lib/other/Makefile.in +++ b/lib/other/Makefile.in @@ -61,6 +61,7 @@ libc_FILES=" \ putw.c \ random.c \ rindex.c \ + setenv.c \ setgroups.c \ settimeofday.c \ stderr.c \ diff --git a/lib/other/setenv.c b/lib/other/setenv.c new file mode 100755 index 000000000..b734a983a --- /dev/null +++ b/lib/other/setenv.c @@ -0,0 +1,25 @@ + +#include +#include + +int +setenv(const char *name, const char *val, int overwrite) +{ + char *bf; + int r; + + if(!overwrite && getenv(name)) + return 0; + + if(!(bf=malloc(strlen(name)+strlen(val)+2))) + return -1; + + strcpy(bf, name); + strcat(bf, "="); + strcat(bf, val); + + r = putenv(bf); + + return r == 0 ? 0 : -1; +} + diff --git a/lib/other/syslog.c b/lib/other/syslog.c index 9d8048c19..caf2120e4 100644 --- a/lib/other/syslog.c +++ b/lib/other/syslog.c @@ -39,14 +39,6 @@ * Rewritten by Martin Mares on May 14, 1997 * Rewritten by G. Falzoni for porting to Minix * - * $Log$ - * Revision 1.1 2005/10/31 14:31:05 beng - * Giovanni's symlink (+syslog+flock) patches. - * - * Revision 1.2 2001/01/04 11:54:26 root - * Removed variable to store PID which is computed - * at each call to avoid reporting parent's pid. - * * $Id$ */ #include @@ -68,6 +60,7 @@ #include #include +static int LogPid = (-1); static int nfd = (-1); static int LogFacility = LOG_USER; static int LogFlags = 0; @@ -86,6 +79,8 @@ void openlog(const char *ident, int option, int facility) /* Stores logging flags */ LogFlags = option & (LOG_PID | LOG_PERROR | LOG_CONS); + /* Stores process id. if LOG_PID was specified */ + if (option & LOG_PID) LogPid = getpid(); /* Stores the requested facility */ LogFacility = facility; /* Stores log tag if supplied */ @@ -134,14 +129,14 @@ void syslog(int lprty, const char *msg,...) int len, rc; va_list ap; - /* First log message opens a channel to syslog */ + /* First log message open chnnel to syslog */ if (nfd < 0) openlog(TagBuffer, LogFlags | LOG_NDELAY, LogFacility); time(&now); len = sprintf(buff, "<%d>%.15s %s: ", LogFacility | lprty, ctime(&now) + 4, TagBuffer); if (LogFlags & LOG_PID) { len -= 2; - len += sprintf(buff + len, "[%d]: ", getpid()); + len += sprintf(buff + len, "[%d]: ", LogPid); } va_start(ap, msg); len += vsprintf(buff + len, msg, ap); @@ -163,7 +158,7 @@ void closelog(void) { close(nfd); - nfd = -1; + LogPid = nfd = -1; LogFacility = LOG_USER; LogFlags = 0; return; -- 2.44.0