+
+void scan_pid_environ_list_arg(struct text_object *obj, const char *arg, void* free_at_crash)
+{
+ pid_t pid;
+
+ if(sscanf(arg, "%d", &pid) == 1) {
+ asprintf(&obj->data.s, PROCDIR "/%d/environ", pid);
+ } else {
+ CRIT_ERR(obj, free_at_crash, "syntax error: ${pid_environ pid}");
+ }
+}
+
+void print_pid_environ_list(struct text_object *obj, char *p, int p_max_size)
+{
+ char *buf = NULL;
+ char *buf2;
+ FILE* infofile;
+ int bytes_read, total_read = 0;
+ int i = 0;
+
+ infofile = fopen(obj->data.s, "r");
+ if(infofile) {
+ do {
+ buf = realloc(buf, total_read + p_max_size + 1);
+ bytes_read = fread(buf + total_read, 1, p_max_size, infofile);
+ total_read += bytes_read;
+ buf[total_read] = 0;
+ }while(bytes_read != 0);
+ while(bytes_read < total_read) {
+ buf2 = strdup(buf+bytes_read);
+ bytes_read += strlen(buf2)+1;
+ sscanf(buf2, "%[^=]", buf+i);
+ free(buf2);
+ i = strlen(buf) + 1;
+ buf[i-1] = ';';
+ }
+ buf[i-1] = 0;
+ snprintf(p, p_max_size, buf);
+ free(buf);
+ fclose(infofile);
+ } else {
+ NORM_ERR(READERR, obj->data.s);
+ }
+}