1*7c478bd9Sstevel@tonic-gate /*
2*7c478bd9Sstevel@tonic-gate * CDDL HEADER START
3*7c478bd9Sstevel@tonic-gate *
4*7c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*7c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*7c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*7c478bd9Sstevel@tonic-gate * with the License.
8*7c478bd9Sstevel@tonic-gate *
9*7c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*7c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*7c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions
12*7c478bd9Sstevel@tonic-gate * and limitations under the License.
13*7c478bd9Sstevel@tonic-gate *
14*7c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*7c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*7c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*7c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*7c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*7c478bd9Sstevel@tonic-gate *
20*7c478bd9Sstevel@tonic-gate * CDDL HEADER END
21*7c478bd9Sstevel@tonic-gate */
22*7c478bd9Sstevel@tonic-gate /*
23*7c478bd9Sstevel@tonic-gate * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
24*7c478bd9Sstevel@tonic-gate * Use is subject to license terms.
25*7c478bd9Sstevel@tonic-gate */
26*7c478bd9Sstevel@tonic-gate
27*7c478bd9Sstevel@tonic-gate /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*7c478bd9Sstevel@tonic-gate /* All Rights Reserved */
29*7c478bd9Sstevel@tonic-gate
30*7c478bd9Sstevel@tonic-gate #include <stdio.h>
31*7c478bd9Sstevel@tonic-gate #include <stdlib.h>
32*7c478bd9Sstevel@tonic-gate #include <string.h>
33*7c478bd9Sstevel@tonic-gate #include <unistd.h>
34*7c478bd9Sstevel@tonic-gate #include <errno.h>
35*7c478bd9Sstevel@tonic-gate #include <sys/types.h>
36*7c478bd9Sstevel@tonic-gate #include <sys/priocntl.h>
37*7c478bd9Sstevel@tonic-gate #include <sys/tspriocntl.h>
38*7c478bd9Sstevel@tonic-gate #include <sys/param.h>
39*7c478bd9Sstevel@tonic-gate #include <sys/ts.h>
40*7c478bd9Sstevel@tonic-gate
41*7c478bd9Sstevel@tonic-gate #include "dispadmin.h"
42*7c478bd9Sstevel@tonic-gate
43*7c478bd9Sstevel@tonic-gate /*
44*7c478bd9Sstevel@tonic-gate * This file contains the class specific code implementing
45*7c478bd9Sstevel@tonic-gate * the time-sharing dispadmin sub-command.
46*7c478bd9Sstevel@tonic-gate */
47*7c478bd9Sstevel@tonic-gate
48*7c478bd9Sstevel@tonic-gate #define BASENMSZ 16
49*7c478bd9Sstevel@tonic-gate
50*7c478bd9Sstevel@tonic-gate extern char *basename();
51*7c478bd9Sstevel@tonic-gate
52*7c478bd9Sstevel@tonic-gate static void get_tsdptbl(), set_tsdptbl();
53*7c478bd9Sstevel@tonic-gate
54*7c478bd9Sstevel@tonic-gate static char usage[] =
55*7c478bd9Sstevel@tonic-gate "usage: dispadmin -l\n\
56*7c478bd9Sstevel@tonic-gate dispadmin -c TS -g [-r res]\n\
57*7c478bd9Sstevel@tonic-gate dispadmin -c TS -s infile\n";
58*7c478bd9Sstevel@tonic-gate
59*7c478bd9Sstevel@tonic-gate static char basenm[BASENMSZ];
60*7c478bd9Sstevel@tonic-gate static char cmdpath[256];
61*7c478bd9Sstevel@tonic-gate
62*7c478bd9Sstevel@tonic-gate
63*7c478bd9Sstevel@tonic-gate int
main(int argc,char ** argv)64*7c478bd9Sstevel@tonic-gate main(int argc, char **argv)
65*7c478bd9Sstevel@tonic-gate {
66*7c478bd9Sstevel@tonic-gate extern char *optarg;
67*7c478bd9Sstevel@tonic-gate
68*7c478bd9Sstevel@tonic-gate int c;
69*7c478bd9Sstevel@tonic-gate int lflag, gflag, rflag, sflag;
70*7c478bd9Sstevel@tonic-gate ulong_t res;
71*7c478bd9Sstevel@tonic-gate char *infile;
72*7c478bd9Sstevel@tonic-gate
73*7c478bd9Sstevel@tonic-gate (void) strcpy(cmdpath, argv[0]);
74*7c478bd9Sstevel@tonic-gate (void) strcpy(basenm, basename(argv[0]));
75*7c478bd9Sstevel@tonic-gate lflag = gflag = rflag = sflag = 0;
76*7c478bd9Sstevel@tonic-gate while ((c = getopt(argc, argv, "lc:gr:s:")) != -1) {
77*7c478bd9Sstevel@tonic-gate switch (c) {
78*7c478bd9Sstevel@tonic-gate
79*7c478bd9Sstevel@tonic-gate case 'l':
80*7c478bd9Sstevel@tonic-gate lflag++;
81*7c478bd9Sstevel@tonic-gate break;
82*7c478bd9Sstevel@tonic-gate
83*7c478bd9Sstevel@tonic-gate case 'c':
84*7c478bd9Sstevel@tonic-gate if (strcmp(optarg, "TS") != 0)
85*7c478bd9Sstevel@tonic-gate fatalerr("error: %s executed for %s class, \
86*7c478bd9Sstevel@tonic-gate %s is actually sub-command for TS class\n", cmdpath, optarg, cmdpath);
87*7c478bd9Sstevel@tonic-gate break;
88*7c478bd9Sstevel@tonic-gate
89*7c478bd9Sstevel@tonic-gate case 'g':
90*7c478bd9Sstevel@tonic-gate gflag++;
91*7c478bd9Sstevel@tonic-gate break;
92*7c478bd9Sstevel@tonic-gate
93*7c478bd9Sstevel@tonic-gate case 'r':
94*7c478bd9Sstevel@tonic-gate rflag++;
95*7c478bd9Sstevel@tonic-gate res = strtoul(optarg, (char **)NULL, 10);
96*7c478bd9Sstevel@tonic-gate break;
97*7c478bd9Sstevel@tonic-gate
98*7c478bd9Sstevel@tonic-gate case 's':
99*7c478bd9Sstevel@tonic-gate sflag++;
100*7c478bd9Sstevel@tonic-gate infile = optarg;
101*7c478bd9Sstevel@tonic-gate break;
102*7c478bd9Sstevel@tonic-gate
103*7c478bd9Sstevel@tonic-gate case '?':
104*7c478bd9Sstevel@tonic-gate fatalerr(usage);
105*7c478bd9Sstevel@tonic-gate
106*7c478bd9Sstevel@tonic-gate default:
107*7c478bd9Sstevel@tonic-gate break;
108*7c478bd9Sstevel@tonic-gate }
109*7c478bd9Sstevel@tonic-gate }
110*7c478bd9Sstevel@tonic-gate
111*7c478bd9Sstevel@tonic-gate if (lflag) {
112*7c478bd9Sstevel@tonic-gate if (gflag || rflag || sflag)
113*7c478bd9Sstevel@tonic-gate fatalerr(usage);
114*7c478bd9Sstevel@tonic-gate
115*7c478bd9Sstevel@tonic-gate (void) printf("TS\t(Time Sharing)\n");
116*7c478bd9Sstevel@tonic-gate return (0);
117*7c478bd9Sstevel@tonic-gate
118*7c478bd9Sstevel@tonic-gate } else if (gflag) {
119*7c478bd9Sstevel@tonic-gate if (lflag || sflag)
120*7c478bd9Sstevel@tonic-gate fatalerr(usage);
121*7c478bd9Sstevel@tonic-gate
122*7c478bd9Sstevel@tonic-gate if (rflag == 0)
123*7c478bd9Sstevel@tonic-gate res = 1000;
124*7c478bd9Sstevel@tonic-gate
125*7c478bd9Sstevel@tonic-gate get_tsdptbl(res);
126*7c478bd9Sstevel@tonic-gate return (0);
127*7c478bd9Sstevel@tonic-gate
128*7c478bd9Sstevel@tonic-gate } else if (sflag) {
129*7c478bd9Sstevel@tonic-gate if (lflag || gflag || rflag)
130*7c478bd9Sstevel@tonic-gate fatalerr(usage);
131*7c478bd9Sstevel@tonic-gate
132*7c478bd9Sstevel@tonic-gate set_tsdptbl(infile);
133*7c478bd9Sstevel@tonic-gate return (0);
134*7c478bd9Sstevel@tonic-gate
135*7c478bd9Sstevel@tonic-gate } else {
136*7c478bd9Sstevel@tonic-gate fatalerr(usage);
137*7c478bd9Sstevel@tonic-gate }
138*7c478bd9Sstevel@tonic-gate return (1);
139*7c478bd9Sstevel@tonic-gate }
140*7c478bd9Sstevel@tonic-gate
141*7c478bd9Sstevel@tonic-gate
142*7c478bd9Sstevel@tonic-gate /*
143*7c478bd9Sstevel@tonic-gate * Retrieve the current ts_dptbl from memory, convert the time quantum
144*7c478bd9Sstevel@tonic-gate * values to the resolution specified by res and write the table to stdout.
145*7c478bd9Sstevel@tonic-gate */
146*7c478bd9Sstevel@tonic-gate static void
get_tsdptbl(ulong_t res)147*7c478bd9Sstevel@tonic-gate get_tsdptbl(ulong_t res)
148*7c478bd9Sstevel@tonic-gate {
149*7c478bd9Sstevel@tonic-gate int i;
150*7c478bd9Sstevel@tonic-gate int tsdpsz;
151*7c478bd9Sstevel@tonic-gate pcinfo_t pcinfo;
152*7c478bd9Sstevel@tonic-gate pcadmin_t pcadmin;
153*7c478bd9Sstevel@tonic-gate tsadmin_t tsadmin;
154*7c478bd9Sstevel@tonic-gate tsdpent_t *ts_dptbl;
155*7c478bd9Sstevel@tonic-gate hrtimer_t hrtime;
156*7c478bd9Sstevel@tonic-gate
157*7c478bd9Sstevel@tonic-gate (void) strcpy(pcinfo.pc_clname, "TS");
158*7c478bd9Sstevel@tonic-gate if (priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo) == -1)
159*7c478bd9Sstevel@tonic-gate fatalerr("%s: Can't get TS class ID, priocntl system \
160*7c478bd9Sstevel@tonic-gate call failed with errno %d\n", basenm, errno);
161*7c478bd9Sstevel@tonic-gate
162*7c478bd9Sstevel@tonic-gate pcadmin.pc_cid = pcinfo.pc_cid;
163*7c478bd9Sstevel@tonic-gate pcadmin.pc_cladmin = (char *)&tsadmin;
164*7c478bd9Sstevel@tonic-gate tsadmin.ts_cmd = TS_GETDPSIZE;
165*7c478bd9Sstevel@tonic-gate
166*7c478bd9Sstevel@tonic-gate if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1)
167*7c478bd9Sstevel@tonic-gate fatalerr("%s: Can't get ts_dptbl size, priocntl system \
168*7c478bd9Sstevel@tonic-gate call failed with errno %d\n", basenm, errno);
169*7c478bd9Sstevel@tonic-gate
170*7c478bd9Sstevel@tonic-gate tsdpsz = tsadmin.ts_ndpents * sizeof (tsdpent_t);
171*7c478bd9Sstevel@tonic-gate if ((ts_dptbl = (tsdpent_t *)malloc(tsdpsz)) == NULL)
172*7c478bd9Sstevel@tonic-gate fatalerr("%s: Can't allocate memory for ts_dptbl\n", basenm);
173*7c478bd9Sstevel@tonic-gate
174*7c478bd9Sstevel@tonic-gate tsadmin.ts_dpents = ts_dptbl;
175*7c478bd9Sstevel@tonic-gate
176*7c478bd9Sstevel@tonic-gate tsadmin.ts_cmd = TS_GETDPTBL;
177*7c478bd9Sstevel@tonic-gate if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1)
178*7c478bd9Sstevel@tonic-gate fatalerr("%s: Can't get ts_dptbl, priocntl system call \
179*7c478bd9Sstevel@tonic-gate call failed with errno %d\n", basenm, errno);
180*7c478bd9Sstevel@tonic-gate
181*7c478bd9Sstevel@tonic-gate (void) printf("# Time Sharing Dispatcher Configuration\n");
182*7c478bd9Sstevel@tonic-gate (void) printf("RES=%ld\n\n", res);
183*7c478bd9Sstevel@tonic-gate (void) printf("# ts_quantum ts_tqexp ts_slpret ts_maxwait ts_lwait \
184*7c478bd9Sstevel@tonic-gate PRIORITY LEVEL\n");
185*7c478bd9Sstevel@tonic-gate
186*7c478bd9Sstevel@tonic-gate for (i = 0; i < tsadmin.ts_ndpents; i++) {
187*7c478bd9Sstevel@tonic-gate if (res != HZ) {
188*7c478bd9Sstevel@tonic-gate hrtime.hrt_secs = 0;
189*7c478bd9Sstevel@tonic-gate hrtime.hrt_rem = ts_dptbl[i].ts_quantum;
190*7c478bd9Sstevel@tonic-gate hrtime.hrt_res = HZ;
191*7c478bd9Sstevel@tonic-gate if (_hrtnewres(&hrtime, res, HRT_RNDUP) == -1)
192*7c478bd9Sstevel@tonic-gate fatalerr("%s: Can't convert to requested \
193*7c478bd9Sstevel@tonic-gate resolution\n", basenm);
194*7c478bd9Sstevel@tonic-gate if ((ts_dptbl[i].ts_quantum = hrtconvert(&hrtime))
195*7c478bd9Sstevel@tonic-gate == -1)
196*7c478bd9Sstevel@tonic-gate fatalerr("%s: Can't express time quantum in "
197*7c478bd9Sstevel@tonic-gate "requested resolution,\n"
198*7c478bd9Sstevel@tonic-gate "try coarser resolution\n", basenm);
199*7c478bd9Sstevel@tonic-gate }
200*7c478bd9Sstevel@tonic-gate (void) printf("%10d%10d%10d%12d%10d # %3d\n",
201*7c478bd9Sstevel@tonic-gate ts_dptbl[i].ts_quantum, ts_dptbl[i].ts_tqexp,
202*7c478bd9Sstevel@tonic-gate ts_dptbl[i].ts_slpret, ts_dptbl[i].ts_maxwait,
203*7c478bd9Sstevel@tonic-gate ts_dptbl[i].ts_lwait, i);
204*7c478bd9Sstevel@tonic-gate }
205*7c478bd9Sstevel@tonic-gate }
206*7c478bd9Sstevel@tonic-gate
207*7c478bd9Sstevel@tonic-gate
208*7c478bd9Sstevel@tonic-gate /*
209*7c478bd9Sstevel@tonic-gate * Read the ts_dptbl values from infile, convert the time quantum values
210*7c478bd9Sstevel@tonic-gate * to HZ resolution, do a little sanity checking and overwrite the table
211*7c478bd9Sstevel@tonic-gate * in memory with the values from the file.
212*7c478bd9Sstevel@tonic-gate */
213*7c478bd9Sstevel@tonic-gate static void
set_tsdptbl(infile)214*7c478bd9Sstevel@tonic-gate set_tsdptbl(infile)
215*7c478bd9Sstevel@tonic-gate char *infile;
216*7c478bd9Sstevel@tonic-gate {
217*7c478bd9Sstevel@tonic-gate int i;
218*7c478bd9Sstevel@tonic-gate int ntsdpents;
219*7c478bd9Sstevel@tonic-gate char *tokp;
220*7c478bd9Sstevel@tonic-gate pcinfo_t pcinfo;
221*7c478bd9Sstevel@tonic-gate pcadmin_t pcadmin;
222*7c478bd9Sstevel@tonic-gate tsadmin_t tsadmin;
223*7c478bd9Sstevel@tonic-gate tsdpent_t *ts_dptbl;
224*7c478bd9Sstevel@tonic-gate int linenum;
225*7c478bd9Sstevel@tonic-gate ulong_t res;
226*7c478bd9Sstevel@tonic-gate hrtimer_t hrtime;
227*7c478bd9Sstevel@tonic-gate FILE *fp;
228*7c478bd9Sstevel@tonic-gate char buf[512];
229*7c478bd9Sstevel@tonic-gate int wslength;
230*7c478bd9Sstevel@tonic-gate
231*7c478bd9Sstevel@tonic-gate (void) strcpy(pcinfo.pc_clname, "TS");
232*7c478bd9Sstevel@tonic-gate if (priocntl(0, 0, PC_GETCID, (caddr_t)&pcinfo) == -1)
233*7c478bd9Sstevel@tonic-gate fatalerr("%s: Can't get TS class ID, priocntl system \
234*7c478bd9Sstevel@tonic-gate call failed with errno %d\n", basenm, errno);
235*7c478bd9Sstevel@tonic-gate
236*7c478bd9Sstevel@tonic-gate pcadmin.pc_cid = pcinfo.pc_cid;
237*7c478bd9Sstevel@tonic-gate pcadmin.pc_cladmin = (char *)&tsadmin;
238*7c478bd9Sstevel@tonic-gate tsadmin.ts_cmd = TS_GETDPSIZE;
239*7c478bd9Sstevel@tonic-gate
240*7c478bd9Sstevel@tonic-gate if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1)
241*7c478bd9Sstevel@tonic-gate fatalerr("%s: Can't get ts_dptbl size, priocntl system \
242*7c478bd9Sstevel@tonic-gate call failed with errno %d\n", basenm, errno);
243*7c478bd9Sstevel@tonic-gate
244*7c478bd9Sstevel@tonic-gate ntsdpents = tsadmin.ts_ndpents;
245*7c478bd9Sstevel@tonic-gate if ((ts_dptbl =
246*7c478bd9Sstevel@tonic-gate (tsdpent_t *)malloc(ntsdpents * sizeof (tsdpent_t))) == NULL)
247*7c478bd9Sstevel@tonic-gate fatalerr("%s: Can't allocate memory for ts_dptbl\n", basenm);
248*7c478bd9Sstevel@tonic-gate
249*7c478bd9Sstevel@tonic-gate if ((fp = fopen(infile, "r")) == NULL)
250*7c478bd9Sstevel@tonic-gate fatalerr("%s: Can't open %s for input\n", basenm, infile);
251*7c478bd9Sstevel@tonic-gate
252*7c478bd9Sstevel@tonic-gate linenum = 0;
253*7c478bd9Sstevel@tonic-gate
254*7c478bd9Sstevel@tonic-gate /*
255*7c478bd9Sstevel@tonic-gate * Find the first non-blank, non-comment line. A comment line
256*7c478bd9Sstevel@tonic-gate * is any line with '#' as the first non-white-space character.
257*7c478bd9Sstevel@tonic-gate */
258*7c478bd9Sstevel@tonic-gate do {
259*7c478bd9Sstevel@tonic-gate if (fgets(buf, sizeof (buf), fp) == NULL)
260*7c478bd9Sstevel@tonic-gate fatalerr("%s: Too few lines in input table\n", basenm);
261*7c478bd9Sstevel@tonic-gate linenum++;
262*7c478bd9Sstevel@tonic-gate } while (buf[0] == '#' || buf[0] == '\0' ||
263*7c478bd9Sstevel@tonic-gate (wslength = strspn(buf, " \t\n")) == strlen(buf) ||
264*7c478bd9Sstevel@tonic-gate strchr(buf, '#') == buf + wslength);
265*7c478bd9Sstevel@tonic-gate
266*7c478bd9Sstevel@tonic-gate if ((tokp = strtok(buf, " \t")) == NULL)
267*7c478bd9Sstevel@tonic-gate fatalerr("%s: Bad RES specification, line %d of input file\n",
268*7c478bd9Sstevel@tonic-gate basenm, linenum);
269*7c478bd9Sstevel@tonic-gate if ((int)strlen(tokp) > 4) {
270*7c478bd9Sstevel@tonic-gate if (strncmp(tokp, "RES=", 4) != 0)
271*7c478bd9Sstevel@tonic-gate fatalerr("%s: Bad RES specification, \
272*7c478bd9Sstevel@tonic-gate line %d of input file\n", basenm, linenum);
273*7c478bd9Sstevel@tonic-gate if (tokp[4] == '-')
274*7c478bd9Sstevel@tonic-gate fatalerr("%s: Bad RES specification, \
275*7c478bd9Sstevel@tonic-gate line %d of input file\n", basenm, linenum);
276*7c478bd9Sstevel@tonic-gate res = strtoul(&tokp[4], (char **)NULL, 10);
277*7c478bd9Sstevel@tonic-gate } else if (strlen(tokp) == 4) {
278*7c478bd9Sstevel@tonic-gate if (strcmp(tokp, "RES=") != 0)
279*7c478bd9Sstevel@tonic-gate fatalerr("%s: Bad RES specification, \
280*7c478bd9Sstevel@tonic-gate line %d of input file\n", basenm, linenum);
281*7c478bd9Sstevel@tonic-gate if ((tokp = strtok(NULL, " \t")) == NULL)
282*7c478bd9Sstevel@tonic-gate fatalerr("%s: Bad RES specification, \
283*7c478bd9Sstevel@tonic-gate line %d of input file\n", basenm, linenum);
284*7c478bd9Sstevel@tonic-gate if (tokp[0] == '-')
285*7c478bd9Sstevel@tonic-gate fatalerr("%s: Bad RES specification, \
286*7c478bd9Sstevel@tonic-gate line %d of input file\n", basenm, linenum);
287*7c478bd9Sstevel@tonic-gate res = strtoul(tokp, (char **)NULL, 10);
288*7c478bd9Sstevel@tonic-gate } else if (strlen(tokp) == 3) {
289*7c478bd9Sstevel@tonic-gate if (strcmp(tokp, "RES") != 0)
290*7c478bd9Sstevel@tonic-gate fatalerr("%s: Bad RES specification, \
291*7c478bd9Sstevel@tonic-gate line %d of input file\n", basenm, linenum);
292*7c478bd9Sstevel@tonic-gate if ((tokp = strtok(NULL, " \t")) == NULL)
293*7c478bd9Sstevel@tonic-gate fatalerr("%s: Bad RES specification, \
294*7c478bd9Sstevel@tonic-gate line %d of input file\n", basenm, linenum);
295*7c478bd9Sstevel@tonic-gate if ((int)strlen(tokp) > 1) {
296*7c478bd9Sstevel@tonic-gate if (strncmp(tokp, "=", 1) != 0)
297*7c478bd9Sstevel@tonic-gate fatalerr("%s: Bad RES specification, \
298*7c478bd9Sstevel@tonic-gate line %d of input file\n", basenm, linenum);
299*7c478bd9Sstevel@tonic-gate if (tokp[1] == '-')
300*7c478bd9Sstevel@tonic-gate fatalerr("%s: Bad RES specification, \
301*7c478bd9Sstevel@tonic-gate line %d of input file\n", basenm, linenum);
302*7c478bd9Sstevel@tonic-gate res = strtoul(&tokp[1], (char **)NULL, 10);
303*7c478bd9Sstevel@tonic-gate } else if (strlen(tokp) == 1) {
304*7c478bd9Sstevel@tonic-gate if ((tokp = strtok(NULL, " \t")) == NULL)
305*7c478bd9Sstevel@tonic-gate fatalerr("%s: Bad RES specification, \
306*7c478bd9Sstevel@tonic-gate line %d of input file\n", basenm, linenum);
307*7c478bd9Sstevel@tonic-gate if (tokp[0] == '-')
308*7c478bd9Sstevel@tonic-gate fatalerr("%s: Bad RES specification, \
309*7c478bd9Sstevel@tonic-gate line %d of input file\n", basenm, linenum);
310*7c478bd9Sstevel@tonic-gate res = strtoul(tokp, (char **)NULL, 10);
311*7c478bd9Sstevel@tonic-gate }
312*7c478bd9Sstevel@tonic-gate } else {
313*7c478bd9Sstevel@tonic-gate fatalerr("%s: Bad RES specification, line %d of input file\n",
314*7c478bd9Sstevel@tonic-gate basenm, linenum);
315*7c478bd9Sstevel@tonic-gate }
316*7c478bd9Sstevel@tonic-gate
317*7c478bd9Sstevel@tonic-gate /*
318*7c478bd9Sstevel@tonic-gate * The remainder of the input file should contain exactly enough
319*7c478bd9Sstevel@tonic-gate * non-blank, non-comment lines to fill the table (ts_ndpents lines).
320*7c478bd9Sstevel@tonic-gate * We assume that any non-blank, non-comment line is data for the
321*7c478bd9Sstevel@tonic-gate * table and fail if we find more or less than we need.
322*7c478bd9Sstevel@tonic-gate */
323*7c478bd9Sstevel@tonic-gate for (i = 0; i < tsadmin.ts_ndpents; i++) {
324*7c478bd9Sstevel@tonic-gate
325*7c478bd9Sstevel@tonic-gate /*
326*7c478bd9Sstevel@tonic-gate * Get the next non-blank, non-comment line.
327*7c478bd9Sstevel@tonic-gate */
328*7c478bd9Sstevel@tonic-gate do {
329*7c478bd9Sstevel@tonic-gate if (fgets(buf, sizeof (buf), fp) == NULL)
330*7c478bd9Sstevel@tonic-gate fatalerr("%s: Too few lines in input table\n",
331*7c478bd9Sstevel@tonic-gate basenm);
332*7c478bd9Sstevel@tonic-gate linenum++;
333*7c478bd9Sstevel@tonic-gate } while (buf[0] == '#' || buf[0] == '\0' ||
334*7c478bd9Sstevel@tonic-gate (wslength = strspn(buf, " \t\n")) == strlen(buf) ||
335*7c478bd9Sstevel@tonic-gate strchr(buf, '#') == buf + wslength);
336*7c478bd9Sstevel@tonic-gate
337*7c478bd9Sstevel@tonic-gate if ((tokp = strtok(buf, " \t")) == NULL)
338*7c478bd9Sstevel@tonic-gate fatalerr("%s: Too few values, line %d of input file\n",
339*7c478bd9Sstevel@tonic-gate basenm, linenum);
340*7c478bd9Sstevel@tonic-gate
341*7c478bd9Sstevel@tonic-gate if (res != HZ) {
342*7c478bd9Sstevel@tonic-gate hrtime.hrt_secs = 0;
343*7c478bd9Sstevel@tonic-gate hrtime.hrt_rem = atol(tokp);
344*7c478bd9Sstevel@tonic-gate hrtime.hrt_res = res;
345*7c478bd9Sstevel@tonic-gate if (_hrtnewres(&hrtime, HZ, HRT_RNDUP) == -1)
346*7c478bd9Sstevel@tonic-gate fatalerr("%s: Can't convert specified "
347*7c478bd9Sstevel@tonic-gate "resolution to ticks\n", basenm);
348*7c478bd9Sstevel@tonic-gate if ((ts_dptbl[i].ts_quantum = hrtconvert(&hrtime))
349*7c478bd9Sstevel@tonic-gate == -1)
350*7c478bd9Sstevel@tonic-gate fatalerr("%s: ts_quantum value out of "
351*7c478bd9Sstevel@tonic-gate "valid range; line %d of input,\n"
352*7c478bd9Sstevel@tonic-gate "table not overwritten\n",
353*7c478bd9Sstevel@tonic-gate basenm, linenum);
354*7c478bd9Sstevel@tonic-gate } else {
355*7c478bd9Sstevel@tonic-gate ts_dptbl[i].ts_quantum = atol(tokp);
356*7c478bd9Sstevel@tonic-gate }
357*7c478bd9Sstevel@tonic-gate if (ts_dptbl[i].ts_quantum <= 0)
358*7c478bd9Sstevel@tonic-gate fatalerr("%s: ts_quantum value out of valid range; "
359*7c478bd9Sstevel@tonic-gate "line %d of input,\ntable not overwritten\n",
360*7c478bd9Sstevel@tonic-gate basenm, linenum);
361*7c478bd9Sstevel@tonic-gate
362*7c478bd9Sstevel@tonic-gate if ((tokp = strtok(NULL, " \t")) == NULL || tokp[0] == '#')
363*7c478bd9Sstevel@tonic-gate fatalerr("%s: Too few values, line %d of input file\n",
364*7c478bd9Sstevel@tonic-gate basenm, linenum);
365*7c478bd9Sstevel@tonic-gate ts_dptbl[i].ts_tqexp = (short)atoi(tokp);
366*7c478bd9Sstevel@tonic-gate if (ts_dptbl[i].ts_tqexp < 0 ||
367*7c478bd9Sstevel@tonic-gate ts_dptbl[i].ts_tqexp > tsadmin.ts_ndpents)
368*7c478bd9Sstevel@tonic-gate fatalerr("%s: ts_tqexp value out of valid range; "
369*7c478bd9Sstevel@tonic-gate "line %d of input,\ntable not overwritten\n",
370*7c478bd9Sstevel@tonic-gate basenm, linenum);
371*7c478bd9Sstevel@tonic-gate
372*7c478bd9Sstevel@tonic-gate if ((tokp = strtok(NULL, " \t")) == NULL || tokp[0] == '#')
373*7c478bd9Sstevel@tonic-gate fatalerr("%s: Too few values, line %d of input file\n",
374*7c478bd9Sstevel@tonic-gate basenm, linenum);
375*7c478bd9Sstevel@tonic-gate ts_dptbl[i].ts_slpret = (short)atoi(tokp);
376*7c478bd9Sstevel@tonic-gate if (ts_dptbl[i].ts_slpret < 0 ||
377*7c478bd9Sstevel@tonic-gate ts_dptbl[i].ts_slpret > tsadmin.ts_ndpents)
378*7c478bd9Sstevel@tonic-gate fatalerr("%s: ts_slpret value out of valid range; "
379*7c478bd9Sstevel@tonic-gate "line %d of input,\ntable not overwritten\n",
380*7c478bd9Sstevel@tonic-gate basenm, linenum);
381*7c478bd9Sstevel@tonic-gate
382*7c478bd9Sstevel@tonic-gate if ((tokp = strtok(NULL, " \t")) == NULL || tokp[0] == '#')
383*7c478bd9Sstevel@tonic-gate fatalerr("%s: Too few values, line %d of input file\n",
384*7c478bd9Sstevel@tonic-gate basenm, linenum);
385*7c478bd9Sstevel@tonic-gate ts_dptbl[i].ts_maxwait = (short)atoi(tokp);
386*7c478bd9Sstevel@tonic-gate if (ts_dptbl[i].ts_maxwait < 0)
387*7c478bd9Sstevel@tonic-gate fatalerr("%s: ts_maxwait value out of valid range; "
388*7c478bd9Sstevel@tonic-gate "line %d of input,\ntable not overwritten\n",
389*7c478bd9Sstevel@tonic-gate basenm, linenum);
390*7c478bd9Sstevel@tonic-gate
391*7c478bd9Sstevel@tonic-gate if ((tokp = strtok(NULL, " \t")) == NULL || tokp[0] == '#')
392*7c478bd9Sstevel@tonic-gate fatalerr("%s: Too few values, line %d of input file\n",
393*7c478bd9Sstevel@tonic-gate basenm, linenum);
394*7c478bd9Sstevel@tonic-gate ts_dptbl[i].ts_lwait = (short)atoi(tokp);
395*7c478bd9Sstevel@tonic-gate if (ts_dptbl[i].ts_lwait < 0 ||
396*7c478bd9Sstevel@tonic-gate ts_dptbl[i].ts_lwait > tsadmin.ts_ndpents)
397*7c478bd9Sstevel@tonic-gate fatalerr("%s: ts_lwait value out of valid range; "
398*7c478bd9Sstevel@tonic-gate "line %d of input,\ntable not overwritten\n",
399*7c478bd9Sstevel@tonic-gate basenm, linenum);
400*7c478bd9Sstevel@tonic-gate
401*7c478bd9Sstevel@tonic-gate if ((tokp = strtok(NULL, " \t")) != NULL && tokp[0] != '#')
402*7c478bd9Sstevel@tonic-gate fatalerr("%s: Too many values, line %d of input file\n",
403*7c478bd9Sstevel@tonic-gate basenm, linenum);
404*7c478bd9Sstevel@tonic-gate }
405*7c478bd9Sstevel@tonic-gate
406*7c478bd9Sstevel@tonic-gate /*
407*7c478bd9Sstevel@tonic-gate * We've read enough lines to fill the table. We fail
408*7c478bd9Sstevel@tonic-gate * if the input file contains any more.
409*7c478bd9Sstevel@tonic-gate */
410*7c478bd9Sstevel@tonic-gate while (fgets(buf, sizeof (buf), fp) != NULL) {
411*7c478bd9Sstevel@tonic-gate if (buf[0] != '#' && buf[0] != '\0' &&
412*7c478bd9Sstevel@tonic-gate (wslength = strspn(buf, " \t\n")) != strlen(buf) &&
413*7c478bd9Sstevel@tonic-gate strchr(buf, '#') != buf + wslength)
414*7c478bd9Sstevel@tonic-gate fatalerr("%s: Too many lines in input table\n",
415*7c478bd9Sstevel@tonic-gate basenm);
416*7c478bd9Sstevel@tonic-gate }
417*7c478bd9Sstevel@tonic-gate
418*7c478bd9Sstevel@tonic-gate tsadmin.ts_dpents = ts_dptbl;
419*7c478bd9Sstevel@tonic-gate tsadmin.ts_cmd = TS_SETDPTBL;
420*7c478bd9Sstevel@tonic-gate if (priocntl(0, 0, PC_ADMIN, (caddr_t)&pcadmin) == -1)
421*7c478bd9Sstevel@tonic-gate fatalerr("%s: Can't set ts_dptbl, priocntl system call \
422*7c478bd9Sstevel@tonic-gate failed with errno %d\n", basenm, errno);
423*7c478bd9Sstevel@tonic-gate }
424