mirror of
https://github.com/samba-team/samba.git
synced 2025-02-09 09:57:48 +03:00
ctdb-daemon: Improve error handling for running event scripts
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): Fri Nov 14 03:06:12 CET 2014 on sn-devel-104
This commit is contained in:
parent
04a9a1ac6d
commit
d04bfc6ec6
@ -67,7 +67,7 @@ int main(int argc, char *argv[])
|
|||||||
{
|
{
|
||||||
int log_fd, write_fd;
|
int log_fd, write_fd;
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
int status, output;
|
int status, output, ret;
|
||||||
|
|
||||||
progname = argv[0];
|
progname = argv[0];
|
||||||
|
|
||||||
@ -99,33 +99,47 @@ int main(int argc, char *argv[])
|
|||||||
|
|
||||||
pid = fork();
|
pid = fork();
|
||||||
if (pid < 0) {
|
if (pid < 0) {
|
||||||
|
int save_errno = errno;
|
||||||
fprintf(stderr, "Failed to fork - %s\n", strerror(errno));
|
fprintf(stderr, "Failed to fork - %s\n", strerror(errno));
|
||||||
exit(errno);
|
sys_write(write_fd, &save_errno, sizeof(save_errno));
|
||||||
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pid == 0) {
|
if (pid == 0) {
|
||||||
int save_errno;
|
ret = check_executable(argv[3]);
|
||||||
|
if (ret != 0) {
|
||||||
execv(argv[3], &argv[3]);
|
_exit(ret);
|
||||||
if (errno == EACCES) {
|
}
|
||||||
save_errno = check_executable(argv[3]);
|
ret = execv(argv[3], &argv[3]);
|
||||||
} else {
|
if (ret != 0) {
|
||||||
save_errno = errno;
|
int save_errno = errno;
|
||||||
fprintf(stderr, "Error executing '%s' - %s\n",
|
fprintf(stderr, "Error executing '%s' - %s\n",
|
||||||
argv[3], strerror(errno));
|
argv[3], strerror(save_errno));
|
||||||
}
|
}
|
||||||
_exit(save_errno);
|
/* This should never happen */
|
||||||
|
_exit(ENOEXEC);
|
||||||
}
|
}
|
||||||
|
|
||||||
waitpid(pid, &status, 0);
|
ret = waitpid(pid, &status, 0);
|
||||||
if (WIFEXITED(status)) {
|
if (ret == -1) {
|
||||||
output = WEXITSTATUS(status);
|
output = -errno;
|
||||||
if (output == ENOENT || output == ENOEXEC) {
|
fprintf(stderr, "waitpid() failed - %s\n", strerror(errno));
|
||||||
output = -output;
|
|
||||||
}
|
|
||||||
sys_write(write_fd, &output, sizeof(output));
|
sys_write(write_fd, &output, sizeof(output));
|
||||||
exit(output);
|
exit(1);
|
||||||
|
}
|
||||||
|
if (WIFEXITED(status)) {
|
||||||
|
output = -WEXITSTATUS(status);
|
||||||
|
sys_write(write_fd, &output, sizeof(output));
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
if (WIFSIGNALED(status)) {
|
||||||
|
output = -EINTR;
|
||||||
|
fprintf(stderr, "Process terminated with signal - %d\n",
|
||||||
|
WTERMSIG(status));
|
||||||
|
sys_write(write_fd, &output, sizeof(output));
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "waitpid() status=%d\n", status);
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
@ -367,6 +367,8 @@ static void ctdb_event_script_handler(struct event_context *ev, struct fd_event
|
|||||||
r = sys_read(state->fd[0], ¤t->status, sizeof(current->status));
|
r = sys_read(state->fd[0], ¤t->status, sizeof(current->status));
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
current->status = -errno;
|
current->status = -errno;
|
||||||
|
} else if (r == 0) {
|
||||||
|
current->status = -EINTR;
|
||||||
} else if (r != sizeof(current->status)) {
|
} else if (r != sizeof(current->status)) {
|
||||||
current->status = -EIO;
|
current->status = -EIO;
|
||||||
}
|
}
|
||||||
@ -384,8 +386,12 @@ static void ctdb_event_script_handler(struct event_context *ev, struct fd_event
|
|||||||
|
|
||||||
/* Aborted or finished all scripts? We're done. */
|
/* Aborted or finished all scripts? We're done. */
|
||||||
if (status != 0 || state->current+1 == state->scripts->num_scripts) {
|
if (status != 0 || state->current+1 == state->scripts->num_scripts) {
|
||||||
DEBUG(DEBUG_INFO,(__location__ " Eventscript %s %s finished with state %d\n",
|
if (status != 0) {
|
||||||
ctdb_eventscript_call_names[state->call], state->options, status));
|
DEBUG(DEBUG_INFO,
|
||||||
|
("Eventscript %s %s finished with state %d\n",
|
||||||
|
ctdb_eventscript_call_names[state->call],
|
||||||
|
state->options, status));
|
||||||
|
}
|
||||||
|
|
||||||
ctdb->event_script_timeouts = 0;
|
ctdb->event_script_timeouts = 0;
|
||||||
talloc_free(state);
|
talloc_free(state);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user