In procfs_doproccmdline() if arguments are not cashed read them from

the process stack.

Suggested by:	kib
Reviewed by:	kib
Tested by:	pho
MFC after:	2 weeks
This commit is contained in:
Mikolaj Golub 2011-11-22 20:43:03 +00:00
parent c5cfcb1c19
commit beb7471b16
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=227834

View File

@ -170,15 +170,10 @@ procfs_doprocstatus(PFS_FILL_ARGS)
int
procfs_doproccmdline(PFS_FILL_ARGS)
{
struct ps_strings pstr;
char **ps_argvstr;
int error, i;
/*
* If we are using the ps/cmdline caching, use that. Otherwise
* revert back to the old way which only implements full cmdline
* for the current process and just p->p_comm for all other
* processes.
* read argv from the process space.
* Note that if the argv is no longer available, we deliberately
* don't fall back on p->p_comm or return an error: the authentic
* Linux behaviour is to return zero-length in this case.
@ -190,30 +185,13 @@ procfs_doproccmdline(PFS_FILL_ARGS)
PROC_UNLOCK(p);
return (0);
}
PROC_UNLOCK(p);
if (p != td->td_proc) {
sbuf_printf(sb, "%.*s", MAXCOMLEN, p->p_comm);
} else {
error = copyin((void *)p->p_sysent->sv_psstrings, &pstr,
sizeof(pstr));
if (error)
return (error);
if (pstr.ps_nargvstr > ARG_MAX)
return (E2BIG);
ps_argvstr = malloc(pstr.ps_nargvstr * sizeof(char *),
M_TEMP, M_WAITOK);
error = copyin((void *)pstr.ps_argvstr, ps_argvstr,
pstr.ps_nargvstr * sizeof(char *));
if (error) {
free(ps_argvstr, M_TEMP);
return (error);
}
for (i = 0; i < pstr.ps_nargvstr; i++) {
sbuf_copyin(sb, ps_argvstr[i], 0);
sbuf_printf(sb, "%c", '\0');
}
free(ps_argvstr, M_TEMP);
if ((p->p_flag & P_SYSTEM) != 0) {
PROC_UNLOCK(p);
return (0);
}
return (0);
PROC_UNLOCK(p);
return (proc_getargv(td, p, sb, ARG_MAX));
}