Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add --listen-backlog option in munged #139

Merged
merged 2 commits into from
Mar 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/munged/conf.c
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@
#define OPT_SEED_FILE 268
#define OPT_TRUSTED_GROUP 269
#define OPT_ORIGIN 270
#define OPT_LAST 271
#define OPT_LISTEN_BACKLOG 271
#define OPT_LAST 272

const char * const short_opts = ":hLVfFMsS:v";

Expand All @@ -102,6 +103,7 @@ struct option long_opts[] = {
{ "group-check-mtime", required_argument, NULL, OPT_GROUP_CHECK },
{ "group-update-time", required_argument, NULL, OPT_GROUP_UPDATE },
{ "key-file", required_argument, NULL, OPT_KEY_FILE },
{ "listen-backlog", required_argument, NULL, OPT_LISTEN_BACKLOG},
{ "log-file", required_argument, NULL, OPT_LOG_FILE },
{ "max-ttl", required_argument, NULL, OPT_MAX_TTL },
{ "num-threads", required_argument, NULL, OPT_NUM_THREADS },
Expand Down Expand Up @@ -178,6 +180,7 @@ create_conf (void)
conf->config_name = NULL;
conf->lockfile_fd = -1;
conf->lockfile_name = NULL;
conf->listen_backlog = MUNGE_SOCKET_BACKLOG;

_conf_set_cwd (conf);

Expand Down Expand Up @@ -407,6 +410,25 @@ parse_cmdline (conf_t conf, int argc, char **argv)
_conf_set_string (&conf->key_name, optarg, conf->cwd,
"key-file name");
break;
case OPT_LISTEN_BACKLOG:
errno = 0;
l = strtol (optarg, &p, 10);
if (((errno == ERANGE) && ((l == LONG_MIN) || (l == LONG_MAX)))
|| (optarg == p) || (*p != '\0')
|| (l < -1) || (l > INT_MAX)) {
log_err (EMUNGE_SNAFU, LOG_ERR,
"Invalid value \"%s\" for listen-backlog", optarg);
}
else if (l == 0) {
conf->listen_backlog = MUNGE_SOCKET_BACKLOG;
}
else if (l == -1) {
conf->listen_backlog = SOMAXCONN;
}
else {
conf->listen_backlog = l;
}
break;
case OPT_LOG_FILE:
_conf_set_string (&conf->logfile_name, optarg, conf->cwd,
"log-file name");
Expand Down Expand Up @@ -751,6 +773,9 @@ _conf_display_help (char *prog)
printf (" %*s %s [%s]\n", w, "--key-file=PATH",
"Specify key file", MUNGE_KEYFILE_PATH);

printf (" %*s %s [%d]\n", w, "--listen-backlog=INT",
"Specify listen backlog limit of socket", MUNGE_SOCKET_BACKLOG);

printf (" %*s %s [%s]\n", w, "--log-file=PATH",
"Specify log file", MUNGE_LOGFILE_PATH);

Expand Down
1 change: 1 addition & 0 deletions src/munged/conf.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ struct conf {
char *logfile_name; /* daemon logfile name */
char *pidfile_name; /* daemon pidfile name */
char *socket_name; /* unix domain socket filename */
int listen_backlog; /* unix domain socket listen backlog */
char *seed_name; /* random seed filename */
char *key_name; /* symmetric key filename */
unsigned char *dek_key; /* subkey for cipher ops */
Expand Down
6 changes: 6 additions & 0 deletions src/munged/munged.8.in
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,12 @@ triggered by a \fBSIGHUP\fR). A value of \-1 causes it to be disabled.
.BI "\-\-key\-file " path
Specify an alternate pathname to the key file.
.TP
.BI "\-\-listen\-backlog " integer
Specify the socket's listen backlog limit; note that the kernel may impose
a lower limit. A value of 0 uses the software default. A value of \-1
specifies \fBSOMAXCONN\fR, the maximum listen backlog queue length defined
in \fI<sys/socket.h>\fR.
.TP
.BI "\-\-log\-file " path
Specify an alternate pathname to the log file.
.TP
Expand Down
4 changes: 3 additions & 1 deletion src/munged/munged.c
Original file line number Diff line number Diff line change
Expand Up @@ -670,12 +670,14 @@ sock_create (conf_t conf)
log_errno (EMUNGE_SNAFU, LOG_ERR,
"Failed to bind socket \"%s\"", conf->socket_name);
}
if (listen (sd, MUNGE_SOCKET_BACKLOG) < 0) {
if (listen (sd, conf->listen_backlog) < 0) {
log_errno (EMUNGE_SNAFU, LOG_ERR,
"Failed to listen on socket \"%s\"", conf->socket_name);
}
conf->ld = sd;
log_msg (LOG_INFO, "Created socket \"%s\"", conf->socket_name);
log_msg (LOG_INFO, "Set socket listen backlog to %d",
conf->listen_backlog);
return;
}

Expand Down