Save and restore errno before using %m specifier
This commit is contained in:
parent
38b6caa6f9
commit
92ec05ab67
|
@ -111,11 +111,14 @@ int log_func_fd;
|
|||
void log_func_file(int level, const char* fmt, ...)
|
||||
{
|
||||
va_list va;
|
||||
int ret;
|
||||
int ret, saved_errno;
|
||||
const char* level_str;
|
||||
char timebuf[40];
|
||||
time_t t;
|
||||
|
||||
/* save errno, because dprintf will clobber it */
|
||||
saved_errno = errno;
|
||||
|
||||
/* choose appropriate line description */
|
||||
switch(level) {
|
||||
case LOG_EMERG: level_str = "EMERG"; break;
|
||||
|
@ -136,6 +139,7 @@ void log_func_file(int level, const char* fmt, ...)
|
|||
/* print to file descriptor */
|
||||
va_start(va, fmt);
|
||||
ret = dprintf(log_func_fd, "%s %s ", timebuf, level_str);
|
||||
errno = saved_errno;
|
||||
if(ret != -1) ret = vdprintf(log_func_fd, fmt, va);
|
||||
if(ret != -1 && safe_write_fixed(log_func_fd, "\n", 1) != 1) ret = -1;
|
||||
va_end(va);
|
||||
|
|
Loading…
Reference in New Issue