blob: 4a60ee32ef6624c4eb54ae7446087614ac46c7f9 [file] [log] [blame]
William A. Kennington IIIac69b482021-06-02 12:28:27 -07001From bca73ff2fbff2dc311040a87a4f536f89af07ad6 Mon Sep 17 00:00:00 2001
Brad Bishop19323692019-04-05 15:28:33 -04002From: Chen Qi <Qi.Chen@windriver.com>
3Date: Mon, 25 Feb 2019 14:56:21 +0800
William A. Kennington IIIac69b482021-06-02 12:28:27 -07004Subject: [PATCH] don't fail if GLOB_BRACE and GLOB_ALTDIRFUNC is not defined
Brad Bishop19323692019-04-05 15:28:33 -04005
6If the standard library doesn't provide brace
7expansion users just won't get it.
8
9Dont use GNU GLOB extentions on non-glibc systems
10
11Conditionalize use of GLOB_ALTDIRFUNC
12
13Upstream-Status: Inappropriate [musl specific]
14
15Signed-off-by: Khem Raj <raj.khem@gmail.com>
16Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
Brad Bishopa34c0302019-09-23 22:34:48 -040017[rebased for systemd 243]
18Signed-off-by: Scott Murray <scott.murray@konsulko.com>
William A. Kennington IIIac69b482021-06-02 12:28:27 -070019
Brad Bishop19323692019-04-05 15:28:33 -040020---
Brad Bishopa34c0302019-09-23 22:34:48 -040021 src/basic/glob-util.c | 12 ++++++++++++
Brad Bishopc342db32019-05-15 21:57:59 -040022 src/test/test-glob-util.c | 16 ++++++++++++++++
23 src/tmpfiles/tmpfiles.c | 10 ++++++++++
Brad Bishopa34c0302019-09-23 22:34:48 -040024 3 files changed, 38 insertions(+)
Brad Bishop19323692019-04-05 15:28:33 -040025
Andrew Geisslerd1e89492021-02-12 15:35:20 -060026--- a/src/basic/glob-util.c
27+++ b/src/basic/glob-util.c
Andrew Geissler82c905d2020-04-13 13:39:40 -050028@@ -12,6 +12,12 @@
Brad Bishop19323692019-04-05 15:28:33 -040029 #include "path-util.h"
30 #include "strv.h"
Brad Bishopc342db32019-05-15 21:57:59 -040031
Brad Bishop19323692019-04-05 15:28:33 -040032+/* Don't fail if the standard library
33+ * doesn't provide brace expansion */
34+#ifndef GLOB_BRACE
35+#define GLOB_BRACE 0
36+#endif
Brad Bishopc342db32019-05-15 21:57:59 -040037+
Brad Bishop19323692019-04-05 15:28:33 -040038 static void closedir_wrapper(void* v) {
39 (void) closedir(v);
Brad Bishopc342db32019-05-15 21:57:59 -040040 }
Andrew Geissler82c905d2020-04-13 13:39:40 -050041@@ -19,6 +25,7 @@ static void closedir_wrapper(void* v) {
Brad Bishop19323692019-04-05 15:28:33 -040042 int safe_glob(const char *path, int flags, glob_t *pglob) {
43 int k;
44
45+#ifdef GLOB_ALTDIRFUNC
46 /* We want to set GLOB_ALTDIRFUNC ourselves, don't allow it to be set. */
47 assert(!(flags & GLOB_ALTDIRFUNC));
48
Patrick Williams213cb262021-08-07 19:21:33 -050049@@ -32,9 +39,14 @@ int safe_glob(const char *path, int flag
Brad Bishop19323692019-04-05 15:28:33 -040050 pglob->gl_lstat = lstat;
51 if (!pglob->gl_stat)
52 pglob->gl_stat = stat;
53+#endif
54
55 errno = 0;
56+#ifdef GLOB_ALTDIRFUNC
57 k = glob(path, flags | GLOB_ALTDIRFUNC, NULL, pglob);
Brad Bishop19323692019-04-05 15:28:33 -040058+#else
59+ k = glob(path, flags, NULL, pglob);
60+#endif
61 if (k == GLOB_NOMATCH)
62 return -ENOENT;
63 if (k == GLOB_NOSPACE)
Andrew Geisslerd1e89492021-02-12 15:35:20 -060064--- a/src/test/test-glob-util.c
65+++ b/src/test/test-glob-util.c
Andrew Geissler82c905d2020-04-13 13:39:40 -050066@@ -12,6 +12,12 @@
Brad Bishop19323692019-04-05 15:28:33 -040067 #include "rm-rf.h"
68 #include "tmpfile-util.h"
Brad Bishopc342db32019-05-15 21:57:59 -040069
Brad Bishop19323692019-04-05 15:28:33 -040070+/* Don't fail if the standard library
71+ * doesn't provide brace expansion */
72+#ifndef GLOB_BRACE
73+#define GLOB_BRACE 0
74+#endif
Brad Bishopc342db32019-05-15 21:57:59 -040075+
Brad Bishop19323692019-04-05 15:28:33 -040076 static void test_glob_exists(void) {
Patrick Williams213cb262021-08-07 19:21:33 -050077 log_info("/* %s */", __func__);
78
79@@ -41,11 +47,13 @@ static void test_glob_no_dot(void) {
Brad Bishop19323692019-04-05 15:28:33 -040080 const char *fn;
Brad Bishopc342db32019-05-15 21:57:59 -040081
Brad Bishop19323692019-04-05 15:28:33 -040082 _cleanup_globfree_ glob_t g = {
83+#ifdef GLOB_ALTDIRFUNC
84 .gl_closedir = closedir_wrapper,
85 .gl_readdir = (struct dirent *(*)(void *)) readdir_no_dot,
86 .gl_opendir = (void *(*)(const char *)) opendir,
87 .gl_lstat = lstat,
88 .gl_stat = stat,
89+#endif
90 };
Brad Bishop19323692019-04-05 15:28:33 -040091
Brad Bishopc342db32019-05-15 21:57:59 -040092 int r;
Patrick Williams213cb262021-08-07 19:21:33 -050093@@ -55,11 +63,19 @@ static void test_glob_no_dot(void) {
Brad Bishop19323692019-04-05 15:28:33 -040094 assert_se(mkdtemp(template));
95
96 fn = strjoina(template, "/*");
97+#ifdef GLOB_ALTDIRFUNC
98 r = glob(fn, GLOB_NOSORT|GLOB_BRACE|GLOB_ALTDIRFUNC, NULL, &g);
99+#else
100+ r = glob(fn, GLOB_NOSORT|GLOB_BRACE, NULL, &g);
101+#endif
102 assert_se(r == GLOB_NOMATCH);
103
104 fn = strjoina(template, "/.*");
105+#ifdef GLOB_ALTDIRFUNC
106 r = glob(fn, GLOB_NOSORT|GLOB_BRACE|GLOB_ALTDIRFUNC, NULL, &g);
107+#else
108+ r = glob(fn, GLOB_NOSORT|GLOB_BRACE, NULL, &g);
109+#endif
110 assert_se(r == GLOB_NOMATCH);
111
112 (void) rm_rf(template, REMOVE_ROOT|REMOVE_PHYSICAL);
Andrew Geisslerd1e89492021-02-12 15:35:20 -0600113--- a/src/tmpfiles/tmpfiles.c
114+++ b/src/tmpfiles/tmpfiles.c
William A. Kennington IIIac69b482021-06-02 12:28:27 -0700115@@ -66,6 +66,12 @@
Brad Bishop19323692019-04-05 15:28:33 -0400116 #include "umask-util.h"
117 #include "user-util.h"
Brad Bishopc342db32019-05-15 21:57:59 -0400118
Brad Bishop19323692019-04-05 15:28:33 -0400119+/* Don't fail if the standard library
120+ * doesn't provide brace expansion */
121+#ifndef GLOB_BRACE
122+#define GLOB_BRACE 0
123+#endif
Brad Bishopc342db32019-05-15 21:57:59 -0400124+
Brad Bishop19323692019-04-05 15:28:33 -0400125 /* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates
126 * them in the file system. This is intended to be used to create
Brad Bishopc342db32019-05-15 21:57:59 -0400127 * properly owned directories beneath /tmp, /var/tmp, /run, which are
Patrick Williams213cb262021-08-07 19:21:33 -0500128@@ -1990,7 +1996,9 @@ finish:
Brad Bishop19323692019-04-05 15:28:33 -0400129
130 static int glob_item(Item *i, action_t action) {
131 _cleanup_globfree_ glob_t g = {
132+#ifdef GLOB_ALTDIRFUNC
133 .gl_opendir = (void *(*)(const char *)) opendir_nomod,
134+#endif
135 };
136 int r = 0, k;
137 char **fn;
Patrick Williams213cb262021-08-07 19:21:33 -0500138@@ -2010,7 +2018,9 @@ static int glob_item(Item *i, action_t a
Brad Bishop19323692019-04-05 15:28:33 -0400139
140 static int glob_item_recursively(Item *i, fdaction_t action) {
141 _cleanup_globfree_ glob_t g = {
142+#ifdef GLOB_ALTDIRFUNC
143 .gl_opendir = (void *(*)(const char *)) opendir_nomod,
144+#endif
145 };
146 int r = 0, k;
147 char **fn;