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