From: B. Wilson Date: Mon, 12 Apr 2021 15:29:58 +0000 (+0900) Subject: ras-record: Create RASSTATEDIR at runtime instead of install time X-Git-Tag: v0.6.7~12 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=9367354a4e57506a7090143e423fa620f86eeed1;p=users%2Fmchehab%2Frasdaemon.git ras-record: Create RASSTATEDIR at runtime instead of install time Package managers such as Nix and Guix force installation into an isolated directory hierarchy. Furthermore, said hierarchy becomes readonly after the install has completed, rendering any /var/lib/rasdaemon/ directory effectively useless. In addition to being standard practice, creating RASSTATEDIR when necessary at runtime fixes the above use cases. Signed-off-by: Mauro Carvalho Chehab --- diff --git a/Makefile.am b/Makefile.am index 2a04dff..821f5f9 100644 --- a/Makefile.am +++ b/Makefile.am @@ -92,7 +92,6 @@ upload: # custom target install-data-local: - $(install_sh) -d "$(DESTDIR)@RASSTATEDIR@" $(install_sh) -d "$(DESTDIR)@sysconfdir@/ras/dimm_labels.d" if WITH_MEMORY_CE_PFA $(install_sh) @abs_srcdir@/misc/rasdaemon.env "$(DESTDIR)@SYSCONFDEFDIR@/rasdaemon" diff --git a/ras-record.c b/ras-record.c index 25e0fe1..e1ac0d5 100644 --- a/ras-record.c +++ b/ras-record.c @@ -25,6 +25,8 @@ #include #include #include +#include +#include #include "ras-events.h" #include "ras-mc-handler.h" #include "ras-aer-handler.h" @@ -717,6 +719,21 @@ int ras_mc_event_opendb(unsigned cpu, struct ras_events *ras) if (!priv) return -1; + struct stat st = {0}; + if (stat(RASSTATEDIR, &st) == -1) { + if (errno != ENOENT) { + log(TERM, LOG_ERR, + "Failed to read state directory " RASSTATEDIR); + goto error; + } + + if (mkdir(RASSTATEDIR, 0700) == -1) { + log(TERM, LOG_ERR, + "Failed to create state directory " RASSTATEDIR); + goto error; + } + } + rc = sqlite3_initialize(); if (rc != SQLITE_OK) { log(TERM, LOG_ERR,