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.
18 #include "wrappers-io.h"
19 #include "pathconfig.h"
22 readExcludeListFD(int fd,
23 char ***files, size_t *size,
30 if (fd==-1) return; // todo: message on verbose?
32 len = Elseek(fd, 0, SEEK_END);
33 Elseek(fd, 0, SEEK_SET);
35 *buf = Emalloc(sizeof(*buf) * (len+1));
36 EreadAll(fd, *buf, len);
40 while ((ptr=strchr(ptr, '\n'))) {
46 *files = Emalloc(sizeof(**files) * lines);
51 char *end_ptr = strchr(ptr, '\n');
54 if (end_ptr==0) break;
60 } while (tmp>ptr && *tmp==' ');
62 if (tmp>ptr) (*files)[(*size)++] = ptr;
70 readExcludeList(char const *filename,
71 char ***files, size_t *size,
74 int fd = open(filename, O_RDONLY);
75 if (fd==-1) return; // todo: message on verbose?
77 readExcludeListFD(fd, files, size, buf);
81 getConfigfileList(char const *vserver,
82 char ***files, size_t *size,
85 char tmpname[] = "/tmp/vunify.XXXXXX";
87 int fd = Emkstemp(tmpname);
94 char const **ptr = (char const **)(args)+0;
98 if (fd!=1) Eclose(fd);
100 *ptr++ = PKGMGMT_INFO_PROG;
102 *ptr++ = "conffiles";
105 Eexecv(args[0], args);
110 if (TEMP_FAILURE_RETRY(wait4(pid, &status, 0,0))==-1) {
115 if (!WIFEXITED(status) || WEXITSTATUS(status)!=0) {
116 WRITE_MSG(2, "failed to determine configfiles\n");
120 readExcludeListFD(fd, files, size, buf);
126 initMatchList(struct MatchList *list, char const *vserver,
127 char const *vdir, char const *exclude_file)
129 char *buf[2] = { 0,0 };
131 char **fixed_files = 0;
132 size_t fixed_count = 0;
134 char **expr_files = 0;
135 size_t expr_count = 0;
137 if (vserver && global_args->do_renew) {
138 getConfigfileList(vserver, &fixed_files, &fixed_count, buf+0);
141 // abuse special values (NULL, empty string) to skip the next step
142 if (exclude_file && *exclude_file) {
143 readExcludeList(exclude_file,
144 &expr_files, &expr_count,
148 MatchList_init(list, vdir, fixed_count + expr_count);
149 list->buf = Emalloc(sizeof(void *) * 2);
150 list->buf[0] = buf[0];
151 list->buf[1] = buf[1];
154 MatchList_appendFiles(list, 0, fixed_files, fixed_count, false);
155 MatchList_appendFiles(list, fixed_count, expr_files, expr_count, true);
162 initMatchListByVserver(struct MatchList *list, char const *vserver,
163 char const **res_appdir)
169 style = vc_getVserverCfgStyle(vserver);
170 vdir = vc_getVserverVdir( vserver, style);
171 appdir = vc_getVserverAppDir(vserver, style, "vunify");
173 if (vdir==0 || appdir==0) {
174 free((char *)appdir);
180 size_t l1 = strlen(appdir);
181 char excl_list[l1 + sizeof("/exclude")];
183 memcpy(excl_list, appdir, l1);
184 memcpy(excl_list+l1, "/exclude", 9);
186 // 'vdir' is transferred to matchlist and must not be free'ed here
187 initMatchList(list, vserver, vdir, excl_list);
191 *res_appdir = appdir;
193 free((char *)appdir);