/////////////////////////////////////////////////
-// copy an already 'escaped' string,
+// copy a string, but 'escape' any control characters
// using the traditional escape.h calling conventions
int escaped_copy(char *restrict dst, const char *restrict src, int bufsize, int *maxroom){
- int n;
+ int i, n;
SECURE_ESCAPE_ARGS(dst, bufsize, *maxroom);
if (bufsize > *maxroom+1) bufsize = *maxroom+1;
return 0;
}
if (n >= bufsize) n = bufsize-1;
+
+ // control chars, especially tabs, create alignment problems for ps & top ...
+ for (i = 0; i < n; i++)
+ if ((unsigned char)dst[i] < 0x20 || dst[i] == 0x7f)
+ dst[i] = '?';
+
*maxroom -= n;
return n;
}
len = snprintf(dst, vMAX, "%s", (dst > dst_buffer) ? "," : "");
if (len < 0 || len >= vMAX) break;
dst += len;
- dst += escape_str(dst, grp, vMAX, &whackable_int);
+ dst += escaped_copy(dst, grp, vMAX, &whackable_int);
}
p->cgroup = vectorize_this_str(dst_buffer[0] ? dst_buffer : "-");
int whackable_int = MAX_BUFSZ;
if (read_unvectored(src_buffer, MAX_BUFSZ, directory, "cmdline", ' '))
- escape_str(dst_buffer, src_buffer, MAX_BUFSZ, &whackable_int);
+ escaped_copy(dst_buffer, src_buffer, MAX_BUFSZ, &whackable_int);
else
escape_command(dst_buffer, p, MAX_BUFSZ, &whackable_int, uFLG);
p->cmdline = vectorize_this_str(dst_buffer);
dst_buffer[0] = '\0';
if (read_unvectored(src_buffer, MAX_BUFSZ, directory, "environ", ' '))
- escape_str(dst_buffer, src_buffer, MAX_BUFSZ, &whackable_int);
+ escaped_copy(dst_buffer, src_buffer, MAX_BUFSZ, &whackable_int);
p->environ = vectorize_this_str(dst_buffer[0] ? dst_buffer : "-");
}