* [PATCH v2 1/8] rt-utils.c: Check return values of write()
2025-07-26 9:18 [PATCH v2 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
@ 2025-07-26 9:18 ` Cheng-Yang Chou
2025-09-26 17:38 ` John Kacur
2025-07-26 9:18 ` [PATCH v2 2/8] pmqtest.c: Check return values of write() and ftruncate() Cheng-Yang Chou
` (7 subsequent siblings)
8 siblings, 1 reply; 20+ messages in thread
From: Cheng-Yang Chou @ 2025-07-26 9:18 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv, yphbchou0911
Add error handling for write() to tracefs in tracemark() to avoid ignoring
partial or failed writes.
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
src/lib/rt-utils.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
index 6bbd25a..447e158 100644
--- a/src/lib/rt-utils.c
+++ b/src/lib/rt-utils.c
@@ -465,6 +465,7 @@ void tracemark(char *fmt, ...)
{
va_list ap;
int len;
+ int ret;
/* bail out if we're not tracing */
/* or if the kernel doesn't support trace_mark */
@@ -476,10 +477,14 @@ void tracemark(char *fmt, ...)
va_end(ap);
/* write the tracemark message */
- write(tracemark_fd, tracebuf, len);
+ ret = write(tracemark_fd, tracebuf, len);
+ if (ret != len)
+ warn("%s: write failed", __func__);
/* now stop any trace */
- write(trace_fd, "0\n", 2);
+ ret = write(trace_fd, "0\n", 2);
+ if (ret != 2)
+ warn("trace stop write failed");
}
void enable_trace_mark(void)
--
2.48.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v2 1/8] rt-utils.c: Check return values of write()
2025-07-26 9:18 ` [PATCH v2 1/8] rt-utils.c: Check return values of write() Cheng-Yang Chou
@ 2025-09-26 17:38 ` John Kacur
0 siblings, 0 replies; 20+ messages in thread
From: John Kacur @ 2025-09-26 17:38 UTC (permalink / raw)
To: Cheng-Yang Chou; +Cc: williams, linux-rt-users, jserv
On Sat, 26 Jul 2025, Cheng-Yang Chou wrote:
> Add error handling for write() to tracefs in tracemark() to avoid ignoring
> partial or failed writes.
>
> Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> ---
> src/lib/rt-utils.c | 9 +++++++--
> 1 file changed, 7 insertions(+), 2 deletions(-)
>
> diff --git a/src/lib/rt-utils.c b/src/lib/rt-utils.c
> index 6bbd25a..447e158 100644
> --- a/src/lib/rt-utils.c
> +++ b/src/lib/rt-utils.c
> @@ -465,6 +465,7 @@ void tracemark(char *fmt, ...)
> {
> va_list ap;
> int len;
> + int ret;
>
> /* bail out if we're not tracing */
> /* or if the kernel doesn't support trace_mark */
> @@ -476,10 +477,14 @@ void tracemark(char *fmt, ...)
> va_end(ap);
>
> /* write the tracemark message */
> - write(tracemark_fd, tracebuf, len);
> + ret = write(tracemark_fd, tracebuf, len);
> + if (ret != len)
> + warn("%s: write failed", __func__);
>
> /* now stop any trace */
> - write(trace_fd, "0\n", 2);
> + ret = write(trace_fd, "0\n", 2);
> + if (ret != 2)
> + warn("trace stop write failed");
> }
>
> void enable_trace_mark(void)
> --
- resolved merge conflict because an earlier patch changed tracemark()
and tracing_stop() since this was submitted
Signed-off-by: John Kacur <jkacur@redhat.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 2/8] pmqtest.c: Check return values of write() and ftruncate()
2025-07-26 9:18 [PATCH v2 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
2025-07-26 9:18 ` [PATCH v2 1/8] rt-utils.c: Check return values of write() Cheng-Yang Chou
@ 2025-07-26 9:18 ` Cheng-Yang Chou
2025-09-26 17:40 ` John Kacur
2025-07-26 9:18 ` [PATCH v2 3/8] ptsematest.c: " Cheng-Yang Chou
` (6 subsequent siblings)
8 siblings, 1 reply; 20+ messages in thread
From: Cheng-Yang Chou @ 2025-07-26 9:18 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv, yphbchou0911
Add error handling for write() to tracefs and ftruncate() on shared memory
to avoid ignoring errors.
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
src/pmqtest/pmqtest.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/pmqtest/pmqtest.c b/src/pmqtest/pmqtest.c
index 04e36a1..eb20baa 100644
--- a/src/pmqtest/pmqtest.c
+++ b/src/pmqtest/pmqtest.c
@@ -75,6 +75,7 @@ void *pmqthread(void *param)
int policy = SCHED_FIFO;
struct sched_param schedp;
struct timespec ts;
+ int ret;
memset(&schedp, 0, sizeof(schedp));
schedp.sched_priority = par->priority;
@@ -189,7 +190,10 @@ void *pmqthread(void *param)
int tracing_enabled =
open(tracing_enabled_file, O_WRONLY);
if (tracing_enabled >= 0) {
- write(tracing_enabled, "0", 1);
+ ret = write(tracing_enabled, "0", 1);
+ if (ret < 0)
+ fatal("Could not write to %s: %s\n",
+ tracing_enabled_file, strerror(errno));
close(tracing_enabled);
} else
fatal("Could not access %s\n", tracing_enabled_file);
--
2.48.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v2 2/8] pmqtest.c: Check return values of write() and ftruncate()
2025-07-26 9:18 ` [PATCH v2 2/8] pmqtest.c: Check return values of write() and ftruncate() Cheng-Yang Chou
@ 2025-09-26 17:40 ` John Kacur
0 siblings, 0 replies; 20+ messages in thread
From: John Kacur @ 2025-09-26 17:40 UTC (permalink / raw)
To: Cheng-Yang Chou; +Cc: williams, linux-rt-users, jserv
On Sat, 26 Jul 2025, Cheng-Yang Chou wrote:
> Add error handling for write() to tracefs and ftruncate() on shared memory
> to avoid ignoring errors.
>
> Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> ---
> src/pmqtest/pmqtest.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/src/pmqtest/pmqtest.c b/src/pmqtest/pmqtest.c
> index 04e36a1..eb20baa 100644
> --- a/src/pmqtest/pmqtest.c
> +++ b/src/pmqtest/pmqtest.c
> @@ -75,6 +75,7 @@ void *pmqthread(void *param)
> int policy = SCHED_FIFO;
> struct sched_param schedp;
> struct timespec ts;
> + int ret;
>
> memset(&schedp, 0, sizeof(schedp));
> schedp.sched_priority = par->priority;
> @@ -189,7 +190,10 @@ void *pmqthread(void *param)
> int tracing_enabled =
> open(tracing_enabled_file, O_WRONLY);
> if (tracing_enabled >= 0) {
> - write(tracing_enabled, "0", 1);
> + ret = write(tracing_enabled, "0", 1);
> + if (ret < 0)
> + fatal("Could not write to %s: %s\n",
> + tracing_enabled_file, strerror(errno));
> close(tracing_enabled);
> } else
> fatal("Could not access %s\n", tracing_enabled_file);
> --
> 2.48.1
>
>
>
Signed-off-by: John Kacur <jkacur@redhat.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 3/8] ptsematest.c: Check return values of write() and ftruncate()
2025-07-26 9:18 [PATCH v2 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
2025-07-26 9:18 ` [PATCH v2 1/8] rt-utils.c: Check return values of write() Cheng-Yang Chou
2025-07-26 9:18 ` [PATCH v2 2/8] pmqtest.c: Check return values of write() and ftruncate() Cheng-Yang Chou
@ 2025-07-26 9:18 ` Cheng-Yang Chou
2025-09-26 17:57 ` John Kacur
2025-07-26 9:18 ` [PATCH v2 4/8] rt-migrate-test.c: " Cheng-Yang Chou
` (5 subsequent siblings)
8 siblings, 1 reply; 20+ messages in thread
From: Cheng-Yang Chou @ 2025-07-26 9:18 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv, yphbchou0911
Add error handling for write() to tracefs and ftruncate() on shared memory
to avoid ignoring errors.
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
src/ptsematest/ptsematest.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/ptsematest/ptsematest.c b/src/ptsematest/ptsematest.c
index d211669..787909c 100644
--- a/src/ptsematest/ptsematest.c
+++ b/src/ptsematest/ptsematest.c
@@ -62,6 +62,7 @@ void *semathread(void *param)
cpu_set_t mask;
int policy = SCHED_FIFO;
struct sched_param schedp;
+ int ret;
memset(&schedp, 0, sizeof(schedp));
schedp.sched_priority = par->priority;
@@ -112,7 +113,10 @@ void *semathread(void *param)
int tracing_enabled =
open(tracing_enabled_file, O_WRONLY);
if (tracing_enabled >= 0) {
- write(tracing_enabled, "0", 1);
+ ret = write(tracing_enabled, "0", 1);
+ if (ret < 0)
+ fatal("Could not write to %s: %s\n",
+ tracing_enabled_file, strerror(errno));
close(tracing_enabled);
} else
fatal("Could not access %s\n",
--
2.48.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v2 3/8] ptsematest.c: Check return values of write() and ftruncate()
2025-07-26 9:18 ` [PATCH v2 3/8] ptsematest.c: " Cheng-Yang Chou
@ 2025-09-26 17:57 ` John Kacur
0 siblings, 0 replies; 20+ messages in thread
From: John Kacur @ 2025-09-26 17:57 UTC (permalink / raw)
To: Cheng-Yang Chou; +Cc: williams, linux-rt-users, jserv
On Sat, 26 Jul 2025, Cheng-Yang Chou wrote:
> Add error handling for write() to tracefs and ftruncate() on shared memory
> to avoid ignoring errors.
>
> Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> ---
> src/ptsematest/ptsematest.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
>
> diff --git a/src/ptsematest/ptsematest.c b/src/ptsematest/ptsematest.c
> index d211669..787909c 100644
> --- a/src/ptsematest/ptsematest.c
> +++ b/src/ptsematest/ptsematest.c
> @@ -62,6 +62,7 @@ void *semathread(void *param)
> cpu_set_t mask;
> int policy = SCHED_FIFO;
> struct sched_param schedp;
> + int ret;
>
> memset(&schedp, 0, sizeof(schedp));
> schedp.sched_priority = par->priority;
> @@ -112,7 +113,10 @@ void *semathread(void *param)
> int tracing_enabled =
> open(tracing_enabled_file, O_WRONLY);
> if (tracing_enabled >= 0) {
> - write(tracing_enabled, "0", 1);
> + ret = write(tracing_enabled, "0", 1);
> + if (ret < 0)
> + fatal("Could not write to %s: %s\n",
> + tracing_enabled_file, strerror(errno));
> close(tracing_enabled);
> } else
> fatal("Could not access %s\n",
> --
Signed-off-by: John Kacur <jkacur@redhat.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 4/8] rt-migrate-test.c: Check return values of write() and ftruncate()
2025-07-26 9:18 [PATCH v2 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
` (2 preceding siblings ...)
2025-07-26 9:18 ` [PATCH v2 3/8] ptsematest.c: " Cheng-Yang Chou
@ 2025-07-26 9:18 ` Cheng-Yang Chou
2025-09-26 19:49 ` John Kacur
2025-07-26 9:18 ` [PATCH v2 5/8] cyclicdeadline.c: " Cheng-Yang Chou
` (4 subsequent siblings)
8 siblings, 1 reply; 20+ messages in thread
From: Cheng-Yang Chou @ 2025-07-26 9:18 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv, yphbchou0911
Add error handling for write() to tracefs and ftruncate() on shared memory
to avoid ignoring errors.
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
src/rt-migrate-test/rt-migrate-test.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/src/rt-migrate-test/rt-migrate-test.c b/src/rt-migrate-test/rt-migrate-test.c
index 8afe083..e007ed7 100644
--- a/src/rt-migrate-test/rt-migrate-test.c
+++ b/src/rt-migrate-test/rt-migrate-test.c
@@ -61,6 +61,7 @@ static void ftrace_write(const char *fmt, ...)
{
va_list ap;
int n;
+ int ret;
if (mark_fd < 0)
return;
@@ -69,7 +70,9 @@ static void ftrace_write(const char *fmt, ...)
n = vsnprintf(buff, BUFSIZ, fmt, ap);
va_end(ap);
- write(mark_fd, buff, n);
+ ret = write(mark_fd, buff, n);
+ if (ret < 0)
+ fprintf(stderr, "%s: write failed\n", __func__);
}
#define nano2sec(nan) (nan / 1000000000ULL)
--
2.48.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v2 4/8] rt-migrate-test.c: Check return values of write() and ftruncate()
2025-07-26 9:18 ` [PATCH v2 4/8] rt-migrate-test.c: " Cheng-Yang Chou
@ 2025-09-26 19:49 ` John Kacur
0 siblings, 0 replies; 20+ messages in thread
From: John Kacur @ 2025-09-26 19:49 UTC (permalink / raw)
To: Cheng-Yang Chou; +Cc: williams, linux-rt-users, jserv
On Sat, 26 Jul 2025, Cheng-Yang Chou wrote:
> Add error handling for write() to tracefs and ftruncate() on shared memory
> to avoid ignoring errors.
>
> Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> ---
> src/rt-migrate-test/rt-migrate-test.c | 5 ++++-
> 1 file changed, 4 insertions(+), 1 deletion(-)
>
> diff --git a/src/rt-migrate-test/rt-migrate-test.c b/src/rt-migrate-test/rt-migrate-test.c
> index 8afe083..e007ed7 100644
> --- a/src/rt-migrate-test/rt-migrate-test.c
> +++ b/src/rt-migrate-test/rt-migrate-test.c
> @@ -61,6 +61,7 @@ static void ftrace_write(const char *fmt, ...)
> {
> va_list ap;
> int n;
> + int ret;
>
> if (mark_fd < 0)
> return;
> @@ -69,7 +70,9 @@ static void ftrace_write(const char *fmt, ...)
> n = vsnprintf(buff, BUFSIZ, fmt, ap);
> va_end(ap);
>
> - write(mark_fd, buff, n);
> + ret = write(mark_fd, buff, n);
> + if (ret < 0)
> + fprintf(stderr, "%s: write failed\n", __func__);
> }
>
> #define nano2sec(nan) (nan / 1000000000ULL)
> --
Signed-off-by: John Kacur <jkacur@redhat.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 5/8] cyclicdeadline.c: Check return values of write() and ftruncate()
2025-07-26 9:18 [PATCH v2 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
` (3 preceding siblings ...)
2025-07-26 9:18 ` [PATCH v2 4/8] rt-migrate-test.c: " Cheng-Yang Chou
@ 2025-07-26 9:18 ` Cheng-Yang Chou
2025-09-26 19:58 ` John Kacur
2025-07-26 9:18 ` [PATCH v2 6/8] deadline_test.c: " Cheng-Yang Chou
` (3 subsequent siblings)
8 siblings, 1 reply; 20+ messages in thread
From: Cheng-Yang Chou @ 2025-07-26 9:18 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv, yphbchou0911
Add error handling for write() to tracefs, cpuset control files, and
system() calls to avoid ignoring errors.
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
src/sched_deadline/cyclicdeadline.c | 32 ++++++++++++++++++++++++-----
1 file changed, 27 insertions(+), 5 deletions(-)
diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
index 04e61ed..6b5d3e0 100644
--- a/src/sched_deadline/cyclicdeadline.c
+++ b/src/sched_deadline/cyclicdeadline.c
@@ -206,6 +206,7 @@ static void ftrace_write(char *buf, const char *fmt, ...)
{
va_list ap;
int n;
+ int ret;
if (mark_fd < 0)
return;
@@ -214,7 +215,9 @@ static void ftrace_write(char *buf, const char *fmt, ...)
n = my_vsprintf(buf, BUFSIZ, fmt, ap);
va_end(ap);
- write(mark_fd, buf, n);
+ ret = write(mark_fd, buf, n);
+ if (ret < 0)
+ perror("ftrace write failed");
}
static void setup_ftrace_marker(void)
@@ -448,6 +451,10 @@ static int mount_cpuset(void)
if (fd < 0)
return fd;
ret = write(fd, "0", 2);
+ if (ret < 0) {
+ close(fd);
+ return ret;
+ }
close(fd);
return 0;
@@ -634,7 +641,14 @@ static void destroy_cpuset(const char *name, int print)
sprintf(buf, "%d", pid);
if (print)
printf("Moving %d out of %s\n", pid, name);
- write(fd, buf, strlen(buf));
+ ret = write(fd, buf, strlen(buf));
+ if (ret < 0 && errno == ENOSPC) {
+ fclose(fp);
+ close(fd);
+ fatal("Cannot move tasks out of cpuset %s\n", name);
+ }
+
+
}
fclose(fp);
close(fd);
@@ -656,19 +670,24 @@ static void destroy_cpuset(const char *name, int print)
static void teardown(void)
{
int fd;
+ int ret;
if (all_cpus)
return;
fd = open_cpuset(CPUSET_PATH, "cpuset.cpu_exclusive");
if (fd >= 0) {
- write(fd, "0", 2);
+ ret = write(fd, "0", 2);
+ if (ret < 0)
+ perror("cpuset.cpu_exclusive");
close(fd);
}
fd = open_cpuset(CPUSET_PATH, "cpuset.sched_load_balance");
if (fd >= 0) {
- write(fd, "1", 2);
+ ret = write(fd, "1", 2);
+ if (ret < 0)
+ perror("cpuset.sched_load_balance");
close(fd);
}
@@ -1164,6 +1183,7 @@ int main(int argc, char **argv)
int nr_cpus;
int i;
int c;
+ int ret;
rt_init(argc, argv);
@@ -1387,7 +1407,9 @@ int main(int argc, char **argv)
CPUSET_FL_CLONE_CHILDREN |
CPUSET_FL_TASKS, pids);
- system("cat /sys/fs/cgroup/cpuset/my_cpuset/tasks");
+ ret = system("cat /sys/fs/cgroup/cpuset/my_cpuset/tasks");
+ if (ret < 0)
+ perror("system call failed");
}
debug(debug_enable, "main thread %d\n", gettid());
--
2.48.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v2 5/8] cyclicdeadline.c: Check return values of write() and ftruncate()
2025-07-26 9:18 ` [PATCH v2 5/8] cyclicdeadline.c: " Cheng-Yang Chou
@ 2025-09-26 19:58 ` John Kacur
0 siblings, 0 replies; 20+ messages in thread
From: John Kacur @ 2025-09-26 19:58 UTC (permalink / raw)
To: Cheng-Yang Chou; +Cc: williams, linux-rt-users, jserv
On Sat, 26 Jul 2025, Cheng-Yang Chou wrote:
> Add error handling for write() to tracefs, cpuset control files, and
> system() calls to avoid ignoring errors.
>
> Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> ---
> src/sched_deadline/cyclicdeadline.c | 32 ++++++++++++++++++++++++-----
> 1 file changed, 27 insertions(+), 5 deletions(-)
>
> diff --git a/src/sched_deadline/cyclicdeadline.c b/src/sched_deadline/cyclicdeadline.c
> index 04e61ed..6b5d3e0 100644
> --- a/src/sched_deadline/cyclicdeadline.c
> +++ b/src/sched_deadline/cyclicdeadline.c
> @@ -206,6 +206,7 @@ static void ftrace_write(char *buf, const char *fmt, ...)
> {
> va_list ap;
> int n;
> + int ret;
>
> if (mark_fd < 0)
> return;
> @@ -214,7 +215,9 @@ static void ftrace_write(char *buf, const char *fmt, ...)
> n = my_vsprintf(buf, BUFSIZ, fmt, ap);
> va_end(ap);
>
> - write(mark_fd, buf, n);
> + ret = write(mark_fd, buf, n);
> + if (ret < 0)
> + perror("ftrace write failed");
> }
>
> static void setup_ftrace_marker(void)
> @@ -448,6 +451,10 @@ static int mount_cpuset(void)
> if (fd < 0)
> return fd;
> ret = write(fd, "0", 2);
> + if (ret < 0) {
> + close(fd);
> + return ret;
> + }
> close(fd);
>
> return 0;
> @@ -634,7 +641,14 @@ static void destroy_cpuset(const char *name, int print)
> sprintf(buf, "%d", pid);
> if (print)
> printf("Moving %d out of %s\n", pid, name);
> - write(fd, buf, strlen(buf));
> + ret = write(fd, buf, strlen(buf));
> + if (ret < 0 && errno == ENOSPC) {
> + fclose(fp);
> + close(fd);
> + fatal("Cannot move tasks out of cpuset %s\n", name);
> + }
> +
> +
> }
> fclose(fp);
> close(fd);
> @@ -656,19 +670,24 @@ static void destroy_cpuset(const char *name, int print)
> static void teardown(void)
> {
> int fd;
> + int ret;
>
> if (all_cpus)
> return;
>
> fd = open_cpuset(CPUSET_PATH, "cpuset.cpu_exclusive");
> if (fd >= 0) {
> - write(fd, "0", 2);
> + ret = write(fd, "0", 2);
> + if (ret < 0)
> + perror("cpuset.cpu_exclusive");
> close(fd);
> }
>
> fd = open_cpuset(CPUSET_PATH, "cpuset.sched_load_balance");
> if (fd >= 0) {
> - write(fd, "1", 2);
> + ret = write(fd, "1", 2);
> + if (ret < 0)
> + perror("cpuset.sched_load_balance");
> close(fd);
> }
>
> @@ -1164,6 +1183,7 @@ int main(int argc, char **argv)
> int nr_cpus;
> int i;
> int c;
> + int ret;
>
> rt_init(argc, argv);
>
> @@ -1387,7 +1407,9 @@ int main(int argc, char **argv)
> CPUSET_FL_CLONE_CHILDREN |
> CPUSET_FL_TASKS, pids);
>
> - system("cat /sys/fs/cgroup/cpuset/my_cpuset/tasks");
> + ret = system("cat /sys/fs/cgroup/cpuset/my_cpuset/tasks");
> + if (ret < 0)
> + perror("system call failed");
> }
>
> debug(debug_enable, "main thread %d\n", gettid());
> --
> 2.48.1
>
>
>
- Fixed merge conflict due to bd5967b42597 which removed
ftrace_write()
Signed-off-by: John Kacur <jkacur@redhat.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 6/8] deadline_test.c: Check return values of write() and ftruncate()
2025-07-26 9:18 [PATCH v2 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
` (4 preceding siblings ...)
2025-07-26 9:18 ` [PATCH v2 5/8] cyclicdeadline.c: " Cheng-Yang Chou
@ 2025-07-26 9:18 ` Cheng-Yang Chou
2025-09-26 20:00 ` John Kacur
2025-07-26 9:18 ` [PATCH v2 7/8] sigwaittest.c: " Cheng-Yang Chou
` (2 subsequent siblings)
8 siblings, 1 reply; 20+ messages in thread
From: Cheng-Yang Chou @ 2025-07-26 9:18 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv, yphbchou0911
Add error handling for write() to tracefs, cpuset control files, and
system() calls to avoid ignoring errors.
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
src/sched_deadline/deadline_test.c | 37 ++++++++++++++++++++++++++----
1 file changed, 32 insertions(+), 5 deletions(-)
diff --git a/src/sched_deadline/deadline_test.c b/src/sched_deadline/deadline_test.c
index ca2da47..a74d514 100644
--- a/src/sched_deadline/deadline_test.c
+++ b/src/sched_deadline/deadline_test.c
@@ -325,6 +325,7 @@ static void ftrace_write(char *buf, const char *fmt, ...)
{
va_list ap;
int n;
+ int ret;
if (mark_fd < 0)
return;
@@ -333,7 +334,9 @@ static void ftrace_write(char *buf, const char *fmt, ...)
n = my_vsprintf(buf, BUFSIZ, fmt, ap);
va_end(ap);
- write(mark_fd, buf, n);
+ ret = write(mark_fd, buf, n);
+ if (ret < 0)
+ perror("ftrace write failed");
}
/**
@@ -626,6 +629,10 @@ static int mount_cpuset(void)
if (fd < 0)
return fd;
ret = write(fd, "0", 2);
+ if (ret < 0) {
+ close(fd);
+ return ret;
+ }
close(fd);
return 0;
@@ -875,7 +882,19 @@ static void destroy_cpuset(const char *name, int print)
sprintf(buf, "%d", pid);
if (print)
printf("Moving %d out of %s\n", pid, name);
- write(fd, buf, strlen(buf));
+ ret = write(fd, buf, strlen(buf));
+ if (ret < 0 && errno == ENOSPC) {
+ /*
+ * If we get ENOSPC, then we have a problem, as it
+ * means that the cpuset is full, and we cannot move
+ * the tasks out of it.
+ */
+ fclose(fp);
+ close(fd);
+ fprintf(stderr, "Failed to move %d out of %s\n", pid, name);
+ perror("write");
+ return;
+ }
}
fclose(fp);
close(fd);
@@ -910,16 +929,21 @@ static void destroy_cpuset(const char *name, int print)
static void teardown(void)
{
int fd;
+ int ret;
fd = open_cpuset(CPUSET_PATH, "cpuset.cpu_exclusive");
if (fd >= 0) {
- write(fd, "0", 2);
+ ret = write(fd, "0", 2);
+ if (ret < 0)
+ perror("cpuset.cpu_exclusive");
close(fd);
}
fd = open_cpuset(CPUSET_PATH, "cpuset.sched_load_balance");
if (fd >= 0) {
- write(fd, "1", 2);
+ ret = write(fd, "1", 2);
+ if (ret < 0)
+ perror("cpuset.sched_load_balance");
close(fd);
}
@@ -1790,6 +1814,7 @@ int main(int argc, char **argv)
int rt_task = 0;
int i;
int c;
+ int ret;
cpu_count = sysconf(_SC_NPROCESSORS_CONF);
if (cpu_count < 1) {
@@ -2041,7 +2066,9 @@ int main(int argc, char **argv)
exit(-1);
}
- system("cat /sys/fs/cgroup/cpuset/my_cpuset/tasks");
+ ret = system("cat /sys/fs/cgroup/cpuset/my_cpuset/tasks");
+ if (ret < 0)
+ perror("system call failed");
}
pthread_barrier_wait(&barrier);
--
2.48.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v2 6/8] deadline_test.c: Check return values of write() and ftruncate()
2025-07-26 9:18 ` [PATCH v2 6/8] deadline_test.c: " Cheng-Yang Chou
@ 2025-09-26 20:00 ` John Kacur
0 siblings, 0 replies; 20+ messages in thread
From: John Kacur @ 2025-09-26 20:00 UTC (permalink / raw)
To: Cheng-Yang Chou; +Cc: williams, linux-rt-users, jserv
On Sat, 26 Jul 2025, Cheng-Yang Chou wrote:
> Add error handling for write() to tracefs, cpuset control files, and
> system() calls to avoid ignoring errors.
>
> Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> ---
> src/sched_deadline/deadline_test.c | 37 ++++++++++++++++++++++++++----
> 1 file changed, 32 insertions(+), 5 deletions(-)
>
> diff --git a/src/sched_deadline/deadline_test.c b/src/sched_deadline/deadline_test.c
> index ca2da47..a74d514 100644
> --- a/src/sched_deadline/deadline_test.c
> +++ b/src/sched_deadline/deadline_test.c
> @@ -325,6 +325,7 @@ static void ftrace_write(char *buf, const char *fmt, ...)
> {
> va_list ap;
> int n;
> + int ret;
>
> if (mark_fd < 0)
> return;
> @@ -333,7 +334,9 @@ static void ftrace_write(char *buf, const char *fmt, ...)
> n = my_vsprintf(buf, BUFSIZ, fmt, ap);
> va_end(ap);
>
> - write(mark_fd, buf, n);
> + ret = write(mark_fd, buf, n);
> + if (ret < 0)
> + perror("ftrace write failed");
> }
>
> /**
> @@ -626,6 +629,10 @@ static int mount_cpuset(void)
> if (fd < 0)
> return fd;
> ret = write(fd, "0", 2);
> + if (ret < 0) {
> + close(fd);
> + return ret;
> + }
> close(fd);
>
> return 0;
> @@ -875,7 +882,19 @@ static void destroy_cpuset(const char *name, int print)
> sprintf(buf, "%d", pid);
> if (print)
> printf("Moving %d out of %s\n", pid, name);
> - write(fd, buf, strlen(buf));
> + ret = write(fd, buf, strlen(buf));
> + if (ret < 0 && errno == ENOSPC) {
> + /*
> + * If we get ENOSPC, then we have a problem, as it
> + * means that the cpuset is full, and we cannot move
> + * the tasks out of it.
> + */
> + fclose(fp);
> + close(fd);
> + fprintf(stderr, "Failed to move %d out of %s\n", pid, name);
> + perror("write");
> + return;
> + }
> }
> fclose(fp);
> close(fd);
> @@ -910,16 +929,21 @@ static void destroy_cpuset(const char *name, int print)
> static void teardown(void)
> {
> int fd;
> + int ret;
>
> fd = open_cpuset(CPUSET_PATH, "cpuset.cpu_exclusive");
> if (fd >= 0) {
> - write(fd, "0", 2);
> + ret = write(fd, "0", 2);
> + if (ret < 0)
> + perror("cpuset.cpu_exclusive");
> close(fd);
> }
>
> fd = open_cpuset(CPUSET_PATH, "cpuset.sched_load_balance");
> if (fd >= 0) {
> - write(fd, "1", 2);
> + ret = write(fd, "1", 2);
> + if (ret < 0)
> + perror("cpuset.sched_load_balance");
> close(fd);
> }
>
> @@ -1790,6 +1814,7 @@ int main(int argc, char **argv)
> int rt_task = 0;
> int i;
> int c;
> + int ret;
>
> cpu_count = sysconf(_SC_NPROCESSORS_CONF);
> if (cpu_count < 1) {
> @@ -2041,7 +2066,9 @@ int main(int argc, char **argv)
> exit(-1);
> }
>
> - system("cat /sys/fs/cgroup/cpuset/my_cpuset/tasks");
> + ret = system("cat /sys/fs/cgroup/cpuset/my_cpuset/tasks");
> + if (ret < 0)
> + perror("system call failed");
> }
>
> pthread_barrier_wait(&barrier);
> --
> 2.48.1
>
>
>
Signed-off-by: John Kacur <jkacur@redhat.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 7/8] sigwaittest.c: Check return values of write() and ftruncate()
2025-07-26 9:18 [PATCH v2 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
` (5 preceding siblings ...)
2025-07-26 9:18 ` [PATCH v2 6/8] deadline_test.c: " Cheng-Yang Chou
@ 2025-07-26 9:18 ` Cheng-Yang Chou
2025-09-26 20:01 ` John Kacur
2025-07-26 9:18 ` [PATCH v2 8/8] svsematest.c: " Cheng-Yang Chou
2025-08-07 16:26 ` [PATCH v2 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
8 siblings, 1 reply; 20+ messages in thread
From: Cheng-Yang Chou @ 2025-07-26 9:18 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv, yphbchou0911
Add error handling for write() to tracefs and ftruncate() on shared memory
to avoid ignoring errors.
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
src/sigwaittest/sigwaittest.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/sigwaittest/sigwaittest.c b/src/sigwaittest/sigwaittest.c
index 026cc81..3944b54 100644
--- a/src/sigwaittest/sigwaittest.c
+++ b/src/sigwaittest/sigwaittest.c
@@ -72,6 +72,7 @@ void *semathread(void *param)
cpu_set_t mask;
int policy = SCHED_FIFO;
struct sched_param schedp;
+ int ret;
memset(&schedp, 0, sizeof(schedp));
schedp.sched_priority = par->priority;
@@ -168,7 +169,10 @@ void *semathread(void *param)
int tracing_enabled =
open(tracing_enabled_file, O_WRONLY);
if (tracing_enabled >= 0) {
- write(tracing_enabled, "0", 1);
+ ret = write(tracing_enabled, "0", 1);
+ if (ret < 0)
+ fatal("Could not write to %s: %s\n",
+ tracing_enabled_file, strerror(errno));
close(tracing_enabled);
} else
fatal("Could not access %s\n",
@@ -489,7 +493,12 @@ int main(int argc, char *argv[])
fprintf(stderr, "Could not create shared memory\n");
return 1;
}
- ftruncate(shmem, totalsize);
+ if (ftruncate(shmem, totalsize) == -1) {
+ perror("ftruncate failed");
+ close(shmem);
+ shm_unlink("/sigwaittest");
+ return 1;
+ }
param = mmap(0, totalsize, PROT_READ|PROT_WRITE, MAP_SHARED,
shmem, 0);
if (param == MAP_FAILED) {
--
2.48.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v2 7/8] sigwaittest.c: Check return values of write() and ftruncate()
2025-07-26 9:18 ` [PATCH v2 7/8] sigwaittest.c: " Cheng-Yang Chou
@ 2025-09-26 20:01 ` John Kacur
0 siblings, 0 replies; 20+ messages in thread
From: John Kacur @ 2025-09-26 20:01 UTC (permalink / raw)
To: Cheng-Yang Chou; +Cc: williams, linux-rt-users, jserv
On Sat, 26 Jul 2025, Cheng-Yang Chou wrote:
> Add error handling for write() to tracefs and ftruncate() on shared memory
> to avoid ignoring errors.
>
> Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> ---
> src/sigwaittest/sigwaittest.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/src/sigwaittest/sigwaittest.c b/src/sigwaittest/sigwaittest.c
> index 026cc81..3944b54 100644
> --- a/src/sigwaittest/sigwaittest.c
> +++ b/src/sigwaittest/sigwaittest.c
> @@ -72,6 +72,7 @@ void *semathread(void *param)
> cpu_set_t mask;
> int policy = SCHED_FIFO;
> struct sched_param schedp;
> + int ret;
>
> memset(&schedp, 0, sizeof(schedp));
> schedp.sched_priority = par->priority;
> @@ -168,7 +169,10 @@ void *semathread(void *param)
> int tracing_enabled =
> open(tracing_enabled_file, O_WRONLY);
> if (tracing_enabled >= 0) {
> - write(tracing_enabled, "0", 1);
> + ret = write(tracing_enabled, "0", 1);
> + if (ret < 0)
> + fatal("Could not write to %s: %s\n",
> + tracing_enabled_file, strerror(errno));
> close(tracing_enabled);
> } else
> fatal("Could not access %s\n",
> @@ -489,7 +493,12 @@ int main(int argc, char *argv[])
> fprintf(stderr, "Could not create shared memory\n");
> return 1;
> }
> - ftruncate(shmem, totalsize);
> + if (ftruncate(shmem, totalsize) == -1) {
> + perror("ftruncate failed");
> + close(shmem);
> + shm_unlink("/sigwaittest");
> + return 1;
> + }
> param = mmap(0, totalsize, PROT_READ|PROT_WRITE, MAP_SHARED,
> shmem, 0);
> if (param == MAP_FAILED) {
> --
> 2.48.1
>
>
>
Signed-off-by: John Kacur <jkacur@redhat.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* [PATCH v2 8/8] svsematest.c: Check return values of write() and ftruncate()
2025-07-26 9:18 [PATCH v2 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
` (6 preceding siblings ...)
2025-07-26 9:18 ` [PATCH v2 7/8] sigwaittest.c: " Cheng-Yang Chou
@ 2025-07-26 9:18 ` Cheng-Yang Chou
2025-09-26 20:03 ` John Kacur
2025-08-07 16:26 ` [PATCH v2 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
8 siblings, 1 reply; 20+ messages in thread
From: Cheng-Yang Chou @ 2025-07-26 9:18 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv, yphbchou0911
Add error handling for write() to tracefs and ftruncate() on shared memory
to avoid ignoring errors.
Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
---
src/svsematest/svsematest.c | 13 +++++++++++--
1 file changed, 11 insertions(+), 2 deletions(-)
diff --git a/src/svsematest/svsematest.c b/src/svsematest/svsematest.c
index f3cddf8..bdc82bc 100644
--- a/src/svsematest/svsematest.c
+++ b/src/svsematest/svsematest.c
@@ -84,6 +84,7 @@ void *semathread(void *param)
struct sched_param schedp;
struct sembuf sb = { 0, 0, 0};
sigset_t sigset;
+ int ret;
sigemptyset(&sigset);
pthread_sigmask(SIG_SETMASK, &sigset, NULL);
@@ -175,7 +176,10 @@ void *semathread(void *param)
int tracing_enabled =
open(tracing_enabled_file, O_WRONLY);
if (tracing_enabled >= 0) {
- write(tracing_enabled, "0", 1);
+ ret = write(tracing_enabled, "0", 1);
+ if (ret < 0)
+ fatal("Could not write to %s: %s\n",
+ tracing_enabled_file, strerror(errno));
close(tracing_enabled);
} else
fatal("Could not access %s\n",
@@ -544,7 +548,12 @@ int main(int argc, char *argv[])
fprintf(stderr, "Could not create shared memory\n");
return 1;
}
- ftruncate(shmem, totalsize);
+ if (ftruncate(shmem, totalsize) == -1) {
+ perror("ftruncate failed");
+ close(shmem);
+ shm_unlink("/sigwaittest");
+ return 1;
+ }
param = mmap(0, totalsize, PROT_READ|PROT_WRITE, MAP_SHARED,
shmem, 0);
if (param == MAP_FAILED) {
--
2.48.1
^ permalink raw reply related [flat|nested] 20+ messages in thread* Re: [PATCH v2 8/8] svsematest.c: Check return values of write() and ftruncate()
2025-07-26 9:18 ` [PATCH v2 8/8] svsematest.c: " Cheng-Yang Chou
@ 2025-09-26 20:03 ` John Kacur
0 siblings, 0 replies; 20+ messages in thread
From: John Kacur @ 2025-09-26 20:03 UTC (permalink / raw)
To: Cheng-Yang Chou; +Cc: williams, linux-rt-users, jserv
On Sat, 26 Jul 2025, Cheng-Yang Chou wrote:
> Add error handling for write() to tracefs and ftruncate() on shared memory
> to avoid ignoring errors.
>
> Signed-off-by: Cheng-Yang Chou <yphbchou0911@gmail.com>
> ---
> src/svsematest/svsematest.c | 13 +++++++++++--
> 1 file changed, 11 insertions(+), 2 deletions(-)
>
> diff --git a/src/svsematest/svsematest.c b/src/svsematest/svsematest.c
> index f3cddf8..bdc82bc 100644
> --- a/src/svsematest/svsematest.c
> +++ b/src/svsematest/svsematest.c
> @@ -84,6 +84,7 @@ void *semathread(void *param)
> struct sched_param schedp;
> struct sembuf sb = { 0, 0, 0};
> sigset_t sigset;
> + int ret;
>
> sigemptyset(&sigset);
> pthread_sigmask(SIG_SETMASK, &sigset, NULL);
> @@ -175,7 +176,10 @@ void *semathread(void *param)
> int tracing_enabled =
> open(tracing_enabled_file, O_WRONLY);
> if (tracing_enabled >= 0) {
> - write(tracing_enabled, "0", 1);
> + ret = write(tracing_enabled, "0", 1);
> + if (ret < 0)
> + fatal("Could not write to %s: %s\n",
> + tracing_enabled_file, strerror(errno));
> close(tracing_enabled);
> } else
> fatal("Could not access %s\n",
> @@ -544,7 +548,12 @@ int main(int argc, char *argv[])
> fprintf(stderr, "Could not create shared memory\n");
> return 1;
> }
> - ftruncate(shmem, totalsize);
> + if (ftruncate(shmem, totalsize) == -1) {
> + perror("ftruncate failed");
> + close(shmem);
> + shm_unlink("/sigwaittest");
> + return 1;
> + }
> param = mmap(0, totalsize, PROT_READ|PROT_WRITE, MAP_SHARED,
> shmem, 0);
> if (param == MAP_FAILED) {
> --
> 2.48.1
>
>
>
Signed-off-by: John Kacur <jkacur@redhat.com>
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v2 0/8] Fix -Wunused-result warnings by checking return values
2025-07-26 9:18 [PATCH v2 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
` (7 preceding siblings ...)
2025-07-26 9:18 ` [PATCH v2 8/8] svsematest.c: " Cheng-Yang Chou
@ 2025-08-07 16:26 ` Cheng-Yang Chou
2025-08-23 12:40 ` Cheng-Yang Chou
8 siblings, 1 reply; 20+ messages in thread
From: Cheng-Yang Chou @ 2025-08-07 16:26 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv
On Sat, Jul 26, 2025 at 05:18:29PM +0800, Cheng-Yang Chou wrote:
> This v2 series adds proper commit messages and addresses coding style
> warnings previously reported by checkpatch.pl.
>
> All patches have been verified with checkpatch.pl and show no errors
> or warnings.
>
> Changes in v2:
> - Add commit messages to all patches
> - Ensure all patches pass checkpatch cleanly
> - Link to v1: https://lore.kernel.org/all/20250712134213.58582-1-yphbchou0911@gmail.com/
Hi Clark and John,
Gentle ping.
Thanks
-chengyang
^ permalink raw reply [flat|nested] 20+ messages in thread* Re: [PATCH v2 0/8] Fix -Wunused-result warnings by checking return values
2025-08-07 16:26 ` [PATCH v2 0/8] Fix -Wunused-result warnings by checking return values Cheng-Yang Chou
@ 2025-08-23 12:40 ` Cheng-Yang Chou
2025-09-05 18:27 ` Cheng-Yang Chou
0 siblings, 1 reply; 20+ messages in thread
From: Cheng-Yang Chou @ 2025-08-23 12:40 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv
On Fri, Aug 08, 2025 at 12:26:03AM +0800, Cheng-Yang Chou wrote:
> On Sat, Jul 26, 2025 at 05:18:29PM +0800, Cheng-Yang Chou wrote:
> > This v2 series adds proper commit messages and addresses coding style
> > warnings previously reported by checkpatch.pl.
> >
> > All patches have been verified with checkpatch.pl and show no errors
> > or warnings.
> >
> > Changes in v2:
> > - Add commit messages to all patches
> > - Ensure all patches pass checkpatch cleanly
> > - Link to v1: https://lore.kernel.org/all/20250712134213.58582-1-yphbchou0911@gmail.com/
>
> Hi Clark and John,
>
> Gentle ping.
Gentle ping.
Thanks
-chengyang
^ permalink raw reply [flat|nested] 20+ messages in thread
* Re: [PATCH v2 0/8] Fix -Wunused-result warnings by checking return values
2025-08-23 12:40 ` Cheng-Yang Chou
@ 2025-09-05 18:27 ` Cheng-Yang Chou
0 siblings, 0 replies; 20+ messages in thread
From: Cheng-Yang Chou @ 2025-09-05 18:27 UTC (permalink / raw)
To: williams, jkacur; +Cc: linux-rt-users, jserv
On Sat, Aug 23, 2025 at 08:40:26PM +0800, Cheng-Yang Chou wrote:
> On Fri, Aug 08, 2025 at 12:26:03AM +0800, Cheng-Yang Chou wrote:
> > On Sat, Jul 26, 2025 at 05:18:29PM +0800, Cheng-Yang Chou wrote:
> > > This v2 series adds proper commit messages and addresses coding style
> > > warnings previously reported by checkpatch.pl.
> > >
> > > All patches have been verified with checkpatch.pl and show no errors
> > > or warnings.
> > >
> > > Changes in v2:
> > > - Add commit messages to all patches
> > > - Ensure all patches pass checkpatch cleanly
> > > - Link to v1: https://lore.kernel.org/all/20250712134213.58582-1-yphbchou0911@gmail.com/
> >
> > Hi Clark and John,
> >
> > Gentle ping.
>
> Gentle ping.
>
Gentle ping.
Thanks
-chengyang
^ permalink raw reply [flat|nested] 20+ messages in thread