The event is required.
}
struct program_client *
-program_client_local_create(const char *bin_path,
+program_client_local_create(struct event *event, const char *bin_path,
const char *const *args,
const struct program_client_parameters *params)
{
pool = pool_alloconly_create("program client local", 1024);
plclient = p_new(pool, struct program_client_local, 1);
- program_client_init(&plclient->client, pool, label, args, params);
+ program_client_init(&plclient->client, pool, event, label, args, params);
plclient->client.connect = program_client_local_connect;
plclient->client.close_output = program_client_local_close_output;
plclient->client.switch_ioloop = program_client_local_switch_ioloop;
const char *label);
void program_client_init(struct program_client *pclient, pool_t pool,
- const char *initial_label,
+ struct event *event, const char *initial_label,
const char *const *args,
const struct program_client_parameters *params)
ATTR_NULL(5);
}
struct program_client *
-program_client_unix_create(const char *socket_path, const char *const *args,
+program_client_unix_create(struct event *event,
+ const char *socket_path, const char *const *args,
const struct program_client_parameters *params)
{
struct program_client_remote *prclient;
pool = pool_alloconly_create("program client unix", 1024);
prclient = p_new(pool, struct program_client_remote, 1);
- program_client_init(&prclient->client, pool, label, args, params);
+ program_client_init(&prclient->client, pool, event, label, args, params);
prclient->client.connect = program_client_unix_connect;
prclient->client.close_output = program_client_remote_close_output;
prclient->client.disconnect = program_client_remote_disconnect;
}
struct program_client *
-program_client_net_create(const char *host, in_port_t port,
+program_client_net_create(struct event *event, const char *host, in_port_t port,
const char *const *args,
const struct program_client_parameters *params)
{
pool = pool_alloconly_create("program client net", 1024);
prclient = p_new(pool, struct program_client_remote, 1);
- program_client_init(&prclient->client, pool, label, args, params);
+ program_client_init(&prclient->client, pool, event, label, args, params);
prclient->client.connect = program_client_net_connect_init;
prclient->client.close_output = program_client_remote_close_output;
prclient->client.disconnect = program_client_remote_disconnect;
}
struct program_client *
-program_client_net_create_ips(const struct ip_addr *ips, size_t ips_count,
+program_client_net_create_ips(struct event *event,
+ const struct ip_addr *ips, size_t ips_count,
in_port_t port,
const char *const *args,
const struct program_client_parameters *params)
pool = pool_alloconly_create("program client net", 1024);
prclient = p_new(pool, struct program_client_remote, 1);
- program_client_init(&prclient->client, pool, label, args, params);
+ program_client_init(&prclient->client, pool, event, label, args, params);
prclient->client.connect = program_client_net_connect_init;
prclient->client.close_output = program_client_remote_close_output;
prclient->client.disconnect = program_client_remote_disconnect;
}
void program_client_init(struct program_client *pclient, pool_t pool,
- const char *initial_label, const char *const *args,
+ struct event *event, const char *initial_label,
+ const char *const *args,
const struct program_client_parameters *params)
{
pclient->pool = pool;
+ pclient->event = event_create(event);
if (args != NULL)
pclient->args = p_strarray_dup(pool, args);
pclient->fd_in = -1;
pclient->fd_out = -1;
- if (params == NULL)
- pclient->event = event_create(NULL);
- else {
+ if (params != NULL) {
pclient->params = *params;
pclient->params.dns_client_socket_path =
p_strdup(pool, params->dns_client_socket_path);
-
- pclient->event = event_create(params->event);
}
program_client_set_label(pclient, initial_label);
pclient->switch_ioloop(pclient);
}
-int program_client_create(const char *uri, const char *const *args,
+int program_client_create(struct event *event, const char *uri,
+ const char *const *args,
const struct program_client_parameters *params,
struct program_client **pc_r, const char **error_r)
{
const char *suffix;
if (str_begins(uri, "exec:", &suffix)) {
- *pc_r = program_client_local_create(suffix, args, params);
+ *pc_r = program_client_local_create(event, suffix, args, params);
return 0;
} else if (str_begins(uri, "unix:", &suffix)) {
- *pc_r = program_client_unix_create(suffix, args, params);
+ *pc_r = program_client_unix_create(event, suffix, args, params);
return 0;
} else if (str_begins(uri, "tcp:", &suffix)) {
const char *host;
"must be host:port in '%s'", suffix);
return -1;
}
- *pc_r = program_client_net_create(host, port, args, params);
+ *pc_r = program_client_net_create(event, host, port, args, params);
return 0;
} else {
*error_r = t_strdup_printf(
unsigned int input_idle_timeout_msecs;
const char *dns_client_socket_path;
- /* Event to use for the program client. */
- struct event *event;
-
/* use o_stream_dot, which is mainly useful to make sure that an
unexpectedly closed connection doesn't cause the partial input to
be accepted as valid and complete program input. This is always
void *context);
struct program_client *
-program_client_local_create(const char *bin_path, const char *const *args,
+program_client_local_create(struct event *event,
+ const char *bin_path, const char *const *args,
const struct program_client_parameters *params)
ATTR_NULL(3);
struct program_client *
-program_client_unix_create(const char *socket_path, const char *const *args,
+program_client_unix_create(struct event *event,
+ const char *socket_path, const char *const *args,
const struct program_client_parameters *params);
struct program_client *
-program_client_net_create(const char *host, in_port_t port,
+program_client_net_create(struct event *event,
+ const char *host, in_port_t port,
const char *const *args,
const struct program_client_parameters *params);
struct program_client *
-program_client_net_create_ips(const struct ip_addr *ips, size_t ips_count,
+program_client_net_create_ips(struct event *event,
+ const struct ip_addr *ips, size_t ips_count,
in_port_t port, const char *const *args,
const struct program_client_parameters *params);
-int program_client_create(const char *uri, const char *const *args,
+int program_client_create(struct event *event, const char *uri,
+ const char *const *args,
const struct program_client_parameters *params,
struct program_client **pc_r, const char **error_r);
.client_connect_timeout_msecs = 10000,
.input_idle_timeout_msecs = 5000,
};
+static struct event *event;
static void test_program_success(void)
{
test_begin("test_program_success");
- pc = program_client_local_create("/bin/echo", args, &pc_params);
+ pc = program_client_local_create(event, "/bin/echo", args, &pc_params);
buffer_t *output = buffer_create_dynamic(default_pool, 16);
struct ostream *os = test_ostream_create(output);
test_begin("test_program_io (sync)");
- pc = program_client_local_create("/bin/cat", args, &pc_params);
+ pc = program_client_local_create(event, "/bin/cat", args, &pc_params);
struct istream *is = test_istream_create(pclient_test_io_string);
program_client_set_input(pc, is);
prev_ioloop = current_ioloop;
ioloop = io_loop_create();
- pc = program_client_local_create("/bin/cat", args, &pc_params);
+ pc = program_client_local_create(event, "/bin/cat", args, &pc_params);
struct istream *is = test_istream_create(pclient_test_io_string);
program_client_set_input(pc, is);
test_begin("test_program_failure");
- pc = program_client_local_create("/bin/false", args, &pc_params);
+ pc = program_client_local_create(event, "/bin/false", args, &pc_params);
buffer_t *output = buffer_create_dynamic(default_pool, 16);
struct ostream *os = test_ostream_create(output);
test_begin("test_program_io (big)");
- pc = program_client_local_create("/bin/sh", args, &pc_params);
+ pc = program_client_local_create(event, "/bin/sh", args, &pc_params);
/* make big input with only a small reference string */
struct istream *is1 = test_istream_create(pclient_test_io_string);
params.client_connect_timeout_msecs = 0;
params.input_idle_timeout_msecs = 0;
- pc = program_client_local_create("/bin/sh", args, ¶ms);
+ pc = program_client_local_create(event, "/bin/sh", args, ¶ms);
test_assert(program_client_run(pc) == 1);
lib_init();
- pc_params.event = event_create(NULL);
+ event = event_create(NULL);
while ((c = getopt(argc, argv, "D")) > 0) {
switch (c) {
case 'D':
- event_set_forced_debug(pc_params.event, TRUE);
+ event_set_forced_debug(event, TRUE);
break;
default:
i_fatal("Usage: %s [-D]", argv[0]);
lib_signals_deinit();
io_loop_destroy(&ioloop);
- event_unref(&pc_params.event);
+ event_unref(&event);
lib_deinit();
return ret;
}
.client_connect_timeout_msecs = 5000,
.input_idle_timeout_msecs = 10000,
};
+struct event *event;
static struct test_server {
struct ioloop *ioloop;
test_begin("test_program_success");
pc_params.no_reply = FALSE;
- pc = program_client_net_create("127.0.0.1", test_globals.port, args,
- &pc_params);
+ pc = program_client_net_create(event, "127.0.0.1", test_globals.port,
+ args, &pc_params);
buffer_t *output = buffer_create_dynamic(default_pool, 16);
struct ostream *os = test_ostream_create(output);
int ret = -2;
pc_params.no_reply = FALSE;
- pc = program_client_net_create("127.0.0.1", test_globals.port, args,
- &pc_params);
+ pc = program_client_net_create(event, "127.0.0.1", test_globals.port,
+ args, &pc_params);
struct istream *is = test_istream_create(pclient_test_io_string);
program_client_set_input(pc, is);
test_begin("test_program_failure");
pc_params.no_reply = FALSE;
- pc = program_client_net_create("127.0.0.1", test_globals.port, args,
- &pc_params);
+ pc = program_client_net_create(event, "127.0.0.1", test_globals.port,
+ args, &pc_params);
buffer_t *output = buffer_create_dynamic(default_pool, 16);
struct ostream *os = test_ostream_create(output);
test_begin("test_program_noreply");
pc_params.no_reply = TRUE;
- pc = program_client_net_create("127.0.0.1", test_globals.port, args,
- &pc_params);
+ pc = program_client_net_create(event, "127.0.0.1", test_globals.port,
+ args, &pc_params);
program_client_run_async(pc, test_program_async_callback, &ret);
}
pc_params.no_reply = TRUE;
- pc = program_client_net_create_ips(ips, N_ELEMENTS(ips),
+ pc = program_client_net_create_ips(event, ips, N_ELEMENTS(ips),
test_globals.port, args,
&pc_params);
lib_init();
- pc_params.event = event_create(NULL);
+ event = event_create(NULL);
while ((c = getopt(argc, argv, "D")) > 0) {
switch (c) {
case 'D':
- event_set_forced_debug(pc_params.event, TRUE);
+ event_set_forced_debug(event, TRUE);
break;
default:
i_fatal("Usage: %s [-D]", argv[0]);
ret = test_run(tests);
- event_unref(&pc_params.event);
+ event_unref(&event);
lib_deinit();
return ret;
}
.client_connect_timeout_msecs = 1000,
.input_idle_timeout_msecs = 5000,
};
+static struct event *event;
static struct test_server {
struct ioloop *ioloop;
test_begin("test_program_success");
pc_params.no_reply = FALSE;
- pc = program_client_unix_create(TEST_SOCKET, args, &pc_params);
+ pc = program_client_unix_create(event, TEST_SOCKET, args, &pc_params);
buffer_t *output = buffer_create_dynamic(default_pool, 16);
struct ostream *os = test_ostream_create(output);
int ret;
pc_params.no_reply = FALSE;
- pc = program_client_unix_create(TEST_SOCKET, args, &pc_params);
+ pc = program_client_unix_create(event, TEST_SOCKET, args, &pc_params);
struct istream *is = test_istream_create(pclient_test_io_string);
program_client_set_input(pc, is);
test_begin("test_program_failure");
pc_params.no_reply = FALSE;
- pc = program_client_unix_create(TEST_SOCKET, args, &pc_params);
+ pc = program_client_unix_create(event, TEST_SOCKET, args, &pc_params);
buffer_t *output = buffer_create_dynamic(default_pool, 16);
struct ostream *os = test_ostream_create(output);
test_begin("test_program_noreply");
pc_params.no_reply = TRUE;
- pc = program_client_unix_create(TEST_SOCKET, args, &pc_params);
+ pc = program_client_unix_create(event, TEST_SOCKET, args, &pc_params);
program_client_run_async(pc, test_program_async_callback, &ret);
test_begin("test_program_sync");
pc_params.no_reply = TRUE;
- pc = program_client_unix_create(TEST_SOCKET, args, &pc_params);
+ pc = program_client_unix_create(event, TEST_SOCKET, args, &pc_params);
ret = program_client_run(pc);
test_assert(ret == 1);
test_begin("test_program_async_wait");
pc_params.no_reply = TRUE;
- test_globals.async_client = program_client_unix_create(TEST_SOCKET,
+ test_globals.async_client = program_client_unix_create(event, TEST_SOCKET,
args, &pc_params);
program_client_run_async(test_globals.async_client,
lib_init();
- pc_params.event = event_create(NULL);
+ event = event_create(NULL);
while ((c = getopt(argc, argv, "D")) > 0) {
switch (c) {
case 'D':
- event_set_forced_debug(pc_params.event, TRUE);
+ event_set_forced_debug(event, TRUE);
break;
default:
i_fatal("Usage: %s [-D]", argv[0]);
ret = test_run(tests);
- event_unref(&pc_params.event);
+ event_unref(&event);
lib_deinit();
return ret;
}
i_zero(&pc_params);
pc_params.client_connect_timeout_msecs = set->submission_timeout * 1000;
pc_params.input_idle_timeout_msecs = set->submission_timeout * 1000;
- pc_params.event = subm->event;
- pc = program_client_local_create
- (sendmail_bin, array_front(&args), &pc_params);
+ pc = program_client_local_create(subm->event, sendmail_bin,
+ array_front(&args), &pc_params);
program_client_set_input(pc, subm->input);
i_stream_unref(&subm->input);
struct program_client_parameters params = {
.client_connect_timeout_msecs = 1000,
- .event = root->quota->event,
.no_reply = TRUE,
};
struct program_client *pc;
args++;
- if (program_client_create(socket_path, args, ¶ms,
- &pc, &error) < 0) {
+ if (program_client_create(root->quota->event, socket_path, args,
+ ¶ms, &pc, &error) < 0) {
e_error(root->quota->event,
"program_client_create(%s) failed: %s", socket_path,
error);
struct program_client_parameters params = {
.client_connect_timeout_msecs = 1000,
- .event = user->event,
.no_reply = !wait,
};
}
struct welcome_client_list *wclient = i_new(struct welcome_client_list, 1);
- wclient->client = program_client_unix_create(socket_path, args, ¶ms);
+ wclient->client = program_client_unix_create(user->event, socket_path,
+ args, ¶ms);
if (wait) {
enum program_client_exit_status ret =