]> PatchyGit - patchyircd.git/commitdiff
assume FOPEN_CLOEXEC exists
authorEgor <egor@patchysicp.xyz>
Thu, 12 Jun 2025 23:49:47 +0000 (02:49 +0300)
committerEgor <egor@patchysicp.xyz>
Thu, 12 Jun 2025 23:49:47 +0000 (02:49 +0300)
src/irc.cpp
src/main.cpp
src/netsock.h
src/passwd.cpp

index f21809b..349c0bc 100644 (file)
@@ -532,7 +532,7 @@ saslcleanup:
                if (!hash)
                        return 0; // TODO: error message
                memset(args[1], 0, strlen(args[1]));
-               FILE *f = fopen(getdatafile("newusers.txt"), "ab" FOPEN_CLOEXEC);
+               FILE *f = fopen(getdatafile("newusers.txt"), "abe");
                if (!f)
                        return 0; // TODO: error message
                fprintf(f, "%s:%s\n", args[0], hash);
@@ -803,7 +803,7 @@ saslcleanup:
                if (!is_registered(client))
                        return err_notregistered(client), sendbuf(client), 0;
                char line[512];
-               FILE *f = fopen(getdatafile("help.txt"), "r" FOPEN_CLOEXEC);
+               FILE *f = fopen(getdatafile("help.txt"), "re");
                if (f) {
                        rpl_helpstart(client), sendbuf(client);
                        while (fgets(line, 512, f)) {
@@ -830,7 +830,7 @@ saslcleanup:
                if (args[0] && strcmp(args[0], hostname) != 0)
                        return err_nosuchserver(client, args[0]), sendbuf(client), 0;
                char line[512];
-               FILE *f = fopen(getdatafile("admin.txt"), "r" FOPEN_CLOEXEC);
+               FILE *f = fopen(getdatafile("admin.txt"), "re");
                if (f) {
                        auto nextline = [f, &line]()->bool{
                                if (fgets(line, 512, f)) {
@@ -1286,7 +1286,7 @@ void sendLUSERS(struct client_data *client)
 
 void sendMOTD(struct client_data *client) {
        char line[512];
-       FILE *f = fopen(getdatafile("motd.txt"), "r" FOPEN_CLOEXEC);
+       FILE *f = fopen(getdatafile("motd.txt"), "re");
        if (f) {
                rpl_motdstart(client), sendbuf(client);
                while (fgets(line, 512, f)) {
index 3663412..3670f22 100644 (file)
@@ -292,7 +292,7 @@ int main(int argc, char *argv[])
                netpoll::reg(listener.sock, UV_READABLE);
        }
 
-       FILE *f = fopen(getdatafile("init.txt"), "rb" FOPEN_CLOEXEC);
+       FILE *f = fopen(getdatafile("init.txt"), "rbe");
        if (f) {
                struct client_data *fake = allocClient();
                fake->FD = INVALID_SOCKET;
@@ -344,7 +344,7 @@ int main(int argc, char *argv[])
                set_time(0);
                fclose(f);
        }
-       fchanlog = fopen(getdatafile("chanlog.txt"), "ab" FOPEN_CLOEXEC);
+       fchanlog = fopen(getdatafile("chanlog.txt"), "abe");
        if (fchanlog) {
                fprintf(fchanlog, "$0 AAA :server starting %lu\r\n", (unsigned long)get_time());
                fflush(fchanlog);
index 2213fc8..e5fc000 100644 (file)
@@ -56,8 +56,4 @@ typedef int SOCKET;
 #define net_perror(p) (perror((p)))
 #define net_wouldblock() (errno == EAGAIN || errno == EWOULDBLOCK)
 #define closesocket close
-#ifndef SOCK_CLOEXEC
-#error "SOCK_CLOEXEC is required"
-#endif
-#define FOPEN_CLOEXEC "e"
 #endif
index 569614c..018b4e0 100644 (file)
@@ -1,6 +1,5 @@
 // Copyright (c) 2022-2025 Egor
 // SPDX-License-Identifier: GPL-2.0-or-later
-#include "netsock.h"
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
@@ -49,10 +48,10 @@ char *password_hash(const char *pw)
 }
 int password_set(const char *key, const char *pw, const char *fn, const char *tmpfn)
 {
-       FILE *fi = fopen(fn, "rb" FOPEN_CLOEXEC);
+       FILE *fi = fopen(fn, "rbe");
        if (!fi)
                return -1;
-       FILE *fo = fopen(tmpfn, "wb" FOPEN_CLOEXEC);
+       FILE *fo = fopen(tmpfn, "wbe");
        if (!fo) {
                fclose(fi);
                return -1;
@@ -97,7 +96,7 @@ int password_set(const char *key, const char *pw, const char *fn, const char *tm
 char *password_get(const char *key, const char *fn)
 {
        // NOTE: there are probably a lot of timing leaks in here
-       FILE *fi = fopen(fn, "rb" FOPEN_CLOEXEC);
+       FILE *fi = fopen(fn, "rbe");
        if (!fi)
                return 0;
        int keylen = strlen(key);
@@ -131,7 +130,7 @@ int password_check(const char *key, const char *pw, const char *fn)
        }
 }
 const char *db_read_rhs(const char *key, const char *fn) {
-       FILE *fi = fopen(fn, "rb" FOPEN_CLOEXEC);
+       FILE *fi = fopen(fn, "rbe");
        if (!fi)
                return 0;
        int keylen = strlen(key);