From 8a3ebab50de301cb294dc75a255eaace72149010 Mon Sep 17 00:00:00 2001 From: "Constantine A. Murenin" Date: Wed, 10 Feb 2010 20:06:53 -0500 Subject: [PATCH] sysctl(8): support setting acpi temperature in K, C and F Obtained-from: FreeBSD (sysctl.c#rev1.94) --- sbin/sysctl/sysctl.c | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/sbin/sysctl/sysctl.c b/sbin/sysctl/sysctl.c index 3e1fdbb94b..f26613f4d9 100644 --- a/sbin/sysctl/sysctl.c +++ b/sbin/sysctl/sysctl.c @@ -64,6 +64,7 @@ static void parse(const char *); static int show_var(int *, size_t); static int sysctl_all(int *, size_t); static void set_T_dev_t(const char *, void **, size_t *); +static int set_IK(const char *, int *); static void usage(void) @@ -206,7 +207,12 @@ parse(const char *string) switch (kind & CTLTYPE) { case CTLTYPE_INT: - intval = (int) strtol(newval, NULL, 0); + if (!strcmp(fmt, "IK") == 0) { + if (!set_IK(newval, &intval)) + errx(1, "invalid value '%s'", + (char *)newval); + } else + intval = (int) strtol(newval, NULL, 0); newval = &intval; newsize = sizeof(intval); break; @@ -528,6 +534,33 @@ set_T_dev_t(const char *path, void **val, size_t *size) *size = sizeof statb.st_rdev; } +static int +set_IK(const char *str, int *val) +{ + float temp; + int len, kelv; + const char *p; + char *endptr; + + if ((len = strlen(str)) == 0) + return (0); + p = &str[len - 1]; + if (*p == 'C' || *p == 'F') { + temp = strtof(str, &endptr); + if (endptr == str || endptr != p) + return 0; + if (*p == 'F') + temp = (temp - 32) * 5 / 9; + kelv = temp * 10 + 2732; + } else { + kelv = (int)strtol(str, &endptr, 10); + if (endptr == str || *endptr != '\0') + return 0; + } + *val = kelv; + return 1; +} + /* * These functions uses a presently undocumented interface to the kernel * to walk the tree and get the type so it can print the value. -- 2.11.4.GIT