10Sstevel@tonic-gate /* 20Sstevel@tonic-gate * CDDL HEADER START 30Sstevel@tonic-gate * 40Sstevel@tonic-gate * The contents of this file are subject to the terms of the 53028Smh27603 * Common Development and Distribution License (the "License"). 63028Smh27603 * You may not use this file except in compliance with the License. 70Sstevel@tonic-gate * 80Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 90Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 100Sstevel@tonic-gate * See the License for the specific language governing permissions 110Sstevel@tonic-gate * and limitations under the License. 120Sstevel@tonic-gate * 130Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 140Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 150Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 160Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 170Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 180Sstevel@tonic-gate * 190Sstevel@tonic-gate * CDDL HEADER END 200Sstevel@tonic-gate */ 210Sstevel@tonic-gate /* 22*5295Srandyf * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 230Sstevel@tonic-gate * Use is subject to license terms. 240Sstevel@tonic-gate */ 250Sstevel@tonic-gate 260Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 270Sstevel@tonic-gate 280Sstevel@tonic-gate #include "pmconfig.h" 290Sstevel@tonic-gate #include <deflt.h> 300Sstevel@tonic-gate #include <pwd.h> 310Sstevel@tonic-gate 320Sstevel@tonic-gate #ifdef sparc 330Sstevel@tonic-gate #include <libdevinfo.h> 340Sstevel@tonic-gate static char sf_cmt[] = "# Statefile\t\tPath\n"; 350Sstevel@tonic-gate #endif 360Sstevel@tonic-gate 370Sstevel@tonic-gate static char as_cmt[] = 380Sstevel@tonic-gate "# Auto-Shutdown\t\tIdle(min)\tStart/Finish(hh:mm)\tBehavior\n"; 390Sstevel@tonic-gate 400Sstevel@tonic-gate char **line_args; 410Sstevel@tonic-gate int lineno = 0; 420Sstevel@tonic-gate 430Sstevel@tonic-gate /* 440Sstevel@tonic-gate * cpr and pm combined permission/update status 450Sstevel@tonic-gate */ 460Sstevel@tonic-gate prmup_t cpr_status = { 0, OKUP, "cpr" }; 470Sstevel@tonic-gate prmup_t pm_status = { 0, OKUP, "pm" }; 480Sstevel@tonic-gate 490Sstevel@tonic-gate 500Sstevel@tonic-gate /* 510Sstevel@tonic-gate * For config file parsing to work correctly/efficiently, this table 520Sstevel@tonic-gate * needs to be sorted by .keyword and any longer string like "device" 530Sstevel@tonic-gate * must appear before a substring like "dev". 540Sstevel@tonic-gate */ 550Sstevel@tonic-gate static cinfo_t conftab[] = { 56*5295Srandyf "S3-support", S3sup, &pm_status, NULL, 2, 0, 1, 57*5295Srandyf "autoS3", autoS3, &pm_status, NULL, 2, 0, 1, 580Sstevel@tonic-gate "autopm", autopm, &pm_status, NULL, 2, 0, 1, 590Sstevel@tonic-gate "autoshutdown", autosd, &cpr_status, as_cmt, 5, 0, 1, 603028Smh27603 "cpu-threshold", cputhr, &pm_status, NULL, 2, 0, 1, 613028Smh27603 "cpupm", cpupm, &pm_status, NULL, 2, 0, 1, 620Sstevel@tonic-gate "device-dependency-property", 630Sstevel@tonic-gate ddprop, &pm_status, NULL, 3, 1, 1, 640Sstevel@tonic-gate "device-dependency", devdep, &pm_status, NULL, 3, 1, 1, 650Sstevel@tonic-gate "device-thresholds", devthr, &pm_status, NULL, 3, 1, 1, 660Sstevel@tonic-gate "diskreads", dreads, &cpr_status, NULL, 2, 0, 1, 670Sstevel@tonic-gate "idlecheck", idlechk, &cpr_status, NULL, 2, 0, 0, 680Sstevel@tonic-gate "loadaverage", loadavg, &cpr_status, NULL, 2, 0, 1, 690Sstevel@tonic-gate "nfsreqs", nfsreq, &cpr_status, NULL, 2, 0, 1, 700Sstevel@tonic-gate #ifdef sparc 710Sstevel@tonic-gate "statefile", sfpath, &cpr_status, sf_cmt, 2, 0, 0, 720Sstevel@tonic-gate #endif 730Sstevel@tonic-gate "system-threshold", systhr, &pm_status, NULL, 2, 0, 1, 740Sstevel@tonic-gate "ttychars", tchars, &cpr_status, NULL, 2, 0, 1, 750Sstevel@tonic-gate NULL, NULL, NULL, NULL, 0, 0, 0, 760Sstevel@tonic-gate }; 770Sstevel@tonic-gate 780Sstevel@tonic-gate 790Sstevel@tonic-gate /* 800Sstevel@tonic-gate * Set cpr/pm permission from default file info. 810Sstevel@tonic-gate */ 820Sstevel@tonic-gate static void 830Sstevel@tonic-gate set_perm(char *defstr, char *user, int *perm, int cons) 840Sstevel@tonic-gate { 850Sstevel@tonic-gate char *dinfo, *tk; 860Sstevel@tonic-gate 870Sstevel@tonic-gate /* 880Sstevel@tonic-gate * /etc/default/power entries are: 890Sstevel@tonic-gate * all (all users + root) 900Sstevel@tonic-gate * - (none + root) 910Sstevel@tonic-gate * <user1[, user2...> (list users + root) 920Sstevel@tonic-gate * console-owner (console onwer + root) 930Sstevel@tonic-gate * Any error in reading/parsing the file limits the 940Sstevel@tonic-gate * access requirement to root. 950Sstevel@tonic-gate */ 960Sstevel@tonic-gate dinfo = defread(defstr); 970Sstevel@tonic-gate mesg(MDEBUG, "set_perm: \"%s\", value \"%s\"\n", 980Sstevel@tonic-gate defstr, dinfo ? dinfo : "NULL"); 990Sstevel@tonic-gate if (dinfo == NULL) 1000Sstevel@tonic-gate return; 1010Sstevel@tonic-gate else if (strcmp(dinfo, "all") == 0) 1020Sstevel@tonic-gate *perm = 1; 1030Sstevel@tonic-gate else if (strcmp(dinfo, "console-owner") == 0) 1040Sstevel@tonic-gate *perm = cons; 1050Sstevel@tonic-gate else if (user != NULL && 1060Sstevel@tonic-gate (*dinfo == '<') && (tk = strrchr(++dinfo, '>'))) { 1070Sstevel@tonic-gate /* Scan dinfo for a matching user. */ 1080Sstevel@tonic-gate for (*tk = '\0'; tk = strtok(dinfo, ", "); dinfo = NULL) { 1090Sstevel@tonic-gate mesg(MDEBUG, "match_user: cmp (\"%s\", \"%s\")\n", 1100Sstevel@tonic-gate tk, user); 1110Sstevel@tonic-gate if (strcmp(tk, user) == 0) { 1120Sstevel@tonic-gate *perm = 1; 1130Sstevel@tonic-gate break; 1140Sstevel@tonic-gate } 1150Sstevel@tonic-gate } 1160Sstevel@tonic-gate } 1170Sstevel@tonic-gate } 1180Sstevel@tonic-gate 1190Sstevel@tonic-gate 1200Sstevel@tonic-gate /* 1210Sstevel@tonic-gate * Lookup cpr/pm user permissions in "/etc/default/power". 1220Sstevel@tonic-gate */ 1230Sstevel@tonic-gate void 1240Sstevel@tonic-gate lookup_perms(void) 1250Sstevel@tonic-gate { 1260Sstevel@tonic-gate struct passwd *pent; 1270Sstevel@tonic-gate struct stat stbuf; 1280Sstevel@tonic-gate int cons_perm; 1290Sstevel@tonic-gate char *user; 1300Sstevel@tonic-gate 1310Sstevel@tonic-gate if ((ruid = getuid()) == 0) { 1320Sstevel@tonic-gate cpr_status.perm = pm_status.perm = 1; 1330Sstevel@tonic-gate return; 1340Sstevel@tonic-gate } else if ((pent = getpwuid(ruid)) != NULL) { 1350Sstevel@tonic-gate user = pent->pw_name; 1360Sstevel@tonic-gate } else { 1370Sstevel@tonic-gate user = NULL; 1380Sstevel@tonic-gate } 1390Sstevel@tonic-gate 1400Sstevel@tonic-gate if (defopen("/etc/default/power") == -1) 1410Sstevel@tonic-gate return; 1420Sstevel@tonic-gate if (stat("/dev/console", &stbuf) == -1) 1430Sstevel@tonic-gate cons_perm = 0; 1440Sstevel@tonic-gate else 1450Sstevel@tonic-gate cons_perm = (ruid == stbuf.st_uid); 1460Sstevel@tonic-gate 1470Sstevel@tonic-gate set_perm("PMCHANGEPERM=", user, &pm_status.perm, cons_perm); 1480Sstevel@tonic-gate set_perm("CPRCHANGEPERM=", user, &cpr_status.perm, cons_perm); 1490Sstevel@tonic-gate 1500Sstevel@tonic-gate (void) defopen(NULL); 1510Sstevel@tonic-gate } 1520Sstevel@tonic-gate 1530Sstevel@tonic-gate 1540Sstevel@tonic-gate #ifdef sparc 1550Sstevel@tonic-gate /* 1560Sstevel@tonic-gate * Lookup energystar-v[23] property and set estar_vers. 1570Sstevel@tonic-gate */ 1580Sstevel@tonic-gate void 1590Sstevel@tonic-gate lookup_estar_vers(void) 1600Sstevel@tonic-gate { 1610Sstevel@tonic-gate char es_prop[] = "energystar-v?", *fmt = "%s init/access error\n"; 1620Sstevel@tonic-gate di_prom_handle_t ph; 1630Sstevel@tonic-gate di_node_t node; 1640Sstevel@tonic-gate uchar_t *prop_data; 1650Sstevel@tonic-gate int last; 1660Sstevel@tonic-gate char ch; 1670Sstevel@tonic-gate 1680Sstevel@tonic-gate if ((node = di_init("/", DINFOPROP)) == DI_NODE_NIL) { 1690Sstevel@tonic-gate mesg(MERR, fmt, "di_init"); 1700Sstevel@tonic-gate return; 1710Sstevel@tonic-gate } else if ((ph = di_prom_init()) == DI_PROM_HANDLE_NIL) { 1720Sstevel@tonic-gate mesg(MERR, fmt, "di_prom_init"); 1730Sstevel@tonic-gate di_fini(node); 1740Sstevel@tonic-gate return; 1750Sstevel@tonic-gate } 1760Sstevel@tonic-gate last = strlen(es_prop) - 1; 1770Sstevel@tonic-gate for (ch = ESTAR_V2; ch <= ESTAR_V3; ch++) { 1780Sstevel@tonic-gate es_prop[last] = ch; 1790Sstevel@tonic-gate if (di_prom_prop_lookup_bytes(ph, node, 1800Sstevel@tonic-gate es_prop, &prop_data) == 0) { 1810Sstevel@tonic-gate mesg(MDEBUG, "get_estar_vers: %s prop found\n", 1820Sstevel@tonic-gate es_prop); 1830Sstevel@tonic-gate estar_vers = ch; 1840Sstevel@tonic-gate break; 1850Sstevel@tonic-gate } 1860Sstevel@tonic-gate } 1870Sstevel@tonic-gate di_prom_fini(ph); 1880Sstevel@tonic-gate di_fini(node); 1890Sstevel@tonic-gate } 1900Sstevel@tonic-gate #endif /* sparc */ 1910Sstevel@tonic-gate 1920Sstevel@tonic-gate 1930Sstevel@tonic-gate /* 1940Sstevel@tonic-gate * limit open() to the real user 1950Sstevel@tonic-gate */ 1960Sstevel@tonic-gate static int 1970Sstevel@tonic-gate pmc_open(char *name, int oflag) 1980Sstevel@tonic-gate { 1990Sstevel@tonic-gate uid_t euid; 2000Sstevel@tonic-gate int fd; 2010Sstevel@tonic-gate 2020Sstevel@tonic-gate euid = geteuid(); 2030Sstevel@tonic-gate if (seteuid(ruid) == -1) 2040Sstevel@tonic-gate mesg(MEXIT, "cannot reset euid to %d, %s\n", 2050Sstevel@tonic-gate ruid, strerror(errno)); 2060Sstevel@tonic-gate fd = open(name, oflag); 2070Sstevel@tonic-gate (void) seteuid(euid); 2080Sstevel@tonic-gate return (fd); 2090Sstevel@tonic-gate } 2100Sstevel@tonic-gate 2110Sstevel@tonic-gate 2120Sstevel@tonic-gate /* 2130Sstevel@tonic-gate * Alloc space and read a config file; caller needs to free the space. 2140Sstevel@tonic-gate */ 2150Sstevel@tonic-gate static char * 2160Sstevel@tonic-gate get_conf_data(char *name) 2170Sstevel@tonic-gate { 2180Sstevel@tonic-gate struct stat stbuf; 2190Sstevel@tonic-gate ssize_t nread; 2200Sstevel@tonic-gate size_t size; 2210Sstevel@tonic-gate char *buf; 2220Sstevel@tonic-gate int fd; 2230Sstevel@tonic-gate 2240Sstevel@tonic-gate if ((fd = pmc_open(name, O_RDONLY)) == -1) 2250Sstevel@tonic-gate mesg(MEXIT, "cannot open %s\n", name); 2260Sstevel@tonic-gate else if (fstat(fd, &stbuf) == -1) 2270Sstevel@tonic-gate mesg(MEXIT, "cannot stat %s\n", name); 2280Sstevel@tonic-gate size = (size_t)stbuf.st_size; 2290Sstevel@tonic-gate def_src = (stbuf.st_ino == def_info.st_ino && 2300Sstevel@tonic-gate stbuf.st_dev == def_info.st_dev); 2310Sstevel@tonic-gate if ((buf = malloc(size + 1)) == NULL) 2320Sstevel@tonic-gate mesg(MEXIT, "cannot allocate %u for \"%s\"\n", size + 1, name); 2330Sstevel@tonic-gate nread = read(fd, buf, size); 2340Sstevel@tonic-gate (void) close(fd); 2350Sstevel@tonic-gate if (nread != (ssize_t)size) 2360Sstevel@tonic-gate mesg(MEXIT, "read error, expect %u, got %d, file \"%s\"\n", 2370Sstevel@tonic-gate size, nread, name); 2380Sstevel@tonic-gate *(buf + size) = '\0'; 2390Sstevel@tonic-gate return (buf); 2400Sstevel@tonic-gate } 2410Sstevel@tonic-gate 2420Sstevel@tonic-gate 2430Sstevel@tonic-gate /* 2440Sstevel@tonic-gate * Add an arg to line_args, adding space if needed. 2450Sstevel@tonic-gate */ 2460Sstevel@tonic-gate static void 2470Sstevel@tonic-gate newarg(char *arg, int index) 2480Sstevel@tonic-gate { 2490Sstevel@tonic-gate static int alcnt; 2500Sstevel@tonic-gate size_t size; 2510Sstevel@tonic-gate 2520Sstevel@tonic-gate if ((index + 1) > alcnt) { 2530Sstevel@tonic-gate alcnt += 4; 2540Sstevel@tonic-gate size = alcnt * sizeof (*line_args); 2550Sstevel@tonic-gate if ((line_args = realloc(line_args, size)) == NULL) 2560Sstevel@tonic-gate mesg(MEXIT, "cannot alloc %u for line args\n", size); 2570Sstevel@tonic-gate } 2580Sstevel@tonic-gate *(line_args + index) = arg; 2590Sstevel@tonic-gate } 2600Sstevel@tonic-gate 2610Sstevel@tonic-gate 2620Sstevel@tonic-gate /* 2630Sstevel@tonic-gate * Convert blank-delimited words into an arg vector and return 2640Sstevel@tonic-gate * the arg count; character strings get null-terminated in place. 2650Sstevel@tonic-gate */ 2660Sstevel@tonic-gate static int 2670Sstevel@tonic-gate build_args(char *cline, char *tail) 2680Sstevel@tonic-gate { 2690Sstevel@tonic-gate extern int debug; 2700Sstevel@tonic-gate char **vec, *arg, *cp; 2710Sstevel@tonic-gate int cnt = 0; 2720Sstevel@tonic-gate 2730Sstevel@tonic-gate /* 2740Sstevel@tonic-gate * Search logic: look for "\\\n" as a continuation marker, 2750Sstevel@tonic-gate * treat any other "\\*" as ordinary arg data, scan until a 2760Sstevel@tonic-gate * white-space delimiter is found, and if the arg has length, 2770Sstevel@tonic-gate * null-terminate and save arg to line_args. The scan includes 2780Sstevel@tonic-gate * tail so the last arg is found without any special-case code. 2790Sstevel@tonic-gate */ 2800Sstevel@tonic-gate for (arg = cp = cline; cp <= tail; cp++) { 2810Sstevel@tonic-gate if (*cp == '\\') { 2820Sstevel@tonic-gate if (*(cp + 1) && *(cp + 1) != '\n') { 2830Sstevel@tonic-gate cp++; 2840Sstevel@tonic-gate continue; 2850Sstevel@tonic-gate } 2860Sstevel@tonic-gate } else if (strchr(" \t\n", *cp) == NULL) 2870Sstevel@tonic-gate continue; 2880Sstevel@tonic-gate if (cp - arg) { 2890Sstevel@tonic-gate *cp = '\0'; 2900Sstevel@tonic-gate newarg(arg, cnt++); 2910Sstevel@tonic-gate } 2920Sstevel@tonic-gate arg = cp + 1; 2930Sstevel@tonic-gate } 2940Sstevel@tonic-gate newarg(NULL, cnt); 2950Sstevel@tonic-gate 2960Sstevel@tonic-gate if (debug) { 2970Sstevel@tonic-gate mesg(MDEBUG, "\nline %d, found %d args:\n", lineno, cnt); 2980Sstevel@tonic-gate for (vec = line_args; *vec; vec++) 2990Sstevel@tonic-gate mesg(MDEBUG, " \"%s\"\n", *vec); 3000Sstevel@tonic-gate } 3010Sstevel@tonic-gate 3020Sstevel@tonic-gate return (cnt); 3030Sstevel@tonic-gate } 3040Sstevel@tonic-gate 3050Sstevel@tonic-gate 3060Sstevel@tonic-gate /* 3070Sstevel@tonic-gate * Match leading keyword from a conf line and 3080Sstevel@tonic-gate * return a reference to a config info struct. 3090Sstevel@tonic-gate */ 3100Sstevel@tonic-gate static cinfo_t * 3110Sstevel@tonic-gate get_cinfo(void) 3120Sstevel@tonic-gate { 3130Sstevel@tonic-gate cinfo_t *cip, *info = NULL; 3140Sstevel@tonic-gate char *keyword; 3150Sstevel@tonic-gate int chr_diff; 3160Sstevel@tonic-gate 3170Sstevel@tonic-gate /* 3180Sstevel@tonic-gate * Scan the config table for a matching keyword; since the table 3190Sstevel@tonic-gate * is sorted by keyword strings, a few optimizations can be done: 3200Sstevel@tonic-gate * first compare only the first byte of the keyword, skip any 3210Sstevel@tonic-gate * table string that starts with a lower ASCII value, compare the 3220Sstevel@tonic-gate * full string only when the first byte matches, and stop checking 3230Sstevel@tonic-gate * if the table string starts with a higher ASCII value. 3240Sstevel@tonic-gate */ 3250Sstevel@tonic-gate keyword = LINEARG(0); 3260Sstevel@tonic-gate for (cip = conftab; cip->keyword; cip++) { 3270Sstevel@tonic-gate chr_diff = (int)(*cip->keyword - *keyword); 3280Sstevel@tonic-gate #if 0 3290Sstevel@tonic-gate mesg(MDEBUG, "line %d, ('%c' - '%c') = %d\n", 3300Sstevel@tonic-gate lineno, *cip->keyword, *line, chr_diff); 3310Sstevel@tonic-gate #endif 3320Sstevel@tonic-gate if (chr_diff < 0) 3330Sstevel@tonic-gate continue; 3340Sstevel@tonic-gate else if (chr_diff == 0) { 3350Sstevel@tonic-gate if (strcmp(keyword, cip->keyword) == 0) { 3360Sstevel@tonic-gate info = cip; 3370Sstevel@tonic-gate break; 3380Sstevel@tonic-gate } 3390Sstevel@tonic-gate } else 3400Sstevel@tonic-gate break; 3410Sstevel@tonic-gate } 3420Sstevel@tonic-gate return (info); 3430Sstevel@tonic-gate } 3440Sstevel@tonic-gate 3450Sstevel@tonic-gate 3460Sstevel@tonic-gate /* 3470Sstevel@tonic-gate * Find the end of a [possibly continued] conf line 3480Sstevel@tonic-gate * and record the real/lf-delimited line count at *lcnt. 3490Sstevel@tonic-gate */ 3500Sstevel@tonic-gate static char * 3510Sstevel@tonic-gate find_line_end(char *line, int *lcnt) 3520Sstevel@tonic-gate { 3530Sstevel@tonic-gate char *next, *lf; 3540Sstevel@tonic-gate 3550Sstevel@tonic-gate *lcnt = 0; 3560Sstevel@tonic-gate next = line; 3570Sstevel@tonic-gate while (lf = strchr(next, '\n')) { 3580Sstevel@tonic-gate (*lcnt)++; 3590Sstevel@tonic-gate if (lf == line || (*(lf - 1) != '\\') || *(lf + 1) == '\0') 3600Sstevel@tonic-gate break; 3610Sstevel@tonic-gate next = lf + 1; 3620Sstevel@tonic-gate } 3630Sstevel@tonic-gate return (lf); 3640Sstevel@tonic-gate } 3650Sstevel@tonic-gate 3660Sstevel@tonic-gate 3670Sstevel@tonic-gate /* 3680Sstevel@tonic-gate * Parse the named conf file and for each conf line 3690Sstevel@tonic-gate * call the action routine or conftab handler routine. 3700Sstevel@tonic-gate */ 3710Sstevel@tonic-gate void 3720Sstevel@tonic-gate parse_conf_file(char *name, vact_t action) 3730Sstevel@tonic-gate { 3740Sstevel@tonic-gate char *file_buf, *cline, *line, *lend; 3750Sstevel@tonic-gate cinfo_t *cip; 3760Sstevel@tonic-gate int linc, cnt; 3770Sstevel@tonic-gate size_t llen; 378*5295Srandyf int dontcare; 379*5295Srandyf 380*5295Srandyf /* 381*5295Srandyf * Do the "implied default" for autoS3 382*5295Srandyf */ 383*5295Srandyf (void) S3_helper("S3-support-enable", "S3-support-disable", 384*5295Srandyf PM_ENABLE_S3, PM_DISABLE_S3, "S3-support", "default", 385*5295Srandyf &dontcare, -1); 3860Sstevel@tonic-gate 3870Sstevel@tonic-gate file_buf = get_conf_data(name); 3880Sstevel@tonic-gate mesg(MDEBUG, "\nnow parsing \"%s\"...\n", name); 3890Sstevel@tonic-gate 3900Sstevel@tonic-gate lineno = 1; 3910Sstevel@tonic-gate line = file_buf; 3920Sstevel@tonic-gate while (lend = find_line_end(line, &linc)) { 3930Sstevel@tonic-gate /* 3940Sstevel@tonic-gate * Each line should start with valid data 3950Sstevel@tonic-gate * but leading white-space can be ignored 3960Sstevel@tonic-gate */ 3970Sstevel@tonic-gate while (line < lend) { 3980Sstevel@tonic-gate if (*line != ' ' && *line != '\t') 3990Sstevel@tonic-gate break; 4000Sstevel@tonic-gate line++; 4010Sstevel@tonic-gate } 4020Sstevel@tonic-gate 4030Sstevel@tonic-gate /* 4040Sstevel@tonic-gate * Copy line into allocated space and null-terminate 4050Sstevel@tonic-gate * without the trailing line-feed. 4060Sstevel@tonic-gate */ 4070Sstevel@tonic-gate if ((llen = (lend - line)) != 0) { 4080Sstevel@tonic-gate if ((cline = malloc(llen + 1)) == NULL) 4090Sstevel@tonic-gate mesg(MEXIT, "cannot alloc %u bytes " 4100Sstevel@tonic-gate "for line copy\n", llen); 4110Sstevel@tonic-gate (void) memcpy(cline, line, llen); 4120Sstevel@tonic-gate *(cline + llen) = '\0'; 4130Sstevel@tonic-gate } else 4140Sstevel@tonic-gate cline = NULL; 4150Sstevel@tonic-gate 4160Sstevel@tonic-gate /* 4170Sstevel@tonic-gate * For blank and comment lines: possibly show a debug 4180Sstevel@tonic-gate * message and otherwise ignore them. For other lines: 4190Sstevel@tonic-gate * parse into an arg vector and try to match the first 4200Sstevel@tonic-gate * arg with conftab keywords. When a match is found, 4210Sstevel@tonic-gate * check for exact or minimum arg count, and call the 4220Sstevel@tonic-gate * action or handler routine; if handler does not return 4230Sstevel@tonic-gate * OKUP, set the referenced update value to NOUP so that 4240Sstevel@tonic-gate * later CPR or PM updates are skipped. 4250Sstevel@tonic-gate */ 4260Sstevel@tonic-gate if (llen == 0) 4270Sstevel@tonic-gate mesg(MDEBUG, "\nline %d, blank...\n", lineno); 4280Sstevel@tonic-gate else if (*line == '#') 4290Sstevel@tonic-gate mesg(MDEBUG, "\nline %d, comment...\n", lineno); 4300Sstevel@tonic-gate else if (cnt = build_args(cline, cline + llen)) { 4310Sstevel@tonic-gate if ((cip = get_cinfo()) == NULL) { 4320Sstevel@tonic-gate mesg(MEXIT, "unrecognized keyword \"%s\"\n", 4330Sstevel@tonic-gate LINEARG(0)); 4340Sstevel@tonic-gate } else if (cnt != cip->argc && 4350Sstevel@tonic-gate (cip->any == 0 || cnt < cip->argc)) { 4360Sstevel@tonic-gate mesg(MEXIT, "found %d args, expect %d%s\n", 4370Sstevel@tonic-gate cnt, cip->argc, cip->any ? "+" : ""); 4380Sstevel@tonic-gate } else if (action) 4390Sstevel@tonic-gate (*action)(line, llen + 1, cip); 4400Sstevel@tonic-gate else if (cip->status->perm && (def_src || cip->alt)) { 4410Sstevel@tonic-gate if ((*cip->handler)() != OKUP) 4420Sstevel@tonic-gate cip->status->update = NOUP; 4430Sstevel@tonic-gate } else { 4440Sstevel@tonic-gate mesg(MDEBUG, 4450Sstevel@tonic-gate "==> handler skipped: %s_perm %d, " 4460Sstevel@tonic-gate "def_src %d, alt %d\n", cip->status->set, 4470Sstevel@tonic-gate cip->status->perm, def_src, cip->alt); 4480Sstevel@tonic-gate } 4490Sstevel@tonic-gate } 4500Sstevel@tonic-gate 4510Sstevel@tonic-gate if (cline) 4520Sstevel@tonic-gate free(cline); 4530Sstevel@tonic-gate line = lend + 1; 4540Sstevel@tonic-gate lineno += linc; 4550Sstevel@tonic-gate } 4560Sstevel@tonic-gate lineno = 0; 4570Sstevel@tonic-gate 4580Sstevel@tonic-gate free(file_buf); 459*5295Srandyf 460*5295Srandyf if (verify) { 461*5295Srandyf int ret = ioctl(pm_fd, PM_GET_PM_STATE, NULL); 462*5295Srandyf if (ret < 0) { 463*5295Srandyf mesg(MDEBUG, "Cannot get PM state: %s\n", 464*5295Srandyf strerror(errno)); 465*5295Srandyf } 466*5295Srandyf switch (ret) { 467*5295Srandyf case PM_SYSTEM_PM_ENABLED: 468*5295Srandyf mesg(MDEBUG, "Autopm Enabled\n"); 469*5295Srandyf break; 470*5295Srandyf case PM_SYSTEM_PM_DISABLED: 471*5295Srandyf mesg(MDEBUG, "Autopm Disabled\n"); 472*5295Srandyf break; 473*5295Srandyf } 474*5295Srandyf ret = ioctl(pm_fd, PM_GET_S3_SUPPORT_STATE, NULL); 475*5295Srandyf if (ret < 0) { 476*5295Srandyf mesg(MDEBUG, "Cannot get PM state: %s\n", 477*5295Srandyf strerror(errno)); 478*5295Srandyf } 479*5295Srandyf switch (ret) { 480*5295Srandyf case PM_S3_SUPPORT_ENABLED: 481*5295Srandyf mesg(MDEBUG, "S3 support Enabled\n"); 482*5295Srandyf break; 483*5295Srandyf case PM_S3_SUPPORT_DISABLED: 484*5295Srandyf mesg(MDEBUG, "S3 support Disabled\n"); 485*5295Srandyf break; 486*5295Srandyf } 487*5295Srandyf ret = ioctl(pm_fd, PM_GET_AUTOS3_STATE, NULL); 488*5295Srandyf if (ret < 0) { 489*5295Srandyf mesg(MDEBUG, "Cannot get PM state: %s\n", 490*5295Srandyf strerror(errno)); 491*5295Srandyf } 492*5295Srandyf switch (ret) { 493*5295Srandyf case PM_AUTOS3_ENABLED: 494*5295Srandyf mesg(MDEBUG, "AutoS3 Enabled\n"); 495*5295Srandyf break; 496*5295Srandyf case PM_AUTOS3_DISABLED: 497*5295Srandyf mesg(MDEBUG, "AutoS3 Disabled\n"); 498*5295Srandyf break; 499*5295Srandyf } 500*5295Srandyf } 5010Sstevel@tonic-gate } 502