static void main_deinit(void) { if (doveadm_client != NULL) client_connection_destroy(&doveadm_client); doveadm_mail_deinit(); doveadm_unload_modules(); doveadm_print_deinit(); }
static void stats_top_output(struct top_context *ctx) { static const char *names[] = { "user", "service", "user_cpu", "sys_cpu", "", "" }; struct winsize ws; struct top_line *const *lines; unsigned int i, j, row, maxrow, count, indexes[N_ELEMENTS(names)]; names[4] = disk_input_field; names[5] = disk_output_field; /* ANSI clear screen and move cursor to top of screen */ printf("\x1b[2J\x1b[1;1H"); fflush(stdout); doveadm_print_deinit(); doveadm_print_init(DOVEADM_PRINT_TYPE_TABLE); doveadm_print_header("USER", "USER", DOVEADM_PRINT_HEADER_FLAG_EXPAND); doveadm_print_header_simple("SERVICE"); doveadm_print_header_simple("%CPU"); doveadm_print_header_simple("%SYS"); doveadm_print_header_simple("DISKIN"); doveadm_print_header_simple("DISKOUT"); if (!stats_top_round(ctx)) { /* no connections yet */ return; } for (i = 0; i < N_ELEMENTS(names); i++) { if (!stats_header_find(ctx, names[i], &indexes[i])) indexes[i] = UINT_MAX; } if (ioctl(STDOUT_FILENO, TIOCGWINSZ, &ws) < 0) ws.ws_row = 24; maxrow = ws.ws_row-1; lines = array_get(&ctx->lines, &count); for (i = 0, row = 1; row < maxrow && i < count; i++, row++) { for (j = 0; j < N_ELEMENTS(names); j++) { if (indexes[j] == UINT_MAX) doveadm_print("?"); else stats_top_output_diff(ctx, lines[i], indexes[j]); } } }
static int doveadm_cmd_handle(struct client_connection *conn, const char *cmd_name, const struct mail_storage_service_input *input, int argc, char *argv[]) { struct ioloop *ioloop, *prev_ioloop = current_ioloop; const struct doveadm_cmd *cmd; const struct doveadm_mail_cmd *mail_cmd; struct doveadm_mail_cmd_context *ctx; cmd = doveadm_cmd_find(cmd_name, &argc, &argv); if (cmd == NULL) { mail_cmd = doveadm_mail_cmd_find(cmd_name); if (mail_cmd == NULL) { i_error("doveadm: Client sent unknown command: %s", cmd_name); return -1; } if (doveadm_mail_cmd_server_parse(mail_cmd, conn->set, input, argc, argv, &ctx) < 0) return -1; } /* some commands will want to call io_loop_run(), but we're already running one and we can't call the original one recursively, so create a new ioloop. */ ioloop = io_loop_create(); lib_signals_reset_ioloop(); if (cmd != NULL) doveadm_cmd_server_run(conn, cmd, argc, argv); else doveadm_mail_cmd_server_run(conn, ctx, input); io_loop_set_current(prev_ioloop); lib_signals_reset_ioloop(); o_stream_switch_ioloop(conn->output); io_loop_set_current(ioloop); io_loop_destroy(&ioloop); /* clear all headers */ doveadm_print_deinit(); doveadm_print_init(DOVEADM_PRINT_TYPE_SERVER); return 0; }
static void doveadm_mail_cmd_server_run(struct client_connection *conn, struct doveadm_mail_cmd_context *ctx, const struct mail_storage_service_input *input) { const char *error; int ret; ctx->conn = conn; if (ctx->v.preinit != NULL) ctx->v.preinit(ctx); ret = doveadm_mail_single_user(ctx, input, &error); doveadm_mail_server_flush(); ctx->v.deinit(ctx); doveadm_print_flush(); mail_storage_service_deinit(&ctx->storage_service); if (ret < 0) { i_error("%s: %s", ctx->cmd->name, error); o_stream_nsend(conn->output, "\n-\n", 3); } else if (ret == 0) { o_stream_nsend_str(conn->output, "\n-NOUSER\n"); } else if (ctx->exit_code != 0) { /* maybe not an error, but not a full success either */ o_stream_nsend(conn->output, "\n-\n", 3); } else { o_stream_nsend(conn->output, "\n+\n", 3); } pool_unref(&ctx->pool); /* clear all headers */ doveadm_print_deinit(); doveadm_print_init(DOVEADM_PRINT_TYPE_SERVER); }