Skip to content

Commit 00f79f5

Browse files
committed
Fix some places where errno might not be preserved.
1 parent 9a7f6f3 commit 00f79f5

3 files changed

Lines changed: 22 additions & 12 deletions

File tree

backend/ipp.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* IPP backend for CUPS.
33
*
4-
* Copyright © 2021-2025 by OpenPrinting
4+
* Copyright © 2021-2026 by OpenPrinting
55
* Copyright © 2007-2021 by Apple Inc.
66
* Copyright © 1997-2007 by Easy Software Products, all rights reserved.
77
*
@@ -718,7 +718,7 @@ main(int argc, /* I - Number of command-line args */
718718

719719
if (httpReconnect2(http, 30000, NULL))
720720
{
721-
int error = errno; /* Connection error */
721+
int error = errno; /* Save connection error */
722722

723723
if (http->status == HTTP_STATUS_CUPS_PKI_ERROR)
724724
update_reasons(NULL, "+cups-certificate-error");
@@ -752,7 +752,7 @@ main(int argc, /* I - Number of command-line args */
752752

753753
fprintf(stderr, "DEBUG: Connection error: %s\n", strerror(errno));
754754

755-
if (errno == ECONNREFUSED || errno == EHOSTDOWN || errno == EHOSTUNREACH || errno == ETIMEDOUT || errno == ENOTCONN)
755+
if (error == ECONNREFUSED || error == EHOSTDOWN || error == EHOSTUNREACH || error == ETIMEDOUT || error == ENOTCONN)
756756
{
757757
if (contimeout && (time(NULL) - start_time) > contimeout)
758758
{

backend/lpd.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Line Printer Daemon backend for CUPS.
33
*
4-
* Copyright © 2020-2024 by OpenPrinting.
4+
* Copyright © 2020-2026 by OpenPrinting.
55
* Copyright © 2007-2019 by Apple Inc.
66
* Copyright © 1997-2007 by Easy Software Products, all rights reserved.
77
*
@@ -863,7 +863,7 @@ lpd_queue(const char *hostname, /* I - Host to connect to */
863863

864864
fprintf(stderr, "DEBUG: Connection error: %s\n", strerror(error));
865865

866-
if (errno == ECONNREFUSED || errno == EHOSTDOWN || errno == EHOSTUNREACH || errno == ETIMEDOUT || errno == ENOTCONN)
866+
if (error == ECONNREFUSED || error == EHOSTDOWN || error == EHOSTUNREACH || error == ETIMEDOUT || error == ENOTCONN)
867867
{
868868
if (contimeout && (time(NULL) - start_time) > contimeout)
869869
{

cups/debug.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Debugging functions for CUPS.
33
*
4-
* Copyright © 2020-2024 by OpenPrinting.
4+
* Copyright © 2020-2026 by OpenPrinting.
55
* Copyright © 2008-2018 by Apple Inc.
66
*
77
* Licensed under Apache License v2.0. See the file "LICENSE" for more
@@ -89,6 +89,7 @@ _cups_debug_printf(const char *format, /* I - Printf-style format string */
8989
char buffer[2048]; /* Output buffer */
9090
ssize_t bytes; /* Number of bytes in buffer */
9191
int level; /* Log level in message */
92+
int myerrno = errno;/* Copy of errno value */
9293

9394

9495
/*
@@ -100,7 +101,7 @@ _cups_debug_printf(const char *format, /* I - Printf-style format string */
100101
getenv("CUPS_DEBUG_FILTER"), 0);
101102

102103
if (_cups_debug_fd < 0)
103-
return;
104+
goto done;
104105

105106
/*
106107
* Filter as needed...
@@ -112,7 +113,7 @@ _cups_debug_printf(const char *format, /* I - Printf-style format string */
112113
level = 0;
113114

114115
if (level > _cups_debug_level)
115-
return;
116+
goto done;
116117

117118
if (debug_filter)
118119
{
@@ -123,7 +124,7 @@ _cups_debug_printf(const char *format, /* I - Printf-style format string */
123124
_cupsMutexUnlock(&debug_init_mutex);
124125

125126
if (result)
126-
return;
127+
goto done;
127128
}
128129

129130
/*
@@ -158,6 +159,10 @@ _cups_debug_printf(const char *format, /* I - Printf-style format string */
158159
_cupsMutexLock(&debug_log_mutex);
159160
write(_cups_debug_fd, buffer, (size_t)bytes);
160161
_cupsMutexUnlock(&debug_log_mutex);
162+
163+
done:
164+
165+
errno = myerrno;
161166
}
162167

163168

@@ -172,6 +177,7 @@ _cups_debug_puts(const char *s) /* I - String to output */
172177
char buffer[2048]; /* Output buffer */
173178
ssize_t bytes; /* Number of bytes in buffer */
174179
int level; /* Log level in message */
180+
int myerrno = errno;/* Copy of errno value */
175181

176182

177183
/*
@@ -183,7 +189,7 @@ _cups_debug_puts(const char *s) /* I - String to output */
183189
getenv("CUPS_DEBUG_FILTER"), 0);
184190

185191
if (_cups_debug_fd < 0)
186-
return;
192+
goto done;
187193

188194
/*
189195
* Filter as needed...
@@ -195,7 +201,7 @@ _cups_debug_puts(const char *s) /* I - String to output */
195201
level = 0;
196202

197203
if (level > _cups_debug_level)
198-
return;
204+
goto done;
199205

200206
if (debug_filter)
201207
{
@@ -206,7 +212,7 @@ _cups_debug_puts(const char *s) /* I - String to output */
206212
_cupsMutexUnlock(&debug_init_mutex);
207213

208214
if (result)
209-
return;
215+
goto done;
210216
}
211217

212218
/*
@@ -238,6 +244,10 @@ _cups_debug_puts(const char *s) /* I - String to output */
238244
_cupsMutexLock(&debug_log_mutex);
239245
write(_cups_debug_fd, buffer, (size_t)bytes);
240246
_cupsMutexUnlock(&debug_log_mutex);
247+
248+
done:
249+
250+
errno = myerrno;
241251
}
242252

243253

0 commit comments

Comments
 (0)