]> PatchyGit - patchyircd.git/commitdiff
output everything to stderr
authorEgor <egor@patchysicp.xyz>
Wed, 11 May 2022 17:29:28 +0000 (20:29 +0300)
committerEgor <egor@patchysicp.xyz>
Wed, 11 May 2022 17:31:04 +0000 (20:31 +0300)
NetSock/netsock.c
irc.c
main.c
net.c

index 540a323..f2dd72b 100644 (file)
@@ -47,8 +47,7 @@ void net_perror(const char *p)
 
 // Init and shutdown
 void net_init(void) {
-       puts("[NetSock]: NetSock initializing...");
-       fflush(stdout);
+       fprintf(stderr, "[NetSock]: NetSock initializing...\n");
        // Initialize WSA
 #if defined(_WIN32)
        int WStartCode = WSAStartup(MAKEWORD(2, 0), &net_wd);
@@ -56,25 +55,21 @@ void net_init(void) {
                fprintf(stderr, "Winsock API startup failed: %s\n", net_strerror(WStartCode));
                exit(EXIT_FAILURE);
        }
-       printf("[NetSock]: WinSock initialized V%d.%d!\n",LOBYTE(net_wd.wVersion), HIBYTE(net_wd.wVersion));
-       fflush(stdout);
+       fprintf(stderr, "[NetSock]: WinSock initialized V%d.%d!\n",LOBYTE(net_wd.wVersion), HIBYTE(net_wd.wVersion));
 #endif
 }
 void net_cleanup(void) {
-       puts("[NetSock]: NetSock cleaning up...");
-       fflush(stdout);
+       fprintf(stderr, "[NetSock]: NetSock cleaning up...\n");
        // Initialize WSA
 #if defined(_WIN32)
        WSACleanup();
-       puts("[NetSock]: WinSock cleaned up! (probably)");
-       fflush(stdout);
+       fprintf(stderr, "[NetSock]: WinSock cleaned up! (probably)\n");
 #endif
 }
 
 // Misc
 ssize_t send_log(SOCKET socket, const char *buffer, size_t length, int flags) {
-       printf("SERVER %"PRISocket": %.*s", socket, (int)length, (char*)buffer);
-       fflush(stdout);
+       fprintf(stderr, "SERVER %"PRISocket": %.*s", socket, (int)length, (char*)buffer);
        if (socket != INVALID_SOCKET)
                return send(socket, buffer, length, flags);
        else
@@ -83,8 +78,7 @@ ssize_t send_log(SOCKET socket, const char *buffer, size_t length, int flags) {
 ssize_t recv_log(SOCKET socket, char *buffer, size_t length, int flags) {
        ssize_t bytesRead = recv(socket,buffer,length,flags);
        if(bytesRead > 0) {
-               printf("CLIENT %"PRISocket": %.*s", socket, (int)length, (char*)buffer);
-               fflush(stdout);
+               fprintf(stderr, "CLIENT %"PRISocket": %.*s", socket, (int)length, (char*)buffer);
        }
        return bytesRead;
 }
diff --git a/irc.c b/irc.c
index 9a5c5eb..84eb689 100644 (file)
--- a/irc.c
+++ b/irc.c
@@ -116,14 +116,12 @@ int parsePacket(struct client_data *client) {
                        if (end > p && end[-1] == '\r')
                                *--end = '\n';
                        if (memchr(p, '\0', end-p)) {
-                               printf("Client %"PRISocket" sent a NULL\n", client->FD);
-                               fflush(stdout);
+                               fprintf(stderr, "Client %"PRISocket" sent a NULL\n", client->FD);
                                killConnection(client, false);
                                return 1; // null detected
                        }
                        if (memchr(p, '\r', end-p)) {
-                               printf("Client %"PRISocket" sent an extra CR\n", client->FD);
-                               fflush(stdout);
+                               fprintf(stderr, "Client %"PRISocket" sent an extra CR\n", client->FD);
                                killConnection(client, false);
                                return 1; // internal \r detected
                        }
@@ -168,13 +166,13 @@ int parsePacket(struct client_data *client) {
                }
                args[argc] = NULL;
        }
-       printf("parsed %"PRISocket": %s", client->FD, command);
+       fprintf(stderr, "parsed %"PRISocket": %s", client->FD, command);
        if (strcmp(command, "PASS") != 0 && strcmp(command, "OPER") != 0) {
                for (int i = 0; i < argc; i++){
-                       printf(" %d:%s", i, args[i]);
+                       fprintf(stderr, " %d:%s", i, args[i]);
                }
        }
-       printf("\n");
+       fprintf(stderr, "\n");
        return processPacket(client, source, command, argc, args);
 }
 int processPacket(struct client_data *client, char *source, char *command, int argc, char *args[]) {
diff --git a/main.c b/main.c
index 685c2a8..9f036bd 100644 (file)
--- a/main.c
+++ b/main.c
@@ -145,9 +145,8 @@ void accept_from_sock(SOCKET serverSocket, struct tls *ctx)
                        strcpy(client_addr, "?");
                        port = 0;
                }
-               printf("Connection accepted from Socket: %"PRISocket", IP: %s PORT: %d\n", newSocket,
+               fprintf(stderr, "Connection accepted from Socket: %"PRISocket", IP: %s PORT: %d\n", newSocket,
                                client_addr, port);
-               fflush(stdout);
                struct tls *cctx = NULL;
                if (ctx) {
 #ifdef HAS_TLS
@@ -184,8 +183,7 @@ int main() {
        struct tls *listeners_tls[4];
        int listener_count = 0;
        setlocale(LC_ALL, "C");
-       puts("[PatchyIRCD]: Starting up...");
-       fflush(stdout);
+       fprintf(stderr, "[PatchyIRCD]: Starting up...\n");
 
        net_init();
        set_handler();
@@ -352,8 +350,7 @@ int main() {
                                recvProc(clients[i]);
        }
 
-       puts("[PatchyIRCD]: Cleaning up...");
-       fflush(stdout);
+       fprintf(stderr, "[PatchyIRCD]: Cleaning up...\n");
        for (int i = 0; i < CLIENTS; i++)
                if (clients[i])
                        killConnection(clients[i], false);
diff --git a/net.c b/net.c
index a534f3e..315c55b 100644 (file)
--- a/net.c
+++ b/net.c
@@ -14,10 +14,8 @@ void killConnection(struct client_data *cl, bool byChoice) {
        for (int i = 0; i < CLIENTS; i++)
                if(clients[i] == cl)
                        clients[i] = 0;
-       if (cl->peername) {
-               printf("Client disconnected from Socket: %"PRISocket", IP: %s PORT: %d\n", cl->FD, cl->peername, cl->peerport);
-               fflush(stdout);
-       }
+       if (cl->peername)
+               fprintf(stderr, "Client disconnected from Socket: %"PRISocket", IP: %s PORT: %d\n", cl->FD, cl->peername, cl->peerport);
        // Start GitHub Copilot
        if(!byChoice && cl->nick && cl->username) {
                msg_quit(cl, "", "Has left the building (Forced)");