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 up to 30 seconds to give the kernel enough time to generate the files.

Signed-off-by: zhuofeng <[email protected]>
Signed-off-by: Mauro Carvalho Chehab <[email protected]>
  • Loading branch information
zhuofeng authored and mchehab committed Nov 18, 2024
1 parent 7575b78 commit d22ed5e
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ras-events.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,19 @@ 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)
{
char fname[MAX_PATH + 1];
Expand All @@ -115,6 +128,12 @@ static int open_trace(struct ras_events *ras, char *name, int flags)
if (rc < 0)
return rc;

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

rc = open(fname, flags);
if (rc < 0) {
rc = -errno;
Expand Down

0 comments on commit d22ed5e

Please sign in to comment.