aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/directive.c37
-rw-r--r--src/gpg.c29
-rw-r--r--src/wydawca.h4
3 files changed, 50 insertions, 20 deletions
diff --git a/src/directive.c b/src/directive.c
index 1e245e0..aaeab2a 100644
--- a/src/directive.c
+++ b/src/directive.c
@@ -394,14 +394,14 @@ verify_directive_format(struct wy_triplet *trp)
}
static char *
-save_script(const char *script)
+save_script(const char *wd, const char *script)
{
char *file_name;
mode_t old_mask;
int fd;
size_t length;
- file_name = concat_file(temp_homedir, "chkXXXXXX", NULL);
+ file_name = concat_file(wd, "chkXXXXXX", NULL);
old_mask = umask(0077);
fd = mkstemp(file_name);
umask(old_mask);
@@ -489,25 +489,38 @@ run_check_script(const char *script, struct wy_triplet *trp,
FILE *fp;
char *buf;
size_t size, total;
-
- wy_debug(2, (_("prep script: %20.20s%s"),
- script, strlen(script) > 20 ? "..." : ""));
- script_file = save_script(script);
- if (!script_file)
+ char *wd;
+
+ wd = wy_tempdir();
+ wy_debug(2, (_("prep script in %s: %20.20s%s"),
+ wd, script, strlen(script) > 20 ? "..." : ""));
+
+ script_file = save_script(wd, script);
+ if (!script_file) {
+ wy_rmdir_r(wd);
+ free(wd);
return 1;
+ }
+
wy_debug(2, (_("script file: %s"), script_file));
if (pipe(p)) {
wy_log(LOG_CRIT, "pipe: %s", strerror(errno));
+ free(script_file);
+ wy_rmdir_r(wd);
+ free(wd);
return 1;
}
+
oldsig = signal(SIGCHLD, SIG_DFL);
pid = fork();
if (pid == -1) {
wy_log(LOG_CRIT, "fork: %s", strerror(errno));
- free(script_file);
close(p[0]);
close(p[1]);
+ free(script_file);
+ wy_rmdir_r(wd);
+ free(wd);
signal(SIGCHLD, oldsig);
return 1;
}
@@ -554,9 +567,9 @@ run_check_script(const char *script, struct wy_triplet *trp,
setenv("WYDAWCA_TRIPLET_BASE", trp->name, 1);
setenv("WYDAWCA_DIST_FILE", trp->file[file_dist].name, 1);
- if (chdir(temp_homedir)) {
+ if (chdir(wd)) {
wy_log(LOG_CRIT, "cannot change to %s: %s",
- temp_homedir, strerror(errno));
+ wd, strerror(errno));
_exit(127);
}
@@ -588,7 +601,9 @@ run_check_script(const char *script, struct wy_triplet *trp,
waitpid(pid, &status, 0);
signal(SIGCHLD, oldsig);
-
+ wy_rmdir_r(wd);
+ free(wd);
+
if (total)
trp->check_diag = grecs_txtacc_finish(trp->acc, 0);
else
diff --git a/src/gpg.c b/src/gpg.c
index d4ae632..1fdecea 100644
--- a/src/gpg.c
+++ b/src/gpg.c
@@ -67,8 +67,8 @@ cwd_pop(struct cwd **tos)
/* Recursively remove the contents of the directory NAME and the directory
itself. Do not change CWD. */
-static int
-rmdir_r(const char *name)
+int
+wy_rmdir_r(const char *name)
{
struct dirent *ent;
struct cwd *cwd = NULL;
@@ -116,12 +116,26 @@ rmdir_r(const char *name)
return err;
}
+char *
+wy_tempdir(void)
+{
+ char *s = grecs_strdup("/tmp/wydawca-XXXXXX");
+ if (!mkdtemp(s)) {
+ wy_log(LOG_CRIT,
+ _("cannot create temporary directory (%s): %s"),
+ s, strerror(errno));
+ free(s);
+ s = NULL;
+ }
+ return s;
+}
+
/* Remove temporary GPG home directory */
static void
remove_homedir(void)
{
wy_debug(2, (_("removing GNUPG home directory: %s"), temp_homedir));
- if (rmdir_r(temp_homedir)) {
+ if (wy_rmdir_r(temp_homedir)) {
wy_log(LOG_CRIT, _("failed to remove GPG directory %s"),
temp_homedir);
}
@@ -134,13 +148,10 @@ create_gpg_homedir(void)
if (temp_homedir)
return 0;
- temp_homedir = grecs_strdup("/tmp/wydawca-XXXXXX");
- if (!mkdtemp(temp_homedir)) {
- wy_log(LOG_CRIT,
- _("cannot create GPG home directory (%s): %s"),
- temp_homedir, strerror(errno));
+ temp_homedir = wy_tempdir();
+ if (!temp_homedir)
return 1;
- }
+
atexit(remove_homedir);
wy_debug(2, (_("GNUPG home directory: %s"), temp_homedir));
setenv("GNUPGHOME", temp_homedir, 1);
diff --git a/src/wydawca.h b/src/wydawca.h
index eede04c..df7ef9b 100644
--- a/src/wydawca.h
+++ b/src/wydawca.h
@@ -551,3 +551,7 @@ void *wy_thr_cleaner(void *ptr);
void wy_triplet_wait(void);
void *wy_thr_tcpmux(void *ptr);
void *wy_thr_connection_watcher(void *ptr);
+
+char *wy_tempdir(void);
+int wy_rmdir_r(const char *name);
+

Return to:

Send suggestions and report system problems to the System administrator.