mirror of
git://sourceware.org/git/newlib-cygwin.git
synced 2025-03-02 13:05:42 +08:00
* syscalls.cc (struct system_cleanup_args): New struct.
(system_cleanup): New function. (system): Use pthread_cleanup_push and _pop to save and restore signal handlers and sigprocmask.
This commit is contained in:
parent
53c384f206
commit
5ae9331a32
@ -1,3 +1,10 @@
|
|||||||
|
2003-02-04 Thomas Pfaff <tpfaff@gmx.net>
|
||||||
|
|
||||||
|
* syscalls.cc (struct system_cleanup_args): New struct.
|
||||||
|
(system_cleanup): New function.
|
||||||
|
(system): Use pthread_cleanup_push and _pop to save and restore
|
||||||
|
signal handlers and sigprocmask.
|
||||||
|
|
||||||
2003-02-04 Corinna Vinschen <corinna@vinschen.de>
|
2003-02-04 Corinna Vinschen <corinna@vinschen.de>
|
||||||
|
|
||||||
* path.cc (symlink): Create security attributes so that only the
|
* path.cc (symlink): Create security attributes so that only the
|
||||||
|
@ -1371,6 +1371,21 @@ done:
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct system_cleanup_args
|
||||||
|
{
|
||||||
|
_sig_func_ptr oldint, oldquit;
|
||||||
|
sigset_t old_mask;
|
||||||
|
};
|
||||||
|
|
||||||
|
static void system_cleanup (void *args)
|
||||||
|
{
|
||||||
|
struct system_cleanup_args *cleanup_args = (struct system_cleanup_args *) args;
|
||||||
|
|
||||||
|
signal (SIGINT, cleanup_args->oldint);
|
||||||
|
signal (SIGQUIT, cleanup_args->oldquit);
|
||||||
|
(void) sigprocmask (SIG_SETMASK, &cleanup_args->old_mask, 0);
|
||||||
|
}
|
||||||
|
|
||||||
extern "C" int
|
extern "C" int
|
||||||
system (const char *cmdstring)
|
system (const char *cmdstring)
|
||||||
{
|
{
|
||||||
@ -1382,23 +1397,25 @@ system (const char *cmdstring)
|
|||||||
sigframe thisframe (mainthread);
|
sigframe thisframe (mainthread);
|
||||||
int res;
|
int res;
|
||||||
const char* command[4];
|
const char* command[4];
|
||||||
_sig_func_ptr oldint, oldquit;
|
struct system_cleanup_args cleanup_args;
|
||||||
sigset_t child_block, old_mask;
|
sigset_t child_block;
|
||||||
|
|
||||||
if (cmdstring == (const char *) NULL)
|
if (cmdstring == (const char *) NULL)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
oldint = signal (SIGINT, SIG_IGN);
|
cleanup_args.oldint = signal (SIGINT, SIG_IGN);
|
||||||
oldquit = signal (SIGQUIT, SIG_IGN);
|
cleanup_args.oldquit = signal (SIGQUIT, SIG_IGN);
|
||||||
sigemptyset (&child_block);
|
sigemptyset (&child_block);
|
||||||
sigaddset (&child_block, SIGCHLD);
|
sigaddset (&child_block, SIGCHLD);
|
||||||
(void) sigprocmask (SIG_BLOCK, &child_block, &old_mask);
|
(void) sigprocmask (SIG_BLOCK, &child_block, &cleanup_args.old_mask);
|
||||||
|
|
||||||
command[0] = "sh";
|
command[0] = "sh";
|
||||||
command[1] = "-c";
|
command[1] = "-c";
|
||||||
command[2] = cmdstring;
|
command[2] = cmdstring;
|
||||||
command[3] = (const char *) NULL;
|
command[3] = (const char *) NULL;
|
||||||
|
|
||||||
|
pthread_cleanup_push (system_cleanup, (void *) &cleanup_args);
|
||||||
|
|
||||||
if ((res = spawnvp (_P_WAIT, "sh", command)) == -1)
|
if ((res = spawnvp (_P_WAIT, "sh", command)) == -1)
|
||||||
{
|
{
|
||||||
// when exec fails, return value should be as if shell
|
// when exec fails, return value should be as if shell
|
||||||
@ -1406,9 +1423,8 @@ system (const char *cmdstring)
|
|||||||
res = 127;
|
res = 127;
|
||||||
}
|
}
|
||||||
|
|
||||||
signal (SIGINT, oldint);
|
pthread_cleanup_pop (1);
|
||||||
signal (SIGQUIT, oldquit);
|
|
||||||
(void) sigprocmask (SIG_SETMASK, &old_mask, 0);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user