Skip to content

Commit c05d32b

Browse files
committed
Fix a long-standing logging issue with messages logged from a background printer setup thread (Issue #1450)
1 parent 2af52b6 commit c05d32b

1 file changed

Lines changed: 42 additions & 24 deletions

File tree

scheduler/log.c

Lines changed: 42 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,10 @@ cupsdLogClient(cupsd_client_t *con, /* I - Client connection */
503503
const char *message, /* I - Printf-style message string */
504504
...) /* I - Additional arguments as needed */
505505
{
506-
va_list ap, ap2; /* Argument pointers */
507-
char clientmsg[1024];/* Format string for client message */
508-
int status; /* Formatting status */
506+
int ret; /* Return value */
507+
va_list ap, ap2; /* Argument pointers */
508+
char clientmsg[1024]; /* Format string for client message */
509+
int status; /* Formatting status */
509510

510511

511512
/*
@@ -522,6 +523,8 @@ cupsdLogClient(cupsd_client_t *con, /* I - Client connection */
522523
* Format and write the log message...
523524
*/
524525

526+
_cupsMutexLock(&log_mutex);
527+
525528
if (con)
526529
snprintf(clientmsg, sizeof(clientmsg), "[Client %d] %s", con->number,
527530
message);
@@ -541,10 +544,13 @@ cupsdLogClient(cupsd_client_t *con, /* I - Client connection */
541544
va_end(ap);
542545

543546
if (status > 0)
544-
return (cupsdWriteErrorLog(level, log_line));
547+
ret = cupsdWriteErrorLog(level, log_line);
545548
else
546-
return (cupsdWriteErrorLog(CUPSD_LOG_ERROR,
547-
"Unable to allocate memory for log line."));
549+
ret = cupsdWriteErrorLog(CUPSD_LOG_ERROR, "Unable to allocate memory for log line.");
550+
551+
_cupsMutexUnlock(&log_mutex);
552+
553+
return (ret);
548554
}
549555

550556

@@ -558,9 +564,10 @@ cupsdLogJob(cupsd_job_t *job, /* I - Job */
558564
const char *message, /* I - Printf-style message string */
559565
...) /* I - Additional arguments as needed */
560566
{
561-
va_list ap, ap2; /* Argument pointers */
562-
char jobmsg[1024]; /* Format string for job message */
563-
int status; /* Formatting status */
567+
int ret; /* Return value */
568+
va_list ap, ap2; /* Argument pointers */
569+
char jobmsg[1024]; /* Format string for job message */
570+
int status; /* Formatting status */
564571

565572

566573
/*
@@ -577,6 +584,8 @@ cupsdLogJob(cupsd_job_t *job, /* I - Job */
577584
* Format and write the log message...
578585
*/
579586

587+
_cupsMutexLock(&log_mutex);
588+
580589
if (job)
581590
snprintf(jobmsg, sizeof(jobmsg), "[Job %d] %s", job->id, message);
582591
else
@@ -633,7 +642,7 @@ cupsdLogJob(cupsd_job_t *job, /* I - Job */
633642
else if (temp)
634643
free(temp);
635644

636-
return (1);
645+
ret = 1;
637646
}
638647
else if (level <= LogLevel)
639648
{
@@ -666,19 +675,26 @@ cupsdLogJob(cupsd_job_t *job, /* I - Job */
666675
"PRIORITY=%i", log_levels[level],
667676
NULL);
668677

669-
return (1);
678+
ret = 1;
670679
}
671680
else
672681
#endif /* HAVE_SYSTEMD_SD_JOURNAL_H */
673682

674-
return (cupsdWriteErrorLog(level, log_line));
683+
ret = cupsdWriteErrorLog(level, log_line);
675684
}
676685
else
677-
return (1);
686+
{
687+
ret = 1;
688+
}
678689
}
679690
else
680-
return (cupsdWriteErrorLog(CUPSD_LOG_ERROR,
681-
"Unable to allocate memory for log line."));
691+
{
692+
ret = cupsdWriteErrorLog(CUPSD_LOG_ERROR, "Unable to allocate memory for log line.");
693+
}
694+
695+
_cupsMutexUnlock(&log_mutex);
696+
697+
return (ret);
682698
}
683699

684700

@@ -691,8 +707,9 @@ cupsdLogMessage(int level, /* I - Log level */
691707
const char *message, /* I - printf-style message string */
692708
...) /* I - Additional args as needed */
693709
{
694-
va_list ap, ap2; /* Argument pointers */
695-
int status; /* Formatting status */
710+
int ret; /* Return value */
711+
va_list ap, ap2; /* Argument pointers */
712+
int status; /* Formatting status */
696713

697714

698715
/*
@@ -746,6 +763,8 @@ cupsdLogMessage(int level, /* I - Log level */
746763
* Format and write the log message...
747764
*/
748765

766+
_cupsMutexLock(&log_mutex);
767+
749768
va_start(ap, message);
750769

751770
do
@@ -759,10 +778,13 @@ cupsdLogMessage(int level, /* I - Log level */
759778
va_end(ap);
760779

761780
if (status > 0)
762-
return (cupsdWriteErrorLog(level, log_line));
781+
ret = cupsdWriteErrorLog(level, log_line);
763782
else
764-
return (cupsdWriteErrorLog(CUPSD_LOG_ERROR,
765-
"Unable to allocate memory for log line!"));
783+
ret = cupsdWriteErrorLog(CUPSD_LOG_ERROR, "Unable to allocate memory for log line.");
784+
785+
_cupsMutexUnlock(&log_mutex);
786+
787+
return (ret);
766788
}
767789

768790

@@ -1263,8 +1285,6 @@ cupsdWriteErrorLog(int level, /* I - Log level */
12631285
* Not using syslog; check the log file...
12641286
*/
12651287

1266-
_cupsMutexLock(&log_mutex);
1267-
12681288
if (!cupsdCheckLogFile(&ErrorFile, ErrorLog))
12691289
{
12701290
ret = 0;
@@ -1280,8 +1300,6 @@ cupsdWriteErrorLog(int level, /* I - Log level */
12801300
cupsFileFlush(ErrorFile);
12811301
}
12821302

1283-
_cupsMutexUnlock(&log_mutex);
1284-
12851303
return (ret);
12861304
}
12871305

0 commit comments

Comments
 (0)