Example #1
0
static int
acpi_cst_global_lowest_use_sysctl(SYSCTL_HANDLER_ARGS)
{
    char	state[8];

    ksnprintf(state, sizeof(state), "C%d", acpi_cst_cx_lowest + 1);
    return sysctl_handle_string(oidp, state, sizeof(state), req);
}
Example #2
0
static int
acpi_cst_lowest_use_sysctl(SYSCTL_HANDLER_ARGS)
{
    struct	 acpi_cst_softc *sc;
    char	 state[8];

    sc = (struct acpi_cst_softc *)arg1;
    ksnprintf(state, sizeof(state), "C%d", sc->cst_cx_lowest + 1);
    return sysctl_handle_string(oidp, state, sizeof(state), req);
}
Example #3
0
static int
linux_sysctl_osrelease(SYSCTL_HANDLER_ARGS)
{
	char osrelease[LINUX_MAX_UTSNAME];
	int error;

	linux_get_osrelease(req->td, osrelease);
	error = sysctl_handle_string(oidp, osrelease, LINUX_MAX_UTSNAME, req);
	if (error || req->newptr == NULL)
		return (error);
	error = linux_set_osrelease(req->td, osrelease);
	return (error);
}
static int
sysctl_hostname(SYSCTL_HANDLER_ARGS)
{
	struct prison *pr;
	char tmphostname[MAXHOSTNAMELEN];
	int error;

	pr = req->td->td_ucred->cr_prison;
	if (pr != NULL) {
		if (!jail_set_hostname_allowed && req->newptr)
			return (EPERM);
		/*
		 * Process is in jail, so make a local copy of jail
		 * hostname to get/set so we don't have to hold the jail
		 * mutex during the sysctl copyin/copyout activities.
		 */
		mtx_lock(&pr->pr_mtx);
		bcopy(pr->pr_host, tmphostname, MAXHOSTNAMELEN);
		mtx_unlock(&pr->pr_mtx);

		error = sysctl_handle_string(oidp, tmphostname,
		    sizeof pr->pr_host, req);

		if (req->newptr != NULL && error == 0) {
			/*
			 * Copy the locally set hostname to the jail, if
			 * appropriate.
			 */
			mtx_lock(&pr->pr_mtx);
			bcopy(tmphostname, pr->pr_host, MAXHOSTNAMELEN);
			mtx_unlock(&pr->pr_mtx);
		}
	} else
		error = sysctl_handle_string(oidp,
		    hostname, sizeof hostname, req);
	return (error);
}
Example #5
0
/* Report registered DTrace providers. */
static int
sysctl_dtrace_providers(SYSCTL_HANDLER_ARGS)
{
	char	*p_name	= NULL;
	dtrace_provider_t
		*prov	= dtrace_provider;
	int	error	= 0;
	size_t	len	= 0;

	mutex_enter(&dtrace_provider_lock);
	mutex_enter(&dtrace_lock);

	/* Compute the length of the space-separated provider name string. */
	while (prov != NULL) {
		len += strlen(prov->dtpv_name) + 1;
		prov = prov->dtpv_next;
	}

	if ((p_name = kmem_alloc(len, KM_SLEEP)) == NULL)
		error = ENOMEM;
	else {
		/* Start with an empty string. */
		*p_name = '\0';

		/* Point to the first provider again. */
		prov = dtrace_provider;

		/* Loop through the providers, appending the names. */
		while (prov != NULL) {
			if (prov != dtrace_provider)
				(void) strlcat(p_name, " ", len);

			(void) strlcat(p_name, prov->dtpv_name, len);

			prov = prov->dtpv_next;
		}
	}

	mutex_exit(&dtrace_lock);
	mutex_exit(&dtrace_provider_lock);

	if (p_name != NULL) {
		error = sysctl_handle_string(oidp, p_name, len, req);

		kmem_free(p_name, 0);
	}

	return (error);
}
Example #6
0
static int
ahci_sysctl_link_pwr_state (SYSCTL_HANDLER_ARGS)
{
	struct ahci_port *ap = arg1;
	const char *state_names[] = {"unknown", "active", "partial", "slumber"};
	char buf[16];
	int state;

	state = ahci_port_link_pwr_state(ap);
	if (state < 0 || state >= NELEM(state_names))
		state = 0;

	ksnprintf(buf, sizeof(buf), "%s", state_names[state]);
	return sysctl_handle_string(oidp, buf, sizeof(buf), req);
}
Example #7
0
static int
sysctl_hostname(SYSCTL_HANDLER_ARGS)
{
	struct prison *pr, *cpr;
	size_t pr_offset;
	char tmpname[MAXHOSTNAMELEN];
	int descend, error, len;

	/*
	 * This function can set: hostname domainname hostuuid.
	 * Keep that in mind when comments say "hostname".
	 */
	pr_offset = (size_t)arg1;
	len = arg2;
	KASSERT(len <= sizeof(tmpname),
	    ("length %d too long for %s", len, __func__));

	pr = req->td->td_ucred->cr_prison;
	if (!(pr->pr_allow & PR_ALLOW_SET_HOSTNAME) && req->newptr)
		return (EPERM);
	/*
	 * Make a local copy of hostname to get/set so we don't have to hold
	 * the jail mutex during the sysctl copyin/copyout activities.
	 */
	mtx_lock(&pr->pr_mtx);
	bcopy((char *)pr + pr_offset, tmpname, len);
	mtx_unlock(&pr->pr_mtx);

	error = sysctl_handle_string(oidp, tmpname, len, req);

	if (req->newptr != NULL && error == 0) {
		/*
		 * Copy the locally set hostname to all jails that share
		 * this host info.
		 */
		sx_slock(&allprison_lock);
		while (!(pr->pr_flags & PR_HOST))
			pr = pr->pr_parent;
		mtx_lock(&pr->pr_mtx);
		bcopy(tmpname, (char *)pr + pr_offset, len);
		FOREACH_PRISON_DESCENDANT_LOCKED(pr, cpr, descend)
			if (cpr->pr_flags & PR_HOST)
				descend = 0;
			else
				bcopy(tmpname, (char *)cpr + pr_offset, len);
		mtx_unlock(&pr->pr_mtx);
		sx_sunlock(&allprison_lock);
	}
Example #8
0
static int
kdb_sysctl_current(SYSCTL_HANDLER_ARGS)
{
	char buf[16];
	int error;

	if (kdb_dbbe != NULL)
		strlcpy(buf, kdb_dbbe->dbbe_name, sizeof(buf));
	else
		*buf = '\0';
	error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
	if (error != 0 || req->newptr == NULL)
		return (error);
	if (kdb_active)
		return (EBUSY);
	return (kdb_dbbe_select(buf));
}
Example #9
0
static int
aw_sid_sysctl(SYSCTL_HANDLER_ARGS)
{
	enum sid_keys key = arg2;
	u_char rootkey[16];
	char out[33];

	if (key != AW_SID_ROOT_KEY)
		return (ENOENT);

	if (aw_sid_get_rootkey(rootkey) != 0)
		return (ENOENT);
	snprintf(out, sizeof(out),
	  "%16D", rootkey, "");

	return sysctl_handle_string(oidp, out, sizeof(out), req);
}
Example #10
0
static int
zy7_devcfg_fclk_sysctl_source(SYSCTL_HANDLER_ARGS)
{
	char buf[4];
	struct zy7_fclk_config *cfg;
	int unit;
	int error;

	cfg = arg1;
	unit = arg2;

	switch (cfg->source) {
		case ZY7_PL_FCLK_SRC_IO:
		case ZY7_PL_FCLK_SRC_IO_ALT:
			strncpy(buf, "IO", sizeof(buf));
			break;
		case ZY7_PL_FCLK_SRC_DDR:
			strncpy(buf, "DDR", sizeof(buf));
			break;
		case ZY7_PL_FCLK_SRC_ARM:
			strncpy(buf, "ARM", sizeof(buf));
			break;
		default:
			strncpy(buf, "???", sizeof(buf));
			break;
	}

	error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
	if (error != 0 || req->newptr == NULL)
		return (error);

	if (strcasecmp(buf, "io") == 0)
		cfg->source = ZY7_PL_FCLK_SRC_IO;
	else if (strcasecmp(buf, "ddr") == 0)
		cfg->source = ZY7_PL_FCLK_SRC_DDR;
	else if (strcasecmp(buf, "arm") == 0)
		cfg->source = ZY7_PL_FCLK_SRC_ARM;
	else
		return (EINVAL);

	zy7_pl_fclk_set_source(unit, cfg->source);
	if (cfg->frequency > 0)
		cfg->actual_frequency = zy7_pl_fclk_get_freq(unit);

	return (0);
}
Example #11
0
static int
memguard_sysctl_desc(SYSCTL_HANDLER_ARGS)
{
	char desc[sizeof(vm_memguard_desc)];
	int error;

	strlcpy(desc, vm_memguard_desc, sizeof(desc));
	error = sysctl_handle_string(oidp, desc, sizeof(desc), req);
	if (error != 0 || req->newptr == NULL)
		return (error);

	mtx_lock(&malloc_mtx);
	/* If mtp is NULL, it will be initialized in memguard_cmp() */
	vm_memguard_mtype = malloc_desc2type(desc);
	strlcpy(vm_memguard_desc, desc, sizeof(vm_memguard_desc));
	mtx_unlock(&malloc_mtx);
	return (error);
}
Example #12
0
static int
vmbus_br_sysctl_state(SYSCTL_HANDLER_ARGS)
{
	const struct vmbus_br *br = arg1;
	uint32_t rindex, windex, imask, ravail, wavail;
	char state[256];

	rindex = br->vbr_rindex;
	windex = br->vbr_windex;
	imask = br->vbr_imask;
	wavail = VMBUS_BR_WAVAIL(rindex, windex, br->vbr_dsize);
	ravail = br->vbr_dsize - wavail;

	snprintf(state, sizeof(state),
	    "rindex:%u windex:%u imask:%u ravail:%u wavail:%u",
	    rindex, windex, imask, ravail, wavail);
	return sysctl_handle_string(oidp, state, sizeof(state), req);
}
Example #13
0
static int
sysctl_debug_ktr_cpumask(SYSCTL_HANDLER_ARGS)
{
    char lktr_cpumask_str[CPUSETBUFSIZ];
    cpuset_t imask;
    int error;

    cpusetobj_strprint(lktr_cpumask_str, &ktr_cpumask);
    error = sysctl_handle_string(oidp, lktr_cpumask_str,
                                 sizeof(lktr_cpumask_str), req);
    if (error != 0 || req->newptr == NULL)
        return (error);
    if (cpusetobj_strscan(&imask, lktr_cpumask_str) == -1)
        return (EINVAL);
    CPU_COPY(&imask, &ktr_cpumask);

    return (error);
}
Example #14
0
static int kern_mib_hostname(SYSCTL_HANDLER_ARGS)
{
    char tmp_hostname[MAXHOSTNAMELEN + 1];
    int error;

    memcpy(tmp_hostname, hostname, sizeof(hostname));
    error = sysctl_handle_string(oidp, tmp_hostname, sizeof(tmp_hostname), req);
    if (!error && req->newptr) { /* Validate new hostname before setting it */
        size_t label_nch = 0;

        if (ka_isdigit(tmp_hostname[0]) || !ka_isalpha(tmp_hostname[0]))
            return EINVAL;

        for (size_t i = 0; i < sizeof(tmp_hostname); i++) {
            char c = tmp_hostname[i];

            if (c == '\0') {
                if (tmp_hostname[i - 1] == '-')
                    return EINVAL;
                break;
            }

            if (c == '.') {
                if (label_nch == 0)
                    return EINVAL;
                label_nch = 0;
                continue;
            }

            if (++label_nch > 63)
                return EINVAL;

            if (!(ka_isalnum(c) || (c == '-')))
                return EINVAL;

            if (i >= 253)
                return EINVAL;
        }

        memcpy(hostname, tmp_hostname, sizeof(tmp_hostname));
    }

    return error;
}
Example #15
0
static int
oce_sys_fwupgrade(SYSCTL_HANDLER_ARGS)
{
	char ufiname[256] = {0};
	uint32_t status = 1;
	struct oce_softc *sc  = (struct oce_softc *)arg1;
	const struct firmware *fw;

	status = sysctl_handle_string(oidp, ufiname, sizeof(ufiname), req);
	if (status || !req->newptr)
		return status;

	fw = firmware_get(ufiname);
	if (fw == NULL) {
		device_printf(sc->dev, "Unable to get Firmware. "
			"Make sure %s is copied to /boot/modules\n", ufiname);
		return ENOENT;
	}

	if (IS_BE(sc)) {
		if ((sc->flags & OCE_FLAGS_BE2)) {
			device_printf(sc->dev, 
				"Flashing not supported for BE2 yet.\n");
			status = 1;
			goto done;
		}
		status = oce_be3_fwupgrade(sc, fw);
	} else if (IS_SH(sc)) {
		status = oce_skyhawk_fwupgrade(sc,fw);
	} else
		status = oce_lancer_fwupgrade(sc, fw);
done:
	if (status) {
		device_printf(sc->dev, "Firmware Upgrade failed\n");
	} else {
		device_printf(sc->dev, "Firmware Flashed successfully\n");
	}

	/* Release Firmware*/
	firmware_put(fw, FIRMWARE_UNLOAD);

	return status;
}
Example #16
0
/*
 * debug.ddb.scripting.unscript has somewhat unusual sysctl semantics -- set
 * the name of the script that you want to delete.
 */
static int
sysctl_debug_ddb_scripting_unscript(SYSCTL_HANDLER_ARGS)
{
	char name[DB_MAXSCRIPTNAME];
	int error;

	bzero(name, sizeof(name));
	error = sysctl_handle_string(oidp, name, sizeof(name), req);
	if (error)
		return (error);
	if (req->newptr == NULL)
		return (0);
	mtx_lock(&db_script_mtx);
	error = db_script_unset(name);
	mtx_unlock(&db_script_mtx);
	if (error == ENOENT)
		return (EINVAL);	/* Don't confuse sysctl consumers. */
	return (0);
}
Example #17
0
static int
memguard_sysctl_desc(SYSCTL_HANDLER_ARGS)
{
	struct malloc_type_internal *mtip;
	struct malloc_type_stats *mtsp;
	struct malloc_type *mtp;
	char desc[128];
	long bytes;
	int error, i;

	strlcpy(desc, vm_memguard_desc, sizeof(desc));
	error = sysctl_handle_string(oidp, desc, sizeof(desc), req);
	if (error != 0 || req->newptr == NULL)
		return (error);

	/*
	 * We can change memory type when no memory has been allocated for it
	 * or when there is no such memory type yet (ie. it will be loaded with
	 * kernel module).
	 */
	bytes = 0;
	mtx_lock(&malloc_mtx);
	mtp = malloc_desc2type(desc);
	if (mtp != NULL) {
		mtip = mtp->ks_handle;
		for (i = 0; i < MAXCPU; i++) {
			mtsp = &mtip->mti_stats[i];
			bytes += mtsp->mts_memalloced;
			bytes -= mtsp->mts_memfreed;
		}
	}
	if (bytes > 0)
		error = EBUSY;
	else {
		/*
		 * If mtp is NULL, it will be initialized in memguard_cmp().
		 */
		vm_memguard_mtype = mtp;
		strlcpy(vm_memguard_desc, desc, sizeof(vm_memguard_desc));
	}
	mtx_unlock(&malloc_mtx);
	return (error);
}
Example #18
0
static int
sysctl_smb_server_proto(SYSCTL_HANDLER_ARGS)
{
	char proto[FNBUFSIZ_32];
	int error, new_proto, old_proto;

	old_proto = *(int *)oidp->oid_arg1;
	strlcpy(proto, smbproto2name(old_proto), sizeof(proto));

	error = sysctl_handle_string(oidp, proto, sizeof(proto), req);
	if (error == 0 && req->newptr != NULL) {
		new_proto = smbname2proto(proto);
		if (new_proto < CORE)
			return (EINVAL);
		if (new_proto != old_proto)
			*(int *)oidp->oid_arg1 = new_proto;
	}

	return (error);
}
Example #19
0
/*
 * This sysctl forces the kernel to enter the debugger.
 */
static int
sysctl_debug_enter_debugger(SYSCTL_HANDLER_ARGS)
{
	char dmode[64];
	int error;

	strncpy(dmode, READ_MODE, sizeof(dmode) - 1);
	dmode[sizeof(dmode) - 1] = '\0';
	error = sysctl_handle_string(oidp, &dmode[0], sizeof(dmode), req);

	if (error == 0 && req->newptr != NULL) {
		if (strcmp(dmode, MODE_DDB) == 0)
			boothowto &= ~RB_GDB;
		else if (strcmp(dmode, MODE_GDB) == 0)
			boothowto |= RB_GDB;
		else
			return EINVAL;
		Debugger("debug.enter_debugger");
	}
	return error;
}
Example #20
0
static int
linux_sysctl_debug(SYSCTL_HANDLER_ARGS)
{
	char value[LINUX_MAX_DEBUGSTR], *p;
	int error, sysc, toggle;
	int global = 0;

	value[0] = '\0';
	error = sysctl_handle_string(oidp, value, LINUX_MAX_DEBUGSTR, req);
	if (error || req->newptr == NULL)
		return (error);
	for (p = value; *p != '\0' && *p != '.'; p++);
	if (*p == '\0')
		return (EINVAL);
	*p++ = '\0';
	sysc = strtol(value, NULL, 0);
	toggle = strtol(p, NULL, 0);
	if (strcmp(value, "all") == 0)
		global = 1;
	error = linux_debug(sysc, toggle, global);
	return (error);
}
Example #21
0
static int
sysctl_kern_eventtimer_timer2(SYSCTL_HANDLER_ARGS)
{
	char buf[32];
	struct eventtimer *et;
	int error;

	ET_LOCK();
	et = timer[1];
	if (et == NULL)
		snprintf(buf, sizeof(buf), "NONE");
	else
		snprintf(buf, sizeof(buf), "%s", et->et_name);
	ET_UNLOCK();
	error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
	ET_LOCK();
	et = timer[1];
	if (error != 0 || req->newptr == NULL ||
	    strcmp(buf, et ? et->et_name : "NONE") == 0) {
		ET_UNLOCK();
		return (error);
	}
	et = et_find(buf, ET_FLAGS_PERIODIC, ET_FLAGS_PERIODIC);
	if (et == NULL && strcasecmp(buf, "NONE") != 0) {
		ET_UNLOCK();
		return (ENOENT);
	}
	if (timer[1] != NULL) {
		timer2hz = 0;
		configtimer(1);
		et_free(timer[1]);
	}
	timer[1] = et;
	if (timer[1] != NULL)
		et_init(timer[1], timer2cb, NULL, NULL);
	cpu_restartclocks();
	ET_UNLOCK();
	return (error);
}
Example #22
0
static int
acpi_cst_global_lowest_sysctl(SYSCTL_HANDLER_ARGS)
{
    struct	acpi_cst_softc *sc;
    char	state[8];
    int		val, error, i;

    ksnprintf(state, sizeof(state), "C%d", acpi_cst_cx_lowest_req + 1);
    error = sysctl_handle_string(oidp, state, sizeof(state), req);
    if (error != 0 || req->newptr == NULL)
	return (error);
    if (strlen(state) < 2 || toupper(state[0]) != 'C')
	return (EINVAL);
    val = (int) strtol(state + 1, NULL, 10) - 1;
    if (val < 0)
	return (EINVAL);

    lwkt_serialize_enter(&acpi_cst_slize);

    acpi_cst_cx_lowest_req = val;
    acpi_cst_cx_lowest = val;
    if (acpi_cst_cx_lowest > acpi_cst_cx_count - 1)
	acpi_cst_cx_lowest = acpi_cst_cx_count - 1;

    /* Update the new lowest useable Cx state for all CPUs. */
    for (i = 0; i < acpi_cst_ndevices; i++) {
	sc = device_get_softc(acpi_cst_devices[i]);
	error = acpi_cst_set_lowest(sc, val);
	if (error) {
	    KKASSERT(i == 0);
	    break;
	}
    }

    lwkt_serialize_exit(&acpi_cst_slize);

    return error;
}
Example #23
0
static int
acpi_cst_lowest_sysctl(SYSCTL_HANDLER_ARGS)
{
    struct	 acpi_cst_softc *sc;
    char	 state[8];
    int		 val, error;

    sc = (struct acpi_cst_softc *)arg1;
    ksnprintf(state, sizeof(state), "C%d", sc->cst_cx_lowest_req + 1);
    error = sysctl_handle_string(oidp, state, sizeof(state), req);
    if (error != 0 || req->newptr == NULL)
	return (error);
    if (strlen(state) < 2 || toupper(state[0]) != 'C')
	return (EINVAL);
    val = (int) strtol(state + 1, NULL, 10) - 1;
    if (val < 0)
	return (EINVAL);

    lwkt_serialize_enter(&acpi_cst_slize);
    error = acpi_cst_set_lowest(sc, val);
    lwkt_serialize_exit(&acpi_cst_slize);

    return error;
}
static int
acpi_cpu_cx_lowest_sysctl(SYSCTL_HANDLER_ARGS)
{
    struct	 acpi_cpu_softc *sc;
    char	 state[8];
    int		 val, error;

    sc = (struct acpi_cpu_softc *) arg1;
    snprintf(state, sizeof(state), "C%d", sc->cpu_cx_lowest + 1);
    error = sysctl_handle_string(oidp, state, sizeof(state), req);
    if (error != 0 || req->newptr == NULL)
	return (error);
    if (strlen(state) < 2 || toupper(state[0]) != 'C')
	return (EINVAL);
    val = (int) strtol(state + 1, NULL, 10) - 1;
    if (val < 0 || val > sc->cpu_cx_count - 1)
	return (EINVAL);

    ACPI_SERIAL_BEGIN(cpu);
    acpi_cpu_set_cx_lowest(sc, val);
    ACPI_SERIAL_END(cpu);

    return (0);
}