3 // Copyright (C) 2004 Enrico Scholz <enrico.scholz@informatik.tu-chemnitz.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; version 2 of the License.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 #include "pathconfig.h"
24 #include "matchlist.h"
34 #define ENSC_WRAPPERS_UNISTD 1
35 #define ENSC_WRAPPERS_STDLIB 1
36 #define ENSC_WRAPPERS_IO 1
40 extern int Global_getVerbosity() PURE CONST;
41 extern bool Global_doRenew() PURE CONST;
44 readExcludeListFD(int fd,
45 char ***files, size_t *size,
52 if (fd==-1) return; // todo: message on verbose?
54 len = Elseek(fd, 0, SEEK_END);
55 Elseek(fd, 0, SEEK_SET);
57 *buf = Emalloc(sizeof(*buf) * (len+1));
58 EreadAll(fd, *buf, len);
62 while ((ptr=strchr(ptr, '\n'))) {
68 *files = Emalloc(sizeof(**files) * lines);
73 char *end_ptr = strchr(ptr, '\n');
76 if (end_ptr==0) break;
82 } while (tmp>ptr && *tmp==' ');
84 if (tmp>ptr) (*files)[(*size)++] = ptr;
92 readExcludeList(char const *filename,
93 char ***files, size_t *size,
96 int fd = open(filename, O_RDONLY);
97 if (fd==-1) return; // todo: message on verbose?
99 readExcludeListFD(fd, files, size, buf);
104 getConfigfileList(char const *vserver,
105 char ***files, size_t *size,
108 char tmpname[] = "/tmp/vunify.XXXXXX";
110 int fd = Emkstemp(tmpname);
117 char const **ptr = (char const **)(args)+0;
121 if (fd!=1) Eclose(fd);
125 *ptr++ = "get-conffiles";
128 Eexecv(args[0], args);
133 if (TEMP_FAILURE_RETRY(wait4(pid, &status, 0,0))==-1) {
138 if (!WIFEXITED(status) || WEXITSTATUS(status)!=0) {
139 WRITE_MSG(2, "failed to determine configfiles\n");
143 readExcludeListFD(fd, files, size, buf);
149 MatchList_initManually(struct MatchList *list, char const *vserver,
150 char const *vdir, char const *exclude_file)
152 char *buf[2] = { 0,0 };
154 char **fixed_files = 0;
155 size_t fixed_count = 0;
157 char **expr_files = 0;
158 size_t expr_count = 0;
160 if (Global_getVerbosity()>=1) {
161 WRITE_MSG(1, "Initializing exclude-list for ");
165 WRITE_STR(1, vserver);
170 if (vserver && Global_doRenew()) {
171 if (Global_getVerbosity()>=2)
172 WRITE_MSG(1, " Fetching configuration-file list from packagemanagement\n");
173 getConfigfileList(vserver, &fixed_files, &fixed_count, buf+0);
176 // abuse special values (NULL, empty string) to skip the next step
177 if (exclude_file && *exclude_file) {
178 if (Global_getVerbosity()>=6) WRITE_MSG(1, " Reading exclude file\n");
179 readExcludeList(exclude_file,
180 &expr_files, &expr_count,
184 MatchList_init(list, vdir, fixed_count + expr_count);
185 list->buf = Emalloc(sizeof(void *) * 3);
186 list->buf[0] = buf[0];
187 list->buf[1] = buf[1];
191 MatchList_appendFiles(list, 0, fixed_files, fixed_count, false);
192 MatchList_appendFiles(list, fixed_count, expr_files, expr_count, true);