{"record":{"id":"649b4673e7cc9ab1","repo":"xai-org/grok-build","slug":"daemonize-is-only-supported-on-unix-and-windows","errorCode":null,"errorMessage":"daemonize is only supported on Unix and Windows","messagePattern":"daemonize is only supported on Unix and Windows","errorType":"exception","errorClass":"io::Error","httpStatus":null,"severity":"error","filePath":"crates/codegen/xai-grok-workspace-daemon/src/daemonize.rs","lineNumber":202,"sourceCode":"        .create(true)\n        .append(true)\n        .open(log_path)?;\n\n    let handle = HANDLE(log.as_raw_handle());\n    // SAFETY: `handle` is a live file handle owned by `log`; SetStdHandle only\n    // records it as the process stdout/stderr. `forget(log)` keeps it open for\n    // the process lifetime (the std streams reference it now).\n    unsafe {\n        SetStdHandle(STD_OUTPUT_HANDLE, handle).map_err(io::Error::other)?;\n        SetStdHandle(STD_ERROR_HANDLE, handle).map_err(io::Error::other)?;\n    }\n    std::mem::forget(log);\n    Ok(())\n}\n\n#[cfg(not(any(unix, windows)))]\npub fn daemonize(_log_path: &Path) -> io::Result<()> {\n    Err(io::Error::new(\n        io::ErrorKind::Unsupported,\n        \"daemonize is only supported on Unix and Windows\",\n    ))\n}\n\n/// `fork()`; the parent exits 0, the child returns `Ok(())` to continue.\n#[cfg(unix)]\nfn fork_and_exit_parent() -> io::Result<()> {\n    // SAFETY: only called pre-runtime while single-threaded, so the fork\n    // cannot strand another thread's lock in the child.\n    match unsafe { libc::fork() } {\n        -1 => Err(io::Error::last_os_error()),\n        0 => Ok(()),\n        _ => process::exit(0),\n    }\n}\n\n/// `OpenOptions` for a daemon-owned file (log or pidfile).","sourceCodeStart":184,"sourceCodeEnd":220,"githubUrl":"https://github.com/xai-org/grok-build/blob/bc7f02eddd3d84085849dc19ed216f11c23b0571/crates/codegen/xai-grok-workspace-daemon/src/daemonize.rs#L184-L220","documentation":"daemonize() detaches the current process into a background daemon. This is implemented with platform-specific APIs that exist only on Unix and Windows; on any other target (e.g. wasm32) the function is compiled to a stub that always returns io::ErrorKind::Unsupported with 'daemonize is only supported on Unix and Windows'.","triggerScenarios":"Calling xai_grok_workspace_daemon::daemonize() (with any log_path) while compiled for a target other than unix or windows, such as wasm32-unknown-unknown or embedded targets.","commonSituations":"Cross-compiling the workspace daemon for wasm/browser or embedded targets where fork/detach APIs do not exist; building a universal abstraction layer that calls daemonize unconditionally.","solutions":["Build and run the daemon only on unix or windows targets (check cfg!(any(unix, windows)) before calling).","Gate the daemonize call behind a compile-time cfg or runtime feature so unsupported targets skip daemonization.","On unsupported targets, run the work directly in-process instead of daemonizing."],"exampleFix":"// before\ndaemonize(&log_path)?;\n// after\n#[cfg(any(unix, windows))]\ndaemonize(&log_path)?;\n#[cfg(not(any(unix, windows)))]\nreturn Err(\"daemonize unsupported on this target\".into());","handlingStrategy":"type-guard","validationCode":"fn daemonize_supported() -> bool {\n    cfg!(any(unix, windows))\n}\n// only call daemonize when true","typeGuard":null,"tryCatchPattern":"match daemonize(&log_path) {\n    Ok(()) => { /* daemonized */ }\n    Err(e) if e.kind() == std::io::ErrorKind::Unsupported => {\n        eprintln!(\"daemonize unsupported here; running in foreground\");\n        run_in_foreground()?;\n    }\n    Err(e) => return Err(e.into()),\n}","preventionTips":["Gate daemonize calls behind #[cfg(any(unix, windows))]","Add a CI build for non-unix/windows targets to catch the stub early","Provide an explicit foreground-mode fallback in your supervisor code"],"tags":["platform","daemon","unsupported"],"backgroundTag":"unsupported-platform","analyzedSha":"bc7f02eddd3d84085849dc19ed216f11c23b0571","analyzedAt":"2026-08-31T04:59:42.031Z","schemaVersion":2},"datasetVersion":"2026-08-31T09:17:48.483Z"}