{"record":{"id":"37a319e8bf0048fd","repo":"rustdesk/rustdesk","slug":"root-update-mktemp-output-error","errorCode":null,"errorMessage":"[root-update] mktemp output error: {}","messagePattern":"\\[root-update\\] mktemp output error: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/platform/macos.rs","lineNumber":1096,"sourceCode":"}\n\n/// Performs a silent update from a DMG file without any osascript dialog.\n/// Must be called from a process running as root (e.g. the service binary).\npub fn update_from_dmg_as_root(dmg_path: &str, expected_version: &str) -> ResultType<()> {\n    let app_name = crate::get_app_name();\n    if app_name.is_empty()\n        || !app_name\n            .bytes()\n            .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'_' | b'-'))\n    {\n        bail!(\"[root-update] unsafe application name\");\n    }\n    let app_bundle = format!(\"/Applications/{}.app\", app_name);\n    let tmp_dir_output = std::process::Command::new(\"/usr/bin/mktemp\")\n        .args(&[\"-d\", \"/tmp/.rustdeskupdate-root-XXXXXX\"])\n        .output()?;\n    let tmp_dir = String::from_utf8(tmp_dir_output.stdout)\n        .map_err(|e| anyhow!(\"[root-update] mktemp output error: {}\", e))?\n        .trim()\n        .to_string();\n    if tmp_dir.is_empty() {\n        bail!(\"[root-update] Failed to create temp directory\");\n    }\n    {\n        use std::os::unix::fs::PermissionsExt;\n        std::fs::set_permissions(&tmp_dir, std::fs::Permissions::from_mode(0o700))?;\n    }\n    let agent_plist = format!(\"/Library/LaunchAgents/com.carriez.{}_server.plist\", app_name);\n    let daemon_plist = format!(\"/Library/LaunchDaemons/com.carriez.{}_service.plist\", app_name);\n\n    log::info!(\"[root-update] Starting silent root update from {}\", dmg_path);\n    // Check sessions before extracting to avoid unnecessary work\n    if !crate::updater::has_no_active_conns_ipc() {\n        bail!(\"[root-update] Active session detected, deferring update.\");\n    }\n    // Extract DMG to temp dir","sourceCodeStart":1078,"sourceCodeEnd":1114,"githubUrl":"https://github.com/rustdesk/rustdesk/blob/91c9fccbb0f7bfe5f11644d5fbdec9b23fa10540/src/platform/macos.rs#L1078-L1114","documentation":"This error is raised in `update_from_dmg_as_root` (src/platform/macos.rs:1096) when the stdout of `/usr/bin/mktemp -d /tmp/.rustdeskupdate-root-XXXXXX` is not valid UTF-8. It is a wrapper around `String::from_utf8` failure, meaning the temp-directory path returned by mktemp contained invalid bytes — practically a system-level anomaly since mktemp emits plain ASCII paths.","triggerScenarios":"Calling `update_from_dmg_as_root` on a system where `/tmp` resolves to a path containing non-UTF-8 bytes (e.g. TMPDIR pointing to a directory with non-UTF-8 characters, or a modified mktemp wrapper producing binary output). Note `Command::new(\"/usr/bin/mktemp\")` ignores TMPDIR, so this usually implies a replaced/aliased binary or filesystem-level oddity.","commonSituations":"Systems with unusual locale/filesystem setups where /tmp is a symlink chain into non-UTF-8-named directories; security tooling or wrappers that intercept mktemp and emit extra non-text output; corrupted system files.","solutions":["Verify `/usr/bin/mktemp` is the genuine system binary (`which -a mktemp`, check for wrappers/aliases) and restore it if replaced.","Check that `/tmp` resolves to a plain ASCII path (`ls -ld /tmp`) and remove symlinks or mount points with non-UTF-8 names.","Confirm the filesystem hosting /tmp is HFS+/APFS, not a network or unusual filesystem that mangles names.","Retry the update after fixing the environment; if transient, re-running the update is safe because nothing has been staged yet."],"exampleFix":"// before: diagnostic\n$ ls -ld /tmp\nlrwxr-xr-x 1 root wheel 33 /tmp -> /private/tép\n// after: fix the link\n$ sudo ln -sfn /private/tmp /tmp","handlingStrategy":"try-catch","validationCode":"let out = std::process::Command::new(\"/usr/bin/mktemp\").args(&[\"-d\", \"/tmp/.t-XXXXXX\"]).output().ok()?;\nif out.status.success() && String::from_utf8(out.stdout).is_ok() && !out.stdout.is_empty() { Some(()) } else { None }","typeGuard":null,"tryCatchPattern":"match update_from_dmg_as_root(dmg, version) {\n    Err(e) if e.to_string().contains(\"mktemp output error\") => {\n        log::error!(\"mktemp emitted non-UTF-8 path; inspect /tmp and /usr/bin/mktemp: {}\", e);\n    }\n    other => other?,\n}","preventionTips":["Keep /tmp a plain ASCII HFS+/APFS path; avoid symlinking it into non-UTF-8-named directories.","Do not wrap or alias /usr/bin/mktemp with scripts that emit extra binary/text output on stdout.","Ensure the system locale/filesystem settings keep paths UTF-8-clean after OS upgrades.","Fail fast in your own tooling by validating any temp-path output with from_utf8 before use."],"tags":["rust","macos","utf-8","temp-directory","process-output"],"backgroundTag":"invalid-argument-format","analyzedSha":"91c9fccbb0f7bfe5f11644d5fbdec9b23fa10540","analyzedAt":"2026-09-10T19:53:44.083Z","contentChangedAt":"2026-09-10T19:53:44.083Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}