From: John Kacur <jkacur@redhat.com>
To: Cheng-Yang Chou <yphbchou0911@gmail.com>
Cc: williams@redhat.com, linux-rt-users@vger.kernel.org,
jserv@ccns.ncku.edu.tw
Subject: Re: [PATCH v2 6/8] deadline_test.c: Check return values of write() and ftruncate()
Date: Fri, 26 Sep 2025 16:00:09 -0400 (EDT) [thread overview]
Message-ID: <b8b68d23-bc6d-e580-b974-310fa93ab8be@redhat.com> (raw)
In-Reply-To: <20250726091837.493915-7-yphbchou0911@gmail.com>
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>
next prev parent reply other threads:[~2025-09-26 20:00 UTC|newest]
Thread overview: 20+ messages / expand[flat|nested] mbox.gz Atom feed top
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-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
2025-09-26 17:40 ` John Kacur
2025-07-26 9:18 ` [PATCH v2 3/8] ptsematest.c: " 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
2025-09-26 19:49 ` John Kacur
2025-07-26 9:18 ` [PATCH v2 5/8] cyclicdeadline.c: " 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
2025-09-26 20:00 ` John Kacur [this message]
2025-07-26 9:18 ` [PATCH v2 7/8] sigwaittest.c: " 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-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
2025-08-23 12:40 ` Cheng-Yang Chou
2025-09-05 18:27 ` Cheng-Yang Chou
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=b8b68d23-bc6d-e580-b974-310fa93ab8be@redhat.com \
--to=jkacur@redhat.com \
--cc=jserv@ccns.ncku.edu.tw \
--cc=linux-rt-users@vger.kernel.org \
--cc=williams@redhat.com \
--cc=yphbchou0911@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.