Good catch, thank you for that.

Here is v2 with the actions pulled out of the asserts so they survive
release builds.
How does this look?

Milos

On Sun, Apr 12, 2026 at 3:53 PM Samuel Thibault <[email protected]>
wrote:

> Milos Nikic, le dim. 12 avril 2026 15:46:04 -0700, a ecrit:
> > Added assertions to calls to fflush and getc,
> > removed an unused include and added one new.
> > ---
> >  libdiskfs/boot-start.c | 20 ++++++++++----------
> >  1 file changed, 10 insertions(+), 10 deletions(-)
> >
> > @@ -33,7 +34,6 @@
> >  #include <string.h>
> >  #include <argz.h>
> >  #include <error.h>
> > -#include "exec_S.h"
> >  #include "exec_startup_S.h"
> >  #include "fsys_S.h"
> >  #include "fsys_reply_U.h"
> > @@ -150,7 +150,7 @@ diskfs_start_bootstrap (void)
> >               Hurd server bootstrap: bootfs[bootdev] exec ourfs
> >        */
> >        printf ("\nContinuing on new root filesystem %s:",
> diskfs_disk_name);
> > -      fflush (stdout);
> > +      assert_backtrace (fflush (stdout) == 0);
>
> No, that won't fly in builds with NDEBUG defined, the content of the
> assert would then get dropped.
>
> Samuel
>
From 805bbaae2e6836e97b306c51d447c11e316e9ce7 Mon Sep 17 00:00:00 2001
From: Milos Nikic <[email protected]>
Date: Sun, 12 Apr 2026 15:43:49 -0700
Subject: [PATCH] libdiskfs: Cleanup of boot-start.c

Added assertions to calls to fflush and getc,
removed an unused include and added one new.
---
 libdiskfs/boot-start.c | 47 +++++++++++++++++++++++++++++++++---------
 1 file changed, 37 insertions(+), 10 deletions(-)

diff --git a/libdiskfs/boot-start.c b/libdiskfs/boot-start.c
index be47e1b8..bc09766e 100644
--- a/libdiskfs/boot-start.c
+++ b/libdiskfs/boot-start.c
@@ -20,6 +20,7 @@
 
 /* Written by Michael I. Bushnell.  */
 
+#include <assert-backtrace.h>
 #include "priv.h"
 #include <stdio.h>
 #include <hurd.h>
@@ -33,7 +34,6 @@
 #include <string.h>
 #include <argz.h>
 #include <error.h>
-#include "exec_S.h"
 #include "exec_startup_S.h"
 #include "fsys_S.h"
 #include "fsys_reply_U.h"
@@ -150,7 +150,10 @@ diskfs_start_bootstrap (void)
 	 	Hurd server bootstrap: bootfs[bootdev] exec ourfs
       */
       printf ("\nContinuing on new root filesystem %s:", diskfs_disk_name);
-      fflush (stdout);
+      if (fflush (stdout) != 0)
+        {
+          assert_backtrace (0);
+        }
     }
   else
     {
@@ -159,7 +162,10 @@ diskfs_start_bootstrap (void)
 
       printf ("Hurd server bootstrap: %s[%s]",
 	      program_invocation_short_name, diskfs_disk_name);
-      fflush (stdout);
+      if (fflush (stdout) != 0)
+        {
+          assert_backtrace (0);
+        }
 
       /* Get the execserver going and wait for its fsys_startup */
       pthread_mutex_init (&execstartlock, NULL);
@@ -270,7 +276,10 @@ diskfs_start_bootstrap (void)
     {
       printf ("\nCannot find startup program `%s': %s\n",
 	      initname, strerror (err));
-      fflush (stdout);
+      if (fflush (stdout) != 0)
+        {
+          assert_backtrace (0);
+        }
       free (exec_argv);
       assert_perror_backtrace (err);	/* XXX this won't reboot properly */
     }
@@ -307,11 +316,20 @@ diskfs_start_bootstrap (void)
   if (_diskfs_boot_pause)
     {
       printf ("pausing for %s...\n", exec_argv);
-      fflush (stdout);
-      getc (stdin);
+      if (fflush (stdout) != 0)
+        {
+          assert_backtrace (0);
+        }
+      if (getc (stdin) == EOF)
+        {
+          assert_backtrace (0);
+        }
     }
   printf (" %s", basename (exec_argv));
-  fflush (stdout);
+  if (fflush (stdout) != 0)
+    {
+      assert_backtrace (0);
+    }
   err = exec_exec (diskfs_exec, startup_pt, MACH_MSG_TYPE_COPY_SEND,
 		   newt, 0, (data_t)exec_argv, exec_argvlen, (data_t)exec_env, exec_envlen,
 		   fdarray, MACH_MSG_TYPE_COPY_SEND, 3,
@@ -696,12 +714,21 @@ start_execserver (void)
   if (_diskfs_boot_pause)
     {
       printf ("pausing for exec\n");
-      fflush (stdout);
-      getc (stdin);
+      if (fflush (stdout) != 0)
+        {
+          assert_backtrace (0);
+        }
+      if (getc (stdin) == EOF)
+        {
+          assert_backtrace (0);
+        }
     }
   err = task_resume (diskfs_exec_server_task);
   assert_perror_backtrace (err);
 
   printf (" exec");
-  fflush (stdout);
+  if (fflush (stdout) != 0)
+    {
+      assert_backtrace (0);
+    }
 }
-- 
2.53.0

Reply via email to