The branch stable/13 has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=ba5f7719f63ea1bde229ff0ff6204cf91516c8ce
commit ba5f7719f63ea1bde229ff0ff6204cf91516c8ce Author: Dag-Erling Smørgrav <[email protected]> AuthorDate: 2026-02-26 06:15:14 +0000 Commit: Dag-Erling Smørgrav <[email protected]> CommitDate: 2026-03-04 14:46:06 +0000 lpd: Add timeout option Set a 120-second receive timeout on all client connections, and add a command-line option to change that value. MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D55400 (cherry picked from commit 56fbfd1ecdc78fc99b3a2e381c355ce8980de39d) --- usr.sbin/lpr/lpd/lpd.8 | 8 +++++++- usr.sbin/lpr/lpd/lpd.c | 30 +++++++++++++++++++----------- 2 files changed, 26 insertions(+), 12 deletions(-) diff --git a/usr.sbin/lpr/lpd/lpd.8 b/usr.sbin/lpr/lpd/lpd.8 index 048014843b3b..5a78b282a6b1 100644 --- a/usr.sbin/lpr/lpd/lpd.8 +++ b/usr.sbin/lpr/lpd/lpd.8 @@ -27,7 +27,7 @@ .\" .\" @(#)lpd.8 8.3 (Berkeley) 4/19/94 .\" -.Dd April 15, 2021 +.Dd February 19, 2026 .Dt LPD 8 .Os .Sh NAME @@ -36,6 +36,7 @@ .Sh SYNOPSIS .Nm .Op Fl cdlpsFW46 +.Op Fl t Ar timeout .Op Ar port# .Sh DESCRIPTION The @@ -107,6 +108,11 @@ This means that will not accept any connections from any remote hosts, although it will still accept print requests from all local users. +.It Fl t Ar timeout +Set the network receive timeout for client connections to +.Ar timeout +seconds. +The default is 120. .It Fl F By default, .Nm diff --git a/usr.sbin/lpr/lpd/lpd.c b/usr.sbin/lpr/lpd/lpd.c index 19456c9406df..23bcd0f674b4 100644 --- a/usr.sbin/lpr/lpd/lpd.c +++ b/usr.sbin/lpr/lpd/lpd.c @@ -73,28 +73,28 @@ static char sccsid[] = "@(#)lpd.c 8.7 (Berkeley) 5/10/95"; */ #include <sys/param.h> -#include <sys/wait.h> -#include <sys/types.h> +#include <sys/file.h> #include <sys/socket.h> -#include <sys/un.h> #include <sys/stat.h> -#include <sys/file.h> +#include <sys/un.h> +#include <sys/wait.h> + #include <netinet/in.h> #include <arpa/inet.h> -#include <netdb.h> -#include <unistd.h> -#include <syslog.h> -#include <signal.h> +#include <ctype.h> +#include <dirent.h> #include <err.h> #include <errno.h> #include <fcntl.h> -#include <dirent.h> +#include <netdb.h> +#include <signal.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sysexits.h> -#include <ctype.h> +#include <syslog.h> +#include <unistd.h> #include "lp.h" #include "lp.local.h" #include "pathnames.h" @@ -129,6 +129,7 @@ uid_t uid, euid; int main(int argc, char **argv) { + struct timeval tv = { .tv_sec = 120 }; int ch_options, errs, f, funix, *finet, i, lfd, socket_debug; fd_set defreadfds; struct sockaddr_un un, fromunix; @@ -151,7 +152,7 @@ main(int argc, char **argv) errx(EX_NOPERM,"must run as root"); errs = 0; - while ((i = getopt(argc, argv, "cdlpswFW46")) != -1) + while ((i = getopt(argc, argv, "cdlpst:wFW46")) != -1) switch (i) { case 'c': /* log all kinds of connection-errors to syslog */ @@ -171,6 +172,9 @@ main(int argc, char **argv) case 's': /* secure (no inet) */ sflag++; break; + case 't': + tv.tv_sec = atol(optarg); + break; case 'w': /* netbsd uses -w for maxwait */ /* * This will be removed after the release of 4.4, as @@ -398,6 +402,10 @@ main(int argc, char **argv) syslog(LOG_WARNING, "accept: %m"); continue; } + if (tv.tv_sec > 0) { + (void) setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &tv, + sizeof(tv)); + } if (fork() == 0) { /* * Note that printjob() also plays around with
