xref: /php-src/sapi/fpm/fpm/fpm_trace_pread.c (revision 067df263)
1 	/* (c) 2007,2008 Andrei Nigmatulin */
2 
3 #ifndef _GNU_SOURCE
4 # define _GNU_SOURCE
5 #endif
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 #include <inttypes.h>
15 
16 #include "fpm_trace.h"
17 #include "fpm_process_ctl.h"
18 #include "zlog.h"
19 
20 static int mem_file = -1;
21 
fpm_trace_signal(pid_t pid)22 int fpm_trace_signal(pid_t pid) /* {{{ */
23 {
24 	if (0 > fpm_pctl_kill(pid, FPM_PCTL_STOP)) {
25 		zlog(ZLOG_SYSERROR, "failed to send SIGSTOP to %d", pid);
26 		return -1;
27 	}
28 	return 0;
29 }
30 /* }}} */
31 
fpm_trace_ready(pid_t pid)32 int fpm_trace_ready(pid_t pid) /* {{{ */
33 {
34 	char buf[128];
35 
36 	sprintf(buf, "/proc/%d/" PROC_MEM_FILE, (int) pid);
37 	mem_file = open(buf, O_RDONLY);
38 	if (0 > mem_file) {
39 		zlog(ZLOG_SYSERROR, "failed to open %s", buf);
40 		return -1;
41 	}
42 	return 0;
43 }
44 /* }}} */
45 
fpm_trace_close(pid_t pid)46 int fpm_trace_close(pid_t pid) /* {{{ */
47 {
48 	close(mem_file);
49 	mem_file = -1;
50 	return 0;
51 }
52 /* }}} */
53 
fpm_trace_get_long(long addr,long * data)54 int fpm_trace_get_long(long addr, long *data) /* {{{ */
55 {
56 	if (sizeof(*data) != pread(mem_file, (void *) data, sizeof(*data), (uintptr_t) addr)) {
57 		zlog(ZLOG_SYSERROR, "pread() failed");
58 		return -1;
59 	}
60 	return 0;
61 }
62 /* }}} */
63