pgrep: Use POSIX _SC_ARG_MAX for maximum full command line length
Modified for newlib but based upon patch in master by Clay Baenziger <cwb@clayb.net> References: commit f9e56d3c667513d96b798340f7b7c1b40096f084 procps-ng/procps!85
This commit is contained in:
parent
012db8222e
commit
61b627d53c
24
pgrep.c
24
pgrep.c
@ -42,8 +42,6 @@
|
|||||||
#define EXIT_FATAL 3
|
#define EXIT_FATAL 3
|
||||||
#define XALLOC_EXIT_CODE EXIT_FATAL
|
#define XALLOC_EXIT_CODE EXIT_FATAL
|
||||||
|
|
||||||
#define CMDSTRSIZE 4096
|
|
||||||
|
|
||||||
#include "c.h"
|
#include "c.h"
|
||||||
#include "fileutils.h"
|
#include "fileutils.h"
|
||||||
#include "nls.h"
|
#include "nls.h"
|
||||||
@ -496,8 +494,10 @@ static struct el * select_procs (int *num)
|
|||||||
regex_t *preg;
|
regex_t *preg;
|
||||||
pid_t myself = getpid();
|
pid_t myself = getpid();
|
||||||
struct el *list = NULL;
|
struct el *list = NULL;
|
||||||
char cmdsearch[CMDSTRSIZE] = "";
|
long cmdlen = sysconf(_SC_ARG_MAX) * sizeof(char);
|
||||||
char cmdoutput[CMDSTRSIZE] = "";
|
char *cmdline = xmalloc(cmdlen);
|
||||||
|
char *cmdsearch = xmalloc(cmdlen);
|
||||||
|
char *cmdoutput = xmalloc(cmdlen);
|
||||||
char *task_cmdline;
|
char *task_cmdline;
|
||||||
enum pids_fetch_type which;
|
enum pids_fetch_type which;
|
||||||
|
|
||||||
@ -551,22 +551,21 @@ static struct el * select_procs (int *num)
|
|||||||
match = 0;
|
match = 0;
|
||||||
|
|
||||||
task_cmdline = PIDS_GETSTR(CMDLINE);
|
task_cmdline = PIDS_GETSTR(CMDLINE);
|
||||||
task_cmdline[CMDSTRSIZE -1] = '\0';
|
|
||||||
|
|
||||||
if (opt_long || opt_longlong || (match && opt_pattern)) {
|
if (opt_long || opt_longlong || (match && opt_pattern)) {
|
||||||
if (opt_longlong)
|
if (opt_longlong)
|
||||||
strncpy (cmdoutput, task_cmdline, sizeof cmdoutput -1);
|
strncpy (cmdoutput, task_cmdline, cmdlen -1);
|
||||||
else
|
else
|
||||||
strncpy (cmdoutput, PIDS_GETSTR(CMD), sizeof cmdoutput -1);
|
strncpy (cmdoutput, PIDS_GETSTR(CMD), cmdlen -1);
|
||||||
cmdoutput[sizeof cmdoutput - 1] = '\0';
|
cmdoutput[cmdlen - 1] = '\0';
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match && opt_pattern) {
|
if (match && opt_pattern) {
|
||||||
if (opt_full)
|
if (opt_full)
|
||||||
strncpy (cmdsearch, task_cmdline, sizeof cmdsearch -1);
|
strncpy (cmdsearch, task_cmdline, cmdlen -1);
|
||||||
else
|
else
|
||||||
strncpy (cmdsearch, PIDS_GETSTR(CMD), sizeof cmdsearch -1);
|
strncpy (cmdsearch, PIDS_GETSTR(CMD), cmdlen -1);
|
||||||
cmdsearch[sizeof cmdsearch - 1] = '\0';
|
cmdsearch[cmdlen - 1] = '\0';
|
||||||
|
|
||||||
if (regexec (preg, cmdsearch, 0, NULL, 0) != 0)
|
if (regexec (preg, cmdsearch, 0, NULL, 0) != 0)
|
||||||
match = 0;
|
match = 0;
|
||||||
@ -604,6 +603,9 @@ static struct el * select_procs (int *num)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
procps_pids_unref(&info);
|
procps_pids_unref(&info);
|
||||||
|
free(cmdline);
|
||||||
|
free(cmdsearch);
|
||||||
|
free(cmdoutput);
|
||||||
|
|
||||||
*num = matches;
|
*num = matches;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user