11/*
22 * Log file routines for the CUPS scheduler.
33 *
4- * Copyright © 2020-2025 by OpenPrinting.
4+ * Copyright © 2020-2026 by OpenPrinting.
55 * Copyright © 2007-2018 by Apple Inc.
66 * Copyright © 1997-2007 by Easy Software Products, all rights reserved.
77 *
@@ -505,9 +505,10 @@ cupsdLogClient(cupsd_client_t *con, /* I - Client connection */
505505 const char * message , /* I - Printf-style message string */
506506 ...) /* I - Additional arguments as needed */
507507{
508- va_list ap , ap2 ; /* Argument pointers */
509- char clientmsg [1024 ];/* Format string for client message */
510- int status ; /* Formatting status */
508+ int ret ; /* Return value */
509+ va_list ap , ap2 ; /* Argument pointers */
510+ char clientmsg [1024 ]; /* Format string for client message */
511+ int status ; /* Formatting status */
511512
512513
513514 /*
@@ -524,6 +525,8 @@ cupsdLogClient(cupsd_client_t *con, /* I - Client connection */
524525 * Format and write the log message...
525526 */
526527
528+ cupsMutexLock (& log_mutex );
529+
527530 if (con )
528531 snprintf (clientmsg , sizeof (clientmsg ), "[Client %d] %s" , con -> number ,
529532 message );
@@ -543,10 +546,13 @@ cupsdLogClient(cupsd_client_t *con, /* I - Client connection */
543546 va_end (ap );
544547
545548 if (status > 0 )
546- return ( cupsdWriteErrorLog (level , log_line ) );
549+ ret = cupsdWriteErrorLog (level , log_line );
547550 else
548- return (cupsdWriteErrorLog (CUPSD_LOG_ERROR ,
549- "Unable to allocate memory for log line." ));
551+ ret = cupsdWriteErrorLog (CUPSD_LOG_ERROR , "Unable to allocate memory for log line." );
552+
553+ cupsMutexUnlock (& log_mutex );
554+
555+ return (ret );
550556}
551557
552558
@@ -560,9 +566,10 @@ cupsdLogJob(cupsd_job_t *job, /* I - Job */
560566 const char * message , /* I - Printf-style message string */
561567 ...) /* I - Additional arguments as needed */
562568{
563- va_list ap , ap2 ; /* Argument pointers */
564- char jobmsg [1024 ]; /* Format string for job message */
565- int status ; /* Formatting status */
569+ int ret ; /* Return value */
570+ va_list ap , ap2 ; /* Argument pointers */
571+ char jobmsg [1024 ]; /* Format string for job message */
572+ int status ; /* Formatting status */
566573
567574
568575 /*
@@ -579,6 +586,8 @@ cupsdLogJob(cupsd_job_t *job, /* I - Job */
579586 * Format and write the log message...
580587 */
581588
589+ cupsMutexLock (& log_mutex );
590+
582591 if (job )
583592 snprintf (jobmsg , sizeof (jobmsg ), "[Job %d] %s" , job -> id , message );
584593 else
@@ -635,7 +644,7 @@ cupsdLogJob(cupsd_job_t *job, /* I - Job */
635644 else if (temp )
636645 free (temp );
637646
638- return ( 1 ) ;
647+ ret = 1 ;
639648 }
640649 else if (level <= LogLevel )
641650 {
@@ -668,19 +677,26 @@ cupsdLogJob(cupsd_job_t *job, /* I - Job */
668677 "PRIORITY=%i" , log_levels [level ],
669678 NULL );
670679
671- return ( 1 ) ;
680+ ret = 1 ;
672681 }
673682 else
674683#endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
675684
676- return ( cupsdWriteErrorLog (level , log_line ) );
685+ ret = cupsdWriteErrorLog (level , log_line );
677686 }
678687 else
679- return (1 );
688+ {
689+ ret = 1 ;
690+ }
680691 }
681692 else
682- return (cupsdWriteErrorLog (CUPSD_LOG_ERROR ,
683- "Unable to allocate memory for log line." ));
693+ {
694+ ret = cupsdWriteErrorLog (CUPSD_LOG_ERROR , "Unable to allocate memory for log line." );
695+ }
696+
697+ cupsMutexUnlock (& log_mutex );
698+
699+ return (ret );
684700}
685701
686702
@@ -693,8 +709,9 @@ cupsdLogMessage(int level, /* I - Log level */
693709 const char * message , /* I - printf-style message string */
694710 ...) /* I - Additional args as needed */
695711{
696- va_list ap , ap2 ; /* Argument pointers */
697- int status ; /* Formatting status */
712+ int ret ; /* Return value */
713+ va_list ap , ap2 ; /* Argument pointers */
714+ int status ; /* Formatting status */
698715
699716
700717 /*
@@ -748,6 +765,8 @@ cupsdLogMessage(int level, /* I - Log level */
748765 * Format and write the log message...
749766 */
750767
768+ cupsMutexLock (& log_mutex );
769+
751770 va_start (ap , message );
752771
753772 do
@@ -761,10 +780,13 @@ cupsdLogMessage(int level, /* I - Log level */
761780 va_end (ap );
762781
763782 if (status > 0 )
764- return ( cupsdWriteErrorLog (level , log_line ) );
783+ ret = cupsdWriteErrorLog (level , log_line );
765784 else
766- return (cupsdWriteErrorLog (CUPSD_LOG_ERROR ,
767- "Unable to allocate memory for log line!" ));
785+ ret = cupsdWriteErrorLog (CUPSD_LOG_ERROR , "Unable to allocate memory for log line." );
786+
787+ cupsMutexUnlock (& log_mutex );
788+
789+ return (ret );
768790}
769791
770792
@@ -1030,6 +1052,7 @@ cupsdLogPrinter(
10301052 const char * message , /* I - Printf-style message string */
10311053 ...) /* I - Additional arguments as needed */
10321054{
1055+ int ret ; /* Return value */
10331056 va_list ap , ap2 ; /* Argument pointers */
10341057 char pmsg [1024 ]; /* Format string for printer message */
10351058 int status ; /* Formatting status */
@@ -1049,6 +1072,8 @@ cupsdLogPrinter(
10491072 * Format and write the log message...
10501073 */
10511074
1075+ cupsMutexLock (& log_mutex );
1076+
10521077 if (p )
10531078 snprintf (pmsg , sizeof (pmsg ), "[Printer %s] %s" , p -> name , message );
10541079 else
@@ -1090,15 +1115,21 @@ cupsdLogPrinter(
10901115 "PRIORITY=%i" , log_levels [level ],
10911116 NULL );
10921117
1093- return ( 1 ) ;
1118+ ret = 1 ;
10941119 }
10951120 else
10961121#endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
10971122
1098- return ( cupsdWriteErrorLog (level , log_line ) );
1123+ ret = cupsdWriteErrorLog (level , log_line );
10991124 }
11001125 else
1101- return (cupsdWriteErrorLog (CUPSD_LOG_ERROR , "Unable to allocate memory for log line." ));
1126+ {
1127+ ret = cupsdWriteErrorLog (CUPSD_LOG_ERROR , "Unable to allocate memory for log line." );
1128+ }
1129+
1130+ cupsMutexUnlock (& log_mutex );
1131+
1132+ return (ret );
11021133}
11031134
11041135
@@ -1348,8 +1379,6 @@ cupsdWriteErrorLog(int level, /* I - Log level */
13481379 * Not using syslog; check the log file...
13491380 */
13501381
1351- cupsMutexLock (& log_mutex );
1352-
13531382 if (!cupsdCheckLogFile (& ErrorFile , ErrorLog ))
13541383 {
13551384 ret = 0 ;
@@ -1365,8 +1394,6 @@ cupsdWriteErrorLog(int level, /* I - Log level */
13651394 cupsFileFlush (ErrorFile );
13661395 }
13671396
1368- cupsMutexUnlock (& log_mutex );
1369-
13701397 return (ret );
13711398}
13721399
0 commit comments