summaryrefslogtreecommitdiff
path: root/libc/misc
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>2003-04-19 23:35:01 +0000
committerEric Andersen <andersen@codepoet.org>2003-04-19 23:35:01 +0000
commit080865820280749a0da0a14957ae3da56f88d901 (patch)
treec963acf0282bd3d605f3ae20d59716a811c9992a /libc/misc
parentf2473c7d658d765400ae22136086b1447e384e25 (diff)
Patch from Marshall M. Midden:
It turns out that uClibc's syslog.c does not close sockets when doing retries and when it exits due to errors. This patch fixes it.
Diffstat (limited to 'libc/misc')
-rw-r--r--libc/misc/syslog/syslog.c72
1 files changed, 39 insertions, 33 deletions
diff --git a/libc/misc/syslog/syslog.c b/libc/misc/syslog/syslog.c
index 2320caf25..8822b02a5 100644
--- a/libc/misc/syslog/syslog.c
+++ b/libc/misc/syslog/syslog.c
@@ -111,7 +111,9 @@ static void
closelog_intern(int to_default)
{
LOCK;
- (void) close(LogFile);
+ if (LogFile != -1) {
+ (void) close(LogFile);
+ }
LogFile = -1;
connected = 0;
if (to_default)
@@ -264,46 +266,50 @@ getout:
void
openlog( const char *ident, int logstat, int logfac )
{
- int logType = SOCK_DGRAM;
-
- LOCK;
-
- if (ident != NULL)
- LogTag = ident;
- LogStat = logstat;
- if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0)
- LogFacility = logfac;
- if (LogFile == -1) {
- SyslogAddr.sa_family = AF_UNIX;
- (void)strncpy(SyslogAddr.sa_data, _PATH_LOG,
- sizeof(SyslogAddr.sa_data));
+ int logType = SOCK_DGRAM;
+
+ LOCK;
+
+ if (ident != NULL)
+ LogTag = ident;
+ LogStat = logstat;
+ if (logfac != 0 && (logfac &~ LOG_FACMASK) == 0)
+ LogFacility = logfac;
+ if (LogFile == -1) {
+ SyslogAddr.sa_family = AF_UNIX;
+ (void)strncpy(SyslogAddr.sa_data, _PATH_LOG,
+ sizeof(SyslogAddr.sa_data));
retry:
- if (LogStat & LOG_NDELAY) {
- if ((LogFile = socket(AF_UNIX, logType, 0)) == -1){
- UNLOCK;
- return;
- }
-/* fcntl(LogFile, F_SETFD, 1); */
- }
+ if (LogStat & LOG_NDELAY) {
+ if ((LogFile = socket(AF_UNIX, logType, 0)) == -1){
+ UNLOCK;
+ return;
+ }
+ /* fcntl(LogFile, F_SETFD, 1); */
}
- if (LogFile != -1 && !connected &&
-#if 0
- connect(LogFile, &SyslogAddr, sizeof(SyslogAddr.sa_family)+
- strlen(SyslogAddr.sa_data)) != -1
-#else
- connect(LogFile, &SyslogAddr, sizeof(SyslogAddr) -
- sizeof(SyslogAddr.sa_data) +
- strlen(SyslogAddr.sa_data)) != -1
-#endif
- )
+ }
+
+ if (LogFile != -1 && !connected) {
+ if (connect(LogFile, &SyslogAddr, sizeof(SyslogAddr) -
+ sizeof(SyslogAddr.sa_data) + strlen(SyslogAddr.sa_data)) != -1)
{
- connected = 1;
+ connected = 1;
} else if (logType == SOCK_DGRAM) {
logType = SOCK_STREAM;
+ if (LogFile != -1) {
+ close(LogFile);
+ LogFile = -1;
+ }
goto retry;
+ } else {
+ if (LogFile != -1) {
+ close(LogFile);
+ LogFile = -1;
+ }
}
+ }
- UNLOCK;
+ UNLOCK;
}
/*