library: correct 'vectorized' string logic, <PIDS> api
The commit referenced below addressed (some) anomalies
surrounding 'strv' pointers. However, there remained a
couple quirks involving a potential NULL return value.
Any NULL values returned from the old library readproc
guys would cause no real harm for newlib. But they did
produce the misleading "[ duplicate ENUM_ID ]" result.
The following all represent potential NULL results and
suggest shortcomings in testing of that earlier patch.
. kernel threads do not have cgroup, cmdline & environ
. even if present environ could require root to access
So, this patch reverts a portion of the earlier commit
and ensures when some vectored string is not available
a traditional dash ('-') is the 'strv' returned value.
[ and we'll also correct one typo in the header file ]
Reference(s):
. eliminated a final potential NULL, <PIDS> api
commit 09503dc597
Signed-off-by: Jim Warner <james.warner@comcast.net>
This commit is contained in:
21
proc/pids.c
21
proc/pids.c
@ -94,25 +94,6 @@ struct pids_info {
|
||||
|
||||
// ___ Results 'Set' Support ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||
|
||||
static char** pids_vectorize_this (const char* src) {
|
||||
#define pSZ (sizeof(char*))
|
||||
char *cpy, **vec;
|
||||
size_t adj, tot;
|
||||
|
||||
tot = strlen(src) + 1; // prep for our vectors
|
||||
if (tot < 1 || tot >= INT_MAX) tot = INT_MAX-1; // integer overflow?
|
||||
adj = (pSZ-1) - ((tot + pSZ-1) & (pSZ-1)); // calc alignment bytes
|
||||
cpy = calloc(1, tot + adj + (2 * pSZ)); // get new larger buffer
|
||||
if (!cpy) return NULL; // oops, looks like ENOMEM
|
||||
snprintf(cpy, tot, "%s", src); // duplicate their string
|
||||
vec = (char**)(cpy + tot + adj); // prep pointer to pointers
|
||||
*vec = cpy; // point 1st vector to string
|
||||
*(vec+1) = NULL; // null ptr 'list' delimit
|
||||
return vec; // ==> free(*vec) to dealloc
|
||||
#undef pSZ
|
||||
} // end: pids_vectorize_this
|
||||
|
||||
|
||||
#define setNAME(e) set_pids_ ## e
|
||||
#define setDECL(e) static void setNAME(e) \
|
||||
(struct pids_info *I, struct pids_result *R, proc_t *P)
|
||||
@ -136,7 +117,7 @@ static char** pids_vectorize_this (const char* src) {
|
||||
some sort of hint that they duplicated this char ** item ... */
|
||||
#define VEC_set(e,x) setDECL(e) { \
|
||||
if (NULL != P-> x) { R->result.strv = P-> x; P-> x = NULL; } \
|
||||
else { R->result.strv = pids_vectorize_this("[ duplicate " STRINGIFY(e) " ]"); \
|
||||
else { R->result.strv = vectorize_this_str("[ duplicate " STRINGIFY(e) " ]"); \
|
||||
if (!R->result.str) I->seterr = 1; } }
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user