From: Art Cancro Date: Tue, 7 Jan 2014 17:39:23 +0000 (-0500) Subject: Merge branch 'stable-82x' of ssh://git.citadel.org/appl/gitroot/citadel into stable-82x X-Git-Tag: v8.24~9 X-Git-Url: https://code.citadel.org/?a=commitdiff_plain;h=b5235ed837d76758397f3cb57a418eef62b807d1;hp=03c05b7e8b6670d8d0a2737840d4bf18f810431b;p=citadel.git Merge branch 'stable-82x' of ssh://git.citadel.org/appl/gitroot/citadel into stable-82x --- diff --git a/citadel/modules/migrate/serv_migrate.c b/citadel/modules/migrate/serv_migrate.c index 117eb21bb..c3446e0d2 100644 --- a/citadel/modules/migrate/serv_migrate.c +++ b/citadel/modules/migrate/serv_migrate.c @@ -524,6 +524,7 @@ void migr_xml_chardata(void *data, const XML_Char *s, int len) { old_len = migr_chardata_len; new_len = old_len + len; + new_buffer = realloc(migr_chardata, new_len + 1); if (new_buffer != NULL) { memcpy(&new_buffer[old_len], s, len); @@ -868,6 +869,7 @@ void migr_xml_end(void *data, const char *el) { cdb_store(CDB_MSGMAIN, &import_msgnum, sizeof(long), decoded_msg, msglen); free(decoded_msg); decoded_msg = NULL; + smi.meta_msgnum = import_msgnum; PutMetaData(&smi); syslog(LOG_INFO, "Imported message #%ld, size=%ld, refcount=%d, content-type: %s\n", import_msgnum, msglen, smi.meta_refcount, smi.meta_content_type); @@ -891,7 +893,7 @@ void migr_xml_end(void *data, const char *el) { void migr_do_import(void) { StrBuf *Buf; XML_Parser xp; - int linelen; + int Finished = 0; unbuffer_output(); Buf = NewStrBufPlain(NULL, SIZ); @@ -908,17 +910,23 @@ void migr_do_import(void) { cprintf("%d sock it to me\n", SEND_LISTING); unbuffer_output(); - while (CtdlClientGetLine(Buf) >= 0 && strcmp(ChrPtr(Buf), "000")) { - linelen = StrLength(Buf); - StrBufAppendBufPlain(Buf, HKEY("\n"), 0); + client_set_inbound_buf(SIZ * 10); + while (!Finished && client_read_random_blob(Buf, -1) >= 0) { + if ((StrLength(Buf) > 4) && + !strcmp(ChrPtr(Buf) + StrLength(Buf) - 4, "000\n")) + { + Finished = 1; + StrBufCutAt(Buf, StrLength(Buf) - 4, NULL); + } if (server_shutting_down) break; // Should we break or return? - if (linelen == 0) + if (StrLength(Buf) == 0) continue; - XML_Parse(xp, ChrPtr(Buf), linelen, 0); + XML_Parse(xp, ChrPtr(Buf), StrLength(Buf), 0); + FlushStrBuf(Buf); } XML_Parse(xp, "", 0, 1); diff --git a/citadel/sysconfig.h b/citadel/sysconfig.h index f0c9bd2be..9b784816e 100644 --- a/citadel/sysconfig.h +++ b/citadel/sysconfig.h @@ -88,7 +88,6 @@ #define SYSCONFIGROOM "Local System Configuration" #define SMTP_SPOOLOUT_ROOM "__CitadelSMTPspoolout__" #define FNBL_QUEUE_ROOM "__CitadelFNBLqueue__" -#define PAGER_QUEUE_ROOM "__CitadelPagerQueue__" /* * Where we keep messages containing the vCards that source our directory. It * makes no sense to change this, because you'd have to change it on every diff --git a/citadel/utils/sendcommand.c b/citadel/utils/sendcommand.c index 6146dbb65..5ee87fd41 100644 --- a/citadel/utils/sendcommand.c +++ b/citadel/utils/sendcommand.c @@ -150,6 +150,8 @@ int main(int argc, char **argv) char relhome[PATH_MAX]=""; char ctdldir[PATH_MAX]=CTDLDIR; + StartLibCitadel(SIZ); + /* Parse command line */ while ((a = getopt(argc, argv, "h:w:")) != EOF) { switch (a) { @@ -179,7 +181,7 @@ int main(int argc, char **argv) ); fflush(stderr); -// alarm(watchdog); + alarm(watchdog); serv_sock = uds_connectsock(file_citadel_admin_socket); serv_gets(buf); @@ -210,8 +212,10 @@ int main(int argc, char **argv) IOB.fd = serv_sock; FDIOBufferInit(&FDIO, &IOB, fileno(stdin), -1); - while (FileSendChunked(&FDIO, &ErrStr)); + while (FileSendChunked(&FDIO, &ErrStr) >= 0); alarm(watchdog); /* reset the watchdog timer */ + if (ErrStr != NULL) + fprintf(stderr, "Error while piping stuff: %s\n", ErrStr); FDIOBufferDelete(&FDIO); FreeStrBuf(&IOB.Buf); serv_puts("000"); @@ -251,7 +255,7 @@ int main(int argc, char **argv) } StrBufAppendBuf(OutBuf, Line, 0); StrBufAppendBufPlain(OutBuf, HKEY("\n"), 0); -// alarm(watchdog); /* reset the watchdog timer */ + alarm(watchdog); /* reset the watchdog timer */ break; case eBufferNotEmpty: break; diff --git a/libcitadel/lib/stringbuf.c b/libcitadel/lib/stringbuf.c index a245c3c37..ff44368f1 100644 --- a/libcitadel/lib/stringbuf.c +++ b/libcitadel/lib/stringbuf.c @@ -3936,15 +3936,23 @@ inline static void FDIOBufferFlush(FDIOBuffer *FDB) void FDIOBufferInit(FDIOBuffer *FDB, IOBuffer *IO, int FD, long TotalSendSize) { FDIOBufferFlush(FDB); - FDB->ChunkSize = - FDB->TotalSendSize = TotalSendSize; + + FDB->TotalSendSize = TotalSendSize; + if (TotalSendSize > 0) + FDB->ChunkSize = TotalSendSize; + else + { + TotalSendSize = SIZ * 10; + FDB->ChunkSize = TotalSendSize; + } FDB->IOB = IO; + #ifdef LINUX_SPLICE if (EnableSplice) pipe(FDB->SplicePipe); else #endif - FDB->ChunkBuffer = NewStrBufPlain(NULL, TotalSendSize + 1); + FDB->ChunkBuffer = NewStrBufPlain(NULL, TotalSendSize+ 1); FDB->OtherFD = FD; } @@ -3971,68 +3979,159 @@ void FDIOBufferDelete(FDIOBuffer *FDB) int FileSendChunked(FDIOBuffer *FDB, const char **Err) { ssize_t sent, pipesize; -#ifdef LINUX_SPLICE - if (EnableSplice) + + if (FDB->TotalSendSize > 0) { - if (FDB->PipeSize == 0) +#ifdef LINUX_SPLICE + if (EnableSplice) { - pipesize = splice(FDB->OtherFD, - &FDB->TotalSentAlready, - FDB->SplicePipe[1], - NULL, - FDB->ChunkSendRemain, - SPLICE_F_MOVE); + if (FDB->PipeSize == 0) + { + pipesize = splice(FDB->OtherFD, + &FDB->TotalSentAlready, + FDB->SplicePipe[1], + NULL, + FDB->ChunkSendRemain, + SPLICE_F_MOVE); - if (pipesize == -1) + if (pipesize == -1) + { + *Err = strerror(errno); + return pipesize; + } + FDB->PipeSize = pipesize; + } + sent = splice(FDB->SplicePipe[0], + NULL, + FDB->IOB->fd, + NULL, + FDB->PipeSize, + SPLICE_F_MORE | SPLICE_F_MOVE | SPLICE_F_NONBLOCK); + if (sent == -1) { *Err = strerror(errno); - return pipesize; + return sent; } - FDB->PipeSize = pipesize; + FDB->PipeSize -= sent; + FDB->ChunkSendRemain -= sent; + return sent; } - sent = splice(FDB->SplicePipe[0], - NULL, - FDB->IOB->fd, - NULL, - FDB->PipeSize, - SPLICE_F_MORE | SPLICE_F_MOVE | SPLICE_F_NONBLOCK); - if (sent == -1) + else +#endif { - *Err = strerror(errno); - return sent; + char *pRead; + long nRead = 0; + + pRead = FDB->ChunkBuffer->buf; + while ((FDB->ChunkBuffer->BufUsed < FDB->TotalSendSize) && (nRead >= 0)) + { + nRead = read(FDB->OtherFD, pRead, FDB->TotalSendSize - FDB->ChunkBuffer->BufUsed); + if (nRead > 0) { + FDB->ChunkBuffer->BufUsed += nRead; + FDB->ChunkBuffer->buf[FDB->ChunkBuffer->BufUsed] = '\0'; + } + else if (nRead == 0) {} + else return nRead; + } + + nRead = write(FDB->IOB->fd, + FDB->ChunkBuffer->buf + FDB->TotalSentAlready, + FDB->ChunkBuffer->BufUsed - FDB->TotalSentAlready); + + if (nRead >= 0) { + FDB->TotalSentAlready += nRead; + FDB->ChunkSendRemain -= nRead; + return FDB->ChunkSendRemain; + } + else { + return nRead; + } } - FDB->PipeSize -= sent; - FDB->ChunkSendRemain -= sent; - return sent; } else -#endif { - char *pRead; - long nRead = 0; - - pRead = FDB->ChunkBuffer->buf; - while ((FDB->ChunkBuffer->BufUsed < FDB->TotalSendSize) && (nRead >= 0)) +#ifdef LINUX_SPLICE + if (EnableSplice) { - nRead = read(FDB->OtherFD, pRead, FDB->TotalSendSize - FDB->ChunkBuffer->BufUsed); - if (nRead > 0) { - FDB->ChunkBuffer->BufUsed += nRead; - FDB->ChunkBuffer->buf[FDB->ChunkBuffer->BufUsed] = '\0'; + if (FDB->PipeSize == 0) + { + pipesize = splice(FDB->OtherFD, + &FDB->TotalSentAlready, + FDB->SplicePipe[1], + NULL, + SIZ * 10, + SPLICE_F_MOVE); + + if (pipesize == -1) + { + *Err = strerror(errno); + return pipesize; + } + FDB->PipeSize = pipesize; + if (pipesize == 0) + return -1; } - else if (nRead == 0) {} - else return nRead; - + sent = splice(FDB->SplicePipe[0], + NULL, + FDB->IOB->fd, + NULL, + FDB->PipeSize, + SPLICE_F_MORE | SPLICE_F_MOVE | SPLICE_F_NONBLOCK); + if (sent == -1) + { + *Err = strerror(errno); + return sent; + } + FDB->PipeSize -= sent; + FDB->ChunkSendRemain -= sent; + return sent; } + else +#endif + { + char *pRead; + long nRead = 0; - nRead = write(FDB->IOB->fd, FDB->ChunkBuffer->buf + FDB->TotalSentAlready, FDB->ChunkSendRemain); + pRead = FDB->ChunkBuffer->buf; + while ((FDB->ChunkSendRemain == 0) && + (FDB->ChunkBuffer->BufUsed < FDB->ChunkBuffer->BufSize) && + (nRead >= 0)) + { + FDB->TotalSentAlready = 0; + nRead = read(FDB->OtherFD, pRead, FDB->ChunkBuffer->BufSize - FDB->ChunkBuffer->BufUsed); + if (nRead > 0) { + FDB->ChunkBuffer->BufUsed += nRead; + FDB->ChunkBuffer->buf[FDB->ChunkBuffer->BufUsed] = '\0'; + FDB->ChunkSendRemain += nRead; + } + else if (nRead == 0) + { + return -1; + } + else + { + *Err = strerror(errno); + return nRead; + } + } - if (nRead >= 0) { - FDB->TotalSentAlready += nRead; - FDB->ChunkSendRemain -= nRead; - return FDB->ChunkSendRemain; - } - else { - return nRead; + nRead = write(FDB->IOB->fd, + FDB->ChunkBuffer->buf + FDB->TotalSentAlready, + FDB->ChunkBuffer->BufUsed - FDB->TotalSentAlready); + + if (nRead >= 0) { + FDB->TotalSentAlready += nRead; + FDB->ChunkSendRemain -= nRead; + if (FDB->ChunkSendRemain == 0) + { + FDB->ChunkBuffer->BufUsed = 0; + FDB->TotalSentAlready = 0; + } + return FDB->ChunkSendRemain; + } + else { + return nRead; + } } } }