You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Mar 10, 2026. It is now read-only.
Repository navigation
This repository was archived by the owner on Mar 10, 2026. It is now read-only.
Crashes randomly after reading tls stuff (Debian, GNU TLS) #4484
Didier, GNU TLS is aborting the process (never appropriate behavior for a library...), and without a backtrace it is impossible to diagnose this further.
Feel free to re-open if you determine there is something in CUPS that needs to be fixed, but right now it looks like GNU TLS doesn't like something and isn't being nice enough to allow cupsd to deal with it.
This issue got discussed for some time, with new strace dumps (see https://bugs.debian.org/760476 for the full discussion). The conclusion seems to be that CUPS is "closing all file descriptors" at some point (including closing the /dev/urandom fd, which GnuTLS is using). Would this ring a bell for you, somewhere in the CUPS code?
Re-opening for discussion, but this is not just CUPS.
The only time cupsd closes all file descriptors is on initial launch when running in "daemon mode", like any other well-behaved daemon. And then we exec ourselves to avoid any nonsense with init on load code that DBUS uses. The only bug here seems to be that when running in child mode we are still closing the file descriptors...
But, looking at the latest strace output it appears that GNU TLS has some init on load code that opens /dev/urandom, which is extremely odd given that you MUST call gnutls_global_init() before you use the library. This will cause problems for any daemon process since closing extra file descriptors is standard operating procedure.
So it looks like you also need to fix GNU TLS to only open /dev/urandom when gnutls_global_init() is called and not before.
Hi,
I'm the author of gnutls. In 3.3.0 we made gnutls_global_init() optional [0], and is no longer required to be called to use the library. As Linux only supports randomness via a file descriptor we need to open /dev/urandom early and keep its fd (to avoid issues with servers which chroot in an environment without /dev/urandom). If you cannot avoid the mass fd closing, would a new function gnutls_fd_in_use() [1] solve the issue of cups?
I'm thinking of an alternative approach that will reopen the fd on the first call to gnutls_global_init() by the application if it is not available. That would solve the issue transparently for cups.
Mike: I see you've marked this as pending; I assume you have a plan? I'm looking forward to a patch that would apply to 1.7.5 as that's the version we'll release the future stable release with. :)
Nikos: Having a gnutls_fd_in_use function isn't really useful, as it makes for a fragile API. I do understand the issues of needing to open /dev/urandom early, however since you've required applications to call gnutls_global_init for a long time it seems like the change to not require it (or at least moving its actions to load-time initializations) has unwanted side effects. Previously an application could make sure that initializations were done at an appropriate time, and now you've made that impossible...
Didier: The change should be usable with 1.7.x, although you might need to tweak it slightly. All in the main() function anyways...
--- a/scheduler/main.c
+++ b/scheduler/main.c
@@ -100,6 +100,8 @@
int i; /* Looping var /
char *opt; / Option character /
int fg; / Run in the foreground */
int close_all = 1, /* Close all file descriptors? */
disconnect = 1; /\* Disconnect from controlling terminal? _/
int fds; /_ Number of ready descriptors /
cupsd_client_t *con; / Current client /
cupsd_job_t *job; / Current job */
@@ -152,6 +154,8 @@
{
Launchd = 1;
fg = 1;
close_all = 0;
disconnect = 0;
}
#endif /* HAVE_LAUNCHD */
@@ -163,6 +167,7 @@
case 'C' : /* Run as child with config file */
run_as_child = 1;
fg = -1;
close_all = 0;
case 'c' : /* Configuration file */
i ++;
@@ -218,10 +223,13 @@
case 'f' : /* Run in foreground... */
fg = 1;
disconnect = 0;
close_all = 0;
break;
case 'F' : /* Run in foreground, but disconnect from terminal... */
fg = -1;
close_all = 0;
break;
case 'h' : /* Show usage/help */
Yes, when we added support for systemd I changed "launchd" named variables to "ondemand" to make things more general purpose.
As for the "fg" changes, yes I decided to clean that up because the different values were starting to get hard to track - instead it now just determines whether cupsd runs in the foreground, with the other variables tracking how things are initialized...
given that Debian's now in freeze, I'd like to only import minimal changes; would the attached patch (none of the 'fg' changes) be working correctly on top of 1.7 ?
Activity
michaelrsweet commentedon Sep 16, 2014
CUPS.org User: mike
Didier, GNU TLS is aborting the process (never appropriate behavior for a library...), and without a backtrace it is impossible to diagnose this further.
Feel free to re-open if you determine there is something in CUPS that needs to be fixed, but right now it looks like GNU TLS doesn't like something and isn't being nice enough to allow cupsd to deal with it.
michaelrsweet commentedon Oct 29, 2014
CUPS.org User: odyx
This issue got discussed for some time, with new strace dumps (see https://bugs.debian.org/760476 for the full discussion). The conclusion seems to be that CUPS is "closing all file descriptors" at some point (including closing the /dev/urandom fd, which GnuTLS is using). Would this ring a bell for you, somewhere in the CUPS code?
Cheers, OdyX
michaelrsweet commentedon Oct 29, 2014
CUPS.org User: mike
Re-opening for discussion, but this is not just CUPS.
The only time cupsd closes all file descriptors is on initial launch when running in "daemon mode", like any other well-behaved daemon. And then we exec ourselves to avoid any nonsense with init on load code that DBUS uses. The only bug here seems to be that when running in child mode we are still closing the file descriptors...
But, looking at the latest strace output it appears that GNU TLS has some init on load code that opens /dev/urandom, which is extremely odd given that you MUST call gnutls_global_init() before you use the library. This will cause problems for any daemon process since closing extra file descriptors is standard operating procedure.
So it looks like you also need to fix GNU TLS to only open /dev/urandom when gnutls_global_init() is called and not before.
michaelrsweet commentedon Oct 29, 2014
CUPS.org User: nikmav
Hi,
I'm the author of gnutls. In 3.3.0 we made gnutls_global_init() optional [0], and is no longer required to be called to use the library. As Linux only supports randomness via a file descriptor we need to open /dev/urandom early and keep its fd (to avoid issues with servers which chroot in an environment without /dev/urandom). If you cannot avoid the mass fd closing, would a new function gnutls_fd_in_use() [1] solve the issue of cups?
[0]. http://www.gnutls.org/manual/gnutls.html#Initialization
[1]. https://gitorious.org/gnutls/gnutls/commit/2c12530bacc89485e807ec18ae455f4e190b383f
michaelrsweet commentedon Oct 31, 2014
CUPS.org User: nikmav
I'm thinking of an alternative approach that will reopen the fd on the first call to gnutls_global_init() by the application if it is not available. That would solve the issue transparently for cups.
https://www.gitorious.org/gnutls/gnutls/commit/684b825f5f78cc7ad1f61be232fd20ee0bc5b56f
michaelrsweet commentedon Nov 6, 2014
CUPS.org User: odyx
Mike: I see you've marked this as pending; I assume you have a plan? I'm looking forward to a patch that would apply to 1.7.5 as that's the version we'll release the future stable release with. :)
michaelrsweet commentedon Nov 12, 2014
CUPS.org User: mike
Nikos: Having a gnutls_fd_in_use function isn't really useful, as it makes for a fragile API. I do understand the issues of needing to open /dev/urandom early, however since you've required applications to call gnutls_global_init for a long time it seems like the change to not require it (or at least moving its actions to load-time initializations) has unwanted side effects. Previously an application could make sure that initializations were done at an appropriate time, and now you've made that impossible...
Didier: The change should be usable with 1.7.x, although you might need to tweak it slightly. All in the main() function anyways...
michaelrsweet commentedon Nov 12, 2014
CUPS.org User: mike
Fixed in Subversion repository.
michaelrsweet commentedon Nov 12, 2014
"str4484.patch":
Index: scheduler/main.c
--- scheduler/main.c (revision 12243)
+++ scheduler/main.c (working copy)
@@ -100,7 +100,11 @@
{
int i; /* Looping var /
char *opt; / Option character */
cupsd_client_t *con; / Current client /
cupsd_job_t *job; / Current job /
@@ -116,8 +120,6 @@
#if defined(HAVE_SIGACTION) && !defined(HAVE_SIGSET)
struct sigaction action; / Actions for POSIX signals /
#endif / HAVE_SIGACTION && !HAVE_SIGSET */
int use_sysman = 1; /_ Use system management functions? */
#else
@@ -150,8 +152,10 @@
#ifdef HAVE_LAUNCHD
if (getenv("CUPSD_LAUNCHD"))
{
}
#endif /* HAVE_LAUNCHD */
@@ -162,7 +166,8 @@
{
case 'C' : /* Run as child with config file */
run_as_child = 1;
case 'c' : /* Configuration file */
i ++;
@@ -217,11 +222,14 @@
break;
@@ -230,12 +238,16 @@
#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)
#else
_cupsLangPuts(stderr, _("cupsd: On-demand support not compiled "
"in, running in normal mode."));
#endif /* HAVE_LAUNCHD || HAVE_SYSTEMD */
break;
@@ -244,6 +256,8 @@
"use only!\n", stderr);
stop_scheduler = 1;
fg = 1;
@@ -285,6 +299,8 @@
case 't' : /* Test the cupsd.conf file... */
TestConfigFile = 1;
fg = 1;
default : /* Unknown option */
@@ -332,8 +348,57 @@
free(filename);
}
if (disconnect)
{
/*
* Make sure we aren't tying up any filesystems...
*/
/*
* If the user hasn't specified "-f", run in the background...
*/
if (!fg)
@@ -408,74 +473,17 @@
#endif /* OpenBSD && OpenBSD < 201211 */
/*
* Since CoreFoundation and DBUS both create fork-unsafe data on execution of
* a program, and since this kind of really unfriendly behavior seems to be
* more common these days in system libraries, we need to re-execute the
* background cupsd with the "-C" option to avoid problems. Unfortunately,
* we also have to assume that argv[0] contains the name of the cupsd
* executable - there is no portable way to get the real pathname...
* Since many system libraries create fork-unsafe data on execution of a
* program, we need to re-execute the background cupsd with the "-C" and "-s"
* options to avoid problems. Unfortunately, we also have to assume that
* argv[0] contains the name of the cupsd executable - there is no portable
*/
execlp(argv[0], argv[0], "-C", ConfigurationFile, (char *)0);
execlp(argv[0], argv[0], "-C", ConfigurationFile, "-s", CupsFilesFile, (char *)0);
exit(errno);
}
if (fg < 1)
{
/*
* Make sure we aren't tying up any filesystems...
- */
- chdir("/");
-#ifndef DEBUG
- */
- setrlimit(RLIMIT_CORE, &limit);
- */
- setsid();
- */
- getrlimit(RLIMIT_NOFILE, &limit);
- close(i);
- */
- }
- }
-#endif /* DEBUG */
- }
/*
*/
michaelrsweet commentedon Nov 12, 2014
"str4484-1.7.patch":
--- a/scheduler/main.c
+++ b/scheduler/main.c
@@ -100,6 +100,8 @@
int i; /* Looping var /
char *opt; / Option character /
int fg; / Run in the foreground */
cupsd_client_t *con; / Current client /
cupsd_job_t *job; / Current job */
@@ -152,6 +154,8 @@
{
Launchd = 1;
fg = 1;
}
#endif /* HAVE_LAUNCHD */
@@ -163,6 +167,7 @@
case 'C' : /* Run as child with config file */
run_as_child = 1;
fg = -1;
case 'c' : /* Configuration file */
i ++;
@@ -218,10 +223,13 @@
@@ -232,10 +240,14 @@
#ifdef HAVE_LAUNCHD
Launchd = 1;
fg = 1;
#else
_cupsLangPuts(stderr, _("cupsd: launchd(8) support not compiled "
"in, running in normal mode."));
fg = 0;
#endif /* HAVE_LAUNCHD */
break;
@@ -244,6 +256,8 @@
"use only!\n", stderr);
stop_scheduler = 1;
fg = 1;
@@ -286,6 +300,8 @@
case 't' : /* Test the cupsd.conf file... */
TestConfigFile = 1;
fg = 1;
default : /* Unknown option */
@@ -333,8 +349,57 @@
free(filename);
}
if (disconnect)
{
/*
* Make sure we aren't tying up any filesystems...
*/
/*
* If the user hasn't specified "-f", run in the background...
*/
if (!fg)
@@ -409,74 +474,17 @@
#endif /* OpenBSD && OpenBSD < 201211 */
/*
* Since CoreFoundation and DBUS both create fork-unsafe data on execution of
* a program, and since this kind of really unfriendly behavior seems to be
* more common these days in system libraries, we need to re-execute the
* background cupsd with the "-C" option to avoid problems. Unfortunately,
* we also have to assume that argv[0] contains the name of the cupsd
* executable - there is no portable way to get the real pathname...
* Since many system libraries create fork-unsafe data on execution of a
* program, we need to re-execute the background cupsd with the "-C" and "-s"
* options to avoid problems. Unfortunately, we also have to assume that
* argv[0] contains the name of the cupsd executable - there is no portable
*/
execlp(argv[0], argv[0], "-C", ConfigurationFile, (char *)0);
execlp(argv[0], argv[0], "-C", ConfigurationFile, "-s", CupsFilesFile, (char *)0);
exit(errno);
}
if (fg < 1)
{
/*
* Make sure we aren't tying up any filesystems...
- */
- chdir("/");
-#ifndef DEBUG
- */
- setrlimit(RLIMIT_CORE, &limit);
- */
- setsid();
- */
- getrlimit(RLIMIT_NOFILE, &limit);
- close(i);
- */
- }
- }
-#endif /* DEBUG */
- }
/*
*/
michaelrsweet commentedon Nov 13, 2014
CUPS.org User: alexk
@@ -230,12 +238,16 @@
#if defined(HAVE_LAUNCHD) || defined(HAVE_SYSTEMD)
CUPS 1.7.5 has Launchd = 1 here and in a few other places. Should OnDemand be renamed to LaunchD for 1.7.5 patch?
Also, in the majority of updates fg retains its value, but in a couple of them it changes. It is expected and not a copy/paste error, right?
michaelrsweet commentedon Nov 13, 2014
CUPS.org User: mike
Yes, when we added support for systemd I changed "launchd" named variables to "ondemand" to make things more general purpose.
As for the "fg" changes, yes I decided to clean that up because the different values were starting to get hard to track - instead it now just determines whether cupsd runs in the foreground, with the other variables tracking how things are initialized...
michaelrsweet commentedon Nov 17, 2014
CUPS.org User: odyx
Hi Mike,
given that Debian's now in freeze, I'd like to only import minimal changes; would the attached patch (none of the 'fg' changes) be working correctly on top of 1.7 ?
TIA, cheers, OdyX
michaelrsweet commentedon Nov 17, 2014
CUPS.org User: mike
Looks good.