/*
* Log file routines for the CUPS scheduler.
*
- * Copyright © 2020-2025 by OpenPrinting.
+ * Copyright © 2020-2026 by OpenPrinting.
* Copyright © 2007-2018 by Apple Inc.
* Copyright © 1997-2007 by Easy Software Products, all rights reserved.
*
const char *message, /* I - Printf-style message string */
...) /* I - Additional arguments as needed */
{
- va_list ap, ap2; /* Argument pointers */
- char clientmsg[1024];/* Format string for client message */
- int status; /* Formatting status */
+ int ret; /* Return value */
+ va_list ap, ap2; /* Argument pointers */
+ char clientmsg[1024]; /* Format string for client message */
+ int status; /* Formatting status */
/*
* Format and write the log message...
*/
+ cupsMutexLock(&log_mutex);
+
if (con)
snprintf(clientmsg, sizeof(clientmsg), "[Client %d] %s", con->number,
message);
va_end(ap);
if (status > 0)
- return (cupsdWriteErrorLog(level, log_line));
+ ret = cupsdWriteErrorLog(level, log_line);
else
- return (cupsdWriteErrorLog(CUPSD_LOG_ERROR,
- "Unable to allocate memory for log line."));
+ ret = cupsdWriteErrorLog(CUPSD_LOG_ERROR, "Unable to allocate memory for log line.");
+
+ cupsMutexUnlock(&log_mutex);
+
+ return (ret);
}
const char *message, /* I - Printf-style message string */
...) /* I - Additional arguments as needed */
{
- va_list ap, ap2; /* Argument pointers */
- char jobmsg[1024]; /* Format string for job message */
- int status; /* Formatting status */
+ int ret; /* Return value */
+ va_list ap, ap2; /* Argument pointers */
+ char jobmsg[1024]; /* Format string for job message */
+ int status; /* Formatting status */
/*
* Format and write the log message...
*/
+ cupsMutexLock(&log_mutex);
+
if (job)
snprintf(jobmsg, sizeof(jobmsg), "[Job %d] %s", job->id, message);
else
else if (temp)
free(temp);
- return (1);
+ ret = 1;
}
else if (level <= LogLevel)
{
"PRIORITY=%i", log_levels[level],
NULL);
- return (1);
+ ret = 1;
}
else
#endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
- return (cupsdWriteErrorLog(level, log_line));
+ ret = cupsdWriteErrorLog(level, log_line);
}
else
- return (1);
+ {
+ ret = 1;
+ }
}
else
- return (cupsdWriteErrorLog(CUPSD_LOG_ERROR,
- "Unable to allocate memory for log line."));
+ {
+ ret = cupsdWriteErrorLog(CUPSD_LOG_ERROR, "Unable to allocate memory for log line.");
+ }
+
+ cupsMutexUnlock(&log_mutex);
+
+ return (ret);
}
const char *message, /* I - printf-style message string */
...) /* I - Additional args as needed */
{
- va_list ap, ap2; /* Argument pointers */
- int status; /* Formatting status */
+ int ret; /* Return value */
+ va_list ap, ap2; /* Argument pointers */
+ int status; /* Formatting status */
/*
* Format and write the log message...
*/
+ cupsMutexLock(&log_mutex);
+
va_start(ap, message);
do
va_end(ap);
if (status > 0)
- return (cupsdWriteErrorLog(level, log_line));
+ ret = cupsdWriteErrorLog(level, log_line);
else
- return (cupsdWriteErrorLog(CUPSD_LOG_ERROR,
- "Unable to allocate memory for log line!"));
+ ret = cupsdWriteErrorLog(CUPSD_LOG_ERROR, "Unable to allocate memory for log line.");
+
+ cupsMutexUnlock(&log_mutex);
+
+ return (ret);
}
const char *message, /* I - Printf-style message string */
...) /* I - Additional arguments as needed */
{
+ int ret; /* Return value */
va_list ap, ap2; /* Argument pointers */
char pmsg[1024]; /* Format string for printer message */
int status; /* Formatting status */
* Format and write the log message...
*/
+ cupsMutexLock(&log_mutex);
+
if (p)
snprintf(pmsg, sizeof(pmsg), "[Printer %s] %s", p->name, message);
else
"PRIORITY=%i", log_levels[level],
NULL);
- return (1);
+ ret = 1;
}
else
#endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
- return (cupsdWriteErrorLog(level, log_line));
+ ret = cupsdWriteErrorLog(level, log_line);
}
else
- return (cupsdWriteErrorLog(CUPSD_LOG_ERROR, "Unable to allocate memory for log line."));
+ {
+ ret = cupsdWriteErrorLog(CUPSD_LOG_ERROR, "Unable to allocate memory for log line.");
+ }
+
+ cupsMutexUnlock(&log_mutex);
+
+ return (ret);
}
* Not using syslog; check the log file...
*/
- cupsMutexLock(&log_mutex);
-
if (!cupsdCheckLogFile(&ErrorFile, ErrorLog))
{
ret = 0;
cupsFileFlush(ErrorFile);
}
- cupsMutexUnlock(&log_mutex);
-
return (ret);
}