aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--configure.ac1
-rw-r--r--doc/wydawca.texi16
-rw-r--r--src/cmdline.opt9
-rw-r--r--src/config.c19
-rw-r--r--src/gpg.c33
-rw-r--r--src/job.c64
-rw-r--r--src/net.c10
-rw-r--r--src/process.c4
-rw-r--r--src/triplet.c15
-rw-r--r--src/verify.c7
-rw-r--r--src/watcher.c18
-rw-r--r--src/wydawca.c36
-rw-r--r--src/wydawca.h10
-rw-r--r--tests/.gitignore4
-rw-r--r--tests/Makefile.am8
-rw-r--r--tests/atlocal.in82
-rw-r--r--tests/check-fail.at16
-rw-r--r--tests/check-notify.at26
-rw-r--r--tests/check-ok.at11
-rw-r--r--tests/etc/mailstats.cfin2
-rw-r--r--tests/etc/notify.cfin2
-rw-r--r--tests/etc/wydawca.cfin13
-rw-r--r--tests/inotify-ok.at54
-rw-r--r--tests/mailstats.at9
-rw-r--r--tests/notify-upl.at11
-rw-r--r--tests/testsuite.at27
-rw-r--r--tests/upl11.at15
-rw-r--r--tests/upl12f.at23
-rw-r--r--tests/upl12t.at17
-rw-r--r--tests/upload-dry.at22
-rw-r--r--tests/upload.at8
-rw-r--r--tests/wyasync.c334
-rw-r--r--tests/wyinit.c120
33 files changed, 818 insertions, 228 deletions
diff --git a/configure.ac b/configure.ac
index 5febba2..26ae9ac 100644
--- a/configure.ac
+++ b/configure.ac
@@ -142,6 +142,7 @@ if test $status_inotify = yes; then
AC_DEFINE([WITH_INOTIFY],1,[Set to 1 if inotify(7) is to be used])
fi
AM_CONDITIONAL([COND_INOTIFY],[test $status_inotify = yes])
+AC_SUBST(WY_INOTIFY,[$status_inotify])
# Grecs subsystem
diff --git a/doc/wydawca.texi b/doc/wydawca.texi
index f7245ee..127abde 100644
--- a/doc/wydawca.texi
+++ b/doc/wydawca.texi
@@ -413,13 +413,17 @@ all diagnostics via @command{syslog}, and the option
the standard error.
@xopindex{cron, described}
- The operation mode is configured in the configuration file. If the
-latter configures daemon mode, you can still instruct
-@command{wydawca} to run as a cron job by the @option{--cron} command
-line option. This may be needed, for example, to schedule a daily
+ The operation mode can be configured in the configuration file or
+in the command line. Command line options take precedence over
+configuration settings. The cron mode is the default. It can also
+be requested explicitly, using the @option{--cron} command
+line option. This may be needed, for example, to schedule a daily
@command{wydawca} run when the main daemon instance is already
running.
+@xopindex{daemon, described}
+Similarly, the @option{--daemon} option enables daemon mode.
+
@anchor{spool selection}
Usually @command{wydawca} attempts to process all the configured
spools. You may instruct it to process only a subset of these
@@ -3692,6 +3696,10 @@ Run in cron mode. @xref{starting,, cron}.
@xref{stderr, The @option{--syslog} option}.
+@opsummary{daemon}
+@item --daemon
+Run in daemon mode. @xref{starting,, daemon}.
+
@opsummary{debug}
@sopindex{d, summary}
@item --debug
diff --git a/src/cmdline.opt b/src/cmdline.opt
index 88c7c32..bcb92d8 100644
--- a/src/cmdline.opt
+++ b/src/cmdline.opt
@@ -75,8 +75,13 @@ END
OPTION(cron,,,
[<force cron mode>])
BEGIN
- cron_option = 1;
- wy_log_to_stderr = 0;
+ wy_mode_option = WY_MODE_CRON;
+END
+
+OPTION(daemon,,,
+ [<force daemon mode>])
+BEGIN
+ wy_mode_option = WY_MODE_DAEMON;
END
OPTION(force,,,
diff --git a/src/config.c b/src/config.c
index 2bb3550..240645a 100644
--- a/src/config.c
+++ b/src/config.c
@@ -1412,11 +1412,28 @@ cb_upload_version(enum grecs_callback_command cmd, grecs_node_t * node,
*pversion = n;
return 0;
}
+
+static int
+cb_daemon_mode(enum grecs_callback_command cmd, grecs_node_t *node,
+ void *varptr, void *cb_data)
+{
+ grecs_locus_t *locus = &node->locus;
+ grecs_value_t *value = node->v.value;
+ int t;
+
+ if (wy_assert_string_arg(locus, cmd, value))
+ return 1;
+ if (grecs_string_convert(&t, grecs_type_bool, value->v.string, locus))
+ return 1;
+ if (t)
+ wy_mode = WY_MODE_DAEMON;
+ return 0;
+}
static struct grecs_keyword wydawca_kw[] = {
{ "daemon", NULL,
N_("Enable daemon mode"),
- grecs_type_bool, GRECS_DFLT, &daemon_mode },
+ grecs_type_bool, GRECS_DFLT, NULL, 0, cb_daemon_mode },
{ "foreground", NULL,
N_("Start in foreground even in daemon mode"),
grecs_type_bool, GRECS_DFLT, &foreground },
diff --git a/src/gpg.c b/src/gpg.c
index 7da0f0d..dd15927 100644
--- a/src/gpg.c
+++ b/src/gpg.c
@@ -42,6 +42,8 @@ recursive_rmdir(const char *name)
struct dirent *ent;
if (chdir(name)) {
+ if (errno == ENOENT)
+ return 0;
wy_log(LOG_ERR, _("cannot change to directory %s: %s"),
name, strerror(errno));
return 1;
@@ -218,7 +220,9 @@ verify_directive_signature(struct wy_triplet *trp)
gpgme_error_t ec;
int rc;
struct wy_user *uptr;
-
+ struct stat st;
+ FILE *fp;
+
create_gpg_homedir();
fail_if_err(gpgme_new(&ctx));
@@ -237,9 +241,30 @@ verify_directive_signature(struct wy_triplet *trp)
uptr->name, uptr->fpr));
}
- fail_if_err(gpgme_data_new_from_file(&directive_data,
- trp->file[file_directive].name,
- 1));
+ fp = fopenat_ro(trp->spool->source_fd, trp->file[file_directive].name);
+ if (!fp) {
+ wy_log(LOG_ERR, _("cannot open file %s/%s: %s"),
+ trp->spool->source_dir, trp->file[file_directive].name,
+ strerror(errno));
+ return 1;
+ }
+ if (fstat(fileno(fp), &st)) {
+ wy_log(LOG_ERR, _("cannot stat file %s/%s: %s"),
+ trp->spool->source_dir, trp->file[file_directive].name,
+ strerror(errno));
+ fclose(fp);
+ return 1;
+ }
+
+ ec = gpgme_data_new_from_filepart(&directive_data,
+ NULL, fp, 0, st.st_size);
+ fclose(fp);
+ if (ec) {
+ wy_log(LOG_ERR, _("%s: GPGME error: %s"),
+ "gpgme_data_new_from_filepart", gpgme_strerror(ec));
+ return 1;
+ }
+
gpgme_data_new(&plain);
ec = gpgme_op_verify(ctx, directive_data, NULL, plain);
if (ec == GPG_ERR_NO_ERROR) {
diff --git a/src/job.c b/src/job.c
index 54fce7d..b413bf5 100644
--- a/src/job.c
+++ b/src/job.c
@@ -16,11 +16,18 @@
#include "wydawca.h"
-#define STATE_FINISHED 0x01
-#define STATE_QUEUED 0x02
-#define STATE_ACTIVE 0x04
+enum {
+ STATE_FINISHED,
+ STATE_QUEUED,
+ STATE_ACTIVE
+};
+
+#define STATE_MASK(s) (1<<(s))
-#define STATE_ANY (STATE_FINISHED|STATE_QUEUED|STATE_ACTIVE)
+#define STATE_ANY \
+ (STATE_MASK(STATE_FINISHED) |\
+ STATE_MASK(STATE_QUEUED) | \
+ STATE_MASK(STATE_ACTIVE))
struct job {
enum job_type type;
@@ -130,7 +137,7 @@ job_locate(int type, int mask, void *data)
{
struct job *p;
for (p = queue; p; p = p->next)
- if (p->type == type && (p->state & mask)) {
+ if (p->type == type && (STATE_MASK(p->state) & mask)) {
switch (p->type) {
case JOB_TRIPLET:{
struct wy_triplet *tp;
@@ -161,7 +168,7 @@ job_active_count()
struct job *job;
size_t count = 0;
for (job = queue; job; job = job->next)
- if (job->state & STATE_ACTIVE)
+ if (job->state == STATE_ACTIVE)
count++;
return count;
}
@@ -229,7 +236,6 @@ job_start(struct job *job)
pid = fork();
if (pid == 0) {
- int i;
signal(SIGHUP, SIG_DFL);
signal(SIGTERM, SIG_DFL);
signal(SIGQUIT, SIG_DFL);
@@ -237,8 +243,6 @@ job_start(struct job *job)
signal(SIGCHLD, SIG_DFL);
signal(SIGALRM, SIG_DFL);
alarm(0);
- for (i = getdtablesize(); i > 2; i--)
- close(i);
exit(wydawca_scanner(job) ? WYDAWCA_EX_AGAIN : 0);
} else if (pid == -1) {
wy_log(LOG_CRIT, "fork: %s", strerror(errno));
@@ -301,7 +305,9 @@ job_schedule(int type, void *data)
{
struct job *job;
- job = job_locate(type, type == JOB_TRIPLET ? STATE_QUEUED : STATE_ANY,
+ job = job_locate(type,
+ type == JOB_TRIPLET
+ ? STATE_MASK(STATE_QUEUED) : STATE_ANY,
data);
if (!job) {
job = grecs_zalloc(sizeof(*job));
@@ -332,7 +338,7 @@ job_schedule(int type, void *data)
job_insert(job, NULL);
}
- job->state |= STATE_QUEUED;
+ job->state = STATE_QUEUED;
job_start(job);
}
@@ -399,9 +405,8 @@ job_queue_runner(time_t min_interval)
if (pid <= 0)
break;
for (job = queue; job; job = job->next) {
- if ((job->state & STATE_ACTIVE) && job->pid == pid) {
- job->state &= ~STATE_ACTIVE;
- job->state |= STATE_FINISHED;
+ if (job->state == STATE_ACTIVE && job->pid == pid) {
+ job->state = STATE_FINISHED;
jq_clear(job);
job->exit_status = status;
jobcnt--;
@@ -411,24 +416,21 @@ job_queue_runner(time_t min_interval)
for (job = queue; job;) {
struct job *next = job->next;
- if (job->state & STATE_FINISHED) {
+ if (job->state == STATE_FINISHED) {
print_status(job, 0);
- if ((job->state &= ~STATE_FINISHED) == 0) {
- if (WIFEXITED(job->exit_status) &&
- WEXITSTATUS(job->exit_status) ==
- WYDAWCA_EX_AGAIN) {
- time_t interval = lock_timeout;
- if (interval == 0)
- interval = lock_expire_time;
- /* Re-queue the job */
- job->state = STATE_QUEUED;
- job->timestamp = now + interval;
- } else {
- job_remove(job);
- job_destroy(job);
- job = next;
- continue;
- }
+ if (WIFEXITED(job->exit_status) &&
+ WEXITSTATUS(job->exit_status) == WYDAWCA_EX_AGAIN) {
+ time_t interval = lock_timeout;
+ if (interval == 0)
+ interval = lock_expire_time;
+ /* Re-queue the job */
+ job->state = STATE_QUEUED;
+ job->timestamp = now + interval;
+ } else {
+ job_remove(job);
+ job_destroy(job);
+ job = next;
+ continue;
}
}
diff --git a/src/net.c b/src/net.c
index a27a9e7..9e951af 100644
--- a/src/net.c
+++ b/src/net.c
@@ -155,6 +155,13 @@ sig_term(int sig)
terminate = 1;
}
+static inline int
+notify_parent(void)
+{
+ char *p = getenv("WYDAWCA_NOTIFY_PARENT");
+ return (p && strcmp(p, "1") == 0);
+}
+
void
wydawca_listener()
{
@@ -175,6 +182,9 @@ wydawca_listener()
exit(EX_CONFIG);
}
+ if (notify_parent())
+ kill(getppid(), SIGUSR1);
+
job_init();
signal(SIGHUP, sig_hup);
signal(SIGTERM, sig_term);
diff --git a/src/process.c b/src/process.c
index f2b172c..80fd511 100644
--- a/src/process.c
+++ b/src/process.c
@@ -184,7 +184,7 @@ spool_add_new_file(const struct spool *spool, const char *name,
/* Scan upload directory from the DPAIR and register all files found
there, forming triplets when possible */
void
-scan_spool_unlocked(struct spool *spool, int uc, uid_t * uv)
+scan_spool_unlocked(struct spool *spool, int uc, uid_t *uv)
{
DIR *dir;
struct dirent *ent;
@@ -219,7 +219,7 @@ scan_spool_unlocked(struct spool *spool, int uc, uid_t * uv)
}
int
-scan_spool(struct spool *spool, int uc, uid_t * uv)
+scan_spool(struct spool *spool, int uc, uid_t *uv)
{
char *lockfile = wydawca_lockname(spool->tag);
int rc = wydawca_lock(lockfile);
diff --git a/src/triplet.c b/src/triplet.c
index 4cf9bac..6612ddf 100644
--- a/src/triplet.c
+++ b/src/triplet.c
@@ -365,7 +365,11 @@ static int
triplet_processor(void *data, void *proc_data)
{
struct wy_triplet *trp = data;
-
+ struct spool *spool = proc_data;
+
+ if (trp->spool != spool)
+ return 0;
+
wy_debug(1, ("FILE %s, DIST=%s, SIG=%s, DIRECTIVE=%s",
trp->name,
SP(trp->file[file_dist].name),
@@ -411,14 +415,11 @@ spool_commit_triplets(struct spool *spool, struct wy_triplet *tplist)
push_dir(spool->source_dir);
if (tplist) {
while (tplist) {
- struct wy_triplet *next = tplist->jq_next;
- if (tplist->spool == spool)
- triplet_processor(tplist, NULL);
- tplist = next;
+ triplet_processor(tplist, spool);
+ tplist = tplist->jq_next;
}
} else if (triplet_table) {
- grecs_symtab_foreach(triplet_table, triplet_processor, NULL);
- grecs_symtab_clear(triplet_table);
+ grecs_symtab_foreach(triplet_table, triplet_processor, spool);
}
pop_dir();
}
diff --git a/src/verify.c b/src/verify.c
index b5880db..09451ea 100644
--- a/src/verify.c
+++ b/src/verify.c
@@ -102,10 +102,11 @@ fill_project_name(struct wy_triplet *trp)
return 1;
}
- fp = fopen(trp->file[file_directive].name, "r");
+ fp = fopenat_ro(trp->spool->source_fd, trp->file[file_directive].name);
if (!fp) {
- wy_log(LOG_ERR, _("cannot open file %s: %s"),
- trp->file[file_directive].name, strerror(errno));
+ wy_log(LOG_ERR, _("cannot open file %s/%s: %s"),
+ trp->spool->source_dir, trp->file[file_directive].name,
+ strerror(errno));
return 1;
}
diff --git a/src/watcher.c b/src/watcher.c
index 814385d..cb05f07 100644
--- a/src/watcher.c
+++ b/src/watcher.c
@@ -229,3 +229,21 @@ watcher_run(int ifd)
return 0;
}
+
+FILE *
+fopenat_ro(int dirfd, char const *name)
+{
+ int fd;
+ FILE *fp;
+
+ fd = openat(dirfd, name, O_RDONLY);
+ if (fd == -1)
+ return NULL;
+ fp = fdopen(fd, "r");
+ if (fp == NULL) {
+ int ec = errno;
+ close(fd);
+ errno = ec;
+ }
+ return fp;
+}
diff --git a/src/wydawca.c b/src/wydawca.c
index 4450bac..d83ccab 100644
--- a/src/wydawca.c
+++ b/src/wydawca.c
@@ -36,13 +36,16 @@ unsigned long print_stats; /* Print final statistics output */
time_t file_sweep_time = 0;
char *tar_command_name = "tar";
int archive_signatures = 1; /* Archive sig files by default */
-int lint_mode = 0;
+
+int lint_mode;
+
+int wy_mode = WY_MODE_NORMAL;
+int wy_mode_option = -1;
+
int preprocess_only = 0;
-int cron_option = 0;
int foreground_option = -1;
int single_process_option = -1;
-int daemon_mode = 0;
int foreground;
int single_process;
time_t wakeup_interval;
@@ -353,7 +356,7 @@ main(int argc, char **argv)
wy_debug(4, (_("using GPGME version %s"), p));
if (argc) {
- if (daemon_mode) {
+ if (wy_mode == WY_MODE_DAEMON) {
wy_log(LOG_CRIT, _("extra arguments in daemon mode"));
exit(EX_UNAVAILABLE);
} else {
@@ -384,17 +387,28 @@ main(int argc, char **argv)
exit(0);
if (wy_dry_run || selected_spools())
- cron_option = 1;
- if (cron_option)
- daemon_mode = 0;
+ wy_mode_option = WY_MODE_CRON;
+ if (wy_mode_option != -1)
+ wy_mode = wy_mode_option;
if (foreground_option >= 0)
foreground = foreground_option;
if (single_process_option >= 0)
single_process = single_process_option;
- if (wy_log_to_stderr == -1)
- wy_log_to_stderr = !daemon_mode || foreground;
-
+ if (wy_log_to_stderr == -1) {
+ switch (wy_mode) {
+ case WY_MODE_NORMAL:
+ wy_log_to_stderr = 1;
+ break;
+ case WY_MODE_CRON:
+ wy_log_to_stderr = 0;
+ break;
+ case WY_MODE_DAEMON:
+ wy_log_to_stderr = foreground;
+ break;
+ }
+ }
+
grecs_log_to_stderr = wy_log_to_stderr;
if (!wy_log_to_stderr) {
openlog(wy_syslog_tag, LOG_PID, wy_log_facility);
@@ -419,7 +433,7 @@ main(int argc, char **argv)
wy_log(LOG_NOTICE, _("wydawca (%s) started"), PACKAGE_STRING);
scan_all_spools(uidc, uidv);
- if (daemon_mode)
+ if (wy_mode == WY_MODE_DAEMON)
wydawca_daemon();
else
logstats();
diff --git a/src/wydawca.h b/src/wydawca.h
index c2ae2de..fd0bbfb 100644
--- a/src/wydawca.h
+++ b/src/wydawca.h
@@ -334,7 +334,13 @@ extern time_t lock_expire_time;
extern time_t lock_timeout;
extern int enable_locking;
-extern int daemon_mode;
+enum {
+ WY_MODE_NORMAL,
+ WY_MODE_CRON,
+ WY_MODE_DAEMON,
+};
+extern int wy_mode;
+
extern time_t wakeup_interval;
extern int foreground;
extern int single_process;
@@ -601,3 +607,5 @@ int watcher_run(int);
#endif
int wy_stat_expansion(char **ret, char const *name, size_t len);
+FILE *fopenat_ro(int dirfd, char const *name);
+
diff --git a/tests/.gitignore b/tests/.gitignore
index 4fa16bb..d2800cc 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -4,9 +4,9 @@ package.m4
testsuite
testsuite.dir
testsuite.log
-source
-dest
pushck
bkupname
nullmail
cwdrepl
+wyasync
+wyinit
diff --git a/tests/Makefile.am b/tests/Makefile.am
index edf7b08..437eff4 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -47,6 +47,7 @@ TESTSUITE_AT = \
check-fail.at\
check-notify.at\
check-ok.at\
+ inotify-ok.at\
notify-upl.at\
mailstats.at\
pushdir.at\
@@ -79,7 +80,7 @@ check-local: atconfig atlocal $(TESTSUITE)
#installcheck-local:
# $(SHELL) $(TESTSUITE) AUTOTEST_PATH=$(exec_prefix)/bin
-check_PROGRAMS = pushck bkupname cwdrepl
+check_PROGRAMS = pushck bkupname cwdrepl wyinit
AM_CPPFLAGS = \
@GRECS_INCLUDES@ \
-I$(top_srcdir)/include\
@@ -88,6 +89,11 @@ LDADD=@GRECS_LDADD@
pushck_LDADD=../src/pushd.o
bkupname_LDADD=../src/backup.o @GRECS_LDADD@
+wyinit_LDADD=@GRECS_LDADD@
+
+if COND_INOTIFY
+ check_PROGRAMS += wyasync
+endif
if COND_MAILUTILS
check_PROGRAMS += nullmail
diff --git a/tests/atlocal.in b/tests/atlocal.in
index d0a9899..6102995 100644
--- a/tests/atlocal.in
+++ b/tests/atlocal.in
@@ -6,14 +6,15 @@ PATH=@abs_builddir@:@abs_top_builddir@/src:@abs_top_srcdir@/build-aux:$top_srcdi
XFAILFILE=$abs_builddir/.badversion
-trap "cleanup; test -r $XFAILFILE && cat $XFAILFILE; exit $?" 1 2 13 15
+trap "test -r $XFAILFILE && cat $XFAILFILE; exit $?" 1 2 13 15
WY_CONFSRC=@abs_top_srcdir@/tests/etc
WY_DISTDIR=@abs_top_srcdir@/tests/dist
WY_SRC=@abs_top_builddir@/tests/source
-WY_DST=@abs_top_builddir@/tests/dest
+WY_DST=dest
WY_TESTDIR=@abs_top_builddir@/tests
WY_MAILUTILS=@WY_MAILUTILS@
+WY_INOTIFY=@WY_INOTIFY@
MKDIR_P="@MKDIR_P@"
if test -w /; then
@@ -24,62 +25,49 @@ fi
ulimit -c unlimited
-wydawca_init_testdirs() {
- for dir in "$WY_SRC" "$WY_SRC/test" "${WY_SRC}/fail" "${WY_SRC}/ok" "$WY_DST"
- do
- if test -d "$dir"; then
- rm -rf "$dir"/*
- else
- mkdir "$dir"
- fi
- done
-}
-
-wydawca_clean_testdirs() {
- rm -rf "$WY_SRC" "$WY_DST"
-}
-
wydawca_expandmeta() {
- sed -e "s/@USER@/$USER/g" \
- -e "s,@WY_SRC@,$WY_SRC,g" \
- -e "s,@WY_DST@,$WY_DST,g" \
- -e "s,@WY_CONFSRC@,$WY_CONFSRC,g" \
- -e "s,@WY_TESTDIR@,$WY_TESTDIR,g" \
- -e "s,@WY_MODDIR@,@abs_top_builddir@/modules/mailutils,g" $1 > $2
+ sed -e "s/@USER@/$USER/g" \
+ -e "s,@CWD@,$PWD,g" \
+ -e "s,@WY_SRC@,$WY_SRC,g" \
+ -e "s,@WY_DST@,$WY_DST,g" \
+ -e "s,@WY_CONFSRC@,$WY_CONFSRC,g" \
+ -e "s,@WY_TESTDIR@,$WY_TESTDIR,g" \
+ -e "s,@WY_MODDIR@,@abs_top_builddir@/modules/mailutils,g" $1 > $2
}
wydawca_config() {
- wydawca_expandmeta $WY_CONFSRC/${1}in $1
+ wydawca_expandmeta $WY_CONFSRC/${1}in $1
+ wyinit $1
}
wydawca_upload() {
- dir="$WY_SRC/$1"
- shift
- file=$1
- shift
- cp "$WY_DISTDIR/$file" "$dir"
- cp "$WY_DISTDIR/$file.sig" "$dir"
- if test -n "$1"; then
- cp "$WY_DISTDIR/$1" "$dir/$file.directive.asc"
- else
- cp "$WY_DISTDIR/$file.directive.asc" "$dir"
- fi
+ dir=source/$1
+ shift
+ file=$1
+ shift
+ cp "$WY_DISTDIR/$file" "$dir"
+ cp "$WY_DISTDIR/$file.sig" "$dir"
+ if test -n "$1"; then
+ cp "$WY_DISTDIR/$1" "$dir/$file.directive.asc"
+ else
+ cp "$WY_DISTDIR/$file.directive.asc" "$dir"
+ fi
}
wydawca_cmp() {
- p=$1
- shift
- for file in $@
- do
- cmp "$WY_DISTDIR/$file" "$WY_DST/$p/$file" || exit 1
- done
+ p=$1
+ shift
+ for file in $@
+ do
+ cmp "$WY_DISTDIR/$file" "$WY_DST/$p/$file" || exit 1
+ done
}
wydawca_cmparc() {
- p=$1
- shift
- for file in $@
- do
- cmp "$WY_DISTDIR/$file" "$WY_DST/$p/archive/$file" || exit 1
- done
+ p=$1
+ shift
+ for file in $@
+ do
+ cmp "$WY_DISTDIR/$file" "$WY_DST/$p/archive/$file" || exit 1
+ done
}
diff --git a/tests/check-fail.at b/tests/check-fail.at
index f330a2e..268ca47 100644
--- a/tests/check-fail.at
+++ b/tests/check-fail.at
@@ -17,14 +17,14 @@
AT_SETUP([Verification test failure])
AT_KEYWORDS([uploads check-test check-fail])
-AT_DATA([template],
+AT_DATA([experr],
[wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
wydawca: [[NOTICE]] file.directive.asc: VERSION: 1.1
wydawca: [[NOTICE]] file.directive.asc: COMMENT: Gnupload for Wydawca testsuite
wydawca: [[ERR]] spool check script for file@ckfail returned 1
-wydawca: [[NOTICE]] removing @WY_SRC@/fail/file
-wydawca: [[NOTICE]] removing @WY_SRC@/fail/file.sig
-wydawca: [[NOTICE]] removing @WY_SRC@/fail/file.directive.asc
+wydawca: [[NOTICE]] removing ./source/fail/file
+wydawca: [[NOTICE]] removing ./source/fail/file.sig
+wydawca: [[NOTICE]] removing ./source/fail/file.directive.asc
wydawca: [[INFO]] errors: 1
wydawca: [[INFO]] warnings: 0
wydawca: [[INFO]] bad signatures: 0
@@ -43,18 +43,14 @@ wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) fini
])
AT_CHECK([
-wydawca_init_testdirs
wydawca_config wydawca.cf
wydawca_upload fail file
-wydawca_expandmeta template experr
-
-wydawca $WY_FORCE --no-preproc -c wydawca.cf
+wydawca $WY_FORCE --no-preproc -c wydawca.cf 2>err
+cat err | cwdrepl >&2
],
[0],
[],
[experr])
-wydawca_clean_testdirs
-
AT_CLEANUP
diff --git a/tests/check-notify.at b/tests/check-notify.at
index ec539c4..298ebd0 100644
--- a/tests/check-notify.at
+++ b/tests/check-notify.at
@@ -17,14 +17,14 @@
AT_SETUP([Verification test failure notification])
AT_KEYWORDS([uploads check-test check-fail check-fail-notify notify])
-AT_DATA([template],
+AT_DATA([experr],
[wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
wydawca: [[NOTICE]] file.directive.asc: VERSION: 1.1
wydawca: [[NOTICE]] file.directive.asc: COMMENT: Gnupload for Wydawca testsuite
wydawca: [[ERR]] spool check script for file@ckfail returned 1
-wydawca: [[NOTICE]] removing @WY_SRC@/fail/file
-wydawca: [[NOTICE]] removing @WY_SRC@/fail/file.sig
-wydawca: [[NOTICE]] removing @WY_SRC@/fail/file.directive.asc
+wydawca: [[NOTICE]] removing ./source/fail/file
+wydawca: [[NOTICE]] removing ./source/fail/file.sig
+wydawca: [[NOTICE]] removing ./source/fail/file.directive.asc
wydawca: [[INFO]] errors: 1
wydawca: [[INFO]] warnings: 0
wydawca: [[INFO]] bad signatures: 0
@@ -42,7 +42,7 @@ wydawca: [[INFO]] check failures: 1
wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) finished
])
-AT_DATA([outtmpl],
+AT_DATA([expout],
[From wydawca-noreply@localhost
From: wydawca-noreply@localhost
To: "Wydawca Test User" <gray@localhost>
@@ -52,8 +52,8 @@ Your upload of file has been rejected by the distribution
verification procedure with the following diagnostics:
WYDAWCA_SPOOL=ckfail
-WYDAWCA_SOURCE=@WY_SRC@/fail
-WYDAWCA_DEST=@WY_DST@
+WYDAWCA_SOURCE=./source/fail
+WYDAWCA_DEST=./dest
WYDAWCA_URL=ftp://wydawca.ckfail
WYDAWCA_TRIPLET_BASE=file
WYDAWCA_DIST_FILE=file
@@ -67,24 +67,18 @@ The Project Submission Robot
AT_CHECK([
AT_MAILUTILS_PREREQ
-wydawca_init_testdirs
wydawca_config wydawca.cf
mv wydawca.cf simple.cf
wydawca_config notify.cf
cat notify.cf simple.cf >> wydawca.cf
wydawca_upload fail file
-
-wydawca_expandmeta outtmpl expout
-wydawca_expandmeta template experr
-
-wydawca $WY_FORCE --no-preproc -c wydawca.cf || exit $?
-cat $WY_DST/mail.out
+wydawca $WY_FORCE --no-preproc -c wydawca.cf 2>err || exit $?
+cat err | cwdrepl >&2
+cat mail.out | cwdrepl
],
[0],
[expout],
[experr])
-wydawca_clean_testdirs
-
AT_CLEANUP
diff --git a/tests/check-ok.at b/tests/check-ok.at
index 3193be6..11ee9a1 100644
--- a/tests/check-ok.at
+++ b/tests/check-ok.at
@@ -17,7 +17,7 @@
AT_SETUP([Verification test success])
AT_KEYWORDS([uploads check-test check-success check-ok])
-AT_DATA([template],
+AT_DATA([experr],
[wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
wydawca: [[NOTICE]] file.directive.asc: VERSION: 1.1
wydawca: [[NOTICE]] file.directive.asc: COMMENT: Gnupload for Wydawca testsuite
@@ -39,19 +39,14 @@ wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) fini
])
AT_CHECK([
-wydawca_init_testdirs
wydawca_config wydawca.cf
wydawca_upload ok file
-
-wydawca_expandmeta template experr
-
-wydawca $WY_FORCE --no-preproc -c wydawca.cf || exit $?
+wydawca $WY_FORCE --no-preproc -c wydawca.cf 2>err|| exit $?
+cat err | cwdrepl >&2
wydawca_cmp proj file file.sig
],
[0],
[],
[experr])
-wydawca_clean_testdirs
-
AT_CLEANUP
diff --git a/tests/etc/mailstats.cfin b/tests/etc/mailstats.cfin
index 46be62e..c81da14 100644
--- a/tests/etc/mailstats.cfin
+++ b/tests/etc/mailstats.cfin
@@ -20,7 +20,7 @@ module-init mailutils {
admin-address "root@localhost";
from-address "wydawca-noreply@localhost";
- mailer "| @WY_TESTDIR@/nullmail -o @WY_DST@/mail.out -F ${sender} ${rcpt}";
+ mailer "| @WY_TESTDIR@/nullmail -o @CWD@/mail.out -F ${sender} ${rcpt}";
mail-statistics {
statistics all;
diff --git a/tests/etc/notify.cfin b/tests/etc/notify.cfin
index 70d2895..64c09b3 100644
--- a/tests/etc/notify.cfin
+++ b/tests/etc/notify.cfin
@@ -20,7 +20,7 @@ module-init mailutils {
admin-address "root@localhost";
from-address "wydawca-noreply@localhost";
- mailer "| @WY_TESTDIR@/nullmail -o @WY_DST@/mail.out -F ${sender} ${rcpt}";
+ mailer "| @WY_TESTDIR@/nullmail -o @CWD@/mail.out -F ${sender} ${rcpt}";
}
# Notify the user about successful uploads
diff --git a/tests/etc/wydawca.cfin b/tests/etc/wydawca.cfin
index 6f00159..1daf435 100644
--- a/tests/etc/wydawca.cfin
+++ b/tests/etc/wydawca.cfin
@@ -14,6 +14,7 @@
# You should have received a copy of the GNU General Public License
# along with Wydawca. If not, see <http://www.gnu.org/licenses/>.
+pidfile @CWD@/wydawca.pid;
statistics all;
umask 022;
@@ -67,8 +68,8 @@ create-directories yes;
spool test {
url ftp://wydawca.test;
- source "@WY_SRC@/test";
- destination "@WY_DST@";
+ source "@CWD@/source/test";
+ destination "@CWD@/dest";
archive directory {
name "archive";
};
@@ -76,8 +77,8 @@ spool test {
spool ckfail {
url ftp://wydawca.ckfail;
- source "@WY_SRC@/fail";
- destination "@WY_DST@";
+ source "@CWD@/source/fail";
+ destination "@CWD@/dest";
archive none;
check-script <<EOT
echo WYDAWCA_SPOOL=$WYDAWCA_SPOOL
@@ -92,8 +93,8 @@ EOT;
spool ckok {
url ftp://wydawca.ckok;
- source "@WY_SRC@/ok";
- destination "@WY_DST@";
+ source "@CWD@/source/ok";
+ destination "@CWD@/dest";
archive none;
check-script "exit 0";
}
diff --git a/tests/inotify-ok.at b/tests/inotify-ok.at
new file mode 100644
index 0000000..2c23cf7
--- /dev/null
+++ b/tests/inotify-ok.at
@@ -0,0 +1,54 @@
+# Check distribution verification tests - success -*- Autotest -*-
+# Copyright (C) 2010-2012, 2017, 2019-2020 Sergey Poznyakoff
+#
+# Wydawca is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 3, or (at your option)
+# any later version.
+#
+# Wydawca 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 Wydawca. If not, see <http://www.gnu.org/licenses/>.
+
+AT_SETUP([Successful upload])
+AT_KEYWORDS([uploads check-test check-success check-ok inotify inotify-ok])
+
+AT_DATA([experr],
+[wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
+wydawca: [[NOTICE]] file.directive.asc: VERSION: 1.1
+wydawca: [[NOTICE]] file.directive.asc: VERSION: 1.1
+wydawca: [[NOTICE]] file.directive.asc: COMMENT: Gnupload for Wydawca testsuite
+wydawca: [[INFO]] errors: 0
+wydawca: [[INFO]] warnings: 0
+wydawca: [[INFO]] bad signatures: 0
+wydawca: [[INFO]] access violation attempts: 0
+wydawca: [[INFO]] complete triplets: 1
+wydawca: [[INFO]] incomplete triplets: 0
+wydawca: [[INFO]] bad triplets: 0
+wydawca: [[INFO]] expired triplets: 0
+wydawca: [[INFO]] triplet successes: 1
+wydawca: [[INFO]] files uploaded: 2
+wydawca: [[INFO]] files archived: 0
+wydawca: [[INFO]] symlinks created: 0
+wydawca: [[INFO]] symlinks removed: 0
+wydawca: [[INFO]] check failures: 0
+wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) finished
+])
+
+AT_WYDAWCA_DAEMON([
+wydawca_upload ok file
+while ! test -f @CWD@/dest/proj/file && ! test -f @CWD@/dest/proj/file.sig
+do
+ sleep 1
+done
+],
+[wydawca_cmp proj file file.sig
+],
+[],
+[experr])
+
+AT_CLEANUP
diff --git a/tests/mailstats.at b/tests/mailstats.at
index 5a0955e..a235aa2 100644
--- a/tests/mailstats.at
+++ b/tests/mailstats.at
@@ -16,7 +16,7 @@
AT_SETUP([Simple upload statistics])
-AT_DATA([errtmpl],
+AT_DATA([experr],
[wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
wydawca: [[NOTICE]] file.directive.asc: VERSION: 1.1
wydawca: [[NOTICE]] file.directive.asc: COMMENT: Gnupload for Wydawca testsuite
@@ -66,22 +66,17 @@ Wydawca
AT_CHECK([
AT_MAILUTILS_PREREQ
-wydawca_init_testdirs
wydawca_config wydawca.cf
wydawca_config mailstats.cf
cat mailstats.cf >> wydawca.cf
wydawca_upload test file
-wydawca_expandmeta errtmpl experr
-
wydawca $WY_FORCE --no-preproc -c wydawca.cf || exit $?
wydawca_cmp proj file file.sig
-cat $WY_DST/mail.out
+cat mail.out
],
[0],
[expout],
[experr])
-wydawca_clean_testdirs
-
AT_CLEANUP
diff --git a/tests/notify-upl.at b/tests/notify-upl.at
index 5930c4f..ab75370 100644
--- a/tests/notify-upl.at
+++ b/tests/notify-upl.at
@@ -17,7 +17,7 @@
AT_SETUP([Simple upload and notification])
AT_KEYWORDS([notify notify-upl])
-AT_DATA([errtmpl],
+AT_DATA([experr],
[wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
wydawca: [[NOTICE]] file.directive.asc: VERSION: 1.1
wydawca: [[NOTICE]] file.directive.asc: COMMENT: Gnupload for Wydawca testsuite
@@ -38,7 +38,7 @@ wydawca: [[INFO]] check failures: 0
wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) finished
])
-AT_DATA([outtmpl],
+AT_DATA([expout],
[From wydawca-noreply@localhost
From: wydawca-noreply@localhost
To: "Project Admin" <proj-owner@localhost>
@@ -76,25 +76,20 @@ s,^-[[rwx-]]\{9\} @USER@.*file.sig$,listing of file.sig,
AT_CHECK([
AT_MAILUTILS_PREREQ
-wydawca_init_testdirs
wydawca_config wydawca.cf
mv wydawca.cf simple.cf
wydawca_config notify.cf
cat notify.cf simple.cf >> wydawca.cf
wydawca_upload test file
-wydawca_expandmeta errtmpl experr
-wydawca_expandmeta outtmpl expout
wydawca_expandmeta ls.sin ls.sed
wydawca $WY_FORCE --no-preproc -c wydawca.cf || exit $?
wydawca_cmp proj file file.sig
-cat $WY_DST/mail.out | sed -f ls.sed
+cat mail.out | sed -f ls.sed
],
[0],
[expout],
[experr])
-wydawca_clean_testdirs
-
AT_CLEANUP
diff --git a/tests/testsuite.at b/tests/testsuite.at
index bd8792f..b60623e 100644
--- a/tests/testsuite.at
+++ b/tests/testsuite.at
@@ -24,6 +24,30 @@ test -z "`sort < /dev/null 2>&1`" || AT_SKIP_TEST
])
m4_define([AT_MAILUTILS_PREREQ],[test "$WY_MAILUTILS" = yes || AT_SKIP_TEST])
+m4_define([AT_INOTIFY_PREREQ],[test "$WY_INOTIFY" = yes || AT_SKIP_TEST])
+
+# AT_WYDAWCA_DAEMON([SHELL-COMMANDS],[TEXT],[STDOUT],[STDERR])
+m4_define([AT_WYDAWCA_DAEMON],
+[AT_CHECK([AT_INOTIFY_PREREQ
+AT_DATA([helper.in],[$1
+])
+cat > helper.sh <<EOT
+#!/bin/sh
+. $WY_TESTDIR/atlocal
+EOT
+wydawca_expandmeta helper.in helper.bot
+cat helper.bot >> helper.sh
+
+wydawca_config wydawca.cf
+
+wyasync -c $PWD/wydawca.cf -w --no-preproc -- /bin/sh ./helper.sh || exit $?
+$2
+cat wydawca.out | cwdrepl
+cat wydawca.err | cwdrepl >&2
+],
+[0],
+[$3],
+[$4])])
AT_INIT
AT_TESTED([wydawca])
@@ -45,3 +69,6 @@ m4_include([mailstats.at])
m4_include([check-fail.at])
m4_include([check-ok.at])
m4_include([check-notify.at])
+
+AT_BANNER([inotify])
+m4_include([inotify-ok.at])
diff --git a/tests/upl11.at b/tests/upl11.at
index ec63df9..fc0429b 100644
--- a/tests/upl11.at
+++ b/tests/upl11.at
@@ -17,7 +17,7 @@
AT_SETUP([Implicit archivation (version 1.1)])
AT_KEYWORDS([upl11])
-AT_DATA([template],
+AT_DATA([experr],
[wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
wydawca: [[NOTICE]] file.directive.asc: VERSION: 1.1
wydawca: [[NOTICE]] file.directive.asc: COMMENT: Gnupload for Wydawca testsuite
@@ -39,16 +39,13 @@ wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) fini
])
AT_CHECK([
-wydawca_init_testdirs
wydawca_config wydawca.cf
-destdir=$WY_DST/proj
-test -d $destdir || $MKDIR_P -p $destdir
-cp "$WY_DISTDIR/file" "$destdir"
-cp "$WY_DISTDIR/file.sig" "$destdir"
-
wydawca_upload test file
+mkdir dest/proj
+cp "$WY_DISTDIR/file" dest/proj
+cp "$WY_DISTDIR/file.sig" dest/proj
-wydawca_expandmeta template experr
+wydawca_upload test file
wydawca $WY_FORCE --no-preproc -c wydawca.cf || exit $?
wydawca_cmp proj file file.sig
@@ -58,6 +55,4 @@ wydawca_cmparc proj file file.sig
[],
[experr])
-wydawca_clean_testdirs
-
AT_CLEANUP
diff --git a/tests/upl12f.at b/tests/upl12f.at
index 9d5844e..51d02e9 100644
--- a/tests/upl12f.at
+++ b/tests/upl12f.at
@@ -17,14 +17,14 @@
AT_SETUP([Implicit archivation disabled (version 1.2)])
AT_KEYWORDS([upl12f])
-AT_DATA([template],
+AT_DATA([experr],
[wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
wydawca: [[NOTICE]] file.directive.asc: VERSION: 1.2
wydawca: [[NOTICE]] file.directive.asc: COMMENT: Gnupload for Wydawca testsuite
wydawca: [[ERR]] refusing to upload file because it already exists and replace is not allowed
-wydawca: [[NOTICE]] removing @WY_SRC@/test/file
-wydawca: [[NOTICE]] removing @WY_SRC@/test/file.sig
-wydawca: [[NOTICE]] removing @WY_SRC@/test/file.directive.asc
+wydawca: [[NOTICE]] removing ./source/test/file
+wydawca: [[NOTICE]] removing ./source/test/file.sig
+wydawca: [[NOTICE]] removing ./source/test/file.directive.asc
wydawca: [[INFO]] errors: 1
wydawca: [[INFO]] warnings: 0
wydawca: [[INFO]] bad signatures: 0
@@ -43,24 +43,19 @@ wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) fini
])
AT_CHECK([
-wydawca_init_testdirs
wydawca_config wydawca.cf
-destdir=$WY_DST/proj
-test -d $destdir || $MKDIR_P $destdir
-cp "$WY_DISTDIR/file" "$destdir"
-cp "$WY_DISTDIR/file.sig" "$destdir"
+mkdir dest/proj
+cp "$WY_DISTDIR/file" dest/proj
+cp "$WY_DISTDIR/file.sig" dest/proj
wydawca_upload test file file12f.directive.asc
-wydawca_expandmeta template experr
-
-wydawca $WY_FORCE --no-preproc -c wydawca.cf || exit $?
+wydawca $WY_FORCE --no-preproc -c wydawca.cf 2>err || exit $?
+cat err | cwdrepl >&2
wydawca_cmp proj file file.sig
],
[0],
[],
[experr])
-wydawca_clean_testdirs
-
AT_CLEANUP
diff --git a/tests/upl12t.at b/tests/upl12t.at
index a9f5587..634cd56 100644
--- a/tests/upl12t.at
+++ b/tests/upl12t.at
@@ -17,7 +17,7 @@
AT_SETUP([Implicit archivation enabled (version 1.2)])
AT_KEYWORDS([upl12t])
-AT_DATA([template],
+AT_DATA([experr],
[wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
wydawca: [[NOTICE]] file.directive.asc: VERSION: 1.2
wydawca: [[NOTICE]] file.directive.asc: COMMENT: Gnupload for Wydawca testsuite
@@ -39,18 +39,15 @@ wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) fini
])
AT_CHECK([
-wydawca_init_testdirs
wydawca_config wydawca.cf
-destdir=$WY_DST/proj
-test -d $destdir || $MKDIR_P $destdir
-cp "$WY_DISTDIR/file" "$destdir"
-cp "$WY_DISTDIR/file.sig" "$destdir"
+mkdir dest/proj
+cp "$WY_DISTDIR/file" dest/proj
+cp "$WY_DISTDIR/file.sig" dest/proj
wydawca_upload test file file12t.directive.asc
-wydawca_expandmeta template experr
-
-wydawca $WY_FORCE --no-preproc -c wydawca.cf || exit $?
+wydawca $WY_FORCE --no-preproc -c wydawca.cf 2>err || exit $?
+cat err | cwdrepl >&2
wydawca_cmp proj file file.sig
wydawca_cmparc proj file file.sig
],
@@ -58,6 +55,4 @@ wydawca_cmparc proj file file.sig
[],
[experr])
-wydawca_clean_testdirs
-
AT_CLEANUP
diff --git a/tests/upload-dry.at b/tests/upload-dry.at
index 6dbf679..8245552 100644
--- a/tests/upload-dry.at
+++ b/tests/upload-dry.at
@@ -16,13 +16,13 @@
AT_SETUP([Dry-run upload])
-AT_DATA([template],
+AT_DATA([experr],
[wydawca: [[DEBUG]] test: creating archive directory
wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
-wydawca: [[DEBUG]] @WY_SRC@/ok -> @WY_DST@
-wydawca: [[DEBUG]] @WY_SRC@/fail -> @WY_DST@
-wydawca: [[DEBUG]] @WY_SRC@/test -> @WY_DST@
-wydawca: [[DEBUG]] processing spool test (@WY_DST@)
+wydawca: [[DEBUG]] ./source/ok -> ./dest
+wydawca: [[DEBUG]] ./source/fail -> ./dest
+wydawca: [[DEBUG]] ./source/test -> ./dest
+wydawca: [[DEBUG]] processing spool test (./dest)
wydawca: [[DEBUG]] FILE file, DIST=file, SIG=file.sig, DIRECTIVE=file.directive.asc
wydawca: [[DEBUG]] Good signature from Wydawca (Testsuite) <bug-wydawca@gnu.org.ua>
wydawca: [[DEBUG]] file: directive file signature OK
@@ -30,8 +30,8 @@ wydawca: [[NOTICE]] file.directive.asc: VERSION: 1.1
wydawca: [[DEBUG]] processing triplet `file'
wydawca: [[NOTICE]] file.directive.asc: COMMENT: Gnupload for Wydawca testsuite
wydawca: [[DEBUG]] good detached signature for file
-wydawca: [[DEBUG]] installing file to @WY_DST@/proj
-wydawca: [[DEBUG]] installing file.sig to @WY_DST@/proj
+wydawca: [[DEBUG]] installing file to ./dest/proj
+wydawca: [[DEBUG]] installing file.sig to ./dest/proj
wydawca: [[INFO]] errors: 0
wydawca: [[INFO]] warnings: 0
wydawca: [[INFO]] bad signatures: 0
@@ -50,16 +50,14 @@ wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) fini
])
AT_CHECK([AT_SORT_PREREQ
-wydawca_init_testdirs
wydawca_config wydawca.cf
wydawca_upload test file
-wydawca_expandmeta template experr
set -e
-wydawca $WY_FORCE --no-preproc --dry-run -c wydawca.cf 2>err
+wydawca $WY_FORCE --no-preproc --dry-run -c wydawca.cf 2>err
set +e
grep "found file" err | sort
-grep -v "found file" err >&2
+grep -v "found file" err | cwdrepl >&2
],
[0],
[wydawca: [[DEBUG]] found file file.directive.asc: signed upload directive, stem: file
@@ -68,6 +66,4 @@ wydawca: [[DEBUG]] found file file: distributive, stem: file
],
[experr])
-wydawca_clean_testdirs
-
AT_CLEANUP
diff --git a/tests/upload.at b/tests/upload.at
index f4c9202..5eb4e64 100644
--- a/tests/upload.at
+++ b/tests/upload.at
@@ -16,7 +16,7 @@
AT_SETUP([Simple upload])
-AT_DATA([template],
+AT_DATA([experr],
[wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) started
wydawca: [[NOTICE]] file.directive.asc: VERSION: 1.1
wydawca: [[NOTICE]] file.directive.asc: COMMENT: Gnupload for Wydawca testsuite
@@ -38,12 +38,8 @@ wydawca: [[NOTICE]] AT_PACKAGE_TARNAME (AT_PACKAGE_NAME AT_PACKAGE_VERSION) fini
])
AT_CHECK([
-wydawca_init_testdirs
wydawca_config wydawca.cf
wydawca_upload test file
-
-wydawca_expandmeta template experr
-
wydawca $WY_FORCE --no-preproc -c wydawca.cf || exit $?
wydawca_cmp proj file file.sig
],
@@ -51,6 +47,4 @@ wydawca_cmp proj file file.sig
[],
[experr])
-wydawca_clean_testdirs
-
AT_CLEANUP
diff --git a/tests/wyasync.c b/tests/wyasync.c
new file mode 100644
index 0000000..a4bafea
--- /dev/null
+++ b/tests/wyasync.c
@@ -0,0 +1,334 @@
+/*
+ NAME
+
+ wyasync - wydawca inotify test tool
+
+ SYNOPSIS
+
+ wyasync [OPTIONS] -- COMMAND
+
+ DESCRIPTION
+
+ Starts two programs: wydawca in foreground mode, and COMMAND. Waits for
+ COMMAND to terminate, shuts down wydawca and exits with the exit code of
+ COMMAND.
+
+ OPTIONS
+
+ -c FILE
+ Name of the configuration file.
+
+ -p NAME
+ Full pathname of the "wydawca" binary.
+
+ -t N
+ Time allotted for the COMMAND to terminate. Default is 60 seconds.
+
+ -w ARG
+ Pass ARG to wydawca verbatim.
+
+ EXIT STATUS
+
+ On error conditions, exits with the following codes:
+
+ 64
+ Command line usage error.
+ 65
+ wydawca terminated prematurely.
+ 66
+ COMMAND timed out.
+ 67
+ Operating system error (can't open file, dup fd, etc).
+ 68
+ Internal software error.
+
+ On success, exits with the exit code of COMMAND. The latter should not
+ use exit codes described above.
+
+ */
+#include <config.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+enum {
+ EX_OK = 0,
+ EX_USAGE = 64,
+ EX_WY_TERM = 65,
+ EX_TIMEOUT = 66,
+ EX_OSERR = 67,
+ EX_INTERNAL = 68
+};
+
+char *progname;
+int timeout = 60;
+char *wydawca_prog = "wydawca";
+char *wydawca_out = "wydawca.out";
+char *wydawca_err = "wydawca.err";
+
+#define MAX_ARGS 64
+#define EXTRA_ARGS 3
+
+int w_argc;
+char *w_argv[MAX_ARGS+EXTRA_ARGS+1];
+
+pid_t wydawca_pid, command_pid;
+
+pid_t
+runcom(char *prog, char **argv, char *out, char *err)
+{
+ pid_t pid;
+ int fd_out, fd_err;
+
+ if (out) {
+ fd_out = open(out, O_WRONLY|O_CREAT|O_TRUNC, 0666);
+ if (!fd_out) {
+ fprintf(stderr, "%s: can't open %s: %s\n",
+ progname, out, strerror(errno));
+ exit(EX_OSERR);
+ }
+ } else
+ fd_out = -1;
+ if (err) {
+ fd_err = open(err, O_WRONLY|O_CREAT|O_TRUNC, 0666);
+ if (!fd_err) {
+ fprintf(stderr, "%s: can't open %s: %s\n",
+ progname, err, strerror(errno));
+ exit(EX_OSERR);
+ }
+ } else
+ fd_err = -1;
+
+ pid = fork();
+ if (pid == -1) {
+ fprintf(stderr, "%s: fork: %s\n", progname, strerror(errno));
+ exit(EX_OSERR);
+ }
+
+ if (pid > 0)
+ return pid;
+
+ /* Child */
+ switch (fd_out) {
+ case -1:
+ case 1:
+ break;
+ default:
+ if (dup2(fd_out, 1) == -1) {
+ perror("dup2");
+ exit(EX_OSERR);
+ }
+ close(fd_out);
+ }
+
+ switch (fd_err) {
+ case -1:
+ case 1:
+ break;
+ default:
+ if (dup2(fd_err, 2) == -1) {
+ perror("dup2");
+ exit(EX_OSERR);
+ }
+ close(fd_err);
+ }
+
+ execvp(prog ? prog : argv[0], argv);
+ perror(argv[0]);
+ _exit(127);
+}
+
+int volatile signum;
+
+void
+sighan(int sig)
+{
+ signum = sig;
+}
+
+typedef enum {
+ WYASYNC_INITIAL,
+ WYASYNC_RUNNING,
+ WYASYNC_CHLDEXIT,
+ WYASYNC_STOP
+} WYASYNC_STATE;
+
+void
+usage(void)
+{
+ printf("usage: %s [OPTIONS] -- COMMAND ARGS...\n", progname);
+ printf("wydawca asynchronous test tool\n");
+ printf("\nOPTIONS are:\n\n");
+ printf(" -c FILE Name of the configuration file.\n");
+ printf(" -p PROG Full name of the wydawca binary.\n");
+ printf(" -t N Set execution timeout in seconds.\n");
+ printf(" -w ARG Pass ARG to wydawca verbatim.\n");
+ printf("\n");
+}
+
+int
+main(int argc, char **argv)
+{
+ int c;
+ WYASYNC_STATE state;
+ int exit_code;
+ struct sigaction act;
+ sigset_t sigs, oldsigs;
+
+ progname = strrchr(argv[0], '/');
+ if (!progname)
+ progname = argv[0];
+ else
+ progname++;
+
+ w_argv[w_argc++] = wydawca_prog = "wydawca";
+ while ((c = getopt(argc, argv, "c:hp:t:w:")) != EOF) {
+ switch (c) {
+ case 'h':
+ usage();
+ exit(EX_OK);
+
+ case 'p':
+ wydawca_prog = optarg;
+ break;
+
+ case 't':
+ timeout = atoi(optarg);
+ if (timeout <= 0) {
+ fprintf(stderr, "%s: %s\n", progname, "invalid timeout");
+ exit(EX_USAGE);
+ }
+ break;
+
+ case 'c':
+ if (w_argc >= MAX_ARGS - 2) {
+ fprintf(stderr, "%s: %s\n", progname,
+ "too many arguments for wydawca");
+ exit(EX_USAGE);
+ }
+ w_argv[w_argc++] = "-c";
+ w_argv[w_argc++] = optarg;
+ break;
+
+ case 'w':
+ if (w_argc == MAX_ARGS) {
+ fprintf(stderr, "%s: %s\n", progname,
+ "too many arguments for wydawca");
+ exit(EX_USAGE);
+ }
+ w_argv[w_argc++] = optarg;
+ break;
+
+ default:
+ exit(EX_USAGE);
+ }
+ }
+
+ argc -= optind;
+ argv += optind;
+ if (argc == 0) {
+ fprintf(stderr, "%s: %s\n", progname, "command not given");
+ exit(EX_USAGE);
+ }
+
+ /* Finalize wydawca arguments */
+ w_argv[w_argc++] = "--daemon";
+ w_argv[w_argc++] = "--foreground";
+ w_argv[w_argc++] = "--stderr";
+ w_argv[w_argc] = NULL;
+
+ /* Install signals */
+ act.sa_flags = 0;
+ sigemptyset(&act.sa_mask);
+ act.sa_handler = sighan;
+
+ sigaction(SIGCHLD, &act, NULL);
+ sigaction(SIGALRM, &act, NULL);
+ sigaction(SIGUSR1, &act, NULL);
+
+ sigemptyset(&sigs);
+ sigaddset(&sigs, SIGCHLD);
+ sigaddset(&sigs, SIGALRM);
+ sigaddset(&sigs, SIGUSR1);
+ sigprocmask(SIG_BLOCK, &sigs, &oldsigs);
+
+ /* Start wydawca */
+ if (setenv("WYDAWCA_NOTIFY_PARENT", "1", 1)) {
+ fprintf(stderr, "%s: failed to modify environment\n", progname);
+ exit(EX_OSERR);
+ }
+ wydawca_pid = runcom(wydawca_prog, w_argv, wydawca_out, wydawca_err);
+
+ /* Set timeout */
+ alarm(timeout);
+
+ state = WYASYNC_INITIAL;
+ while (state != WYASYNC_STOP) {
+ pid_t pid;
+ int status;
+
+ sigsuspend(&oldsigs);
+ switch (signum) {
+ case SIGUSR1:
+ /* Start command */
+ command_pid = runcom(NULL, argv, NULL, NULL);
+ state = WYASYNC_RUNNING;
+ break;
+
+ case SIGCHLD:
+ while ((pid = waitpid((pid_t)-1, &status, WNOHANG)) > 0) {
+ if (pid == wydawca_pid) {
+ wydawca_pid = -1;
+ switch (state) {
+ case WYASYNC_INITIAL:
+ exit_code = EX_WY_TERM;
+ state = WYASYNC_STOP;
+ break;
+
+ case WYASYNC_RUNNING:
+ kill(command_pid, SIGTERM);
+ exit_code = EX_WY_TERM;
+ state = WYASYNC_CHLDEXIT;
+ break;
+
+ case WYASYNC_CHLDEXIT:
+ state = WYASYNC_STOP;
+ break;
+
+ default:
+ abort();
+ }
+ } else if (pid == command_pid) {
+ command_pid = -1;
+ switch (state) {
+ case WYASYNC_RUNNING:
+ kill(wydawca_pid, SIGTERM);
+ exit_code = WEXITSTATUS(status);
+ state = WYASYNC_CHLDEXIT;
+ break;
+
+ case WYASYNC_CHLDEXIT:
+ state = WYASYNC_STOP;
+ break;
+
+ default:
+ abort();
+ }
+ }
+ }
+ break;
+
+ case SIGALRM:
+ state = WYASYNC_STOP;
+ exit_code = EX_TIMEOUT;
+ }
+ }
+
+ exit(exit_code);
+}
diff --git a/tests/wyinit.c b/tests/wyinit.c
new file mode 100644
index 0000000..f5f0302
--- /dev/null
+++ b/tests/wyinit.c
@@ -0,0 +1,120 @@
+/*
+ NAME
+
+ wyinit - initialize wydawca testsuite directories
+
+ SYNOPSIS
+
+ wyinit FILE
+
+ DESCRIPTION
+
+ Parses wydawca configuration file FILE. For each "source" and "destination"
+ keyword found, ensures that its argument exists and is a directory. Creates
+ missing directories.
+*/
+
+#include <config.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/stat.h>
+#include "grecs.h"
+
+static char *progname;
+
+static void
+mkdir_p(char *dir)
+{
+ char *p;
+ struct stat st;
+
+ p = dir;
+ if (*p == '/')
+ p++;
+ while (1) {
+ if (*p == 0 || *p == '/') {
+ int c = *p;
+ *p = 0;
+ if (stat(dir, &st)) {
+ if (errno == ENOENT) {
+ if (mkdir(dir, 0700)) {
+ fprintf(stderr, "%s: cannot create %s: %s\n",
+ progname, dir, strerror(errno));
+ exit(1);
+ }
+ } else {
+ fprintf(stderr, "%s: cannot stat %s: %s\n",
+ progname, dir, strerror(errno));
+ exit(1);
+ }
+ } else if (!S_ISDIR(st.st_mode)) {
+ fprintf(stderr, "%s: component \"%s\" is not a directory\n",
+ progname, dir);
+ exit(1);
+ }
+ *p = c;
+ if (c == 0)
+ break;
+ }
+ p++;
+ }
+}
+
+static void
+mkdir_recursive(const char *dir)
+{
+ char *p = grecs_strdup(dir);
+ mkdir_p(p);
+ free(p);
+}
+
+void
+makehier(struct grecs_node *tree, char *path)
+{
+ struct grecs_node *node;
+ grecs_match_buf_t match_buf;
+
+ for (node = grecs_match_first(tree, path, &match_buf);
+ node;
+ node = grecs_match_next(match_buf)) {
+ if (node->type != grecs_node_stmt)
+ continue;
+ if (node->v.value->type != GRECS_TYPE_STRING)
+ continue;
+ mkdir_recursive(node->v.value->v.string);
+ }
+ grecs_match_buf_free(match_buf);
+}
+
+
+int
+main(int argc, char **argv)
+{
+ struct grecs_node *tree;
+
+ progname = strrchr(argv[0], '/');
+ if (!progname)
+ progname = argv[0];
+ else
+ progname++;
+
+ if (argc != 2) {
+ fprintf(stderr, "usage: %s FILE\n", progname);
+ fprintf(stderr, "creates source and destination directories for wydawca\n");
+ fprintf(stderr, "configuration file.\n");
+ exit(1);
+ }
+
+ grecs_log_to_stderr = 1;
+ grecs_parser_options = GRECS_OPTION_QUOTED_STRING_CONCAT;
+ tree = grecs_parse(argv[1]);
+ if (!tree)
+ exit(2);
+ makehier(tree, ".spool.source");
+ makehier(tree, ".spool.destination");
+ return 0;
+}
+
+

Return to:

Send suggestions and report system problems to the System administrator.