aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Guzik <mjg@FreeBSD.org>2023-02-16 18:12:46 +0000
committerMateusz Guzik <mjg@FreeBSD.org>2023-02-16 18:18:49 +0000
commit2924ae099a1e8ffc5b6040f3af5645aa54c0f629 (patch)
treedb64069c73fa0f5ddf503fb5a6f5f81b7662d341
parent2b460910326c4f39068fe2158a0726dc3d362f68 (diff)
downloadsrc-2924ae099a1e8ffc5b6040f3af5645aa54c0f629.tar.gz
src-2924ae099a1e8ffc5b6040f3af5645aa54c0f629.zip
Revert "cpuset: add --count"
The patch introduced a behavior change coming from getopt_long, namely the entire argument array would be parsed looking for opts, which affected uses spawning new processes without passing '--' to delimit where cpuset arguments end. [1] Apart from that turns out the change had a bug: using CPU_LEVEL_ROOT instead of CPU_LEVEL_WHICH, returning a different cpuset than intended. [2] The intended functionality is provided with nproc(1), which landed after this change. As such, revert for the time being. This reverts commit d9d5f2c042a51a9f0dd69eb1fc349efd81ffa483. Reported by: Mark Millard [1] Reported by: jbeich [2]
-rw-r--r--usr.bin/cpuset/cpuset.116
-rw-r--r--usr.bin/cpuset/cpuset.c51
2 files changed, 2 insertions, 65 deletions
diff --git a/usr.bin/cpuset/cpuset.1 b/usr.bin/cpuset/cpuset.1
index 31a3e45134d7..1d0180c98991 100644
--- a/usr.bin/cpuset/cpuset.1
+++ b/usr.bin/cpuset/cpuset.1
@@ -25,7 +25,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd August 25, 2022
+.Dd July 3, 2018
.Dt CPUSET 1
.Os
.Sh NAME
@@ -57,10 +57,6 @@
.Fl g
.Op Fl cir
.Op Fl d Ar domain | Fl j Ar jail | Fl p Ar pid | Fl t Ar tid | Fl s Ar setid | Fl x Ar irq
-.Nm
-.Fl g
-.Fl -count
-.Fl p Ar pid
.Sh DESCRIPTION
The
.Nm
@@ -176,16 +172,6 @@ Specifies a thread id as the target of the operation.
.It Fl x Ar irq
Specifies an irq as the target of the operation.
.El
-.Pp
-The long options are as follows:
-.Bl -tag -width ".Fl -count"
-.It Fl -count
-Count the number of hardware threads included in the set. Requires
-.Fl g
-and
-.Fl p
-flags.
-.El
.Sh EXIT STATUS
.Ex -std
.Sh EXAMPLES
diff --git a/usr.bin/cpuset/cpuset.c b/usr.bin/cpuset/cpuset.c
index 528cbc39bbc7..79c6c2b6ca79 100644
--- a/usr.bin/cpuset/cpuset.c
+++ b/usr.bin/cpuset/cpuset.c
@@ -44,7 +44,6 @@ __FBSDID("$FreeBSD$");
#include <ctype.h>
#include <err.h>
#include <errno.h>
-#include <getopt.h>
#include <jail.h>
#include <limits.h>
#include <stdio.h>
@@ -53,9 +52,6 @@ __FBSDID("$FreeBSD$");
#include <unistd.h>
#include <string.h>
-/*
- * Short opts.
- */
static int Cflag;
static int cflag;
static int dflag;
@@ -69,24 +65,12 @@ static int rflag;
static int sflag;
static int tflag;
static int xflag;
-
-/*
- * Long-only opts.
- */
-static int count_flag;
-
static id_t id;
static cpulevel_t level;
static cpuwhich_t which;
-#define OPT_THREADCOUNT (CHAR_MAX + 1)
static void usage(void);
-static struct option long_opts[] = {
- { "count", no_argument, NULL, OPT_THREADCOUNT },
- { NULL, 0, NULL, 0 }
-};
-
struct numa_policy {
const char *name;
int policy;
@@ -299,18 +283,6 @@ printsetid(void)
levelnames[level], setid);
}
-static void
-printcpucount(void)
-{
- cpuset_t mask;
- CPU_ZERO(&mask);
-
- if (cpuset_getaffinity(CPU_LEVEL_ROOT, CPU_WHICH_PID, id,
- sizeof(mask), &mask) != 0)
- err(EXIT_FAILURE, "getaffinity");
- printf("%d\n", CPU_COUNT(&mask));
-}
-
int
main(int argc, char *argv[])
{
@@ -328,8 +300,7 @@ main(int argc, char *argv[])
level = CPU_LEVEL_WHICH;
which = CPU_WHICH_PID;
id = pid = tid = setid = -1;
- while ((ch = getopt_long(argc, argv,
- "Ccd:gij:l:n:p:rs:t:x:", long_opts, NULL)) != -1) {
+ while ((ch = getopt(argc, argv, "Ccd:gij:l:n:p:rs:t:x:")) != -1) {
switch (ch) {
case 'C':
Cflag = 1;
@@ -388,30 +359,12 @@ main(int argc, char *argv[])
which = CPU_WHICH_IRQ;
id = atoi(optarg);
break;
- case OPT_THREADCOUNT:
- count_flag = 1;
- break;
default:
usage();
}
}
argc -= optind;
argv += optind;
-
- /*
- * count requires g and p flags and is incompatible with
- * everything else for simplicity.
- */
- if (count_flag) {
- if (!gflag || !pflag)
- usage();
- if (Cflag || cflag || dflag || iflag || jflag || lflag ||
- nflag || rflag || sflag || tflag || xflag)
- usage();
- printcpucount();
- exit(EXIT_SUCCESS);
- }
-
if (gflag) {
if (argc || Cflag || lflag || nflag)
usage();
@@ -518,7 +471,5 @@ usage(void)
fprintf(stderr,
" cpuset -g [-cir]\n"
" [-d domain | -j jailid | -p pid | -t tid | -s setid | -x irq]\n");
- fprintf(stderr,
- " cpuset -g --count -p pid\n");
exit(1);
}