make sure signals are only handled by the main thread. Fix bus error on rclmon exit (double delete)
This commit is contained in:
+2
-11
@@ -1,5 +1,5 @@
|
||||
#ifndef lint
|
||||
static char rcsid[] = "@(#$Id: execmd.cpp,v 1.22 2007-02-19 18:14:13 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
static char rcsid[] = "@(#$Id: execmd.cpp,v 1.23 2007-05-21 13:30:22 dockes Exp $ (C) 2004 J.F.Dockes";
|
||||
#endif
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
@@ -26,6 +26,7 @@ static char rcsid[] = "@(#$Id: execmd.cpp,v 1.22 2007-02-19 18:14:13 dockes Exp
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
|
||||
#ifdef PUTENV_ARG_NOT_CONST
|
||||
#include <string.h>
|
||||
#endif
|
||||
@@ -178,14 +179,6 @@ int ExecCmd::doexec(const string &cmd, const list<string>& args,
|
||||
}
|
||||
|
||||
if (e.pid) {
|
||||
// Ignore SIGPIPE and block SIGCHLD in here.
|
||||
void (*osig)(int);
|
||||
osig = signal(SIGPIPE, SIG_IGN);
|
||||
sigset_t blkcld;
|
||||
sigemptyset(&blkcld);
|
||||
sigaddset(&blkcld, SIGCHLD);
|
||||
sigprocmask(SIG_BLOCK, &blkcld, 0);
|
||||
|
||||
// Father process
|
||||
if (input) {
|
||||
close(e.pipein[0]);
|
||||
@@ -286,8 +279,6 @@ int ExecCmd::doexec(const string &cmd, const list<string>& args,
|
||||
(void)waitpid(e.pid, &status, 0);
|
||||
e.pid = -1;
|
||||
}
|
||||
signal(SIGPIPE, osig);
|
||||
sigprocmask(SIG_UNBLOCK, &blkcld, 0);
|
||||
LOGDEB1(("ExecCmd::doexec: father got status 0x%x\n", status));
|
||||
return haderror ? -1 : status;
|
||||
|
||||
|
||||
+5
-1
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
#ifndef _EXECMD_H_INCLUDED_
|
||||
#define _EXECMD_H_INCLUDED_
|
||||
/* @(#$Id: execmd.h,v 1.11 2006-12-14 13:53:43 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
/* @(#$Id: execmd.h,v 1.12 2007-05-21 13:30:22 dockes Exp $ (C) 2004 J.F.Dockes */
|
||||
|
||||
#include <string>
|
||||
#include <list>
|
||||
@@ -55,6 +55,10 @@ class ExecCmdProvide {
|
||||
* Output from the command is normally returned in a single string, but a
|
||||
* callback can be set to be called whenever new data arrives, in which case
|
||||
* it is permissible to consume the data and erase the string.
|
||||
*
|
||||
* Note that SIGPIPE should be ignored and SIGCLD blocked when calling doexec,
|
||||
* else things might fail randomly. (This is not done inside the class because
|
||||
* of concerns with multithreaded programs).
|
||||
*
|
||||
*/
|
||||
class ExecCmd {
|
||||
|
||||
Reference in New Issue
Block a user