Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:coolo:alp:workbench
libdlm
bug-1191734_0002-dlm_controld-create-var-parent...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File bug-1191734_0002-dlm_controld-create-var-parent-directories.patch of Package libdlm
From 4c774ebe7358d4ce773502d1703046c29371b4ec Mon Sep 17 00:00:00 2001 From: Alexander Aring <aahringo@redhat.com> Date: Wed, 31 Mar 2021 16:20:42 -0400 Subject: [PATCH 02/14] dlm_controld: create var parent directories This patch creates /var/log/dlm_controld and /var/run/dlm_controld and it's parents if not exists before. In case of logging there was a likely issue no log file is created when /var/log/dlm_controld didn't exists before starting dlm_controld. Reported-by: Bob Peterson <rpeterso@redhat.com> --- dlm_controld/dlm_daemon.h | 8 ++++++-- dlm_controld/logging.c | 24 ++++++++++++++++++++++++ dlm_controld/main.c | 20 ++++++++++++++++---- 3 files changed, 46 insertions(+), 6 deletions(-) diff --git a/dlm_controld/dlm_daemon.h b/dlm_controld/dlm_daemon.h index 45b295eafe2b..436fc9109aa6 100644 --- a/dlm_controld/dlm_daemon.h +++ b/dlm_controld/dlm_daemon.h @@ -65,8 +65,12 @@ /* TODO: get CONFDIR, LOGDIR, RUNDIR from build */ -#define RUNDIR "/var/run/dlm_controld" -#define LOGDIR "/var/log/dlm_controld" +#define SYS_VARDIR "/var" +#define SYS_RUNDIR SYS_VARDIR "/run" +#define SYS_LOGDIR SYS_VARDIR "/log" + +#define RUNDIR SYS_RUNDIR "/dlm_controld" +#define LOGDIR SYS_LOGDIR "/dlm_controld" #define CONFDIR "/etc/dlm" #define RUN_FILE_NAME "dlm_controld.pid" diff --git a/dlm_controld/logging.c b/dlm_controld/logging.c index 4aa3406c0725..d48b8aebc237 100644 --- a/dlm_controld/logging.c +++ b/dlm_controld/logging.c @@ -16,6 +16,9 @@ static FILE *logfile_fp; void init_logging(void) { + mode_t old_umask; + int rv; + syslog_facility = DEFAULT_SYSLOG_FACILITY; syslog_priority = DEFAULT_SYSLOG_PRIORITY; logfile_priority = DEFAULT_LOGFILE_PRIORITY; @@ -28,6 +31,26 @@ void init_logging(void) logfile_priority = LOG_DEBUG; if (logfile[0]) { + old_umask = umask(0077); + rv = mkdir(SYS_VARDIR, 0700); + if (rv < 0 && errno != EEXIST) { + umask(old_umask); + goto skip_logfile; + } + + rv = mkdir(SYS_LOGDIR, 0700); + if (rv < 0 && errno != EEXIST) { + umask(old_umask); + goto skip_logfile; + } + + rv = mkdir(LOGDIR, 0700); + if (rv < 0 && errno != EEXIST) { + umask(old_umask); + goto skip_logfile; + } + umask(old_umask); + logfile_fp = fopen(logfile, "a+"); if (logfile_fp != NULL) { int fd = fileno(logfile_fp); @@ -35,6 +58,7 @@ void init_logging(void) } } +skip_logfile: openlog(DAEMON_NAME, LOG_CONS | LOG_PID, syslog_facility); } diff --git a/dlm_controld/main.c b/dlm_controld/main.c index c35756d48c0b..504cafa12ec6 100644 --- a/dlm_controld/main.c +++ b/dlm_controld/main.c @@ -1598,7 +1598,7 @@ static int loop(void) return rv; } -static int lockfile(const char *dir, const char *name) +static int lockfile(const char *name) { char path[PATH_MAX]; char buf[16]; @@ -1607,14 +1607,26 @@ static int lockfile(const char *dir, const char *name) int fd, rv; old_umask = umask(0022); - rv = mkdir(dir, 0775); + rv = mkdir(SYS_VARDIR, 0775); + if (rv < 0 && errno != EEXIST) { + umask(old_umask); + return rv; + } + + rv = mkdir(SYS_RUNDIR, 0775); + if (rv < 0 && errno != EEXIST) { + umask(old_umask); + return rv; + } + + rv = mkdir(RUNDIR, 0775); if (rv < 0 && errno != EEXIST) { umask(old_umask); return rv; } umask(old_umask); - snprintf(path, PATH_MAX, "%s/%s", dir, name); + snprintf(path, PATH_MAX, "%s/%s", RUNDIR, name); fd = open(path, O_CREAT|O_WRONLY|O_CLOEXEC, 0644); if (fd < 0) { @@ -2125,7 +2137,7 @@ int main(int argc, char **argv) init_logging(); - fd = lockfile(RUNDIR, RUN_FILE_NAME); + fd = lockfile(RUN_FILE_NAME); if (fd < 0) return 1; -- 2.33.0
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor