about summary refs log tree commit diff stats
path: root/src/main.c
diff options
context:
space:
mode:
authorRen Kararou <[email protected]>2025-01-06 17:06:05 -0600
committerRen Kararou <[email protected]>2025-01-06 17:06:05 -0600
commitb9635ce3b4ca30b14128c131bb9fe9be08740d6d (patch)
tree14e3a0d128635b70fd71bedbb6caee074ac7eda4 /src/main.c
parent5605a5ddf3c77232b04c002a82b91e227c0f27da (diff)
downloadnbtpd-b9635ce3b4ca30b14128c131bb9fe9be08740d6d.tar.gz
nbtpd-b9635ce3b4ca30b14128c131bb9fe9be08740d6d.tar.bz2
nbtpd-b9635ce3b4ca30b14128c131bb9fe9be08740d6d.zip
start documentation efforts; cleanup handlers
socket connect in handlers, etc.
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/src/main.c b/src/main.c
index 31d8aec..c36bc9a 100644
--- a/src/main.c
+++ b/src/main.c
@@ -176,7 +176,7 @@ int main(int argc, char **argv) {
 		if (daemon(1, 0)) {
 			syslog(LOG_ERR, "failed to daemonize: %s", strerror(errno));
 			retme = -1;
-			goto nbd_nbtpd_cleanup_main;
+			goto cleanup;
 		} else {
 			syslog(LOG_INFO, "daemonized");
 		}
@@ -185,7 +185,7 @@ int main(int argc, char **argv) {
 	if (setsockopt(s, SOL_SOCKET, SO_RCVTIMEO, &timeout, sizeof(timeout)) < 0) {
 		syslog(LOG_ERR, "unable to set socket timeout: %s", strerror(errno));
 		retme = -1;
-		goto nbd_nbtpd_cleanup_main;
+		goto cleanup;
 	}
 	struct sockaddr_in saddr;
 	saddr.sin_family = AF_INET;
@@ -194,7 +194,7 @@ int main(int argc, char **argv) {
 	if (bind(s, (struct sockaddr*)&saddr, sizeof(saddr)) < 0) {
 		syslog(LOG_ERR, "socket bind failed: %s", strerror(errno));
 		retme = -1;
-		goto nbd_nbtpd_cleanup_main;
+		goto cleanup;
 	}
 	syslog(LOG_INFO, "socket bind success");
 	if (daemonize) {
@@ -207,7 +207,7 @@ int main(int argc, char **argv) {
 				strerror(errno)
 			);
 			retme = -1;
-			goto nbd_nbtpd_cleanup_main;
+			goto cleanup;
 		}
 		struct passwd *u = getpwnam((const char *)&user);
 		if (setuid((*u).pw_uid) == -1) {
@@ -217,14 +217,17 @@ int main(int argc, char **argv) {
 				strerror(errno)
 			);
 			retme = -1;
-			goto nbd_nbtpd_cleanup_main;
+			goto cleanup;
 		}
 	}
+#ifdef __illumos__
+	//TODO: illumos priv.h privdrop
+#endif
 	buf = malloc(1024);
 	if (buf == NULL) {
 		syslog(LOG_CRIT, "unable to allocate memory: %s", strerror(errno));
 		retme = -1;
-		goto nbd_nbtpd_cleanup_main;
+		goto cleanup;
 	}
 	while (!nbtpd_stop) {
 		struct sockaddr_in caddr;
@@ -300,9 +303,10 @@ int main(int argc, char **argv) {
 			free(args);
 		}
 	}
-nbd_nbtpd_cleanup_main:
+cleanup:
 	free(buf);
 	close(s);
 	pthread_exit(NULL);
 	return retme;
 }
+