MCPcopy Create free account
hub / github.com/F-Stack/f-stack / get_ps_strings

Function get_ps_strings

freebsd/kern/kern_proc.c:1987–2033  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1985#define GET_PS_STRINGS_CHUNK_SZ 256 /* Chunk size (bytes) for ps_strings operations. */
1986
1987static int
1988get_ps_strings(struct thread *td, struct proc *p, struct sbuf *sb,
1989 enum proc_vector_type type)
1990{
1991 size_t done, len, nchr, vsize;
1992 int error, i;
1993 char **proc_vector, *sptr;
1994 char pss_string[GET_PS_STRINGS_CHUNK_SZ];
1995
1996 PROC_ASSERT_HELD(p);
1997
1998 /*
1999 * We are not going to read more than 2 * (PATH_MAX + ARG_MAX) bytes.
2000 */
2001 nchr = 2 * (PATH_MAX + ARG_MAX);
2002
2003 error = get_proc_vector(td, p, &proc_vector, &vsize, type);
2004 if (error != 0)
2005 return (error);
2006 for (done = 0, i = 0; i < (int)vsize && done < nchr; i++) {
2007 /*
2008 * The program may have scribbled into its argv array, e.g. to
2009 * remove some arguments. If that has happened, break out
2010 * before trying to read from NULL.
2011 */
2012 if (proc_vector[i] == NULL)
2013 break;
2014 for (sptr = proc_vector[i]; ; sptr += GET_PS_STRINGS_CHUNK_SZ) {
2015 error = proc_read_string(td, p, sptr, pss_string,
2016 sizeof(pss_string));
2017 if (error != 0)
2018 goto done;
2019 len = strnlen(pss_string, GET_PS_STRINGS_CHUNK_SZ);
2020 if (done + len >= nchr)
2021 len = nchr - done - 1;
2022 sbuf_bcat(sb, pss_string, len);
2023 if (len != GET_PS_STRINGS_CHUNK_SZ)
2024 break;
2025 done += GET_PS_STRINGS_CHUNK_SZ;
2026 }
2027 sbuf_bcat(sb, "", 1);
2028 done += len + 1;
2029 }
2030done:
2031 free(proc_vector, M_TEMP);
2032 return (error);
2033}
2034
2035int
2036proc_getargv(struct thread *td, struct proc *p, struct sbuf *sb)

Callers 2

proc_getargvFunction · 0.85
proc_getenvvFunction · 0.85

Calls 5

get_proc_vectorFunction · 0.85
proc_read_stringFunction · 0.85
strnlenFunction · 0.85
sbuf_bcatFunction · 0.85
freeFunction · 0.70

Tested by

no test coverage detected