socsvn commit: r290020 - in soc2015/roam: ayiya_listen ayiya_resp

roam at FreeBSD.org roam at FreeBSD.org
Fri Aug 21 15:43:37 UTC 2015


Author: roam
Date: Fri Aug 21 15:43:35 2015
New Revision: 290020
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=290020

Log:
  ayiya_listen, ayiya_resp: use C99's bool.
  
  ObQuote:	"You say 'yes', I say 'no'"

Modified:
  soc2015/roam/ayiya_listen/main.c
  soc2015/roam/ayiya_resp/main.c

Modified: soc2015/roam/ayiya_listen/main.c
==============================================================================
--- soc2015/roam/ayiya_listen/main.c	Fri Aug 21 15:43:31 2015	(r290019)
+++ soc2015/roam/ayiya_listen/main.c	Fri Aug 21 15:43:35 2015	(r290020)
@@ -42,6 +42,7 @@
 #include <sha.h>
 #include <signal.h>
 #include <stdarg.h>
+#include <stdbool.h>
 #include <stdio.h>
 #include <stdint.h>
 #include <stdlib.h>
@@ -80,7 +81,7 @@
 
 static int		verbose;
 
-static void		usage(int _ferr);
+static void		usage(bool _ferr);
 static void		version(void);
 static void		debug(const char *fmt, ...) __printflike(1, 2);
 
@@ -89,7 +90,7 @@
 static void		accept_connection(int);
 static void		handle_tunnel(struct tunnel *, const char *,
 			const struct sockaddr_in *, const char *, size_t);
