* Re: [PATCH 2/2] lscpu-arm: Remove the "Ampere-1a" part.
From: Jeremy Linton @ 2025-07-14 20:48 UTC (permalink / raw)
To: Karel Zak, Paul Benoit; +Cc: util-linux
In-Reply-To: <crm5fcuper7bhu7iv7jbejf3rnowwo4tuwrjnutngta56dedgm@zajfg6nh2okx>
On 7/14/25 7:16 AM, Karel Zak wrote:
> On Fri, Jul 11, 2025 at 02:16:48PM -0700, Paul Benoit wrote:
>> Remove the "Ampere-1a" part. On newer Ampere Computing systems, the
>> system/model name will be obtained from /sys/bus/soc/devices/soc0/machine,
>> that is populated with the ARM SMC CC SOC_ID Name.
>
> If I understand correctly, there are old systems without
> /sys/.../soc0/machine, right? The change will remove Ampere-1a from
> the lscpu output. This sounds backward incompatible.
Thats a good point, but as I understand it, Ampere hasn't been happy
with the string that is there.
If its OK to break whatever scripts/etc might depend on it at the
moment, why not just update the string.
Then invert the check so that the /sys/bus entry is preferred?
^ permalink raw reply
* Re: [PATCH 2/2] lscpu-arm: Remove the "Ampere-1a" part.
From: Karel Zak @ 2025-07-14 12:16 UTC (permalink / raw)
To: Paul Benoit; +Cc: util-linux
In-Reply-To: <20250711211648.53361-2-paul@os.amperecomputing.com>
On Fri, Jul 11, 2025 at 02:16:48PM -0700, Paul Benoit wrote:
> Remove the "Ampere-1a" part. On newer Ampere Computing systems, the
> system/model name will be obtained from /sys/bus/soc/devices/soc0/machine,
> that is populated with the ARM SMC CC SOC_ID Name.
If I understand correctly, there are old systems without
/sys/.../soc0/machine, right? The change will remove Ampere-1a from
the lscpu output. This sounds backward incompatible.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH 1/2] lscpu-arm: Allow externally sourced model name.
From: Karel Zak @ 2025-07-14 12:11 UTC (permalink / raw)
To: Paul Benoit; +Cc: util-linux
In-Reply-To: <20250711211648.53361-1-paul@os.amperecomputing.com>
Hi Paul,
On Fri, Jul 11, 2025 at 02:16:47PM -0700, Paul Benoit wrote:
> When there isn't an entry for the model name in the id_part table(s),
> attempt to get the machine name from /sys/bus/soc/devices/soc0/machine
How is it supposed to work on a system with multiple CPU types (more CPU
models) if it reads all from the same path?
> + /*
> + * If the Model name was not found in the lscpu 'id_part' tables, see
> + * if there is a Machine name associated with the SOC. This name may
> + * have been set via either SOC specific support code, or obtained
> + * via an ARM SMC CC call into Trusted Firmware.
> + */
> + if (!ct->modelname) {
> + fd = ul_path_fopen(NULL, "r", _PATH_SOC_MACHINENAME);
> + if (fd) {
> + if (!fgets(machinename, sizeof(machinename), fd))
> + machinename[0] = '\0';
> + fclose(fd);
> +
> + /* Replace newline with string terminator */
> + for (i = 0; i < strlen(machinename); i++) {
> + if (machinename[i] == '\n')
> + machinename[i] = '\0';
> + }
> +
> + if (strnlen(machinename, sizeof(machinename)))
> + ct->modelname = xstrdup(machinename);
if (!ct->modelname)
ul_path_read_string(NULL, &ct->modelname, _PATH_SOC_MACHINENAME);
This should be enough, it reads the string, removes \n and strdup()
the result.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH] cpuset: Use stride in cpulist_create
From: Karel Zak @ 2025-07-14 11:55 UTC (permalink / raw)
To: Jesse Rosenstock; +Cc: util-linux
In-Reply-To: <CAMZQ0rLE-6_Nowk5N+YCt35AM4L3XgvxtBQudr59Je73s2kffA@mail.gmail.com>
On Tue, Jul 08, 2025 at 02:20:14PM +0200, Jesse Rosenstock wrote:
> Format cpu lists for `taskset -c`, `lscpu`, etc. using stride. This
> usually produces shorter output.
Thanks! It had been missing for years.
> The patch below uses spaces because gmail hates tabs. Tabs are used in the PR.
>
> https://github.com/util-linux/util-linux/pull/3646
Merged from GitHub.
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: chrt from git segfaults
From: Karel Zak @ 2025-07-14 11:32 UTC (permalink / raw)
To: Benno Schulenberg; +Cc: Madadi Vineeth Reddy, util-linux
In-Reply-To: <25e238da-af73-42fa-ad18-8d9e77d33bab@telfort.nl>
On Thu, Jul 10, 2025 at 10:11:58AM +0200, Benno Schulenberg wrote:
>
> Op 09-07-2025 om 20:45 schreef Madadi Vineeth Reddy:
> > Could you spin off a patch to make sure the priority argument is
> > optional for policies that don’t need it, even when --pid is not used?
>
> No. You broke it, you fix it.
Please, please, don't forget to finalize it to avoid releasing it
incomplete ;-)
I have merged Benno's V2 set of patches, so nothing else is in the
queue for now.
Thanks guys!
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH 4/4 V2] chrt: do not try to interpret any other option as a PID either
From: Karel Zak @ 2025-07-14 11:28 UTC (permalink / raw)
To: Madadi Vineeth Reddy; +Cc: Benno Schulenberg, util-linux
In-Reply-To: <547205fc-ae34-4ac4-a7d9-d32e65b5c3cb@linux.ibm.com>
On Sun, Jul 06, 2025 at 11:39:44AM +0530, Madadi Vineeth Reddy wrote:
> On 03/07/25 20:17, Benno Schulenberg wrote:
> > When doing, for example, `chrt --pid --max`, it would report:
> >
> > chrt: invalid PID argument: '--max'
> >
> > This mistakenly gave the impression that the PID argument has to follow
> > directly after the --pid option.
> >
> > Avoid this by delaying the parsing of a PID until after all options have
> > been parsed. Temporarily set 'ctl->pid' to zero to indicate that a PID
> > needs to be read.
> >
> > After this change, `chrt --pid --max` will simply report the minimum and
> > maximum valid priorities. And `chrt --pid -v`:
>
> According to help text,
> chrt [options] --pid <priority> <pid>
>
> I’m still not sure about allowing the --max option after --pid.
> I’ll leave it to Karel to decide what’s best here.
My point of view (may be wrong, sched-utils CLI is odd). The core of
the chrt command line can be described as:
chrt <options> [<prio>] <process>
where <process> is
1) new process by exec()
2) already running process
The default is 1), --pid enables the 2) and in this case
<process> is PID.
The --pid is just an option to switch between the cases. There is no
argument for the option; it informs how to interpret the <process>.
The ideal would be to use "--" before <process>.
It means that arbitrary options could be after --pid, including --max.
Does it make sense?
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: chrt from git segfaults
From: Madadi Vineeth Reddy @ 2025-07-12 16:29 UTC (permalink / raw)
To: Benno Schulenberg, util-linux; +Cc: Karel Zak, Madadi Vineeth Reddy
In-Reply-To: <25e238da-af73-42fa-ad18-8d9e77d33bab@telfort.nl>
On 10/07/25 13:41, Benno Schulenberg wrote:
>
> Op 09-07-2025 om 20:45 schreef Madadi Vineeth Reddy:
>> Could you spin off a patch to make sure the priority argument is
>> optional for policies that don’t need it, even when --pid is not used?
>
> No. You broke it, you fix it.
>
Sure, I’ll send a patch. Thanks.
Thanks,
Madadi Vineeth Reddy
>
> Benno
>
^ permalink raw reply
* Re: [PATCH 1/2] lscpu-arm: Allow externally sourced model name.
From: Jeremy Linton @ 2025-07-11 22:22 UTC (permalink / raw)
To: Paul Benoit, util-linux
In-Reply-To: <20250711211648.53361-1-paul@os.amperecomputing.com>
Hi,
On 7/11/25 4:16 PM, Paul Benoit wrote:
> When there isn't an entry for the model name in the id_part table(s),
> attempt to get the machine name from /sys/bus/soc/devices/soc0/machine
> to use as the model name. This mechanism allows lscpu to use the
> model/machine name provided via the ARM SMC support code rather than via
> hard-coded lscpu tables.
Since this is suppose to be synced with the DMI data, and is sourced
from the firmware would it make more sense to replace the BIOS name with it?
>
> This code was tested by removing the "Ampere-1a" entry from the
> ampere-part table and verifying that lscpu displayed the correct machine
> name obtained via the ARM SMC interface to Trusted Firmware. The
> "Ampere-1a" entry will be permanently removed by a separate patch.
>
> Signed-off-by: Paul Benoit <paul@os.amperecomputing.com>
> ---
> sys-utils/lscpu-arm.c | 35 ++++++++++++++++++++++++++++++++---
> sys-utils/lscpu.h | 1 +
> 2 files changed, 33 insertions(+), 3 deletions(-)
>
> diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c
> index 8745599d4..a46106bcb 100644
> --- a/sys-utils/lscpu-arm.c
> +++ b/sys-utils/lscpu-arm.c
> @@ -388,7 +388,10 @@ int is_arm(struct lscpu_cxt *cxt)
> static int arm_ids_decode(struct lscpu_cputype *ct)
> {
> int impl, part, j;
> + unsigned int i;
> const struct id_part *parts = NULL;
> + FILE *fd;
> + char machinename[BUFSIZ] = "";
>
> impl = parse_implementer_id(ct);
> if (impl <= 0)
> @@ -406,11 +409,11 @@ static int arm_ids_decode(struct lscpu_cputype *ct)
>
> /* decode model */
> if (!parts)
> - goto done;
> + goto try_machinename;
>
> part = parse_model_id(ct);
> if (part <= 0)
> - goto done;
> + goto try_machinename;
>
> for (j = 0; parts[j].id != -1; j++) {
> if (parts[j].id == part) {
> @@ -419,7 +422,33 @@ static int arm_ids_decode(struct lscpu_cputype *ct)
> break;
> }
> }
> -done:
> +
> +try_machinename:
> +
> + /*
> + * If the Model name was not found in the lscpu 'id_part' tables, see
> + * if there is a Machine name associated with the SOC. This name may
> + * have been set via either SOC specific support code, or obtained
> + * via an ARM SMC CC call into Trusted Firmware.
> + */
> + if (!ct->modelname) {
> + fd = ul_path_fopen(NULL, "r", _PATH_SOC_MACHINENAME);
> + if (fd) {
> + if (!fgets(machinename, sizeof(machinename), fd))
> + machinename[0] = '\0';
> + fclose(fd);
> +
> + /* Replace newline with string terminator */
> + for (i = 0; i < strlen(machinename); i++) {
> + if (machinename[i] == '\n')
> + machinename[i] = '\0';
> + }
> +
> + if (strnlen(machinename, sizeof(machinename)))
> + ct->modelname = xstrdup(machinename);
> + }
> + }
> +
> return 0;
> }
>
> diff --git a/sys-utils/lscpu.h b/sys-utils/lscpu.h
> index bd7b64cc5..581602f70 100644
> --- a/sys-utils/lscpu.h
> +++ b/sys-utils/lscpu.h
> @@ -46,6 +46,7 @@ UL_DEBUG_DECLARE_MASK(lscpu);
> #define _PATH_SYS_NODE _PATH_SYS_SYSTEM "/node"
> #define _PATH_SYS_DMI "/sys/firmware/dmi/tables/DMI"
> #define _PATH_ACPI_PPTT "/sys/firmware/acpi/tables/PPTT"
> +#define _PATH_SOC_MACHINENAME "/sys/bus/soc/devices/soc0/machine"
>
> struct lscpu_cache {
> int id; /* unique identifier */
^ permalink raw reply
* [PATCH 2/2] lscpu-arm: Remove the "Ampere-1a" part.
From: Paul Benoit @ 2025-07-11 21:16 UTC (permalink / raw)
To: util-linux; +Cc: Paul Benoit
In-Reply-To: <20250711211648.53361-1-paul@os.amperecomputing.com>
Remove the "Ampere-1a" part. On newer Ampere Computing systems, the
system/model name will be obtained from /sys/bus/soc/devices/soc0/machine,
that is populated with the ARM SMC CC SOC_ID Name.
Signed-off-by: Paul Benoit <paul@os.amperecomputing.com>
---
sys-utils/lscpu-arm.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c
index 8745599d4..4ea555d86 100644
--- a/sys-utils/lscpu-arm.c
+++ b/sys-utils/lscpu-arm.c
@@ -268,7 +268,6 @@ static const struct id_part hisi_part[] = {
static const struct id_part ampere_part[] = {
{ 0xac3, "Ampere-1" },
- { 0xac4, "Ampere-1a" },
{ -1, "unknown" },
};
--
2.48.1
^ permalink raw reply related
* [PATCH 1/2] lscpu-arm: Allow externally sourced model name.
From: Paul Benoit @ 2025-07-11 21:16 UTC (permalink / raw)
To: util-linux; +Cc: Paul Benoit
When there isn't an entry for the model name in the id_part table(s),
attempt to get the machine name from /sys/bus/soc/devices/soc0/machine
to use as the model name. This mechanism allows lscpu to use the
model/machine name provided via the ARM SMC support code rather than via
hard-coded lscpu tables.
This code was tested by removing the "Ampere-1a" entry from the
ampere-part table and verifying that lscpu displayed the correct machine
name obtained via the ARM SMC interface to Trusted Firmware. The
"Ampere-1a" entry will be permanently removed by a separate patch.
Signed-off-by: Paul Benoit <paul@os.amperecomputing.com>
---
sys-utils/lscpu-arm.c | 35 ++++++++++++++++++++++++++++++++---
sys-utils/lscpu.h | 1 +
2 files changed, 33 insertions(+), 3 deletions(-)
diff --git a/sys-utils/lscpu-arm.c b/sys-utils/lscpu-arm.c
index 8745599d4..a46106bcb 100644
--- a/sys-utils/lscpu-arm.c
+++ b/sys-utils/lscpu-arm.c
@@ -388,7 +388,10 @@ int is_arm(struct lscpu_cxt *cxt)
static int arm_ids_decode(struct lscpu_cputype *ct)
{
int impl, part, j;
+ unsigned int i;
const struct id_part *parts = NULL;
+ FILE *fd;
+ char machinename[BUFSIZ] = "";
impl = parse_implementer_id(ct);
if (impl <= 0)
@@ -406,11 +409,11 @@ static int arm_ids_decode(struct lscpu_cputype *ct)
/* decode model */
if (!parts)
- goto done;
+ goto try_machinename;
part = parse_model_id(ct);
if (part <= 0)
- goto done;
+ goto try_machinename;
for (j = 0; parts[j].id != -1; j++) {
if (parts[j].id == part) {
@@ -419,7 +422,33 @@ static int arm_ids_decode(struct lscpu_cputype *ct)
break;
}
}
-done:
+
+try_machinename:
+
+ /*
+ * If the Model name was not found in the lscpu 'id_part' tables, see
+ * if there is a Machine name associated with the SOC. This name may
+ * have been set via either SOC specific support code, or obtained
+ * via an ARM SMC CC call into Trusted Firmware.
+ */
+ if (!ct->modelname) {
+ fd = ul_path_fopen(NULL, "r", _PATH_SOC_MACHINENAME);
+ if (fd) {
+ if (!fgets(machinename, sizeof(machinename), fd))
+ machinename[0] = '\0';
+ fclose(fd);
+
+ /* Replace newline with string terminator */
+ for (i = 0; i < strlen(machinename); i++) {
+ if (machinename[i] == '\n')
+ machinename[i] = '\0';
+ }
+
+ if (strnlen(machinename, sizeof(machinename)))
+ ct->modelname = xstrdup(machinename);
+ }
+ }
+
return 0;
}
diff --git a/sys-utils/lscpu.h b/sys-utils/lscpu.h
index bd7b64cc5..581602f70 100644
--- a/sys-utils/lscpu.h
+++ b/sys-utils/lscpu.h
@@ -46,6 +46,7 @@ UL_DEBUG_DECLARE_MASK(lscpu);
#define _PATH_SYS_NODE _PATH_SYS_SYSTEM "/node"
#define _PATH_SYS_DMI "/sys/firmware/dmi/tables/DMI"
#define _PATH_ACPI_PPTT "/sys/firmware/acpi/tables/PPTT"
+#define _PATH_SOC_MACHINENAME "/sys/bus/soc/devices/soc0/machine"
struct lscpu_cache {
int id; /* unique identifier */
--
2.48.1
^ permalink raw reply related
* Re: chrt from git segfaults
From: Benno Schulenberg @ 2025-07-10 8:11 UTC (permalink / raw)
To: Madadi Vineeth Reddy, util-linux; +Cc: Karel Zak
In-Reply-To: <3239b9c9-844e-40c0-9735-604842af6953@linux.ibm.com>
[-- Attachment #1.1: Type: text/plain, Size: 247 bytes --]
Op 09-07-2025 om 20:45 schreef Madadi Vineeth Reddy:
> Could you spin off a patch to make sure the priority argument is
> optional for policies that don’t need it, even when --pid is not used?
No. You broke it, you fix it.
Benno
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
^ permalink raw reply
* Re: chrt from git segfaults
From: Madadi Vineeth Reddy @ 2025-07-09 18:45 UTC (permalink / raw)
To: Benno Schulenberg, util-linux; +Cc: Karel Zak, Madadi Vineeth Reddy
In-Reply-To: <42f6841b-973d-4e18-b91b-6ef98ef85b9d@telfort.nl>
On 09/07/25 12:42, Benno Schulenberg wrote:
>
> Hello Vineeth,
>
> Just in case you missed the bug report buried in the previous message:
>
>> With current git, running `./chrt --other ls` says here:
>>
>> Segmentatiefout (geheugendump gemaakt)
>>
>> Running valgrind on it gives:
>>
>> ==38370== Invalid read of size 1
>> ==38370== by 0x10C6EB: main (chrt.c:574)
>>
>> Pointing to: if (strcmp(argv[0], "--") == 0)
>
> My patch will prevent that case from occurring. But if instead it
> should work, something needs fixing.
Could you spin off a patch to make sure the priority argument is
optional for policies that don’t need it, even when --pid is not used?
Thanks,
Madadi Vineeth Reddy
>
>
> Benno
^ permalink raw reply
* [PATCH 3/3] textual: harmonize the messages for invalid count and timeout values
From: Benno Schulenberg @ 2025-07-09 9:07 UTC (permalink / raw)
To: util-linux
In-Reply-To: <20250709090734.18263-1-bensberg@telfort.nl>
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
---
login-utils/sulogin.c | 2 +-
misc-utils/findmnt.c | 2 +-
misc-utils/uuidgen.c | 2 +-
misc-utils/waitpid.c | 5 ++---
sys-utils/flock.c | 3 +--
sys-utils/wdctl.c | 4 ++--
term-utils/agetty.c | 2 +-
term-utils/wall.c | 4 ++--
8 files changed, 11 insertions(+), 13 deletions(-)
diff --git a/login-utils/sulogin.c b/login-utils/sulogin.c
index 0de850508..eb4609db6 100644
--- a/login-utils/sulogin.c
+++ b/login-utils/sulogin.c
@@ -1037,7 +1037,7 @@ int main(int argc, char **argv)
while ((c = getopt_long(argc, argv, "ehpt:V", longopts, NULL)) != -1) {
switch(c) {
case 't':
- timeout = strtou32_or_err(optarg, _("invalid timeout argument"));
+ timeout = strtou32_or_err(optarg, _("invalid timeout"));
break;
case 'p':
profile = 1;
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
index ee9371e69..31350df78 100644
--- a/misc-utils/findmnt.c
+++ b/misc-utils/findmnt.c
@@ -1998,7 +1998,7 @@ int main(int argc, char *argv[])
findmnt.flags |= FL_UNIQ;
break;
case 'w':
- timeout = strtos32_or_err(optarg, _("invalid timeout argument"));
+ timeout = strtos32_or_err(optarg, _("invalid timeout"));
break;
case 'x':
verify = 1;
diff --git a/misc-utils/uuidgen.c b/misc-utils/uuidgen.c
index 6133cb0eb..8e07cdb65 100644
--- a/misc-utils/uuidgen.c
+++ b/misc-utils/uuidgen.c
@@ -147,7 +147,7 @@ main (int argc, char *argv[])
do_type = UUID_TYPE_DCE_MD5;
break;
case 'C':
- count = strtou32_or_err(optarg, _("invalid count argument"));
+ count = strtou32_or_err(optarg, _("invalid count"));
break;
case 's':
do_type = UUID_TYPE_DCE_SHA1;
diff --git a/misc-utils/waitpid.c b/misc-utils/waitpid.c
index f108206a9..b63532790 100644
--- a/misc-utils/waitpid.c
+++ b/misc-utils/waitpid.c
@@ -197,14 +197,13 @@ static int parse_options(int argc, char **argv)
verbose = true;
break;
case 't':
- strtotimespec_or_err(optarg, &timeout,
- _("Could not parse timeout"));
+ strtotimespec_or_err(optarg, &timeout, _("invalid timeout"));
break;
case 'e':
allow_exited = true;
break;
case 'c':
- count = str2num_or_err(optarg, 10, _("Invalid count"),
+ count = str2num_or_err(optarg, 10, _("invalid count"),
1, INT64_MAX);
break;
case 'V':
diff --git a/sys-utils/flock.c b/sys-utils/flock.c
index 6e58a1d51..fe1a71f72 100644
--- a/sys-utils/flock.c
+++ b/sys-utils/flock.c
@@ -273,8 +273,7 @@ int main(int argc, char *argv[])
break;
case 'w':
have_timeout = 1;
- strtotimeval_or_err(optarg, &timeout.it_value,
- _("invalid timeout value"));
+ strtotimeval_or_err(optarg, &timeout.it_value, _("invalid timeout"));
break;
case 'E':
conflict_exit_code = strtos32_or_err(optarg,
diff --git a/sys-utils/wdctl.c b/sys-utils/wdctl.c
index b3203d461..f3ae0e3f8 100644
--- a/sys-utils/wdctl.c
+++ b/sys-utils/wdctl.c
@@ -792,11 +792,11 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
break;
case 's':
- ctl.timeout = strtos32_or_err(optarg, _("invalid timeout argument"));
+ ctl.timeout = strtos32_or_err(optarg, _("invalid timeout"));
ctl.set_timeout = 1;
break;
case 'p':
- ctl.pretimeout = strtos32_or_err(optarg, _("invalid pretimeout argument"));
+ ctl.pretimeout = strtos32_or_err(optarg, _("invalid pretimeout"));
ctl.set_pretimeout = 1;
break;
case 'f':
diff --git a/term-utils/agetty.c b/term-utils/agetty.c
index f65e511ca..5e564c4f0 100644
--- a/term-utils/agetty.c
+++ b/term-utils/agetty.c
@@ -852,7 +852,7 @@ static void parse_args(int argc, char **argv, struct options *op)
op->flags |= F_KEEPSPEED;
break;
case 't':
- op->timeout = strtou32_or_err(optarg, _("invalid timeout argument"));
+ op->timeout = strtou32_or_err(optarg, _("invalid timeout"));
break;
case 'U':
op->flags |= F_LCUC;
diff --git a/term-utils/wall.c b/term-utils/wall.c
index 293275cb3..1152a1222 100644
--- a/term-utils/wall.c
+++ b/term-utils/wall.c
@@ -240,9 +240,9 @@ int main(int argc, char **argv)
warnx(_("--nobanner is available only for root"));
break;
case 't':
- timeout = strtou32_or_err(optarg, _("invalid timeout argument"));
+ timeout = strtou32_or_err(optarg, _("invalid timeout"));
if (timeout < 1)
- errx(EXIT_FAILURE, _("invalid timeout argument: %s"), optarg);
+ errx(EXIT_FAILURE, _("invalid timeout: %s"), optarg);
break;
case 'g':
group_buf = init_group_workspace(optarg);
--
2.48.2
^ permalink raw reply related
* [PATCH 2/3] textual: harmonize the messages for an invalid size, length, and offset
From: Benno Schulenberg @ 2025-07-09 9:07 UTC (permalink / raw)
To: util-linux
In-Reply-To: <20250709090734.18263-1-bensberg@telfort.nl>
The added words "argument" or "value" or "specified" don't make things
clearer and are just unneeded verbosity. Also, use all lowercase.
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
---
disk-utils/addpart.c | 2 +-
disk-utils/mkswap.c | 4 ++--
disk-utils/resizepart.c | 2 +-
misc-utils/blkid.c | 4 ++--
misc-utils/fadvise.c | 4 ++--
misc-utils/lsclocks.c | 2 +-
misc-utils/pipesz.c | 2 +-
misc-utils/wipefs.c | 2 +-
sys-utils/fallocate.c | 6 +++---
9 files changed, 14 insertions(+), 14 deletions(-)
diff --git a/disk-utils/addpart.c b/disk-utils/addpart.c
index 6bdb33662..5f45bbc3a 100644
--- a/disk-utils/addpart.c
+++ b/disk-utils/addpart.c
@@ -69,7 +69,7 @@ int main(int argc, char **argv)
if (partx_add_partition(fd,
strtou32_or_err(argv[2], _("invalid partition number argument")),
strtou64_or_err(argv[3], _("invalid start argument")),
- strtou64_or_err(argv[4], _("invalid length argument"))))
+ strtou64_or_err(argv[4], _("invalid length"))))
err(EXIT_FAILURE, _("failed to add partition"));
return EXIT_SUCCESS;
diff --git a/disk-utils/mkswap.c b/disk-utils/mkswap.c
index 609ecadd0..3cb7a043b 100644
--- a/disk-utils/mkswap.c
+++ b/disk-utils/mkswap.c
@@ -641,10 +641,10 @@ int main(int argc, char **argv)
break;
case 'o':
ctl.offset = str2unum_or_err(optarg,
- 10, _("Invalid offset"), SINT_MAX(off_t));
+ 10, _("invalid offset"), SINT_MAX(off_t));
break;
case 's':
- ctl.filesz = strtosize_or_err(optarg, _("Invalid size"));
+ ctl.filesz = strtosize_or_err(optarg, _("invalid size"));
break;
case 'F':
ctl.file = 1;
diff --git a/disk-utils/resizepart.c b/disk-utils/resizepart.c
index e29021b37..798dd3079 100644
--- a/disk-utils/resizepart.c
+++ b/disk-utils/resizepart.c
@@ -118,7 +118,7 @@ int main(int argc, char **argv)
wholedisk, argv[2]);
if (partx_resize_partition(fd, partno, start,
- strtou64_or_err(argv[3], _("invalid length argument"))))
+ strtou64_or_err(argv[3], _("invalid length"))))
err(EXIT_FAILURE, _("failed to resize partition"));
if (close_fd(fd) != 0)
diff --git a/misc-utils/blkid.c b/misc-utils/blkid.c
index 63e61b5fa..3960b0d97 100644
--- a/misc-utils/blkid.c
+++ b/misc-utils/blkid.c
@@ -813,7 +813,7 @@ int main(int argc, char **argv)
errx(BLKID_EXIT_OTHER, _("unsupported output format %s"), optarg);
break;
case 'O':
- ctl.offset = strtosize_or_err(optarg, _("invalid offset argument"));
+ ctl.offset = strtosize_or_err(optarg, _("invalid offset"));
break;
case 'p':
ctl.lowprobe_superblocks = 1;
@@ -826,7 +826,7 @@ int main(int argc, char **argv)
ctl.show[numtag++] = optarg;
break;
case 'S':
- ctl.size = strtosize_or_err(optarg, _("invalid size argument"));
+ ctl.size = strtosize_or_err(optarg, _("invalid size"));
break;
case 't':
if (search_type) {
diff --git a/misc-utils/fadvise.c b/misc-utils/fadvise.c
index abbc3a62d..da7fc691a 100644
--- a/misc-utils/fadvise.c
+++ b/misc-utils/fadvise.c
@@ -111,11 +111,11 @@ int main(int argc, char ** argv)
break;
case 'l':
len = strtosize_or_err(optarg,
- _("invalid length argument"));
+ _("invalid length"));
break;
case 'o':
offset = strtosize_or_err(optarg,
- _("invalid offset argument"));
+ _("invalid offset"));
break;
case 'V':
print_version(EXIT_SUCCESS);
diff --git a/misc-utils/lsclocks.c b/misc-utils/lsclocks.c
index 435894182..3fdec7ef2 100644
--- a/misc-utils/lsclocks.c
+++ b/misc-utils/lsclocks.c
@@ -266,7 +266,7 @@ static int64_t get_namespace_offset(const char *name)
space = strchr(line, ' ');
if (space)
*space = '\0';
- ret = strtos64_or_err(line, _("Invalid offset"));
+ ret = strtos64_or_err(line, _("invalid offset"));
break;
}
diff --git a/misc-utils/pipesz.c b/misc-utils/pipesz.c
index 0d1a2fc92..8a3da8612 100644
--- a/misc-utils/pipesz.c
+++ b/misc-utils/pipesz.c
@@ -269,7 +269,7 @@ int main(int argc, char **argv)
opt_quiet = TRUE;
break;
case 's':
- sz = strtosize_or_err(optarg, _("invalid size argument"));
+ sz = strtosize_or_err(optarg, _("invalid size"));
opt_size = sz >= INT_MAX ? INT_MAX : (int)sz;
++n_opt_size;
break;
diff --git a/misc-utils/wipefs.c b/misc-utils/wipefs.c
index a215088a4..b712ce700 100644
--- a/misc-utils/wipefs.c
+++ b/misc-utils/wipefs.c
@@ -737,7 +737,7 @@ main(int argc, char **argv)
break;
case 'o':
add_offset(&ctl.offsets, strtosize_or_err(optarg,
- _("invalid offset argument")));
+ _("invalid offset")));
break;
case 'p':
ctl.parsable = 1;
diff --git a/sys-utils/fallocate.c b/sys-utils/fallocate.c
index 7b65481cc..13bf52915 100644
--- a/sys-utils/fallocate.c
+++ b/sys-utils/fallocate.c
@@ -386,16 +386,16 @@ int main(int argc, char **argv)
if (length == -2LL)
length = 0;
if (length < 0)
- errx(EXIT_FAILURE, _("invalid length value specified"));
+ errx(EXIT_FAILURE, _("invalid length"));
} else {
/* it's safer to require the range specification (--length --offset) */
if (length == -2LL)
errx(EXIT_FAILURE, _("no length argument specified"));
if (length <= 0)
- errx(EXIT_FAILURE, _("invalid length value specified"));
+ errx(EXIT_FAILURE, _("invalid length"));
}
if (offset < 0)
- errx(EXIT_FAILURE, _("invalid offset value specified"));
+ errx(EXIT_FAILURE, _("invalid offset"));
/* O_CREAT makes sense only for the default fallocate(2) behavior
* when mode is no specified and new space is allocated */
--
2.48.2
^ permalink raw reply related
* [PATCH 1/3] column: call gettext() on an error message only when it gets printed
From: Benno Schulenberg @ 2025-07-09 9:07 UTC (permalink / raw)
To: util-linux
Just mark error messages for translation, with gettext_noop(), and pass
them untranslated to the subroutines. Then call gettext() on such a
message only when an error occurs and the message gets printed.
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
---
text-utils/column.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/text-utils/column.c b/text-utils/column.c
index c3321ae16..96120774c 100644
--- a/text-utils/column.c
+++ b/text-utils/column.c
@@ -323,7 +323,7 @@ static char **split_or_error(const char *str, const char *errmsg)
if (errno == ENOMEM)
err_oom();
if (errmsg)
- errx(EXIT_FAILURE, "%s: '%s'", errmsg, str);
+ errx(EXIT_FAILURE, "%s: '%s'", _(errmsg), str);
else
return NULL;
}
@@ -522,7 +522,7 @@ static void reorder_table(struct column_control *ctl)
struct libscols_column **wanted, *last = NULL;
size_t i, count = 0;
size_t ncols = scols_table_get_ncols(ctl->tab);
- char **order = split_or_error(ctl->tab_order, _("failed to parse --table-order list"));
+ char **order = split_or_error(ctl->tab_order, N_("failed to parse --table-order list"));
char **one;
wanted = xcalloc(ncols, sizeof(struct libscols_column *));
@@ -600,23 +600,23 @@ static void modify_table(struct column_control *ctl)
if (ctl->tab_colhide)
apply_columnflag_from_list(ctl, ctl->tab_colhide,
- SCOLS_FL_HIDDEN , _("failed to parse --table-hide list"));
+ SCOLS_FL_HIDDEN , N_("failed to parse --table-hide list"));
if (ctl->tab_colright)
apply_columnflag_from_list(ctl, ctl->tab_colright,
- SCOLS_FL_RIGHT, _("failed to parse --table-right list"));
+ SCOLS_FL_RIGHT, N_("failed to parse --table-right list"));
if (ctl->tab_coltrunc)
apply_columnflag_from_list(ctl, ctl->tab_coltrunc,
- SCOLS_FL_TRUNC , _("failed to parse --table-trunc list"));
+ SCOLS_FL_TRUNC , N_("failed to parse --table-trunc list"));
if (ctl->tab_colnoextrem)
apply_columnflag_from_list(ctl, ctl->tab_colnoextrem,
- SCOLS_FL_NOEXTREMES , _("failed to parse --table-noextreme list"));
+ SCOLS_FL_NOEXTREMES , N_("failed to parse --table-noextreme list"));
if (ctl->tab_colwrap)
apply_columnflag_from_list(ctl, ctl->tab_colwrap,
- SCOLS_FL_WRAP , _("failed to parse --table-wrap list"));
+ SCOLS_FL_WRAP , N_("failed to parse --table-wrap list"));
if (!ctl->tab_colnoextrem) {
struct libscols_column *cl = get_last_visible_column(ctl, 0);
@@ -1036,7 +1036,7 @@ int main(int argc, char **argv)
errx(EXIT_FAILURE, _("columns limit must be greater than zero"));
break;
case 'N':
- ctl.tab_colnames = split_or_error(optarg, _("failed to parse column names"));
+ ctl.tab_colnames = split_or_error(optarg, N_("failed to parse column names"));
break;
case 'n':
ctl.tab_name = optarg;
--
2.48.2
^ permalink raw reply related
* chrt from git segfaults
From: Benno Schulenberg @ 2025-07-09 7:12 UTC (permalink / raw)
To: Madadi Vineeth Reddy, util-linux; +Cc: Karel Zak
In-Reply-To: <e118a2c7-4e25-4240-b585-5de0ddf16d59@telfort.nl>
[-- Attachment #1.1: Type: text/plain, Size: 510 bytes --]
Hello Vineeth,
Just in case you missed the bug report buried in the previous message:
> With current git, running `./chrt --other ls` says here:
>
> Segmentatiefout (geheugendump gemaakt)
>
> Running valgrind on it gives:
>
> ==38370== Invalid read of size 1
> ==38370== by 0x10C6EB: main (chrt.c:574)
>
> Pointing to: if (strcmp(argv[0], "--") == 0)
My patch will prevent that case from occurring. But if instead it
should work, something needs fixing.
Benno
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
^ permalink raw reply
* High-speed, Bulk, Multi-threaded, Built-in Proxies ..
From: Email Marketing software . @ 2025-07-08 23:29 UTC (permalink / raw)
To: Email Marketing software .
Cc: jpoppleton, manfred.kuenzel, RPACKER, comex, info, wakehurst,
mcianfarano, jmcouture, principal, util-linux, jliang, librarian,
Chibudu, buchhaltung, catering, megan.thomas, Jason.Cegayle,
rdbros, watershedplanner, dthomson, media.relations, achalvashi
[-- Attachment #1.1: Type: text/plain, Size: 566 bytes --]
✔. Thousands to hundreds of thousands of emails sent per day.
✔. The only software on the market that uses Web mode + Http protocol to
send mail. It completely simulates the manual login and sending of Chrome
browser.
✔. One-click start, Http protocol,Fully Automated, High-speed, Bulk,
Multi-threaded,Built-in Proxies.
✔. Free full-featured trial for 3 days.
DEMO: youtu.be/vGpfyP18VLA
TG: wowofrom2008
*cracker contentiousinvalid contentiousbrighten contentiousrest
contentiousretelling contentiousvasilis contentious.*
[-- Attachment #1.2: Type: text/html, Size: 3468 bytes --]
^ permalink raw reply
* [PATCH] cpuset: Use stride in cpulist_create
From: Jesse Rosenstock @ 2025-07-08 12:20 UTC (permalink / raw)
To: util-linux
Format cpu lists for `taskset -c`, `lscpu`, etc. using stride. This
usually produces shorter output.
Now:
% ./taskset -c 0-24:2,25-47:4 ./taskset -pc 0
pid 3937653's current affinity list: 0-24:2,25-45:4
Previously:
% ./taskset -c 0-23:2,24-47:4 ./taskset -pc 0
pid 3933321's current affinity list:
0,2,4,6,8,10,12,14,16,18,20,22,24,28,32,36,40,44
The ranges are constructed greedily; in general it is difficult to
construct a minimal list.
% ./taskset -c 0-63:3,0-63:4 ./taskset -pc 0
pid 3926213's current affinity list:
0,3,4-8:2,9-15:3,16-20:2,21-27:3,28-32:2,33-39:3,40-44:2,45
The patch below uses spaces because gmail hates tabs. Tabs are used in the PR.
https://github.com/util-linux/util-linux/pull/3646
Signed-off-by: Jesse Rosenstock <jmr@google.com>
---
lib/cpuset.c | 75 +++++++++++++++++--------
tests/expected/lscpu/lscpu-x86_64-64cpu | 6 +-
tests/expected/misc/bits-list | 2 +-
tests/expected/misc/bits-parse-mask | 2 +-
tests/expected/schedutils/cpuset | 4 +-
5 files changed, 58 insertions(+), 31 deletions(-)
diff --git a/lib/cpuset.c b/lib/cpuset.c
index 533b8ab309b..d6469203092 100644
--- a/lib/cpuset.c
+++ b/lib/cpuset.c
@@ -147,43 +147,70 @@ int __cpuset_count_s(size_t setsize, const cpu_set_t *set)
}
#endif
+/*
+ * Finds the first CPU present after the specified index.
+ *
+ * start: starting index, inclusive.
+ * setsize: size of the set in *bytes*.
+ * set: CPU set to search.
+ *
+ * Return: the index of the first CPU present in `set`, starting at `start`.
+ * If no such CPU exists, returns the size of the set in *bits*.
+ */
+static size_t find_next_cpu(size_t start, size_t setsize, cpu_set_t *set)
+{
+ size_t nbits = cpuset_nbits(setsize);
+ for (; start < nbits; start++)
+ if (CPU_ISSET_S(start, setsize, set))
+ return start;
+ return start;
+}
+
/*
* Returns human readable representation of the cpuset. The output format is
- * a list of CPUs with ranges (for example, "0,1,3-9").
+ * a list of CPUs with ranges (for example, "0,1,3-9:3").
*/
char *cpulist_create(char *str, size_t len,
cpu_set_t *set, size_t setsize)
{
- size_t i;
char *ptr = str;
int entry_made = 0;
size_t max = cpuset_nbits(setsize);
-
- for (i = 0; i < max; i++) {
- if (CPU_ISSET_S(i, setsize, set)) {
- int rlen;
- size_t j, run = 0;
- entry_made = 1;
- for (j = i + 1; j < max; j++) {
- if (CPU_ISSET_S(j, setsize, set))
- run++;
- else
- break;
+ size_t a = 0; /* min for cpu range */
+ size_t next = 0; /* where to start looking for next cpu */
+
+ while ((a = find_next_cpu(next, setsize, set)) < max) {
+ int rlen;
+ next = find_next_cpu(a + 1, setsize, set);
+ if (next == max) {
+ rlen = snprintf(ptr, len, "%zu,", a);
+ } else {
+ /* Extend range as long as we have the same stride. */
+ size_t b = next;
+ size_t s = b - a;
+ while (((next = find_next_cpu(b + 1, setsize, set)) <
+ max) && next - b == s) {
+ b = next;
}
- if (!run)
- rlen = snprintf(ptr, len, "%zu,", i);
- else if (run == 1) {
- rlen = snprintf(ptr, len, "%zu,%zu,", i, i + 1);
- i++;
+ if (b - a == s) {
+ /*
+ * Only print one CPU. Hope the next one can
+ * be put in the next range.
+ */
+ rlen = snprintf(ptr, len, "%zu,", a);
+ next = b;
+ } else if (s == 1) {
+ rlen = snprintf(ptr, len, "%zu-%zu,", a, b);
} else {
- rlen = snprintf(ptr, len, "%zu-%zu,",
i, i + run);
- i += run;
+ rlen = snprintf(ptr, len, "%zu-%zu:%zu,",
+ a, b, s);
}
- if (rlen < 0 || (size_t) rlen >= len)
- return NULL;
- ptr += rlen;
- len -= rlen;
}
+ if (rlen < 0 || (size_t) rlen >= len)
+ return NULL;
+ ptr += rlen;
+ len -= rlen;
+ entry_made = 1;
}
ptr -= entry_made;
*ptr = '\0';
diff --git a/tests/expected/lscpu/lscpu-x86_64-64cpu
b/tests/expected/lscpu/lscpu-x86_64-64cpu
index b5b6c85c322..d359a6875e6 100644
--- a/tests/expected/lscpu/lscpu-x86_64-64cpu
+++ b/tests/expected/lscpu/lscpu-x86_64-64cpu
@@ -21,9 +21,9 @@ L1i cache: 1 MiB (32 instances)
L2 cache: 8 MiB (32 instances)
L3 cache: 72 MiB (4 instances)
NUMA node(s): 3
-NUMA node0 CPU(s):
0,2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36,38,40,42,44,46,48,50,52,54,56,58,60,62
-NUMA node2 CPU(s): 1,5,9,13,17,21,25,29,33,37,41,45,49,53,57,61
-NUMA node3 CPU(s): 3,7,11,15,19,23,27,31,35,39,43,47,51,55,59,63
+NUMA node0 CPU(s): 0-62:2
+NUMA node2 CPU(s): 1-61:4
+NUMA node3 CPU(s): 3-63:4
# The following is the parsable format, which can be fed to other
# programs. Each different item in every column has an unique ID
diff --git a/tests/expected/misc/bits-list b/tests/expected/misc/bits-list
index 7511e5378ea..e6c6d142a2f 100644
--- a/tests/expected/misc/bits-list
+++ b/tests/expected/misc/bits-list
@@ -1 +1 @@
-11,22,33,44
+11-44:11
diff --git a/tests/expected/misc/bits-parse-mask
b/tests/expected/misc/bits-parse-mask
index 59dd4b4c169..37b1257b85e 100644
--- a/tests/expected/misc/bits-parse-mask
+++ b/tests/expected/misc/bits-parse-mask
@@ -1 +1 @@
-1,3,6,7,9,11,14-16,18,19,21,23-25,27
+1,3,6,7-11:2,14-16,18,19-23:2,24,25,27
diff --git a/tests/expected/schedutils/cpuset b/tests/expected/schedutils/cpuset
index 10e17606c0e..695e75dc9f6 100644
--- a/tests/expected/schedutils/cpuset
+++ b/tests/expected/schedutils/cpuset
@@ -8,7 +8,7 @@ masks:
0x00000007 = 7 [0-2]
0x00000008 = 8 [3]
0x00000009 = 9 [0,3]
-0x00005555 = 5555 [0,2,4,6,8,10,12,14]
+0x00005555 = 5555 [0-14:2]
0x00007777 = 7777 [0-2,4-6,8-10,12-14]
strings:
0 = 1 [0]
@@ -20,5 +20,5 @@ strings:
0-2 = 7 [0-2]
3 = 8 [3]
0,3 = 9 [0,3]
-0,2,4,6,8,10,12,14 = 5555 [0,2,4,6,8,10,12,14]
+0,2,4,6,8,10,12,14 = 5555 [0-14:2]
0-2,4-6,8-10,12-14 = 7777 [0-2,4-6,8-10,12-14]
^ permalink raw reply related
* Re: btrfs device detection bug util-linux 2.39.4 to 2.41
From: Karel Zak @ 2025-07-07 11:24 UTC (permalink / raw)
To: Mio; +Cc: util-linux
In-Reply-To: <TY4PR01MB1385345D7813E44642723316E9243A@TY4PR01MB13853.jpnprd01.prod.outlook.com>
HI Mio,
On Thu, Jul 03, 2025 at 03:05:52PM +1200, Mio wrote:
> I found a bug affecting device detection of my btrfs filesystem with 3
> devices. My test system is currently running NixOS 25.05 with util-linux
> 2.41. I am able to run a older version of util-linux with the command `nix
> shell github:NixOS/nixpkgs/nixos-24.11#util-linux` which doesn't have the
> bug.
It would be nice to make your bug report a little more detailed.
The command "blkid" without any option can return cached information,
etc. The ideal is to call "blkid -p <devname>" and provide output from
the command. You can also use "LIBBLKID_DEBUG=all blkid -p <devname>"
to get debug output.
Were your disks used for ZFS before btrfs? If yes, you're probably
affected by https://github.com/util-linux/util-linux/issues/3613
Try "wipefs <device>" to get more information (don't worry, it does
not wipe anything from the device by default).
Karel
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply
* Re: [PATCH 3/4 V2] chrt: simplify the other check for too few arguments
From: Benno Schulenberg @ 2025-07-06 9:10 UTC (permalink / raw)
To: Madadi Vineeth Reddy, util-linux; +Cc: Karel Zak
In-Reply-To: <246a9986-6a79-46c5-9832-9cb9e30ba8ef@linux.ibm.com>
[-- Attachment #1.1: Type: text/plain, Size: 1017 bytes --]
Op 06-07-2025 om 07:58 schreef Madadi Vineeth Reddy:
> But priority should also be optional when --pid is not used, for
> policies that don’t require it.
Oh... Then the synopses need adjusting, because currently they
indicate the priority value as mandatory when a command is given:
chrt [options] priority command [argument...]
> With your patch, this fails:
> chrt --other ls
> chrt: too few arguments
> Try 'chrt --help' for more information.
>
> while this works:
> chrt --other 0 ls
>
> The first case should work too, to match the behavior introduced in
> commit e7a2d62434c2 ("chrt: Make priority optional for policies that don't use it").
With current git (or after checking out that commit), and then running
`./chrt --other ls`, it says here:
Segmentatiefout (geheugendump gemaakt)
Running valgrind on it gives:
==38370== Invalid read of size 1
==38370== by 0x10C6EB: main (chrt.c:574)
Pointing to: if (strcmp(argv[0], "--") == 0)
Benno
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 840 bytes --]
^ permalink raw reply
* Re: [PATCH 4/4 V2] chrt: do not try to interpret any other option as a PID either
From: Madadi Vineeth Reddy @ 2025-07-06 6:09 UTC (permalink / raw)
To: Benno Schulenberg, util-linux; +Cc: Karel Zak, Madadi Vineeth Reddy
In-Reply-To: <20250703144752.29971-4-bensberg@telfort.nl>
On 03/07/25 20:17, Benno Schulenberg wrote:
> When doing, for example, `chrt --pid --max`, it would report:
>
> chrt: invalid PID argument: '--max'
>
> This mistakenly gave the impression that the PID argument has to follow
> directly after the --pid option.
>
> Avoid this by delaying the parsing of a PID until after all options have
> been parsed. Temporarily set 'ctl->pid' to zero to indicate that a PID
> needs to be read.
>
> After this change, `chrt --pid --max` will simply report the minimum and
> maximum valid priorities. And `chrt --pid -v`:
According to help text,
chrt [options] --pid <priority> <pid>
I’m still not sure about allowing the --max option after --pid.
I’ll leave it to Karel to decide what’s best here.
Thanks,
Madadi Vineeth Reddy
>
> chrt: too few arguments
>
> Also, add a missing call of gettext() for the other error message.
>
> CC: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
> Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
> ---
> schedutils/chrt.c | 24 +++++++++++-------------
> 1 file changed, 11 insertions(+), 13 deletions(-)
>
> diff --git a/schedutils/chrt.c b/schedutils/chrt.c
> index 731f995bb..10ba7fbf6 100644
> --- a/schedutils/chrt.c
> +++ b/schedutils/chrt.c
> @@ -474,11 +474,7 @@ int main(int argc, char **argv)
> policy_given = true;
> break;
> case 'p':
> - if (argc - optind == 0)
> - errx(EXIT_FAILURE, _("too few arguments"));
> - errno = 0;
> - /* strtopid_or_err() is not suitable here; 0 can be passed.*/
> - ctl->pid = strtos32_or_err(argv[argc - 1], _("invalid PID argument"));
> + ctl->pid = 0; /* indicate that a PID is expected */
> break;
> case 'r':
> ctl->policy = SCHED_RR;
> @@ -507,20 +503,22 @@ int main(int argc, char **argv)
> }
> }
>
> - if (argc - optind < (ctl->pid > -1 ? 1 : 2)) {
> + if (argc - optind < (ctl->pid == 0 ? 1 : 2)) {
> warnx(_("too few arguments"));
> errtryhelp(EXIT_FAILURE);
> }
>
> - /* pid exists but priority not given */
> - if (ctl->pid > -1 && argc - optind == 1) {
> - /* Error if priority is missing for a policy that requires it */
> - if (policy_given && need_prio)
> - errx(EXIT_FAILURE, ("policy %s requires a priority argument"),
> + /* If option --pid was given, parse the very last argument as a PID. */
> + if (ctl->pid == 0) {
> + if (need_prio && argc - optind < 2)
> + errx(EXIT_FAILURE, _("policy %s requires a priority argument"),
> get_policy_name(ctl->policy));
> + errno = 0;
> + /* strtopid_or_err() is not suitable here, as 0 can be passed. */
> + ctl->pid = strtos32_or_err(argv[argc - 1], _("invalid PID argument"));
>
> - /* If no policy specified, show current settings */
> - if (!policy_given) {
> + /* If no policy nor priority was given, show current settings. */
> + if (!policy_given && argc - optind == 1) {
> show_sched_info(ctl);
> return EXIT_SUCCESS;
> }
^ permalink raw reply
* Re: [PATCH 3/4 V2] chrt: simplify the other check for too few arguments
From: Madadi Vineeth Reddy @ 2025-07-06 5:58 UTC (permalink / raw)
To: Benno Schulenberg, util-linux; +Cc: Karel Zak, Madadi Vineeth Reddy
In-Reply-To: <20250703144752.29971-3-bensberg@telfort.nl>
On 03/07/25 20:17, Benno Schulenberg wrote:
> Without option --pid, always at least two arguments are needed:
> the <priority> value and a <command>. (The 'need_prio' variable
> is relevant only for the --pid case.)
Yes, need_prio is only relevant for the --pid case as of now.
But priority should also be optional when --pid is not used, for
policies that don’t require it.
With your patch, this fails:
chrt --other ls
chrt: too few arguments
Try 'chrt --help' for more information.
while this works:
chrt --other 0 ls
The first case should work too, to match the behavior introduced in
commit e7a2d62434c2 ("chrt: Make priority optional for policies that don't use it").
Thanks,
Madadi Vineeth Reddy.
>
> Also, make the error message more informative.
>
> CC: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
> Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
> ---
>
> V2: left in the call errtryhelp()
>
> schedutils/chrt.c | 12 +++++-------
> 1 file changed, 5 insertions(+), 7 deletions(-)
>
> diff --git a/schedutils/chrt.c b/schedutils/chrt.c
> index a72c0de26..731f995bb 100644
> --- a/schedutils/chrt.c
> +++ b/schedutils/chrt.c
> @@ -507,9 +507,8 @@ int main(int argc, char **argv)
> }
> }
>
> - if (((ctl->pid > -1) && argc - optind < (need_prio ? 1 : 0)) ||
> - ((ctl->pid == -1) && argc - optind < (need_prio ? 2 : 1))) {
> - warnx(_("bad usage"));
> + if (argc - optind < (ctl->pid > -1 ? 1 : 2)) {
> + warnx(_("too few arguments"));
> errtryhelp(EXIT_FAILURE);
> }
>
> @@ -530,11 +529,10 @@ int main(int argc, char **argv)
> if (ctl->verbose)
> show_sched_info(ctl);
>
> - errno = 0;
> -
> - if (need_prio || argc - optind > 1)
> + if (argc - optind > 1) {
> + errno = 0;
> ctl->priority = strtos32_or_err(argv[optind], _("invalid priority argument"));
> - else
> + } else
> ctl->priority = 0;
>
> if (ctl->runtime && !supports_runtime_param(ctl->policy))
^ permalink raw reply
* [PATCH 4/4 V2] chrt: do not try to interpret any other option as a PID either
From: Benno Schulenberg @ 2025-07-03 14:47 UTC (permalink / raw)
To: util-linux; +Cc: Madadi Vineeth Reddy
In-Reply-To: <20250703144752.29971-1-bensberg@telfort.nl>
When doing, for example, `chrt --pid --max`, it would report:
chrt: invalid PID argument: '--max'
This mistakenly gave the impression that the PID argument has to follow
directly after the --pid option.
Avoid this by delaying the parsing of a PID until after all options have
been parsed. Temporarily set 'ctl->pid' to zero to indicate that a PID
needs to be read.
After this change, `chrt --pid --max` will simply report the minimum and
maximum valid priorities. And `chrt --pid -v`:
chrt: too few arguments
Also, add a missing call of gettext() for the other error message.
CC: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
---
schedutils/chrt.c | 24 +++++++++++-------------
1 file changed, 11 insertions(+), 13 deletions(-)
diff --git a/schedutils/chrt.c b/schedutils/chrt.c
index 731f995bb..10ba7fbf6 100644
--- a/schedutils/chrt.c
+++ b/schedutils/chrt.c
@@ -474,11 +474,7 @@ int main(int argc, char **argv)
policy_given = true;
break;
case 'p':
- if (argc - optind == 0)
- errx(EXIT_FAILURE, _("too few arguments"));
- errno = 0;
- /* strtopid_or_err() is not suitable here; 0 can be passed.*/
- ctl->pid = strtos32_or_err(argv[argc - 1], _("invalid PID argument"));
+ ctl->pid = 0; /* indicate that a PID is expected */
break;
case 'r':
ctl->policy = SCHED_RR;
@@ -507,20 +503,22 @@ int main(int argc, char **argv)
}
}
- if (argc - optind < (ctl->pid > -1 ? 1 : 2)) {
+ if (argc - optind < (ctl->pid == 0 ? 1 : 2)) {
warnx(_("too few arguments"));
errtryhelp(EXIT_FAILURE);
}
- /* pid exists but priority not given */
- if (ctl->pid > -1 && argc - optind == 1) {
- /* Error if priority is missing for a policy that requires it */
- if (policy_given && need_prio)
- errx(EXIT_FAILURE, ("policy %s requires a priority argument"),
+ /* If option --pid was given, parse the very last argument as a PID. */
+ if (ctl->pid == 0) {
+ if (need_prio && argc - optind < 2)
+ errx(EXIT_FAILURE, _("policy %s requires a priority argument"),
get_policy_name(ctl->policy));
+ errno = 0;
+ /* strtopid_or_err() is not suitable here, as 0 can be passed. */
+ ctl->pid = strtos32_or_err(argv[argc - 1], _("invalid PID argument"));
- /* If no policy specified, show current settings */
- if (!policy_given) {
+ /* If no policy nor priority was given, show current settings. */
+ if (!policy_given && argc - optind == 1) {
show_sched_info(ctl);
return EXIT_SUCCESS;
}
--
2.48.1
^ permalink raw reply related
* [PATCH 3/4 V2] chrt: simplify the other check for too few arguments
From: Benno Schulenberg @ 2025-07-03 14:47 UTC (permalink / raw)
To: util-linux; +Cc: Madadi Vineeth Reddy
In-Reply-To: <20250703144752.29971-1-bensberg@telfort.nl>
Without option --pid, always at least two arguments are needed:
the <priority> value and a <command>. (The 'need_prio' variable
is relevant only for the --pid case.)
Also, make the error message more informative.
CC: Madadi Vineeth Reddy <vineethr@linux.ibm.com>
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
---
V2: left in the call errtryhelp()
schedutils/chrt.c | 12 +++++-------
1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/schedutils/chrt.c b/schedutils/chrt.c
index a72c0de26..731f995bb 100644
--- a/schedutils/chrt.c
+++ b/schedutils/chrt.c
@@ -507,9 +507,8 @@ int main(int argc, char **argv)
}
}
- if (((ctl->pid > -1) && argc - optind < (need_prio ? 1 : 0)) ||
- ((ctl->pid == -1) && argc - optind < (need_prio ? 2 : 1))) {
- warnx(_("bad usage"));
+ if (argc - optind < (ctl->pid > -1 ? 1 : 2)) {
+ warnx(_("too few arguments"));
errtryhelp(EXIT_FAILURE);
}
@@ -530,11 +529,10 @@ int main(int argc, char **argv)
if (ctl->verbose)
show_sched_info(ctl);
- errno = 0;
-
- if (need_prio || argc - optind > 1)
+ if (argc - optind > 1) {
+ errno = 0;
ctl->priority = strtos32_or_err(argv[optind], _("invalid priority argument"));
- else
+ } else
ctl->priority = 0;
if (ctl->runtime && !supports_runtime_param(ctl->policy))
--
2.48.1
^ permalink raw reply related
* [PATCH 2/4 V2] chrt: do not try to interpret the --pid option itself as a PID
From: Benno Schulenberg @ 2025-07-03 14:47 UTC (permalink / raw)
To: util-linux
In-Reply-To: <20250703144752.29971-1-bensberg@telfort.nl>
When not specifying a PID with --pid, `chrt` would report:
chrt: invalid PID argument: '--pid'
That was silly. After this change, `chrt --pid` will report:
chrt: too few arguments
Signed-off-by: Benno Schulenberg <bensberg@telfort.nl>
---
schedutils/chrt.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/schedutils/chrt.c b/schedutils/chrt.c
index 415a9aa77..a72c0de26 100644
--- a/schedutils/chrt.c
+++ b/schedutils/chrt.c
@@ -474,6 +474,8 @@ int main(int argc, char **argv)
policy_given = true;
break;
case 'p':
+ if (argc - optind == 0)
+ errx(EXIT_FAILURE, _("too few arguments"));
errno = 0;
/* strtopid_or_err() is not suitable here; 0 can be passed.*/
ctl->pid = strtos32_or_err(argv[argc - 1], _("invalid PID argument"));
--
2.48.1
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox