WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Conversation

@robo-monk
Copy link

Using a debugger such as GDB or CodeLLDB on a program that uses nob.h and depends something like this:

if (!nob_cmd_run(&cmd)) {
    fatal("Failed to run command");
  };

causes the debugging process to detach because of:

[ERROR] could not wait on command (pid 16237): Interrupted system call

This happens when a signal interrupts the waitpid() call, setting errno to EINTR.

This fix adds a retry logic for waitpid() to correctly handle EINTR, ensuring the command wait loop resumes normally instead of treating it as a fatal error.

@rexim
Copy link
Member

rexim commented Dec 28, 2025

Could you please provide more detailed instructions to reproduce the problem? I want to verify that the fix works on my side. Thank you!

@robo-monk
Copy link
Author

Hi Tsoding, happy new year!

  1. main.c
#include <signal.h>
#include <unistd.h>

#define NOB_IMPLEMENTATION
#include "nob.h"

  // add a breakpoint here
void breakpoint() {
  nob_log(NOB_INFO, "34 + 35");
} 


int main(void) {
  Nob_Cmd cmd = {0};
  nob_cmd_append(&cmd, "sleep", "2");

  nob_log(NOB_INFO, "Running command...");
  bool ok = nob_cmd_run(&cmd);

  nob_log(NOB_INFO, "Command ran: %s", ok ? "true" : "false");

  nob_cmd_free(cmd);

  breakpoint();

  return ok ? 0 : 1;
}
  1. compile && attach debugger
cc -g -o w main.c
lldb ./w
  1. add demo breakpoint and start execution
(lldb) b breakpoint
Breakpoint 1: 2 locations.
(lldb) r
Process 93430 launched: '/Users/monk/Documents/random_shit/ccomptime/w' (arm64)
[INFO] Running command...
[INFO] CMD: sleep 2
[ERROR] could not wait on command (pid 93500): Interrupted system call
[INFO] Command ran: false
Process 93430 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100007040 w`breakpoint at waitpid_eintr.c:9:3
   6
   7      // add a breakpoint here
   8    void breakpoint() {
-> 9      nob_log(NOB_INFO, "34 + 35");
   10   }
   11
   12
Target 0: (w) stopped.

The fix hopefully transforms the above into something like this:

(lldb) target create "./w"
Current executable set to '/Users/monk/Documents/random_shit/ccomptime/w' (arm64).
(lldb) b breakpoint
Breakpoint 1: 2 locations.
(lldb) r
Process 92350 launched: '/Users/monk/Documents/random_shit/ccomptime/w' (arm64)
[INFO] Running command...
[INFO] CMD: sleep 2
[INFO] Command ran: true
Process 92350 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = breakpoint 1.1
    frame #0: 0x0000000100007040 w`breakpoint at waitpid_eintr.c:9:3
   6
   7      // add a breakpoint here
   8    void breakpoint() {
-> 9      nob_log(NOB_INFO, "34 + 35");
   10   }
   11
   12
Target 0: (w) stopped.
(lldb) c
Process 92350 resuming
[INFO] 34 + 35
Process 92350 exited with status = 0 (0x00000000)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants