xref: /titanic_52/usr/src/cmd/priocntl/sdcpriocntl.c (revision ac23bf836b7aa423b14eafd726f921e705676f80)
135a5a358SJonathan Adams /*
235a5a358SJonathan Adams  * CDDL HEADER START
335a5a358SJonathan Adams  *
435a5a358SJonathan Adams  * The contents of this file are subject to the terms of the
535a5a358SJonathan Adams  * Common Development and Distribution License (the "License").
635a5a358SJonathan Adams  * You may not use this file except in compliance with the License.
735a5a358SJonathan Adams  *
835a5a358SJonathan Adams  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
935a5a358SJonathan Adams  * or http://www.opensolaris.org/os/licensing.
1035a5a358SJonathan Adams  * See the License for the specific language governing permissions
1135a5a358SJonathan Adams  * and limitations under the License.
1235a5a358SJonathan Adams  *
1335a5a358SJonathan Adams  * When distributing Covered Code, include this CDDL HEADER in each
1435a5a358SJonathan Adams  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
1535a5a358SJonathan Adams  * If applicable, add the following below this CDDL HEADER, with the
1635a5a358SJonathan Adams  * fields enclosed by brackets "[]" replaced with your own identifying
1735a5a358SJonathan Adams  * information: Portions Copyright [yyyy] [name of copyright owner]
1835a5a358SJonathan Adams  *
1935a5a358SJonathan Adams  * CDDL HEADER END
2035a5a358SJonathan Adams  */
2135a5a358SJonathan Adams /*
2235a5a358SJonathan Adams  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
2335a5a358SJonathan Adams  * Use is subject to license terms.
2435a5a358SJonathan Adams  */
2535a5a358SJonathan Adams 
2635a5a358SJonathan Adams #include	<errno.h>
2735a5a358SJonathan Adams #include	<stdio.h>
2835a5a358SJonathan Adams #include	<stdlib.h>
2935a5a358SJonathan Adams #include	<string.h>
30*ac23bf83SBlake Jones #include	<libgen.h>
3135a5a358SJonathan Adams #include	<sys/param.h>
3235a5a358SJonathan Adams #include	<sys/priocntl.h>
3335a5a358SJonathan Adams #include	<sys/types.h>
3435a5a358SJonathan Adams 
3535a5a358SJonathan Adams #include	"priocntl.h"
3635a5a358SJonathan Adams 
37*ac23bf83SBlake Jones static char usage[] =
38*ac23bf83SBlake Jones "usage:	priocntl -l\n\
39*ac23bf83SBlake Jones 	priocntl -d [-i idtype] [idlist]\n";
4035a5a358SJonathan Adams 
41*ac23bf83SBlake Jones /*
42*ac23bf83SBlake Jones  * A whole lot of to-do for a scheduling class that can't actually be
43*ac23bf83SBlake Jones  * configured or used by user processes.
44*ac23bf83SBlake Jones  */
4535a5a358SJonathan Adams int
4635a5a358SJonathan Adams main(int argc, char *argv[])
4735a5a358SJonathan Adams {
48*ac23bf83SBlake Jones 	int	dflag, eflag, iflag, lflag, sflag;
4935a5a358SJonathan Adams 	int	c;
50*ac23bf83SBlake Jones 	char	cmdpath[MAXPATHLEN];
51*ac23bf83SBlake Jones 	char	basenm[BASENMSZ];
5235a5a358SJonathan Adams 
53*ac23bf83SBlake Jones 	(void) strlcpy(cmdpath, argv[0], MAXPATHLEN);
54*ac23bf83SBlake Jones 	(void) strlcpy(basenm, basename(argv[0]), BASENMSZ);
55*ac23bf83SBlake Jones 
56*ac23bf83SBlake Jones 	dflag = eflag = iflag = lflag = sflag = 0;
57*ac23bf83SBlake Jones 	while ((c = getopt(argc, argv, "c:dei:ls")) != -1) {
5835a5a358SJonathan Adams 		switch (c) {
5935a5a358SJonathan Adams 
6035a5a358SJonathan Adams 		case 'c':
6135a5a358SJonathan Adams 			if (strcmp(optarg, "SDC") != 0)
6235a5a358SJonathan Adams 				fatalerr("error: %s executed for %s class, "
6335a5a358SJonathan Adams 				    "%s is actually sub-command for %s class\n",
64*ac23bf83SBlake Jones 				    cmdpath, optarg, cmdpath, "SDC");
65*ac23bf83SBlake Jones 			break;
6635a5a358SJonathan Adams 
67*ac23bf83SBlake Jones 		case 'd':
68*ac23bf83SBlake Jones 			dflag++;
69*ac23bf83SBlake Jones 			break;
70*ac23bf83SBlake Jones 
71*ac23bf83SBlake Jones 		case 'e':
72*ac23bf83SBlake Jones 			eflag++;
73*ac23bf83SBlake Jones 			break;
74*ac23bf83SBlake Jones 
75*ac23bf83SBlake Jones 		case 'i':
76*ac23bf83SBlake Jones 			iflag++;	/* optarg is parsed, but ignored */
77*ac23bf83SBlake Jones 			break;
78*ac23bf83SBlake Jones 
79*ac23bf83SBlake Jones 		case 'l':
80*ac23bf83SBlake Jones 			lflag++;
81*ac23bf83SBlake Jones 			break;
82*ac23bf83SBlake Jones 
83*ac23bf83SBlake Jones 		case 's':
84*ac23bf83SBlake Jones 			sflag++;
8535a5a358SJonathan Adams 			break;
8635a5a358SJonathan Adams 
8735a5a358SJonathan Adams 		case '?':
8835a5a358SJonathan Adams 			fatalerr(usage);
89*ac23bf83SBlake Jones 			/*NOTREACHED*/
90*ac23bf83SBlake Jones 
9135a5a358SJonathan Adams 		default:
9235a5a358SJonathan Adams 			break;
9335a5a358SJonathan Adams 		}
9435a5a358SJonathan Adams 	}
9535a5a358SJonathan Adams 
96*ac23bf83SBlake Jones 	if (sflag && eflag) {
9735a5a358SJonathan Adams 		fatalerr(usage);
98*ac23bf83SBlake Jones 	}
99*ac23bf83SBlake Jones 	if (sflag || eflag) {
100*ac23bf83SBlake Jones 		fatalerr(
101*ac23bf83SBlake Jones 		    "priocntl: \"-%c\" may not be used with the %s class\n",
102*ac23bf83SBlake Jones 		    (sflag ? 's' : 'e'), "SDC");
103*ac23bf83SBlake Jones 	}
10435a5a358SJonathan Adams 
105*ac23bf83SBlake Jones 	if ((!dflag && !lflag) || (dflag && lflag)) {
106*ac23bf83SBlake Jones 		fatalerr(usage);
107*ac23bf83SBlake Jones 	}
108*ac23bf83SBlake Jones 
109*ac23bf83SBlake Jones 	if (dflag) {
110*ac23bf83SBlake Jones 		pid_t *pidlist;
111*ac23bf83SBlake Jones 		size_t numread, i;
112*ac23bf83SBlake Jones 
113*ac23bf83SBlake Jones 		/*
114*ac23bf83SBlake Jones 		 * No scheduling-class-specific information to print,
115*ac23bf83SBlake Jones 		 * but we read the pidlist to avoid generating a SIGPIPE
116*ac23bf83SBlake Jones 		 * in the main priocntl process.  Once we've read it,
117*ac23bf83SBlake Jones 		 * we might as well print it.
118*ac23bf83SBlake Jones 		 */
119*ac23bf83SBlake Jones 		if ((pidlist = read_pidlist(&numread, stdin)) == NULL) {
120*ac23bf83SBlake Jones 			fatalerr("%s: Can't read pidlist.\n", basenm);
121*ac23bf83SBlake Jones 		} else if (numread == 0) {
122*ac23bf83SBlake Jones 			fatalerr("%s: No pids on input.\n", basenm);
123*ac23bf83SBlake Jones 		} else {
124*ac23bf83SBlake Jones 			(void) printf("SYSTEM DUTY-CYCLE PROCESSES:\n");
125*ac23bf83SBlake Jones 			(void) printf("%7s\n", "PID");
126*ac23bf83SBlake Jones 			for (i = 0; i < numread; i++) {
127*ac23bf83SBlake Jones 				(void) printf("%7ld\n", pidlist[i]);
128*ac23bf83SBlake Jones 			}
129*ac23bf83SBlake Jones 		}
130*ac23bf83SBlake Jones 		free_pidlist(pidlist);
131*ac23bf83SBlake Jones 	} else {
132*ac23bf83SBlake Jones 		(void) printf("SDC (System Duty-Cycle Class)\n");
133*ac23bf83SBlake Jones 	}
134*ac23bf83SBlake Jones 
13535a5a358SJonathan Adams 	return (0);
13635a5a358SJonathan Adams }
137