From 9c27e87a499ba017bb01d5d8f44d6abbd98c22f6 Mon Sep 17 00:00:00 2001
From: Moe Jette <jette1@llnl.gov>
Date: Tue, 25 May 2004 21:48:38 +0000
Subject: [PATCH] Add support for AIX's five argument ptrace function (Linux
 has four args).

---
 NEWS                  |  1 +
 auxdir/Makefile.am    |  1 +
 auxdir/x_ac_ptrace.m4 | 26 ++++++++++++++++++++++++++
 configure.ac          |  3 +++
 src/slurmd/smgr.c     |  8 ++++++++
 5 files changed, 39 insertions(+)
 create mode 100644 auxdir/x_ac_ptrace.m4

diff --git a/NEWS b/NEWS
index 6a6b491a16c..af51778dc51 100644
--- a/NEWS
+++ b/NEWS
@@ -10,6 +10,7 @@ documents those changes that are of interest to users and admins.
     responding in a timely fashion) then send a registration RPC
     to slurmctld
  -- Add "slurm_" prefix to slurm's hostlist_ function man pages.
+ -- More AIX support added.
 
 * Changes in SLURM 0.3.1
 ========================
diff --git a/auxdir/Makefile.am b/auxdir/Makefile.am
index 605caddb5e5..917a22d47db 100644
--- a/auxdir/Makefile.am
+++ b/auxdir/Makefile.am
@@ -12,6 +12,7 @@ EXTRA_DIST = \
     x_ac_debug.m4 \
     x_ac_elan.m4 \
     x_ac_gpl_licensed.m4 \
+    x_ac_ptrace.m4 \
     x_ac_readline.m4 \
     x_ac_setproctitle.m4 \
     x_ac_slurm_ssl.m4 
diff --git a/auxdir/x_ac_ptrace.m4 b/auxdir/x_ac_ptrace.m4
new file mode 100644
index 00000000000..c952656ebdd
--- /dev/null
+++ b/auxdir/x_ac_ptrace.m4
@@ -0,0 +1,26 @@
+##*****************************************************************************
+#  $Id$
+##*****************************************************************************
+#  AUTHOR:
+#    Morris Jette <jette1@llnl.gov>
+#
+#  SYNOPSIS:
+#    X_AC_PTRACE
+#
+#  DESCRIPTION:
+#    Test argument count of ptrace function.
+#
+#  WARNINGS:
+#    This macro must be placed after AC_PROG_CC or equivalent.
+##*****************************************************************************
+
+AC_DEFUN([X_AC_PTRACE], [
+  AC_TRY_COMPILE(
+   [#include <sys/reg.h>
+    #include <sys/ptrace.h>
+    #include <sys/ldr.h>], 
+   [ptrace(PT_TRACE_ME,0,0,0,0);],
+   [AC_DEFINE(PTRACE_FIVE_ARGS, 1,
+             [Define to 1 if ptrace takes five arguments.])])
+])
+
diff --git a/configure.ac b/configure.ac
index bea8f763a3e..749e7e8f325 100644
--- a/configure.ac
+++ b/configure.ac
@@ -58,6 +58,9 @@ dnl check to see if glibc's program_invocation_short_name is available:
 dnl
 X_AC_SLURM_PROGRAM_INVOCATION_SHORT_NAME
 
+dnl Check if ptrace takes four or five arguments
+dnl
+X_AC_PTRACE
 
 dnl Checks for types.
 dnl
diff --git a/src/slurmd/smgr.c b/src/slurmd/smgr.c
index b0c51aaa9af..604bac3503d 100644
--- a/src/slurmd/smgr.c
+++ b/src/slurmd/smgr.c
@@ -562,7 +562,11 @@ _pdebug_trace_process(slurmd_job_t *job, pid_t pid)
 		waitpid(pid, &status, WUNTRACED);
 		if (kill(pid, SIGSTOP) < 0)
 			error("kill(%lu): %m", (unsigned long) pid);
+#ifdef PTRACE_FIVE_ARGS
+		if (ptrace(PTRACE_DETACH, (long) pid, NULL, 0, NULL))
+#else
 		if (ptrace(PTRACE_DETACH, (long) pid, NULL, NULL))
+#endif
 			error("ptrace(%lu): %m", (unsigned long) pid);
 	}
 }
@@ -577,6 +581,10 @@ _pdebug_stop_current(slurmd_job_t *job)
 	 * Stop the task on exec for TotalView to connect 
 	 */
 	if ( (job->task_flags & TASK_PARALLEL_DEBUG)
+#ifdef PTRACE_FIVE_ARGS
+	     && (ptrace(PTRACE_TRACEME, 0, NULL, 0, NULL) < 0) )
+#else
 	     && (ptrace(PTRACE_TRACEME, 0, NULL, NULL) < 0) )
+#endif
 		error("ptrace: %m");
 }
-- 
GitLab