doveadm-master.c revision 7237f2f0a577413e12662228ee2039425fd2f5b0
02c335c23bf5fa225a467c19f2c063fb0dc7b8c3Timo Sirainen/* Copyright (c) 2010-2016 Dovecot authors, see the included COPYING file */
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainenstatic bool pid_file_read(const char *path, pid_t *pid_r)
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainen unsigned int i;
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainen pidfile_path = t_strconcat(doveadm_settings->base_dir,
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainen i_fatal("Dovecot is not running (read from %s)", pidfile_path);
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainen i_fatal("kill(%s, %d) failed: %m", dec2str(pid), signo);
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainen /* wait for a while for the process to die */
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainen for (i = 0; i < 30; i++) {
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainenstatic void cmd_stop(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED)
169b1488b6eea7a968021afa4f929b2e26d75d98Timo Sirainenstatic void cmd_reload(int argc ATTR_UNUSED, char *argv[] ATTR_UNUSED)
7237f2f0a577413e12662228ee2039425fd2f5b0Timo Sirainenstatic struct istream *master_service_send_cmd(const char *cmd)
c7713320cd35e77543f1bdc7229988a160dae322Timo Sirainen path = t_strconcat(doveadm_settings->base_dir, "/master", NULL);
c7713320cd35e77543f1bdc7229988a160dae322Timo Sirainen i_fatal("net_connect_unix(%s) failed: %m", path);
7237f2f0a577413e12662228ee2039425fd2f5b0Timo Sirainen const char *str =
7237f2f0a577413e12662228ee2039425fd2f5b0Timo Sirainen t_strdup_printf("VERSION\tmaster-client\t1\t0\n%s\n", cmd);
7237f2f0a577413e12662228ee2039425fd2f5b0Timo Sirainen return i_stream_create_fd_autoclose(&fd, IO_BLOCK_SIZE);
7237f2f0a577413e12662228ee2039425fd2f5b0Timo Sirainenstatic void cmd_service_stop(int argc, char *argv[])
7237f2f0a577413e12662228ee2039425fd2f5b0Timo Sirainen struct istream *input = master_service_send_cmd(str_c(cmd));
c7713320cd35e77543f1bdc7229988a160dae322Timo Sirainen (line = i_stream_read_next_line(input)) == NULL) {
7237f2f0a577413e12662228ee2039425fd2f5b0Timo Sirainen i_error("read(%s) failed: %s", i_stream_get_name(input),
68cc278710182485b6c09e9a9ff8db90a727f343Aki Tuomistruct doveadm_cmd_ver2 doveadm_cmd_reload_ver2 = {
c7713320cd35e77543f1bdc7229988a160dae322Timo Sirainenstruct doveadm_cmd_ver2 doveadm_cmd_service_stop_ver2 = {