From: LeonardoBizzoni Date: Thu, 25 Sep 2025 16:22:14 +0000 (+0200) Subject: Print executable name on child process creation failure X-Git-Url: http://git.leonardobizzoni.com/?a=commitdiff_plain;h=1f21ea490e42d06c0c8e8596d1ee95cdcbc2cc5c;p=CBuild Print executable name on child process creation failure --- diff --git a/cbuild.h b/cbuild.h index 500b214..2fbce3a 100644 --- a/cbuild.h +++ b/cbuild.h @@ -580,8 +580,8 @@ internal CB_Process _cb_cmd_run(CB_Cmd *cmd, struct Cb_Cmd_RunArgs args) { FORMAT_MESSAGE_IGNORE_INSERTS, 0, error, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), (LPTSTR)&lpMsgBuf, 0, 0); - cb_println(CB_LogLevel_Error, "Child process creation failed with error %u: %s", - error, lpMsgBuf); + cb_println(CB_LogLevel_Error, "Child process `%s` creation failed with error %u: %s", + cmd->values[0], error, lpMsgBuf); exit(-1); } @@ -590,8 +590,8 @@ internal CB_Process _cb_cmd_run(CB_Cmd *cmd, struct Cb_Cmd_RunArgs args) { #else res.handle = fork(); if (res.handle < 0) { - cb_println(CB_LogLevel_Error, "Child process creation failed with error %d: %s\n", - errno, strerror(errno)); + cb_println(CB_LogLevel_Error, "Child process `%s` creation failed with error %d: %s\n", + cmd->values[0], errno, strerror(errno)); exit(-1); } else if (!res.handle) { if (args.stdout) { dup2(args.stdout, STDOUT_FILENO); } @@ -605,8 +605,8 @@ internal CB_Process _cb_cmd_run(CB_Cmd *cmd, struct Cb_Cmd_RunArgs args) { cb_cmd_append_dyn(&_cmd, cmd->values, cmd->count); cb_cmd_push(&_cmd, 0); if (execvp(_cmd.values[0], _cmd.values) < 0) { - cb_println(CB_LogLevel_Error, "Child process creation failed with error %d: %s\n", - errno, strerror(errno)); + cb_println(CB_LogLevel_Error, "Child process `%s` creation failed with error %d: %s\n", + cmd->values[0], errno, strerror(errno)); exit(-1); } // NOTE(lb): unreachable, execvp only returns on error. diff --git a/examples/02-async-commands/build.c b/examples/02-async-commands/build.c index 2256e7f..02aa16e 100644 --- a/examples/02-async-commands/build.c +++ b/examples/02-async-commands/build.c @@ -5,12 +5,19 @@ int main(int argc, char **argv) { CB_Cmd cmd = {}; CB_ProcessList procs = {}; +#if OS_WINDOWS + cb_cmd_append(&cmd, "cmd.exe", "/C", "dir"); + cb_proclist_push(&procs, cb_cmd_run(&cmd, .async = true)); + cb_cmd_append(&cmd, "cmd.exe", "/C", "dir", "C:\\"); + cb_proclist_push(&procs, cb_cmd_run(&cmd, .async = true)); +#else cb_cmd_append(&cmd, "ls", "-lah", "."); cb_proclist_push(&procs, cb_cmd_run(&cmd, .async = true)); cb_cmd_append(&cmd, "ls", "-lah", "/"); cb_proclist_push(&procs, cb_cmd_run(&cmd, .async = true)); cb_cmd_append(&cmd, "pwd"); cb_proclist_push(&procs, cb_cmd_run(&cmd, .async = true)); +#endif cb_proclist_wait(&procs); }