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