// this is the former under utilized 'read_cmdline', which has been
// generalized in support of these new libproc flags:
- // PROC_EDITCGRPCVT, PROC_EDITCMDLCVT
+ // PROC_EDITCGRPCVT, PROC_EDITCMDLCVT and PROC_EDITENVRCVT
static int read_unvectored(char *restrict const dst, unsigned sz, const char* whom, const char *what, char sep) {
char path[PROCPATHLEN];
int fd;
#undef uFLG
}
+ // This routine reads an 'environ' for the designated proc_t and
+ // guarantees the caller a valid proc_t.environ pointer.
+static void fill_environ_cvt (const char* directory, proc_t *restrict p) {
+ int whackable_int = MAX_BUFSZ;
+
+ dst_buffer[0] = '\0';
+ if (read_unvectored(src_buffer, MAX_BUFSZ, directory, "environ", ' '))
+ escape_str(dst_buffer, src_buffer, MAX_BUFSZ, &whackable_int);
+ p->environ = vectorize_this_str(dst_buffer[0] ? dst_buffer : "-");
+}
+
// warning: interface may change
int read_cmdline(char *restrict const dst, unsigned sz, unsigned pid) {
char path[PROCPATHLEN];
}
}
- if (unlikely(flags & PROC_FILLENV)) // read /proc/#/environ
- p->environ = file2strvec(path, "environ");
- else
+ if (unlikely(flags & PROC_FILLENV)) { // read /proc/#/environ
+ if (flags & PROC_EDITENVRCVT)
+ fill_environ_cvt(path, p);
+ else
+ p->environ = file2strvec(path, "environ");
+ } else
p->environ = NULL;
if (flags & (PROC_FILLCOM|PROC_FILLARG)) { // read /proc/#/cmdline
if (flags & PROC_FILLSUPGRP)
supgrps_from_supgids(t);
#endif
- if (unlikely(flags & PROC_FILLENV)) // read /proc/#/task/#/environ
- t->environ = file2strvec(path, "environ");
- else
+ if (unlikely(flags & PROC_FILLENV)) { // read /proc/#/task/#/environ
+ if (flags & PROC_EDITENVRCVT)
+ fill_environ_cvt(path, t);
+ else
+ t->environ = file2strvec(path, "environ");
+ } else
t->environ = NULL;
if (flags & (PROC_FILLCOM|PROC_FILLARG)) { // read /proc/#/task/#/cmdline