Back to index

php5  5.3.10
fpm_trace_pread.c
Go to the documentation of this file.
00001 
00002        /* $Id: fpm_trace_pread.c,v 1.7 2008/08/26 15:09:15 anight Exp $ */
00003        /* (c) 2007,2008 Andrei Nigmatulin */
00004 
00005 #define _GNU_SOURCE
00006 #define _FILE_OFFSET_BITS 64
00007 
00008 #include "fpm_config.h"
00009 
00010 #include <unistd.h>
00011 
00012 #include <fcntl.h>
00013 #include <stdio.h>
00014 #if HAVE_INTTYPES_H
00015 # include <inttypes.h>
00016 #else
00017 # include <stdint.h>
00018 #endif
00019 
00020 #include "fpm_trace.h"
00021 #include "fpm_process_ctl.h"
00022 #include "zlog.h"
00023 
00024 static int mem_file = -1;
00025 
00026 int fpm_trace_signal(pid_t pid) /* {{{ */
00027 {
00028        if (0 > fpm_pctl_kill(pid, FPM_PCTL_STOP)) {
00029               zlog(ZLOG_SYSERROR, "failed to send SIGSTOP to %d", pid);
00030               return -1;
00031        }
00032        return 0;
00033 }
00034 /* }}} */
00035 
00036 int fpm_trace_ready(pid_t pid) /* {{{ */
00037 {
00038        char buf[128];
00039 
00040        sprintf(buf, "/proc/%d/" PROC_MEM_FILE, (int) pid);
00041        mem_file = open(buf, O_RDONLY);
00042        if (0 > mem_file) {
00043               zlog(ZLOG_SYSERROR, "failed to open %s", buf);
00044               return -1;
00045        }
00046        return 0;
00047 }
00048 /* }}} */
00049 
00050 int fpm_trace_close(pid_t pid) /* {{{ */
00051 {
00052        close(mem_file);
00053        mem_file = -1;
00054        return 0;
00055 }
00056 /* }}} */
00057 
00058 int fpm_trace_get_long(long addr, long *data) /* {{{ */
00059 {
00060        if (sizeof(*data) != pread(mem_file, (void *) data, sizeof(*data), (uintptr_t) addr)) {
00061               zlog(ZLOG_SYSERROR, "pread() failed");
00062               return -1;
00063        }
00064        return 0;
00065 }
00066 /* }}} */
00067