{"record":{"id":"78e4fb5fae5fda8e","repo":"ben-manes/caffeine","slug":"fail-to-generate-file-s-n","errorCode":null,"errorMessage":"Fail to generate file %s\\n","messagePattern":"Fail to generate file (.+?)\\\\n","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"simulator/src/main/resources/com/github/benmanes/caffeine/cache/simulator/parser/lirs/lirs.c","lineNumber":424,"sourceCode":"  old_ref_ptr->LIRS_next = new_ref_ptr->LIRS_next;\n  old_ref_ptr->LIRS_prev = new_ref_ptr;\n\n  if (new_ref_ptr->LIRS_next)\n    new_ref_ptr->LIRS_next->LIRS_prev = old_ref_ptr;\n  new_ref_ptr->LIRS_next = old_ref_ptr;\n\n  return;\n}\n\nvoid print_lir_stack(int idx) {\n  FILE *file;\n  char path[256];\n  page_struct *iter;\n\n  sprintf(path, \"%s-output-LIR-%d.log\", trc_file_name, idx);\n  file = fopen(path, \"w\");\n  if (file == NULL) {\n    fprintf(stderr, \"Fail to generate file %s\\n\", path);\n    exit(1);\n  }\n\n  fprintf(file, \"** LIRS stack TOP **\\n\");\n  for (iter = LRU_list_head;\n       iter && LIR_LRU_block_ptr && iter != LIR_LRU_block_ptr->LIRS_next;\n       iter = iter->LIRS_next) {\n    fprintf(file, \"<%s%s> %ld\\n\", iter->isResident ? \"R\" : \"NR\",\n                          iter->isResident ? (iter->isHIR_block ? \"H\" : \"L\") : \"\",\n                          iter->page_num);\n  }\n  fprintf(file, \"** LIRS stack BOTTOM **\\n\");\n\n  fclose(file);\n}\n\nvoid print_hir_queue(int idx) {\n  FILE *file;","sourceCodeStart":406,"sourceCodeEnd":442,"githubUrl":"https://github.com/ben-manes/caffeine/blob/9da6581ee366aa63c51e0dc96692d02f9c29ccff/simulator/src/main/resources/com/github/benmanes/caffeine/cache/simulator/parser/lirs/lirs.c#L406-L442","documentation":"print_lir_stack() dumps the LIRS stack to a file named '<trace>-output-LIR-<idx>.log' via fopen(path, \"w\"); if fopen returns NULL the tool prints this message with the offending path and exits(1). It means the output file could not be created — the directory does not exist, is not writable, the path is too long (it is built into a fixed 256-byte buffer), or the filesystem is full.","triggerScenarios":"trc_file_name points into a directory that does not exist or lacks write permission; running the tool in a read-only working directory (some CI sandboxes/containers); a trace file name so long that path[256] overflows/truncates; disk full (ENOSPC) at dump time; too many open files (EMFILE).","commonSituations":"Running the simulator's LIRS conversion from a directory where the user has no write permission (e.g. /usr/share); CI containers with read-only workspaces; embedded traces with absolute paths; NFS mounts mounted read-only.","solutions":["Run the tool from a writable directory and/or pass a trace path whose directory is writable","mkdir -p the output directory and chmod it for the running user","Shorten the trace file path or run from the same directory so '<trace>-output-LIR-<idx>.log' fits within 256 bytes","Free disk space / raise the open-file ulimit if df shows 100% or fopen fails with EMFILE"],"exampleFix":"# before\ncd /opt/readonly && ./lirs /tmp/trace.dat 4096   # cannot create output file\n\n# after\nmkdir -p /tmp/lirs-out && cd /tmp/lirs-out && ./lirs /tmp/trace.dat 4096","handlingStrategy":"validation","validationCode":"# verify the dump target is creatable before running\nout_prefix=\"$(basename trace.dat)\"\ntouch \"./${out_prefix}-output-LIR-0.log\" 2>/dev/null || { echo \"output dir not writable\"; exit 1; }\nrm -f \"./${out_prefix}-output-LIR-0.log\"","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always run the LIRS tool from a writable directory","Keep trace file names short so output paths stay under 256 chars","Pre-flight check with touch in the output directory","Ensure free disk space and adequate ulimit -n"],"tags":["c","file-io","simulator","lirs","exit-on-error","environment"],"backgroundTag":null,"analyzedSha":"9da6581ee366aa63c51e0dc96692d02f9c29ccff","analyzedAt":"2026-08-14T14:45:28.147Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}