about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2024-01-23 16:11:53 +0100
committerLeah Neukirchen <leah@vuxu.org>2024-01-23 20:57:39 +0100
commitadc60561cd40bc0d3c19ebc214ab08a6c8986810 (patch)
treeac196fe7f87c2f16dd51002f3424385470930e0d
parent36696956948eea74a83c368cd9679a15edd350f0 (diff)
downloadnitro-adc60561cd40bc0d3c19ebc214ab08a6c8986810.tar.gz
nitro-adc60561cd40bc0d3c19ebc214ab08a6c8986810.tar.xz
nitro-adc60561cd40bc0d3c19ebc214ab08a6c8986810.zip
formatting cleanup
-rw-r--r--nitro.c108
-rw-r--r--nitroctl.c8
2 files changed, 58 insertions, 58 deletions
diff --git a/nitro.c b/nitro.c
index abe9989..752288b 100644
--- a/nitro.c
+++ b/nitro.c
@@ -1,10 +1,10 @@
 #include <sys/ioctl.h>
-#include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/stat.h>
 #include <sys/time.h>
-#include <sys/wait.h>
+#include <sys/types.h>
 #include <sys/un.h>
+#include <sys/wait.h>
 #ifdef __linux__
 #include <sys/mount.h>
 #include <sys/reboot.h>
@@ -22,24 +22,24 @@
 #include <stdlib.h>
 #include <string.h>
 #include <syslog.h>
-#include <time.h>
 #include <termios.h>
+#include <time.h>
 #include <unistd.h>
 
 /* no stdio */
 #ifdef DEBUG
-#define assert(x)							   \
-	do { if(!(x)) { prn(2, "%s:%d: %s: error: assertion failed: %s\n", \
-	    __FILE__, __LINE__, __func__, #x); abort(); } } while(0);
+#define assert(x)                                                           \
+	do { if (!(x)) { prn(2, "%s:%d: %s: error: assertion failed: %s\n", \
+	     __FILE__, __LINE__, __func__, #x); abort(); } } while (0);
 #else
-#define assert(x) do { if(!(x)) abort(); } while(0);
+#define assert(x) do { if (!(x)) abort(); } while (0);
 #endif
 
 extern char **environ;
 char **child_environ;
 char *envbuf[64];
 
-typedef int64_t deadline;		/* milliseconds since boot */
+typedef int64_t deadline;               /* milliseconds since boot */
 
 deadline time_now()
 {
@@ -71,9 +71,9 @@ enum process_events {
 	EVNT_WANT_UP,
 	EVNT_WANT_DOWN,
 	EVNT_WANT_RESTART,
-	EVNT_SETUP,		/* setup script exited */
+	EVNT_SETUP,             /* setup script exited */
 	EVNT_EXITED,
-	EVNT_FINISHED,		/* finish script exited */
+	EVNT_FINISHED,          /* finish script exited */
 	// EVNT_DIED,   health check failed
 };
 
@@ -111,58 +111,58 @@ volatile sig_atomic_t want_reboot;
 static char *
 stecpe(char *dst, const char *end, const char *src, const char *srcend)
 {
-        if (dst >= end)
-                return dst;
-
-        ptrdiff_t l = end - dst - 1;
-        size_t t = 1;
-        if (srcend - src < l) {
-                l = srcend - src;
-                t = 0;
-        }
+	if (dst >= end)
+		return dst;
+
+	ptrdiff_t l = end - dst - 1;
+	size_t t = 1;
+	if (srcend - src < l) {
+		l = srcend - src;
+		t = 0;
+	}
 
-        memcpy(dst, src, l);
-        dst[l] = 0;
+	memcpy(dst, src, l);
+	dst[l] = 0;
 
-        return dst + l + t;
+	return dst + l + t;
 }
 
 static char *
 stecpy(char *dst, char *end, const char *src)
 {
-        if (dst >= end)
-                return dst;
+	if (dst >= end)
+		return dst;
 
-        while (dst < end && (*dst = *src))
-                src++, dst++;
+	while (dst < end && (*dst = *src))
+		src++, dst++;
 
-        if (dst == end)
-                dst[-1] = 0;
+	if (dst == end)
+		dst[-1] = 0;
 
-        return dst;
+	return dst;
 }
 
 static char *
 steprl(char *dst, char *end, long n)
 {
-        if (dst >= end)
-                return end;
+	if (dst >= end)
+		return end;
 
-        char buf[24];
-        char *bufend = buf + sizeof buf;
-        char *s = bufend;
+	char buf[24];
+	char *bufend = buf + sizeof buf;
+	char *s = bufend;
 
-        unsigned long u = n < 0 ? -n : n;
+	unsigned long u = n < 0 ? -n : n;
 
-        do {
-                *--s = '0' + (u % 10);
-                u /= 10;
-        } while (u);
+	do {
+		*--s = '0' + (u % 10);
+		u /= 10;
+	} while (u);
 
-        if (n < 0)
-                *--s = '-';
+	if (n < 0)
+		*--s = '-';
 
-        return stecpe(dst, end, s, bufend);
+	return stecpe(dst, end, s, bufend);
 }
 
 size_t
@@ -336,7 +336,7 @@ proc_launch(int i)
 		write(alivepipefd[1], &status, 1);
 		_exit(status);
 	} else if (child < 0) {
-		abort();	/* XXX handle retry */
+		abort();        /* XXX handle retry */
 	}
 
 	close(alivepipefd[1]);
@@ -403,7 +403,7 @@ proc_setup(int i)
 			execle("setup", "setup", (char *)0, child_environ);
 		_exit(127);
 	} else if (child < 0) {
-		abort();	/* XXX handle retry */
+		abort();        /* XXX handle retry */
 	}
 
 	// XXX use alivepipe?
@@ -472,7 +472,7 @@ proc_finish(int i)
 			execle("finish", "finish", run_status, run_signal, (char *)0, child_environ);
 		_exit(127);
 	} else if (child < 0) {
-		abort();	/* XXX handle retry */
+		abort();        /* XXX handle retry */
 	}
 
 	services[i].finishpid = child;
@@ -552,7 +552,7 @@ proc_zap(int i) {
 			services[i] = services[--max_service];
 		} else {
 			assert(i == 0);
-			services[i] = (struct service){ 0 };
+			services[i] = (struct service) { 0 };
 		}
 	}
 }
@@ -681,8 +681,8 @@ process_step(int i, enum process_events ev)
 
 		case PROC_SETUP:               /* can't happen */
 		case PROC_DOWN:                /* can't happen */
-		case PROC_DELAY:	       /* can't happen */
-		case PROC_ONESHOT:	       /* can't happen */
+		case PROC_DELAY:               /* can't happen */
+		case PROC_ONESHOT:             /* can't happen */
 			assert(!"invalid state transition");
 			break;
 		}
@@ -723,7 +723,7 @@ process_step(int i, enum process_events ev)
 
 		case PROC_SETUP:               /* can't happen */
 		case PROC_DOWN:                /* can't happen */
-		case PROC_DELAY:	       /* can't happen */
+		case PROC_DELAY:               /* can't happen */
 			assert(!"invalid state transition");
 			break;
 		}
