PidFile switch

Swen Schillig swen at vnet.ibm.com
Mon Apr 10 16:25:27 WST 2006


Hi all

I want to use the dropbear package in a project
but I'm missing a functionality which allows me to 
provide the pidfile name on the cmd-line.

I've created a diff which would provide this functionality
and I'd like to get some feedback on this patch.
Especially if it's going to be part of the next code-drop.

I've posted this diff already to Matt but unfortunately haven't received any feedback so far.

Anywy, here it is and let me know what you think !

Only in dropbear-0.48.1-dev: Makefile
Only in dropbear-0.48.1-dev: config.h
Only in dropbear-0.48.1-dev: config.log
Only in dropbear-0.48.1-dev: config.status
Only in dropbear-0.48.1-dev/libtomcrypt: Makefile
Only in dropbear-0.48.1-dev/libtommath: Makefile
diff -aur dropbear-0.48.1/runopts.h dropbear-0.48.1-dev/runopts.h
--- dropbear-0.48.1/runopts.h	2006-03-12 05:52:51.000000000 +0100
+++ dropbear-0.48.1-dev/runopts.h	2006-03-21 19:27:05.000000000 +0100
@@ -83,6 +83,7 @@
 
 	sign_key *hostkey;
 	buffer * banner;
+	char * pidfile;
 
 } svr_runopts;
 
diff -aur dropbear-0.48.1/svr-main.c dropbear-0.48.1-dev/svr-main.c
--- dropbear-0.48.1/svr-main.c	2006-03-12 05:52:52.000000000 +0100
+++ dropbear-0.48.1-dev/svr-main.c	2006-03-21 19:44:37.000000000 +0100
@@ -145,7 +145,7 @@
 	}
 
 	/* create a PID file so that we can be killed easily */
-	pidfile = fopen(DROPBEAR_PIDFILE, "w");
+	pidfile = fopen(svr_opts.pidfile, "w");
 	if (pidfile) {
 		fprintf(pidfile, "%d\n", getpid());
 		fclose(pidfile);
@@ -188,7 +188,7 @@
 		val = select(maxsock+1, &fds, NULL, NULL, &seltimeout);
 
 		if (exitflag) {
-			unlink(DROPBEAR_PIDFILE);
+			unlink(svr_opts.pidfile);
 			dropbear_exit("Terminated by signal");
 		}
 		
diff -aur dropbear-0.48.1/svr-runopts.c dropbear-0.48.1-dev/svr-runopts.c
--- dropbear-0.48.1/svr-runopts.c	2006-03-12 05:52:52.000000000 +0100
+++ dropbear-0.48.1-dev/svr-runopts.c	2006-03-21 19:40:09.000000000 +0100
@@ -72,6 +72,8 @@
 #endif
 					"-p port		Listen on specified tcp port, up to %d can be specified\n"
 					"		(default %s if none specified)\n"
+					"-P PidFile	Create pid file PidFile\n"
+					"		(default %s)\n"
 #ifdef INETD_MODE
 					"-i		Start for inetd\n"
 #endif
@@ -85,7 +87,7 @@
 #ifdef DROPBEAR_RSA
 					RSA_PRIV_FILENAME,
 #endif
-					DROPBEAR_MAX_PORTS, DROPBEAR_DEFPORT);
+					DROPBEAR_MAX_PORTS, DROPBEAR_DEFPORT, DROPBEAR_PIDFILE);
 }
 
 void svr_getopts(int argc, char ** argv) {
@@ -105,6 +107,7 @@
 	svr_opts.inetdmode = 0;
 	svr_opts.portcount = 0;
 	svr_opts.hostkey = NULL;
+	svr_opts.pidfile = DROPBEAR_PIDFILE;
 #ifdef ENABLE_SVR_LOCALTCPFWD
 	svr_opts.nolocaltcp = 0;
 #endif
@@ -185,6 +188,9 @@
 						svr_opts.portcount++;
 					}
 					break;
+				case 'P':
+					next = &svr_opts.pidfile;
+					break;
 #ifdef DO_MOTD
 				/* motd is displayed by default, -m turns it off */
 				case 'm':



More information about the Dropbear mailing list