From 26e444a11c3b7de7f85d5941862fd0bd4bdcc523 Mon Sep 17 00:00:00 2001 From: Pavel Roskin Date: Sun, 26 Oct 2003 05:42:29 +0000 Subject: [PATCH] * background.c (tell_parent): Eliminate. (background_attention): Use error code instead. * file.c (panel_operate): Exit with code 0, not 1. --- src/ChangeLog | 4 ++++ src/background.c | 34 ++++++++++++++++------------------ src/background.h | 16 +--------------- src/file.c | 3 +-- 4 files changed, 22 insertions(+), 35 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 6b2fb2875..09ab33698 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,9 @@ 2003-10-26 Pavel Roskin + * background.c (tell_parent): Eliminate. + (background_attention): Use error code instead. + * file.c (panel_operate): Exit with code 0, not 1. + * wtools.c: Merge mc_message() and message() into one background safe function message(). Fix all callers. diff --git a/src/background.c b/src/background.c index 6f749c704..1a8be84b1 100644 --- a/src/background.c +++ b/src/background.c @@ -43,6 +43,11 @@ #include "fileopctx.h" /* FileOpContext */ #include "key.h" /* add_select_channel(), delete_select_channel() */ +enum ReturnType { + Return_String, + Return_Integer +}; + /* If true, this is a background process */ int we_are_background = 0; @@ -195,24 +200,23 @@ background_attention (int fd, void *closure) ctx = closure; bytes = read (fd, &routine, sizeof (routine)); - if (bytes < (sizeof (routine))){ + if (bytes < (sizeof (routine))) { char *background_process_error = _(" Background process error "); unregister_task_running (ctx->pid, fd); - waitpid (ctx->pid, &status, 0); - - if (errno == ECHILD) - message (1, background_process_error, _(" Child died unexpectedly ")); - else + if (!waitpid (ctx->pid, &status, WNOHANG)) { + /* the process is still running, but it misbehaves - kill it */ + kill (ctx->pid, SIGTERM); message (1, background_process_error, _(" Unknown error in child ")); + return 0; + } - return 0; - } + /* 0 means happy end */ + if (WIFEXITED (status) && (WEXITSTATUS (status) == 0)) + return 0; + + message (1, background_process_error, _(" Child died unexpectedly ")); - /* If the routine is zero, then the child is telling us that he is dying */ - if ((long) routine == MSG_CHILD_EXITING){ - unregister_task_running (ctx->pid, fd); - waitpid (ctx->pid, &status, 0); return 0; } @@ -403,10 +407,4 @@ parent_call_string (void *routine, int argc, ...) return str; } -void -tell_parent (int msg) -{ - write (parent_fd, &msg, sizeof (int)); -} - #endif /* WITH_BACKGROUND */ diff --git a/src/background.h b/src/background.h index aefbc3330..cd0df8921 100644 --- a/src/background.h +++ b/src/background.h @@ -2,18 +2,6 @@ #define __BACKGROUND_H #ifdef WITH_BACKGROUND -/* - * Used for parent/child communication. These are numbers that - * could not possible be a routine address. - */ -enum { - MSG_CHILD_EXITING -}; - -enum ReturnType { - Return_String, - Return_Integer -}; enum TaskState { Task_Running, @@ -30,14 +18,12 @@ typedef struct TaskList { extern struct TaskList *task_list; -void tell_parent (int msg); - struct FileOpContext; int do_background (struct FileOpContext *ctx, char *info); int parent_call (void *routine, struct FileOpContext *ctx, int argc, ...); char *parent_call_string (void *routine, int argc, ...); -void unregister_task_running (pid_t, int fd); +void unregister_task_running (pid_t pid, int fd); extern int we_are_background; #endif /* !WITH_BACKGROUND */ diff --git a/src/file.c b/src/file.c index 7d4e91d42..1859df373 100644 --- a/src/file.c +++ b/src/file.c @@ -2124,8 +2124,7 @@ panel_operate (void *source_panel, FileOperation operation, /* Let our parent know we are saying bye bye */ if (we_are_background) { vfs_shut (); - tell_parent (MSG_CHILD_EXITING); - _exit (1); + _exit (0); } #endif /* WITH_BACKGROUND */