bool ctdb_logging_init(TALLOC_CTX *mem_ctx, const char *logging,
const char *debug_level);
-struct ctdb_log_state *ctdb_vfork_with_logging(TALLOC_CTX *mem_ctx,
- struct ctdb_context *ctdb,
- const char *log_prefix,
- const char *helper,
- int helper_argc,
- const char **helper_argv,
- void (*logfn)(const char *,
- uint16_t, void *),
- void *logfn_private, pid_t *pid);
-
int ctdb_set_child_logging(struct ctdb_context *ctdb);
/* from ctdb_logging_file.c */
}
}
-static int log_context_destructor(struct ctdb_log_state *log)
-{
- /* Flush buffer in case it wasn't \n-terminated. */
- if (log->buf_used > 0) {
- write_to_log(log, log->buf, log->buf_used);
- }
- return 0;
-}
-
-/*
- * vfork + exec, redirecting child output to logging and specified callback.
- */
-struct ctdb_log_state *ctdb_vfork_with_logging(TALLOC_CTX *mem_ctx,
- struct ctdb_context *ctdb,
- const char *log_prefix,
- const char *helper,
- int helper_argc,
- const char **helper_argv,
- void (*logfn)(const char *, uint16_t, void *),
- void *logfn_private, pid_t *pid)
-{
- int p[2];
- struct ctdb_log_state *log;
- struct tevent_fd *fde;
- char **argv;
- int i;
- struct timeval before;
- double delta_t;
-
- log = talloc_zero(mem_ctx, struct ctdb_log_state);
- CTDB_NO_MEMORY_NULL(ctdb, log);
-
- log->prefix = log_prefix;
- log->logfn = logfn;
- log->logfn_private = logfn_private;
-
- if (pipe(p) != 0) {
- DEBUG(DEBUG_ERR, (__location__ " Failed to setup pipe for child logging:"
- " %s\n", strerror(errno)));
- goto free_log;
- }
-
- argv = talloc_array(mem_ctx, char *, helper_argc + 2);
- if (argv == NULL) {
- DEBUG(DEBUG_ERR, (__location__ "Failed to allocate memory for helper\n"));
- goto free_log;
- }
- argv[0] = discard_const(helper);
- argv[1] = talloc_asprintf(argv, "%d", p[1]);
- if (argv[1] == NULL) {
- DEBUG(DEBUG_ERR, (__location__ "Failed to allocate memory for helper\n"));
- talloc_free(argv);
- goto free_log;
- }
-
- for (i=0; i<helper_argc; i++) {
- argv[i+2] = discard_const(helper_argv[i]);
- }
-
- before = timeval_current();
-
- *pid = vfork();
- if (*pid == 0) {
- execv(helper, argv);
- _exit(1);
- }
- close(p[1]);
-
- if (*pid < 0) {
- DEBUG(DEBUG_ERR, (__location__ "vfork failed for helper process\n"));
- close(p[0]);
- goto free_log;
- }
-
- delta_t = timeval_elapsed(&before);
- if (delta_t > 3.0) {
- DEBUG(DEBUG_WARNING, ("vfork() took %lf seconds\n", delta_t));
- }
-
- ctdb_track_child(ctdb, *pid);
-
- log->pfd = p[0];
- set_close_on_exec(log->pfd);
- talloc_set_destructor(log, log_context_destructor);
- fde = tevent_add_fd(ctdb->ev, log, log->pfd, TEVENT_FD_READ,
- ctdb_child_log_handler, log);
- tevent_fd_set_auto_close(fde);
-
- return log;
-
-free_log:
- talloc_free(log);
- return NULL;
-}
-
-
/*
setup for logging of child process stdout
*/