FreeBSD/usr.sbin/kgmon/kgmon.c
/*
 * Reset the kernel profiling date structures.
 */
Reset the kernel profiling date structures.
Reset the kernel profiling date structures .
void
reset(struct kvmvars *kvp)
{
	char *zbuf;
	u_long biggest;
	int mib[3];
	setprof(kvp, GMON_PROF_OFF);
	biggest = kvp->gpm.kcountsize;
	if (kvp->gpm.fromssize > biggest)
		biggest = kvp->gpm.fromssize;
	if (kvp->gpm.tossize > biggest)
		biggest = kvp->gpm.tossize;
	if ((zbuf = (char *)malloc(biggest)) == NULL)
		errx(12, "cannot allocate zbuf space");
	bzero(zbuf, biggest);
	if (kflag) {
		if (kvm_write(kvp->kd, (u_long)kvp->gpm.kcount, zbuf,
		    kvp->gpm.kcountsize) != (ssize_t)kvp->gpm.kcountsize)
			errx(13, "tickbuf zero: %s", kvm_geterr(kvp->kd));
		if (kvm_write(kvp->kd, (u_long)kvp->gpm.froms, zbuf,
		    kvp->gpm.fromssize) != (ssize_t)kvp->gpm.fromssize)
			errx(14, "froms zero: %s", kvm_geterr(kvp->kd));
		if (kvm_write(kvp->kd, (u_long)kvp->gpm.tos, zbuf,
		    kvp->gpm.tossize) != (ssize_t)kvp->gpm.tossize)
			errx(15, "tos zero: %s", kvm_geterr(kvp->kd));
		return;
	}
	(void)seteuid(0);
	mib[0] = CTL_KERN;
	mib[1] = KERN_PROF;
	mib[2] = GPROF_COUNT;
	if (sysctl(mib, 3, NULL, NULL, zbuf, kvp->gpm.kcountsize) < 0)
		err(13, "tickbuf zero");
	mib[2] = GPROF_FROMS;
	if (sysctl(mib, 3, NULL, NULL, zbuf, kvp->gpm.fromssize) < 0)
		err(14, "froms zero");
	mib[2] = GPROF_TOS;
	if (sysctl(mib, 3, NULL, NULL, zbuf, kvp->gpm.tossize) < 0)
		err(15, "tos zero");
	(void)seteuid(getuid());
	free(zbuf);
}
void reset ( struct kvmvars * kvp ) { char * zbuf ; u_long biggest ; int mib [ 3 ] ; setprof ( kvp , GMON_PROF_OFF ) ; biggest = kvp -> gpm . kcountsize ; if ( kvp -> gpm . fromssize > biggest ) biggest = kvp -> gpm . fromssize ; if ( kvp -> gpm . tossize > biggest ) biggest = kvp -> gpm . tossize ; if ( ( zbuf = ( char * ) malloc ( biggest ) ) == NULL ) errx ( 12 , " " ) ; bzero ( zbuf , biggest ) ; if ( kflag ) { if ( kvm_write ( kvp -> kd , ( u_long ) kvp -> gpm . kcount , zbuf , kvp -> gpm . kcountsize ) != ( ssize_t ) kvp -> gpm . kcountsize ) errx ( 13 , " " , kvm_geterr ( kvp -> kd ) ) ; if ( kvm_write ( kvp -> kd , ( u_long ) kvp -> gpm . froms , zbuf , kvp -> gpm . fromssize ) != ( ssize_t ) kvp -> gpm . fromssize ) errx ( 14 , " " , kvm_geterr ( kvp -> kd ) ) ; if ( kvm_write ( kvp -> kd , ( u_long ) kvp -> gpm . tos , zbuf , kvp -> gpm . tossize ) != ( ssize_t ) kvp -> gpm . tossize ) errx ( 15 , " " , kvm_geterr ( kvp -> kd ) ) ; return ; } ( void ) seteuid ( 0 ) ; mib [ 0 ] = CTL_KERN ; mib [ 1 ] = KERN_PROF ; mib [ 2 ] = GPROF_COUNT ; if ( sysctl ( mib , 3 , NULL , NULL , zbuf , kvp -> gpm . kcountsize ) < 0 ) err ( 13 , " " ) ; mib [ 2 ] = GPROF_FROMS ; if ( sysctl ( mib , 3 , NULL , NULL , zbuf , kvp -> gpm . fromssize ) < 0 ) err ( 14 , " " ) ; mib [ 2 ] = GPROF_TOS ; if ( sysctl ( mib , 3 , NULL , NULL , zbuf , kvp -> gpm . tossize ) < 0 ) err ( 15 , " " ) ; ( void ) seteuid ( getuid ( ) ) ; free ( zbuf ) ; }
Reset the kernel profiling date structures.
Reset the kernel profiling date structures .