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.
23 #include "vserver-start.h"
25 #include <pathconfig.h>
26 #include <lib_internal/command.h>
27 #include <lib_internal/util.h>
29 #include <sys/types.h>
31 #include <sys/param.h>
35 #define HAS_SUFFIX(STR, LEN, SUF) \
36 (LEN>sizeof(SUF) && strcmp(STR+LEN-sizeof(SUF), SUF)==0)
39 visitFile(char const *fname, char const *vname, char const *style)
44 if (stat(fname, &st)==-1 ||
48 if ((st.st_mode & 0111)==0) {
50 "!!!LEGACY ALERT!!!\n"
51 "The special handling of non-executable scriptlets which allows to\n"
52 "override environment variables is not supported anymore. This change\n"
53 "was needed as 'vserver ... start' is done by a native C program now.\n"
54 "If you need the old functionality please fill a bugreport so that\n"
55 "workarounds can be found/implemented.\n"
56 "The file triggering this message was\n"
64 char const *par[] = { fname, style, vname, 0 };
65 Command_setParams(&cmd, par);
67 if (!Command_exec(&cmd, true) ||
68 !Command_wait(&cmd, true)) {
69 WRITE_MSG(2, "vserver-start: exec('");
72 WRITE_STR(2, strerror(cmd.err));
73 WRITE_MSG(2, "; aborting...\n");
79 WRITE_MSG(2, "vserver-start: scriptlet '");
81 WRITE_MSG(2, "' failed; aborting...\n");
92 visitDirentry(PathInfo const *basepath, char const *d_name,
96 size_t l = strlen(d_name);
97 char path[basepath->l + l + 1];
100 if (isDotfile(d_name) ||
101 HAS_SUFFIX(d_name, l, ".rpmnew") ||
102 HAS_SUFFIX(d_name, l, ".rpmsave") ||
103 HAS_SUFFIX(d_name, l, ".rpmorig") ||
104 HAS_SUFFIX(d_name, l, ".cfsaved"))
107 ptr = Xmemcpy(path, basepath->d, basepath->l);
108 ptr = Xmemcpy(ptr, d_name, l);
111 return visitFile(path, vname, style);
115 visitPath(PathInfo const *basepath,
117 PathInfo const *style)
119 char tmp[basepath->l + style->l + sizeof(".d/")];
120 PathInfo path = { .d = tmp };
123 bool did_something = false;
125 ptr = Xmemcpy(tmp, basepath->d, basepath->l);
126 ptr = Xmemcpy(ptr, style->d, style->l);
130 did_something = visitFile(path.d, vname, style->d) || did_something;
132 ptr = Xmemcpy(ptr, ".d/", sizeof(".d/"));
137 struct dirent *ent = readdir(dir);
140 did_something = visitDirentry(&path, ent->d_name, vname, style->d) || did_something;
142 if (dir!=0) closedir(dir);
144 return did_something;
148 execScriptlets(PathInfo const *cfgdir, char const *vname, char const *style)
150 char path_buf[MAX(cfgdir->l, sizeof(CONFDIR "/.defaults")) +
151 sizeof("/scripts/")];
152 PathInfo basepath = { .d = path_buf };
153 PathInfo styledir = {
160 ptr = Xmemcpy(path_buf, cfgdir->d, cfgdir->l);
161 ptr = Xmemcpy(ptr, "/scripts/", sizeof("/scripts/"));
162 basepath.l = ptr-path_buf-1;
163 doit = !visitPath(&basepath, vname, &styledir);
166 ptr = Xmemcpy(path_buf, CONFDIR "/.defaults/scripts/",
167 sizeof(CONFDIR "/.defaults/scripts/"));
168 basepath.l = ptr-path_buf-1;
169 doit = !visitPath(&basepath, vname, &styledir);