1 /* $Id: fpm_trace_pread.c,v 1.7 2008/08/26 15:09:15 anight Exp $ */
2 /* (c) 2007,2008 Andrei Nigmatulin */
3
4 #define _GNU_SOURCE
5 #define _FILE_OFFSET_BITS 64
6
7 #include "fpm_config.h"
8
9 #include <unistd.h>
10
11 #include <fcntl.h>
12 #include <stdio.h>
13 #if HAVE_INTTYPES_H
14 # include <inttypes.h>
15 #else
16 # include <stdint.h>
17 #endif
18
19 #include "fpm_trace.h"
20 #include "fpm_process_ctl.h"
21 #include "zlog.h"
22
23 static int mem_file = -1;
24
fpm_trace_signal(pid_t pid)25 int fpm_trace_signal(pid_t pid) /* {{{ */
26 {
27 if (0 > fpm_pctl_kill(pid, FPM_PCTL_STOP)) {
28 zlog(ZLOG_SYSERROR, "failed to send SIGSTOP to %d", pid);
29 return -1;
30 }
31 return 0;
32 }
33 /* }}} */
34
fpm_trace_ready(pid_t pid)35 int fpm_trace_ready(pid_t pid) /* {{{ */
36 {
37 char buf[128];
38
39 sprintf(buf, "/proc/%d/" PROC_MEM_FILE, (int) pid);
40 mem_file = open(buf, O_RDONLY);
41 if (0 > mem_file) {
42 zlog(ZLOG_SYSERROR, "failed to open %s", buf);
43 return -1;
44 }
45 return 0;
46 }
47 /* }}} */
48
fpm_trace_close(pid_t pid)49 int fpm_trace_close(pid_t pid) /* {{{ */
50 {
51 close(mem_file);
52 mem_file = -1;
53 return 0;
54 }
55 /* }}} */
56
fpm_trace_get_long(long addr,long * data)57 int fpm_trace_get_long(long addr, long *data) /* {{{ */
58 {
59 if (sizeof(*data) != pread(mem_file, (void *) data, sizeof(*data), (uintptr_t) addr)) {
60 zlog(ZLOG_SYSERROR, "pread() failed");
61 return -1;
62 }
63 return 0;
64 }
65 /* }}} */
66