View | Details | Raw Unified | Return to bug 186114 | Differences between
and this patch

Collapse All | Expand All

(-)lib/libc/gen/syslog.c (-21 / +24 lines)
Lines 129-136 syslog(int pri, const char *fmt, ...) Link Here
129
	va_end(ap);
129
	va_end(ap);
130
}
130
}
131
131
132
void
132
static void
133
vsyslog(int pri, const char *fmt, va_list ap)
133
vsyslog1(int pri, const char *fmt, va_list ap)
134
{
134
{
135
	int cnt;
135
	int cnt;
136
	char ch, *p;
136
	char ch, *p;
Lines 151-163 vsyslog(int pri, const char *fmt, va_lis Link Here
151
151
152
	saved_errno = errno;
152
	saved_errno = errno;
153
153
154
	THREAD_LOCK();
155
156
	/* Check priority against setlogmask values. */
154
	/* Check priority against setlogmask values. */
157
	if (!(LOG_MASK(LOG_PRI(pri)) & LogMask)) {
155
	if (!(LOG_MASK(LOG_PRI(pri)) & LogMask))
158
		THREAD_UNLOCK();
159
		return;
156
		return;
160
	}
161
157
162
	/* Set default facility if none specified. */
158
	/* Set default facility if none specified. */
163
	if ((pri & LOG_FACMASK) == 0)
159
	if ((pri & LOG_FACMASK) == 0)
Lines 167-176 vsyslog(int pri, const char *fmt, va_lis Link Here
167
	tbuf_cookie.base = tbuf;
163
	tbuf_cookie.base = tbuf;
168
	tbuf_cookie.left = sizeof(tbuf);
164
	tbuf_cookie.left = sizeof(tbuf);
169
	fp = fwopen(&tbuf_cookie, writehook);
165
	fp = fwopen(&tbuf_cookie, writehook);
170
	if (fp == NULL) {
166
	if (fp == NULL)
171
		THREAD_UNLOCK();
172
		return;
167
		return;
173
	}
174
168
175
	/* Build the message. */
169
	/* Build the message. */
176
	(void)time(&now);
170
	(void)time(&now);
Lines 200-206 vsyslog(int pri, const char *fmt, va_lis Link Here
200
		fmt_fp = fwopen(&fmt_cookie, writehook);
194
		fmt_fp = fwopen(&fmt_cookie, writehook);
201
		if (fmt_fp == NULL) {
195
		if (fmt_fp == NULL) {
202
			fclose(fp);
196
			fclose(fp);
203
			THREAD_UNLOCK();
204
			return;
197
			return;
205
		}
198
		}
206
199
Lines 285-294 vsyslog(int pri, const char *fmt, va_lis Link Here
285
			 */
278
			 */
286
			disconnectlog();
279
			disconnectlog();
287
			connectlog();
280
			connectlog();
288
			if (send(LogFile, tbuf, cnt, 0) >= 0) {
281
			if (send(LogFile, tbuf, cnt, 0) >= 0)
289
				THREAD_UNLOCK();
290
				return;
282
				return;
291
			}
292
			/*
283
			/*
293
			 * if the resend failed, fall through to
284
			 * if the resend failed, fall through to
294
			 * possible scenario 2
285
			 * possible scenario 2
Lines 303-317 vsyslog(int pri, const char *fmt, va_lis Link Here
303
			if (status == CONNPRIV)
294
			if (status == CONNPRIV)
304
				break;
295
				break;
305
			_usleep(1);
296
			_usleep(1);
306
			if (send(LogFile, tbuf, cnt, 0) >= 0) {
297
			if (send(LogFile, tbuf, cnt, 0) >= 0)
307
				THREAD_UNLOCK();
308
				return;
298
				return;
309
			}
310
		}
299
		}
311
	} else {
300
	} else
312
		THREAD_UNLOCK();
313
		return;
301
		return;
314
	}
315
302
316
	/*
303
	/*
317
	 * Output the message to the console; try not to block
304
	 * Output the message to the console; try not to block
Lines 333-342 vsyslog(int pri, const char *fmt, va_lis Link Here
333
		(void)_writev(fd, iov, 2);
320
		(void)_writev(fd, iov, 2);
334
		(void)_close(fd);
321
		(void)_close(fd);
335
	}
322
	}
323
}
324
325
static void
326
syslog_cancel_cleanup(void *arg __unused)
327
{
336
328
337
	THREAD_UNLOCK();
329
	THREAD_UNLOCK();
338
}
330
}
339
331
332
void
333
vsyslog(int pri, const char *fmt, va_list ap)
334
{
335
336
	THREAD_LOCK();
337
	pthread_cleanup_push(syslog_cancel_cleanup, NULL);
338
	vsyslog1(pri, fmt, ap);
339
	pthread_cleanup_pop(1);
340
}
341
340
/* Should be called with mutex acquired */
342
/* Should be called with mutex acquired */
341
static void
343
static void
342
disconnectlog(void)
344
disconnectlog(void)
Lines 424-431 void Link Here
424
openlog(const char *ident, int logstat, int logfac)
426
openlog(const char *ident, int logstat, int logfac)
425
{
427
{
426
	THREAD_LOCK();
428
	THREAD_LOCK();
429
	pthread_cleanup_push(syslog_cancel_cleanup, NULL);
427
	openlog_unlocked(ident, logstat, logfac);
430
	openlog_unlocked(ident, logstat, logfac);
428
	THREAD_UNLOCK();
431
	pthread_cleanup_pop(1);
429
}
432
}
430
433
431
434

Return to bug 186114