Executive summary:
If PR_KLC is set for a process, should Prelease() cause the process to
be killed?
Details:
I've been looking at 6712247 ("dtrace -c runs the program despite
errors"), and it looks like libdtrace expects Prelease() to terminate
a process if PR_KLC is set. The code that shows this assumption is
the following from
http://src.opensolaris.org/source/xref/onnv/onnv-gate/usr/src/lib/libdtrace/common/dt_proc.c:
707 /*
708 * If neither PR_KLC nor PR_RLC is set, then the process is
stopped by
709 * an external debugger and we were waiting in
dt_proc_waitrun().
710 * Leave the process in this condition using PRELEASE_HANG.
711 */
712 if (!(Pstatus(dpr->dpr_proc)->pr_flags & (PR_KLC | PR_RLC))) {
713 dt_dprintf("abandoning pid %d\n", (int)dpr->dpr_pid);
714 rflag = PRELEASE_HANG;
715 } else {
716 dt_dprintf("releasing pid %d\n", (int)dpr->dpr_pid);
717 rflag = 0; /* apply kill or run-on-last-close */
718 }
The following program demonstrates that a process with PR_KLC set
won't be killed if Prelease() is called:
------------------------------------------------------------------------
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "libproc.h"
int
main(int argc, char *argv[])
{
int err;
pid_t pid;
struct ps_prochandle *P;
if (argc < 2 || (pid = (pid_t) atoi(argv[1])) == 0) {
fprintf(stderr, "Need a valid pid\n");
exit(1);
}
if ((P = Pgrab(pid, 0, &err)) == NULL) {
fprintf(stderr, "Couldn't grab pid %d (reason %d)\n",
(int) pid, err);
exit(1);
}
if (Punsetflags(P, PR_RLC) < 0)
fprintf(stderr, "Couldn't set PR_RLC\n");
if (Psetflags(P, PR_KLC) < 0)
fprintf(stderr, "Couldn't set PR_KLC\n");
#if 0
Prelease(P, 0);
#endif
printf("released pid %d\n", (int) pid);
}
------------------------------------------------------------------------
Without the Prelease() call, a process is killed if its pid is fed to
this program. With the Prelease() call, a process continues to run.
(I've observed what happens in prclose() when both versions of the
above program are run, but I'm really asking what _should_ happen in
this case. I can see what _is_ happening.)
Thanks,
Chad
_______________________________________________
dtrace-discuss mailing list
[email protected]