mirror of
https://github.com/MidnightCommander/mc
synced 2024-12-22 20:36:50 +03:00
* gutil.c: Remove broken child management.
(my_system): Fix file modes for standard descriptors.
This commit is contained in:
parent
b502ddc39f
commit
3543e015f4
@ -1,5 +1,8 @@
|
|||||||
2001-07-24 Pavel Roskin <proski@gnu.org>
|
2001-07-24 Pavel Roskin <proski@gnu.org>
|
||||||
|
|
||||||
|
* gutil.c: Remove broken child management.
|
||||||
|
(my_system): Fix file modes for standard descriptors.
|
||||||
|
|
||||||
* glayout.c (create_new_menu): Use fixed meny position instead
|
* glayout.c (create_new_menu): Use fixed meny position instead
|
||||||
of gnome_app_find_menu_pos() - the later is not reliable and
|
of gnome_app_find_menu_pos() - the later is not reliable and
|
||||||
breaks in many locales.
|
breaks in many locales.
|
||||||
|
107
gnome/gutil.c
107
gnome/gutil.c
@ -48,66 +48,11 @@
|
|||||||
#include <gdk/gdkprivate.h>
|
#include <gdk/gdkprivate.h>
|
||||||
#include "global.h"
|
#include "global.h"
|
||||||
|
|
||||||
static struct sigaction previous_sigchld;
|
int my_system (int flags, const char *shell, const char *command)
|
||||||
static int child_died_notify_handler;
|
{
|
||||||
|
|
||||||
/*
|
|
||||||
* A list of childs that were executed with a temporary file
|
|
||||||
* We remove the files when they die
|
|
||||||
*/
|
|
||||||
static GList *children;
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
pid_t pid;
|
pid_t pid;
|
||||||
char *temp_file;
|
|
||||||
} Child;
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Received when a child dies, notifies the high level routione
|
|
||||||
* that new input is available
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
gnome_sigchld_handler (int sig)
|
|
||||||
{
|
|
||||||
char c;
|
|
||||||
|
|
||||||
if (previous_sigchld.sa_handler != SIG_IGN &&
|
|
||||||
previous_sigchld.sa_handler != SIG_DFL){
|
|
||||||
(*previous_sigchld.sa_handler)(sig);
|
|
||||||
}
|
|
||||||
write (child_died_notify_handler, &c, sizeof (c));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Invoked from the main loop when a child has died
|
|
||||||
* deal with it
|
|
||||||
*/
|
|
||||||
static void
|
|
||||||
gnome_child_died (gpointer data, gint source, GdkInputCondition condition)
|
|
||||||
{
|
|
||||||
GList *l;
|
|
||||||
char c;
|
|
||||||
|
|
||||||
read (source, &c, sizeof (c));
|
|
||||||
for (l = children; l; l = l->next){
|
|
||||||
int status;
|
|
||||||
Child *child = l->data;
|
|
||||||
|
|
||||||
if (child->pid == waitpid (child->pid, &status, WUNTRACED | WNOHANG)){
|
|
||||||
children = g_list_remove (children, child);
|
|
||||||
|
|
||||||
unlink (child->temp_file);
|
|
||||||
g_free (child->temp_file);
|
|
||||||
g_free (child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int my_system_get_child_pid (int flags, const char *shell, const char *command, pid_t *pid)
|
|
||||||
{
|
|
||||||
struct sigaction ignore, save_intr, save_quit, save_stop;
|
struct sigaction ignore, save_intr, save_quit, save_stop;
|
||||||
int status = 0, i;
|
int status = 0, i;
|
||||||
static int gnome_sigchld_installed;
|
|
||||||
|
|
||||||
ignore.sa_handler = SIG_IGN;
|
ignore.sa_handler = SIG_IGN;
|
||||||
sigemptyset (&ignore.sa_mask);
|
sigemptyset (&ignore.sa_mask);
|
||||||
@ -116,25 +61,10 @@ int my_system_get_child_pid (int flags, const char *shell, const char *command,
|
|||||||
sigaction (SIGINT, &ignore, &save_intr);
|
sigaction (SIGINT, &ignore, &save_intr);
|
||||||
sigaction (SIGQUIT, &ignore, &save_quit);
|
sigaction (SIGQUIT, &ignore, &save_quit);
|
||||||
|
|
||||||
if (!gnome_sigchld_installed){
|
if ((pid = fork ()) < 0){
|
||||||
struct sigaction newsig;
|
|
||||||
int monitors [2];
|
|
||||||
|
|
||||||
pipe (monitors);
|
|
||||||
sigemptyset (&newsig.sa_mask);
|
|
||||||
newsig.sa_flags = 0;
|
|
||||||
newsig.sa_handler = gnome_sigchld_handler;
|
|
||||||
|
|
||||||
sigaction (SIGCHLD, &newsig, &previous_sigchld);
|
|
||||||
gnome_sigchld_installed = 1;
|
|
||||||
|
|
||||||
gdk_input_add (monitors [0], GDK_INPUT_READ, gnome_child_died, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ((*pid = fork ()) < 0){
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (*pid == 0){
|
if (pid == 0){
|
||||||
const int top = max_open_files ();
|
const int top = max_open_files ();
|
||||||
struct sigaction default_pipe;
|
struct sigaction default_pipe;
|
||||||
|
|
||||||
@ -156,18 +86,18 @@ int my_system_get_child_pid (int flags, const char *shell, const char *command,
|
|||||||
/* Setup the file descriptor for the child */
|
/* Setup the file descriptor for the child */
|
||||||
|
|
||||||
/* stdin */
|
/* stdin */
|
||||||
open ("/dev/null", O_APPEND);
|
open ("/dev/null", O_RDONLY);
|
||||||
|
|
||||||
/* stdout */
|
/* stdout */
|
||||||
open ("/dev/null", O_RDONLY);
|
open ("/dev/null", O_WRONLY);
|
||||||
|
|
||||||
/* stderr */
|
/* stderr */
|
||||||
open ("/dev/null", O_RDONLY);
|
open ("/dev/null", O_WRONLY);
|
||||||
|
|
||||||
if (!(flags & EXECUTE_WAIT))
|
if (!(flags & EXECUTE_WAIT))
|
||||||
*pid = fork ();
|
pid = fork ();
|
||||||
|
|
||||||
if (*pid == 0){
|
if (pid == 0){
|
||||||
if (flags & EXECUTE_AS_SHELL)
|
if (flags & EXECUTE_AS_SHELL)
|
||||||
execl (shell, shell, "-c", command, (char *) 0);
|
execl (shell, shell, "-c", command, (char *) 0);
|
||||||
else
|
else
|
||||||
@ -178,15 +108,7 @@ int my_system_get_child_pid (int flags, const char *shell, const char *command,
|
|||||||
int status;
|
int status;
|
||||||
|
|
||||||
if (flags & EXECUTE_WAIT)
|
if (flags & EXECUTE_WAIT)
|
||||||
waitpid (*pid, &status, 0);
|
waitpid (pid, &status, 0);
|
||||||
|
|
||||||
if (flags & EXECUTE_TEMPFILE){
|
|
||||||
Child *child;
|
|
||||||
|
|
||||||
child = g_new (Child, 1);
|
|
||||||
child->pid = *pid;
|
|
||||||
child->temp_file = g_strdup (command);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* We need to use _exit instead of exit to avoid
|
/* We need to use _exit instead of exit to avoid
|
||||||
* calling the atexit handlers (specifically the gdk atexit
|
* calling the atexit handlers (specifically the gdk atexit
|
||||||
@ -194,17 +116,10 @@ int my_system_get_child_pid (int flags, const char *shell, const char *command,
|
|||||||
*/
|
*/
|
||||||
_exit (0);
|
_exit (0);
|
||||||
}
|
}
|
||||||
waitpid (*pid, &status, 0);
|
waitpid (pid, &status, 0);
|
||||||
sigaction (SIGINT, &save_intr, NULL);
|
sigaction (SIGINT, &save_intr, NULL);
|
||||||
sigaction (SIGQUIT, &save_quit, NULL);
|
sigaction (SIGQUIT, &save_quit, NULL);
|
||||||
sigaction (SIGTSTP, &save_stop, NULL);
|
sigaction (SIGTSTP, &save_stop, NULL);
|
||||||
|
|
||||||
return WEXITSTATUS(status);
|
return WEXITSTATUS(status);
|
||||||
}
|
}
|
||||||
|
|
||||||
int my_system (int flags, const char *shell, const char *command)
|
|
||||||
{
|
|
||||||
pid_t pid;
|
|
||||||
|
|
||||||
return my_system_get_child_pid (flags, shell, command, &pid);
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user