pbind.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (the "License"). You may not use this file except in compliance
* with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* pbind - bind a process to a processor (non-exclusively)
*/
#include <sys/processor.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <procfs.h>
#include <fcntl.h>
#include <errno.h>
#include <dirent.h>
#include <locale.h>
#include <libproc.h>
#include <stdarg.h>
#if !defined(TEXT_DOMAIN) /* should be defined by cc -D */
#endif
#define ERR_OK 0 /* exit status for success */
static char *progname;
static char bflag;
static char qflag;
static char Qflag;
static char uflag;
static char Uflag;
static int errors;
#define MAX_PROCFS_PATH 80
/*PRINTFLIKE1*/
static void
{
}
/*PRINTFLIKE1*/
static void
{
}
/*
* Output for query.
*/
static void
{
char *proclwp;
char pidstr[21];
if (lwpid == -1) {
proclwp = "process";
} else {
proclwp = "lwp";
}
if (cpu == PBIND_NONE)
else
}
/*
* Binding error.
*/
static void
{
char *msg;
switch (cpu) {
case PBIND_NONE:
break;
case PBIND_QUERY:
break;
default:
break;
}
if (lwpid == -1)
else
}
/*
* Output for bind.
*/
static void
{
char *proclwp;
char pidstr[21];
if (lwpid == -1) {
proclwp = "process";
} else {
proclwp = "lwp";
}
if (old == PBIND_NONE) {
if (new == PBIND_NONE)
else
} else {
if (new == PBIND_NONE)
else
}
}
static struct ps_prochandle *
{
int ret;
struct ps_prochandle *Pr;
return (NULL);
}
/*
* Set run-on-last-close flag so the controlled process
* runs even if we die on a signal, and create an agent LWP.
*/
return (NULL);
}
return (Pr);
}
static void
{
return;
}
static void
{
} else {
if (qflag)
else
}
}
/*
* Query, set, or clear bindings for the range of LWPs in the given process.
*/
static int
{
char procfile[MAX_PROCFS_PATH];
struct ps_prochandle *Pr;
/*
* Report bindings for LWPs in process 'pid'.
*/
return (ERR_FAIL);
}
return (ERR_FAIL);
}
return (ERR_FAIL);
}
return (ERR_FAIL);
}
return (ERR_FAIL);
}
found = 0;
/*LINTED ALIGNMENT*/
continue;
found++;
else if (binding != PBIND_NONE)
}
if (found == 0) {
"No matching LWPs found\n"),
return (ERR_FAIL);
}
return (ERR_OK);
}
/*ARGSUSED*/
static int
{
/*
* Ignore search errors. The process may have exited
* since we read the directory.
*/
return (0);
return (0);
}
if (binding != PBIND_NONE)
return (0);
}
static int
{
return (0);
}
static int
usage(void)
{
gettext("usage: \n\t%1$s -b processor_id pid[/lwpids] ...\n"
"\t%1$s -U [processor_id] ...\n"
"\t%1$s -Q [processor_id] ...\n"
"\t%1$s -u pid[/lwpids] ...\n"
"\t%1$s [-q] [pid[/lwpids] ...]\n"),
progname);
return (ERR_USAGE);
}
int
{
int c;
int ret;
char *endstr;
(void) textdomain(TEXT_DOMAIN);
switch (c) {
case 'b':
bflag = 1;
optarg);
break;
case 'q':
qflag = 1;
cpu = PBIND_QUERY;
break;
case 'Q':
Qflag = 1;
cpu = PBIND_QUERY;
break;
case 'u':
uflag = 1;
cpu = PBIND_NONE;
break;
case 'U':
Uflag = 1;
break;
default:
return (usage());
}
}
/*
* Make sure that at most one of the options b, q, Q, u, or U
* was specified.
*/
if (c < 1) { /* nothing specified */
cpu = PBIND_QUERY;
} else if (c > 1) {
"are mutually exclusive\n"));
return (usage());
}
errors = 0;
/*
* Handle query of all processes.
*/
if (argc == 0) {
return (usage());
}
if (Uflag) {
}
if (Qflag) {
return (errors);
} else {
return (errors);
}
}
/*
* Go through listed processor IDs.
*/
errno = 0;
continue;
}
if (Qflag) {
(void) proc_walk(query_all_lwp,
&cpu, PR_WALK_LWP);
continue;
}
if (Uflag) {
PBIND_NONE, &old_cpu) != 0) {
"processor %d"), (int)cpu);
}
continue;
}
}
return (errors);
}
/*
* Go through listed process[/lwp_ranges].
*/
errno = 0;
if (errno != 0 ||
continue;
}
/*
* Handle lwp range case
*/
if (*lwps == '\0' ||
proc_lwp_range_valid(lwps) != 0) {
"for pid %d\n"), (int)pid);
continue;
}
if (!qflag)
(void) proc_initstdio();
if (!qflag)
(void) proc_finistdio();
} else {
/*
* Handle whole process case.
*/
continue;
}
if (qflag)
else
}
}
return (errors);
}