diff options
author | June McEnroe <june@causal.agency> | 2024-05-22 19:39:44 -0400 |
---|---|---|
committer | June McEnroe <june@causal.agency> | 2024-05-22 19:39:44 -0400 |
commit | d3b3c96385a9f456ac7a0e8f7eaa615d1dfc78d4 (patch) | |
tree | 920ef7c7a642d01d8063f234ef4c63d865ad9808 | |
parent | Pronouns (diff) | |
download | catgirl-d3b3c96385a9f456ac7a0e8f7eaa615d1dfc78d4.tar.gz catgirl-d3b3c96385a9f456ac7a0e8f7eaa615d1dfc78d4.zip |
Remove use of sysexits.h
Preserve exit status 69 (EX_UNAVAILABLE) for getting disconnected. Use 127 for failing to exec, like the shell.
Diffstat (limited to '')
-rw-r--r-- | buffer.c | 9 | ||||
-rw-r--r-- | catgirl.1 | 4 | ||||
-rw-r--r-- | chat.c | 49 | ||||
-rw-r--r-- | chat.h | 7 | ||||
-rw-r--r-- | command.c | 8 | ||||
-rw-r--r-- | complete.c | 7 | ||||
-rw-r--r-- | filter.c | 9 | ||||
-rw-r--r-- | handle.c | 25 | ||||
-rw-r--r-- | input.c | 23 | ||||
-rw-r--r-- | irc.c | 37 | ||||
-rw-r--r-- | log.c | 29 | ||||
-rw-r--r-- | sandman.m | 13 | ||||
-rw-r--r-- | ui.c | 25 | ||||
-rw-r--r-- | url.c | 35 | ||||
-rw-r--r-- | window.c | 11 | ||||
-rw-r--r-- | xdg.c | 3 |
16 files changed, 139 insertions, 155 deletions
diff --git a/buffer.c b/buffer.c index f82e553..6a7b412 100644 --- a/buffer.c +++ b/buffer.c @@ -30,7 +30,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sysexits.h> #include <time.h> #include <wchar.h> #include <wctype.h> @@ -50,7 +49,7 @@ struct Buffer { struct Buffer *bufferAlloc(void) { struct Buffer *buffer = calloc(1, sizeof(*buffer)); - if (!buffer) err(EX_OSERR, "calloc"); + if (!buffer) err(1, "calloc"); return buffer; } @@ -107,7 +106,7 @@ static int flow(struct Lines *hard, int cols, const struct Line *soft) { line->heat = soft->heat; line->time = soft->time; line->str = strdup(soft->str); - if (!line->str) err(EX_OSERR, "strdup"); + if (!line->str) err(1, "strdup"); int width = 0; int align = 0; @@ -185,7 +184,7 @@ static int flow(struct Lines *hard, int cols, const struct Line *soft) { size_t cap = StyleCap + align + strlen(&wrap[n]) + 1; line->str = malloc(cap); - if (!line->str) err(EX_OSERR, "malloc"); + if (!line->str) err(1, "malloc"); char *end = &line->str[cap]; str = seprintf(line->str, end, "%*s", (width = align), ""); @@ -209,7 +208,7 @@ int bufferPush( soft->heat = heat; soft->time = time; soft->str = strdup(str); - if (!soft->str) err(EX_OSERR, "strdup"); + if (!soft->str) err(1, "strdup"); if (heat < thresh) return 0; return flow(&buffer->hard, cols, soft); } diff --git a/catgirl.1 b/catgirl.1 index 815eade..16fa38b 100644 --- a/catgirl.1 +++ b/catgirl.1 @@ -909,9 +909,7 @@ The .Nm client exits 0 if requested by the user, -.Dv EX_UNAVAILABLE -(69) -if the connection is lost, +69 if the connection is lost, and >0 if any other error occurs. . .Sh EXAMPLES diff --git a/chat.c b/chat.c index 6728240..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 @@ -317,40 +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 (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: @@ -411,7 +410,7 @@ int main(int argc, char *argv[]) { 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); @@ -428,7 +427,7 @@ int main(int argc, char *argv[]) { }; while (!self.quit) { int nfds = poll(fds, (self.restricted ? 2 : ARRAY_LEN(fds)), -1); - if (nfds < 0 && errno != EINTR) err(EX_IOERR, "poll"); + if (nfds < 0 && errno != EINTR) err(1, "poll"); if (nfds > 0) { if (fds[0].revents) inputRead(); if (fds[1].revents) ircRecv(); @@ -446,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; diff --git a/chat.h b/chat.h index 2a41cf6..369747c 100644 --- a/chat.h +++ b/chat.h @@ -35,7 +35,6 @@ #include <stdio.h> #include <string.h> #include <strings.h> -#include <sysexits.h> #include <time.h> #include <wchar.h> @@ -131,7 +130,7 @@ static inline uint idFor(const char *name) { if (idNext == IDCap) return Network; idNames[idNext] = strdup(name); idColors[idNext] = Default; - if (!idNames[idNext]) err(EX_OSERR, "strdup"); + if (!idNames[idNext]) err(1, "strdup"); return idNext++; } @@ -221,7 +220,7 @@ extern struct Self { static inline void set(char **field, const char *value) { free(*field); *field = strdup(value); - if (!*field) err(EX_OSERR, "strdup"); + if (!*field) err(1, "strdup"); } #define ENUM_TAG \ @@ -273,7 +272,7 @@ static inline void utilPush(struct Util *util, const char *arg) { if (1 + util->argc < UtilCap) { util->argv[util->argc++] = arg; } else { - errx(EX_CONFIG, "too many utility arguments"); + errx(1, "too many utility arguments"); } } diff --git a/command.c b/command.c index 502ff17..9b2b4eb 100644 --- a/command.c +++ b/command.c @@ -516,7 +516,7 @@ static void commandExec(uint id, char *params) { execID = id; pid_t pid = fork(); - if (pid < 0) err(EX_OSERR, "fork"); + if (pid < 0) err(1, "fork"); if (pid) return; setsid(); @@ -527,7 +527,7 @@ static void commandExec(uint id, char *params) { const char *shell = getenv("SHELL") ?: "/bin/sh"; execl(shell, shell, "-c", params, NULL); warn("%s", shell); - _exit(EX_UNAVAILABLE); + _exit(127); } static void commandHelp(uint id, char *params) { @@ -545,7 +545,7 @@ static void commandHelp(uint id, char *params) { uiHide(); pid_t pid = fork(); - if (pid < 0) err(EX_OSERR, "fork"); + if (pid < 0) err(1, "fork"); if (pid) return; char buf[256]; @@ -554,7 +554,7 @@ static void commandHelp(uint id, char *params) { execlp("man", "man", "1", "catgirl", NULL); dup2(utilPipe[1], STDERR_FILENO); warn("man"); - _exit(EX_UNAVAILABLE); + _exit(127); } enum Flag { diff --git a/complete.c b/complete.c index 3552c7c..d7108e6 100644 --- a/complete.c +++ b/complete.c @@ -28,7 +28,6 @@ #include <err.h> #include <stdlib.h> #include <string.h> -#include <sysexits.h> #include "chat.h" @@ -47,10 +46,10 @@ static struct Node *tail; static struct Node *alloc(uint id, const char *str, enum Color color) { struct Node *node = calloc(1, sizeof(*node)); - if (!node) err(EX_OSERR, "calloc"); + if (!node) err(1, "calloc"); node->id = id; node->str = strdup(str); - if (!node->str) err(EX_OSERR, "strdup"); + if (!node->str) err(1, "strdup"); node->color = color; node->bits = 0; return node; @@ -117,7 +116,7 @@ void completeReplace(const char *old, const char *new) { if (strcmp(node->str, old)) continue; free(node->str); node->str = strdup(new); - if (!node->str) err(EX_OSERR, "strdup"); + if (!node->str) err(1, "strdup"); prepend(detach(node)); } } diff --git a/filter.c b/filter.c index a7f9a29..bbe40c8 100644 --- a/filter.c +++ b/filter.c @@ -31,7 +31,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sysexits.h> #include "chat.h" @@ -48,14 +47,14 @@ struct Filter filterParse(enum Heat heat, char *pattern) { } struct Filter filterAdd(enum Heat heat, const char *pattern) { - if (len == FilterCap) errx(EX_CONFIG, "filter limit exceeded"); + if (len == FilterCap) errx(1, "filter limit exceeded"); char *own; if (!strchr(pattern, '!') && !strchr(pattern, ' ')) { int n = asprintf(&own, "%s!*@*", pattern); - if (n < 0) err(EX_OSERR, "asprintf"); + if (n < 0) err(1, "asprintf"); } else { own = strdup(pattern); - if (!own) err(EX_OSERR, "strdup"); + if (!own) err(1, "strdup"); } struct Filter filter = filterParse(heat, own); filters[len++] = filter; @@ -105,7 +104,7 @@ static void icedPush(const char *msgID) { size_t i = iced.len % IcedCap; free(iced.msgIDs[i]); iced.msgIDs[i] = strdup(msgID); - if (!iced.msgIDs[i]) err(EX_OSERR, "strdup"); + if (!iced.msgIDs[i]) err(1, "strdup"); iced.len++; } diff --git a/handle.c b/handle.c index 5a2cf7c..0cc7c04 100644 --- a/handle.c +++ b/handle.c @@ -32,7 +32,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sysexits.h> #include <wchar.h> #include "chat.h" @@ -83,7 +82,7 @@ static void require(struct Message *msg, bool origin, uint len) { } for (uint i = 0; i < len; ++i) { if (msg->params[i]) continue; - errx(EX_PROTOCOL, "%s missing parameter %u", msg->cmd, 1 + i); + errx(1, "%s missing parameter %u", msg->cmd, 1 + i); } } @@ -162,7 +161,7 @@ static void handleErrorNicknameInUse(struct Message *msg) { static void handleErrorErroneousNickname(struct Message *msg) { require(msg, false, 3); if (!strcmp(self.nick, "*")) { - errx(EX_CONFIG, "%s: %s", msg->params[1], msg->params[2]); + errx(1, "%s: %s", msg->params[1], msg->params[2]); } else { handleErrorGeneric(msg); } @@ -193,7 +192,7 @@ static void handleCap(struct Message *msg) { } if (!(self.caps & CapSASL)) ircFormat("CAP END\r\n"); } else if (!strcmp(msg->params[1], "NAK")) { - errx(EX_CONFIG, "server does not support %s", msg->params[2]); + errx(1, "server does not support %s", msg->params[2]); } } @@ -237,7 +236,7 @@ static void handleAuthenticate(struct Message *msg) { size_t userLen = strlen(self.plainUser); size_t passLen = strlen(self.plainPass); size_t len = 1 + userLen + 1 + passLen; - if (sizeof(buf) < len) errx(EX_USAGE, "SASL PLAIN is too long"); + if (sizeof(buf) < len) errx(1, "SASL PLAIN is too long"); memcpy(&buf[1], self.plainUser, userLen); memcpy(&buf[1 + userLen + 1], self.plainPass, passLen); @@ -260,7 +259,7 @@ static void handleReplyLoggedIn(struct Message *msg) { static void handleErrorSASLFail(struct Message *msg) { require(msg, false, 2); - errx(EX_CONFIG, "%s", msg->params[1]); + errx(1, "%s", msg->params[1]); } static void handleReplyWelcome(struct Message *msg) { @@ -315,7 +314,7 @@ static void handleReplyISupport(struct Message *msg) { char *modes = strsep(&msg->params[i], ")"); char *prefixes = msg->params[i]; if (!modes || !prefixes || strlen(modes) != strlen(prefixes)) { - errx(EX_PROTOCOL, "invalid PREFIX value"); + errx(1, "invalid PREFIX value"); } set(&network.prefixModes, modes); set(&network.prefixes, prefixes); @@ -325,7 +324,7 @@ static void handleReplyISupport(struct Message *msg) { char *setParam = strsep(&msg->params[i], ","); char *channel = strsep(&msg->params[i], ","); if (!list || !param || !setParam || !channel) { - errx(EX_PROTOCOL, "invalid CHANMODES value"); + errx(1, "invalid CHANMODES value"); } set(&network.listModes, list); set(&network.paramModes, param); @@ -857,7 +856,7 @@ static void handleMode(struct Message *msg) { if (strchr(network.prefixModes, *ch)) { if (i >= ParamCap || !msg->params[i]) { - errx(EX_PROTOCOL, "MODE missing %s parameter", mode); + errx(1, "MODE missing %s parameter", mode); } char *nick = msg->params[i++]; char prefix = network.prefixes[ @@ -884,7 +883,7 @@ static void handleMode(struct Message *msg) { if (strchr(network.listModes, *ch)) { if (i >= ParamCap || !msg->params[i]) { - errx(EX_PROTOCOL, "MODE missing %s parameter", mode); + errx(1, "MODE missing %s parameter", mode); } char *mask = msg->params[i++]; if (*ch == 'b') { @@ -917,7 +916,7 @@ static void handleMode(struct Message *msg) { if (strchr(network.paramModes, *ch)) { if (i >= ParamCap || !msg->params[i]) { - errx(EX_PROTOCOL, "MODE missing %s parameter", mode); + errx(1, "MODE missing %s parameter", mode); } char *param = msg->params[i++]; uiFormat( @@ -934,7 +933,7 @@ static void handleMode(struct Message *msg) { if (strchr(network.setParamModes, *ch) && set) { if (i >= ParamCap || !msg->params[i]) { - errx(EX_PROTOCOL, "MODE missing %s parameter", mode); + errx(1, "MODE missing %s parameter", mode); } char *param = msg->params[i++]; uiFormat( @@ -1337,7 +1336,7 @@ static void handlePing(struct Message *msg) { static void handleError(struct Message *msg) { require(msg, false, 1); - errx(EX_UNAVAILABLE, "%s", msg->params[0]); + errx(69, "%s", msg->params[0]); } static const struct Handler { diff --git a/input.c b/input.c index 6b33b93..7e1f9c1 100644 --- a/input.c +++ b/input.c @@ -35,7 +35,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sysexits.h> #include <termios.h> #include <unistd.h> #include <wchar.h> @@ -100,7 +99,7 @@ void inputInit(void) { struct termios term; int error = tcgetattr(STDOUT_FILENO, &term); - if (error) err(EX_OSERR, "tcgetattr"); + if (error) err(1, "tcgetattr"); // Gain use of C-q, C-s, C-c, C-z, C-y, C-v, C-o. term.c_iflag &= ~IXON; @@ -113,7 +112,7 @@ void inputInit(void) { term.c_cc[VDISCARD] = _POSIX_VDISABLE; error = tcsetattr(STDOUT_FILENO, TCSANOW, &term); - if (error) err(EX_OSERR, "tcsetattr"); + if (error) err(1, "tcsetattr"); def_prog_mode(); @@ -172,7 +171,7 @@ void inputUpdate(void) { size_t pos = 0; const char *ptr = editString(&edits[id], &buf, &cap, &pos); - if (!ptr) err(EX_OSERR, "editString"); + if (!ptr) err(1, "editString"); const char *prefix = ""; const char *prompt = self.nick; @@ -394,7 +393,7 @@ fail: static void inputEnter(void) { uint id = windowID(); char *cmd = editString(&edits[id], &buf, &cap, NULL); - if (!cmd) err(EX_OSERR, "editString"); + if (!cmd) err(1, "editString"); tabAccept(); editFn(&edits[id], EditClear); @@ -450,7 +449,7 @@ static void keyCode(int code) { break; case KEY_SHOME: windowScroll(ScrollAll, +1); break; case KEY_UP: windowScroll(ScrollOne, +1); } - if (error) err(EX_OSERR, "editFn"); + if (error) err(1, "editFn"); } static void keyCtrl(wchar_t ch) { @@ -480,7 +479,7 @@ static void keyCtrl(wchar_t ch) { break; case L'X': error = macroExpand(edit); tabAccept(); break; case L'Y': error = editFn(edit, EditPaste); } - if (error) err(EX_OSERR, "editFn"); + if (error) err(1, "editFn"); } static void keyStyle(wchar_t ch) { @@ -516,7 +515,7 @@ static void keyStyle(wchar_t ch) { struct Edit *edit = &edits[windowID()]; for (char *ch = buf; *ch; ++ch) { int error = editInsert(edit, *ch); - if (error) err(EX_OSERR, "editInsert"); + if (error) err(1, "editInsert"); } } @@ -552,7 +551,7 @@ void inputRead(void) { paste ^= true; } else if (paste || literal) { int error = editInsert(&edits[windowID()], ch); - if (error) err(EX_OSERR, "editInsert"); + if (error) err(1, "editInsert"); } else if (ret == KEY_CODE_YES) { keyCode(ch); } else if (ch == (L'Z' ^ L'@')) { @@ -568,7 +567,7 @@ void inputRead(void) { keyCtrl(ch); } else { int error = editInsert(&edits[windowID()], ch); - if (error) err(EX_OSERR, "editInsert"); + if (error) err(1, "editInsert"); } style = false; literal = false; @@ -609,7 +608,7 @@ int inputSave(FILE *file) { static ssize_t readString(FILE *file, char **buf, size_t *cap) { ssize_t len = getdelim(buf, cap, '\0', file); - if (len < 0 && !feof(file)) err(EX_IOERR, "getdelim"); + if (len < 0 && !feof(file)) err(1, "getdelim"); return len; } @@ -620,7 +619,7 @@ void inputLoad(FILE *file, size_t version) { readString(file, &buf, &cap); size_t max = strlen(buf); int error = editReserve(&edits[id], 0, max); - if (error) err(EX_OSERR, "editReserve"); + if (error) err(1, "editReserve"); size_t len = mbstowcs(edits[id].buf, buf, max); assert(len != (size_t)-1); edits[id].len = len; diff --git a/irc.c b/irc.c index 1fc2c3f..28e557b 100644 --- a/irc.c +++ b/irc.c @@ -38,7 +38,6 @@ #include <string.h> #include <sys/socket.h> #include <sys/stat.h> -#include <sysexits.h> #include <tls.h> #include <unistd.h> @@ -54,7 +53,7 @@ void ircConfig( char buf[PATH_MAX]; config = tls_config_new(); - if (!config) errx(EX_SOFTWARE, "tls_config_new"); + if (!config) errx(1, "tls_config_new"); if (insecure) { tls_config_insecure_noverifycert(config); @@ -66,7 +65,7 @@ void ircConfig( error = tls_config_set_ca_file(config, buf); if (!error) break; } - if (error) errx(EX_NOINPUT, "%s: %s", trust, tls_config_error(config)); + if (error) errx(1, "%s: %s", trust, tls_config_error(config)); } // Explicitly load the default CA cert file on OpenBSD now so it doesn't @@ -76,7 +75,7 @@ void ircConfig( if (!insecure && !trust) { const char *ca = tls_default_ca_cert_file(); error = tls_config_set_ca_file(config, ca); - if (error) errx(EX_OSFILE, "%s: %s", ca, tls_config_error(config)); + if (error) errx(1, "%s: %s", ca, tls_config_error(config)); } #endif @@ -89,21 +88,21 @@ void ircConfig( } if (!error) break; } - if (error) errx(EX_NOINPUT, "%s: %s", cert, tls_config_error(config)); + if (error) errx(1, "%s: %s", cert, tls_config_error(config)); } if (priv) { for (int i = 0; configPath(buf, sizeof(buf), priv, i); ++i) { error = tls_config_set_key_file(config, buf); if (!error) break; } - if (error) errx(EX_NOINPUT, "%s: %s", priv, tls_config_error(config)); + if (error) errx(1, "%s: %s", priv, tls_config_error(config)); } client = tls_client(); - if (!client) errx(EX_SOFTWARE, "tls_client"); + if (!client) errx(1, "tls_client"); error = tls_configure(client, config); - if (error) errx(EX_SOFTWARE, "tls_configure: %s", tls_error(client)); + if (error) errx(1, "tls_configure: %s", tls_error(client)); } int ircConnect(const char *bindHost, const char *host, const char *port) { @@ -120,11 +119,11 @@ int ircConnect(const char *bindHost, const char *host, const char *port) { if (bindHost) { error = getaddrinfo(bindHost, NULL, &hints, &head); - if (error) errx(EX_NOHOST, "%s: %s", bindHost, gai_strerror(error)); + if (error) errx(1, "%s: %s", bindHost, gai_strerror(error)); for (struct addrinfo *ai = head; ai; ai = ai->ai_next) { sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if (sock < 0) err(EX_OSERR, "socket"); + if (sock < 0) err(1, "socket"); error = bind(sock, ai->ai_addr, ai->ai_addrlen); if (!error) { @@ -135,17 +134,17 @@ int ircConnect(const char *bindHost, const char *host, const char *port) { close(sock); sock = -1; } - if (sock < 0) err(EX_UNAVAILABLE, "%s", bindHost); + if (sock < 0) err(1, "%s", bindHost); freeaddrinfo(head); } error = getaddrinfo(host, port, &hints, &head); - if (error) errx(EX_NOHOST, "%s:%s: %s", host, port, gai_strerror(error)); + if (error) errx(1, "%s:%s: %s", host, port, gai_strerror(error)); for (struct addrinfo *ai = head; ai; ai = ai->ai_next) { if (sock < 0) { sock = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if (sock < 0) err(EX_OSERR, "socket"); + if (sock < 0) err(1, "socket"); } error = connect(sock, ai->ai_addr, ai->ai_addrlen); @@ -155,12 +154,12 @@ int ircConnect(const char *bindHost, const char *host, const char *port) { close(sock); sock = -1; } - if (sock < 0) err(EX_UNAVAILABLE, "%s:%s", host, port); + if (sock < 0) err(69, "%s:%s", host, port); freeaddrinfo(head); fcntl(sock, F_SETFD, FD_CLOEXEC); error = tls_connect_socket(client, sock, host); - if (error) errx(EX_PROTOCOL, "tls_connect: %s", tls_error(client)); + if (error) errx(1, "tls_connect: %s", tls_error(client)); return sock; } @@ -170,7 +169,7 @@ void ircHandshake(void) { do { error = tls_handshake(client); } while (error == TLS_WANT_POLLIN || error == TLS_WANT_POLLOUT); - if (error) errx(EX_PROTOCOL, "tls_handshake: %s", tls_error(client)); + if (error) errx(1, "tls_handshake: %s", tls_error(client)); tls_config_clear_keys(config); } @@ -202,7 +201,7 @@ void ircSend(const char *ptr, size_t len) { while (len) { ssize_t ret = tls_write(client, ptr, len); if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT) continue; - if (ret < 0) errx(EX_IOERR, "tls_write: %s", tls_error(client)); + if (ret < 0) errx(1, "tls_write: %s", tls_error(client)); ptr += ret; len -= ret; } @@ -287,8 +286,8 @@ void ircRecv(void) { assert(client); ssize_t ret = tls_read(client, &buf[len], sizeof(buf) - len); if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT) return; - if (ret < 0) errx(EX_IOERR, "tls_read: %s", tls_error(client)); - if (!ret) errx(EX_PROTOCOL, "server closed connection"); + if (ret < 0) errx(1, "tls_read: %s", tls_error(client)); + if (!ret) errx(69, "server closed connection"); len += ret; char *crlf; diff --git a/log.c b/log.c index d6b3f2a..181c009 100644 --- a/log.c +++ b/log.c @@ -34,7 +34,6 @@ #include <stdio.h> #include <stdlib.h> #include <sys/stat.h> -#include <sysexits.h> #include <time.h> #include <unistd.h> @@ -49,13 +48,13 @@ static int logDir = -1; void logOpen(void) { char buf[PATH_MAX]; int error = mkdir(dataPath(buf, sizeof(buf), "", 0), S_IRWXU); - if (error && errno != EEXIST) err(EX_CANTCREAT, "%s", buf); + if (error && errno != EEXIST) err(1, "%s", buf); error = mkdir(dataPath(buf, sizeof(buf), "log", 0), S_IRWXU); - if (error && errno != EEXIST) err(EX_CANTCREAT, "%s", buf); + if (error && errno != EEXIST) err(1, "%s", buf); logDir = open(buf, O_RDONLY | O_CLOEXEC); - if (logDir < 0) err(EX_CANTCREAT, "%s", buf); + if (logDir < 0) err(1, "%s", buf); #ifdef __FreeBSD__ cap_rights_t rights; @@ -64,13 +63,13 @@ void logOpen(void) { /* for fdopen(3) */ CAP_FCNTL, CAP_FSTAT ); error = caph_rights_limit(logDir, &rights); - if (error) err(EX_OSERR, "cap_rights_limit"); + if (error) err(1, "cap_rights_limit"); #endif } static void logMkdir(const char *path) { int error = mkdirat(logDir, path, S_IRWXU); - if (error && errno != EEXIST) err(EX_CANTCREAT, "log/%s", path); + if (error && errno != EEXIST) err(1, "log/%s", path); } static void sanitize(char *ptr, char *end) { @@ -99,7 +98,7 @@ static FILE *logFile(uint id, const struct tm *tm) { if (logs[id].file) { int error = fclose(logs[id].file); - if (error) err(EX_IOERR, "%s", idNames[id]); + if (error) err(1, "%s", idNames[id]); } logs[id].year = tm->tm_year; @@ -119,16 +118,16 @@ static FILE *logFile(uint id, const struct tm *tm) { logMkdir(path); size_t len = strftime(ptr, end - ptr, "/%F.log", tm); - if (!len) errx(EX_CANTCREAT, "log path too long"); + if (!len) errx(1, "log path too long"); int fd = openat( logDir, path, O_WRONLY | O_APPEND | O_CREAT | O_CLOEXEC, S_IRUSR | S_IWUSR ); - if (fd < 0) err(EX_CANTCREAT, "log/%s", path); + if (fd < 0) err(1, "log/%s", path); logs[id].file = fdopen(fd, "a"); - if (!logs[id].file) err(EX_OSERR, "fdopen"); + if (!logs[id].file) err(1, "fdopen"); setlinebuf(logs[id].file); return logs[id].file; @@ -139,7 +138,7 @@ void logClose(void) { for (uint id = 0; id < IDCap; ++id) { if (!logs[id].file) continue; int error = fclose(logs[id].file); - if (error) err(EX_IOERR, "%s", idNames[id]); + if (error) err(1, "%s", idNames[id]); } close(logDir); } @@ -149,21 +148,21 @@ void logFormat(uint id, const time_t *src, const char *format, ...) { time_t ts = (src ? *src : time(NULL)); struct tm *tm = localtime(&ts); - if (!tm) err(EX_OSERR, "localtime"); + if (!tm) err(1, "localtime"); FILE *file = logFile(id, tm); char buf[sizeof("0000-00-00T00:00:00+0000")]; strftime(buf, sizeof(buf), "%FT%T%z", tm); int n = fprintf(file, "[%s] ", buf); - if (n < 0) err(EX_IOERR, "%s", idNames[id]); + if (n < 0) err(1, "%s", idNames[id]); va_list ap; va_start(ap, format); n = vfprintf(file, format, ap); va_end(ap); - if (n < 0) err(EX_IOERR, "%s", idNames[id]); + if (n < 0) err(1, "%s", idNames[id]); n = fprintf(file, "\n"); - if (n < 0) err(EX_IOERR, "%s", idNames[id]); + if (n < 0) err(1, "%s", idNames[id]); } diff --git a/sandman.m b/sandman.m index 2e5c4db..c9d0705 100644 --- a/sandman.m +++ b/sandman.m @@ -19,7 +19,6 @@ #import <signal.h> #import <stdio.h> #import <stdlib.h> -#import <sysexits.h> #import <unistd.h> typedef unsigned uint; @@ -27,17 +26,17 @@ typedef unsigned uint; static pid_t pid; static void spawn(char *argv[]) { pid = fork(); - if (pid < 0) err(EX_OSERR, "fork"); + if (pid < 0) err(1, "fork"); if (pid) return; execvp(argv[0], argv); - err(EX_CONFIG, "%s", argv[0]); + err(127, "%s", argv[0]); } static void handler(int signal) { (void)signal; int status; pid_t pid = wait(&status); - if (pid < 0) _exit(EX_OSERR); + if (pid < 0) _exit(1); _exit(status); } @@ -47,12 +46,12 @@ int main(int argc, char *argv[]) { for (int opt; 0 < (opt = getopt(argc, argv, "t:"));) { switch (opt) { break; case 't': delay = strtoul(optarg, NULL, 10); - break; default: return EX_USAGE; + break; default: return 1; } } argc -= optind; argv += optind; - if (!argc) errx(EX_USAGE, "command required"); + if (!argc) errx(1, "command required"); NSWorkspace *workspace = [NSWorkspace sharedWorkspace]; NSNotificationCenter *notifCenter = [workspace notificationCenter]; @@ -64,7 +63,7 @@ int main(int argc, char *argv[]) { (void)notif; signal(SIGCHLD, SIG_IGN); int error = kill(pid, SIGHUP); - if (error) err(EX_UNAVAILABLE, "kill"); + if (error) err(1, "kill"); int status; wait(&status); }]; diff --git a/ui.c b/ui.c index 079ee19..df675b1 100644 --- a/ui.c +++ b/ui.c @@ -39,7 +39,6 @@ #include <stdlib.h> #include <string.h> #include <sys/file.h> -#include <sysexits.h> #include <term.h> #include <time.h> #include <unistd.h> @@ -122,13 +121,13 @@ void uiInit(void) { } uiStatus = newwin(StatusLines, COLS, 0, 0); - if (!uiStatus) err(EX_OSERR, "newwin"); + if (!uiStatus) err(1, "newwin"); uiMain = newwin(MAIN_LINES, COLS, StatusLines, 0); - if (!uiMain) err(EX_OSERR, "newwin"); + if (!uiMain) err(1, "newwin"); uiInput = newpad(InputLines, InputCols); - if (!uiInput) err(EX_OSERR, "newpad"); + if (!uiInput) err(1, "newpad"); windowInit(); uiShow(); @@ -240,7 +239,7 @@ static void notify(uint id, const char *str) { utilPush(&util, buf); pid_t pid = fork(); - if (pid < 0) err(EX_OSERR, "fork"); + if (pid < 0) err(1, "fork"); if (pid) return; setsid(); @@ -249,7 +248,7 @@ static void notify(uint id, const char *str) { dup2(utilPipe[1], STDERR_FILENO); execvp(util.argv[0], (char *const *)util.argv); warn("%s", util.argv[0]); - _exit(EX_CONFIG); + _exit(127); } void uiWrite(uint id, enum Heat heat, const time_t *src, const char *str) { @@ -296,7 +295,7 @@ static size_t signatureVersion(uint64_t signature) { for (size_t i = 0; i < ARRAY_LEN(Signatures); ++i) { if (signature == Signatures[i]) return i; } - errx(EX_DATAERR, "unknown save file signature %" PRIX64, signature); + errx(1, "unknown save file signature %" PRIX64, signature); } static int writeUint64(FILE *file, uint64_t u) { @@ -317,32 +316,32 @@ int uiSave(void) { static uint64_t readUint64(FILE *file) { uint64_t u; fread(&u, sizeof(u), 1, file); - if (ferror(file)) err(EX_IOERR, "fread"); - if (feof(file)) errx(EX_DATAERR, "unexpected end of save file"); + if (ferror(file)) err(1, "fread"); + if (feof(file)) errx(1, "unexpected end of save file"); return u; } void uiLoad(const char *name) { int error; saveFile = dataOpen(name, "a+e"); - if (!saveFile) exit(EX_CANTCREAT); + if (!saveFile) exit(1); rewind(saveFile); #ifdef __FreeBSD__ cap_rights_t rights; cap_rights_init(&rights, CAP_READ, CAP_WRITE, CAP_FLOCK, CAP_FTRUNCATE); error = caph_rights_limit(fileno(saveFile), &rights); - if (error) err(EX_OSERR, "cap_rights_limit"); + if (error) err(1, "cap_rights_limit"); #endif error = flock(fileno(saveFile), LOCK_EX | LOCK_NB); if (error && errno == EWOULDBLOCK) { - errx(EX_CANTCREAT, "%s: save file in use", name); + errx(1, "%s: save file in use", name); } time_t signature; fread(&signature, sizeof(signature), 1, saveFile); - if (ferror(saveFile)) err(EX_IOERR, "fread"); + if (ferror(saveFile)) err(1, "fread"); if (feof(saveFile)) { return; } diff --git a/url.c b/url.c index 7da0968..349dc00 100644 --- a/url.c +++ b/url.c @@ -32,7 +32,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sysexits.h> #include <unistd.h> #include "chat.h" @@ -67,7 +66,7 @@ static void compile(void) { if (!error) return; char buf[256]; regerror(error, &Regex, buf, sizeof(buf)); - errx(EX_SOFTWARE, "regcomp: %s: %s", buf, Pattern); + errx(1, "regcomp: %s: %s", buf, Pattern); } struct URL { @@ -92,10 +91,10 @@ static void push(uint id, const char *nick, const char *str, size_t len) { url->nick = NULL; if (nick) { url->nick = strdup(nick); - if (!url->nick) err(EX_OSERR, "strdup"); + if (!url->nick) err(1, "strdup"); } url->url = malloc(len + 1); - if (!url->url) err(EX_OSERR, "malloc"); + if (!url->url) err(1, "malloc"); char buf[1024]; snprintf(buf, sizeof(buf), "%.*s", (int)len, str); @@ -120,7 +119,7 @@ static const struct Util OpenUtils[] = { static void urlOpen(const char *url) { pid_t pid = fork(); - if (pid < 0) err(EX_OSERR, "fork"); + if (pid < 0) err(1, "fork"); if (pid) return; setsid(); @@ -132,7 +131,7 @@ static void urlOpen(const char *url) { utilPush(&util, url); execvp(util.argv[0], (char *const *)util.argv); warn("%s", util.argv[0]); - _exit(EX_CONFIG); + _exit(127); } for (size_t i = 0; i < ARRAY_LEN(OpenUtils); ++i) { struct Util util = OpenUtils[i]; @@ -140,11 +139,11 @@ static void urlOpen(const char *url) { execvp(util.argv[0], (char *const *)util.argv); if (errno != ENOENT) { warn("%s", util.argv[0]); - _exit(EX_CONFIG); + _exit(127); } } warnx("no open utility found"); - _exit(EX_CONFIG); + _exit(127); } struct Util urlCopyUtil; @@ -158,18 +157,18 @@ static const struct Util CopyUtils[] = { static void urlCopy(const char *url) { int rw[2]; int error = pipe(rw); - if (error) err(EX_OSERR, "pipe"); + if (error) err(1, "pipe"); size_t len = strlen(url); if (len > PIPE_BUF) len = PIPE_BUF; ssize_t n = write(rw[1], url, len); - if (n < 0) err(EX_IOERR, "write"); + if (n < 0) err(1, "write"); error = close(rw[1]); - if (error) err(EX_IOERR, "close"); + if (error) err(1, "close"); pid_t pid = fork(); - if (pid < 0) err(EX_OSERR, "fork"); + if (pid < 0) err(1, "fork"); if (pid) { close(rw[0]); return; @@ -183,17 +182,17 @@ static void urlCopy(const char *url) { if (urlCopyUtil.argc) { execvp(urlCopyUtil.argv[0], (char *const *)urlCopyUtil.argv); warn("%s", urlCopyUtil.argv[0]); - _exit(EX_CONFIG); + _exit(127); } for (size_t i = 0; i < ARRAY_LEN(CopyUtils); ++i) { execvp(CopyUtils[i].argv[0], (char *const *)CopyUtils[i].argv); if (errno != ENOENT) { warn("%s", CopyUtils[i].argv[0]); - _exit(EX_CONFIG); + _exit(127); } } warnx("no copy utility found"); - _exit(EX_CONFIG); + _exit(127); } void urlOpenCount(uint id, uint count) { @@ -239,7 +238,7 @@ static int writeString(FILE *file, const char *str) { } static ssize_t readString(FILE *file, char **buf, size_t *cap) { ssize_t len = getdelim(buf, cap, '\0', file); - if (len < 0 && !feof(file)) err(EX_IOERR, "getdelim"); + if (len < 0 && !feof(file)) err(1, "getdelim"); return len; } @@ -269,11 +268,11 @@ void urlLoad(FILE *file, size_t version) { readString(file, &buf, &cap); if (buf[0]) { url->nick = strdup(buf); - if (!url->nick) err(EX_OSERR, "strdup"); + if (!url->nick) err(1, "strdup"); } readString(file, &buf, &cap); url->url = strdup(buf); - if (!url->url) err(EX_OSERR, "strdup"); + if (!url->url) err(1, "strdup"); } free(buf); } diff --git a/window.c b/window.c index f700fd7..2e79a65 100644 --- a/window.c +++ b/window.c @@ -35,7 +35,6 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <sysexits.h> #include <time.h> #include "chat.h" @@ -107,7 +106,7 @@ uint windowFor(uint id) { } struct Window *window = calloc(1, sizeof(*window)); - if (!window) err(EX_OSERR, "malloc"); + if (!window) err(1, "malloc"); window->id = id; window->mark = true; @@ -132,7 +131,7 @@ void windowInit(void) { struct tm *time = localtime(&(time_t) { -22100400 }); size_t len = strftime(buf, sizeof(buf), fmt, time); - if (!len) errx(EX_CONFIG, "invalid timestamp format: %s", fmt); + if (!len) errx(1, "invalid timestamp format: %s", fmt); int y; waddstr(uiMain, buf); @@ -622,14 +621,14 @@ int windowSave(FILE *file) { static time_t readTime(FILE *file) { time_t time; fread(&time, sizeof(time), 1, file); - if (ferror(file)) err(EX_IOERR, "fread"); - if (feof(file)) errx(EX_DATAERR, "unexpected end of save file"); + if (ferror(file)) err(1, "fread"); + if (feof(file)) errx(1, "unexpected end of save file"); return time; } static ssize_t readString(FILE *file, char **buf, size_t *cap) { ssize_t len = getdelim(buf, cap, '\0', file); - if (len < 0 && !feof(file)) err(EX_IOERR, "getdelim"); + if (len < 0 && !feof(file)) err(1, "getdelim"); return len; } diff --git a/xdg.c b/xdg.c index 75ee871..6f61cf9 100644 --- a/xdg.c +++ b/xdg.c @@ -32,7 +32,6 @@ #include <stdlib.h> #include <string.h> #include <sys/stat.h> -#include <sysexits.h> #include "chat.h" @@ -90,7 +89,7 @@ static char *basePath( } else if (home) { snprintf(buf, cap, "%s/%s/" SUBDIR "/%s", home, base.defHome, path); } else { - errx(EX_USAGE, "HOME unset"); + errx(1, "HOME unset"); } return buf; } |