1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-11-18 02:55:12 +00:00

Merge branch 'master' of ssh://git.omp.am/home/omp/git/conky

This commit is contained in:
Nikolas Garofil 2010-02-09 16:49:31 +01:00
commit 332cf86b7b
6 changed files with 136 additions and 133 deletions

View File

@ -245,16 +245,16 @@ int compare(const char *expr)
int check_if_match(struct text_object *obj) int check_if_match(struct text_object *obj)
{ {
char expression[max_user_text]; std::unique_ptr<char []> expression(new char[max_user_text]);
int val; int val;
int result = 1; int result = 1;
generate_text_internal(expression, max_user_text, *obj->sub); generate_text_internal(expression.get(), max_user_text, *obj->sub);
DBGP("parsed arg into '%s'", expression); DBGP("parsed arg into '%s'", expression.get());
val = compare(expression); val = compare(expression.get());
if (val == -2) { if (val == -2) {
NORM_ERR("compare failed for expression '%s'", expression); NORM_ERR("compare failed for expression '%s'", expression.get());
} else if (!val) { } else if (!val) {
result = 0; result = 0;
} }

View File

@ -64,7 +64,8 @@ static void mbox_scan(char *args, char *output, size_t max_len)
{ {
int i, u, flag; int i, u, flag;
int force_rescan = 0; int force_rescan = 0;
char buf[text_buffer_size]; std::unique_ptr<char []> buf_(new char[text_buffer_size]);
char *buf = buf_.get();
struct stat statbuf; struct stat statbuf;
struct ring_list *curr = 0, *prev = 0, *startlist = 0; struct ring_list *curr = 0, *prev = 0, *startlist = 0;
FILE *fp; FILE *fp;
@ -183,8 +184,8 @@ static void mbox_scan(char *args, char *output, size_t max_len)
* mbox */ * mbox */
for (i = 0; i < print_num_mails; i++) { for (i = 0; i < print_num_mails; i++) {
curr = (struct ring_list *) malloc(sizeof(struct ring_list)); curr = (struct ring_list *) malloc(sizeof(struct ring_list));
curr->from = (char *) malloc(sizeof(char[from_width + 1])); curr->from = (char *) malloc(from_width + 1);
curr->subject = (char *) malloc(sizeof(char[subject_width + 1])); curr->subject = (char *) malloc(subject_width + 1);
curr->from[0] = '\0'; curr->from[0] = '\0';
curr->subject[0] = '\0'; curr->subject[0] = '\0';

View File

@ -59,11 +59,11 @@ char* readfile(char* filename, int* total_read, char showerror) {
void pid_readlink(char *file, char *p, int p_max_size) void pid_readlink(char *file, char *p, int p_max_size)
{ {
char buf[p_max_size]; std::unique_ptr<char []> buf(new char[p_max_size]);
memset(buf, 0, p_max_size); memset(buf.get(), 0, p_max_size);
if(readlink(file, buf, p_max_size) >= 0) { if(readlink(file, buf.get(), p_max_size) >= 0) {
snprintf(p, p_max_size, "%s", buf); snprintf(p, p_max_size, "%s", buf.get());
} else { } else {
NORM_ERR(READERR, file); NORM_ERR(READERR, file);
} }
@ -105,10 +105,10 @@ int inlist(struct ll_string* front, char* string) {
void print_pid_chroot(struct text_object *obj, char *p, int p_max_size) { void print_pid_chroot(struct text_object *obj, char *p, int p_max_size) {
char pathbuf[64]; char pathbuf[64];
char buf[max_user_text]; std::unique_ptr<char []> buf(new char[max_user_text]);
generate_text_internal(buf, max_user_text, *obj->sub); generate_text_internal(buf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/root", buf); snprintf(pathbuf, 64, PROCDIR "/%s/root", buf.get());
pid_readlink(pathbuf, p, p_max_size); pid_readlink(pathbuf, p, p_max_size);
} }
@ -117,12 +117,12 @@ void print_pid_cmdline(struct text_object *obj, char *p, int p_max_size)
char* buf; char* buf;
int i, bytes_read; int i, bytes_read;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
if(*(objbuf) != 0) { if(*(objbuf.get()) != 0) {
snprintf(pathbuf, 64, PROCDIR "/%s/cmdline", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/cmdline", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
for(i = 0; i < bytes_read-1; i++) { for(i = 0; i < bytes_read-1; i++) {
@ -140,17 +140,17 @@ void print_pid_cmdline(struct text_object *obj, char *p, int p_max_size)
void print_pid_cwd(struct text_object *obj, char *p, int p_max_size) void print_pid_cwd(struct text_object *obj, char *p, int p_max_size)
{ {
char buf[p_max_size]; std::unique_ptr<char []> buf(new char[p_max_size]);
int bytes_read; int bytes_read;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/cwd", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/cwd", objbuf.get());
bytes_read = readlink(pathbuf, buf, p_max_size); bytes_read = readlink(pathbuf, buf.get(), p_max_size);
if(bytes_read != -1) { if(bytes_read != -1) {
buf[bytes_read] = 0; buf[bytes_read] = 0;
snprintf(p, p_max_size, "%s", buf); snprintf(p, p_max_size, "%s", buf.get());
} else { } else {
NORM_ERR(READERR, pathbuf); NORM_ERR(READERR, pathbuf);
} }
@ -161,11 +161,11 @@ void print_pid_environ(struct text_object *obj, char *p, int p_max_size)
int i, total_read; int i, total_read;
pid_t pid; pid_t pid;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
char *buf, *var=strdup(obj->data.s);; char *buf, *var=strdup(obj->data.s);;
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
if(sscanf(objbuf, "%d %s", &pid, var) == 2) { if(sscanf(objbuf.get(), "%d %s", &pid, var) == 2) {
for(i = 0; var[i] != 0; i++) { for(i = 0; var[i] != 0; i++) {
var[i] = toupper(var[i]); var[i] = toupper(var[i]);
} }
@ -194,10 +194,10 @@ void print_pid_environ_list(struct text_object *obj, char *p, int p_max_size)
int bytes_read, total_read; int bytes_read, total_read;
int i = 0; int i = 0;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/environ", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/environ", objbuf.get());
buf = readfile(pathbuf, &total_read, 1); buf = readfile(pathbuf, &total_read, 1);
if(buf != NULL) { if(buf != NULL) {
@ -216,10 +216,10 @@ void print_pid_environ_list(struct text_object *obj, char *p, int p_max_size)
void print_pid_exe(struct text_object *obj, char *p, int p_max_size) { void print_pid_exe(struct text_object *obj, char *p, int p_max_size) {
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/exe", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/exe", objbuf.get());
pid_readlink(pathbuf, p, p_max_size); pid_readlink(pathbuf, p, p_max_size);
} }
@ -228,12 +228,12 @@ void print_pid_nice(struct text_object *obj, char *p, int p_max_size) {
int bytes_read; int bytes_read;
long int nice_value; long int nice_value;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
if(*(obj->data.s) != 0) { if(*(obj->data.s) != 0) {
snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { 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); sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*u %*u %*d %*d %*d %ld", &nice_value);
@ -248,24 +248,24 @@ void print_pid_nice(struct text_object *obj, char *p, int p_max_size) {
void print_pid_openfiles(struct text_object *obj, char *p, int p_max_size) { void print_pid_openfiles(struct text_object *obj, char *p, int p_max_size) {
DIR* dir; DIR* dir;
struct dirent *entry; struct dirent *entry;
char buf[p_max_size]; std::unique_ptr<char []> buf(new char[p_max_size]);
int length, totallength = 0; int length, totallength = 0;
struct ll_string* files_front = NULL; struct ll_string* files_front = NULL;
struct ll_string* files_back = NULL; struct ll_string* files_back = NULL;
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
dir = opendir(objbuf); dir = opendir(objbuf.get());
if(dir != NULL) { if(dir != NULL) {
while ((entry = readdir(dir))) { while ((entry = readdir(dir))) {
if(entry->d_name[0] != '.') { if(entry->d_name[0] != '.') {
snprintf(buf, p_max_size, "%s/%s", objbuf, entry->d_name); snprintf(buf.get(), p_max_size, "%s/%s", objbuf.get(), entry->d_name);
length = readlink(buf, buf, p_max_size); length = readlink(buf.get(), buf.get(), p_max_size);
buf[length] = 0; buf[length] = 0;
if(inlist(files_front, buf) == 0) { if(inlist(files_front, buf.get()) == 0) {
files_back = addnode(files_back, buf); files_back = addnode(files_back, buf.get());
snprintf(p + totallength, p_max_size - totallength, "%s; " , buf); snprintf(p + totallength, p_max_size - totallength, "%s; " , buf.get());
totallength += length + strlen("; "); totallength += length + strlen("; ");
} }
if(files_front == NULL) { if(files_front == NULL) {
@ -287,10 +287,10 @@ void print_pid_parent(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL; char *begin, *end, *buf = NULL;
int bytes_read; int bytes_read;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
@ -314,12 +314,12 @@ void print_pid_priority(struct text_object *obj, char *p, int p_max_size) {
int bytes_read; int bytes_read;
long int priority; long int priority;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
if(*(objbuf) != 0) { if(*(objbuf.get()) != 0) {
snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*u %*u %*d %*d %ld", &priority); sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*u %*u %*d %*d %ld", &priority);
@ -337,10 +337,10 @@ void print_pid_state(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL; char *begin, *end, *buf = NULL;
int bytes_read; int bytes_read;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
@ -363,11 +363,11 @@ void print_pid_state_short(struct text_object *obj, char *p, int p_max_size) {
char *begin, *buf = NULL; char *begin, *buf = NULL;
int bytes_read; int bytes_read;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
@ -383,40 +383,40 @@ void print_pid_state_short(struct text_object *obj, char *p, int p_max_size) {
void print_pid_stderr(struct text_object *obj, char *p, int p_max_size) { void print_pid_stderr(struct text_object *obj, char *p, int p_max_size) {
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/fd/2", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/fd/2", objbuf.get());
pid_readlink(pathbuf, p, p_max_size); pid_readlink(pathbuf, p, p_max_size);
} }
void print_pid_stdin(struct text_object *obj, char *p, int p_max_size) { void print_pid_stdin(struct text_object *obj, char *p, int p_max_size) {
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
char pathbuf[64]; char pathbuf[64];
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/fd/0", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/fd/0", objbuf.get());
pid_readlink(pathbuf, p, p_max_size); pid_readlink(pathbuf, p, p_max_size);
} }
void print_pid_stdout(struct text_object *obj, char *p, int p_max_size) { void print_pid_stdout(struct text_object *obj, char *p, int p_max_size) {
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/fd/1", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/fd/1", objbuf.get());
pid_readlink(pathbuf, p, p_max_size); pid_readlink(pathbuf, p, p_max_size);
} }
void scan_cmdline_to_pid_arg(struct text_object *obj, const char *arg, void* free_at_crash) { void scan_cmdline_to_pid_arg(struct text_object *obj, const char *arg, void* free_at_crash) {
unsigned int i; unsigned int i;
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
/* FIXME */ /* FIXME */
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
if(strlen(arg) > 0) { if(strlen(arg) > 0) {
obj->data.s = strdup(arg); obj->data.s = strdup(arg);
@ -471,10 +471,10 @@ void print_pid_threads(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL; char *begin, *end, *buf = NULL;
int bytes_read; int bytes_read;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
@ -498,10 +498,10 @@ void print_pid_thread_list(struct text_object *obj, char *p, int p_max_size) {
struct dirent *entry; struct dirent *entry;
int totallength = 0; int totallength = 0;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/task", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/task", objbuf.get());
dir = opendir(pathbuf); dir = opendir(pathbuf);
if(dir != NULL) { if(dir != NULL) {
@ -523,12 +523,12 @@ void print_pid_time_kernelmode(struct text_object *obj, char *p, int p_max_size)
int bytes_read; int bytes_read;
unsigned long int umtime; unsigned long int umtime;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
if(*(objbuf) != 0) { if(*(objbuf.get()) != 0) {
snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu", &umtime); sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu", &umtime);
@ -545,12 +545,12 @@ void print_pid_time_usermode(struct text_object *obj, char *p, int p_max_size) {
int bytes_read; int bytes_read;
unsigned long int kmtime; unsigned long int kmtime;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
if(*(objbuf) != 0) { if(*(objbuf.get()) != 0) {
snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*u %lu", &kmtime); sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %*u %lu", &kmtime);
@ -567,12 +567,12 @@ void print_pid_time(struct text_object *obj, char *p, int p_max_size) {
int bytes_read; int bytes_read;
unsigned long int umtime, kmtime; unsigned long int umtime, kmtime;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
if(*(objbuf) != 0) { if(*(objbuf.get()) != 0) {
snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/stat", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu %lu", &umtime, &kmtime); sscanf(buf, "%*d %*s %*c %*d %*d %*d %*d %*d %*u %*u %*u %*u %*u %lu %lu", &umtime, &kmtime);
@ -590,10 +590,10 @@ void print_pid_uid(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL; char *begin, *end, *buf = NULL;
int bytes_read; int bytes_read;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
@ -617,10 +617,10 @@ void print_pid_euid(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL; char *begin, *end, *buf = NULL;
int bytes_read; int bytes_read;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
@ -645,10 +645,10 @@ void print_pid_suid(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL; char *begin, *end, *buf = NULL;
int bytes_read; int bytes_read;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
@ -674,10 +674,10 @@ void print_pid_fsuid(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL; char *begin, *end, *buf = NULL;
int bytes_read; int bytes_read;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
@ -705,10 +705,10 @@ void print_pid_gid(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL; char *begin, *end, *buf = NULL;
int bytes_read; int bytes_read;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
@ -732,10 +732,10 @@ void print_pid_egid(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL; char *begin, *end, *buf = NULL;
int bytes_read; int bytes_read;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
@ -760,10 +760,10 @@ void print_pid_sgid(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL; char *begin, *end, *buf = NULL;
int bytes_read; int bytes_read;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
@ -789,10 +789,10 @@ void print_pid_fsgid(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL; char *begin, *end, *buf = NULL;
int bytes_read; int bytes_read;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
@ -818,10 +818,10 @@ void internal_print_pid_vm(struct text_object *obj, char *p, int p_max_size, con
char *begin, *end, *buf = NULL; char *begin, *end, *buf = NULL;
int bytes_read; int bytes_read;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/status", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
@ -889,10 +889,10 @@ void print_pid_read(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL; char *begin, *end, *buf = NULL;
int bytes_read; int bytes_read;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/io", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/io", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {
@ -916,10 +916,10 @@ void print_pid_write(struct text_object *obj, char *p, int p_max_size) {
char *begin, *end, *buf = NULL; char *begin, *end, *buf = NULL;
int bytes_read; int bytes_read;
char pathbuf[64]; char pathbuf[64];
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
snprintf(pathbuf, 64, PROCDIR "/%s/io", objbuf); snprintf(pathbuf, 64, PROCDIR "/%s/io", objbuf.get());
buf = readfile(pathbuf, &bytes_read, 1); buf = readfile(pathbuf, &bytes_read, 1);
if(buf != NULL) { if(buf != NULL) {

View File

@ -111,7 +111,7 @@ int append_object(struct text_object *root, struct text_object *obj)
enum ifblock_type { enum ifblock_type {
IFBLOCK_IF = 1, IFBLOCK_IF = 1,
IFBLOCK_ELSE, IFBLOCK_ELSE,
IFBLOCK_ENDIF, IFBLOCK_ENDIF
}; };
/* linked list of ifblock objects, building a stack /* linked list of ifblock objects, building a stack

View File

@ -36,6 +36,8 @@
#include <errno.h> #include <errno.h>
#include "logging.h" #include "logging.h"
#include <memory>
char print_times_in_seconds = 0; char print_times_in_seconds = 0;
struct tztime_s { struct tztime_s {
@ -321,10 +323,10 @@ static void do_format_time(struct text_object *obj, char *p, unsigned int p_max_
void print_format_time(struct text_object *obj, char *p, int p_max_size) void print_format_time(struct text_object *obj, char *p, int p_max_size)
{ {
char buf[max_user_text]; std::unique_ptr<char []> buf(new char[max_user_text]);
generate_text_internal(buf, max_user_text, *obj->sub); generate_text_internal(buf.get(), max_user_text, *obj->sub);
obj->data.s = buf; obj->data.s = buf.get();
do_format_time(obj, p, p_max_size); do_format_time(obj, p, p_max_size);
} }

View File

@ -38,13 +38,13 @@ void print_uid_name(struct text_object *obj, char *p, int p_max_size) {
struct passwd *pw; struct passwd *pw;
uid_t uid; uid_t uid;
char* firstinvalid; char* firstinvalid;
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
errno = 0; errno = 0;
uid = strtol(objbuf, &firstinvalid, 10); uid = strtol(objbuf.get(), &firstinvalid, 10);
if (errno == 0 && objbuf != firstinvalid) { if (errno == 0 && objbuf.get() != firstinvalid) {
pw = getpwuid(uid); pw = getpwuid(uid);
if(pw != NULL) { if(pw != NULL) {
snprintf(p, p_max_size, "%s", pw->pw_name); snprintf(p, p_max_size, "%s", pw->pw_name);
@ -60,13 +60,13 @@ void print_gid_name(struct text_object *obj, char *p, int p_max_size) {
struct group *grp; struct group *grp;
gid_t gid; gid_t gid;
char* firstinvalid; char* firstinvalid;
char objbuf[max_user_text]; std::unique_ptr<char []> objbuf(new char[max_user_text]);
generate_text_internal(objbuf, max_user_text, *obj->sub); generate_text_internal(objbuf.get(), max_user_text, *obj->sub);
errno = 0; errno = 0;
gid = strtol(objbuf, &firstinvalid, 10); gid = strtol(objbuf.get(), &firstinvalid, 10);
if (errno == 0 && objbuf != firstinvalid) { if (errno == 0 && objbuf.get() != firstinvalid) {
grp = getgrgid(gid); grp = getgrgid(gid);
if(grp != NULL) { if(grp != NULL) {
snprintf(p, p_max_size, "%s", grp->gr_name); snprintf(p, p_max_size, "%s", grp->gr_name);