commit aee018de4a1323337107b270ec150f07ea5f9f80
parent 9b79f6014a1c1648cf877fd26177edcb5367ddef
Author: Andrew Kloet <andrew@kloet.net>
Date: Tue, 21 Apr 2026 12:26:17 -0400
remove reconn support from default build
The server connection state machine is complex--especially with SSL.
It involves networking and file reading, something that aren't anywhere
else in the program.
In an ideal world we only do this at the start of the program so that we
can lock down the permissions after. Reconnection doesn't allow for
this. What I'd like to do is completely remove this and some other
subjectively complex features that may not be worth the tradeoffs.
Instead I would make an in-repo 'patches' directory for optional
features that may be desired depending on your use case.
On a server I'd prefer the high security of connect once, drop all
networking after. On a laptop I'd prefer reconnection attempts on
network dropping.
Diffstat:
| M | TODO | | | 4 | ---- |
| M | cio.c | | | 38 | ++++++++++---------------------------- |
2 files changed, 10 insertions(+), 32 deletions(-)
diff --git a/TODO b/TODO
@@ -2,7 +2,3 @@
1. sndf() output should be limited to 512 chars (2.3).
2. strcase{cmp,str} are technically inadequate per (2.2) but who's counting?
- Might be nice to be able to log the raw IRC packets.
-- It would be really nice to be able to OpenBSD pledge down to tty, stdio after
- server connect but reconnect needs inet, dns, rpath (for system trust store).
- 1. rpath can *kind of* be solved by storing all certificate details in memory
- but loading the entire CA store into memory is a little silly for cio
diff --git a/cio.c b/cio.c
@@ -936,17 +936,13 @@ treset(void)
int
main(int argc, char *argv[])
{
-#ifdef __OpenBSD__
-if (pledge("stdio tty rpath inet dns", NULL) == -1)
- die("pledge");
-#endif /* __OpenBSD__ */
const char *user = getenv("USER");
const char *ircnick = getenv("IRCNICK");
snprintf(key, sizeof(key), "%s", getenv("IRCPASS"));
const char *server = SRV;
const char *port = PORT;
const char *err;
- int o, reconn, ping;
+ int o, ping;
signal(SIGPIPE, SIG_IGN);
while ((o = getopt(argc, argv, "hvTVn:c:u:s:p:l:")) >= 0)
@@ -998,10 +994,13 @@ if (pledge("stdio tty rpath inet dns", NULL) == -1)
atexit(treset);
tinit();
err = dial(server, port);
+#ifdef __OpenBSD__
+ if (pledge("stdio tty", NULL) == -1)
+ die("pledge");
+#endif /* __OpenBSD__ */
if (err) die("cio: %s", err);
chadd(server, 0);
sinit(nick, user);
- reconn = 0;
ping = 0;
while (!quit) {
struct timeval t = {.tv_sec = 5};
@@ -1011,41 +1010,24 @@ if (pledge("stdio tty rpath inet dns", NULL) == -1)
FD_ZERO(&wfs);
FD_ZERO(&rfs);
FD_SET(0, &rfs);
- if (!reconn) {
- FD_SET(srv.fd, &rfs);
- if (outp != outb)
- FD_SET(srv.fd, &wfs);
- }
+ FD_SET(srv.fd, &rfs);
+ if (outp != outb)
+ FD_SET(srv.fd, &wfs);
if (select(srv.fd + 1, &rfs, &wfs, 0, &t) < 0) {
if (errno == EINTR)
continue;
die("cio: select failed:");
}
- if (reconn) {
- hangup();
- if (reconn > MaxRecons)
- die("cio: link lost");
- pushf(0, "-!- Link lost, attempt %d/%d...", reconn++, MaxRecons);
- if (dial(server, port) != 0)
- continue;
- sinit(nick, user);
- for (struct Chan *c = chl; c < &chl[nch]; ++c)
- if (c->join)
- sndf("JOIN %s", c->name);
- reconn = 0;
- }
if (FD_ISSET(srv.fd, &rfs)) {
if (!srd()) {
- reconn = 1;
- continue;
+ die("cio: read error:");
}
}
if (FD_ISSET(srv.fd, &wfs)) {
size_t len = outp - outb;
int wr = ssl ? SSL_write(srv.ssl, outb, len) : write(srv.fd, outb, len);
if (wr <= 0) {
- reconn = 1;
- continue;
+ die("cio: write error:");
}
outp -= wr;
memmove(outb, outb + wr, outp - outb);