Skip to content

Commit 640c9dc

Browse files
devnexenhtejun
authored andcommitted
tools/sched_ext: fix getopt not re-parsed on restart
After goto restart, optind retains its advanced position from the previous getopt loop, causing getopt() to immediately return -1. This silently drops all command-line options on the restarted skeleton. Reset optind to 1 at the restart label so options are re-parsed. Affected schedulers: scx_simple, scx_central, scx_flatcg, scx_pair, scx_sdt, scx_cpu0. Signed-off-by: David Carlier <devnexen@gmail.com> Signed-off-by: Tejun Heo <tj@kernel.org>
1 parent f892f9f commit 640c9dc

6 files changed

Lines changed: 6 additions & 0 deletions

File tree

tools/sched_ext/scx_central.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ int main(int argc, char **argv)
5656
signal(SIGINT, sigint_handler);
5757
signal(SIGTERM, sigint_handler);
5858
restart:
59+
optind = 1;
5960
skel = SCX_OPS_OPEN(central_ops, scx_central);
6061

6162
skel->rodata->central_cpu = 0;

tools/sched_ext/scx_cpu0.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ int main(int argc, char **argv)
6969
signal(SIGINT, sigint_handler);
7070
signal(SIGTERM, sigint_handler);
7171
restart:
72+
optind = 1;
7273
skel = SCX_OPS_OPEN(cpu0_ops, scx_cpu0);
7374

7475
skel->rodata->nr_cpus = libbpf_num_possible_cpus();

tools/sched_ext/scx_flatcg.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ int main(int argc, char **argv)
141141
signal(SIGINT, sigint_handler);
142142
signal(SIGTERM, sigint_handler);
143143
restart:
144+
optind = 1;
144145
skel = SCX_OPS_OPEN(flatcg_ops, scx_flatcg);
145146

146147
skel->rodata->nr_cpus = libbpf_num_possible_cpus();

tools/sched_ext/scx_pair.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ int main(int argc, char **argv)
5353
signal(SIGINT, sigint_handler);
5454
signal(SIGTERM, sigint_handler);
5555
restart:
56+
optind = 1;
5657
skel = SCX_OPS_OPEN(pair_ops, scx_pair);
5758

5859
skel->rodata->nr_cpu_ids = libbpf_num_possible_cpus();

tools/sched_ext/scx_sdt.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ int main(int argc, char **argv)
5151
signal(SIGINT, sigint_handler);
5252
signal(SIGTERM, sigint_handler);
5353
restart:
54+
optind = 1;
5455
skel = SCX_OPS_OPEN(sdt_ops, scx_sdt);
5556

5657
while ((opt = getopt(argc, argv, "fvh")) != -1) {

tools/sched_ext/scx_simple.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ int main(int argc, char **argv)
7171
signal(SIGINT, sigint_handler);
7272
signal(SIGTERM, sigint_handler);
7373
restart:
74+
optind = 1;
7475
skel = SCX_OPS_OPEN(simple_ops, scx_simple);
7576

7677
while ((opt = getopt(argc, argv, "fvh")) != -1) {

0 commit comments

Comments
 (0)