Skip to content

Commit

Permalink
scheduler: Fix cupsd activated on-demand via socket
Browse files Browse the repository at this point in the history
If only the expected cups.sock is set as listener in cupsd.conf, the
array Listeners was NULL. To prevent copying the code, do the array
allocation earlier and have only one check for Listeners, in
service_checkin() which is run every time cupsd starts.

Fixes #985
  • Loading branch information
zdohnal committed Jun 18, 2024
1 parent 56b9728 commit 74f437b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 38 deletions.
49 changes: 12 additions & 37 deletions scheduler/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,18 @@ cupsdReadConfiguration(void)

cupsdDeleteAllListeners();

/*
* Allocate array Listeners
*/

Listeners = cupsArrayNew(NULL, NULL);

if (!Listeners)
{
fprintf(stderr, "Unable to allocate memory for array Listeners.");
return (0);
}

old_remote_port = RemotePort;
RemotePort = 0;

Expand Down Expand Up @@ -1043,32 +1055,6 @@ cupsdReadConfiguration(void)
}
}

/*
* Check that we have at least one listen/port line; if not, report this
* as an error and exit!
*/

#ifdef HAVE_ONDEMAND
if (cupsArrayCount(Listeners) == 0 && !OnDemand)
#else
if (cupsArrayCount(Listeners) == 0)
#endif // HAVE_ONDEMAND
{
/*
* No listeners!
*/

cupsdLogMessage(CUPSD_LOG_EMERG,
"No valid Listen or Port lines were found in the "
"configuration file.");

/*
* Commit suicide...
*/

cupsdEndProcess(getpid(), 0);
}

/*
* Set the default locale using the language and charset...
*/
Expand Down Expand Up @@ -3224,17 +3210,6 @@ read_cupsd_conf(cups_file_t *fp) /* I - File to read from */
* Allocate another listener...
*/

if (!Listeners)
Listeners = cupsArrayNew(NULL, NULL);

if (!Listeners)
{
cupsdLogMessage(CUPSD_LOG_ERROR,
"Unable to allocate %s at line %d - %s.",
line, linenum, strerror(errno));
break;
}

if ((lis = calloc(1, sizeof(cupsd_listener_t))) == NULL)
{
cupsdLogMessage(CUPSD_LOG_ERROR,
Expand Down
2 changes: 1 addition & 1 deletion scheduler/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1977,7 +1977,7 @@ service_checkin(void)
* No listeners!
*/

cupsdLogMessage(CUPSD_LOG_EMERG, "service_checkin: No listener sockets present.");
cupsdLogMessage(CUPSD_LOG_EMERG, "No listener sockets present.");

/*
* Commit suicide...
Expand Down

0 comments on commit 74f437b

Please sign in to comment.