blob: aa2b4cbcf190cd774d2a80251577f7a8ff1a5963 [file] [log] [blame]
Brad Bishop19323692019-04-05 15:28:33 -04001From f8a239b182158ca0a537ba053cb0e6bad9c3a2fb Mon Sep 17 00:00:00 2001
2From: Chen Qi <Qi.Chen@windriver.com>
3Date: Mon, 25 Feb 2019 14:56:21 +0800
4Subject: [PATCH 07/24] 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: Inappropriate [musl specific]
15
16Signed-off-by: Khem Raj <raj.khem@gmail.com>
17Signed-off-by: Chen Qi <Qi.Chen@windriver.com>
18---
Brad Bishopc342db32019-05-15 21:57:59 -040019 src/basic/glob-util.c | 13 ++++++++++++-
20 src/test/test-glob-util.c | 16 ++++++++++++++++
21 src/tmpfiles/tmpfiles.c | 10 ++++++++++
22 3 files changed, 38 insertions(+), 1 deletion(-)
Brad Bishop19323692019-04-05 15:28:33 -040023
24diff --git a/src/basic/glob-util.c b/src/basic/glob-util.c
Brad Bishopc342db32019-05-15 21:57:59 -040025index 32c53f8..ae358d9 100644
Brad Bishop19323692019-04-05 15:28:33 -040026--- a/src/basic/glob-util.c
27+++ b/src/basic/glob-util.c
Brad Bishopc342db32019-05-15 21:57:59 -040028@@ -13,6 +13,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 }
41@@ -20,6 +26,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
Brad Bishopc342db32019-05-15 21:57:59 -040049@@ -33,10 +40,14 @@ int safe_glob(const char *path, int flags, glob_t *pglob) {
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);
58-
59+#else
60+ k = glob(path, flags, NULL, pglob);
61+#endif
62 if (k == GLOB_NOMATCH)
63 return -ENOENT;
64 if (k == GLOB_NOSPACE)
65diff --git a/src/test/test-glob-util.c b/src/test/test-glob-util.c
Brad Bishopc342db32019-05-15 21:57:59 -040066index b4f4144..f0d474e 100644
Brad Bishop19323692019-04-05 15:28:33 -040067--- a/src/test/test-glob-util.c
68+++ b/src/test/test-glob-util.c
Brad Bishopc342db32019-05-15 21:57:59 -040069@@ -13,6 +13,12 @@
Brad Bishop19323692019-04-05 15:28:33 -040070 #include "rm-rf.h"
71 #include "tmpfile-util.h"
Brad Bishopc342db32019-05-15 21:57:59 -040072
Brad Bishop19323692019-04-05 15:28:33 -040073+/* Don't fail if the standard library
74+ * doesn't provide brace expansion */
75+#ifndef GLOB_BRACE
76+#define GLOB_BRACE 0
77+#endif
Brad Bishopc342db32019-05-15 21:57:59 -040078+
Brad Bishop19323692019-04-05 15:28:33 -040079 static void test_glob_exists(void) {
80 char name[] = "/tmp/test-glob_exists.XXXXXX";
Brad Bishopc342db32019-05-15 21:57:59 -040081 int fd = -1;
82@@ -40,11 +46,13 @@ static void test_glob_no_dot(void) {
Brad Bishop19323692019-04-05 15:28:33 -040083 const char *fn;
Brad Bishopc342db32019-05-15 21:57:59 -040084
Brad Bishop19323692019-04-05 15:28:33 -040085 _cleanup_globfree_ glob_t g = {
86+#ifdef GLOB_ALTDIRFUNC
87 .gl_closedir = closedir_wrapper,
88 .gl_readdir = (struct dirent *(*)(void *)) readdir_no_dot,
89 .gl_opendir = (void *(*)(const char *)) opendir,
90 .gl_lstat = lstat,
91 .gl_stat = stat,
92+#endif
93 };
Brad Bishop19323692019-04-05 15:28:33 -040094
Brad Bishopc342db32019-05-15 21:57:59 -040095 int r;
96@@ -52,11 +60,19 @@ static void test_glob_no_dot(void) {
Brad Bishop19323692019-04-05 15:28:33 -040097 assert_se(mkdtemp(template));
98
99 fn = strjoina(template, "/*");
100+#ifdef GLOB_ALTDIRFUNC
101 r = glob(fn, GLOB_NOSORT|GLOB_BRACE|GLOB_ALTDIRFUNC, NULL, &g);
102+#else
103+ r = glob(fn, GLOB_NOSORT|GLOB_BRACE, NULL, &g);
104+#endif
105 assert_se(r == GLOB_NOMATCH);
106
107 fn = strjoina(template, "/.*");
108+#ifdef GLOB_ALTDIRFUNC
109 r = glob(fn, GLOB_NOSORT|GLOB_BRACE|GLOB_ALTDIRFUNC, NULL, &g);
110+#else
111+ r = glob(fn, GLOB_NOSORT|GLOB_BRACE, NULL, &g);
112+#endif
113 assert_se(r == GLOB_NOMATCH);
114
115 (void) rm_rf(template, REMOVE_ROOT|REMOVE_PHYSICAL);
116diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c
Brad Bishopc342db32019-05-15 21:57:59 -0400117index d9d1cc1..477d1e3 100644
Brad Bishop19323692019-04-05 15:28:33 -0400118--- a/src/tmpfiles/tmpfiles.c
119+++ b/src/tmpfiles/tmpfiles.c
Brad Bishopc342db32019-05-15 21:57:59 -0400120@@ -63,6 +63,12 @@
Brad Bishop19323692019-04-05 15:28:33 -0400121 #include "umask-util.h"
122 #include "user-util.h"
Brad Bishopc342db32019-05-15 21:57:59 -0400123
Brad Bishop19323692019-04-05 15:28:33 -0400124+/* Don't fail if the standard library
125+ * doesn't provide brace expansion */
126+#ifndef GLOB_BRACE
127+#define GLOB_BRACE 0
128+#endif
Brad Bishopc342db32019-05-15 21:57:59 -0400129+
Brad Bishop19323692019-04-05 15:28:33 -0400130 /* This reads all files listed in /etc/tmpfiles.d/?*.conf and creates
131 * them in the file system. This is intended to be used to create
Brad Bishopc342db32019-05-15 21:57:59 -0400132 * properly owned directories beneath /tmp, /var/tmp, /run, which are
133@@ -1839,7 +1845,9 @@ finish:
Brad Bishop19323692019-04-05 15:28:33 -0400134
135 static int glob_item(Item *i, action_t action) {
136 _cleanup_globfree_ glob_t g = {
137+#ifdef GLOB_ALTDIRFUNC
138 .gl_opendir = (void *(*)(const char *)) opendir_nomod,
139+#endif
140 };
141 int r = 0, k;
142 char **fn;
Brad Bishopc342db32019-05-15 21:57:59 -0400143@@ -1859,7 +1867,9 @@ static int glob_item(Item *i, action_t action) {
Brad Bishop19323692019-04-05 15:28:33 -0400144
145 static int glob_item_recursively(Item *i, fdaction_t action) {
146 _cleanup_globfree_ glob_t g = {
147+#ifdef GLOB_ALTDIRFUNC
148 .gl_opendir = (void *(*)(const char *)) opendir_nomod,
149+#endif
150 };
151 int r = 0, k;
152 char **fn;
153--
Brad Bishopc342db32019-05-15 21:57:59 -04001542.11.0
Brad Bishop19323692019-04-05 15:28:33 -0400155