script.c revision db776508d6e959ae6e66050e22e2763521e6d272
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen/* Copyright (c) 2010 Dovecot authors, see the included COPYING file */
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainenstatic void script_verify_version(const char *line)
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen !version_string_verify(line, "script", SCRIPT_MAJOR_VERSION)) {
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen i_fatal("Client not compatible with this binary "
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen "(connecting to wrong socket?)");
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainenstatic void client_connected(struct master_service_connection *conn)
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen const unsigned char *end;
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen const char *const *args;
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen unsigned int i, socket_count;
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen input = buffer_create_dynamic(pool_datastack_create(), IO_BLOCK_SIZE);
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen /* Input contains:
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen VERSION .. <lf>
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen buf = buffer_append_space_unsafe(input, IO_BLOCK_SIZE);
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen script_verify_version(t_strcut(str_c(input), '\t'));
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen end = CONST_PTR_OFFSET(input->data, input->used);
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen } while (!(end[-1] == '\n' && (input->used == 1 || end[-2] == '\n')));
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen /* drop the last LF */
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen /* close all fds */
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen socket_count = master_service_get_socket_count(master_service);
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen for (i = 0; i < socket_count; i++) {
db776508d6e959ae6e66050e22e2763521e6d272Timo Sirainen master_service = master_service_init("script", 0, &argc, &argv, "+");
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen master_service_init_log(master_service, "script: ");
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen master_service_set_service_count(master_service, 1);
cbfdc79faac95adc8a3f76ee2216d3fea0c19826Timo Sirainen binary = t_strconcat(PKG_LIBEXECDIR"/", argv[0], NULL);