NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

bin/53221: add a -f option to ftpd, equivalent to -f in httpd



>Number:         53221
>Category:       bin
>Synopsis:       add a -f option to ftpd, equivalent to -f in httpd
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    bin-bug-people
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Sat Apr 28 13:25:00 +0000 2018
>Originator:     Nia Alarie
>Release:        current
>Organization:
>Environment:
>Description:
ftpd runs as a libexec program by default, for use with servers such as inetd.

-D causes ftpd to run as a server and listen for incoming connections, and
detach from the controlling terminal.

This adds an option (-f) allowing ftpd to run as a server without detaching
from the terminal. For my specific use-case, this allows it to be controlled
by sysutils/daemontools.

This option is equivalent to the -f option in httpd.
>How-To-Repeat:

>Fix:
Index: ftpd.8
===================================================================
RCS file: /cvsroot/src/libexec/ftpd/ftpd.8,v
retrieving revision 1.86
diff -u -r1.86 ftpd.8
--- ftpd.8	3 Jul 2017 21:35:48 -0000	1.86
+++ ftpd.8	28 Apr 2018 12:48:33 -0000
@@ -65,7 +65,7 @@
 Internet File Transfer Protocol server
 .Sh SYNOPSIS
 .Nm
-.Op Fl 46DdHlnQqrsUuWwX
+.Op Fl 46DdfHlnQqrsUuWwX
 .Op Fl a Ar anondir
 .Op Fl C Ar user Ns Op @ Ns Ar host
 .Op Fl c Ar confdir
@@ -154,6 +154,10 @@
 .Dq "\&%E"
 escape sequence (see
 .Sx Display file escape sequences )
+.It Fl f
+Stops the
+.Fl D
+flag from detaching from the tty and going into the background.
 .It Fl H
 Equivalent to
 .Do
Index: ftpd.c
===================================================================
RCS file: /cvsroot/src/libexec/ftpd/ftpd.c,v
retrieving revision 1.203
diff -u -r1.203 ftpd.c
--- ftpd.c	19 Jul 2016 21:25:38 -0000	1.203
+++ ftpd.c	28 Apr 2018 12:48:34 -0000
@@ -177,6 +177,7 @@
 
 int	data;
 int	Dflag;
+int	fflag;
 int	sflag;
 int	stru;			/* avoid C keyword */
 int	mode;
@@ -298,6 +299,7 @@
 	logging = 0;
 	pdata = -1;
 	Dflag = 0;
+	fflag = 0;
 	sflag = 0;
 	dataport = 0;
 	dopidfile = 1;		/* default: DO use a pid file to count users */
@@ -323,7 +325,7 @@
 	openlog("ftpd", LOG_PID | LOG_NDELAY, LOG_FTP);
 
 	while ((ch = getopt(argc, argv,
-	    "46a:c:C:Dde:h:HlL:nP:qQrst:T:uUvV:wWX")) != -1) {
+	    "46a:c:C:Dde:fh:HlL:nP:qQrst:T:uUvV:wWX")) != -1) {
 		switch (ch) {
 		case '4':
 			af = AF_INET;
@@ -377,6 +379,10 @@
 			emailaddr = optarg;
 			break;
 
+		case 'f':
+			fflag = 1;
+			break;
+
 		case 'h':
 			strlcpy(hostname, optarg, sizeof(hostname));
 			break;
@@ -505,7 +511,7 @@
 		struct pollfd *fds;
 		struct addrinfo hints, *res, *res0;
 
-		if (daemon(1, 0) == -1) {
+		if (!fflag && daemon(1, 0) == -1) {
 			syslog(LOG_ERR, "failed to daemonize: %m");
 			exit(1);
 		}



Home | Main Index | Thread Index | Old Index