From: Timo Sirainen Date: Sat, 6 Mar 2010 12:04:42 +0000 (+0200) Subject: Set input stream names for mail file streams. X-Git-Tag: 2.0.beta4~119 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f0a2d04321ba456e5c5ba821c0d1ed9e8e0e2e08;p=thirdparty%2Fdovecot%2Fcore.git Set input stream names for mail file streams. --HG-- branch : HEAD --- diff --git a/src/lda/main.c b/src/lda/main.c index 5b01ebd52f..8a0743799a 100644 --- a/src/lda/main.c +++ b/src/lda/main.c @@ -404,6 +404,7 @@ int main(int argc, char *argv[]) i_fatal("Couldn't create internal raw storage: %s", errstr); if (path == NULL) { input = create_raw_stream(&ctx, 0, &mtime); + i_stream_set_name(input, "stdin"); box = mailbox_alloc(raw_ns->list, "Dovecot Delivery Mail", MAILBOX_FLAG_NO_INDEX_FILES); if (mailbox_open_stream(box, input) < 0) { diff --git a/src/lib-storage/index/cydir/cydir-mail.c b/src/lib-storage/index/cydir/cydir-mail.c index 7d231d215d..f8ef8bb1ac 100644 --- a/src/lib-storage/index/cydir/cydir-mail.c +++ b/src/lib-storage/index/cydir/cydir-mail.c @@ -113,6 +113,7 @@ cydir_mail_get_stream(struct mail *_mail, struct message_size *hdr_size, return -1; } mail->data.stream = i_stream_create_fd(fd, 0, TRUE); + i_stream_set_name(mail->data.stream, path); index_mail_set_read_buffer_size(_mail, mail->data.stream); } diff --git a/src/lib-storage/index/dbox-common/dbox-file.c b/src/lib-storage/index/dbox-common/dbox-file.c index e93f2aa4e5..a1845dbc1c 100644 --- a/src/lib-storage/index/dbox-common/dbox-file.c +++ b/src/lib-storage/index/dbox-common/dbox-file.c @@ -204,6 +204,7 @@ static int dbox_file_open_full(struct dbox_file *file, bool try_altpath, } file->input = i_stream_create_fd(file->fd, 0, FALSE); + i_stream_set_name(file->input, file->cur_path); i_stream_set_init_buffer_size(file->input, DBOX_READ_BLOCK_SIZE); return dbox_file_read_header(file); } diff --git a/src/lib-storage/index/maildir/maildir-mail.c b/src/lib-storage/index/maildir/maildir-mail.c index ec14b364c2..b647528991 100644 --- a/src/lib-storage/index/maildir/maildir-mail.c +++ b/src/lib-storage/index/maildir/maildir-mail.c @@ -13,12 +13,20 @@ #include #include +struct maildir_open_context { + int fd; + char *path; +}; + static int -do_open(struct maildir_mailbox *mbox, const char *path, int *fd) +do_open(struct maildir_mailbox *mbox, const char *path, + struct maildir_open_context *ctx) { - *fd = open(path, O_RDONLY); - if (*fd != -1) + ctx->fd = open(path, O_RDONLY); + if (ctx->fd != -1) { + ctx->path = i_strdup(path); return 1; + } if (errno == ENOENT) return 0; @@ -57,27 +65,32 @@ maildir_open_mail(struct maildir_mailbox *mbox, struct mail *mail, struct mail_private *p = (struct mail_private *)mail; struct istream *input; const char *path; - int fd = -1; + struct maildir_open_context ctx; *deleted_r = FALSE; + ctx.fd = -1; + ctx.path = NULL; + p->stats_open_lookup_count++; if (mail->uid != 0) { - if (maildir_file_do(mbox, mail->uid, do_open, &fd) < 0) + if (maildir_file_do(mbox, mail->uid, do_open, &ctx) < 0) return NULL; } else { path = maildir_save_file_get_path(mail->transaction, mail->seq); - if (do_open(mbox, path, &fd) <= 0) + if (do_open(mbox, path, &ctx) <= 0) return NULL; } - if (fd == -1) { + if (ctx.fd == -1) { *deleted_r = TRUE; return NULL; } - input = i_stream_create_fd(fd, 0, TRUE); + input = i_stream_create_fd(ctx.fd, 0, TRUE); + i_stream_set_name(input, ctx.path); index_mail_set_read_buffer_size(mail, input); + i_free(ctx.path); return input; } diff --git a/src/lib-storage/index/mbox/istream-raw-mbox.c b/src/lib-storage/index/mbox/istream-raw-mbox.c index 9fc255edce..2cdc97bda5 100644 --- a/src/lib-storage/index/mbox/istream-raw-mbox.c +++ b/src/lib-storage/index/mbox/istream-raw-mbox.c @@ -10,7 +10,7 @@ struct raw_mbox_istream { struct istream_private istream; time_t received_time, next_received_time; - char *path, *sender, *next_sender; + char *sender, *next_sender; uoff_t from_offset, hdr_offset, body_offset, mail_size; uoff_t input_peak_offset; @@ -30,7 +30,6 @@ static void i_stream_raw_mbox_destroy(struct iostream_private *stream) i_free(rstream->sender); i_free(rstream->next_sender); - i_free(rstream->path); i_stream_seek(rstream->istream.parent, rstream->istream.istream.v_offset); @@ -257,7 +256,8 @@ static ssize_t i_stream_raw_mbox_read(struct istream_private *stream) if (mbox_read_from_line(rstream) < 0) { if (stream->istream.v_offset != 0) { i_error("Next message unexpectedly corrupted in mbox file " - "%s at %"PRIuUOFF_T, rstream->path, + "%s at %"PRIuUOFF_T, + i_stream_get_name(&stream->istream), stream->istream.v_offset); } stream->pos = 0; @@ -358,7 +358,8 @@ static ssize_t i_stream_raw_mbox_read(struct istream_private *stream) /* istream_raw_mbox_set_next_offset() used invalid cached next_offset? */ i_error("Next message unexpectedly lost from mbox file " - "%s at %"PRIuUOFF_T" (%s)", rstream->path, + "%s at %"PRIuUOFF_T" (%s)", + i_stream_get_name(&stream->istream), rstream->hdr_offset + rstream->mail_size, rstream->mail_size_forced ? "cached" : "noncached"); rstream->eof = TRUE; @@ -423,17 +424,14 @@ i_stream_raw_mbox_stat(struct istream_private *stream, bool exact) return &stream->statbuf; } -struct istream * -i_stream_create_raw_mbox(struct istream *input, const char *path) +struct istream *i_stream_create_raw_mbox(struct istream *input) { struct raw_mbox_istream *rstream; - i_assert(path != NULL); i_assert(input->v_offset == 0); rstream = i_new(struct raw_mbox_istream, 1); - rstream->path = i_strdup(path); rstream->body_offset = (uoff_t)-1; rstream->mail_size = (uoff_t)-1; rstream->received_time = (time_t)-1; @@ -517,7 +515,8 @@ uoff_t istream_raw_mbox_get_header_offset(struct istream *stream) if (rstream->corrupted) { i_error("Unexpectedly lost From-line from mbox file %s at " - "%"PRIuUOFF_T, rstream->path, rstream->from_offset); + "%"PRIuUOFF_T, i_stream_get_name(stream), + rstream->from_offset); return (uoff_t)-1; } @@ -545,7 +544,8 @@ uoff_t istream_raw_mbox_get_body_offset(struct istream *stream) if (i_stream_raw_mbox_read(&rstream->istream) < 0) { if (rstream->corrupted) { i_error("Unexpectedly lost From-line from mbox file " - "%s at %"PRIuUOFF_T, rstream->path, + "%s at %"PRIuUOFF_T, + i_stream_get_name(stream), rstream->from_offset); } else { i_assert(rstream->body_offset != (uoff_t)-1); diff --git a/src/lib-storage/index/mbox/istream-raw-mbox.h b/src/lib-storage/index/mbox/istream-raw-mbox.h index 4f2705d1d6..f9ce166f39 100644 --- a/src/lib-storage/index/mbox/istream-raw-mbox.h +++ b/src/lib-storage/index/mbox/istream-raw-mbox.h @@ -4,8 +4,7 @@ /* Create a mbox stream for parsing mbox. Reading stops before From-line, you'll have to call istream_raw_mbox_next() to get to next message. path is used only for logging purposes. */ -struct istream *i_stream_create_raw_mbox(struct istream *input, - const char *path); +struct istream *i_stream_create_raw_mbox(struct istream *input); /* Return offset to beginning of the "\nFrom"-line. */ uoff_t istream_raw_mbox_get_start_offset(struct istream *stream); diff --git a/src/lib-storage/index/mbox/mbox-file.c b/src/lib-storage/index/mbox/mbox-file.c index 9aef60cae0..99a5232580 100644 --- a/src/lib-storage/index/mbox/mbox-file.c +++ b/src/lib-storage/index/mbox/mbox-file.c @@ -86,10 +86,10 @@ int mbox_file_open_stream(struct mbox_mailbox *mbox) i_stream_set_init_buffer_size(mbox->mbox_file_stream, MBOX_READ_BLOCK_SIZE); } + i_stream_set_name(mbox->mbox_file_stream, mbox->box.path); } - mbox->mbox_stream = i_stream_create_raw_mbox(mbox->mbox_file_stream, - mbox->box.path); + mbox->mbox_stream = i_stream_create_raw_mbox(mbox->mbox_file_stream); if (mbox->mbox_lock_type != F_UNLCK) istream_raw_mbox_set_locked(mbox->mbox_stream); return 0; diff --git a/src/lib-storage/index/raw/raw-storage.c b/src/lib-storage/index/raw/raw-storage.c index 9da9df532a..827923d0d5 100644 --- a/src/lib-storage/index/raw/raw-storage.c +++ b/src/lib-storage/index/raw/raw-storage.c @@ -82,6 +82,7 @@ static int raw_mailbox_open(struct mailbox *box) return -1; } box->input = i_stream_create_fd(fd, MAIL_READ_FULL_BLOCK_SIZE, TRUE); + i_stream_set_name(box->input, box->path); i_stream_set_init_buffer_size(box->input, MAIL_READ_FULL_BLOCK_SIZE); return index_storage_mailbox_open(box, FALSE); } diff --git a/src/plugins/zlib/zlib-plugin.c b/src/plugins/zlib/zlib-plugin.c index b4d0d45997..7c906cff17 100644 --- a/src/plugins/zlib/zlib-plugin.c +++ b/src/plugins/zlib/zlib-plugin.c @@ -340,6 +340,7 @@ static int zlib_mailbox_open_input(struct mailbox *box) return -1; } input = i_stream_create_fd(fd, MAX_INBUF_SIZE, FALSE); + i_stream_set_name(input, box->path); box->input = handler->create_istream(input, TRUE); i_stream_unref(&input); box->flags |= MAILBOX_FLAG_READONLY;