switch (lock_ctx->type) {
case LOCK_RECORD:
- nargs = 6;
+ nargs = 5;
break;
case LOCK_DB:
- nargs = 5;
+ nargs = 4;
break;
case LOCK_ALLDB_PRIO:
- nargs = 4;
+ nargs = 3;
ctdb_db_iterator(ctdb, lock_ctx->priority, db_count_handler, &nargs);
break;
case LOCK_ALLDB:
- nargs = 4;
+ nargs = 3;
for (priority=1; priority<NUM_DB_PRIORITIES; priority++) {
ctdb_db_iterator(ctdb, priority, db_count_handler, &nargs);
}
return false;
}
- args[0] = talloc_strdup(args, "ctdb_lock_helper");
- args[1] = talloc_asprintf(args, "%d", getpid());
- args[2] = talloc_asprintf(args, "%d", fd);
+ args[0] = talloc_asprintf(args, "%d", getpid());
+ args[1] = talloc_asprintf(args, "%d", fd);
switch (lock_ctx->type) {
case LOCK_RECORD:
- args[3] = talloc_strdup(args, "RECORD");
- args[4] = talloc_strdup(args, lock_ctx->ctdb_db->db_path);
+ args[2] = talloc_strdup(args, "RECORD");
+ args[3] = talloc_strdup(args, lock_ctx->ctdb_db->db_path);
if (lock_ctx->key.dsize == 0) {
- args[5] = talloc_strdup(args, "NULL");
+ args[4] = talloc_strdup(args, "NULL");
} else {
- args[5] = hex_encode_talloc(args, lock_ctx->key.dptr, lock_ctx->key.dsize);
+ args[4] = hex_encode_talloc(args, lock_ctx->key.dptr, lock_ctx->key.dsize);
}
break;
case LOCK_DB:
- args[3] = talloc_strdup(args, "DB");
- args[4] = talloc_strdup(args, lock_ctx->ctdb_db->db_path);
+ args[2] = talloc_strdup(args, "DB");
+ args[3] = talloc_strdup(args, lock_ctx->ctdb_db->db_path);
break;
case LOCK_ALLDB_PRIO:
- args[3] = talloc_strdup(args, "DB");
+ args[2] = talloc_strdup(args, "DB");
list.names = args;
- list.n = 4;
+ list.n = 3;
ctdb_db_iterator(ctdb, lock_ctx->priority, db_name_handler, &list);
break;
case LOCK_ALLDB:
- args[3] = talloc_strdup(args, "DB");
+ args[2] = talloc_strdup(args, "DB");
list.names = args;
- list.n = 4;
+ list.n = 3;
for (priority=1; priority<NUM_DB_PRIORITIES; priority++) {
ctdb_db_iterator(ctdb, priority, db_name_handler, &list);
}
return;
}
- lock_ctx->child = vfork();
-
- if (lock_ctx->child == (pid_t)-1) {
+ if (!ctdb_vfork_with_logging(lock_ctx, ctdb, "lock_helper",
+ prog, argc, (const char **)args,
+ NULL, NULL, &lock_ctx->child)) {
DEBUG(DEBUG_ERR, ("Failed to create a child in ctdb_lock_schedule\n"));
close(lock_ctx->fd[0]);
close(lock_ctx->fd[1]);
return;
}
-
- /* Child process */
- if (lock_ctx->child == 0) {
- ret = execv(prog, (char * const*) args);
- if (ret < 0) {
- DEBUG(DEBUG_ERR, ("Failed to execute helper %s (%d, %s)\n",
- prog, errno, strerror(errno)));
- }
- _exit(1);
- }
-
/* Parent process */
- ctdb_track_child(ctdb, lock_ctx->child);
close(lock_ctx->fd[1]);
talloc_set_destructor(lock_ctx, ctdb_lock_context_destructor);
int main(int argc, char *argv[])
{
- int write_fd;
+ int write_fd, log_fd;
char result = 0;
int ppid;
const char *lock_type;
progname = argv[0];
- if (argc < 4) {
+ if (argc < 5) {
usage();
exit(1);
}
set_scheduler();
- ppid = atoi(argv[1]);
- write_fd = atoi(argv[2]);
- lock_type = argv[3];
+ log_fd = atoi(argv[1]);
+ close(STDOUT_FILENO);
+ close(STDERR_FILENO);
+ dup2(log_fd, STDOUT_FILENO);
+ dup2(log_fd, STDERR_FILENO);
+ close(log_fd);
+
+ ppid = atoi(argv[2]);
+ write_fd = atoi(argv[3]);
+ lock_type = argv[4];
if (strcmp(lock_type, "RECORD") == 0) {
- if (argc != 6) {
+ if (argc != 7) {
fprintf(stderr, "%s: Invalid number of arguments (%d)\n",
progname, argc);
usage();
exit(1);
}
- result = lock_record(argv[4], argv[5]);
+ result = lock_record(argv[5], argv[6]);
} else if (strcmp(lock_type, "DB") == 0) {
int n;
/* If there are no databases specified, no need for lock */
- if (argc > 4) {
- for (n=4; n<argc; n++) {
+ if (argc > 5) {
+ for (n=5; n<argc; n++) {
result = lock_db(argv[n]);
if (result != 0) {
break;