ben-manes/caffeine · error

Fail to generate file %s\n

Error message

Fail to generate file %s\n

What it means

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.

Source

Thrown at simulator/src/main/resources/com/github/benmanes/caffeine/cache/simulator/parser/lirs/lirs.c:424

  old_ref_ptr->LIRS_next = new_ref_ptr->LIRS_next;
  old_ref_ptr->LIRS_prev = new_ref_ptr;

  if (new_ref_ptr->LIRS_next)
    new_ref_ptr->LIRS_next->LIRS_prev = old_ref_ptr;
  new_ref_ptr->LIRS_next = old_ref_ptr;

  return;
}

void print_lir_stack(int idx) {
  FILE *file;
  char path[256];
  page_struct *iter;

  sprintf(path, "%s-output-LIR-%d.log", trc_file_name, idx);
  file = fopen(path, "w");
  if (file == NULL) {
    fprintf(stderr, "Fail to generate file %s\n", path);
    exit(1);
  }

  fprintf(file, "** LIRS stack TOP **\n");
  for (iter = LRU_list_head;
       iter && LIR_LRU_block_ptr && iter != LIR_LRU_block_ptr->LIRS_next;
       iter = iter->LIRS_next) {
    fprintf(file, "<%s%s> %ld\n", iter->isResident ? "R" : "NR",
                          iter->isResident ? (iter->isHIR_block ? "H" : "L") : "",
                          iter->page_num);
  }
  fprintf(file, "** LIRS stack BOTTOM **\n");

  fclose(file);
}

void print_hir_queue(int idx) {
  FILE *file;

View on GitHub (pinned to 9da6581ee3)

Solutions

  1. Run the tool from a writable directory and/or pass a trace path whose directory is writable
  2. mkdir -p the output directory and chmod it for the running user
  3. Shorten the trace file path or run from the same directory so '<trace>-output-LIR-<idx>.log' fits within 256 bytes
  4. Free disk space / raise the open-file ulimit if df shows 100% or fopen fails with EMFILE

Example fix

# before
cd /opt/readonly && ./lirs /tmp/trace.dat 4096   # cannot create output file

# after
mkdir -p /tmp/lirs-out && cd /tmp/lirs-out && ./lirs /tmp/trace.dat 4096
Defensive patterns

Strategy: validation

Validate before calling

# verify the dump target is creatable before running
out_prefix="$(basename trace.dat)"
touch "./${out_prefix}-output-LIR-0.log" 2>/dev/null || { echo "output dir not writable"; exit 1; }
rm -f "./${out_prefix}-output-LIR-0.log"

Prevention

When it happens

Trigger: 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).

Common situations: 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.

Related errors


AI-assisted analysis of ben-manes/caffeine@9da6581ee3 (2026-08-14). Data as JSON: /api/errors/78e4fb5fae5fda8e. Report an issue: GitHub.