git: 56fbfd1ecdc7 - main - lpd: Add timeout option
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 26 Feb 2026 06:16:27 UTC
The branch main has been updated by des:
URL: https://cgit.FreeBSD.org/src/commit/?id=56fbfd1ecdc78fc99b3a2e381c355ce8980de39d
commit 56fbfd1ecdc78fc99b3a2e381c355ce8980de39d
Author: Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2026-02-26 06:15:14 +0000
Commit: Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2026-02-26 06:15:14 +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
---
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 9a4e46996811..9d24a450ba0e 100644
--- a/usr.sbin/lpr/lpd/lpd.8
+++ b/usr.sbin/lpr/lpd/lpd.8
@@ -25,7 +25,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.Dd April 15, 2021
+.Dd February 19, 2026
.Dt LPD 8
.Os
.Sh NAME
@@ -34,6 +34,7 @@
.Sh SYNOPSIS
.Nm
.Op Fl cdlpsFW46
+.Op Fl t Ar timeout
.Op Ar port#
.Sh DEPRECATION NOTICE
This facility is scheduled for removal prior to the release of
@@ -108,6 +109,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 089b8fedc2d5..d1dcd0766a77 100644
--- a/usr.sbin/lpr/lpd/lpd.c
+++ b/usr.sbin/lpr/lpd/lpd.c
@@ -61,28 +61,28 @@
*/
#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"
@@ -117,6 +117,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;
@@ -139,7 +140,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 */
@@ -159,6 +160,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
@@ -386,6 +390,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