about summary refs log tree commit diff
path: root/chat.c
diff options
context:
space:
mode:
Diffstat (limited to 'chat.c')
-rw-r--r--chat.c65
1 files changed, 27 insertions, 38 deletions
diff --git a/chat.c b/chat.c
index 39b1a93..bc23c3f 100644
--- a/chat.c
+++ b/chat.c
@@ -41,7 +41,6 @@
 #include <sys/stat.h>
 #include <sys/time.h>
 #include <sys/wait.h>
-#include <sysexits.h>
 #include <time.h>
 #include <tls.h>
 #include <unistd.h>
@@ -70,7 +69,7 @@ static void genCert(const char *path) {
 		"-nodes", "-subj", subj, "-out", path, "-keyout", path,
 		NULL
 	);
-	err(EX_UNAVAILABLE, "openssl");
+	err(127, "openssl");
 }
 
 char *idNames[IDCap] = {
@@ -93,7 +92,7 @@ static void exitSave(void) {
 	int error = uiSave();
 	if (error) {
 		warn("%s", save);
-		_exit(EX_IOERR);
+		_exit(1);
 	}
 }
 
@@ -104,7 +103,7 @@ int utilPipe[2] = { -1, -1 };
 static void execRead(void) {
 	char buf[1024];
 	ssize_t len = read(execPipe[0], buf, sizeof(buf) - 1);
-	if (len < 0) err(EX_IOERR, "read");
+	if (len < 0) err(1, "read");
 	if (!len) return;
 	buf[len] = '\0';
 	for (char *ptr = buf; ptr;) {
@@ -116,7 +115,7 @@ static void execRead(void) {
 static void utilRead(void) {
 	char buf[1024];
 	ssize_t len = read(utilPipe[0], buf, sizeof(buf) - 1);
-	if (len < 0) err(EX_IOERR, "read");
+	if (len < 0) err(1, "read");
 	if (!len) return;
 	buf[len] = '\0';
 	for (char *ptr = buf; ptr;) {
@@ -135,7 +134,7 @@ static void parseHash(char *str) {
 
 static void parsePlain(char *str) {
 	self.plainUser = strsep(&str, ":");
-	if (!str) errx(EX_USAGE, "SASL PLAIN missing colon");
+	if (!str) errx(1, "SASL PLAIN missing colon");
 	self.plainPass = str;
 }
 
@@ -159,27 +158,27 @@ static void sandboxEarly(bool log) {
 	if (log) {
 		char buf[PATH_MAX];
 		int error = unveil(dataPath(buf, sizeof(buf), "log", 0), "wc");
-		if (error) err(EX_OSERR, "unveil");
+		if (error) err(1, "unveil");
 		ptr = seprintf(ptr, end, " wpath cpath");
 	}
 
 	if (!self.restricted) {
 		int error = unveil("/", "x");
-		if (error) err(EX_OSERR, "unveil");
+		if (error) err(1, "unveil");
 		ptr = seprintf(ptr, end, " proc exec");
 	}
 
 	promisesInitial = ptr;
 	ptr = seprintf(ptr, end, " inet dns");
 	int error = pledge(promises, NULL);
-	if (error) err(EX_OSERR, "pledge");
+	if (error) err(1, "pledge");
 }
 
 static void sandboxLate(int irc) {
 	(void)irc;
 	*promisesInitial = '\0';
 	int error = pledge(promises, NULL);
-	if (error) err(EX_OSERR, "pledge");
+	if (error) err(1, "pledge");
 }
 
 #elif defined __FreeBSD__
@@ -202,7 +201,7 @@ static void sandboxLate(int irc) {
 		|| caph_rights_limit(
 			irc, cap_rights_init(&rights, CAP_SEND, CAP_RECV, CAP_EVENT)
 		);
-	if (error) err(EX_OSERR, "cap_rights_limit");
+	if (error) err(1, "cap_rights_limit");
 
 	// caph_cache_tzdata(3) doesn't load UTC info, which we need for
 	// certificate verification. gmtime(3) does.
@@ -210,7 +209,7 @@ static void sandboxLate(int irc) {
 	gmtime(&(time_t) { time(NULL) });
 
 	error = cap_enter();
-	if (error) err(EX_OSERR, "cap_enter");
+	if (error) err(1, "cap_enter");
 }
 
 #else
@@ -245,7 +244,6 @@ int main(int argc, char *argv[]) {
 		{ .val = 'C', .name = "copy", required_argument },
 		{ .val = 'H', .name = "hash", required_argument },
 		{ .val = 'I', .name = "highlight", required_argument },
-		{ .val = 'K', .name = "kiosk", no_argument },
 		{ .val = 'N', .name = "notify", required_argument },
 		{ .val = 'O', .name = "open", required_argument },
 		{ .val = 'R', .name = "restrict", no_argument },
@@ -286,7 +284,6 @@ int main(int argc, char *argv[]) {
 			break; case 'C': utilPush(&urlCopyUtil, optarg);
 			break; case 'H': parseHash(optarg);
 			break; case 'I': filterAdd(Hot, optarg);
-			break; case 'K': self.kiosk = true;
 			break; case 'N': utilPush(&uiNotifyUtil, optarg);
 			break; case 'O': utilPush(&urlOpenUtil, optarg);
 			break; case 'R': self.restricted = true;
@@ -319,47 +316,40 @@ int main(int argc, char *argv[]) {
 			break; case 'u': user = optarg;
 			break; case 'v': self.debug = true;
 			break; case 'w': pass = optarg;
-			break; default:  return EX_USAGE;
+			break; default:  return 1;
 		}
 	}
-	if (!host) errx(EX_USAGE, "host required");
+	if (!host) errx(1, "host required");
 
 	if (printCert) {
 #ifdef __OpenBSD__
 		int error = pledge("stdio inet dns", NULL);
-		if (error) err(EX_OSERR, "pledge");
+		if (error) err(1, "pledge");
 #endif
 		ircConfig(true, NULL, NULL, NULL);
 		ircConnect(bind, host, port);
 		ircPrintCert();
 		ircClose();
-		return EX_OK;
+		return 0;
 	}
 
 	if (!self.nicks[0]) self.nicks[0] = getenv("USER");
-	if (!self.nicks[0]) errx(EX_CONFIG, "USER unset");
+	if (!self.nicks[0]) errx(1, "USER unset");
 	if (!user) user = self.nicks[0];
 	if (!real) real = self.nicks[0];
 
-	if (self.kiosk) {
-		char *hash;
-		int n = asprintf(&hash, "%08" PRIx32, _hash(user));
-		if (n < 0) err(EX_OSERR, "asprintf");
-		user = hash;
-	}
-
 	if (pass && !pass[0]) {
 		char *buf = malloc(512);
-		if (!buf) err(EX_OSERR, "malloc");
+		if (!buf) err(1, "malloc");
 		pass = readpassphrase("Server password: ", buf, 512, 0);
-		if (!pass) errx(EX_IOERR, "unable to read passphrase");
+		if (!pass) errx(1, "unable to read passphrase");
 	}
 
 	if (self.plainPass && !self.plainPass[0]) {
 		char *buf = malloc(512);
-		if (!buf) err(EX_OSERR, "malloc");
+		if (!buf) err(1, "malloc");
 		self.plainPass = readpassphrase("Account password: ", buf, 512, 0);
-		if (!self.plainPass) errx(EX_IOERR, "unable to read passphrase");
+		if (!self.plainPass) errx(1, "unable to read passphrase");
 	}
 
 	// Modes defined in RFC 1459:
@@ -374,7 +364,7 @@ int main(int argc, char *argv[]) {
 	set(&network.name, host);
 	set(&self.nick, "*");
 
-	inputCache();
+	inputCompletion();
 
 	ircConfig(insecure, trust, cert, priv);
 
@@ -418,10 +408,9 @@ int main(int argc, char *argv[]) {
 	signal(SIGTERM, signalHandler);
 	signal(SIGCHLD, signalHandler);
 
-	bool pipes = !self.kiosk && !self.restricted;
-	if (pipes) {
+	if (!self.restricted) {
 		int error = pipe(utilPipe) || pipe(execPipe);
-		if (error) err(EX_OSERR, "pipe");
+		if (error) err(1, "pipe");
 
 		fcntl(utilPipe[0], F_SETFD, FD_CLOEXEC);
 		fcntl(utilPipe[1], F_SETFD, FD_CLOEXEC);
@@ -437,8 +426,8 @@ int main(int argc, char *argv[]) {
 		{ .events = POLLIN, .fd = execPipe[0] },
 	};
 	while (!self.quit) {
-		int nfds = poll(fds, (pipes ? ARRAY_LEN(fds) : 2), -1);
-		if (nfds < 0 && errno != EINTR) err(EX_IOERR, "poll");
+		int nfds = poll(fds, (self.restricted ? 2 : ARRAY_LEN(fds)), -1);
+		if (nfds < 0 && errno != EINTR) err(1, "poll");
 		if (nfds > 0) {
 			if (fds[0].revents) inputRead();
 			if (fds[1].revents) ircRecv();
@@ -456,12 +445,12 @@ int main(int argc, char *argv[]) {
 				.it_interval.tv_sec = 30,
 			};
 			int error = setitimer(ITIMER_REAL, &timer, NULL);
-			if (error) err(EX_OSERR, "setitimer");
+			if (error) err(1, "setitimer");
 		}
 		if (signals[SIGALRM]) {
 			signals[SIGALRM] = 0;
 			if (ping) {
-				errx(EX_UNAVAILABLE, "ping timeout");
+				errx(69, "ping timeout");
 			} else {
 				ircFormat("PING nyaa\r\n");
 				ping = true;