mirror of
https://gitlab.alpinelinux.org/alpine/aports.git
synced 2025-04-19 14:56:46 +02:00
The mkmntdirs binary is only used by openrc's localmount, whickh ensures that all directories in /etc/fstab is created before mounting. This is needed in tmpfs installs. This has nothing to do with the alpine-baselayout so move it to where it belongs.
126 lines
2.8 KiB
Diff
126 lines
2.8 KiB
Diff
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
|
|
|