Problem with using PT_SYSCALL.
Hi! I've been experimenting with ptrace() and found out that simply following man (2) ptrace is not enough. The attached problem is supposed to run /bin/ls / and stop at every system call it makes. The problem is that ptrace(PT_SYSCALL,...) at the end of the main loop seems simply to resume the child and make it run until it exits, but not until it makes a system call. Attached program works as expected under FreeBSD and Linux, so I believe there is some detail that needs to be taken into account for NetBSD and that I have missed. Can you please give a hint how to correct this program? --- #include stdio.h #include stdlib.h #include unistd.h #include signal.h #include string.h #include sys/types.h #include sys/wait.h #include sys/ptrace.h #include errno.h #if defined(BSD) #define REQ_TRACE_MEPT_TRACE_ME #define REQ_SYSCALL PT_SYSCALL #define REQ_KILLPT_KILL #define CONT_ADDR (caddr_t)1 #elif defined(LINUX) #define REQ_TRACE_MEPTRACE_TRACEME #define REQ_SYSCALL PTRACE_SYSCALL #define REQ_KILLPTRACE_KILL #define CONT_ADDR NULL #else #error Define BSD or LINUX. #endif static void die(const char *msg) { printf(%s, errno=%d\n,msg,errno); _exit(1); } static void child() { const char *args[] = {/bin/ls,/,NULL}; const char *env[] = {NULL}; if(0ptrace(REQ_TRACE_ME,0,NULL,0)) die(failed to trace myself); execve(args[0],(char * const *)args,(char * const *)env); die(failed to start the child); } int main() { pid_t p; int status; int sig; p=fork(); if(p0) die(failed to fork); if(!p) child(); for(;;) { if(0waitpid(p,status,0)) die(failed to wait for child); if(WIFSTOPPED(status)) { sig=WSTOPSIG(status); printf(child stopped by signal %d (%s)\n,sig,strsignal(sig)); if(sig!=SIGTRAP) { printf(signal is not SIGTRAP; killing child\n); if(0ptrace(REQ_KILL,p,NULL,0)) die(failed to kill the child); break; } } else if(WIFSIGNALED(status)) { sig=WTERMSIG(status); printf(child was signaled by signal %d (%d)\n, sig,strsignal(sig)); if(0ptrace(REQ_KILL,p,NULL,0)) die(failed to kill the child); break; } else if(WIFEXITED(status)) { printf(child exited with status %d\n,WEXITSTATUS(status)); break; } else { printf(neither stopped, nor signaled, nor killed?\n); if(0ptrace(PT_KILL,p,NULL,0)) die(failed to kill the child); break; } printf(resuming the child\n); if(0ptrace(REQ_SYSCALL,p,CONT_ADDR,0)) die(failed to resume the child); } return 0; } ---
Re: Problem with using PT_SYSCALL.
In article 201007161241.30007.aanisi...@inbox.ru, Ð Ñ Ñ ÐµÐ¼ Ð Ð½Ð¸Ñ Ð¸Ð¼Ð¾Ð² aanisi...@inbox.ru wrote: Hi! I've been experimenting with ptrace() and found out that simply following man (2) ptrace is not enough. The attached problem is supposed to run /bin/ls / and stop at every system call it makes. The problem is that ptrace(PT_SYSCALL,...) at the end of the main loop seems simply to resume the child and make it run until it exits, but not until it makes a system call. Attached program works as expected under FreeBSD and Linux, so I believe there is some detail that needs to be taken into account for NetBSD and that I have missed. Can you please give a hint how to correct this program? I think that the problem is not with your program, someone broke PT_SYSCALL. Please file a PR with the code so that it does not get lost. christos
Add NULL power handler to x86/ipmi(4)
Is there any reason anyone can think of to not add a NULL power handler to the ipmi(4) driver? I can't see any reason for anything special to happen either at suspend or resume, and the lack of a power handler prevents the system from going to sleep at all. Proposed patch is attached. - | Paul Goyette | PGP Key fingerprint: | E-mail addresses: | | Customer Service | FA29 0E3B 35AF E8AE 6651 | paul at whooppee.com| | Network Engineer | 0786 F758 55DE 53BA 7731 | pgoyette at juniper.net | | Kernel Developer | | pgoyette at netbsd.org | -Index: ipmi.c === RCS file: /cvsroot/src/sys/arch/x86/x86/ipmi.c,v retrieving revision 1.46 diff -u -p -r1.46 ipmi.c --- ipmi.c 10 Apr 2010 19:02:39 - 1.46 +++ ipmi.c 16 Jul 2010 12:19:09 - @@ -1934,6 +1934,10 @@ ipmi_thread(void *cookie) sc-sc_wdog.smw_tickle = ipmi_watchdog_tickle; sysmon_wdog_register(sc-sc_wdog); + /* Set up a NULL power handler so we can possibly sleep */ + if (!pmf_device_register(self, NULL, NULL)) +aprint_error_dev(self, couldn't establish a power handler\n); + mutex_enter(sc-sc_poll_mtx); while (sc-sc_thread_running) { ipmi_refresh_sensors(sc);
Re: Add NULL power handler to x86/ipmi(4)
On Fri, Jul 16, 2010 at 04:43:02PM -0700, Paul Goyette wrote: Is there any reason anyone can think of to not add a NULL power handler to the ipmi(4) driver? I can't see any reason for anything special to happen either at suspend or resume, and the lack of a power handler prevents the system from going to sleep at all. ipmi(4) should probably not suspend if its watchdog timer is active. Dave -- David Young OJC Technologies dyo...@ojctech.com Urbana, IL * (217) 278-3933