]> Nishi Git Mirror - okuu.git/commitdiff
should have fixed fd issue
authorNishi <nishi@nishi.boats>
Thu, 12 Sep 2024 15:29:22 +0000 (15:29 +0000)
committerNishi <nishi@nishi.boats>
Thu, 12 Sep 2024 15:29:22 +0000 (15:29 +0000)
git-svn-id: file:///raid/svn-personal/okuu/trunk@13 7d206d2a-66c2-044b-96de-ba755a9b3ba8

Bot/bot.c
Bot/news.c

index 8da91cb2558aa40f639a3b5c586c7437c13ff65b..51cc9f158e51883bda25efc920f14a48e128f302 100644 (file)
--- a/Bot/bot.c
+++ b/Bot/bot.c
@@ -16,6 +16,7 @@
 #include <stdbool.h>
 #include <dirent.h>
 #include <poll.h>
+#include <sys/wait.h>
 
 #include <sys/socket.h>
 #include <netinet/tcp.h>
@@ -42,7 +43,9 @@ extern int ircport;
 int ok_sock;
 struct sockaddr_in ok_addr;
 
-void ok_close(int sock) { shutdown(sock, SHUT_RDWR);close(sock); }
+void ok_close(int sock) {
+       while(close(sock) == 0);
+}
 
 void ok_bot_kill(int sig) {
        fprintf(stderr, "Shutdown\n");
@@ -241,7 +244,16 @@ void ok_bot(void) {
                                                }
                                        } else if(sentin[0] == '#') {
                                                /* This was sent in channel */
-                                               if(ok_news_write(nick, msg) != 0) {
+                                               pid_t pid = fork();
+                                               int code;
+                                               if(pid == 0){
+                                                       _exit(ok_news_write(nick, msg));
+                                               }else{
+                                                       int status;
+                                                       waitpid(pid, &status, 0);
+                                                       code = WEXITSTATUS(status);
+                                               }
+                                               if(code != 0) {
                                                        sprintf(construct, "PRIVMSG %s :Could not send the message to the USENET", sentin);
                                                        ircfw_socket_send_cmd(ok_sock, NULL, construct);
                                                }
index f2700e0c1784f5c89c2a959838abd5b72ae6dc51..4d9840c12cdf22ee2dd156125192a0cc6cb5edd6 100644 (file)
@@ -11,6 +11,7 @@
 #include <stdlib.h>
 #include <stdint.h>
 #include <sys/stat.h>
+#include <errno.h>
 
 #include <sys/socket.h>
 #include <netinet/tcp.h>
@@ -250,7 +251,7 @@ int ok_news_write(const char* nick, const char* message) {
        int nt_sock;
        struct sockaddr_in nt_addr;
        if((nt_sock = socket(PF_INET, SOCK_STREAM, 0)) < 0) {
-               fprintf(stderr, "Socket creation failure\n");
+               fprintf(stderr, "Socket creation failure: %s\n", strerror(errno));
                return 1;
        }