Commit 55d79973 authored by Bernhard Link's avatar Bernhard Link

add sethookenvironment function to not duplicate environment variable setting for hooks everywhere

parent 8c033bad
2012-11-24 Bernhard R. Link <brlink@debian.org>
* make setting of environment variables for
hooks more uniform (and with less code duplication).
2012-11-17 Bernhard R. Link <brlink@debian.org>
* '~/' or '+{b,o,c}/' or './' now also special
in ByHandHooks and ListHook.
......
......@@ -18,14 +18,14 @@ AM_CPPFLAGS = $(ARCHIVECPP) $(DBCPPFLAGS)
reprepro_LDADD = $(ARCHIVELIBS) $(DBLIBS)
changestool_LDADD = $(ARCHIVELIBS)
reprepro_SOURCES = descriptions.c sizes.c sourcecheck.c byhandhook.c archallflood.c needbuild.c globmatch.c printlistformat.c diffindex.c rredpatch.c pool.c atoms.c uncompression.c remoterepository.c indexfile.c copypackages.c sourceextraction.c checksums.c readtextfile.c filecntl.c sha1.c sha256.c configparser.c database.c freespace.c log.c changes.c incoming.c uploaderslist.c guesscomponent.c files.c md5.c dirs.c chunks.c reference.c binaries.c sources.c checks.c names.c dpkgversions.c release.c mprintf.c updates.c strlist.c signature_check.c signedfile.c signature.c distribution.c checkindeb.c checkindsc.c checkin.c upgradelist.c target.c aptmethod.c downloadcache.c main.c override.c terms.c termdecide.c ignore.c filterlist.c exports.c tracking.c optionsfile.c donefile.c pull.c contents.c filelist.c $(ARCHIVE_USED) $(ARCHIVE_CONTENTS)
reprepro_SOURCES = descriptions.c sizes.c sourcecheck.c byhandhook.c archallflood.c needbuild.c globmatch.c printlistformat.c diffindex.c rredpatch.c pool.c atoms.c uncompression.c remoterepository.c indexfile.c copypackages.c sourceextraction.c checksums.c readtextfile.c filecntl.c sha1.c sha256.c configparser.c database.c freespace.c hooks.c log.c changes.c incoming.c uploaderslist.c guesscomponent.c files.c md5.c dirs.c chunks.c reference.c binaries.c sources.c checks.c names.c dpkgversions.c release.c mprintf.c updates.c strlist.c signature_check.c signedfile.c signature.c distribution.c checkindeb.c checkindsc.c checkin.c upgradelist.c target.c aptmethod.c downloadcache.c main.c override.c terms.c termdecide.c ignore.c filterlist.c exports.c tracking.c optionsfile.c donefile.c pull.c contents.c filelist.c $(ARCHIVE_USED) $(ARCHIVE_CONTENTS)
EXTRA_reprepro_SOURCE = $(ARCHIVE_UNUSED)
changestool_SOURCES = uncompression.c sourceextraction.c readtextfile.c filecntl.c tool.c chunkedit.c strlist.c checksums.c sha1.c sha256.c md5.c mprintf.c chunks.c signature.c dirs.c names.c $(ARCHIVE_USED)
rredtool_SOURCES = rredtool.c rredpatch.c mprintf.c filecntl.c sha1.c
noinst_HEADERS = descriptions.h sizes.h sourcecheck.h byhandhook.h archallflood.h needbuild.h globmatch.h printlistformat.h pool.h atoms.h uncompression.h remoterepository.h copypackages.h sourceextraction.h checksums.h readtextfile.h filecntl.h sha1.h sha256.h configparser.h database_p.h database.h freespace.h log.h changes.h incoming.h guesscomponent.h md5.h dirs.h files.h chunks.h reference.h binaries.h sources.h checks.h names.h release.h error.h mprintf.h updates.h strlist.h signature.h signature_p.h distribution.h debfile.h checkindeb.h checkindsc.h upgradelist.h target.h aptmethod.h downloadcache.h override.h terms.h termdecide.h ignore.h filterlist.h dpkgversions.h checkin.h exports.h globals.h tracking.h trackingt.h optionsfile.h donefile.h pull.h ar.h filelist.h contents.h chunkedit.h uploaderslist.h indexfile.h rredpatch.h diffindex.h
noinst_HEADERS = descriptions.h sizes.h sourcecheck.h byhandhook.h archallflood.h needbuild.h globmatch.h printlistformat.h pool.h atoms.h uncompression.h remoterepository.h copypackages.h sourceextraction.h checksums.h readtextfile.h filecntl.h sha1.h sha256.h configparser.h database_p.h database.h freespace.h hooks.h log.h changes.h incoming.h guesscomponent.h md5.h dirs.h files.h chunks.h reference.h binaries.h sources.h checks.h names.h release.h error.h mprintf.h updates.h strlist.h signature.h signature_p.h distribution.h debfile.h checkindeb.h checkindsc.h upgradelist.h target.h aptmethod.h downloadcache.h override.h terms.h termdecide.h ignore.h filterlist.h dpkgversions.h checkin.h exports.h globals.h tracking.h trackingt.h optionsfile.h donefile.h pull.h ar.h filelist.h contents.h chunkedit.h uploaderslist.h indexfile.h rredpatch.h diffindex.h
MAINTAINERCLEANFILES = $(srcdir)/Makefile.in $(srcdir)/configure $(srcdir)/stamp-h.in $(srcdir)/aclocal.m4 $(srcdir)/config.h.in
......
......@@ -38,6 +38,7 @@
#include "uncompression.h"
#include "aptmethod.h"
#include "filecntl.h"
#include "hooks.h"
struct tobedone {
/*@null@*/
......@@ -364,12 +365,8 @@ inline static retvalue aptmethod_startup(struct aptmethod *method) {
/* not really useful here, unless someone write reprepro
* specific modules (which I hope noone will) */
setenv("REPREPRO_BASE_DIR", global.basedir, true);
setenv("REPREPRO_OUT_DIR", global.outdir, true);
setenv("REPREPRO_CONF_DIR", global.confdir, true);
setenv("REPREPRO_CONFIG_DIR", global.confdir, true);
setenv("REPREPRO_DIST_DIR", global.distdir, true);
setenv("REPREPRO_LOG_DIR", global.logdir, true);
sethookenvironment(NULL, NULL, NULL, NULL);
/* actually call the method without any arguments: */
(void)execl(methodname, methodname, ENDOFARGUMENTS);
e = errno;
......
......@@ -30,7 +30,7 @@
#include "names.h"
#include "configparser.h"
#include "globmatch.h"
#include "log.h" // for causing*
#include "hooks.h"
#include "byhandhook.h"
struct byhandhook {
......@@ -177,22 +177,7 @@ retvalue byhandhook_call(const struct byhandhook *h, const char *codename, const
if (child == 0) {
/* Try to close all open fd but 0,1,2 */
closefrom(3);
if (causingfile != NULL)
setenv("REPREPRO_CAUSING_FILE", causingfile, true);
else
unsetenv("REPREPRO_CAUSING_FILE");
if (atom_defined(causingcommand))
setenv("REPREPRO_CAUSING_COMMAND",
atoms_commands[causingcommand],
true);
else
unsetenv("REPREPRO_CAUSING_COMMAND");
setenv("REPREPRO_BASE_DIR", global.basedir, true);
setenv("REPREPRO_OUT_DIR", global.outdir, true);
setenv("REPREPRO_CONF_DIR", global.confdir, true);
setenv("REPREPRO_CONFIG_DIR", global.confdir, true);
setenv("REPREPRO_DIST_DIR", global.distdir, true);
setenv("REPREPRO_LOG_DIR", global.logdir, true);
sethookenvironment(causingfile, NULL, NULL, NULL);
(void)execl(h->script, h->script, codename,
section, priority, name,
fullfilename, (char*)NULL);
......
......@@ -38,7 +38,7 @@
#include "guesscomponent.h"
#include "tracking.h"
#include "override.h"
#include "log.h"
#include "hooks.h"
/* This file includes the code to include binaries, i.e.
to create the chunk for the Packages.gz-file and
......
......@@ -36,6 +36,7 @@
#include "exports.h"
#include "configparser.h"
#include "filecntl.h"
#include "hooks.h"
static const char *exportdescription(const struct exportmode *mode, char *buffer, size_t buffersize) {
char *result = buffer;
......@@ -345,12 +346,7 @@ static retvalue callexporthook(/*@null@*/const char *hook, const char *relfilena
if (reltmpfilename == NULL) {
exit(255);
}
setenv("REPREPRO_BASE_DIR", global.basedir, true);
setenv("REPREPRO_OUT_DIR", global.outdir, true);
setenv("REPREPRO_CONF_DIR", global.confdir, true);
setenv("REPREPRO_CONFIG_DIR", global.confdir, true);
setenv("REPREPRO_DIST_DIR", global.distdir, true);
setenv("REPREPRO_LOG_DIR", global.logdir, true);
sethookenvironment(causingfile, NULL, NULL, NULL);
(void)execl(hook, hook, release_dirofdist(release),
reltmpfilename, relfilename, mode,
ENDOFARGUMENTS);
......
/* This file is part of "reprepro"
* Copyright (C) 2007,2012 Bernhard R. Link
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1301 USA
*/
/* general helpers infrastructure for all hooks: */
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "error.h"
#include "hooks.h"
void sethookenvironment(const char *causing_file, const char *causing_rule, const char *suite_from, const char *exitcode) {
if (exitcode != NULL)
setenv("REPREPRO_EXIT_CODE", exitcode, true);
else
unsetenv("REPREPRO_EXIT_CODE");
if (causing_file != NULL)
setenv("REPREPRO_CAUSING_FILE", causing_file, true);
else
unsetenv("REPREPRO_CAUSING_FILE");
if (causing_rule != NULL)
setenv("REPREPRO_CAUSING_RULE", causing_rule, true);
else
unsetenv("REPREPRO_CAUSING_RULE");
if (suite_from != NULL)
setenv("REPREPRO_FROM", suite_from, true);
else
unsetenv("REPREPRO_FROM");
if (atom_defined(causingcommand))
setenv("REPREPRO_CAUSING_COMMAND",
atoms_commands[causingcommand],
true);
else
unsetenv("REPREPRO_CAUSING_COMMAND");
setenv("REPREPRO_BASE_DIR", global.basedir, true);
setenv("REPREPRO_OUT_DIR", global.outdir, true);
setenv("REPREPRO_CONF_DIR", global.confdir, true);
setenv("REPREPRO_CONFIG_DIR", global.confdir, true);
setenv("REPREPRO_DIST_DIR", global.distdir, true);
setenv("REPREPRO_LOG_DIR", global.logdir, true);
}
/* global variables to denote current state */
const char *causingfile = NULL; /* only valid while being called */
command_t causingcommand = atom_unknown; /* valid till end of program */
#ifndef REPREPRO_HOOKS_H
#define REPREPRO_HOOKS_H
#ifndef REPREPRO_ATOMS_H
#include "atoms.h"
#endif
/* the command currently processed (may not changed till all loggers are run) */
extern command_t causingcommand;
/* file causing the current actions (may change so may need to be saved for queued actions)*/
extern /*@null@*/ const char *causingfile;
/* for other hooks */
void sethookenvironment(/*@null@*/const char *, /*@null@*/const char *, /*@null@*/const char *, /*@null@*/const char *);
#endif
......@@ -41,9 +41,6 @@
#include "log.h"
#include "filecntl.h"
const char *causingfile = NULL;
command_t causingcommand = atom_unknown;
/*@null@*/ static /*@refcounted@*/ struct logfile {
/*@null@*/struct logfile *next;
char *filename;
......@@ -601,30 +598,8 @@ static retvalue startchild(void) {
}
/* Try to close all open fd but 0,1,2 */
closefrom(3);
if (p->causingfile != NULL)
setenv("REPREPRO_CAUSING_FILE", p->causingfile, true);
else
unsetenv("REPREPRO_CAUSING_FILE");
if (p->causingrule != NULL)
setenv("REPREPRO_CAUSING_RULE", p->causingrule, true);
else
unsetenv("REPREPRO_CAUSING_RULE");
if (p->suitefrom != NULL)
setenv("REPREPRO_FROM", p->suitefrom, true);
else
unsetenv("REPREPRO_FROM");
if (atom_defined(causingcommand))
setenv("REPREPRO_CAUSING_COMMAND",
atoms_commands[causingcommand],
true);
else
unsetenv("REPREPRO_CAUSING_COMMAND");
setenv("REPREPRO_BASE_DIR", global.basedir, true);
setenv("REPREPRO_OUT_DIR", global.outdir, true);
setenv("REPREPRO_CONF_DIR", global.confdir, true);
setenv("REPREPRO_CONFIG_DIR", global.confdir, true);
setenv("REPREPRO_DIST_DIR", global.distdir, true);
setenv("REPREPRO_LOG_DIR", global.logdir, true);
sethookenvironment(p->causingfile, p->causingrule,
p->suitefrom, NULL);
(void)execv(p->arguments[0], p->arguments);
fprintf(stderr, "Error executing '%s': %s\n", p->arguments[0],
strerror(errno));
......
......@@ -4,18 +4,13 @@
#ifndef REPREPRO_STRLIST_H
#include "strlist.h"
#endif
#ifndef REPREPRO_ATOMS_H
#include "atoms.h"
#ifndef REPREPRO_HOOKS_H
#include "hooks.h"
#endif
struct target;
struct logger;
/* file causing the current logger_log* run */
extern /*@null@*/ const char *causingfile;
/* command causing the current logger_log* run */
extern command_t causingcommand;
retvalue logger_init(struct configiterator *, /*@out@*/struct logger **);
void logger_free(/*@only@*/struct logger *);
......
......@@ -4870,28 +4870,10 @@ static inline int callendhook(int status, char *argv[]) {
/* Try to close all open fd but 0,1,2 */
closefrom(3);
if (causingfile != NULL)
setenv("REPREPRO_CAUSING_FILE", causingfile, true);
else
unsetenv("REPREPRO_CAUSING_FILE");
unsetenv("REPREPRO_CAUSING_RULE");
unsetenv("REPREPRO_FROM");
if (atom_defined(causingcommand))
setenv("REPREPRO_CAUSING_COMMAND",
atoms_commands[causingcommand],
true);
else
unsetenv("REPREPRO_CAUSING_COMMAND");
setenv("REPREPRO_BASE_DIR", global.basedir, true);
setenv("REPREPRO_OUT_DIR", global.outdir, true);
setenv("REPREPRO_CONF_DIR", global.confdir, true);
setenv("REPREPRO_CONFIG_DIR", global.confdir, true);
setenv("REPREPRO_DIST_DIR", global.distdir, true);
setenv("REPREPRO_LOG_DIR", global.logdir, true);
if (snprintf(exitcode, 4, "%u", ((unsigned int)status)&255U) > 3)
setenv("REPREPRO_EXIT_CODE", "255", true);
else
setenv("REPREPRO_EXIT_CODE", exitcode, true);
memcpy(exitcode, "255", 4);
sethookenvironment(causingfile, NULL, NULL, exitcode);
argv[0] = endhook,
(void)execv(endhook, argv);
fprintf(stderr, "Error executing '%s': %s\n", endhook,
......
......@@ -36,6 +36,7 @@
#include "chunks.h"
#include "release.h"
#include "filecntl.h"
#include "hooks.h"
#ifdef HAVE_LIBGPGME
static retvalue check_signature_created(bool clearsign, bool willcleanup, /*@null@*/const struct strlist *options, const char *filename, const char *signaturename) {
......@@ -258,16 +259,7 @@ static retvalue signature_with_extern(const struct strlist *options, const char
if (child == 0) {
/* Try to close all open fd but 0,1,2 */
closefrom(3);
unsetenv("REPREPRO_CAUSING_FILE");
unsetenv("REPREPRO_CAUSING_RULE");
unsetenv("REPREPRO_FROM");
unsetenv("REPREPRO_CAUSING_COMMAND");
setenv("REPREPRO_BASE_DIR", global.basedir, true);
setenv("REPREPRO_OUT_DIR", global.outdir, true);
setenv("REPREPRO_CONF_DIR", global.confdir, true);
setenv("REPREPRO_CONFIG_DIR", global.confdir, true);
setenv("REPREPRO_DIST_DIR", global.distdir, true);
setenv("REPREPRO_LOG_DIR", global.logdir, true);
sethookenvironment(NULL, NULL, NULL, NULL);
(void)execl(command, command, filename,
clearsign, detached, ENDOFARGUMENTS);
fprintf(stderr, "Error executing '%s' '%s' '%s' '%s': %s\n",
......
......@@ -1374,12 +1374,7 @@ static retvalue calllisthook(struct update_target *ut, struct update_index_conne
if (child == 0) {
int e;
(void)closefrom(3);
setenv("REPREPRO_BASE_DIR", global.basedir, true);
setenv("REPREPRO_OUT_DIR", global.outdir, true);
setenv("REPREPRO_CONF_DIR", global.confdir, true);
setenv("REPREPRO_CONFIG_DIR", global.confdir, true);
setenv("REPREPRO_DIST_DIR", global.distdir, true);
setenv("REPREPRO_LOG_DIR", global.logdir, true);
sethookenvironment(NULL, NULL, NULL, NULL);
setenv("REPREPRO_FILTER_CODENAME",
ut->target->distribution->codename, true);
setenv("REPREPRO_FILTER_PACKAGETYPE",
......@@ -1490,12 +1485,7 @@ static retvalue callshellhook(struct update_target *ut, struct update_index_conn
close(infd);
close(outfd);
(void)closefrom(3);
setenv("REPREPRO_BASE_DIR", global.basedir, true);
setenv("REPREPRO_OUT_DIR", global.outdir, true);
setenv("REPREPRO_CONF_DIR", global.confdir, true);
setenv("REPREPRO_CONFIG_DIR", global.confdir, true);
setenv("REPREPRO_DIST_DIR", global.distdir, true);
setenv("REPREPRO_LOG_DIR", global.logdir, true);
sethookenvironment(NULL, NULL, NULL, NULL);
setenv("REPREPRO_FILTER_CODENAME",
ut->target->distribution->codename, true);
setenv("REPREPRO_FILTER_PACKAGETYPE",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment