return -1;
}
- ctdb->syslogd_pid = fork();
+ ctdb->syslogd_pid = ctdb_fork(ctdb);
if (ctdb->syslogd_pid == (pid_t)-1) {
printf("Failed to create syslog child process\n");
close(state->fd[0]);
return 0;
}
+ debug_extra = talloc_asprintf(NULL, "syslogd:");
talloc_free(ctdb->ev);
ctdb->ev = event_context_init(NULL);
+ tevent_loop_allow_nesting(ctdb->ev);
syslog(LOG_ERR, "Starting SYSLOG daemon with pid:%d", (int)getpid());
break;
}
- len = offsetof(struct syslog_message, message) + strlen(s) + 1;
+ len = offsetof(struct syslog_message, message) + strlen(debug_extra) + strlen(s) + 1;
msg = malloc(len);
if (msg == NULL) {
free(s);
return;
}
msg->level = level;
- msg->len = strlen(s);
- strcpy(msg->message, s);
+ msg->len = strlen(debug_extra) + strlen(s);
+ strcpy(msg->message, debug_extra);
+ strcat(msg->message, s);
if (syslogd_is_started == 0) {
syslog(msg->level, "%s", msg->message);
strftime(tbuf,sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm);
- ret = asprintf(&s2, "%s.%06u [%5u]: %s",
- tbuf, (unsigned)t.tv_usec, (unsigned)getpid(), s);
+ ret = asprintf(&s2, "%s.%06u [%s%5u]: %s",
+ tbuf, (unsigned)t.tv_usec,
+ debug_extra, (unsigned)getpid(), s);
free(s);
if (ret == -1) {
const char *errstr = "asprintf failed\n";
goto free_log;
}
- *pid = fork();
+ *pid = ctdb_fork(ctdb);
/* Child? */
if (*pid == 0) {
}
+/*
+ * set up a log handler to catch logging from TEVENT
+ */
+static void ctdb_tevent_logging(void *private_data,
+ enum tevent_debug_level level,
+ const char *fmt,
+ va_list ap)
+{
+ enum debug_level lvl = DEBUG_EMERG;
+
+ switch (level) {
+ case TEVENT_DEBUG_FATAL:
+ lvl = DEBUG_EMERG;
+ break;
+ case TEVENT_DEBUG_ERROR:
+ lvl = DEBUG_ERR;
+ break;
+ case TEVENT_DEBUG_WARNING:
+ lvl = DEBUG_WARNING;
+ break;
+ case TEVENT_DEBUG_TRACE:
+ lvl = DEBUG_DEBUG;
+ break;
+ }
+
+ if (lvl <= LogLevel) {
+ this_log_level = lvl;
+ do_debug_v(fmt, ap);
+ }
+}
+
+int ctdb_init_tevent_logging(struct ctdb_context *ctdb)
+{
+ int ret;
+
+ ret = tevent_set_debug(ctdb->ev,
+ ctdb_tevent_logging,
+ ctdb);
+ return ret;
+}