4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
31 static int mode = 0700;
32 static char workdir[PATH_MAX];
34 /* removes recursively the content of a directory */
35 static int clean_dir()
47 syslog(LOG_ERR, "opendir failed in clean_dir");
53 if (readdir_r(dir, &entry.entry, &ent) != 0) {
54 syslog(LOG_ERR, "readdir_r failed in clean_dir");
59 if (ent->d_name[0] == '.' && (ent->d_name[1] == 0
60 || (ent->d_name[1] == '.' && ent->d_name[2] == 0)))
62 cr = unlink(ent->d_name);
65 if (errno != EISDIR) {
66 syslog(LOG_ERR, "unlink of %s failed in clean_dir", ent->d_name);
69 if (chdir(ent->d_name)) {
70 syslog(LOG_ERR, "enter directory %s failed in clean_dir", ent->d_name);
78 cr = rmdir(ent->d_name);
80 syslog(LOG_ERR, "rmdir of %s failed in clean_dir", ent->d_name);
90 /* removes the content of the working directory */
91 int enter_workdir(int clean)
93 int rc = chdir(workdir);
95 syslog(LOG_ERR, "entring workdir %s failed", workdir);
101 /* removes the working directory */
102 void remove_workdir()
109 int set_workdir(const char *name, int create)
115 /* check the length */
116 length = strlen(name);
117 if (length >= sizeof workdir) {
118 syslog(LOG_ERR, "workdir name too long");
125 syslog(LOG_ERR, "no workdir %s", name);
128 rc = mkdir(name, mode);
130 syslog(LOG_ERR, "can't create workdir %s", name);
134 } else if (!S_ISDIR(s.st_mode)) {
135 syslog(LOG_ERR, "%s isn't a directory", name);
138 memcpy(workdir, name, 1+length);
142 /* install the widgets of the list */
143 int make_workdir(int reuse)
147 /* create a temporary directory */
148 for (i = 0 ; ; i++) {
150 syslog(LOG_ERR, "exhaustion of workdirs");
153 sprintf(workdir, PREDIR "PACK%d", i);
154 if (!mkdir(workdir, mode))
156 if (errno != EEXIST) {
157 syslog(LOG_ERR, "error in creation of workdir %s: %m", workdir);