/* Copyright (c) 2005-2009 Dovecot authors, see the included COPYING file */
#include "common.h"
-#include "fd-close-on-exec.h"
#include "array.h"
+#include "hash.h"
+#include "ioloop.h"
+#include "fd-close-on-exec.h"
#include "service.h"
+#include "service-process.h"
#include "service-log.h"
#include <unistd.h>
return 0;
}
+static void service_remove_log_io_writes(struct service *service)
+{
+ struct hash_iterate_context *iter;
+ void *key, *value;
+
+ iter = hash_table_iterate_init(service->list->pids);
+ while (hash_table_iterate(iter, &key, &value)) {
+ struct service_process *process = value;
+
+ if (process->io_log_write != NULL)
+ io_remove(&process->io_log_write);
+ }
+ hash_table_iterate_deinit(&iter);
+}
+
void services_log_deinit(struct service_list *service_list)
{
struct service *const *services;
}
services[i]->log_fd[0] = -1;
services[i]->log_fd[1] = -1;
+ service_remove_log_io_writes(services[i]);
}
}
}
return process;
}
+static void service_process_log_bye(struct service_process *process)
+{
+ const char *data;
+
+ if (process->service->log_fd[1] == -1) {
+ /* stopping all services */
+ return;
+ }
+
+ data = t_strdup_printf("\001%c%s bye\n",
+ LOG_TYPE_OPTION+1, dec2str(process->pid));
+ if (write(process->service->log_fd[1], data, strlen(data)) < 0) {
+ if (errno != EAGAIN)
+ i_error("write(log process) failed: %m");
+ else {
+ process->io_log_write =
+ io_add(process->service->log_fd[1], IO_WRITE,
+ service_process_log_bye, process);
+ service_process_ref(process);
+ }
+ } else {
+ if (process->io_log_write != NULL) {
+ io_remove(&process->io_log_write);
+ service_process_unref(process);
+ }
+ }
+}
+
void service_process_destroy(struct service_process *process)
{
struct service *service = process->service;
- const char *data;
hash_table_remove(service->list->pids, &process->pid);
break;
}
- data = t_strdup_printf("\001%c%s bye\n",
- LOG_TYPE_OPTION+1, dec2str(process->pid));
- if (write(process->service->log_fd[1], data, strlen(data)) < 0) {
- if (errno != EAGAIN)
- i_error("write(log process) failed: %m");
- else {
- //FIXME:process->io_log_write = io_add();
- //return;
- }
- }
+ service_process_log_bye(process);
process->destroyed = TRUE;
service_process_unref(process);
if (--process->refcount > 0)
return TRUE;
+ i_assert(process->io_log_write == NULL);
i_assert(process->destroyed);
i_free(process);
this process's logging */
data = t_strdup_printf("\001%c%s %s %s\n",
type+1, my_pid, dec2str(process->pid), str);
- if (write_full(process->service->log_fd[1], data, strlen(data)) < 0) {
+ if (write(process->service->log_fd[1], data, strlen(data)) < 0) {
i_error("write(log process) failed: %m");
i_log_type(type, "%s", str);
}