Skip to content

Commit

Permalink
The rasdaemon service may fail to be started for the first time.
Browse files Browse the repository at this point in the history
The rasdaemon creates a separate instance virtual directory on first startup, like `/sys/kernel/debug/tracing/instances/rasdaemon`.

After the directory is created, the kernel generates virtual files such as'trace_clock' and'set_event' in /sys/kernel/debug/tracing/instances/rasdaemon`.

The kernel generates virtual files and the rasdaemon accesses the virtual files at the same time. Therefore, the kernel may not generate the virtual files when the rasdaemon accesses the virtual files.

So add a 100 ms delay to give the kernel enough time to generate the files.
  • Loading branch information
zhuofeng committed Jun 29, 2024
1 parent efc150d commit b393b42
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion ras-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,39 @@ static int get_debugfs_dir(char *tracing_dir, size_t len)
return ENOENT;
}

static int wait_access(char *path, int ms)
{
int i;
for (i = 0; i < ms; i++) {
if (access(path, F_OK) == 0)
return 0;
usleep(1000);
}

log(ALL, LOG_WARNING, "wait_access() failed, %s not created in %d ms\n", path, ms);
return -1;
}

static int open_trace(struct ras_events *ras, char *name, int flags)
{
int ret = 0;
char fname[MAX_PATH + 1];

strcpy(fname, ras->tracing);
strcat(fname, "/");
strcat(fname, name);

return open(fname, flags);
ret = wait_access(fname, 100);
if (ret != 0) {
/* use -1 to keep same error value with open() */
return -1;
}

ret = open(fname, flags);
if (ret == -1)
log(ALL, LOG_WARNING, "open_trace()->open() failed, fname=%s ret=%d errno=%d\n", fname, ret, errno);

return ret;
}

static int get_tracing_dir(struct ras_events *ras)
Expand Down

0 comments on commit b393b42

Please sign in to comment.