FreeBSD/sys/kern/kern_proc.c
/*
 * This sysctl allows a process to retrieve environment of another process.
 */
This sysctl allows a process to retrieve environment of another process.
This sysctl allows a process to retrieve environment of another process .
static int
sysctl_kern_proc_env(SYSCTL_HANDLER_ARGS)
{
	int *name = (int *)arg1;
	u_int namelen = arg2;
	struct proc *p;
	struct sbuf sb;
	int error, error2;
	if (namelen != 1)
		return (EINVAL);
	error = pget((pid_t)name[0], PGET_WANTREAD, &p);
	if (error != 0)
		return (error);
	if ((p->p_flag & P_SYSTEM) != 0) {
		PRELE(p);
		return (0);
	}
	sbuf_new_for_sysctl(&sb, NULL, GET_PS_STRINGS_CHUNK_SZ, req);
	sbuf_clear_flags(&sb, SBUF_INCLUDENUL);
	error = proc_getenvv(curthread, p, &sb);
	error2 = sbuf_finish(&sb);
	PRELE(p);
	sbuf_delete(&sb);
	return (error != 0 ? error : error2);
}
static int sysctl_kern_proc_env ( SYSCTL_HANDLER_ARGS ) { int * name = ( int * ) arg1 ; u_int namelen = arg2 ; struct proc * p ; struct sbuf sb ; int error , error2 ; if ( namelen != 1 ) return ( EINVAL ) ; error = pget ( ( pid_t ) name [ 0 ] , PGET_WANTREAD , & p ) ; if ( error != 0 ) return ( error ) ; if ( ( p -> p_flag & P_SYSTEM ) != 0 ) { PRELE ( p ) ; return ( 0 ) ; } sbuf_new_for_sysctl ( & sb , NULL , GET_PS_STRINGS_CHUNK_SZ , req ) ; sbuf_clear_flags ( & sb , SBUF_INCLUDENUL ) ; error = proc_getenvv ( curthread , p , & sb ) ; error2 = sbuf_finish ( & sb ) ; PRELE ( p ) ; sbuf_delete ( & sb ) ; return ( error != 0 ? error : error2 ) ; }
This sysctl allows a process to retrieve environment of another process.
This sysctl allows a process to retrieve environment of another process .