Well, gdb in Debian unstable still has that fork bug, so here's a patch
to work around it; use-fork is always off in gdb.

I'm not sure if the ptrace autoconf test is tight enough; this test shouldn't
be done on anything but Linux.

By the way, a lot of your copyright dates are outdhted.

-- 
Glenn Maynard
? readline-4.2/configure
? src/.platform.cc.swp
? src/a.out
? src/b
? src/gmon.out
? src/hmm.cc
? src/platform.cc
? src/platform.h
Index: acconfig.h
===================================================================
RCS file: /home/lav/cvsroot/lftp/acconfig.h,v
retrieving revision 1.23
diff -u -r1.23 acconfig.h
--- acconfig.h  2001/08/15 15:39:22     1.23
+++ acconfig.h  2001/08/27 19:36:40
@@ -139,6 +139,9 @@
 /* md5 support is present in libc or libcrypt */
 #undef HAVE_MD5
 
+/* have Linux ptrace (for hopefully temporary gdb check) */
+#undef HAVE_LINUX_PTRACE
+
 @BOTTOM@
 
 #if !defined(HAVE_LSTAT)
Index: configure.in
===================================================================
RCS file: /home/lav/cvsroot/lftp/configure.in,v
retrieving revision 1.102
diff -u -r1.102 configure.in
--- configure.in        2001/08/23 12:25:00     1.102
+++ configure.in        2001/08/27 19:36:42
@@ -344,6 +344,20 @@
    sysconfdir=/etc
 fi
 
+
+# See if we have h_errno (the test is here so we can use -lresolv if necessary).
+AC_CACHE_CHECK([for Linux ptrace], lftp_cv_sys_linux_ptrace,
+   AC_TRY_LINK([#include <sys/ptrace.h>],
+   [
+     ptrace(PTRACE_ATTACH, 1, 0, 0);
+     ptrace(PTRACE_DETACH, 1, 0, 0);
+   ],
+     lftp_cv_sys_linux_ptrace=yes, lftp_cv_sys_linux_ptrace=no))
+
+if test "$lftp_cv_sys_linux_ptrace" = yes; then
+  AC_DEFINE(HAVE_LINUX_PTRACE)
+fi
+
 AC_LINK_FILES($LINK_SRC,$LINK_DST)
 
 AC_OUTPUT(Makefile src/Makefile lib/Makefile include/Makefile doc/Makefile
Index: src/Makefile.am
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/Makefile.am,v
retrieving revision 1.41
diff -u -r1.41 Makefile.am
--- src/Makefile.am     2001/08/27 15:42:46     1.41
+++ src/Makefile.am     2001/08/27 19:36:50
@@ -52,7 +52,7 @@
  FtpDirList.h ArgV.cc ArgV.h HttpDir.cc HttpDir.h ascii_ctype.h\
  NetAccess.cc NetAccess.h FtpSplitList.h FtpSplitList.cc Speedometer.cc\
  Speedometer.h lftp_ssl.cc lftp_ssl.h netrc.cc netrc.h buffer_ssl.cc\
- buffer_ssl.h Fish.cc Fish.h
+ buffer_ssl.h Fish.cc Fish.h platform.cc platform.h
 
 libjobs_a_SOURCES = Job.cc Job.h CmdExec.cc CmdExec.h\
  commands.cc mgetJob.h mgetJob.cc SysCmdJob.cc SysCmdJob.h rmJob.cc rmJob.h\
Index: src/Resolver.cc
===================================================================
RCS file: /home/lav/cvsroot/lftp/src/Resolver.cc,v
retrieving revision 1.47
diff -u -r1.47 Resolver.cc
--- src/Resolver.cc     2001/07/30 14:39:13     1.47
+++ src/Resolver.cc     2001/08/27 19:36:53
@@ -48,6 +48,7 @@
 #include "ResMgr.h"
 #include "log.h"
 #include "plural.h"
+#include "platform.h"
 
 #ifndef T_SRV
 # define T_SRV 33
@@ -112,6 +113,9 @@
    addr_num=0;
    buf=0;
    use_fork=ResMgr::Query("dns:use-fork",0);
+   if(in_broken_debugger()) {
+     use_fork=false;
+   }
 
    error=0;
 
/*
 * platform-specific code
 *
 * Copyright (c) 2001 by Alexander V. Lukyanov ([EMAIL PROTECTED])
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include <config.h>

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <assert.h>

#include <signal.h>

#include <sys/types.h>
#include <sys/wait.h>

#include "ProcWait.h"

/* Figure out if we're in a debugger; this is used to work around a gdb bug
 * which prevents forked DNS from working.  This can be removed if that bug
 * ever gets fixed. */
#if HAVE_LINUX_PTRACE
#include <sys/ptrace.h>
bool in_broken_debugger()
{
	ProcWait::Signal(false);

	int cpid = fork();
	assert(cpid != -1);

	if(cpid == 0) {
		signal(SIGCHLD, SIG_IGN);
		if(ptrace(PTRACE_ATTACH, getppid(), NULL, NULL) == -1) {
			/* Attach failed; it's probably already being debugged. */
			if(errno != EPERM)
				fprintf(stderr, "c ptrace: unexpected error: %s\n", strerror(errno));
			exit(1);
		}
		
		/* We just SIGSTOPped it; we need to CONT it now. */
		int ret;
		waitpid(getppid(), &ret, 0);

		if(ptrace(PTRACE_DETACH, getppid(), NULL, NULL) == -1)
			fprintf(stderr, "detach failed: %s\n", strerror(errno));

		kill(getppid(), SIGCONT);

		exit(0);
	}
	int ret;
	waitpid(cpid, &ret, 0);
	assert(!WIFSIGNALED(ret));

	ProcWait::Signal(true);

	return WEXITSTATUS(ret) != 0;
}
#else
bool in_broken_debugger()
{
	return false;
}
#endif
/*
 * lftp and utils
 *
 * Copyright (c) 1996-1998 by Alexander V. Lukyanov ([EMAIL PROTECTED])
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef PLATFORM_H
#define PLATFORM_H

bool in_broken_debugger();

#endif

Reply via email to