Changed serv_network.c receive_spool to remove the use of mv.
authorDave West <davew@uncensored.citadel.org>
Fri, 5 Oct 2007 00:34:49 +0000 (00:34 +0000)
committerDave West <davew@uncensored.citadel.org>
Fri, 5 Oct 2007 00:34:49 +0000 (00:34 +0000)
This fixed the boom I was getting.
It seems that syscall system may not be thread safe on some systems
(probably old ones).

citadel/modules/network/serv_network.c
citadel/server.h

index 7a7e54f584731a0d10f801ac45c5e69672f0b9c6..4208952d30f870076507d1604db6be861c5140b1 100644 (file)
@@ -1666,8 +1666,9 @@ void receive_spool(int sock, char *remote_nodename) {
        char buf[SIZ];
        static char pbuf[IGNET_PACKET_SIZE];
        char tempfilename[PATH_MAX];
+       char filename[PATH_MAX];
        long plen;
-       FILE *fp;
+       FILE *fp, *newfp;
 
        CtdlMakeTempFileName(tempfilename, sizeof tempfilename);
        if (sock_puts(sock, "NDOP") < 0) return;
@@ -1726,15 +1727,30 @@ void receive_spool(int sock, char *remote_nodename) {
                lprintf(CTDL_NOTICE, "Received %ld octets from <%s>\n",
                                download_len, remote_nodename);
        lprintf(CTDL_DEBUG, "%s\n", buf);
-       /* TODO: make move inline. forking is verry expensive. */
+       
+       /* Now copy the temp file to its permanent location.
+        * (We copy instead of link because they may be on different filesystems)
+        */
+       begin_critical_section(S_NETSPOOL);
        snprintf(buf, 
                         sizeof buf, 
-                        "mv %s %s/%s.%ld",
-                        tempfilename, 
+                        "%s/%s.%ld",
                         ctdl_netin_dir,
                         remote_nodename, 
                         (long) getpid());
-       system(buf);
+       fp = fopen(tempfilename, "r");
+       if (fp != NULL) {
+               newfp = fopen(filename, "w");
+               if (newfp != NULL) {
+                       while (fgets(buf, sizeof buf, fp) != NULL) {
+                               fprintf(newfp, "%s", buf);
+                       }
+                       fclose(newfp);
+                       fclose(fp);
+               }
+       }
+       end_critical_section(S_NETSPOOL);
+       unlink(tempfilename);
 }
 
 
index 3913cee5885ec64b20f6ef841c1679b10fef7fed..98f0755f3fa0a482a55828682a3e52320e601e9e 100644 (file)
@@ -239,6 +239,7 @@ enum {
        S_SIEVELIST,
        S_CHKPWD,
        S_LOG,
+       S_NETSPOOL,
        MAX_SEMAPHORES
 };