2009-11-11 10:33:28 +00:00
|
|
|
/* -*- mode: c; c-basic-offset: 4; tab-width: 4; indent-tabs-mode: t -*-
|
|
|
|
* vim: ts=4 sw=4 noet ai cindent syntax=c
|
|
|
|
*
|
|
|
|
* Conky, a system monitor, based on torsmo
|
|
|
|
*
|
|
|
|
* Any original torsmo code is licensed under the BSD license
|
|
|
|
*
|
|
|
|
* All code written since the fork of torsmo is licensed under the GPL
|
|
|
|
*
|
|
|
|
* Please see COPYING for details
|
|
|
|
*
|
|
|
|
* Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
|
|
|
|
* Copyright (c) 2005-2009 Brenden Matthews, Philip Kovacs, et. al.
|
|
|
|
* (see AUTHORS)
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "conky.h"
|
2009-11-29 15:27:12 +00:00
|
|
|
#include "core.h"
|
|
|
|
#include "logging.h"
|
2009-11-11 12:23:05 +00:00
|
|
|
#include "proc.h"
|
2009-11-11 15:27:19 +00:00
|
|
|
#include <unistd.h>
|
2009-11-11 21:56:12 +00:00
|
|
|
#include <ctype.h>
|
2009-11-12 23:36:46 +00:00
|
|
|
#include <dirent.h>
|
2009-11-11 10:33:28 +00:00
|
|
|
|
2009-11-14 21:07:54 +00:00
|
|
|
char* readfile(char* filename, int* total_read, char showerror) {
|
2009-11-14 14:08:41 +00:00
|
|
|
FILE* file;
|
|
|
|
char* buf = NULL;
|
|
|
|
int bytes_read;
|
|
|
|
|
|
|
|
*total_read = 0;
|
|
|
|
file = fopen(filename, "r");
|
|
|
|
if(file) {
|
|
|
|
do {
|
|
|
|
buf = realloc(buf, *total_read + READSIZE + 1);
|
|
|
|
bytes_read = fread(buf + *total_read, 1, READSIZE, file);
|
|
|
|
*total_read += bytes_read;
|
|
|
|
buf[*total_read] = 0;
|
|
|
|
}while(bytes_read != 0);
|
|
|
|
fclose(file);
|
2009-11-14 21:07:54 +00:00
|
|
|
} else if(showerror != 0) {
|
2009-11-14 14:08:41 +00:00
|
|
|
NORM_ERR(READERR, filename);
|
|
|
|
}
|
|
|
|
return buf;
|
|
|
|
}
|
|
|
|
|
2009-11-14 21:07:54 +00:00
|
|
|
void pid_readlink(char *file, char *p, int p_max_size)
|
|
|
|
{
|
|
|
|
char buf[p_max_size];
|
|
|
|
|
|
|
|
memset(buf, 0, p_max_size);
|
|
|
|
if(readlink(file, buf, p_max_size) >= 0) {
|
|
|
|
snprintf(p, p_max_size, "%s", buf);
|
|
|
|
} else {
|
|
|
|
NORM_ERR(READERR, file);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct ll_string {
|
|
|
|
char *string;
|
|
|
|
struct ll_string* next;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ll_string* addnode(struct ll_string* end, char* string) {
|
|
|
|
struct ll_string* current = malloc(sizeof(struct ll_string));
|
|
|
|
current->string = strdup(string);
|
|
|
|
current->next = NULL;
|
|
|
|
if(end != NULL) end->next = current;
|
|
|
|
return current;
|
|
|
|
}
|
|
|
|
|
|
|
|
void freelist(struct ll_string* front) {
|
|
|
|
if(front != NULL) {
|
|
|
|
free(front->string);
|
|
|
|
if(front->next != NULL) {
|
|
|
|
freelist(front->next);
|
|
|
|
}
|
|
|
|
free(front);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int inlist(struct ll_string* front, char* string) {
|
|
|
|
struct ll_string* current;
|
|
|
|
|
|
|
|
for(current = front; current != NULL; current = current->next) {
|
|
|
|
if(strcmp(current->string, string) == 0) {
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2009-11-29 15:27:12 +00:00
|
|
|
void extract_object_args_to_sub(struct text_object *obj, const char *args)
|
|
|
|
{
|
|
|
|
obj->sub = malloc(sizeof(struct text_object));
|
|
|
|
memset(obj->sub, 0, sizeof(struct text_object));
|
|
|
|
extract_variable_text_internal(obj->sub, args);
|
|
|
|
}
|
|
|
|
|
2009-11-14 21:07:54 +00:00
|
|
|
void print_pid_chroot(struct text_object *obj, char *p, int p_max_size) {
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char buf[max_user_text];
|
2009-11-14 21:07:54 +00:00
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(buf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/root", buf);
|
2009-11-29 14:47:56 +00:00
|
|
|
pid_readlink(pathbuf, p, p_max_size);
|
2009-11-14 21:07:54 +00:00
|
|
|
}
|
|
|
|
|
2009-11-11 15:27:19 +00:00
|
|
|
void print_pid_cmdline(struct text_object *obj, char *p, int p_max_size)
|
2009-11-11 10:33:28 +00:00
|
|
|
{
|
2009-11-14 14:08:41 +00:00
|
|
|
char* buf;
|
2009-11-11 12:43:14 +00:00
|
|
|
int i, bytes_read;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
2009-11-11 10:33:28 +00:00
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
|
|
|
|
if(*(objbuf) != 0) {
|
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/cmdline", objbuf);
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-18 17:02:10 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
for(i = 0; i < bytes_read-1; i++) {
|
|
|
|
if(buf[i] == 0) {
|
|
|
|
buf[i] = ' ';
|
|
|
|
}
|
2009-11-11 10:33:28 +00:00
|
|
|
}
|
2009-11-18 17:02:10 +00:00
|
|
|
snprintf(p, p_max_size, "%s", buf);
|
|
|
|
free(buf);
|
2009-11-11 10:33:28 +00:00
|
|
|
}
|
2009-11-18 17:02:10 +00:00
|
|
|
} else {
|
|
|
|
NORM_ERR("$pid_cmdline didn't receive a argument");
|
2009-11-11 10:33:28 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-11 15:27:19 +00:00
|
|
|
|
|
|
|
void print_pid_cwd(struct text_object *obj, char *p, int p_max_size)
|
|
|
|
{
|
|
|
|
char buf[p_max_size];
|
|
|
|
int bytes_read;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
2009-11-29 14:47:56 +00:00
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/cwd", objbuf);
|
2009-11-29 14:47:56 +00:00
|
|
|
bytes_read = readlink(pathbuf, buf, p_max_size);
|
2009-11-11 15:27:19 +00:00
|
|
|
if(bytes_read != -1) {
|
2009-11-14 21:07:54 +00:00
|
|
|
buf[bytes_read] = 0;
|
2009-11-11 15:27:19 +00:00
|
|
|
snprintf(p, p_max_size, "%s", buf);
|
|
|
|
} else {
|
2009-11-29 14:47:56 +00:00
|
|
|
NORM_ERR(READERR, pathbuf);
|
2009-11-11 15:27:19 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-11 21:56:12 +00:00
|
|
|
|
|
|
|
void print_pid_environ(struct text_object *obj, char *p, int p_max_size)
|
|
|
|
{
|
2009-11-14 21:07:54 +00:00
|
|
|
int i, total_read;
|
|
|
|
pid_t pid;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
2009-11-29 14:47:56 +00:00
|
|
|
char *buf, *var=strdup(obj->data.s);;
|
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
if(sscanf(objbuf, "%d %s", &pid, var) == 2) {
|
2009-11-14 21:07:54 +00:00
|
|
|
for(i = 0; var[i] != 0; i++) {
|
|
|
|
var[i] = toupper(var[i]);
|
|
|
|
}
|
2009-11-29 14:47:56 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%d/environ", pid);
|
|
|
|
buf = readfile(pathbuf, &total_read, 1);
|
2009-11-14 21:07:54 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
for(i = 0; i < total_read; i += strlen(buf + i) + 1) {
|
|
|
|
if(strncmp(buf + i, var, strlen(var)) == 0 && *(buf + i + strlen(var)) == '=') {
|
|
|
|
snprintf(p, p_max_size, "%s", buf + i + strlen(var) + 1);
|
|
|
|
free(buf);
|
|
|
|
free(var);
|
|
|
|
return;
|
|
|
|
}
|
2009-11-11 21:56:12 +00:00
|
|
|
}
|
2009-11-14 21:07:54 +00:00
|
|
|
free(buf);
|
2009-11-11 21:56:12 +00:00
|
|
|
}
|
2009-11-14 21:07:54 +00:00
|
|
|
free(var);
|
|
|
|
*p = 0;
|
2009-11-11 21:56:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-12 14:42:18 +00:00
|
|
|
void print_pid_environ_list(struct text_object *obj, char *p, int p_max_size)
|
|
|
|
{
|
|
|
|
char *buf = NULL;
|
|
|
|
char *buf2;
|
2009-11-14 14:08:41 +00:00
|
|
|
int bytes_read, total_read;
|
2009-11-12 14:42:18 +00:00
|
|
|
int i = 0;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
2009-11-12 14:42:18 +00:00
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/environ", objbuf);
|
2009-11-29 14:47:56 +00:00
|
|
|
|
|
|
|
buf = readfile(pathbuf, &total_read, 1);
|
2009-11-14 14:08:41 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
for(bytes_read = 0; bytes_read < total_read; buf[i-1] = ';') {
|
2009-11-12 14:42:18 +00:00
|
|
|
buf2 = strdup(buf+bytes_read);
|
|
|
|
bytes_read += strlen(buf2)+1;
|
|
|
|
sscanf(buf2, "%[^=]", buf+i);
|
|
|
|
free(buf2);
|
|
|
|
i = strlen(buf) + 1;
|
|
|
|
}
|
|
|
|
buf[i-1] = 0;
|
2009-11-12 20:48:15 +00:00
|
|
|
snprintf(p, p_max_size, "%s", buf);
|
2009-11-12 14:42:18 +00:00
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
2009-11-12 19:34:43 +00:00
|
|
|
|
2009-11-14 21:07:54 +00:00
|
|
|
void print_pid_exe(struct text_object *obj, char *p, int p_max_size) {
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
2009-11-14 21:07:54 +00:00
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/exe", objbuf);
|
2009-11-29 14:47:56 +00:00
|
|
|
pid_readlink(pathbuf, p, p_max_size);
|
2009-11-12 19:34:43 +00:00
|
|
|
}
|
|
|
|
|
2009-11-16 14:01:43 +00:00
|
|
|
void print_pid_nice(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
char *buf = NULL;
|
|
|
|
int bytes_read;
|
|
|
|
long int nice_value;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
2009-11-29 14:47:56 +00:00
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-16 14:01:43 +00:00
|
|
|
|
2009-11-18 16:13:20 +00:00
|
|
|
if(*(obj->data.s) != 0) {
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf);
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-18 16:13:20 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*u %*u %*d %*d %*d %ld", &nice_value);
|
|
|
|
snprintf(p, p_max_size, "%ld", nice_value);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NORM_ERR("$pid_nice didn't receive a argument");
|
2009-11-16 14:01:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-14 21:07:54 +00:00
|
|
|
void print_pid_openfiles(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
DIR* dir;
|
|
|
|
struct dirent *entry;
|
2009-11-12 19:34:43 +00:00
|
|
|
char buf[p_max_size];
|
2009-11-14 21:07:54 +00:00
|
|
|
int length, totallength = 0;
|
|
|
|
struct ll_string* files_front = NULL;
|
|
|
|
struct ll_string* files_back = NULL;
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-12 19:34:43 +00:00
|
|
|
|
2009-11-29 15:27:12 +00:00
|
|
|
dir = opendir(objbuf);
|
2009-11-14 21:07:54 +00:00
|
|
|
if(dir != NULL) {
|
|
|
|
while ((entry = readdir(dir))) {
|
|
|
|
if(entry->d_name[0] != '.') {
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(buf, p_max_size, "%s/%s", objbuf, entry->d_name);
|
2009-11-14 21:07:54 +00:00
|
|
|
length = readlink(buf, buf, p_max_size);
|
|
|
|
buf[length] = 0;
|
|
|
|
if(inlist(files_front, buf) == 0) {
|
|
|
|
files_back = addnode(files_back, buf);
|
|
|
|
snprintf(p + totallength, p_max_size - totallength, "%s; " , buf);
|
|
|
|
totallength += length + strlen("; ");
|
|
|
|
}
|
|
|
|
if(files_front == NULL) {
|
|
|
|
files_front = files_back;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
freelist(files_front);
|
|
|
|
p[totallength - strlen("; ")] = 0;
|
2009-11-12 19:34:43 +00:00
|
|
|
} else {
|
2009-11-14 21:07:54 +00:00
|
|
|
p[0] = 0;
|
2009-11-12 19:34:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-15 12:26:40 +00:00
|
|
|
void print_pid_parent(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
#define PARENT_ENTRY "PPid:\t"
|
|
|
|
#define PARENTNOTFOUND "Can't find the process parent in '%s'"
|
|
|
|
char *begin, *end, *buf = NULL;
|
|
|
|
int bytes_read;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
2009-11-29 14:47:56 +00:00
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf);
|
2009-11-15 12:26:40 +00:00
|
|
|
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-15 12:26:40 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
begin = strstr(buf, PARENT_ENTRY);
|
|
|
|
if(begin != NULL) {
|
|
|
|
begin += strlen(PARENT_ENTRY);
|
|
|
|
end = strchr(begin, '\n');
|
|
|
|
if(end != NULL) {
|
|
|
|
*(end) = 0;
|
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s", begin);
|
|
|
|
} else {
|
2009-11-29 14:47:56 +00:00
|
|
|
NORM_ERR(PARENTNOTFOUND, pathbuf);
|
2009-11-15 12:26:40 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-16 14:01:43 +00:00
|
|
|
void print_pid_priority(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
char *buf = NULL;
|
|
|
|
int bytes_read;
|
|
|
|
long int priority;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
2009-11-29 14:47:56 +00:00
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-16 14:01:43 +00:00
|
|
|
|
2009-11-29 15:27:12 +00:00
|
|
|
if(*(objbuf) != 0) {
|
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf);
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-18 16:13:20 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*u %*u %*d %*d %ld", &priority);
|
|
|
|
snprintf(p, p_max_size, "%ld", priority);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NORM_ERR("$pid_priority didn't receive a argument");
|
2009-11-16 14:01:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-14 12:58:07 +00:00
|
|
|
void print_pid_state(struct text_object *obj, char *p, int p_max_size) {
|
2009-11-15 12:26:40 +00:00
|
|
|
#define STATE_ENTRY "State:\t"
|
|
|
|
#define STATENOTFOUND "Can't find the process state in '%s'"
|
2009-11-14 12:58:07 +00:00
|
|
|
char *begin, *end, *buf = NULL;
|
2009-11-14 14:08:41 +00:00
|
|
|
int bytes_read;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
2009-11-29 14:47:56 +00:00
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf);
|
2009-11-14 12:58:07 +00:00
|
|
|
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-14 14:08:41 +00:00
|
|
|
if(buf != NULL) {
|
2009-11-14 12:58:07 +00:00
|
|
|
begin = strstr(buf, STATE_ENTRY);
|
|
|
|
if(begin != NULL) {
|
|
|
|
begin += strlen(STATE_ENTRY) + 3; // +3 will strip the char representing the short state and the space and '(' that follow
|
|
|
|
end = strchr(begin, '\n');
|
|
|
|
if(end != NULL) {
|
2009-11-15 12:26:40 +00:00
|
|
|
*(end-1) = 0; // -1 strips the ')'
|
2009-11-14 12:58:07 +00:00
|
|
|
}
|
2009-11-14 14:08:41 +00:00
|
|
|
snprintf(p, p_max_size, "%s", begin);
|
2009-11-14 12:58:07 +00:00
|
|
|
} else {
|
2009-11-29 14:47:56 +00:00
|
|
|
NORM_ERR(STATENOTFOUND, pathbuf);
|
2009-11-14 12:58:07 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-14 21:07:54 +00:00
|
|
|
void print_pid_state_short(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
char *begin, *buf = NULL;
|
|
|
|
int bytes_read;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-14 21:07:54 +00:00
|
|
|
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf);
|
2009-11-29 14:47:56 +00:00
|
|
|
|
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-14 21:07:54 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
begin = strstr(buf, STATE_ENTRY);
|
|
|
|
if(begin != NULL) {
|
|
|
|
snprintf(p, p_max_size, "%c", *begin);
|
|
|
|
} else {
|
2009-11-29 14:47:56 +00:00
|
|
|
NORM_ERR(STATENOTFOUND, pathbuf);
|
2009-11-14 21:07:54 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
2009-11-12 19:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_stderr(struct text_object *obj, char *p, int p_max_size) {
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
2009-11-12 19:34:43 +00:00
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
|
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/fd/2", objbuf);
|
2009-11-29 14:47:56 +00:00
|
|
|
pid_readlink(pathbuf, p, p_max_size);
|
2009-11-12 19:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_stdin(struct text_object *obj, char *p, int p_max_size) {
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-12 19:34:43 +00:00
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
|
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/fd/0", objbuf);
|
2009-11-29 14:47:56 +00:00
|
|
|
pid_readlink(pathbuf, p, p_max_size);
|
2009-11-12 19:34:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_stdout(struct text_object *obj, char *p, int p_max_size) {
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
2009-11-12 23:36:46 +00:00
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
|
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/fd/1", objbuf);
|
2009-11-29 14:47:56 +00:00
|
|
|
pid_readlink(pathbuf, p, p_max_size);
|
2009-11-12 23:36:46 +00:00
|
|
|
}
|
|
|
|
|
2009-11-14 21:07:54 +00:00
|
|
|
void scan_cmdline_to_pid_arg(struct text_object *obj, const char *arg, void* free_at_crash) {
|
|
|
|
unsigned int i;
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
|
|
|
|
|
|
|
/* FIXME */
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-12 23:36:46 +00:00
|
|
|
|
2009-11-14 21:07:54 +00:00
|
|
|
if(strlen(arg) > 0) {
|
|
|
|
obj->data.s = strdup(arg);
|
|
|
|
for(i = 0; obj->data.s[i] != 0; i++) {
|
|
|
|
while(obj->data.s[i] == ' ' && obj->data.s[i + 1] == ' ') {
|
|
|
|
memmove(obj->data.s + i, obj->data.s + i + 1, strlen(obj->data.s + i + 1) + 1);
|
|
|
|
}
|
2009-11-12 23:36:46 +00:00
|
|
|
}
|
2009-11-14 21:07:54 +00:00
|
|
|
if(obj->data.s[i - 1] == ' ') {
|
|
|
|
obj->data.s[i - 1] = 0;
|
2009-11-12 23:36:46 +00:00
|
|
|
}
|
2009-11-14 21:07:54 +00:00
|
|
|
} else {
|
|
|
|
CRIT_ERR(obj, free_at_crash, "${cmdline_to_pid commandline}");
|
2009-11-12 23:36:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-14 21:07:54 +00:00
|
|
|
void print_cmdline_to_pid(struct text_object *obj, char *p, int p_max_size) {
|
2009-11-12 23:36:46 +00:00
|
|
|
DIR* dir;
|
|
|
|
struct dirent *entry;
|
2009-11-29 14:47:56 +00:00
|
|
|
char *buf;
|
2009-11-14 21:07:54 +00:00
|
|
|
int bytes_read, i;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-12 23:36:46 +00:00
|
|
|
|
2009-11-14 21:07:54 +00:00
|
|
|
dir = opendir(PROCDIR);
|
2009-11-13 15:29:44 +00:00
|
|
|
if(dir != NULL) {
|
|
|
|
while ((entry = readdir(dir))) {
|
2009-11-29 14:47:56 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/cmdline", entry->d_name);
|
|
|
|
|
|
|
|
buf = readfile(pathbuf, &bytes_read, 0);
|
2009-11-14 21:07:54 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
for(i = 0; i < bytes_read - 1; i++) {
|
|
|
|
if(buf[i] == 0) buf[i] = ' ';
|
2009-11-13 15:29:44 +00:00
|
|
|
}
|
2009-11-14 23:51:38 +00:00
|
|
|
if(strstr(buf, obj->data.s) != NULL) {
|
2009-11-14 21:07:54 +00:00
|
|
|
snprintf(p, p_max_size, "%s", entry->d_name);
|
|
|
|
free(buf);
|
|
|
|
closedir(dir);
|
|
|
|
return;
|
2009-11-13 15:29:44 +00:00
|
|
|
}
|
2009-11-14 21:07:54 +00:00
|
|
|
free(buf);
|
2009-11-12 23:36:46 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-13 15:29:44 +00:00
|
|
|
closedir(dir);
|
|
|
|
} else {
|
2009-11-14 21:07:54 +00:00
|
|
|
NORM_ERR(READERR, PROCDIR);
|
2009-11-12 23:36:46 +00:00
|
|
|
}
|
|
|
|
}
|
2009-11-15 13:49:55 +00:00
|
|
|
|
2009-11-16 08:54:17 +00:00
|
|
|
void print_pid_threads(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
#define THREADS_ENTRY "Threads:\t"
|
|
|
|
#define THREADSNOTFOUND "Can't find the number of the threads of the process in '%s'"
|
|
|
|
char *begin, *end, *buf = NULL;
|
|
|
|
int bytes_read;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
2009-11-29 14:47:56 +00:00
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf);
|
2009-11-16 08:54:17 +00:00
|
|
|
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-16 08:54:17 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
begin = strstr(buf, THREADS_ENTRY);
|
|
|
|
if(begin != NULL) {
|
|
|
|
begin += strlen(THREADS_ENTRY);
|
|
|
|
end = strchr(begin, '\n');
|
|
|
|
if(end != NULL) {
|
|
|
|
*(end) = 0;
|
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s", begin);
|
|
|
|
} else {
|
2009-11-29 14:47:56 +00:00
|
|
|
NORM_ERR(THREADSNOTFOUND, pathbuf);
|
2009-11-16 08:54:17 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_thread_list(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
DIR* dir;
|
|
|
|
struct dirent *entry;
|
|
|
|
int totallength = 0;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
2009-11-16 08:54:17 +00:00
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/task", objbuf);
|
2009-11-29 14:47:56 +00:00
|
|
|
|
|
|
|
dir = opendir(pathbuf);
|
2009-11-16 08:54:17 +00:00
|
|
|
if(dir != NULL) {
|
|
|
|
while ((entry = readdir(dir))) {
|
|
|
|
if(entry->d_name[0] != '.') {
|
|
|
|
snprintf(p + totallength, p_max_size - totallength, "%s," , entry->d_name);
|
|
|
|
totallength += strlen(entry->d_name)+1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
if(p[totallength - 1] == ',') p[totallength - 1] = 0;
|
|
|
|
} else {
|
|
|
|
p[0] = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-16 14:30:57 +00:00
|
|
|
void print_pid_time_kernelmode(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
char *buf = NULL;
|
|
|
|
int bytes_read;
|
|
|
|
unsigned long int umtime;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
2009-11-16 14:30:57 +00:00
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
|
|
|
|
if(*(objbuf) != 0) {
|
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf);
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-18 16:13:20 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu", &umtime);
|
|
|
|
snprintf(p, p_max_size, "%.2f", (float) umtime / 100);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NORM_ERR("$pid_time_kernelmode didn't receive a argument");
|
2009-11-16 14:30:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_time_usermode(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
char *buf = NULL;
|
|
|
|
int bytes_read;
|
|
|
|
unsigned long int kmtime;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
2009-11-16 14:30:57 +00:00
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
|
|
|
|
if(*(objbuf) != 0) {
|
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf);
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-18 16:13:20 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*u %lu", &kmtime);
|
|
|
|
snprintf(p, p_max_size, "%.2f", (float) kmtime / 100);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NORM_ERR("$pid_time_usermode didn't receive a argument");
|
2009-11-16 14:30:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_time(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
char *buf = NULL;
|
|
|
|
int bytes_read;
|
|
|
|
unsigned long int umtime, kmtime;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
2009-11-16 14:30:57 +00:00
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
|
|
|
|
if(*(objbuf) != 0) {
|
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf);
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-18 16:13:20 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu %lu", &umtime, &kmtime);
|
|
|
|
snprintf(p, p_max_size, "%.2f", (float) (umtime + kmtime) / 100);
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
NORM_ERR("$pid_time didn't receive a argument");
|
2009-11-16 14:30:57 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-11-15 13:49:55 +00:00
|
|
|
#define UID_ENTRY "Uid:\t"
|
|
|
|
void print_pid_uid(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
#define UIDNOTFOUND "Can't find the process real uid in '%s'"
|
|
|
|
char *begin, *end, *buf = NULL;
|
|
|
|
int bytes_read;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf);
|
2009-11-15 13:49:55 +00:00
|
|
|
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-15 13:49:55 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
begin = strstr(buf, UID_ENTRY);
|
|
|
|
if(begin != NULL) {
|
|
|
|
begin += strlen(UID_ENTRY);
|
|
|
|
end = strchr(begin, '\t');
|
|
|
|
if(end != NULL) {
|
|
|
|
*(end) = 0;
|
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s", begin);
|
|
|
|
} else {
|
2009-11-29 14:47:56 +00:00
|
|
|
NORM_ERR(UIDNOTFOUND, pathbuf);
|
2009-11-15 13:49:55 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_euid(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
#define EUIDNOTFOUND "Can't find the process effective uid in '%s'"
|
|
|
|
char *begin, *end, *buf = NULL;
|
|
|
|
int bytes_read;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf);
|
2009-11-15 13:49:55 +00:00
|
|
|
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-15 13:49:55 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
begin = strstr(buf, UID_ENTRY);
|
|
|
|
if(begin != NULL) {
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
end = strchr(begin, '\t');
|
|
|
|
if(end != NULL) {
|
|
|
|
*(end) = 0;
|
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s", begin);
|
|
|
|
} else {
|
2009-11-29 14:47:56 +00:00
|
|
|
NORM_ERR(EUIDNOTFOUND, pathbuf);
|
2009-11-15 13:49:55 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_suid(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
#define SUIDNOTFOUND "Can't find the process saved set uid in '%s'"
|
|
|
|
char *begin, *end, *buf = NULL;
|
|
|
|
int bytes_read;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf);
|
2009-11-15 13:49:55 +00:00
|
|
|
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-15 13:49:55 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
begin = strstr(buf, UID_ENTRY);
|
|
|
|
if(begin != NULL) {
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
end = strchr(begin, '\t');
|
|
|
|
if(end != NULL) {
|
|
|
|
*(end) = 0;
|
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s", begin);
|
|
|
|
} else {
|
2009-11-29 14:47:56 +00:00
|
|
|
NORM_ERR(SUIDNOTFOUND, pathbuf);
|
2009-11-15 13:49:55 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_fsuid(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
#define FSUIDNOTFOUND "Can't find the process file system uid in '%s'"
|
|
|
|
char *begin, *end, *buf = NULL;
|
|
|
|
int bytes_read;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf);
|
2009-11-15 13:49:55 +00:00
|
|
|
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-15 13:49:55 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
begin = strstr(buf, UID_ENTRY);
|
|
|
|
if(begin != NULL) {
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
end = strchr(begin, '\n');
|
|
|
|
if(end != NULL) {
|
|
|
|
*(end) = 0;
|
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s", begin);
|
|
|
|
} else {
|
2009-11-29 14:47:56 +00:00
|
|
|
NORM_ERR(FSUIDNOTFOUND, pathbuf);
|
2009-11-15 13:49:55 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define GID_ENTRY "Gid:\t"
|
|
|
|
void print_pid_gid(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
#define GIDNOTFOUND "Can't find the process real gid in '%s'"
|
|
|
|
char *begin, *end, *buf = NULL;
|
|
|
|
int bytes_read;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf);
|
2009-11-15 13:49:55 +00:00
|
|
|
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-15 13:49:55 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
begin = strstr(buf, GID_ENTRY);
|
|
|
|
if(begin != NULL) {
|
|
|
|
begin += strlen(GID_ENTRY);
|
|
|
|
end = strchr(begin, '\t');
|
|
|
|
if(end != NULL) {
|
|
|
|
*(end) = 0;
|
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s", begin);
|
|
|
|
} else {
|
2009-11-29 14:47:56 +00:00
|
|
|
NORM_ERR(GIDNOTFOUND, pathbuf);
|
2009-11-15 13:49:55 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_egid(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
#define EGIDNOTFOUND "Can't find the process effective gid in '%s'"
|
|
|
|
char *begin, *end, *buf = NULL;
|
|
|
|
int bytes_read;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf);
|
2009-11-15 13:49:55 +00:00
|
|
|
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-15 13:49:55 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
begin = strstr(buf, GID_ENTRY);
|
|
|
|
if(begin != NULL) {
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
end = strchr(begin, '\t');
|
|
|
|
if(end != NULL) {
|
|
|
|
*(end) = 0;
|
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s", begin);
|
|
|
|
} else {
|
2009-11-29 14:47:56 +00:00
|
|
|
NORM_ERR(EGIDNOTFOUND, pathbuf);
|
2009-11-15 13:49:55 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_sgid(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
#define SGIDNOTFOUND "Can't find the process saved set gid in '%s'"
|
|
|
|
char *begin, *end, *buf = NULL;
|
|
|
|
int bytes_read;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf);
|
2009-11-15 13:49:55 +00:00
|
|
|
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-15 13:49:55 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
begin = strstr(buf, GID_ENTRY);
|
|
|
|
if(begin != NULL) {
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
end = strchr(begin, '\t');
|
|
|
|
if(end != NULL) {
|
|
|
|
*(end) = 0;
|
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s", begin);
|
|
|
|
} else {
|
2009-11-29 14:47:56 +00:00
|
|
|
NORM_ERR(SGIDNOTFOUND, pathbuf);
|
2009-11-15 13:49:55 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_fsgid(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
#define FSGIDNOTFOUND "Can't find the process file system gid in '%s'"
|
|
|
|
char *begin, *end, *buf = NULL;
|
|
|
|
int bytes_read;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf);
|
2009-11-15 13:49:55 +00:00
|
|
|
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-15 13:49:55 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
begin = strstr(buf, GID_ENTRY);
|
|
|
|
if(begin != NULL) {
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
begin = strchr(begin, '\t'); begin++;
|
|
|
|
end = strchr(begin, '\n');
|
|
|
|
if(end != NULL) {
|
|
|
|
*(end) = 0;
|
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s", begin);
|
|
|
|
} else {
|
2009-11-29 14:47:56 +00:00
|
|
|
NORM_ERR(FSGIDNOTFOUND, pathbuf);
|
2009-11-15 13:49:55 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
2009-11-15 18:44:37 +00:00
|
|
|
|
2009-11-29 15:27:12 +00:00
|
|
|
void internal_print_pid_vm(struct text_object *obj, char *p, int p_max_size, const char* entry, const char* errorstring) {
|
2009-11-15 18:44:37 +00:00
|
|
|
char *begin, *end, *buf = NULL;
|
|
|
|
int bytes_read;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf);
|
2009-11-15 18:44:37 +00:00
|
|
|
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-15 18:44:37 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
begin = strstr(buf, entry);
|
|
|
|
if(begin != NULL) {
|
|
|
|
begin += strlen(entry);
|
|
|
|
while(*begin == '\t' || *begin == ' ') {
|
|
|
|
begin++;
|
|
|
|
}
|
|
|
|
end = strchr(begin, '\n');
|
|
|
|
if(end != NULL) {
|
|
|
|
*(end) = 0;
|
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s", begin);
|
|
|
|
} else {
|
2009-11-29 14:47:56 +00:00
|
|
|
NORM_ERR(errorstring, pathbuf);
|
2009-11-15 18:44:37 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_vmpeak(struct text_object *obj, char *p, int p_max_size) {
|
2009-11-29 15:27:12 +00:00
|
|
|
internal_print_pid_vm(obj, p, p_max_size, "VmPeak:\t", "Can't find the process peak virtual memory size in '%s'");
|
2009-11-15 18:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_vmsize(struct text_object *obj, char *p, int p_max_size) {
|
2009-11-29 15:27:12 +00:00
|
|
|
internal_print_pid_vm(obj, p, p_max_size, "VmSize:\t", "Can't find the process virtual memory size in '%s'");
|
2009-11-15 18:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_vmlck(struct text_object *obj, char *p, int p_max_size) {
|
2009-11-29 15:27:12 +00:00
|
|
|
internal_print_pid_vm(obj, p, p_max_size, "VmLck:\t", "Can't find the process locked memory size in '%s'");
|
2009-11-15 18:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_vmhwm(struct text_object *obj, char *p, int p_max_size) {
|
2009-11-29 15:27:12 +00:00
|
|
|
internal_print_pid_vm(obj, p, p_max_size, "VmHWM:\t", "Can't find the process peak resident set size in '%s'");
|
2009-11-15 18:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_vmrss(struct text_object *obj, char *p, int p_max_size) {
|
2009-11-29 15:27:12 +00:00
|
|
|
internal_print_pid_vm(obj, p, p_max_size, "VmHWM:\t", "Can't find the process resident set size in '%s'");
|
2009-11-15 18:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_vmdata(struct text_object *obj, char *p, int p_max_size) {
|
2009-11-29 15:27:12 +00:00
|
|
|
internal_print_pid_vm(obj, p, p_max_size, "VmData:\t", "Can't find the process data segment size in '%s'");
|
2009-11-15 18:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_vmstk(struct text_object *obj, char *p, int p_max_size) {
|
2009-11-29 15:27:12 +00:00
|
|
|
internal_print_pid_vm(obj, p, p_max_size, "VmData:\t", "Can't find the process stack segment size in '%s'");
|
2009-11-15 18:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_vmexe(struct text_object *obj, char *p, int p_max_size) {
|
2009-11-29 15:27:12 +00:00
|
|
|
internal_print_pid_vm(obj, p, p_max_size, "VmData:\t", "Can't find the process text segment size in '%s'");
|
2009-11-15 18:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_vmlib(struct text_object *obj, char *p, int p_max_size) {
|
2009-11-29 15:27:12 +00:00
|
|
|
internal_print_pid_vm(obj, p, p_max_size, "VmLib:\t", "Can't find the process shared library code size in '%s'");
|
2009-11-15 18:44:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void print_pid_vmpte(struct text_object *obj, char *p, int p_max_size) {
|
2009-11-29 15:27:12 +00:00
|
|
|
internal_print_pid_vm(obj, p, p_max_size, "VmPTE:\t", "Can't find the process page table entries size in '%s'");
|
2009-11-15 18:44:37 +00:00
|
|
|
}
|
2009-11-19 11:32:14 +00:00
|
|
|
|
|
|
|
#define READ_ENTRY "read_bytes: "
|
|
|
|
#define READNOTFOUND "Can't find the amount of bytes read in '%s'"
|
|
|
|
void print_pid_read(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
char *begin, *end, *buf = NULL;
|
|
|
|
int bytes_read;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/io", objbuf);
|
2009-11-19 11:32:14 +00:00
|
|
|
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-19 11:32:14 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
begin = strstr(buf, READ_ENTRY);
|
|
|
|
if(begin != NULL) {
|
|
|
|
end = strchr(begin, '\n');
|
|
|
|
if(end != NULL) {
|
|
|
|
*(end) = 0;
|
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s", begin);
|
|
|
|
} else {
|
2009-11-29 14:47:56 +00:00
|
|
|
NORM_ERR(READNOTFOUND, pathbuf);
|
2009-11-19 11:32:14 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#define WRITE_ENTRY "write_bytes: "
|
|
|
|
#define WRITENOTFOUND "Can't find the amount of bytes written in '%s'"
|
|
|
|
void print_pid_write(struct text_object *obj, char *p, int p_max_size) {
|
|
|
|
char *begin, *end, *buf = NULL;
|
|
|
|
int bytes_read;
|
2009-11-29 14:47:56 +00:00
|
|
|
char pathbuf[64];
|
2009-11-29 15:27:12 +00:00
|
|
|
char objbuf[max_user_text];
|
|
|
|
|
2009-11-29 19:43:46 +00:00
|
|
|
generate_text_internal(objbuf, max_user_text, *obj->sub);
|
2009-11-29 15:27:12 +00:00
|
|
|
snprintf(pathbuf, 64, PROCDIR "/%s/io", objbuf);
|
2009-11-19 11:32:14 +00:00
|
|
|
|
2009-11-29 14:47:56 +00:00
|
|
|
buf = readfile(pathbuf, &bytes_read, 1);
|
2009-11-19 11:32:14 +00:00
|
|
|
if(buf != NULL) {
|
|
|
|
begin = strstr(buf, WRITE_ENTRY);
|
|
|
|
if(begin != NULL) {
|
|
|
|
end = strchr(begin, '\n');
|
|
|
|
if(end != NULL) {
|
|
|
|
*(end) = 0;
|
|
|
|
}
|
|
|
|
snprintf(p, p_max_size, "%s", begin);
|
|
|
|
} else {
|
2009-11-29 14:47:56 +00:00
|
|
|
NORM_ERR(WRITENOTFOUND, pathbuf);
|
2009-11-19 11:32:14 +00:00
|
|
|
}
|
|
|
|
free(buf);
|
|
|
|
}
|
|
|
|
}
|