1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
From 908f77d4f1930c1ac0be036d3d2e10ff15f84fbf Mon Sep 17 00:00:00 2001
From: Natanael Copa <ncopa@alpinelinux.org>
Date: Wed, 1 Feb 2017 04:04:52 +0000
Subject: [PATCH] call /sbin/mkmntdirs in localmount OpenRC service
---
init.d/localmount.in | 2 ++
src/meson.build | 1 +
src/mkmntdirs/meson.build | 5 +++
src/mkmntdirs/mkmntdirs.c | 67 +++++++++++++++++++++++++++++++++++++++
4 files changed, 75 insertions(+)
create mode 100644 src/mkmntdirs/meson.build
create mode 100644 src/mkmntdirs/mkmntdirs.c
diff --git a/init.d/localmount.in b/init.d/localmount.in
index 8a66eb8d..19693b6b 100644
--- a/init.d/localmount.in
+++ b/init.d/localmount.in
@@ -21,6 +21,8 @@ depend()
start()
{
+ [ -x /sbin/mkmntdirs ] && mkmntdirs
+
# Mount local filesystems in /etc/fstab.
# The types variable must start with no, and must be a type
local critical= types="noproc" x= no_netdev= rc=
diff --git a/src/meson.build b/src/meson.build
index 76f6d8a1..0f640eec 100644
--- a/src/meson.build
+++ b/src/meson.build
@@ -12,6 +12,7 @@ subdir('is_newer_than')
subdir('is_older_than')
subdir('kill_all')
subdir('mark_service')
+subdir('mkmntdirs')
subdir('mountinfo')
subdir('on_ac_power')
subdir('openrc')
diff --git a/src/mkmntdirs/meson.build b/src/mkmntdirs/meson.build
new file mode 100644
index 00000000..20f9762d
--- /dev/null
+++ b/src/mkmntdirs/meson.build
@@ -0,0 +1,5 @@
+executable('mkmntdirs',
+ ['mkmntdirs.c'],
+ c_args : cc_branding_flags,
+ install: true,
+ install_dir: sbindir)
diff --git a/src/mkmntdirs/mkmntdirs.c b/src/mkmntdirs/mkmntdirs.c
new file mode 100644
index 00000000..eaeae732
--- /dev/null
+++ b/src/mkmntdirs/mkmntdirs.c
@@ -0,0 +1,67 @@
+/*
+ * Create mount directories in fstab
+ *
+ * Copyright(c) 2008 Natanael Copa <natanael.copa@gmail.com>
+ * May be distributed under the terms of GPL-2
+ *
+ * usage: mkmntdirs [fstab]
+ *
+ */
+
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <err.h>
+#include <mntent.h>
+#include <stdio.h>
+#include <string.h>
+
+
+#ifdef DEBUG
+#define mkdir_recursive(p) puts((p))
+#else
+static void mkdir_recursive(char *path)
+{
+ char *s = path;
+ while (1) {
+ int c = '\0';
+ while (*s) {
+ if (*s == '/') {
+ do {
+ ++s;
+ } while (*s == '/');
+ c = *s; /* Save the current char */
+ *s = '\0'; /* and replace it with nul. */
+ break;
+ }
+ ++s;
+ }
+ mkdir(path, 0755);
+ if (c == '\0')
+ return;
+ *s = c;
+ }
+}
+#endif
+
+int main(int argc, const char *argv[])
+{
+ const char *filename = "/etc/fstab";
+ FILE *f;
+ struct mntent *ent;
+ if (argc == 2)
+ filename = argv[1];
+
+ f = setmntent(filename, "r");
+ if (f == NULL)
+ err(1, "%s", filename);
+
+ while ((ent = getmntent(f)) != NULL) {
+ if (strcmp(ent->mnt_dir, "none") != 0)
+ mkdir_recursive(ent->mnt_dir);
+ }
+
+ endmntent(f);
+ return 0;
+}
+
--
2.37.1
|