* Copyright (c) 2000-2012 by the citadel.org team
*
* This program is open source software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
+ * it under the terms of the GNU General Public License, version 3.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
* ** NOTE ** A word on the S_NETCONFIGS semaphore:
* This is a fairly high-level type of critical section. It ensures that no
* two threads work on the netconfigs files at the same time. Since we do
#include "file_ops.h"
#include "citadel_dirs.h"
#include "threads.h"
-
-#ifndef HAVE_SNPRINTF
-#include "snprintf.h"
-#endif
-
#include "context.h"
#include "netconfig.h"
#include "netspool.h"
#include "netmail.h"
#include "ctdl_module.h"
-
-
-
int read_spoolcontrol_file(SpoolControl **scc, char *filename)
{
FILE *fp;
const StrBuf *nexthop;
StrBuf *NextHop;
int i;
+ struct stat statbuf;
int nFailed = 0;
/* Step 1: consolidate files in the outbound queue into one file per neighbor node */
else {
size_t dsize;
size_t fsize;
- int fd;
+ int infd, outfd;
const char *err = NULL;
network_talking_to(SKEY(NextHop), NTT_ADD);
- IOB.fd = open(filename, O_RDONLY);
- if (IOB.fd == -1) {
+ infd = open(filename, O_RDONLY);
+ if (infd == -1) {
nFailed++;
QN_syslog(LOG_ERR,
"failed to open %s for reading due to %s; skipping.\n",
continue;
}
- fd = open(spooloutfilename,
+ outfd = open(spooloutfilename,
O_EXCL|O_CREAT|O_NONBLOCK|O_WRONLY,
S_IRUSR|S_IWUSR);
- if (fd == -1)
+ if (outfd == -1)
{
- fd = open(spooloutfilename,
- O_EXCL|O_NONBLOCK|O_WRONLY,
- S_IRUSR | S_IWUSR);
+ outfd = open(spooloutfilename,
+ O_EXCL|O_NONBLOCK|O_WRONLY,
+ S_IRUSR | S_IWUSR);
}
- if (fd == -1) {
+ if (outfd == -1) {
nFailed++;
QN_syslog(LOG_ERR,
"failed to open %s for reading due to %s; skipping.\n",
spooloutfilename, strerror(errno)
);
- close(IOB.fd);
+ close(infd);
network_talking_to(SKEY(NextHop), NTT_REMOVE);
continue;
}
- dsize = lseek(fd, 0, SEEK_END);
- fsize = lseek(IOB.fd, 0, SEEK_END);
-
- FDIOBufferInit(&FDIO, &IOB, fd, fsize + dsize);
+
+ dsize = lseek(outfd, 0, SEEK_END);
+ lseek(outfd, -dsize, SEEK_SET);
+
+ fstat(infd, &statbuf);
+ fsize = statbuf.st_size;
+/*
+ fsize = lseek(infd, 0, SEEK_END);
+*/
+ IOB.fd = infd;
+ FDIOBufferInit(&FDIO, &IOB, outfd, fsize + dsize);
FDIO.ChunkSendRemain = fsize;
FDIO.TotalSentAlready = dsize;
err = NULL;
+ errno = 0;
do {} while ((FileMoveChunked(&FDIO, &err) > 0) && (err == NULL));
if (err == NULL) {
unlink(filename);
spooloutfilename, strerror(errno)
);
/* whoops partial append?? truncate spooloutfilename again! */
- ftruncate(fd, dsize);
+ ftruncate(outfd, dsize);
}
FDIOBufferDelete(&FDIO);
- close(IOB.fd);
- close(fd);
+ close(infd);
+ close(outfd);
network_talking_to(SKEY(NextHop), NTT_REMOVE);
}
}