diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2021-04-09 21:28:06 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2021-04-09 21:31:15 +0300 |
commit | 648574a49ad7dc7edacc48d5b6c6366132dbea23 (patch) | |
tree | c62f157167c3b1f642df4a494e0d00a9f8f6352f /src | |
parent | 07ceea263f359a04d4fe43883a621bdd47fedc18 (diff) | |
download | wydawca-648574a49ad7dc7edacc48d5b6c6366132dbea23.tar.gz wydawca-648574a49ad7dc7edacc48d5b6c6366132dbea23.tar.bz2 |
Run the distribution verification script in a separate temporary directory.
The temporary directory is removed when the script terminates.
* src/directive.c (run_check_script): Create a separate temporary
directory to run the script in.
* src/gpg.c (wy_rmdir_r, wy_tempdir): New functions.
* src/wydawca.h (wy_rmdir_r, wy_tempdir): New protos.
Diffstat (limited to 'src')
-rw-r--r-- | src/directive.c | 37 | ||||
-rw-r--r-- | src/gpg.c | 29 | ||||
-rw-r--r-- | src/wydawca.h | 4 |
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 @@ -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); + |