blob: 450947667b336e356431da9bd77f82c76a37ee73 [file] [log] [blame]
Brad Bishop316dfdd2018-06-25 12:45:53 -04001From b45cf4923c7e1f1165925e9b4d7db2108faf2eae Mon Sep 17 00:00:00 2001
2From: Emil Renner Berthing <systemd@esmil.dk>
3Date: Mon, 23 Oct 2017 10:50:14 -0700
4Subject: [PATCH 15/31] don't fail if GLOB_BRACE and GLOB_ALTDIRFUNC is not
5 defined
6
7If the standard library doesn't provide brace
8expansion users just won't get it.
9
10Dont use GNU GLOB extentions on non-glibc systems
11
12Conditionalize use of GLOB_ALTDIRFUNC
13
14Upstream-Status: Pending
15
16Signed-off-by: Khem Raj <raj.khem@gmail.com>
17---
18 src/basic/glob-util.c | 20 +++++++++++++++++---
19 src/test/test-glob-util.c | 17 +++++++++++++++--
20 src/tmpfiles/tmpfiles.c | 8 ++++++++
21 3 files changed, 40 insertions(+), 5 deletions(-)
22
23diff --git a/src/basic/glob-util.c b/src/basic/glob-util.c
24index 6e80a1e23..312bb3fd1 100644
25--- a/src/basic/glob-util.c
26+++ b/src/basic/glob-util.c
27@@ -28,13 +28,18 @@
28 #include "macro.h"
29 #include "path-util.h"
30 #include "strv.h"
31+/* Don't fail if the standard library
32+ * doesn't provide brace expansion */
33+#ifndef GLOB_BRACE
34+#define GLOB_BRACE 0
35+#endif
36
37 int safe_glob(const char *path, int flags, glob_t *pglob) {
38 int k;
39
40+#ifdef GLOB_ALTDIRFUNC
41 /* We want to set GLOB_ALTDIRFUNC ourselves, don't allow it to be set. */
42 assert(!(flags & GLOB_ALTDIRFUNC));
43-
44 if (!pglob->gl_closedir)
45 pglob->gl_closedir = (void (*)(void *)) closedir;
46 if (!pglob->gl_readdir)
47@@ -45,10 +50,13 @@ int safe_glob(const char *path, int flags, glob_t *pglob) {
48 pglob->gl_lstat = lstat;
49 if (!pglob->gl_stat)
50 pglob->gl_stat = stat;
51-
52+#endif
53 errno = 0;
54+#ifdef GLOB_ALTDIRFUNC
55 k = glob(path, flags | GLOB_ALTDIRFUNC, NULL, pglob);
56-
57+#else
58+ k = glob(path, flags, NULL, pglob);
59+#endif
60 if (k == GLOB_NOMATCH)
61 return -ENOENT;
62 if (k == GLOB_NOSPACE)
63@@ -61,6 +69,12 @@ int safe_glob(const char *path, int flags, glob_t *pglob) {
64 return 0;
65 }
66
67+/* Don't fail if the standard library
68+ * doesn't provide brace expansion */
69+#ifndef GLOB_BRACE
70+#define GLOB_BRACE 0
71+#endif
72+
73 int glob_exists(const char *path) {
74 _cleanup_globfree_ glob_t g = {};
75 int k;
76diff --git a/src/test/test-glob-util.c b/src/test/test-glob-util.c
77index bd2f8fcfd..a10c77427 100644
78--- a/src/test/test-glob-util.c
79+++ b/src/test/test-glob-util.c
80@@ -30,6 +30,11 @@
81 #include "glob-util.h"
82 #include "macro.h"
83 #include "rm-rf.h"
84+/* Don't fail if the standard library
85+ * doesn't provide brace expansion */
86+#ifndef GLOB_BRACE
87+#define GLOB_BRACE 0
88+#endif
89
90 static void test_glob_exists(void) {
91 char name[] = "/tmp/test-glob_exists.XXXXXX";
92@@ -52,25 +57,33 @@ static void test_glob_exists(void) {
93 static void test_glob_no_dot(void) {
94 char template[] = "/tmp/test-glob-util.XXXXXXX";
95 const char *fn;
96-
97 _cleanup_globfree_ glob_t g = {
98+#ifdef GLOB_ALTDIRFUNC
99 .gl_closedir = (void (*)(void *)) closedir,
100 .gl_readdir = (struct dirent *(*)(void *)) readdir_no_dot,
101 .gl_opendir = (void *(*)(const char *)) opendir,
102 .gl_lstat = lstat,
103 .gl_stat = stat,
104+#endif
105 };
106-
107 int r;
108
109 assert_se(mkdtemp(template));
110
111 fn = strjoina(template, "/*");
112+#ifdef GLOB_ALTDIRFUNC
113 r = glob(fn, GLOB_NOSORT|GLOB_BRACE|GLOB_ALTDIRFUNC, NULL, &g);
114+#else
115+ r = glob(fn, GLOB_NOSORT|GLOB_BRACE, NULL, &g);
116+#endif
117 assert_se(r == GLOB_NOMATCH);
118
119 fn = strjoina(template, "/.*");
120+#ifdef GLOB_ALTDIRFUNC
121 r = glob(fn, GLOB_NOSORT|GLOB_BRACE|GLOB_ALTDIRFUNC, NULL, &g);
122+#else
123+ r = glob(fn, GLOB_NOSORT|GLOB_BRACE, NULL, &g);
124+#endif
125 assert_se(r == GLOB_NOMATCH);
126
127 (void) rm_rf(template, REMOVE_ROOT|REMOVE_PHYSICAL);
128diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
129index 38cbb739c..88cc543f0 100644
130--- a/src/tmpfiles/tmpfiles.c
131+++ b/src/tmpfiles/tmpfiles.c
132@@ -76,6 +76,12 @@
133 #include "umask-util.h"
134 #include "user-util.h"
135 #include "util.h"
136+/* Don't fail if the standard library
137+ * doesn't provide brace expansion */
138+#ifndef GLOB_BRACE
139+#define GLOB_BRACE 0
140+#endif
141+
142
143 /* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates
144 * them in the file system. This is intended to be used to create
145@@ -1288,7 +1294,9 @@ static int item_do_children(Item *i, const char *path, action_t action) {
146
147 static int glob_item(Item *i, action_t action, bool recursive) {
148 _cleanup_globfree_ glob_t g = {
149+#ifdef GLOB_ALTDIRFUNC
150 .gl_opendir = (void *(*)(const char *)) opendir_nomod,
151+#endif
152 };
153 int r = 0, k;
154 char **fn;
155--
1562.13.0
157