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>
# 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"
#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"
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,