@@ -778,8 +778,8 @@ on_signal(int sig)
 	case SIGHUP:
 		want_rescan = 1;
 		break;
-	case SIGCHLD:		/* just selfpipe */
-	case SIGALRM:		/* just for EINTR */
+	case SIGCHLD:           /* just selfpipe */
+	case SIGALRM:           /* just for EINTR */
 		break;
 	}
 
@@ -1280,7 +1280,7 @@ main(int argc, char *argv[])
 
 	// can't use putenv, which pulls in realloc
 	if (!getenv("PATH")) {
-		envbuf[0] = (char*) "PATH=" _PATH_DEFPATH;
+		envbuf[0] = (char *)"PATH=" _PATH_DEFPATH;
 		for (char **e = environ, **c = envbuf+1; *e; e++, c++)
 			*c = *e;
 		child_environ = envbuf;
@@ -1331,7 +1331,7 @@ main(int argc, char *argv[])
 	sigaction(SIGCHLD, &sa, 0);
 	sigaction(SIGHUP, &sa, 0);
 	sigaction(SIGINT, &sa, 0);
-	if (!real_pid1)		// only standalone and in containers
+	if (!real_pid1)         // only standalone and in containers
 		sigaction(SIGTERM, &sa, 0);
 
 	open_control_socket();
@@ -1465,7 +1465,7 @@ main(int argc, char *argv[])
 		sigaction(SIGALRM, &sa, 0);
 		alarm(3);
 
-		while(1) {
+		while (1) {
 			int r = waitpid(-1, 0, 0);
 			if (r < 0)
 				break;
diff --git a/nitroctl.c b/nitroctl.c
index 29c8963..61841b3 100644
--- a/nitroctl.c
+++ b/nitroctl.c
@@ -102,7 +102,7 @@ send_and_wait(char cmd, const char *service)
 	sigaction(SIGALRM, &sa, 0);
 	alarm(5);
 
-	while(!timed_out) {
+	while (!timed_out) {
 		ssize_t rd;
 		char buf[64];
 
@@ -161,7 +161,7 @@ normalize(char *service)
 
 	char *end = strrchr(buf, '/');
 	if (strcmp(end, "/log") == 0)
-		while(end > buf && *--end != '/')
+		while (end > buf && *--end != '/')
 			;
 
 	return end + 1;
@@ -183,7 +183,7 @@ void write_wtmp(int boot) {
 	if ((fd = open(OUR_WTMP, O_WRONLY|O_APPEND)) < 0)
 		return;
 
-	struct utmp utmp = {0};
+	struct utmp utmp = { 0 };
 	struct utsname uname_buf;
 	struct timeval tv;
 
@@ -194,7 +194,7 @@ void write_wtmp(int boot) {
 	utmp.ut_type = boot ? BOOT_TIME : RUN_LVL;
 
 	strncpy(utmp.ut_name, boot ? "reboot" : "shutdown", sizeof utmp.ut_name);
-	strncpy(utmp.ut_id , "~~", sizeof utmp.ut_id);
+	strncpy(utmp.ut_id, "~~", sizeof utmp.ut_id);
 	strncpy(utmp.ut_line, boot ? "~" : "~~", sizeof utmp.ut_line);
 	if (uname(&uname_buf) == 0)
 		strncpy(utmp.ut_host, uname_buf.release, sizeof utmp.ut_host);