=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/pmdb/Attic/process.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- src/usr.bin/pmdb/Attic/process.c 2002/03/19 07:26:58 1.3 +++ src/usr.bin/pmdb/Attic/process.c 2002/06/09 02:44:13 1.4 @@ -1,4 +1,4 @@ -/* $OpenBSD: process.c,v 1.3 2002/03/19 07:26:58 fgsch Exp $ */ +/* $OpenBSD: process.c,v 1.4 2002/06/09 02:44:13 todd Exp $ */ /* * Copyright (c) 2002 Artur Grabowski * All rights reserved. @@ -27,6 +27,8 @@ #include #include #include +#include + #include #include #include @@ -53,20 +55,34 @@ return (0); } - switch (ps->ps_pid = fork()) { - case 0: - if (ptrace(PT_TRACE_ME, getpid(), NULL, 0) != 0) - err(1, "ptrace(PT_TRACE_ME)"); - execvp(*ps->ps_argv, ps->ps_argv); - err(1, "exec"); - /* NOTREACHED */ - case -1: - err(1, "fork"); - /* NOTREACHED */ - default: - break; + if (stat(ps->ps_argv[0], &(ps->exec_stat)) < 0) + err(1, "stat()"); + + if (ps->ps_pid != 0) { + /* attach to an already running process */ + if (ptrace(PT_ATTACH, ps->ps_pid, (caddr_t) 0, 0) < 0) + err(1, "failed to ptrace process"); + ps->ps_state = STOPPED; + ps->ps_flags |= PSF_ATCH; } + else { + switch (ps->ps_pid = fork()) { + case 0: + if (ptrace(PT_TRACE_ME, getpid(), NULL, 0) != 0) + err(1, "ptrace(PT_TRACE_ME)"); + execvp(*ps->ps_argv, ps->ps_argv); + err(1, "exec"); + /* NOTREACHED */ + case -1: + err(1, "fork"); + /* NOTREACHED */ + default: + break; + } + ps->ps_state = LOADED; + } + if ((ps->ps_flags & PSF_SYMBOLS) == 0) { sym_init_exec(ps, ps->ps_argv[0]); ps->ps_flags |= PSF_SYMBOLS; @@ -75,7 +91,6 @@ if (wait(&status) == 0) err(1, "wait"); - ps->ps_state = LOADED; return 0; }