From: Julian Seward Date: Sat, 13 Jan 2007 22:27:51 +0000 (+0000) Subject: When '-d' (one or more) is specified, disallow the client from closing X-Git-Tag: svn/VALGRIND_3_3_0~423 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e71365244a5ccc60c74ec61d0fa78b79cc870acc;p=thirdparty%2Fvalgrind.git When '-d' (one or more) is specified, disallow the client from closing fd 2 (stderr) since that's what m_debuglog writes to, and the resulting disappearance of the debug log can be confusing. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@6519 --- diff --git a/coregrind/m_syswrap/syswrap-aix5.c b/coregrind/m_syswrap/syswrap-aix5.c index e0a518b1fc..7bc970e50c 100644 --- a/coregrind/m_syswrap/syswrap-aix5.c +++ b/coregrind/m_syswrap/syswrap-aix5.c @@ -764,6 +764,10 @@ PRE(sys_close) { PRINT("close ( %ld )", ARG1); PRE_REG_READ1(void, "close", UInt, fd); + /* If doing -d style logging (which is to fd=2), don't allow that + to be closed. */ + if (ARG1 == 2/*stderr*/ && VG_(debugLog_getLevel)() > 0) + SET_STATUS_Failure( VKI_EBADF ); } PRE(sys_connext) diff --git a/coregrind/m_syswrap/syswrap-generic.c b/coregrind/m_syswrap/syswrap-generic.c index 02daf2d83d..c3a10a08e6 100644 --- a/coregrind/m_syswrap/syswrap-generic.c +++ b/coregrind/m_syswrap/syswrap-generic.c @@ -2668,7 +2668,10 @@ PRE(sys_close) PRE_REG_READ1(long, "close", unsigned int, fd); /* Detect and negate attempts by the client to close Valgrind's log fd */ - if (!ML_(fd_allowed)(ARG1, "close", tid, False)) + if ( (!ML_(fd_allowed)(ARG1, "close", tid, False)) + /* If doing -d style logging (which is to fd=2), don't + allow that to be closed either. */ + || (ARG1 == 2/*stderr*/ && VG_(debugLog_getLevel)() > 0) ) SET_STATUS_Failure( VKI_EBADF ); }