dlm_controld: create var parent directories
PATCH 1/1 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 <[email protected]>
--- dlm_controld/dlm_daemon.h | 8 ++++++-- dlm_controld/logging.c | 24 ++++++++++++++++++++++++ dlm_controld/main.c | 20 ++++++++++++++++---- 3 files changed, 46 insertions(+), 6 deletions(-)
dlm_controld/dlm_daemon.h +6 -2
@@ -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"
dlm_controld/logging.c +24 -0
@@ -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); }
dlm_controld/main.c +16 -4
@@ -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 ;
Signature · 1 line
2.26.3