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
This commit is contained in:
Dag-Erling Smørgrav
2026-02-26 07:15:14 +01:00
parent 9065be0a59
commit 56fbfd1ecd
2 changed files with 27 additions and 13 deletions
+7 -1
View File
@@ -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
+20 -12
View File
@@ -61,28 +61,28 @@
*/
#include <sys/param.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <sys/socket.h>
#include <sys/stat.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