bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2011-2018 Dovecot authors, see the included COPYING file */
48f78a48f2e1cf299026544444666471ae16ad97Timo Sirainenprocess_io_buffer_parse(const char *buf, struct mail_stats *stats)
62461eb609e1d852e027cf4e07d30d51288678a2Aki Tuomi if (str_to_uint64(*tmp + 7, &stats->read_bytes) < 0)
6ca8d19dd94eb79ba65d2c5b686c37225ab33adcTimo Sirainen } else if (strncmp(*tmp, "wchar: ", 7) == 0) {
48f78a48f2e1cf299026544444666471ae16ad97Timo Sirainen if (str_to_uint64(*tmp + 7, &stats->write_bytes) < 0)
22bcfbefeb32d8b787a3449139cdba550c4cf1b8Timo Sirainen } else if (strncmp(*tmp, "syscr: ", 7) == 0) {
22bcfbefeb32d8b787a3449139cdba550c4cf1b8Timo Sirainen if (str_to_uint32(*tmp + 7, &stats->read_count) < 0)
ee19b4573879d83353c2e32e5ac2f5480dec55eaTimo Sirainen } else if (strncmp(*tmp, "syscw: ", 7) == 0) {
ee19b4573879d83353c2e32e5ac2f5480dec55eaTimo Sirainen if (str_to_uint32(*tmp + 7, &stats->write_count) < 0)
cfbe8dbf68fd1c2a98444cdfd0145e002965dd50Timo Sirainen bool dumpable = restrict_access_get_dumpable();
48f78a48f2e1cf299026544444666471ae16ad97Timo Sirainen /* kludge: if we're running with permissions temporarily
48f78a48f2e1cf299026544444666471ae16ad97Timo Sirainen dropped, get them temporarily back so we can open
8ecbb74bc4c7f6f6145da3525941d1d0e20e67f1Timo Sirainen if (seteuid(0) == 0) {
8ecbb74bc4c7f6f6145da3525941d1d0e20e67f1Timo Sirainen /* oops, this is bad */
8ecbb74bc4c7f6f6145da3525941d1d0e20e67f1Timo Sirainen i_fatal("stats: seteuid(%s) failed", dec2str(uid));
6ca8d19dd94eb79ba65d2c5b686c37225ab33adcTimo Sirainen /* ignore access errors too, certain security options can
73a3d209062ede6bda2db328808e36390faf0a72Timo Sirainen prevent root access to this file when not owned by root */
13c6532dc104d23061e6901783ceb1ff8872c206Timo Sirainenstatic void process_read_io_stats(struct mail_stats *stats)
48f78a48f2e1cf299026544444666471ae16ad97Timo Sirainen i_error("read(%s) returned EOF", PROC_IO_PATH);
48f78a48f2e1cf299026544444666471ae16ad97Timo Sirainen /* just shouldn't happen.. */
48f78a48f2e1cf299026544444666471ae16ad97Timo Sirainen i_error("%s is larger than expected", PROC_IO_PATH);
48f78a48f2e1cf299026544444666471ae16ad97Timo Sirainen if (process_io_buffer_parse(buf, stats) < 0) {
48f78a48f2e1cf299026544444666471ae16ad97Timo Sirainenuser_trans_stats_get(struct stats_user *suser, struct mail_stats *dest_r)
48f78a48f2e1cf299026544444666471ae16ad97Timo Sirainen mail_stats_add_transaction(dest_r, &suser->finished_transaction_stats);
48f78a48f2e1cf299026544444666471ae16ad97Timo Sirainen for (strans = suser->transactions; strans != NULL; strans = strans->next)
48f78a48f2e1cf299026544444666471ae16ad97Timo Sirainen mail_stats_add_transaction(dest_r, &strans->trans->stats);
48f78a48f2e1cf299026544444666471ae16ad97Timo Sirainenvoid mail_stats_fill(struct stats_user *suser, struct mail_stats *stats_r)
dd45ee57c3e6b19ff67b4643f52b153535cabe0cTimo Sirainen /* cputime */
8fb31d963d484e2b9e1def6756afcc22c18c0310Timo Sirainen } else if (timeval_diff_usecs(&usage.ru_stime, &prev_usage.ru_stime) < 0) {
8ecbb74bc4c7f6f6145da3525941d1d0e20e67f1Timo Sirainen /* This seems to be a Linux bug. */
8fb31d963d484e2b9e1def6756afcc22c18c0310Timo Sirainen stats_r->disk_input = (unsigned long long)usage.ru_inblock * 512ULL;
8fb31d963d484e2b9e1def6756afcc22c18c0310Timo Sirainen stats_r->disk_output = (unsigned long long)usage.ru_oublock * 512ULL;