File bug-1191734_0002-dlm_controld-create-var-parent-directories.patch of Package libdlm
140
1
From 4c774ebe7358d4ce773502d1703046c29371b4ec Mon Sep 17 00:00:00 2001
2
From: Alexander Aring <aahringo@redhat.com>
3
Date: Wed, 31 Mar 2021 16:20:42 -0400
4
Subject: [PATCH 02/14] dlm_controld: create var parent directories
5
6
This patch creates /var/log/dlm_controld and /var/run/dlm_controld
7
and it's parents if not exists before. In case of logging there was a
8
likely issue no log file is created when /var/log/dlm_controld didn't
9
exists before starting dlm_controld.
10
11
Reported-by: Bob Peterson <rpeterso@redhat.com>
12
---
13
dlm_controld/dlm_daemon.h | 8 ++++++--
14
dlm_controld/logging.c | 24 ++++++++++++++++++++++++
15
dlm_controld/main.c | 20 ++++++++++++++++----
16
3 files changed, 46 insertions(+), 6 deletions(-)
17
18
diff --git a/dlm_controld/dlm_daemon.h b/dlm_controld/dlm_daemon.h
19
index 45b295eafe2b..436fc9109aa6 100644
20
--- a/dlm_controld/dlm_daemon.h
21
+++ b/dlm_controld/dlm_daemon.h
22
23
24
/* TODO: get CONFDIR, LOGDIR, RUNDIR from build */
25
26
-#define RUNDIR "/var/run/dlm_controld"
27
-#define LOGDIR "/var/log/dlm_controld"
28
+#define SYS_VARDIR "/var"
29
+#define SYS_RUNDIR SYS_VARDIR "/run"
30
+#define SYS_LOGDIR SYS_VARDIR "/log"
31
+
32
+#define RUNDIR SYS_RUNDIR "/dlm_controld"
33
+#define LOGDIR SYS_LOGDIR "/dlm_controld"
34
#define CONFDIR "/etc/dlm"
35
36
#define RUN_FILE_NAME "dlm_controld.pid"
37
diff --git a/dlm_controld/logging.c b/dlm_controld/logging.c
38
index 4aa3406c0725..d48b8aebc237 100644
39
--- a/dlm_controld/logging.c
40
+++ b/dlm_controld/logging.c
41
42
43
void init_logging(void)
44
{
45
+ mode_t old_umask;
46
+ int rv;
47
+
48
syslog_facility = DEFAULT_SYSLOG_FACILITY;
49
syslog_priority = DEFAULT_SYSLOG_PRIORITY;
50
logfile_priority = DEFAULT_LOGFILE_PRIORITY;
51
52
logfile_priority = LOG_DEBUG;
53
54
if (logfile[0]) {
55
+ old_umask = umask(0077);
56
+ rv = mkdir(SYS_VARDIR, 0700);
57
+ if (rv < 0 && errno != EEXIST) {
58
+ umask(old_umask);
59
+ goto skip_logfile;
60
+ }
61
+
62
+ rv = mkdir(SYS_LOGDIR, 0700);
63
+ if (rv < 0 && errno != EEXIST) {
64
+ umask(old_umask);
65
+ goto skip_logfile;
66
+ }
67
+
68
+ rv = mkdir(LOGDIR, 0700);
69
+ if (rv < 0 && errno != EEXIST) {
70
+ umask(old_umask);
71
+ goto skip_logfile;
72
+ }
73
+ umask(old_umask);
74
+
75
logfile_fp = fopen(logfile, "a+");
76
if (logfile_fp != NULL) {
77
int fd = fileno(logfile_fp);
78
79
}
80
}
81
82
+skip_logfile:
83
openlog(DAEMON_NAME, LOG_CONS | LOG_PID, syslog_facility);
84
}
85
86
diff --git a/dlm_controld/main.c b/dlm_controld/main.c
87
index c35756d48c0b..504cafa12ec6 100644
88
--- a/dlm_controld/main.c
89
+++ b/dlm_controld/main.c
90
91
return rv;
92
}
93
94
-static int lockfile(const char *dir, const char *name)
95
+static int lockfile(const char *name)
96
{
97
char path[PATH_MAX];
98
char buf[16];
99
100
int fd, rv;
101
102
old_umask = umask(0022);
103
- rv = mkdir(dir, 0775);
104
+ rv = mkdir(SYS_VARDIR, 0775);
105
+ if (rv < 0 && errno != EEXIST) {
106
+ umask(old_umask);
107
+ return rv;
108
+ }
109
+
110
+ rv = mkdir(SYS_RUNDIR, 0775);
111
+ if (rv < 0 && errno != EEXIST) {
112
+ umask(old_umask);
113
+ return rv;
114
+ }
115
+
116
+ rv = mkdir(RUNDIR, 0775);
117
if (rv < 0 && errno != EEXIST) {
118
umask(old_umask);
119
return rv;
120
}
121
umask(old_umask);
122
123
- snprintf(path, PATH_MAX, "%s/%s", dir, name);
124
+ snprintf(path, PATH_MAX, "%s/%s", RUNDIR, name);
125
126
fd = open(path, O_CREAT|O_WRONLY|O_CLOEXEC, 0644);
127
if (fd < 0) {
128
129
130
init_logging();
131
132
- fd = lockfile(RUNDIR, RUN_FILE_NAME);
133
+ fd = lockfile(RUN_FILE_NAME);
134
if (fd < 0)
135
return 1;
136
137
--
138
2.33.0
139
140