This means we can distinguish which child is logging, esp. via syslog where we have no pid.
Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
* to the daemon as a client process, this function can be used to change
* the ctdb context from daemon into client mode
*/
-int switch_from_server_to_client(struct ctdb_context *ctdb)
+int switch_from_server_to_client(struct ctdb_context *ctdb, const char *fmt, ...)
{
int ret;
+ va_list ap;
+
+ /* Add extra information so we can identify this in the logs */
+ va_start(ap, fmt);
+ debug_extra = talloc_append_string(NULL, talloc_vasprintf(NULL, fmt, ap), ":");
+ va_end(ap);
/* shutdown the transport */
if (ctdb->methods) {
}
if (child == 0) {
- if (switch_from_server_to_client(ctdb) != 0) {
+ if (switch_from_server_to_client(ctdb, "log-collector") != 0) {
DEBUG(DEBUG_CRIT, (__location__ "ERROR: failed to switch log collector child into client mode.\n"));
_exit(1);
}
int ctdb_ctrl_recd_ping(struct ctdb_context *ctdb);
-int switch_from_server_to_client(struct ctdb_context *ctdb);
+int switch_from_server_to_client(struct ctdb_context *ctdb, const char *fmt, ...);
#define MONITOR_SCRIPT_OK 0
#define MONITOR_SCRIPT_TIMEOUT 1
strftime(tbuf,sizeof(tbuf)-1,"%Y/%m/%d %H:%M:%S", tm);
- fprintf(stderr, "%s.%06u [%5u]: %s", tbuf, (unsigned)t.tv_usec, (unsigned)getpid(), s);
+ fprintf(stderr, "%s.%06u [%s%5u]: %s", tbuf, (unsigned)t.tv_usec,
+ debug_extra, (unsigned)getpid(), s);
fflush(stderr);
free(s);
}
/* default logging function */
void (*do_debug_v)(const char *, va_list ap) = _do_debug_v;
+const char *debug_extra = "";
void do_debug(const char *format, ...)
{
*/
void (*do_debug_v)(const char *, va_list ap);
+const char *debug_extra;
void (*do_debug_add_v)(const char *, va_list ap);
void log_ringbuffer(const char *format, ...);
void do_debug(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
/* in the child */
close(fd[0]);
+ debug_extra = talloc_asprintf(NULL, "freeze_lock-%u:", priority);
ret = ctdb_lock_all_databases(ctdb, priority);
if (ret != 0) {
_exit(0);
if (result->child == 0) {
char c = 0;
close(result->fd[0]);
+ debug_extra = talloc_asprintf(NULL, "chainlock-%s:", ctdb_db->db_name);
tdb_chainlock(ctdb_db->ltdb->tdb, key);
write(result->fd[1], &c, 1);
/* make sure we die when our parent dies */
return 0;
}
+ debug_extra = talloc_asprintf(NULL, "syslogd:");
talloc_free(ctdb->ev);
ctdb->ev = event_context_init(NULL);
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";
if (child == 0) {
int ret;
+ debug_extra = talloc_asprintf(NULL, "notification-%s:", event);
ret = ctdb_run_notification_script_child(ctdb, event);
if (ret != 0) {
DEBUG(DEBUG_ERR,(__location__ " Notification script failed\n"));
char c = 0;
close(result->fd[0]);
+ debug_extra = talloc_asprintf(NULL, "childwrite-%s:", ctdb_db->db_name);
ret = ctdb_persistent_store(state);
if (ret != 0) {
DEBUG(DEBUG_ERR, (__location__ " Failed to write persistent data\n"));
char cc = 0;
close(state->fd[0]);
+ debug_extra = talloc_asprintf(NULL, "set_recmode:");
/* we should not be able to get the lock on the reclock file,
as it should be held by the recovery master
*/
close(state->fd[0]);
state->fd[0] = -1;
+ debug_extra = talloc_asprintf(NULL, "recovery-lock:");
if (pread(ctdb->recovery_lock_fd, &cc, 1, 0) == -1) {
DEBUG(DEBUG_CRIT,("failed read from recovery_lock_fd - %s\n", strerror(errno)));
cc = RECLOCK_FAILED;
srandom(getpid() ^ time(NULL));
- if (switch_from_server_to_client(ctdb) != 0) {
+ if (switch_from_server_to_client(ctdb, "recoverd") != 0) {
DEBUG(DEBUG_CRIT, (__location__ "ERROR: failed to switch recovery daemon into client mode. shutting down.\n"));
exit(1);
}
if (h->child == 0) {
/* start the traverse in the child */
close(h->fd[0]);
+ debug_extra = talloc_asprintf(NULL, "traverse_local-%s:",
+ ctdb_db->db_name);
tdb_traverse_read(ctdb_db->ltdb->tdb, ctdb_traverse_local_fn, h);
_exit(0);
}
DEBUG(DEBUG_INFO,("Vacuuming child process %d for db %s started\n", getpid(), ctdb_db->db_name));
- if (switch_from_server_to_client(ctdb) != 0) {
+ if (switch_from_server_to_client(ctdb, "vacuum-%s", ctdb_db->db_name) != 0) {
DEBUG(DEBUG_CRIT, (__location__ "ERROR: failed to switch vacuum daemon into client mode. Shutting down.\n"));
_exit(1);
}
if (state->child == 0) {
int rt;
+ debug_extra = talloc_asprintf(NULL, "eventscript-%s-%s:",
+ current->name,
+ ctdb_eventscript_call_names[state->call]);
close(state->fd[0]);
set_close_on_exec(state->fd[1]);