ctdb-recovery: Start recovery helper with ctdb_vfork_exec
authorAmitay Isaacs <amitay@gmail.com>
Wed, 30 Nov 2016 01:23:04 +0000 (12:23 +1100)
committerMartin Schwenke <martins@samba.org>
Mon, 5 Dec 2016 10:59:42 +0000 (11:59 +0100)
The recovery helper does it's own logging, so there is no need to
pass logfd.

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Autobuild-User(master): Martin Schwenke <martins@samba.org>
Autobuild-Date(master): Mon Dec  5 11:59:42 CET 2016 on sn-devel-144

ctdb/server/ctdb_recoverd.c
ctdb/server/ctdb_recovery_helper.c

index aa699aad32c760e8270189015df60ce859cda4ab..1e04960c92360a74bf0a7b44215710e04c158905 100644 (file)
@@ -1158,8 +1158,8 @@ static int db_recovery_parallel(struct ctdb_recoverd *rec, TALLOC_CTX *mem_ctx)
 
        setenv("CTDB_DBDIR_STATE", rec->ctdb->db_directory_state, 1);
 
-       if (!ctdb_vfork_with_logging(state, rec->ctdb, "recovery", prog, nargs,
-                                    args, NULL, NULL, &state->pid)) {
+       state->pid = ctdb_vfork_exec(state, rec->ctdb, prog, nargs, args);
+       if (state->pid == -1) {
                DEBUG(DEBUG_ERR,
                      ("Failed to create child for recovery helper\n"));
                goto fail;
index 09bc9897893b186a1fd4a771794e21ab2687907e..0222aa0bacde27645e7ded31ad81f8b4b49b91c5 100644 (file)
 #include "protocol/protocol_api.h"
 #include "client/client.h"
 
+#include "common/logging.h"
+
 static int recover_timeout = 30;
 
 #define NUM_RETRIES    3
 
 #define TIMEOUT()      timeval_current_ofs(recover_timeout, 0)
 
-static void LOG(const char *fmt, ...) PRINTF_ATTRIBUTE(1,2);
-
-static void LOG(const char *fmt, ...)
-{
-       va_list ap;
-
-       va_start(ap, fmt);
-       vfprintf(stderr, fmt, ap);
-       va_end(ap);
-}
+#define LOG(...)       DEBUG(DEBUG_NOTICE, (__VA_ARGS__))
 
 /*
  * Utility functions
@@ -2720,7 +2713,7 @@ static void recovery_recv(struct tevent_req *req, int *perr)
 
 static void usage(const char *progname)
 {
-       fprintf(stderr, "\nUsage: %s <log-fd> <output-fd> <ctdb-socket-path> <generation>\n",
+       fprintf(stderr, "\nUsage: %s <output-fd> <ctdb-socket-path> <generation>\n",
                progname);
 }
 
@@ -2730,7 +2723,7 @@ static void usage(const char *progname)
  */
 int main(int argc, char *argv[])
 {
-       int log_fd, write_fd;
+       int write_fd;
        const char *sockpath;
        TALLOC_CTX *mem_ctx;
        struct tevent_context *ev;
@@ -2739,27 +2732,24 @@ int main(int argc, char *argv[])
        struct tevent_req *req;
        uint32_t generation;
 
-       if (argc != 5) {
+       if (argc != 4) {
                usage(argv[0]);
                exit(1);
        }
 
-       log_fd = atoi(argv[1]);
-       if (log_fd != STDOUT_FILENO && log_fd != STDERR_FILENO) {
-               close(STDOUT_FILENO);
-               close(STDERR_FILENO);
-               dup2(log_fd, STDOUT_FILENO);
-               dup2(log_fd, STDERR_FILENO);
-       }
-       close(log_fd);
-
-       write_fd = atoi(argv[2]);
-       sockpath = argv[3];
-       generation = (uint32_t)strtoul(argv[4], NULL, 0);
+       write_fd = atoi(argv[1]);
+       sockpath = argv[2];
+       generation = (uint32_t)strtoul(argv[3], NULL, 0);
 
        mem_ctx = talloc_new(NULL);
        if (mem_ctx == NULL) {
-               LOG("talloc_new() failed\n");
+               fprintf(stderr, "recovery: talloc_new() failed\n");
+               goto failed;
+       }
+
+       ret = logging_init(mem_ctx, NULL, NULL, "ctdb-recovery");
+       if (ret != 0) {
+               fprintf(stderr, "recovery: Unable to initialize logging\n");
                goto failed;
        }
 
@@ -2797,6 +2787,6 @@ int main(int argc, char *argv[])
        return 0;
 
 failed:
-       talloc_free(mem_ctx);
+       TALLOC_FREE(mem_ctx);
        return 1;
 }