{"record":{"id":"ed9886a53854b6d7","repo":"podman-container-tools/podman","slug":"error-getting-current-working-directory-m","errorCode":null,"errorMessage":"error getting current working directory: %m\n","messagePattern":"error getting current working directory: %m\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/rootless/rootless_linux.c","lineNumber":834,"sourceCode":"    {\n      cleanup_free char *cwd = NULL;\n      cleanup_close int userns_fd = -1;\n      cleanup_close int mntns_fd = -1;\n      cleanup_close int fd = -1;\n      long pid;\n      char buf[12];\n      uid_t uid;\n      gid_t gid;\n      char path[PATH_MAX];\n      char uid_fmt[16];\n      char gid_fmt[16];\n      size_t len;\n      int r;\n\n      cwd = getcwd (NULL, 0);\n      if (cwd == NULL)\n        {\n          fprintf (stderr, \"error getting current working directory: %m\\n\");\n          _exit (EXIT_FAILURE);\n        }\n\n      uid = geteuid ();\n      gid = getegid ();\n\n      len = snprintf (path, PATH_MAX, \"%s/libpod/tmp/ns_handles\", xdg_runtime_dir);\n      if (len >= PATH_MAX)\n        {\n          errno = ENAMETOOLONG;\n          fprintf (stderr, \"invalid value for XDG_RUNTIME_DIR: %m\");\n          exit (EXIT_FAILURE);\n        }\n\n      if (set_ns_handles (path) == 0)\n        goto joined;\n\n      /* If the handle is stale, give up with the shortcut.  */","sourceCodeStart":816,"sourceCodeEnd":852,"githubUrl":"https://github.com/podman-container-tools/podman/blob/a2409076ef2fef60ad9ac046375dedc7d9410ef4/pkg/rootless/rootless_linux.c#L816-L852","documentation":"On the no-re-exec shortcut path (non-root user, XDG_RUNTIME_DIR set, can_use_shortcut(argv) true), the preamble saves the current directory with getcwd(NULL, 0) so it can chdir back after joining the existing user+mount namespaces (pkg/rootless/rootless_linux.c:833-838). This message means getcwd failed - classically ENOENT when the cwd was deleted, EACCES when a parent directory is not searchable, or ENAMETOOLONG - and the process _exits.","triggerScenarios":"Invoking podman from a directory that has since been removed (e.g. 'cd /tmp/build && rm -rf /tmp/build && podman ...'); a cwd whose path traverses a directory without execute permission for the user; an automounted home that unmounted; a cwd deeper than PATH_MAX.","commonSituations":"CI pipelines that delete the workspace directory and then run podman from it; shells sitting in deleted temp dirs; home directories with 0700 perms owned by another user after uid changes; NFS homes after a remount.","solutions":["Change to an existing, accessible directory first: 'cd ~ && podman <cmd>'","Fix search permissions on the path leading to the cwd if it still exists","In scripts, always cd to a stable directory before removing the working directory","For automount issues, ensure the home mount is active before invoking podman"],"exampleFix":"# before\ncd /tmp/build\nrm -rf /tmp/build\npodman ps   # error getting current working directory: No such file or directory\n\n# after\nWORK=$(pwd); cd ~; rm -rf \"$WORK\"\npodman ps\n","handlingStrategy":"validation","validationCode":"# Verify the startup directory exists and is searchable before invoking podman\nif [ ! -d \"$PWD\" ] || [ ! -x \"$PWD\" ]; then\n  cd \"$HOME\" || exit 1\nfi\npodman \"$@\"\n","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In scripts, cd to a stable directory before deleting the current one","Avoid launching podman from just-removed temp/workspace directories","Ensure automounted home directories are mounted before podman runs"],"tags":["filesystem","cwd","rootless","environment","getcwd"],"backgroundTag":null,"analyzedSha":"a2409076ef2fef60ad9ac046375dedc7d9410ef4","analyzedAt":"2026-08-15T15:57:05.625Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}