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