9804 hal-set-property should support --direct option
[unleashed.git] / usr / src / cmd / priocntl / sdcpriocntl.c
blob0f805177b11f2687249558c7c9aa72de62f91ed9
1 /*
2 * CDDL HEADER START
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
19 * CDDL HEADER END
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #include <errno.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <libgen.h>
31 #include <sys/param.h>
32 #include <sys/priocntl.h>
33 #include <sys/types.h>
35 #include "priocntl.h"
37 static char usage[] =
38 "usage: priocntl -l\n\
39 priocntl -d [-i idtype] [idlist]\n";
42 * A whole lot of to-do for a scheduling class that can't actually be
43 * configured or used by user processes.
45 int
46 main(int argc, char *argv[])
48 int dflag, eflag, iflag, lflag, sflag;
49 int c;
50 char cmdpath[MAXPATHLEN];
51 char basenm[BASENMSZ];
53 (void) strlcpy(cmdpath, argv[0], MAXPATHLEN);
54 (void) strlcpy(basenm, basename(argv[0]), BASENMSZ);
56 dflag = eflag = iflag = lflag = sflag = 0;
57 while ((c = getopt(argc, argv, "c:dei:ls")) != -1) {
58 switch (c) {
60 case 'c':
61 if (strcmp(optarg, "SDC") != 0)
62 fatalerr("error: %s executed for %s class, "
63 "%s is actually sub-command for %s class\n",
64 cmdpath, optarg, cmdpath, "SDC");
65 break;
67 case 'd':
68 dflag++;
69 break;
71 case 'e':
72 eflag++;
73 break;
75 case 'i':
76 iflag++; /* optarg is parsed, but ignored */
77 break;
79 case 'l':
80 lflag++;
81 break;
83 case 's':
84 sflag++;
85 break;
87 case '?':
88 fatalerr(usage);
89 /*NOTREACHED*/
91 default:
92 break;
96 if (sflag && eflag) {
97 fatalerr(usage);
99 if (sflag || eflag) {
100 fatalerr(
101 "priocntl: \"-%c\" may not be used with the %s class\n",
102 (sflag ? 's' : 'e'), "SDC");
105 if ((!dflag && !lflag) || (dflag && lflag)) {
106 fatalerr(usage);
109 if (dflag) {
110 pid_t *pidlist;
111 size_t numread, i;
114 * No scheduling-class-specific information to print,
115 * but we read the pidlist to avoid generating a SIGPIPE
116 * in the main priocntl process. Once we've read it,
117 * we might as well print it.
119 if ((pidlist = read_pidlist(&numread, stdin)) == NULL) {
120 fatalerr("%s: Can't read pidlist.\n", basenm);
121 } else if (numread == 0) {
122 fatalerr("%s: No pids on input.\n", basenm);
123 } else {
124 (void) printf("SYSTEM DUTY-CYCLE PROCESSES:\n");
125 (void) printf("%7s\n", "PID");
126 for (i = 0; i < numread; i++) {
127 (void) printf("%7ld\n", pidlist[i]);
130 free_pidlist(pidlist);
131 } else {
132 (void) printf("SDC (System Duty-Cycle Class)\n");
135 return (0);