From 49b79fa02d93a507df6caf93d3f4545ab057bea5 Mon Sep 17 00:00:00 2001
From: Matt Johnston <matt@ucc.asn.au>
Date: Mon, 9 Apr 2012 20:35:13 +0800
Subject: [PATCH] Rename HAVE_FORK to USE_VFORK

It makes it a bit more obvious why there's a test there since HAVE_FORK
is the normal case.
---
 dbutil.c          |  2 +-
 scp.c             | 14 +++++++-------
 session.h         |  2 +-
 svr-chansession.c |  8 ++++----
 svr-session.c     |  8 +++-----
 sysoptions.h      |  8 +++++++-
 6 files changed, 23 insertions(+), 19 deletions(-)

diff --git a/dbutil.c b/dbutil.c
index 97d72779..044388ae 100644
--- a/dbutil.c
+++ b/dbutil.c
@@ -443,7 +443,7 @@ int spawn_command(void(*exec_fn)(void *user_data), void *exec_data,
 		return DROPBEAR_FAILURE;
 	}
 
-#ifndef HAVE_FORK
+#ifdef USE_VFORK
 	pid = vfork();
 #else
 	pid = fork();
diff --git a/scp.c b/scp.c
index 6911ca29..529498e4 100644
--- a/scp.c
+++ b/scp.c
@@ -130,7 +130,7 @@ do_local_cmd(arglist *a)
 			fprintf(stderr, " %s", a->list[i]);
 		fprintf(stderr, "\n");
 	}
-#ifndef HAVE_FORK
+#ifdef USE_VFORK
 	pid = vfork();
 #else
 	pid = fork();
@@ -141,7 +141,7 @@ do_local_cmd(arglist *a)
 	if (pid == 0) {
 		execvp(a->list[0], a->list);
 		perror(a->list[0]);
-#ifndef HAVE_FORK
+#ifdef USE_VFORK
 		_exit(1);
 #else
 		exit(1);
@@ -210,12 +210,12 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
 
 	/* uClinux needs to build the args here before vforking,
 	   otherwise we do it later on. */
-#ifndef HAVE_FORK
+#ifdef USE_VFORK
 	arg_setup(host, remuser, cmd);
 #endif
 
 	/* Fork a child to execute the command on the remote host using ssh. */
-#ifndef HAVE_FORK
+#ifdef USE_VFORK
 	do_cmd_pid = vfork();
 #else
 	do_cmd_pid = fork();
@@ -230,13 +230,13 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
 		close(pin[0]);
 		close(pout[1]);
 
-#ifndef HAVE_FORK
+#ifdef USE_VFORK
 		arg_setup(host, remuser, cmd);
 #endif
 
 		execvp(ssh_program, args.list);
 		perror(ssh_program);
-#ifndef HAVE_FORK
+#ifdef USE_VFORK
 		_exit(1);
 #else
 		exit(1);
@@ -245,7 +245,7 @@ do_cmd(char *host, char *remuser, char *cmd, int *fdin, int *fdout, int argc)
 		fatal("fork: %s", strerror(errno));
 	}
 
-#ifndef HAVE_FORK
+#ifdef USE_VFORK
 	/* clean up command */
 	/* pop cmd */
 	xfree(args.list[args.num-1]);
diff --git a/session.h b/session.h
index ea59bca1..941dcb9a 100644
--- a/session.h
+++ b/session.h
@@ -218,7 +218,7 @@ struct serversession {
 	/* The resolved remote address, used for lastlog etc */
 	char *remotehost;
 
-#ifndef HAVE_FORK
+#ifdef USE_VFORK
 	pid_t server_pid;
 #endif
 
diff --git a/svr-chansession.c b/svr-chansession.c
index 198dbe6e..f31d9f0c 100644
--- a/svr-chansession.c
+++ b/svr-chansession.c
@@ -658,7 +658,7 @@ static int sessioncommand(struct Channel *channel, struct ChanSess *chansess,
 
 	/* uClinux will vfork(), so there'll be a race as 
 	connection_string is freed below. */
-#ifdef HAVE_FORK
+#ifndef USE_VFORK
 	chansess->connection_string = make_connection_string();
 #endif
 
@@ -670,7 +670,7 @@ static int sessioncommand(struct Channel *channel, struct ChanSess *chansess,
 		ret = ptycommand(channel, chansess);
 	}
 
-#ifdef HAVE_FORK	
+#ifndef USE_VFORK
 	m_free(chansess->connection_string);
 #endif
 
@@ -745,7 +745,7 @@ static int ptycommand(struct Channel *channel, struct ChanSess *chansess) {
 		return DROPBEAR_FAILURE;
 	}
 	
-#ifndef HAVE_FORK
+#ifdef USE_VFORK
 	pid = vfork();
 #else
 	pid = fork();
@@ -865,7 +865,7 @@ static void execchild(void *user_data) {
 
 	/* with uClinux we'll have vfork()ed, so don't want to overwrite the
 	 * hostkey. can't think of a workaround to clear it */
-#ifdef HAVE_FORK
+#ifndef USE_VFORK
 	/* wipe the hostkey */
 	sign_key_free(svr_opts.hostkey);
 	svr_opts.hostkey = NULL;
diff --git a/svr-session.c b/svr-session.c
index 7703a8fc..ac73dab8 100644
--- a/svr-session.c
+++ b/svr-session.c
@@ -84,7 +84,7 @@ void svr_session(int sock, int childpipe) {
 
 	/* Initialise server specific parts of the session */
 	svr_ses.childpipe = childpipe;
-#ifndef HAVE_FORK
+#ifdef USE_VFORK
 	svr_ses.server_pid = getpid();
 #endif
 	svr_authinitialise();
@@ -157,12 +157,10 @@ void svr_dropbear_exit(int exitcode, const char* format, va_list param) {
 
 	_dropbear_log(LOG_INFO, fmtbuf, param);
 
-#ifndef HAVE_FORK
-	/* only the main server process should cleanup - we don't want
+#ifdef USE_VFORK
+	/* For uclinux only the main server process should cleanup - we don't want
 	 * forked children doing that */
 	if (svr_ses.server_pid == getpid())
-#else
-	if (1)
 #endif
 	{
 		/* free potential public key options */
diff --git a/sysoptions.h b/sysoptions.h
index 283229e9..ee5ff367 100644
--- a/sysoptions.h
+++ b/sysoptions.h
@@ -216,4 +216,10 @@
 #define IS_DROPBEAR_SERVER 0
 #define IS_DROPBEAR_CLIENT 0
 
-#endif
+#endif /* neither DROPBEAR_SERVER nor DROPBEAR_CLIENT */
+
+#ifndef HAVE_FORK
+#define USE_VFORK
+#endif  /* don't HAVE_FORK */
+
+/* no include guard for this file */
-- 
GitLab