-static void		stop_tunnel(struct tunnel *, int);
+static void		stop_tunnel(struct tunnel *, bool);
 static void		start_tunnel(struct tunnel *,
 			const struct sockaddr_in *, const char *);
 static void		check_wait_result(pid_t res, int stat, pid_t expected,
@@ -106,10 +107,11 @@
 int
 main(int argc, char * const argv[])
 {
-	int ch, hflag, Vflag;
+	int ch;
+	bool hflag, Vflag;
 	const char *addr, *tunnelsfile;
 
-	hflag = Vflag = 0;
+	hflag = Vflag = false;
 	addr = tunnelsfile = NULL;
 	while (ch = getopt(argc, argv, "a:hr:t:Vv"), ch != -1)
 		switch (ch) {
@@ -120,7 +122,7 @@
 				break;
 
 			case 'h':
-				hflag = 1;
+				hflag = true;
 				break;
 
 			case 'r':
@@ -132,7 +134,7 @@
 				break;
 
 			case 'V':
-				Vflag = 1;
+				Vflag = true;
 				break;
 
 			case 'v':
@@ -140,29 +142,29 @@
 				break;
 
 			default:
-				usage(1);
+				usage(true);
 				/* NOTREACHED */
 		}
 	if (Vflag)
 		version();
 	if (hflag)
-		usage(0);
+		usage(true);
 	if (Vflag || hflag)
 		return (0);
 
 	if (addr == NULL) {
 		warnx("No address (-a) specified");
-		usage(1);
+		usage(true);
 	} else if (tunnelsfile == NULL) {
 		warnx("No tunnels file (-t) specified");
-		usage(1);
+		usage(true);
 	}
 
 	argc -= optind;
 	argv += optind;
 	if (argc > 0) {
 		warnx("No positional arguments expected");
-		usage(1);
+		usage(true);
 	}
 
 	if (resppath == NULL) {
@@ -243,7 +245,7 @@
 }
 
 void
-usage(const int _ferr)
+usage(const bool _ferr)
 {
 	const char * const s =
 	    "Usage:\tayiya_listen [-v] -a address -r resppath -t tunnelsfile config\n"
@@ -362,7 +364,7 @@
 					if (t->pid == pid) {
 						check_wait_result(pid, stat,
 						    t->pid, "AYIYA responder");
-						stop_tunnel(t, 1);
+						stop_tunnel(t, true);
 						break;
 					}
 				}
@@ -410,7 +412,7 @@
 {
 	/* Do we need to kill a tunnel first? */
 	if (strcmp(t->remote_outer, sender) != 0) {
-		stop_tunnel(t, 0);
+		stop_tunnel(t, false);
 		snprintf(t->remote_outer, sizeof(t->remote_outer), "%s", sender);
 	}
 
@@ -451,7 +453,7 @@
 }
 
 void
-stop_tunnel(struct tunnel * const t, const int waited)
+stop_tunnel(struct tunnel * const t, const bool waited)
 {
 	if (t->pid != 0) {
 		close(t->comm[1]);
@@ -750,7 +752,7 @@
 
 	char *line = NULL;
 	size_t cap = 0;
-	int in = 0;
+	bool in = false;
 	struct tunnel *t = tunnels;
 	debug("Parsing the tunnels file %s\n", fname);
 	unsigned flags;
@@ -798,7 +800,7 @@
 			debug("- parsing tunnel %s\n", line);
 
 			flags = 0;
-			in = 1;
+			in = true;
 			continue;
 		} else if (rerr != REG_NOMATCH) {
 			report_regerror(rerr, &re_tunnel);

Modified: soc2015/roam/ayiya_resp/main.c
==============================================================================
--- soc2015/roam/ayiya_resp/main.c	Fri Aug 21 15:43:31 2015	(r290019)
+++ soc2015/roam/ayiya_resp/main.c	Fri Aug 21 15:43:35 2015	(r290020)
@@ -67,10 +67,10 @@
 static int		inputfd = -1;
 static STAILQ_HEAD(ayqhead, ayqueue)	injectq;
 
-static int		quiet;
-static int		verbose;
+static bool		quiet;
+static bool		verbose;
 
-static void		usage(int _ferr);
+static void		usage(bool _ferr);
 static void		version(void);
 static void		debug(const char *fmt, ...) __printflike(1, 2);
 
@@ -107,13 +107,14 @@
 int
 main(int argc, char * const argv[])
 {
-	int ch, hflag, Vflag;
+	int ch;
+	bool hflag, Vflag;
 
-	hflag = Vflag = 0;
+	hflag = Vflag = false;
 	while (ch = getopt(argc, argv, "hi:n:qVv"), ch != -1)
 		switch (ch) {
 			case 'h':
-				hflag = 1;
+				hflag = true;
 				break;
 
 			case 'i':
@@ -137,25 +138,25 @@
 				break;
 
 			case 'q':
-				quiet = 1;
+				quiet = true;
 				break;
 
 			case 'V':
-				Vflag = 1;
+				Vflag = true;
 				break;
 
 			case 'v':
-				verbose++;
+				verbose = true;
 				break;
 
 			default:
-				usage(1);
+				usage(true);
 				/* NOTREACHED */
 		}
 	if (Vflag)
 		version();
 	if (hflag)
-		usage(0);
+		usage(false);
 	if (Vflag || hflag)
 		return (0);
 
@@ -163,7 +164,7 @@
 	argv += optind;
 	if (argc < 1) {
 		warnx("No command specified");
-		usage(1);
+		usage(true);
 	}
 	const size_t len = strlen(argv[0]);
 	unsigned idx = COMMANDS;
@@ -174,20 +175,20 @@
 		} else if (strncmp(argv[0], commands[i].name, len) == 0) {
 			if (idx != COMMANDS) {
 				warnx("Ambiguous command '%s'", argv[0]);
-				usage(1);
+				usage(true);
 			}
 			idx = i;
 		}
 	}
 	if (idx == COMMANDS) {
 		warnx("Unrecognized command '%s'", argv[0]);
-		usage(1);
+		usage(true);
 	}
 	return (commands[idx].func)(argv[0], argv + 1, argc - 1);
 }
 
 void
-usage(const int _ferr)
+usage(const bool _ferr)
 {
 	const char * const s =
 	    "Usage:\tayiya_resp [-v] config\n"


More information about the svn-soc-all mailing list