"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Omar Polo <op@omarpolo.com>
Subject:
gotd: group the fags for subprocesses under -T
To:
gameoftrees@openbsd.org
Date:
Tue, 03 Sep 2024 23:24:42 +0200

Download raw body.

Thread
In the near future I'd like to reuse -s for other purposes, so instead
of figuring out another letter, let's just group the flag for the
re-exec under -T(ype).

bonus diff at the end: less casting for start_child().

no functional changes intended.  ok for both?

-----------------------------------------------
commit 4fa1a3afe620b612057530da57177bdf48161673
from: Omar Polo <op@omarpolo.com>
date: Tue Sep  3 20:00:47 2024 UTC
 
 group flags for select the subprocess under -T
 
diff eed4085c0f4916f79731c3fc1a8adeb149b59a69 4fa1a3afe620b612057530da57177bdf48161673
commit - eed4085c0f4916f79731c3fc1a8adeb149b59a69
commit + 4fa1a3afe620b612057530da57177bdf48161673
blob - 4d75296b687289f7e3ab2a674a5ad53b3b7c8601
blob + 8cf2899a3f3de4adefcc99801b1325960c4f090f
--- gotd/gotd.c
+++ gotd/gotd.c
@@ -1657,25 +1657,25 @@ start_child(enum gotd_procid proc_id, const char *repo
 	argv[argc++] = argv0;
 	switch (proc_id) {
 	case PROC_LISTEN:
-		argv[argc++] = (char *)"-L";
+		argv[argc++] = (char *)"-TL";
 		break;
 	case PROC_AUTH:
-		argv[argc++] = (char *)"-A";
+		argv[argc++] = (char *)"-TA";
 		break;
 	case PROC_SESSION_READ:
-		argv[argc++] = (char *)"-s";
+		argv[argc++] = (char *)"-Ts";
 		break;
 	case PROC_SESSION_WRITE:
-		argv[argc++] = (char *)"-S";
+		argv[argc++] = (char *)"-TS";
 		break;
 	case PROC_REPO_READ:
-		argv[argc++] = (char *)"-R";
+		argv[argc++] = (char *)"-TR";
 		break;
 	case PROC_REPO_WRITE:
-		argv[argc++] = (char *)"-W";
+		argv[argc++] = (char *)"-TW";
 		break;
 	case PROC_NOTIFY:
-		argv[argc++] = (char *)"-N";
+		argv[argc++] = (char *)"-TN";
 		break;
 	default:
 		fatalx("invalid process id %d", proc_id);
@@ -2023,47 +2023,53 @@ main(int argc, char **argv)
 
 	log_init(1, LOG_DAEMON); /* Log to stderr until daemonized. */
 
-	while ((ch = getopt(argc, argv, "Adf:LnNP:RsSvW")) != -1) {
+	while ((ch = getopt(argc, argv, "df:nP:T:v")) != -1) {
 		switch (ch) {
-		case 'A':
-			proc_id = PROC_AUTH;
-			break;
 		case 'd':
 			daemonize = 0;
 			break;
 		case 'f':
 			confpath = optarg;
 			break;
-		case 'L':
-			proc_id = PROC_LISTEN;
-			break;
 		case 'n':
 			noaction = 1;
 			break;
-		case 'N':
-			proc_id = PROC_NOTIFY;
-			break;
 		case 'P':
 			repo_path = realpath(optarg, NULL);
 			if (repo_path == NULL)
 				fatal("realpath '%s'", optarg);
 			break;
-		case 'R':
-			proc_id = PROC_REPO_READ;
+		case 'T':
+			switch (*optarg) {
+			case 'A':
+				proc_id = PROC_AUTH;
+				break;
+			case 'L':
+				proc_id = PROC_LISTEN;
+				break;
+			case 'N':
+				proc_id = PROC_NOTIFY;
+				break;
+			case 'R':
+				proc_id = PROC_REPO_READ;
+				break;
+			case 's':
+				proc_id = PROC_SESSION_READ;
+				break;
+			case 'S':
+				proc_id = PROC_SESSION_WRITE;
+				break;
+			case 'W':
+				proc_id = PROC_REPO_WRITE;
+				break;
+			default:
+				errx(1, "unknown proc type %s", optarg);
+			}
 			break;
-		case 's':
-			proc_id = PROC_SESSION_READ;
-			break;
-		case 'S':
-			proc_id = PROC_SESSION_WRITE;
-			break;
 		case 'v':
 			if (verbosity < 3)
 				verbosity++;
 			break;
-		case 'W':
-			proc_id = PROC_REPO_WRITE;
-			break;
 		default:
 			usage();
 		}

-----------------------------------------------
commit a6dbb351e01de5f7a44e2d091d5546d98d4da351 (main)
from: Omar Polo <op@omarpolo.com>
date: Tue Sep  3 20:04:51 2024 UTC
 
 changing the strategy for casts
 
diff 4fa1a3afe620b612057530da57177bdf48161673 a6dbb351e01de5f7a44e2d091d5546d98d4da351
commit - 4fa1a3afe620b612057530da57177bdf48161673
commit + a6dbb351e01de5f7a44e2d091d5546d98d4da351
blob - 8cf2899a3f3de4adefcc99801b1325960c4f090f
blob + 5830c85ab86441288df899ce965b061f45d21f62
--- gotd/gotd.c
+++ gotd/gotd.c
@@ -1634,9 +1634,9 @@ static pid_t
 start_child(enum gotd_procid proc_id, const char *repo_path,
     char *argv0, const char *confpath, int fd, int daemonize, int verbosity)
 {
-	char	*argv[11];
-	int	 argc = 0;
-	pid_t	 pid;
+	const char	*argv[11];
+	int		 argc = 0;
+	pid_t		 pid;
 
 	switch (pid = fork()) {
 	case -1:
@@ -1657,47 +1657,47 @@ start_child(enum gotd_procid proc_id, const char *repo
 	argv[argc++] = argv0;
 	switch (proc_id) {
 	case PROC_LISTEN:
-		argv[argc++] = (char *)"-TL";
+		argv[argc++] = "-TL";
 		break;
 	case PROC_AUTH:
-		argv[argc++] = (char *)"-TA";
+		argv[argc++] = "-TA";
 		break;
 	case PROC_SESSION_READ:
-		argv[argc++] = (char *)"-Ts";
+		argv[argc++] = "-Ts";
 		break;
 	case PROC_SESSION_WRITE:
-		argv[argc++] = (char *)"-TS";
+		argv[argc++] = "-TS";
 		break;
 	case PROC_REPO_READ:
-		argv[argc++] = (char *)"-TR";
+		argv[argc++] = "-TR";
 		break;
 	case PROC_REPO_WRITE:
-		argv[argc++] = (char *)"-TW";
+		argv[argc++] = "-TW";
 		break;
 	case PROC_NOTIFY:
-		argv[argc++] = (char *)"-TN";
+		argv[argc++] = "-TN";
 		break;
 	default:
 		fatalx("invalid process id %d", proc_id);
 	}
 
-	argv[argc++] = (char *)"-f";
-	argv[argc++] = (char *)confpath;
+	argv[argc++] = "-f";
+	argv[argc++] = confpath;
 
 	if (repo_path) {
-		argv[argc++] = (char *)"-P";
-		argv[argc++] = (char *)repo_path;
+		argv[argc++] = "-P";
+		argv[argc++] = repo_path;
 	}
 
 	if (!daemonize)
-		argv[argc++] = (char *)"-d";
+		argv[argc++] = "-d";
 	if (verbosity > 0)
-		argv[argc++] = (char *)"-v";
+		argv[argc++] = "-v";
 	if (verbosity > 1)
-		argv[argc++] = (char *)"-v";
+		argv[argc++] = "-v";
 	argv[argc++] = NULL;
 
-	execvp(argv0, argv);
+	execvp(argv0, (char * const *)argv);
 	fatal("execvp");
 }