calog/libs/calogProc.h

28 lines
1.6 KiB
C

// calogProc.h -- calog subprocess library: run a child process, capture its output.
//
// procRun(argv: list(string) [, opts: map]) -> map{ exit: int, stdout: string, stderr: string }
// Spawn argv[0] with the given arguments, wait for it, and return its exit code plus its
// captured stdout/stderr (binary-safe). On POSIX a child killed by a signal reports the
// negative signal number as exit. opts: { stdin: string (fed to the child), cwd: string
// (working directory), env: map (string->string; REPLACES the environment -- omit to inherit
// the parent's) }.
//
// POSIX starts the child with posix_spawn (NOT fork -- calog runs many pthreads, and fork in a
// multithreaded process is a well-known hazard) and multiplexes the three pipes with one poll loop.
// Windows starts it with CreateProcess and, because anonymous pipes have no poll, writes stdin on a
// helper thread while the main thread drains stdout/stderr; the argv list is quoted into a single
// command line. NOTE: on Windows a bare program name (no path separator) is resolved by
// CreateProcess's search order, which includes the application directory and the current directory
// AHEAD of PATH -- pass an absolute/relative path when that shadowing matters. Either way the native
// is inline and blocks the calling context's own thread until the child exits, feeding stdin while
// draining stdout/stderr so a large transfer cannot deadlock.
#ifndef CALOG_PROC_H
#define CALOG_PROC_H
#include "calog.h"
// Register the subprocess native on a runtime. Idempotent across runtimes (no shared state).
int32_t calogProcRegister(CalogT *calog);
#endif