From d916d5db86cbbf552401026aab15c3663412d662 Mon Sep 17 00:00:00 2001 From: Craig Small Date: Sun, 17 Apr 2016 14:45:19 +1000 Subject: [PATCH] library: re-arrange escape commands escaped_copy(): only appears in ps, moved to ps/output.c escape_strlist() only used in escape.c made static escape_command() used in library, made internal procps.h no longer includes escape.h escape_str() used by library and ps so needs to be exported definition put into procps.h including the odd define required. Far from ideal to have it this way, will look at it another time to have it all in, all out or split nicer so its not in the API; perhaps a lib/ file? --- proc/escape.c | 17 +++-------------- proc/escape.h | 9 +++------ proc/libprocps.sym | 3 --- proc/procps.h | 5 ++++- ps/output.c | 19 +++++++++++-------- 5 files changed, 21 insertions(+), 32 deletions(-) diff --git a/proc/escape.c b/proc/escape.c index 971c5d81..2244f54a 100644 --- a/proc/escape.c +++ b/proc/escape.c @@ -20,7 +20,8 @@ #include #include #include -#include "procps.h" +#include + #include "escape.h" #include "readproc.h" @@ -162,7 +163,7 @@ int escape_str(char *restrict dst, const char *restrict src, int bufsize, int *m // escape an argv or environment string array // // bytes arg means sizeof(buf) -int escape_strlist(char *restrict dst, char *restrict const *restrict src, size_t bytes, int *cells){ +static int escape_strlist(char *restrict dst, char *restrict const *restrict src, size_t bytes, int *cells){ size_t i = 0; for(;;){ @@ -218,15 +219,3 @@ int escape_command(char *restrict const outbuf, const proc_t *restrict const pp, return end; // bytes, not including the NUL } -///////////////////////////////////////////////// - -// copy an already 'escaped' string, -// using the traditional escape.h calling conventions -int escaped_copy(char *restrict dst, const char *restrict src, int bufsize, int *maxroom){ - int n; - if (bufsize > *maxroom+1) bufsize = *maxroom+1; - n = snprintf(dst, bufsize, "%s", src); - if (n >= bufsize) n = bufsize-1; - *maxroom -= n; - return n; -} diff --git a/proc/escape.h b/proc/escape.h index c2f3c45b..a2494da6 100644 --- a/proc/escape.h +++ b/proc/escape.h @@ -1,21 +1,18 @@ #ifndef PROCPS_PROC_ESCAPE_H #define PROCPS_PROC_ESCAPE_H -#include #include +#include "readproc.h" __BEGIN_DECLS -#define ESC_STRETCH 1 // since we mangle to '?' this is 1 (would be 4 for octal escapes) #define ESC_ARGS 0x1 // try to use cmdline instead of cmd #define ESC_BRACKETS 0x2 // if using cmd, put '[' and ']' around it #define ESC_DEFUNCT 0x4 // mark zombies with " " -extern int escape_strlist(char *__restrict dst, char *__restrict const *__restrict src, size_t n, int *cells); -extern int escape_str(char *__restrict dst, const char *__restrict src, int bufsize, int *maxcells); -extern int escape_command(char *__restrict const outbuf, const proc_t *__restrict const pp, int bytes, int *cells, unsigned flags); -extern int escaped_copy(char *__restrict dst, const char *__restrict src, int bufsize, int *maxroom); + +int escape_command(char *__restrict const outbuf, const proc_t *__restrict const pp, int bytes, int *cells, unsigned flags); __END_DECLS #endif diff --git a/proc/libprocps.sym b/proc/libprocps.sym index 64bb9c7c..b6537eb7 100644 --- a/proc/libprocps.sym +++ b/proc/libprocps.sym @@ -1,9 +1,6 @@ LIBPROCPS_0 { global: - escape_command; escape_str; - escape_strlist; - escaped_copy; fatal_proc_unmounted; procps_cpu_count; procps_diskstat_dev_count; diff --git a/proc/procps.h b/proc/procps.h index 03a38206..a94489ef 100644 --- a/proc/procps.h +++ b/proc/procps.h @@ -20,7 +20,6 @@ /* includes that show public exports go here */ #include -#include #include #include #include @@ -31,4 +30,8 @@ #include #include +// FIXME: only public function in escape.c +#define ESC_STRETCH 1 // since we mangle to '?' this is 1 (would be 4 for octal escapes) +int escape_str(char *__restrict dst, const char *__restrict src, int bufsize, int *maxcells); + #endif diff --git a/ps/output.c b/ps/output.c index b31ce6b5..0117c9c3 100644 --- a/ps/output.c +++ b/ps/output.c @@ -115,6 +115,17 @@ static void get_memory_total() procps_meminfo_unref(&mem_info); } +// copy an already 'escaped' string, +static int escaped_copy(char *restrict dst, const char *restrict src, int bufsize, int *maxroom){ + int n; + if (bufsize > *maxroom+1) + bufsize = *maxroom+1; + n = snprintf(dst, bufsize, "%s", src); + if (n >= bufsize) + n = bufsize-1; + *maxroom -= n; + return n; +} /***************************************************************************/ /************ Lots of format functions, starting with the NOP **************/ @@ -949,7 +960,6 @@ setREL1(TIME_START) } -#ifdef SIGNAL_STRING static int help_pr_sig(char *restrict const outbuf, const char *restrict const sig){ long len = 0; len = strlen(sig); @@ -961,13 +971,6 @@ static int help_pr_sig(char *restrict const outbuf, const char *restrict const s return snprintf(outbuf, COLWID, "<%s", sig+len-8); return snprintf(outbuf, COLWID, "%s", sig+len-8); } -#else -static int help_pr_sig(unsigned long long sig){ - if(wide_signals) return snprintf(outbuf, COLWID, "%016Lx", sig); - if(sig>>32) return snprintf(outbuf, COLWID, "<%08Lx", sig&0xffffffffLL); - return snprintf(outbuf, COLWID, "%08Lx", sig&0xffffffffLL); -} -#endif // This one is always thread-specific pending. (from Dragonfly BSD) static int pr_tsig(char *restrict const outbuf, const proc_t *restrict const pp){