]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-program-client: Use iostream-temp rather than istream-seekable for seekable output.
authorStephan Bosch <stephan.bosch@dovecot.fi>
Sun, 25 Feb 2018 08:55:00 +0000 (09:55 +0100)
committerAki Tuomi <aki.tuomi@dovecot.fi>
Sun, 18 Mar 2018 10:53:18 +0000 (12:53 +0200)
This considerably simplifies the code.

src/lib-program-client/program-client-local.c
src/lib-program-client/program-client-private.h
src/lib-program-client/program-client-remote.c
src/lib-program-client/program-client.c

index 1570e39145f34cad5101d6a770d3b883d26117d0..f82bd468494a912fff342feda020531ec72b245b 100644 (file)
@@ -159,7 +159,7 @@ program_client_local_connect(struct program_client *pclient)
                        return -1;
                }
        }
-       if (pclient->output != NULL || pclient->output_seekable) {
+       if (pclient->output != NULL) {
                if (pipe(fd_out) < 0) {
                        i_error("pipe(out) failed: %m");
                        return -1;
index 9201a4e027f152b64b61d2d9dd9d44f33c0029e8..cf4f4d14c92a17e5164b0f100833e4db4dbb304a 100644 (file)
@@ -41,10 +41,8 @@ struct program_client {
        struct timeout *to;
        struct timeval start_time;
 
-       struct istream *input, *program_input, *seekable_output;
-       struct istream *dot_input;
+       struct istream *input, *program_input, *dot_input;
        struct ostream *output, *program_output, *dot_output;
-       char *temp_prefix;
 
        ARRAY(struct program_client_extra_fd) extra_fds;
 
index 6e5a1d9ee03901b007994584555e162a66d90e0a..63bf8616e1b6d37aa7c2d8938bb751b6f1b8acf7 100644 (file)
@@ -314,8 +314,8 @@ program_client_unix_connect(struct program_client *pclient)
                }
        }
 
-       pclient->fd_in = (prclient->noreply && pclient->output == NULL &&
-                         !pclient->output_seekable ? -1 : fd);
+       pclient->fd_in = (prclient->noreply && pclient->output == NULL ?
+                         -1 : fd);
        pclient->fd_out = fd;
        pclient->io = io_add(fd, IO_WRITE,
                             program_client_remote_connected, prclient);
@@ -397,8 +397,8 @@ program_client_net_connect_real(struct program_client_remote *prclient)
                return;
        }
 
-       pclient->fd_in = (prclient->noreply && pclient->output == NULL &&
-                         !pclient->output_seekable ? -1 : fd);
+       pclient->fd_in = (prclient->noreply && pclient->output == NULL ?
+                         -1 : fd);
        pclient->fd_out = fd;
        pclient->io = io_add(fd, IO_WRITE,
                             program_client_net_connected, prclient);
index c3d1b3d079617bff335a0fff8e5f7e3dcbb3d57c..c29473f4e888c8e4505cc733d3910620a78fe5da 100644 (file)
@@ -6,10 +6,10 @@
 #include "str.h"
 #include "safe-mkstemp.h"
 #include "istream-private.h"
-#include "istream-seekable.h"
 #include "ostream-dot.h"
 #include "istream-dot.h"
 #include "ostream.h"
+#include "iostream-temp.h"
 #include "lib-signals.h"
 
 #include "program-client-private.h"
@@ -31,32 +31,6 @@ program_client_callback(struct program_client *pclient, int result,
        callback(result, context);
 }
 
-static int
-program_client_seekable_fd_callback(const char **path_r, void *context)
-{
-       struct program_client *pclient = (struct program_client *)context;
-       string_t *path;
-       int fd;
-
-       path = t_str_new(128);
-       str_append(path, pclient->temp_prefix);
-       fd = safe_mkstemp(path, 0600, (uid_t)-1, (gid_t)-1);
-       if (fd == -1) {
-               i_error("safe_mkstemp(%s) failed: %m", str_c(path));
-               return -1;
-       }
-
-       /* we just want the fd, unlink it */
-       if (i_unlink(str_c(path)) < 0) {
-               /* shouldn't happen.. */
-               i_close_fd(&fd);
-               return -1;
-       }
-
-       *path_r = str_c(path);
-       return fd;
-}
-
 static void
 program_client_timeout(struct program_client *pclient)
 {
@@ -119,8 +93,7 @@ program_client_disconnect_extra_fds(struct program_client *pclient)
 void program_client_disconnected(struct program_client *pclient)
 {
        if (pclient->program_input != NULL) {
-               if (pclient->output_seekable ||
-                   pclient->set.use_dotstream)
+               if (pclient->set.use_dotstream)
                        i_stream_unref(&pclient->program_input);
                else
                        i_stream_destroy(&pclient->program_input);
@@ -300,20 +273,6 @@ void program_client_program_input(struct program_client *pclient)
        size_t size;
        int ret = 0;
 
-       /* initialize seekable output if required */
-       if (pclient->output_seekable && pclient->seekable_output == NULL) {
-               struct istream *input_list[2] = { input, NULL };
-
-               input = i_stream_create_seekable(input_list,
-                       MAX_OUTPUT_MEMORY_BUFFER,
-                       program_client_seekable_fd_callback, pclient);
-               i_stream_unref(&pclient->program_input);
-               pclient->program_input = input;
-
-               pclient->seekable_output = input;
-               i_stream_ref(pclient->seekable_output);
-       }
-
        if (input != NULL) {
                /* initialize dot stream if required */
                if (!pclient->input_dot_created &&
@@ -461,26 +420,23 @@ void program_client_set_output(struct program_client *pclient,
                o_stream_ref(output);
        pclient->output = output;
        pclient->output_seekable = FALSE;
-       i_free(pclient->temp_prefix);
 }
 
 void program_client_set_output_seekable(struct program_client *pclient,
                                        const char *temp_prefix)
 {
        o_stream_unref(&pclient->output);
-       pclient->temp_prefix = i_strdup(temp_prefix);
+       pclient->output = iostream_temp_create_sized(temp_prefix, 0,
+               "(program client seekable output)",
+               MAX_OUTPUT_MEMORY_BUFFER);
        pclient->output_seekable = TRUE;
 }
 
 struct istream *
 program_client_get_output_seekable(struct program_client *pclient)
 {
-       struct istream *input = pclient->seekable_output;
-
-       pclient->seekable_output = NULL;
-
-       i_stream_seek(input, 0);
-       return input;
+       i_assert(pclient->output_seekable);
+       return iostream_temp_finish(&pclient->output, IO_BLOCK_SIZE);
 }
 
 #undef program_client_set_extra_fd
@@ -582,10 +538,8 @@ void program_client_destroy(struct program_client **_pclient)
        i_stream_unref(&pclient->program_input);
        o_stream_unref(&pclient->program_output);
        o_stream_unref(&pclient->output);
-       i_stream_unref(&pclient->seekable_output);
 
        io_remove(&pclient->io);
-       i_free(pclient->temp_prefix);
 
        if (pclient->destroy != NULL)
                pclient->destroy(pclient);
@@ -599,8 +553,6 @@ void program_client_switch_ioloop(struct program_client *pclient)
                i_stream_switch_ioloop(pclient->input);
        if (pclient->program_input != NULL)
                i_stream_switch_ioloop(pclient->program_input);
-       if (pclient->seekable_output != NULL)
-               i_stream_switch_ioloop(pclient->seekable_output);
        if (pclient->output != NULL)
                o_stream_switch_ioloop(pclient->output);
        if (pclient->program_output != NULL)