]> www.infradead.org Git - users/mchehab/rasdaemon.git/commitdiff
ras-record: Create RASSTATEDIR at runtime instead of install time
authorB. Wilson <x@wilsonb.com>
Mon, 12 Apr 2021 15:29:58 +0000 (00:29 +0900)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Wed, 26 May 2021 07:02:17 +0000 (09:02 +0200)
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
<hierarchy>/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 <mchehab+huawei@kernel.org>
Makefile.am
ras-record.c

index 2a04dff1d0b5a2c9397b68025e02c4b9ac51f6d1..821f5f9d75be5db57a90903a509eae865cfc4e7b 100644 (file)
@@ -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"
index 25e0fe152584ffde44e8cfb9524aeb2113c1a942..e1ac0d56088f070ffccb85d44abfc4d8dd51c54b 100644 (file)
@@ -25,6 +25,8 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <errno.h>
+#include <sys/stat.h>
 #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,