summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org.ua>2013-03-10 21:25:11 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-03-10 21:26:52 (GMT)
commit39a97e438dde837ada9a99cceea93a1cf97db19e (patch) (side-by-side diff)
treeefc492dcfcdc2c21bfdec5c31692b348601cd94a /src
parent87602f5492b842f734dffe22f4e2f85dbc6ce713 (diff)
downloadwydawca-39a97e438dde837ada9a99cceea93a1cf97db19e.tar.gz
wydawca-39a97e438dde837ada9a99cceea93a1cf97db19e.tar.bz2
Provide a convenient debugging macro.
Rename logmsg to wy_log.
Diffstat (limited to 'src') (more/less context) (ignore whitespace changes)
-rw-r--r--src/builtin.c4
-rw-r--r--src/dictionary.c26
-rw-r--r--src/directive.c88
-rw-r--r--src/diskio.c107
-rw-r--r--src/exec.c34
-rw-r--r--src/gpg.c62
-rw-r--r--src/job.c53
-rw-r--r--src/lock.c10
-rw-r--r--src/module.c18
-rw-r--r--src/net.c24
-rw-r--r--src/null.c22
-rw-r--r--src/pidfile.c12
-rw-r--r--src/process.c36
-rw-r--r--src/sql.c18
-rw-r--r--src/triplet.c58
-rw-r--r--src/userprivs.c22
-rw-r--r--src/verify.c42
-rw-r--r--src/watcher.c60
-rw-r--r--src/wydawca.c41
-rw-r--r--src/wydawca.h12
20 files changed, 350 insertions, 399 deletions
diff --git a/src/builtin.c b/src/builtin.c
index 72b73cd..b812236 100644
--- a/src/builtin.c
+++ b/src/builtin.c
@@ -80,7 +80,7 @@ cmp_regex(const char *pat, const char *str, int flags)
char errbuf[512];
regerror(rc, &regex, errbuf, sizeof(errbuf));
- logmsg(LOG_ERR, _("%s: cannot compile regexp: %s"), pat,
+ wy_log(LOG_ERR, _("%s: cannot compile regexp: %s"), pat,
errbuf);
return 0;
}
@@ -119,7 +119,7 @@ parse_cmp_type(const char *pat, strcmp_fn * cmpfn, int *rf)
break;
default:
- logmsg(LOG_NOTICE,
+ wy_log(LOG_NOTICE,
_("unrecognized comparison flag: %c"),
*pat);
}
diff --git a/src/dictionary.c b/src/dictionary.c
index f46dd81..4f18267 100644
--- a/src/dictionary.c
+++ b/src/dictionary.c
@@ -65,10 +65,10 @@ dictionary_init(struct dictionary *dict)
return 0;
if (wy_debug_level > 1) {
int i;
- logmsg(LOG_DEBUG, _("initializing dictionary: %s \"%s\""),
+ wy_log(LOG_DEBUG, _("initializing dictionary: %s \"%s\""),
mp->name, SP(dict->query));
for (i = 0; i < dict->parmc; i++)
- logmsg(LOG_DEBUG, " parmv[%d]=%s", i, dict->parmv[i]);
+ wy_log(LOG_DEBUG, " parmv[%d]=%s", i, dict->parmv[i]);
}
if (mp->init)
rc = mp->init(dict);
@@ -110,10 +110,10 @@ dictionary_done(struct dictionary *dict)
return 0;
if (wy_debug_level > 1) {
int i;
- logmsg(LOG_DEBUG, _("closing dictionary: %s \"%s\""),
+ wy_log(LOG_DEBUG, _("closing dictionary: %s \"%s\""),
mp->name, SP(dict->query));
for (i = 0; i < dict->parmc; i++)
- logmsg(LOG_DEBUG, " parmv[%d]=%s", i, dict->parmv[i]);
+ wy_log(LOG_DEBUG, " parmv[%d]=%s", i, dict->parmv[i]);
}
if (mp->done)
rc = mp->done(dict);
@@ -128,24 +128,22 @@ dictionary_lookup(struct dictionary *dict, void *handle, const char *cmd)
{
struct dictionary_descr *mp = dictionary_tab + dict->type;
- if (wy_debug_level > 1) {
- if (cmd)
- logmsg(LOG_DEBUG, _("dictionary lookup: %s \"%s\""),
- mp->name, cmd);
- else
- logmsg(LOG_DEBUG, _("dictionary lookup: %s"),
- mp->name);
- }
+ if (cmd)
+ wy_debug(1, (_("dictionary lookup: %s \"%s\""),
+ mp->name, cmd));
+ else
+ wy_debug(1, (_("dictionary lookup: %s"),
+ mp->name));
if (!dict->init_passed) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
_("INTERNAL ERROR: "
"dictionary %s \"%s\" not initialized"),
mp->name, SP(dict->query));
return 1;
}
if (!mp->lookup) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
_("INTERNAL ERROR: "
"no lookup function for dictionary %s \"%s\""),
mp->name, SP(dict->query));
diff --git a/src/directive.c b/src/directive.c
index cc43c16..481e267 100644
--- a/src/directive.c
+++ b/src/directive.c
@@ -25,9 +25,8 @@ directive_parse(struct file_triplet *trp)
size_t dcount, i, j;
char *p;
- if (wy_debug_level > 2)
- logmsg(LOG_DEBUG, _("%s: parsing directive blurb: %s"),
- trp->file[file_directive].name, trp->blurb);
+ wy_debug(3, (_("%s: parsing directive blurb: %s"),
+ trp->file[file_directive].name, trp->blurb));
dcount = 0;
for (p = trp->blurb; *p; p++)
@@ -44,7 +43,7 @@ directive_parse(struct file_triplet *trp)
if (trim(trp->directive[j]) == 0) /* ignore empty lines */
continue;
if (strchr(trp->directive[j], ':') == NULL) {
- logmsg(LOG_ERR, _("%s: invalid line: %s"),
+ wy_log(LOG_ERR, _("%s: invalid line: %s"),
trp->file[file_directive].name,
trp->directive[j]);
free(trp->directive);
@@ -174,17 +173,17 @@ directive_version_in_range_p(struct file_triplet *trp,
unsigned version;
if (directive_get_value(trp, "version", &val)) {
- logmsg(LOG_ERR, _("%s: missing `version' directive"),
+ wy_log(LOG_ERR, _("%s: missing `version' directive"),
trp->file[file_directive].name);
return 0;
}
if (directive_pack_version(val, &version)) {
- logmsg(LOG_ERR, _("%s: unparsable version: %s"),
+ wy_log(LOG_ERR, _("%s: unparsable version: %s"),
trp->file[file_directive].name, val);
return 0;
}
- logmsg(LOG_NOTICE, _("%s: VERSION: %s"),
+ wy_log(LOG_NOTICE, _("%s: VERSION: %s"),
trp->file[file_directive].name, val);
trp->version = version;
@@ -192,7 +191,7 @@ directive_version_in_range_p(struct file_triplet *trp,
if (from <= version && version <= to)
return 1;
- logmsg(LOG_ERR, _("%s: version %s is not in the allowed range"),
+ wy_log(LOG_ERR, _("%s: version %s is not in the allowed range"),
trp->file[file_directive].name, val);
return 0;
}
@@ -257,7 +256,7 @@ verify_directive_format(struct file_triplet *trp)
switch (dnum) {
case 1:
if (strcmp(key, "version")) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("%s:%d: expected `%s' but found `%s'"),
trp->file[file_directive].name, n,
"version", key);
@@ -267,7 +266,7 @@ verify_directive_format(struct file_triplet *trp)
case 2:
if (strcmp(key, "directory")) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("%s:%d: expected `%s' but found `%s'"),
trp->file[file_directive].name, n,
"directory", key);
@@ -277,7 +276,7 @@ verify_directive_format(struct file_triplet *trp)
default:
if (find_directive(key) == unknown_dir) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("%s:%d: unknown directive `%s'"),
trp->file[file_directive].name, n, key);
return 1;
@@ -288,12 +287,12 @@ verify_directive_format(struct file_triplet *trp)
if (trp->file[file_dist].name && trp->file[file_signature].name) {
const char *filename;
if (directive_get_value(trp, "filename", &filename)) {
- logmsg(LOG_ERR, _("%s: missing `filename' directive"),
+ wy_log(LOG_ERR, _("%s: missing `filename' directive"),
trp->file[file_directive].name);
return 1;
}
if (strcmp(filename, trp->file[file_dist].name)) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("%s: filename %s does not match actual name"),
trp->file[file_dist].name, filename);
return 1;
@@ -315,7 +314,7 @@ save_script(const char *script)
fd = mkstemp(file_name);
umask(old_mask);
if (fd == -1) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
_("cannot create temporary script file %s: %s"),
file_name, strerror(errno));
free(file_name);
@@ -326,14 +325,14 @@ save_script(const char *script)
while (length) {
ssize_t wrb = write(fd, script, length);
if (wrb == -1) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
_("error writing to temporary script "
"file %s: %s"),
file_name, strerror(errno));
break;
}
if (wrb == 0) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
_("short write to temporary script file %s"),
file_name);
break;
@@ -357,13 +356,13 @@ stderr_redirector(const char *tag)
pid_t pid;
if (pipe(p)) {
- logmsg(LOG_CRIT, "redirector pipe: %s", strerror(errno));
+ wy_log(LOG_CRIT, "redirector pipe: %s", strerror(errno));
return -1;
}
pid = fork();
if (pid == -1) {
- logmsg(LOG_CRIT, "redirector fork: %s", strerror(errno));
+ wy_log(LOG_CRIT, "redirector fork: %s", strerror(errno));
return -1;
}
@@ -378,7 +377,7 @@ stderr_redirector(const char *tag)
_exit(127);
while (grecs_getline(&buf, &size, fp) >= 0) {
trim_crlf(buf);
- logmsg(LOG_NOTICE, "%s: %s", tag, buf);
+ wy_log(LOG_NOTICE, "%s: %s", tag, buf);
}
_exit(0);
}
@@ -400,23 +399,21 @@ run_check_script(const char *script, struct file_triplet *trp,
char *buf;
size_t size, total;
- if (wy_debug_level > 1)
- logmsg(LOG_DEBUG, _("prep script: %20.20s%s"),
- script, strlen(script) > 20 ? "..." : "");
+ wy_debug(2, (_("prep script: %20.20s%s"),
+ script, strlen(script) > 20 ? "..." : ""));
script_file = save_script(script);
if (!script_file)
return 1;
- if (wy_debug_level > 1)
- logmsg(LOG_DEBUG, _("script file: %s"), script_file);
+ wy_debug(2, (_("script file: %s"), script_file));
if (pipe(p)) {
- logmsg(LOG_CRIT, "pipe: %s", strerror(errno));
+ wy_log(LOG_CRIT, "pipe: %s", strerror(errno));
return 1;
}
oldsig = signal(SIGCHLD, SIG_DFL);
pid = fork();
if (pid == -1) {
- logmsg(LOG_CRIT, "fork: %s", strerror(errno));
+ wy_log(LOG_CRIT, "fork: %s", strerror(errno));
free(script_file);
close(p[0]);
close(p[1]);
@@ -446,14 +443,14 @@ run_check_script(const char *script, struct file_triplet *trp,
}
if (p[1] != 1 && dup2(p[1], 1) != 1) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
"cannot duplicate script's stdout: %s",
strerror(errno));
_exit(127);
}
if (efd != 2 && dup2(efd, 2) != 2) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
"cannot duplicate script's stderr: %s",
strerror(errno));
_exit(127);
@@ -467,7 +464,7 @@ run_check_script(const char *script, struct file_triplet *trp,
setenv("WYDAWCA_DIST_FILE", trp->file[file_dist].name, 1);
if (chdir(temp_homedir)) {
- logmsg(LOG_CRIT, "cannot change to %s: %s",
+ wy_log(LOG_CRIT, "cannot change to %s: %s",
temp_homedir, strerror(errno));
_exit(127);
}
@@ -486,18 +483,15 @@ run_check_script(const char *script, struct file_triplet *trp,
fp = fdopen(p[0], "r");
buf = NULL;
size = total = 0;
- if (wy_debug_level > 2)
- logmsg(LOG_DEBUG, _("reading script output..."));
+ wy_debug(3, (_("reading script output...")));
while (grecs_getline(&buf, &size, fp) > 0) {
size_t len = strlen(buf);
- if (wy_debug_level > 2)
- logmsg(LOG_DEBUG, _("read: %s"), buf);
+ wy_debug(3, (_("read: %s"), buf));
txtacc_grow(trp->acc, buf, len);
total += size;
}
txtacc_1grow(trp->acc, 0);
- if (wy_debug_level > 2)
- logmsg(LOG_DEBUG, _("bytes read: %lu"), (unsigned long)total);
+ wy_debug(3, (_("bytes read: %lu"), (unsigned long)total));
fclose(fp);
@@ -511,20 +505,20 @@ run_check_script(const char *script, struct file_triplet *trp,
if (WIFEXITED(status)) {
status = WEXITSTATUS(status);
if (status) {
- logmsg(LOG_ERR, "%s for %s@%s returned %d",
+ wy_log(LOG_ERR, "%s for %s@%s returned %d",
descr, trp->name, trp->spool->tag, status);
return 1;
- } else if (wy_debug_level > 2)
- logmsg(LOG_DEBUG, "%s for %s@%s returned %d",
- descr, trp->name, trp->spool->tag, status);
+ } else
+ wy_debug(3, ("%s for %s@%s returned %d",
+ descr, trp->name, trp->spool->tag, status));
} else if (WIFSIGNALED(status)) {
int sig = WTERMSIG(status);
- logmsg(LOG_NOTICE,
+ wy_log(LOG_NOTICE,
"%s for %s@%s terminated on signal %d",
descr, trp->name, trp->spool->tag, sig);
return 1;
} else {
- logmsg(LOG_NOTICE,
+ wy_log(LOG_NOTICE,
"%s for %s@%s terminated with unhandled status",
descr, trp->name, trp->spool->tag);
return 1;
@@ -576,14 +570,14 @@ symlink_filelist(struct file_triplet *trp, const char *key, const char *val)
struct wordsplit ws;
if (wordsplit(val, &ws, WRDSF_DEFFLAGS)) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("cannot parse symlink value `%s'"), val);
return 1;
}
if (ws.ws_wordc != 2) {
rc = 1;
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("wrong number of arguments to %s directive: `%s'"),
key, val);
} else
@@ -614,7 +608,7 @@ process_directives(struct file_triplet *trp)
abort();
case comment_dir:
- logmsg(LOG_NOTICE, _("%s: COMMENT: %s"),
+ wy_log(LOG_NOTICE, _("%s: COMMENT: %s"),
trp->file[file_directive].name, val);
break;
@@ -632,7 +626,7 @@ process_directives(struct file_triplet *trp)
move_file(trp, file_signature))
return 1;
} else {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("invalid detached signature for %s"),
trp->name);
return 1;
@@ -661,7 +655,7 @@ process_directives(struct file_triplet *trp)
case replace_dir:
if (trp->version < 102) {
rc = 1;
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("\"replace\" directive is invalid "
"for version %d"),
trp->version);
@@ -670,7 +664,7 @@ process_directives(struct file_triplet *trp)
}
if (!dry_run_mode && unlink(trp->file[file_directive].name)) {
- logmsg(LOG_CRIT, _("%s: cannot unlink directive file: %s"),
+ wy_log(LOG_CRIT, _("%s: cannot unlink directive file: %s"),
trp->file[file_directive].name, strerror(errno));
}
diff --git a/src/diskio.c b/src/diskio.c
index 9574014..99d3b54 100644
--- a/src/diskio.c
+++ b/src/diskio.c
@@ -66,13 +66,13 @@ create_hierarchy(char *dir, size_t baselen)
if (stat(dir, &st) == 0) {
if (!S_ISDIR(st.st_mode)) {
- logmsg(LOG_ERR, _("component %s is not a directory"),
+ wy_log(LOG_ERR, _("component %s is not a directory"),
dir);
return 1;
}
return 0;
} else if (errno != ENOENT) {
- logmsg(LOG_ERR, _("cannot stat file %s: %s"), dir,
+ wy_log(LOG_ERR, _("cannot stat file %s: %s"), dir,
strerror(errno));
return 1;
}
@@ -80,7 +80,7 @@ create_hierarchy(char *dir, size_t baselen)
p = strrchr(dir, '/');
if (p) {
if (p - dir + 1 < baselen) {
- logmsg(LOG_ERR, _("base directory %s does not exist"),
+ wy_log(LOG_ERR, _("base directory %s does not exist"),
dir);
return 1;
}
@@ -92,7 +92,7 @@ create_hierarchy(char *dir, size_t baselen)
if (p)
*p = '/';
if (mkdir(dir, MKDIR_PERMISSIONS)) {
- logmsg(LOG_ERR, _("cannot create directory %s: %s"),
+ wy_log(LOG_ERR, _("cannot create directory %s: %s"),
dir, strerror(errno));
rc = 1;
}
@@ -132,14 +132,14 @@ copy_file(const char *file, const char *dst_file)
in_fd = open(file, O_RDONLY);
if (in_fd == -1) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("cannot open source file %s for reading: %s"),
file, strerror(errno));
return 1;
}
if (fstat(in_fd, &st)) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("cannot stat source file %s: %s"),
file, strerror(errno));
close(in_fd);
@@ -148,7 +148,7 @@ copy_file(const char *file, const char *dst_file)
out_fd = creat(dst_file, CREAT_PERMISSIONS);
if (out_fd == -1) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("cannot create destination file %s: %s"),
dst_file, strerror(errno));
close(in_fd);
@@ -171,20 +171,20 @@ copy_file(const char *file, const char *dst_file)
rest = fsize > bufsize ? bufsize : fsize;
rdbytes = read(in_fd, buf, rest);
if (rdbytes == -1) {
- logmsg(LOG_ERR, _("unexpected error reading %s: %s"),
+ wy_log(LOG_ERR, _("unexpected error reading %s: %s"),
file, strerror(errno));
rc = 1;
break;
}
rest = write(out_fd, buf, rdbytes);
if (rest == -1) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("unexpected error writing to %s: %s"),
dst_file, strerror(errno));
rc = 1;
break;
} else if (rest != rdbytes) {
- logmsg(LOG_ERR, _("short write on %s"), dst_file);
+ wy_log(LOG_ERR, _("short write on %s"), dst_file);
rc = 1;
}
fsize -= rdbytes;
@@ -208,15 +208,15 @@ do_move_file(const char *file, const char *dst_file)
if (rename(file, dst_file)) {
if (errno == EXDEV) {
if (copy_file(file, dst_file)) {
- logmsg(LOG_CRIT, _("cannot copy %s to %s: %s"),
+ wy_log(LOG_CRIT, _("cannot copy %s to %s: %s"),
file, dst_file, strerror(errno));
rc = 1;
} else if (unlink(file)) {
- logmsg(LOG_ERR, _("cannot unlink %s: %s"),
+ wy_log(LOG_ERR, _("cannot unlink %s: %s"),
file, strerror(errno));
}
} else {
- logmsg(LOG_CRIT, _("cannot move %s to %s: %s"),
+ wy_log(LOG_CRIT, _("cannot move %s to %s: %s"),
file, dst_file, strerror(errno));
rc = 1;
}
@@ -231,8 +231,7 @@ tar_append_file(const char *archive, const char *file)
{
const char *argv[6];
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("tarring %s to %s"), file, archive);
+ wy_debug(1, (_("tarring %s to %s"), file, archive));
if (dry_run_mode) {
UPDATE_STATS(STAT_ARCHIVES);
return 0;
@@ -252,7 +251,7 @@ tar_append_file(const char *archive, const char *file)
case exec_fail:
case exec_error:
- logmsg(LOG_ERR, _("cannot archive %s"), file);
+ wy_log(LOG_ERR, _("cannot archive %s"), file);
break;
}
@@ -286,13 +285,11 @@ backup_file(const char *dst_file, const char *dst_dir, const char *file,
file_name = concat_dir(adir, file, NULL);
if (access(file_name, F_OK) == 0) {
if (archive->backup_type == no_backups) {
- if (wy_debug_level)
- logmsg(LOG_DEBUG,
- _("removing previous archive "
- "file `%s'"),
- file_name);
+ wy_debug(1, (_("removing previous archive "
+ "file `%s'"),
+ file_name));
if (!dry_run_mode && unlink(file_name)) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("cannot unlink previous archive "
"file `%s': %s"),
file_name, strerror(errno));
@@ -304,16 +301,14 @@ backup_file(const char *dst_file, const char *dst_dir, const char *file,
char *archive_file_name =
find_backup_file_name(file_name,
archive->backup_type);
- if (wy_debug_level)
- logmsg(LOG_DEBUG,
- _("backing up previous archive "
- "file `%s' to `%s'"),
- file_name, archive_file_name);
+ wy_debug(1, (_("backing up previous archive "
+ "file `%s' to `%s'"),
+ file_name, archive_file_name));
if (!dry_run_mode) {
rc = do_move_file(file_name,
archive_file_name);
if (rc) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("backing `%s' up as `%s' failed: %s"),
file_name, archive_file_name,
strerror(errno));
@@ -327,13 +322,11 @@ backup_file(const char *dst_file, const char *dst_dir, const char *file,
}
}
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("archiving `%s' to `%s'"), dst_file,
- file_name);
+ wy_debug(1, (_("archiving `%s' to `%s'"), dst_file, file_name));
if (!dry_run_mode) {
rc = do_move_file(dst_file, file_name);
if (rc)
- logmsg(LOG_ERR, _("archiving `%s' as `%s' failed: %s"),
+ wy_log(LOG_ERR, _("archiving `%s' as `%s' failed: %s"),
dst_file, file_name, strerror(errno));
}
free(file_name);
@@ -365,7 +358,7 @@ do_archive_file(const char *dst_file, const char *dst_dir, const char *file,
}
if (!dry_run_mode && unlink(dst_file) && errno != ENOENT) {
- logmsg(LOG_ERR, _("canot unlink file `%s': %s"),
+ wy_log(LOG_ERR, _("canot unlink file `%s': %s"),
dst_file, strerror(errno));
return 1;
}
@@ -408,9 +401,8 @@ dir_move_file(struct file_triplet *trp, enum file_type file_id)
return 1;
dst_file = concat_dir(dst_dir, trp->file[file_id].name, NULL);
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("installing %s to %s"),
- trp->file[file_id].name, dst_dir);
+ wy_debug(1, (_("installing %s to %s"),
+ trp->file[file_id].name, dst_dir));
if (access(dst_file, F_OK) == 0) {
if (replace_allowed_p(trp))
@@ -419,7 +411,7 @@ dir_move_file(struct file_triplet *trp, enum file_type file_id)
&spool->archive,
trp->relative_dir);
else {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("refusing to upload %s because it already "
"exists and replace is not allowed"),
trp->file[file_id].name);
@@ -457,7 +449,7 @@ archive_single_file(struct file_triplet *trp, const char *file_name,
dst_file = safe_file_name(concat_dir(dst_dir, file_name, NULL));
if (!sub_dir_p(dst_file, spool->dest_dir)) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("file to be archived `%s' does not lie under `%s'"),
dst_file, spool->dest_dir);
free(dst_file);
@@ -466,18 +458,17 @@ archive_single_file(struct file_triplet *trp, const char *file_name,
}
if (access(dst_file, F_OK) == 0) {
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("archiving file `%s'"), dst_file);
+ wy_debug(1, (_("archiving file `%s'"), dst_file));
rc = do_archive_file(dst_file, dst_dir, file_name,
&spool->archive, trp->relative_dir);
} else if (errno == ENOENT) {
if (!noentok)
- logmsg(LOG_NOTICE,
+ wy_log(LOG_NOTICE,
_("nothing to archive: "
"file `%s' does not exist"),
dst_file);
} else {
- logmsg(LOG_ERR, _("canot access file `%s': %s"),
+ wy_log(LOG_ERR, _("canot access file `%s': %s"),
dst_file, strerror(errno));
rc = 1;
}
@@ -539,7 +530,7 @@ dir_symlink_file(struct file_triplet *trp,
src = safe_file_name_alloc(wanted_src);
if (!src || src[0] == '/') {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("symlink source `%s' does not lie under `%s'"),
wanted_src, spool->dest_dir);
free(src);
@@ -548,7 +539,7 @@ dir_symlink_file(struct file_triplet *trp,
dst = safe_file_name_alloc(wanted_dst);
if (!dst || dst[0] == '/') {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("symlink destination `%s' does not lie under `%s'"),
wanted_dst, spool->dest_dir);
free(src);
@@ -556,9 +547,8 @@ dir_symlink_file(struct file_triplet *trp,
return 1;
}
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("symlinking %s to %s in directory %s"),
- src, dst, dst_dir);
+ wy_debug(1, (_("symlinking %s to %s in directory %s"),
+ src, dst, dst_dir));
if (!dry_run_mode) {
char *p = strrchr(dst, '/');
@@ -576,25 +566,25 @@ dir_symlink_file(struct file_triplet *trp,
if (rc == 0) {
if (push_dir(dst_dir))
- logmsg(LOG_ERR, _("cannot change to %s: %s"),
+ wy_log(LOG_ERR, _("cannot change to %s: %s"),
dst_dir, strerror(errno));
else {
struct stat st;
if (lstat(dst, &st) == 0) {
if (!S_ISLNK(st.st_mode)) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("file %s exists and is not a symbolic link"),
dst);
rc = 1;
} else if (unlink(dst)) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("cannot unlink %s: %s"),
dst, strerror(errno));
rc = 1;
}
} else if (errno != ENOENT) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("cannot stat file %s: %s"),
dst, strerror(errno));
rc = 1;
@@ -603,13 +593,13 @@ dir_symlink_file(struct file_triplet *trp,
if (rc == 0) {
rc = symlink(src, dst);
if (rc)
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("symlinking %s to %s in directory %s failed: %s"),
src, dst, dst_dir,
strerror(errno));
}
if (pop_dir()) {
- logmsg(LOG_EMERG,
+ wy_log(LOG_EMERG,
_("cannot restore current directory: %s"),
strerror(errno));
exit(EX_SOFTWARE);
@@ -632,26 +622,25 @@ do_rmsymlink_file(const char *dst_file, int noentok)
{
struct stat st;
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("removing symbolic link %s"), dst_file);
+ wy_debug(1, (_("removing symbolic link %s"), dst_file));
if (stat(dst_file, &st)) {
if (errno == ENOENT) {
if (!noentok)
- logmsg(LOG_NOTICE,
+ wy_log(LOG_NOTICE,
_("symlink `%s' does not exist"),
dst_file);
return 0;
}
if (!S_ISLNK(st.st_mode)) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("refusing to unlink %s: is not a symlink"),
dst_file);
return 1;
}
}
if (!dry_run_mode && unlink(dst_file)) {
- logmsg(LOG_ERR, _("cannot unlink %s: %s"), dst_file,
+ wy_log(LOG_ERR, _("cannot unlink %s: %s"), dst_file,
strerror(errno));
return 1;
}
@@ -676,7 +665,7 @@ dir_rmsymlink_file(struct file_triplet *trp, const char *file_name)
dst_file = safe_file_name(concat_dir(dst_dir, file_name, NULL));
if (!sub_dir_p(dst_file, spool->dest_dir)) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("refusing to remove a symlink `%s' that is not "
"located under `%s'"), dst_file, spool->dest_dir);
free(dst_file);
diff --git a/src/exec.c b/src/exec.c
index c41d48c..5b75f77 100644
--- a/src/exec.c
+++ b/src/exec.c
@@ -31,7 +31,7 @@ start_prog(int argc, const char **argv, pid_t * ppid)
int i;
if (pipe(p)) {
- logmsg(LOG_CRIT, "pipe: %s", strerror(errno));
+ wy_log(LOG_CRIT, "pipe: %s", strerror(errno));
return NULL;
}
@@ -40,12 +40,12 @@ start_prog(int argc, const char **argv, pid_t * ppid)
/* Child process */
if (p[1] != 1 && dup2(p[1], 1) == -1) {
- logmsg(LOG_CRIT, "dup2: %s", strerror(errno));
+ wy_log(LOG_CRIT, "dup2: %s", strerror(errno));
_exit(EX_UNAVAILABLE);
}
if (p[1] != 1 && dup2(p[1], 2) == -1) {
- logmsg(LOG_CRIT, "dup2: %s", strerror(errno));
+ wy_log(LOG_CRIT, "dup2: %s", strerror(errno));
_exit(EX_UNAVAILABLE);
}
@@ -56,12 +56,12 @@ start_prog(int argc, const char **argv, pid_t * ppid)
close(i);
execvp(argv[0], (char **)argv);
- logmsg(LOG_CRIT, _("cannot run %s: %s"), argv[0],
+ wy_log(LOG_CRIT, _("cannot run %s: %s"), argv[0],
strerror(errno));
exit(EX_UNAVAILABLE);
case -1:
- logmsg(LOG_CRIT, _("cannot run `%s': fork failed: %s"),
+ wy_log(LOG_CRIT, _("cannot run `%s': fork failed: %s"),
argv[0], strerror(errno));
return NULL;
@@ -70,7 +70,7 @@ start_prog(int argc, const char **argv, pid_t * ppid)
close(p[1]);
fp = fdopen(p[0], "r");
if (!fp)
- logmsg(LOG_ERR, _("cannot fdopen: %s"),
+ wy_log(LOG_ERR, _("cannot fdopen: %s"),
strerror(errno));
*ppid = pid;
}
@@ -80,15 +80,15 @@ start_prog(int argc, const char **argv, pid_t * ppid)
/* Log everything read from FP as the output from the program PROG, using
syslog priority PRIO. */
void
-log_output(int prio, const char *prog, FILE * fp)
+log_output(int prio, const char *prog, FILE *fp)
{
size_t size = 0;
char *buf = NULL;
- logmsg(prio, _("%s output follows:"), prog);
+ wy_log(prio, _("%s output follows:"), prog);
while (grecs_getline(&buf, &size, fp) > 0)
- logmsg(prio, "%s", buf);
- logmsg(prio, _("end of %s output"), prog);
+ wy_log(prio, "%s", buf);
+ wy_log(prio, _("end of %s output"), prog);
free(buf);
}
@@ -104,7 +104,7 @@ wydawca_exec(int argc, const char **argv, int *retcode)
fp = start_prog(5, argv, &pid);
if (!fp) {
- logmsg(LOG_CRIT, _("cannot start %s"), argv[0]);
+ wy_log(LOG_CRIT, _("cannot start %s"), argv[0]);
return exec_error;
}
@@ -113,13 +113,13 @@ wydawca_exec(int argc, const char **argv, int *retcode)
switch (npid) {
case -1:
- logmsg(LOG_CRIT, _("cannot execute %s: waitpid failed: %s"),
+ wy_log(LOG_CRIT, _("cannot execute %s: waitpid failed: %s"),
argv[0], strerror(errno));
fclose(fp);
return exec_error;
case 0:
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
_("cannot execute %s: the process did not respond "
"within 5 seconds: %s"), argv[0], strerror(errno));
kill(pid, SIGKILL);
@@ -134,7 +134,7 @@ wydawca_exec(int argc, const char **argv, int *retcode)
int rc = WEXITSTATUS(status);
if (rc) {
res = exec_fail;
- logmsg(LOG_ERR, _("command %s returned %d"), argv[0],
+ wy_log(LOG_ERR, _("command %s returned %d"), argv[0],
rc);
log_output(LOG_ERR, argv[0], fp);
} else {
@@ -147,13 +147,13 @@ wydawca_exec(int argc, const char **argv, int *retcode)
} else {
res = exec_error;
if (WIFSIGNALED(status))
- logmsg(LOG_ERR, _("%s terminated on signal %d"),
+ wy_log(LOG_ERR, _("%s terminated on signal %d"),
argv[0], WTERMSIG(status));
else if (WIFSTOPPED(status))
- logmsg(LOG_ERR, _("%s stopped on signal %d"),
+ wy_log(LOG_ERR, _("%s stopped on signal %d"),
argv[0], WTERMSIG(status));
else
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("%s terminated with unrecognized status"),
argv[0]);
}
diff --git a/src/gpg.c b/src/gpg.c
index 1eb1db8..7b5146e 100644
--- a/src/gpg.c
+++ b/src/gpg.c
@@ -22,7 +22,7 @@
#define fail_if_err(expr) do { \
int a = expr; \
if (a) { \
- logmsg(LOG_ERR, _("%s: GPGME error: %s"), #expr, \
+ wy_log(LOG_ERR, _("%s: GPGME error: %s"), #expr, \
gpgme_strerror(a)); \
return 1; \
} \
@@ -42,14 +42,14 @@ recursive_rmdir(const char *name)
struct dirent *ent;
if (chdir(name)) {
- logmsg(LOG_ERR, _("cannot change to directory %s: %s"),
+ wy_log(LOG_ERR, _("cannot change to directory %s: %s"),
name, strerror(errno));
return 1;
}
dir = opendir(".");
if (!dir) {
- logmsg(LOG_ERR, _("cannot open directory %s: %s"),
+ wy_log(LOG_ERR, _("cannot open directory %s: %s"),
name, strerror(errno));
return 1;
}
@@ -62,13 +62,13 @@ recursive_rmdir(const char *name)
continue;
if (stat(ent->d_name, &st) && errno != ENOENT) {
- logmsg(LOG_ERR, _("cannot stat file `%s': %s"),
+ wy_log(LOG_ERR, _("cannot stat file `%s': %s"),
name, strerror(errno));
rc = 1;
} else if (S_ISDIR(st.st_mode))
rc = rmdir_r(ent->d_name);
else if ((rc = unlink(ent->d_name)) != 0 && errno != ENOENT)
- logmsg(LOG_ERR, _("cannot unlink %s: %s"),
+ wy_log(LOG_ERR, _("cannot unlink %s: %s"),
ent->d_name, strerror(errno));
}
closedir(dir);
@@ -83,19 +83,19 @@ rmdir_r(const char *name)
int rc;
if (push_dir(NULL)) {
- logmsg(LOG_ERR, _("cannot save current directory: %s"),
+ wy_log(LOG_ERR, _("cannot save current directory: %s"),
strerror(errno));
return 1;
}
rc = recursive_rmdir(name);
if (pop_dir()) {
- logmsg(LOG_ERR, _("cannot restore current directory: %s"),
+ wy_log(LOG_ERR, _("cannot restore current directory: %s"),
strerror(errno));
rc = 1;
}
if (rc == 0 && rmdir(name)) {
- logmsg(LOG_ERR, _("cannot remove directory %s: %s"),
+ wy_log(LOG_ERR, _("cannot remove directory %s: %s"),
name, strerror(errno));
return 1;
}
@@ -107,11 +107,9 @@ rmdir_r(const char *name)
static void
remove_homedir()
{
- if (wy_debug_level > 1)
- logmsg(LOG_DEBUG, _("removing GNUPG home directory: %s"),
- temp_homedir);
+ wy_debug(2, (_("removing GNUPG home directory: %s"), temp_homedir));
if (rmdir_r(temp_homedir))
- logmsg(LOG_CRIT, _("failed to remove GPG directory %s"),
+ wy_log(LOG_CRIT, _("failed to remove GPG directory %s"),
temp_homedir);
}
@@ -124,14 +122,13 @@ create_gpg_homedir()
temp_homedir = grecs_strdup("/tmp/wydawca-XXXXXX");
if (!mkdtemp(temp_homedir)) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
_("cannot create GPG home directory (%s): %s"),
temp_homedir, strerror(errno));
return 1;
}
atexit(remove_homedir);
- if (wy_debug_level > 1)
- logmsg(LOG_DEBUG, _("GNUPG home directory: %s"), temp_homedir);
+ wy_debug(2, (_("GNUPG home directory: %s"), temp_homedir));
setenv("GNUPGHOME", temp_homedir, 1);
return 0;
}
@@ -141,12 +138,11 @@ checksig(gpgme_signature_t sig, const char *uid, struct file_triplet *trp)
{
switch (gpg_err_code(sig->status)) {
case GPG_ERR_NO_ERROR:
- if (wy_debug_level)
- logmsg(LOG_NOTICE, _("Good signature from %s"), uid);
+ wy_debug(1, (_("Good signature from %s"), uid));
trp->uploader = uploader_find_frp(trp->uploader_list,
sig->fpr);
if (!trp->uploader) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("good signature from %s, "
"but the uploader info for %s not found"),
uid, sig->fpr);
@@ -156,31 +152,31 @@ checksig(gpgme_signature_t sig, const char *uid, struct file_triplet *trp)
case GPG_ERR_BAD_SIGNATURE:
UPDATE_STATS(STAT_BAD_SIGNATURE);
- logmsg(LOG_ERR, _("BAD signature from %s"), uid);
+ wy_log(LOG_ERR, _("BAD signature from %s"), uid);
return 0;
case GPG_ERR_NO_PUBKEY:
UPDATE_STATS(STAT_ACCESS_VIOLATIONS);
- logmsg(LOG_ERR, _("No public key"));
+ wy_log(LOG_ERR, _("No public key"));
return 0;
case GPG_ERR_NO_DATA:
UPDATE_STATS(STAT_BAD_TRIPLETS);
- logmsg(LOG_ERR, _("No signature"));
+ wy_log(LOG_ERR, _("No signature"));
return 0;
case GPG_ERR_SIG_EXPIRED:
UPDATE_STATS(STAT_BAD_SIGNATURE);
- logmsg(LOG_ERR, _("Expired signature from %s"), uid);
+ wy_log(LOG_ERR, _("Expired signature from %s"), uid);
return 0;
case GPG_ERR_KEY_EXPIRED:
UPDATE_STATS(STAT_BAD_SIGNATURE);
- logmsg(LOG_ERR, _("Key expired (%s)"), uid);
+ wy_log(LOG_ERR, _("Key expired (%s)"), uid);
return 0;
default:
- logmsg(LOG_ERR, _("Unknown signature error"));
+ wy_log(LOG_ERR, _("Unknown signature error"));
return 0;
}
return -1;
@@ -234,10 +230,8 @@ verify_directive_signature(struct file_triplet *trp)
res = gpgme_op_import_result(ctx);
pstat = res->imports;
uptr->fpr = grecs_strdup(pstat->fpr);
- if (wy_debug_level > 2)
- logmsg(LOG_DEBUG,
- _("imported key: user = %s, fingerprint = %s"),
- uptr->name, uptr->fpr);
+ wy_debug(3, (_("imported key: user = %s, fingerprint = %s"),
+ uptr->name, uptr->fpr));
}
fail_if_err(gpgme_data_new_from_file(&directive_data,
@@ -259,7 +253,7 @@ verify_directive_signature(struct file_triplet *trp)
} else {
rc = 1;
UPDATE_STATS(STAT_BAD_SIGNATURE);
- logmsg(LOG_ERR, _("%s: directive verification failed: %s"),
+ wy_log(LOG_ERR, _("%s: directive verification failed: %s"),
trp->name, gpgme_strerror(ec));
}
@@ -287,7 +281,7 @@ verify_detached_signature(struct file_triplet *trp)
while (info && info->protocol != GPGME_PROTOCOL_OpenPGP)
info = info->next;
if (!info) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
_("cannot find path to gpg binary (attempting to "
"verify the detached signature for %s"), trp->name);
return 1;
@@ -302,19 +296,17 @@ verify_detached_signature(struct file_triplet *trp)
switch (wydawca_exec(5, argv, NULL)) {
case exec_success:
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("good detached signature for %s"),
- trp->name);
+ wy_debug(1, (_("good detached signature for %s"), trp->name));
return 0;
case exec_fail:
UPDATE_STATS(STAT_BAD_SIGNATURE);
- logmsg(LOG_ERR, _("BAD detached signature for %s"), trp->name);
+ wy_log(LOG_ERR, _("BAD detached signature for %s"), trp->name);
notify(spool->notification, trp, ev_bad_detached_signature);
break;
case exec_error:
- logmsg(LOG_CRIT, _("cannot verify detached signature for %s"),
+ wy_log(LOG_CRIT, _("cannot verify detached signature for %s"),
trp->name);
break;
}
diff --git a/src/job.c b/src/job.c
index 11e488f..316a6a2 100644
--- a/src/job.c
+++ b/src/job.c
@@ -149,13 +149,12 @@ job_start(struct job *job)
pid_t pid;
if (jobmax && jobcnt == jobmax) {
- logmsg(LOG_NOTICE, "maximum number of processes active");
+ wy_log(LOG_NOTICE, "maximum number of processes active");
return 1;
}
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("starting job: %s, %lu"),
- job->spool->tag, (unsigned long)job->uid);
+ wy_debug(1, (_("starting job: %s, %lu"),
+ job->spool->tag, (unsigned long)job->uid));
if (single_process) {
if (wydawca_scanner(job))
@@ -180,7 +179,7 @@ job_start(struct job *job)
close(i);
exit(wydawca_scanner(job) ? WYDAWCA_EX_AGAIN : 0);
} else if (pid == -1) {
- logmsg(LOG_CRIT, "fork: %s", strerror(errno));
+ wy_log(LOG_CRIT, "fork: %s", strerror(errno));
return -1;
} else {
job->state = STATE_ACTIVE;
@@ -195,9 +194,8 @@ job_remove(struct job *job)
{
struct job *p;
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("removing job: %s, %lu"),
- job->spool->tag, (unsigned long)job->uid);
+ wy_debug(1, (_("removing job: %s, %lu"),
+ job->spool->tag, (unsigned long)job->uid));
p = job->prev;
if (p)
p->next = job->next;
@@ -238,9 +236,8 @@ schedule_job(struct spool *spool, uid_t uid, struct file_triplet *tp)
if (!spool)
spool = &fake_spool;
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("scheduling job: %s, %lu"),
- spool->tag, (unsigned long)uid);
+ wy_debug(1, (_("scheduling job: %s, %lu"),
+ spool->tag, (unsigned long)uid));
job = job_locate(spool, uid, tp ? STATE_QUEUED : STATE_ANY);
if (!job) {
@@ -268,21 +265,17 @@ print_status(struct job *job, int expect_term)
if (WIFEXITED(status)) {
int exit_code = WEXITSTATUS(status);
if (exit_code == 0) {
- if (wy_debug_level)
- logmsg(LOG_DEBUG,
- _("%lu (%s, %s) exited successfully"),
- (unsigned long)job->pid,
- job->spool->tag,
- pw->pw_name);
+ wy_debug(1, (_("%lu (%s, %s) exited successfully"),
+ (unsigned long)job->pid,
+ job->spool->tag,
+ pw->pw_name));
} else if (exit_code == WYDAWCA_EX_AGAIN) {
- if (wy_debug_level)
- logmsg(LOG_DEBUG,
- _("%lu (%s, %s) reported tempfail"),
- (unsigned long)job->pid,
- job->spool->tag,
- pw->pw_name);
+ wy_debug(1, (_("%lu (%s, %s) reported tempfail"),
+ (unsigned long)job->pid,
+ job->spool->tag,
+ pw->pw_name));
} else
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("%lu (%s, %s) failed with status %d"),
(unsigned long)job->pid, job->spool->tag,
pw->pw_name, exit_code);
@@ -295,23 +288,23 @@ print_status(struct job *job, int expect_term)
} else
prio = LOG_ERR;
- logmsg(prio,
+ wy_log(prio,
_("%lu (%s, %s) terminated on signal %d"),
(unsigned long)job->pid, job->spool->tag,
pw->pw_name, WTERMSIG(status));
} else if (WIFSTOPPED(status))
- logmsg(LOG_NOTICE,
+ wy_log(LOG_NOTICE,
_("%lu (%s, %s) stopped on signal %d"),
(unsigned long)job->pid, job->spool->tag,
pw->pw_name, WSTOPSIG(status));
#ifdef WCOREDUMP
else if (WCOREDUMP(status))
- logmsg(LOG_NOTICE,
+ wy_log(LOG_NOTICE,
_("%lu (%s, %s) dumped core"),
(unsigned long)job->pid, job->spool->tag, pw->pw_name);
#endif
else
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("%lu (%s, %s) terminated with unrecognized status"),
(unsigned long)job->pid, job->spool->tag, pw->pw_name);
}
@@ -384,9 +377,7 @@ job_queue_runner(time_t min_interval)
}
if (min_interval) {
- if (wy_debug_level > 1)
- logmsg(LOG_DEBUG, _("computed interval: %lu"),
- min_interval);
+ wy_debug(2, (_("computed interval: %lu"), min_interval));
set_timer(min_interval);
}
}
diff --git a/src/lock.c b/src/lock.c
index ff96f40..1613cab 100644
--- a/src/lock.c
+++ b/src/lock.c
@@ -79,7 +79,7 @@ _lock_internal(const char *file, const char *fname)
if (errno == EEXIST)
return LOCK_RETRY;
else {
- logmsg(LOG_ERR, _("cannot create lock file %s: %s"),
+ wy_log(LOG_ERR, _("cannot create lock file %s: %s"),
fname, strerror(errno));
return LOCK_FAILURE;
}
@@ -92,7 +92,7 @@ _lock_internal(const char *file, const char *fname)
if (errno == EEXIST)
return LOCK_RETRY;
else {
- logmsg(LOG_ERR, _("cannot create lock file %s: %s"),
+ wy_log(LOG_ERR, _("cannot create lock file %s: %s"),
file, strerror(errno));
return LOCK_FAILURE;
}
@@ -100,7 +100,7 @@ _lock_internal(const char *file, const char *fname)
if ((fd = open(file, O_RDWR)) == -1) {
unlink(fname);
- logmsg(LOG_ERR, _("cannot open lock file %s: %s"),
+ wy_log(LOG_ERR, _("cannot open lock file %s: %s"),
fname, strerror(errno));
return LOCK_FAILURE;
}
@@ -108,7 +108,7 @@ _lock_internal(const char *file, const char *fname)
err = stat_check(fname, fd, 2);
if (err) {
unlink(fname);
- logmsg(LOG_ERR, _("lock file check failed: %s"),
+ wy_log(LOG_ERR, _("lock file check failed: %s"),
strerror(errno));
return (err == EINVAL) ? LOCK_INVALID : LOCK_FAILURE;
}
@@ -190,7 +190,7 @@ host_name()
#endif
));
if (rc) {
- logmsg(LOG_ERR, _("cannot get hostname: %s"), strerror(rc));
+ wy_log(LOG_ERR, _("cannot get hostname: %s"), strerror(rc));
exit(EX_SOFTWARE);
}
return hostbuf;
diff --git a/src/module.c b/src/module.c
index f9aba39..aa41264 100644
--- a/src/module.c
+++ b/src/module.c
@@ -145,14 +145,14 @@ spoolmodcfg(struct spool *spool, void *unused)
if (np->modname) {
struct module *mod = modlookup(np->modname);
if (!mod) {
- logmsg(LOG_ERR, "spool %s: no such module: %s",
+ wy_log(LOG_ERR, "spool %s: no such module: %s",
spool->tag, np->modname);
return 1;
}
if (mod->config) {
np->modcfg = mod->config(np->modnode);
if (!np->modcfg) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
"spool %s: failed to configure "
"module \"%s\"",
spool->tag, np->modname);
@@ -172,7 +172,7 @@ modules_load()
struct module *mod;
if (lt_dlinit()) {
- logmsg(LOG_ERR, _("failed to initialize libtool"));
+ wy_log(LOG_ERR, _("failed to initialize libtool"));
return;
}
@@ -187,12 +187,12 @@ modules_load()
if (lt_dladvise_init(&advise))
- logmsg(LOG_ERR, "lt_dladvise_init: %s", lt_dlerror());
+ wy_log(LOG_ERR, "lt_dladvise_init: %s", lt_dlerror());
else {
if (lt_dladvise_ext(&advise))
- logmsg(LOG_ERR, "lt_dladvise_ext: %s", lt_dlerror());
+ wy_log(LOG_ERR, "lt_dladvise_ext: %s", lt_dlerror());
if (lt_dladvise_global(&advise))
- logmsg(LOG_ERR, "lt_dladvise_global: %s",
+ wy_log(LOG_ERR, "lt_dladvise_global: %s",
lt_dlerror());
}
@@ -203,7 +203,7 @@ modules_load()
lt_dladvise_destroy(&advise);
if (for_each_spool(spoolmodcfg, NULL)) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
_("some modules failed to configure, exiting"));
exit(EX_UNAVAILABLE);
}
@@ -238,7 +238,7 @@ module_notify(const char *name, void *modcfg,
struct module *mod = modlookup(name);
if (!mod) {
- logmsg(LOG_ERR, "no such module: %s", name);
+ wy_log(LOG_ERR, "no such module: %s", name);
return;
}
if (mod->notify)
@@ -251,7 +251,7 @@ module_flush(const char *name, void *modcfg)
struct module *mod = modlookup(name);
if (!mod) {
- logmsg(LOG_ERR, "no such module: %s", name);
+ wy_log(LOG_ERR, "no such module: %s", name);
return;
}
if (mod->flush)
diff --git a/src/net.c b/src/net.c
index b985247..ccbe370 100644
--- a/src/net.c
+++ b/src/net.c
@@ -26,7 +26,7 @@ open_listener()
fd = socket(listen_sockaddr.sa->sa_family, SOCK_STREAM, 0);
if (fd == -1) {
- logmsg(LOG_CRIT, _("cannot create socket: %s"),
+ wy_log(LOG_CRIT, _("cannot create socket: %s"),
strerror(errno));
exit(EX_OSERR);
}
@@ -36,7 +36,7 @@ open_listener()
(struct sockaddr_un *)listen_sockaddr.sa;
if (stat(s_un->sun_path, &st)) {
if (errno != ENOENT) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
_("%s: cannot stat socket: %s"),
s_un->sun_path, strerror(errno));
exit(errno == EACCES ? EX_NOPERM : EX_OSERR);
@@ -44,7 +44,7 @@ open_listener()
} else {
/* FIXME: Check permissions? */
if (!S_ISSOCK(st.st_mode)) {
- logmsg(LOG_CRIT, _("%s: not a socket"),
+ wy_log(LOG_CRIT, _("%s: not a socket"),
s_un->sun_path);
exit(EX_OSFILE);
}
@@ -58,13 +58,13 @@ open_listener()
}
if (bind(fd, listen_sockaddr.sa, listen_sockaddr.len) < 0) {
- logmsg(LOG_CRIT, _("cannot bind to local address: %s"),
+ wy_log(LOG_CRIT, _("cannot bind to local address: %s"),
strerror(errno));
close(fd);
exit(EX_OSERR);
}
if (listen(fd, 8) == -1) {
- logmsg(LOG_CRIT, "listen: %s", strerror(errno));
+ wy_log(LOG_CRIT, "listen: %s", strerror(errno));
close(fd);
exit(EX_OSERR);
}
@@ -95,8 +95,7 @@ handle_connection(FILE * in, FILE * out)
if (grecs_getline(&buf, &buflen, in) <= 0)
return;
trim_crlf(buf);
- if (wy_debug_level)
- logmsg(LOG_DEBUG, "recv: %s", buf);
+ wy_debug(1, ("recv: %s", buf));
spool = wydawca_find_spool(buf);
if (!spool) {
if (all_spool_aliases
@@ -113,14 +112,13 @@ handle_connection(FILE * in, FILE * out)
fprintf(out, "+ OK, spool %s\r\n", spool->tag);
if (grecs_getline(&buf, &buflen, in) < 0) {
- logmsg(LOG_ERR, "protocol error");
+ wy_log(LOG_ERR, "protocol error");
free(buf);
return;
}
trim_crlf(buf);
- if (wy_debug_level)
- logmsg(LOG_DEBUG, "recv: %s", buf);
+ wy_debug(1, ("recv: %s", buf));
p = strchr(buf, ' ');
if (p) {
@@ -134,7 +132,7 @@ handle_connection(FILE * in, FILE * out)
if (pw)
schedule_job(spool, pw->pw_uid, NULL);
else
- logmsg(LOG_ERR, "no such user: %s", buf);
+ wy_log(LOG_ERR, "no such user: %s", buf);
free(buf);
}
@@ -168,7 +166,7 @@ wydawca_listener()
maxfd = wfd;
if (maxfd == 0) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
_("listener address is not configured and inotify "
"is not available"));
exit(EX_CONFIG);
@@ -205,7 +203,7 @@ wydawca_listener()
else if (rc < 0) {
if (errno == EINTR)
continue;
- logmsg(LOG_ERR, "select: %s", strerror(errno));
+ wy_log(LOG_ERR, "select: %s", strerror(errno));
break;
}
diff --git a/src/null.c b/src/null.c
index 20385a5..4a55b00 100644
--- a/src/null.c
+++ b/src/null.c
@@ -21,12 +21,11 @@ null_move_file(struct file_triplet *trp, enum file_type file_id)
{
const struct spool *spool = trp->spool;
const char *file_name = trp->file[file_id].name;
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("spool %s: installing file `%s/%s'"),
- spool->tag, trp->relative_dir, file_name);
+ wy_debug(1, (_("spool %s: installing file `%s/%s'"),
+ spool->tag, trp->relative_dir, file_name));
UPDATE_STATS(STAT_UPLOADS);
if (!dry_run_mode && unlink(file_name)) {
- logmsg(LOG_ERR, _("cannot unlink %s: %s"),
+ wy_log(LOG_ERR, _("cannot unlink %s: %s"),
file_name, strerror(errno));
return 1;
}
@@ -36,9 +35,8 @@ null_move_file(struct file_triplet *trp, enum file_type file_id)
int
null_archive_file(struct file_triplet *trp, const char *file_name)
{
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("spool %s: archiving `%s'"),
- trp->spool->tag, file_name);
+ wy_debug(1, (_("spool %s: archiving `%s'"),
+ trp->spool->tag, file_name));
UPDATE_STATS(STAT_ARCHIVES);
return 0;
}
@@ -47,9 +45,8 @@ int
null_symlink_file(struct file_triplet *trp,
const char *wanted_src, const char *wanted_dst)
{
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("spool %s: symlinking `%s' to `%s'"),
- trp->spool->tag, wanted_src, wanted_dst);
+ wy_debug(1, (_("spool %s: symlinking `%s' to `%s'"),
+ trp->spool->tag, wanted_src, wanted_dst));
UPDATE_STATS(STAT_SYMLINKS);
return 0;
}
@@ -57,9 +54,8 @@ null_symlink_file(struct file_triplet *trp,
int
null_rmsymlink_file(struct file_triplet *trp, const char *file_name)
{
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("spool %s: removing symlink `%s/%s'"),
- trp->spool->tag, trp->relative_dir, file_name);
+ wy_debug(1, (_("spool %s: removing symlink `%s/%s'"),
+ trp->spool->tag, trp->relative_dir, file_name));
UPDATE_STATS(STAT_RMSYMLINKS);
return 0;
}
diff --git a/src/pidfile.c b/src/pidfile.c
index eda5ba9..afac10f 100644
--- a/src/pidfile.c
+++ b/src/pidfile.c
@@ -33,13 +33,13 @@ check_pidfile()
if (fp) {
unsigned long pid = -1;
if (fscanf(fp, "%lu\n", &pid) != 1) {
- logmsg(LOG_ERR, _("malformed pidfile %s"), pidfile);
+ wy_log(LOG_ERR, _("malformed pidfile %s"), pidfile);
if (!force_startup)
exit(EX_UNAVAILABLE);
} else {
if (kill(pid, 0)) {
if (errno != ESRCH) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("cannot verify if PID %lu "
"is running: %s"),
pid, strerror(errno));
@@ -47,24 +47,24 @@ check_pidfile()
exit(EX_UNAVAILABLE);
}
} else if (!force_startup) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("another wydawca instance may "
"be running (PID %lu)"),
pid);
exit(EX_UNAVAILABLE);
}
}
- logmsg(LOG_NOTICE, _("replacing pidfile %s (PID %lu)"),
+ wy_log(LOG_NOTICE, _("replacing pidfile %s (PID %lu)"),
pidfile, pid);
fseek(fp, 0, SEEK_SET);
} else if (errno != ENOENT) {
- logmsg(LOG_ERR, _("cannot open pidfile %s: %s"), pidfile,
+ wy_log(LOG_ERR, _("cannot open pidfile %s: %s"), pidfile,
strerror(errno));
exit(EX_UNAVAILABLE);
} else {
fp = fopen(pidfile, "w");
if (!fp) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("cannot open pidfile %s for writing: %s"),
pidfile, strerror(errno));
exit(EX_UNAVAILABLE);
diff --git a/src/process.c b/src/process.c
index b907558..181a81b 100644
--- a/src/process.c
+++ b/src/process.c
@@ -155,30 +155,28 @@ spool_cwd_add_new_file(const struct spool *spool, const char *name,
struct file_info finfo;
if (stat(name, &st)) {
- logmsg(LOG_ERR, _("cannot stat file %s/%s: %s"),
+ wy_log(LOG_ERR, _("cannot stat file %s/%s: %s"),
spool->source_dir, name, strerror(errno));
return -1;
}
if (!S_ISREG(st.st_mode)) {
- logmsg(LOG_NOTICE, _("not a regular file: %s/%s"),
+ wy_log(LOG_NOTICE, _("not a regular file: %s/%s"),
spool->source_dir, name);
return -1;
}
if (!match_uid_p(st.st_uid, uc, uv)) {
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("ignoring file: %s/%s"),
- spool->source_dir, name);
+ wy_debug(1, (_("ignoring file: %s/%s"),
+ spool->source_dir, name));
return -1;
}
finfo.sb = st;
parse_file_name(name, &finfo);
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("found file %s: %s, stem: %.*s"), name,
- file_type_str(finfo.type), finfo.root_len, finfo.name);
+ wy_debug(1, (_("found file %s: %s, stem: %.*s"), name,
+ file_type_str(finfo.type), finfo.root_len, finfo.name));
register_file(&finfo, spool);
return 0;
@@ -188,12 +186,11 @@ int
spool_add_new_file(const struct spool *spool, const char *name,
int uc, uid_t * uv)
{
- if (wy_debug_level)
- logmsg(LOG_DEBUG, "%s -> %s, adding %s", spool->source_dir,
- wy_url_printable(spool->dest_url), name);
+ wy_debug(1, ("%s -> %s, adding %s", spool->source_dir,
+ wy_url_printable(spool->dest_url), name));
if (chdir(spool->source_dir)) {
- logmsg(LOG_ERR, _("cannot chdir to %s: %s"), spool->source_dir,
+ wy_log(LOG_ERR, _("cannot chdir to %s: %s"), spool->source_dir,
strerror(errno));
return -1;
}
@@ -208,19 +205,18 @@ scan_spool_unlocked(struct spool *spool, int uc, uid_t *uv)
DIR *dir;
struct dirent *ent;
- if (wy_debug_level)
- logmsg(LOG_DEBUG, "%s -> %s", spool->source_dir,
- wy_url_printable(spool->dest_url));
+ wy_debug(1, ("%s -> %s", spool->source_dir,
+ wy_url_printable(spool->dest_url)));
if (chdir(spool->source_dir)) {
- logmsg(LOG_ERR, _("cannot chdir to %s: %s"), spool->source_dir,
+ wy_log(LOG_ERR, _("cannot chdir to %s: %s"), spool->source_dir,
strerror(errno));
return;
}
dir = opendir(".");
if (!dir) {
- logmsg(LOG_ERR, _("cannot open directory %s: %s"),
+ wy_log(LOG_ERR, _("cannot open directory %s: %s"),
spool->source_dir, strerror(errno));
return;
}
@@ -256,11 +252,11 @@ scan_spool(struct spool *spool, int uc, uid_t * uv)
break;
case LOCK_FAILURE:
- logmsg(LOG_ERR, _("cannot lock spool %s"), spool->tag);
+ wy_log(LOG_ERR, _("cannot lock spool %s"), spool->tag);
break;
case LOCK_RETRY:
- logmsg(LOG_WARNING, _("timed out while looking spool %s"),
+ wy_log(LOG_WARNING, _("timed out while looking spool %s"),
spool->tag);
break;
}
@@ -276,7 +272,7 @@ spool_open_dictionaries(struct spool *spool)
for (i = 0; i < dictionary_count; i++) {
if (dictionary_init(spool->dictionary[i])) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("failed to initialize dictionary %d"),
i);
return -1;
diff --git a/src/sql.c b/src/sql.c
index 3f4da2e..4176e88 100644
--- a/src/sql.c
+++ b/src/sql.c
@@ -60,7 +60,7 @@ sql_init_dictionary(struct dictionary *dict)
struct sqlconn *conn = sql_find_connection(dict->parmv[0]);
if (!conn) {
- logmsg(LOG_EMERG,
+ wy_log(LOG_EMERG,
_("INTERNAL ERROR: cannot find SQL connection %s"),
dict->parmv[0]);
abort();
@@ -83,7 +83,7 @@ sql_init_dictionary(struct dictionary *dict)
conn->password, conn->database,
conn->port, conn->socket,
CLIENT_MULTI_RESULTS)) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("failed to connect to database %s: "
"error: %s\n"),
dict->parmv[0], mysql_error(&conn->mysql));
@@ -134,30 +134,30 @@ sql_lookup_dictionary(struct dictionary *dict, void *handle, const char *query)
MYSQL *mysql = &conn->mysql;
if (!query) {
- logmsg(LOG_ERR, _("no query supplied for dictionary %s"),
+ wy_log(LOG_ERR, _("no query supplied for dictionary %s"),
"sql");
return 1;
}
if (mysql_query(mysql, query)) {
- logmsg(LOG_ERR, _("query failed: %s"), mysql_error(mysql));
- logmsg(LOG_NOTICE, _("the failed query was: %s"), query);
+ wy_log(LOG_ERR, _("query failed: %s"), mysql_error(mysql));
+ wy_log(LOG_NOTICE, _("the failed query was: %s"), query);
return 1;
}
conn->result = mysql_store_result(mysql);
if (!conn->result) {
- logmsg(LOG_ERR, _("cannot get result: %s"), mysql_error(mysql));
- logmsg(LOG_NOTICE, _("the failed query was: %s"), query);
+ wy_log(LOG_ERR, _("cannot get result: %s"), mysql_error(mysql));
+ wy_log(LOG_NOTICE, _("the failed query was: %s"), query);
return 1;
}
dict->nrow = mysql_num_rows(conn->result);
dict->ncol = mysql_num_fields(conn->result);
if (wy_debug_level > 1) {
- logmsg(LOG_DEBUG, _("query returned %u columns in %u rows"),
+ wy_log(LOG_DEBUG, _("query returned %u columns in %u rows"),
dict->ncol, dict->nrow);
- logmsg(LOG_DEBUG, _("the query was: %s"), query);
+ wy_log(LOG_DEBUG, _("the query was: %s"), query);
}
return 0;
diff --git a/src/triplet.c b/src/triplet.c
index f2c2184..ded09c8 100644
--- a/src/triplet.c
+++ b/src/triplet.c
@@ -241,9 +241,7 @@ triplet_expired_p(struct file_triplet *trp)
for (i = 0; i < FILE_TYPE_COUNT; i++) {
if (trp->file[i].name
&& (now - trp->file[i].sb.st_mtime) >= ttl) {
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("file %s expired"),
- trp->file[i].name);
+ wy_debug(1, (_("file %s expired"), trp->file[i].name));
return 1;
}
}
@@ -280,11 +278,9 @@ check_triplet_state(struct file_triplet *trp, int noauth)
trp->file[file_directive].sb.st_uid)
return triplet_complete;
else {
- if (wy_debug_level)
- logmsg(LOG_DEBUG,
- _("%s: invalid triplet: "
- "UIDs differ"),
- trp->name);
+ wy_debug(1, (_("%s: invalid triplet: "
+ "UIDs differ"),
+ trp->name));
return triplet_bad;
}
}
@@ -303,16 +299,16 @@ remove_triplet(struct file_triplet *trp, int check)
if (trp->file[i].name) {
if (check) {
if (access(trp->file[i].name, F_OK) == 0) {
- logmsg(LOG_NOTICE,
+ wy_log(LOG_NOTICE,
_("%s still exists"),
trp->file[i].name);
return 1;
}
} else {
- logmsg(LOG_NOTICE, _("removing %s"),
+ wy_log(LOG_NOTICE, _("removing %s"),
trp->file[i].name);
if (!dry_run_mode && unlink(trp->file[i].name))
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("cannot remove %s: %s"),
trp->file[i].name,
strerror(errno));
@@ -340,27 +336,22 @@ triplet_processor(void *data, void *proc_data)
{
struct file_triplet *trp = data;
- if (wy_debug_level)
- logmsg(LOG_DEBUG, "FILE %s, DIST=%s, SIG=%s, DIRECTIVE=%s",
- trp->name,
- SP(trp->file[file_dist].name),
- SP(trp->file[file_signature].name),
- SP(trp->file[file_directive].name));
+ wy_debug(1, ("FILE %s, DIST=%s, SIG=%s, DIRECTIVE=%s",
+ trp->name,
+ SP(trp->file[file_dist].name),
+ SP(trp->file[file_signature].name),
+ SP(trp->file[file_directive].name)));
switch (check_triplet_state(trp, 0)) {
case triplet_directive:
case triplet_complete:
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("processing triplet `%s'"),
- trp->name);
+ wy_debug(1, (_("processing triplet `%s'"), trp->name));
if (process_directives(trp))
remove_triplet(trp, 0);
return 0;
case triplet_incomplete:
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("%s: incomplete triplet"),
- trp->name);
+ wy_debug(1, (_("%s: incomplete triplet"), trp->name));
/* ignore unless expired (see below); */
UPDATE_STATS(STAT_INCOMPLETE_TRIPLETS);
break;
@@ -383,9 +374,8 @@ triplet_processor(void *data, void *proc_data)
void
spool_commit_triplets(struct spool *spool, struct file_triplet *tplist)
{
- if (wy_debug_level)
- logmsg(LOG_DEBUG, _("processing spool %s (%s)"),
- spool->tag, wy_url_printable(spool->dest_url));
+ wy_debug(1, (_("processing spool %s (%s)"),
+ spool->tag, wy_url_printable(spool->dest_url)));
if (spool_open_dictionaries(spool))
return;
if (tplist) {
@@ -419,12 +409,11 @@ triplet_linker(void *data, void *proc_data)
if (trp->job)
return 0;
- if (wy_debug_level)
- logmsg(LOG_DEBUG, "FILE %s, DIST=%s, SIG=%s, DIRECTIVE=%s",
- trp->name,
- SP(trp->file[file_dist].name),
- SP(trp->file[file_signature].name),
- SP(trp->file[file_directive].name));
+ wy_debug(1, ("FILE %s, DIST=%s, SIG=%s, DIRECTIVE=%s",
+ trp->name,
+ SP(trp->file[file_dist].name),
+ SP(trp->file[file_signature].name),
+ SP(trp->file[file_directive].name)));
switch (check_triplet_state(trp, 1)) {
case triplet_directive:
@@ -478,9 +467,8 @@ triplet_remove_file(struct spool *spool, const char *name)
}
if (!n) {
- if (wy_debug_level > 0)
- logmsg(LOG_DEBUG, "deleting empty triplet (%s/%s)",
- spool->source_dir, name);
+ wy_debug(1, ("deleting empty triplet (%s/%s)",
+ spool->source_dir, name));
remove_triplet(tp, 0);
}
}
diff --git a/src/userprivs.c b/src/userprivs.c
index 11285f1..13a2d87 100644
--- a/src/userprivs.c
+++ b/src/userprivs.c
@@ -26,7 +26,7 @@ wydawca_userprivs(uid_t uid, gid_t gid, gid_t * grplist, size_t ngrp)
/* Reset group permissions */
if (geteuid() == 0 && setgroups(ngrp, grplist)) {
- logmsg(LOG_CRIT, "setgroups(%lu, %lu...): %s",
+ wy_log(LOG_CRIT, "setgroups(%lu, %lu...): %s",
(unsigned long)ngrp, (unsigned long)grplist[0],
strerror(errno));
return rc;
@@ -37,26 +37,26 @@ wydawca_userprivs(uid_t uid, gid_t gid, gid_t * grplist, size_t ngrp)
#if defined(HAVE_SETEGID)
if ((rc = setegid(gid)) < 0)
- logmsg(LOG_CRIT, "setegid(%lu): %s",
+ wy_log(LOG_CRIT, "setegid(%lu): %s",
(unsigned long)gid, strerror(errno));
#elif defined(HAVE_SETREGID)
if ((rc = setregid(gid, gid)) < 0)
- logmsg(LOG_CRIT, "setregid(%lu,%lu)d: %s",
+ wy_log(LOG_CRIT, "setregid(%lu,%lu)d: %s",
(unsigned long)gid, (unsigned long)gid,
strerror(errno));
#elif defined(HAVE_SETRESGID)
if ((rc = setresgid(gid, gid, gid)) < 0)
- logmsg(LOG_CRIT, "setresgid(%lu,%lu,%lu): %s",
+ wy_log(LOG_CRIT, "setresgid(%lu,%lu,%lu): %s",
(unsigned long)gid, (unsigned long)gid,
(unsigned long)gid, strerror(errno));
#endif
if (rc == 0 && gid != 0) {
if ((rc = setgid(gid)) < 0 && getegid() != gid)
- logmsg(LOG_CRIT, "setgid(%lu): %s",
+ wy_log(LOG_CRIT, "setgid(%lu): %s",
(unsigned long)gid, strerror(errno));
if (rc == 0 && getegid() != gid) {
- logmsg(LOG_CRIT, _("cannot set effective gid to %lu"),
+ wy_log(LOG_CRIT, _("cannot set effective gid to %lu"),
(unsigned long)gid);
rc = 1;
}
@@ -73,14 +73,14 @@ wydawca_userprivs(uid_t uid, gid_t gid, gid_t * grplist, size_t ngrp)
#if defined(HAVE_SETREUID)
if (geteuid() != uid) {
if (setreuid(uid, -1) < 0) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
"setreuid(%lu,-1): %s",
(unsigned long)uid,
strerror(errno));
rc = 1;
}
if (setuid(uid) < 0) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
"setreuid(%lu,-1): %s",
(unsigned long)uid,
strerror(errno));
@@ -89,7 +89,7 @@ wydawca_userprivs(uid_t uid, gid_t gid, gid_t * grplist, size_t ngrp)
} else
#endif
{
- logmsg(LOG_CRIT, "setuid(%lu): %s",
+ wy_log(LOG_CRIT, "setuid(%lu): %s",
(unsigned long)uid, strerror(errno));
rc = 1;
}
@@ -97,11 +97,11 @@ wydawca_userprivs(uid_t uid, gid_t gid, gid_t * grplist, size_t ngrp)
euid = geteuid();
if (uid != 0 && setuid(0) == 0) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
_("seteuid(0) succeeded when it should not"));
rc = 1;
} else if (uid != euid && setuid(euid) == 0) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
_("cannot drop non-root setuid privileges"));
rc = 1;
}
diff --git a/src/verify.c b/src/verify.c
index 20a5bb9..af450c8 100644
--- a/src/verify.c
+++ b/src/verify.c
@@ -98,14 +98,14 @@ fill_project_name(struct file_triplet *trp)
size = trp->file[file_directive].sb.st_size;
if (size <= MSG_BEGIN_MARKER_LEN) {
- logmsg(LOG_ERR, _("too small directive file %s"),
+ wy_log(LOG_ERR, _("too small directive file %s"),
trp->file[file_directive].name);
return 1;
}
fp = fopen(trp->file[file_directive].name, "r");
if (!fp) {
- logmsg(LOG_ERR, _("cannot open file %s: %s"),
+ wy_log(LOG_ERR, _("cannot open file %s: %s"),
trp->file[file_directive].name, strerror(errno));
return 1;
}
@@ -116,7 +116,7 @@ fill_project_name(struct file_triplet *trp)
fclose(fp);
if (rc != 1) {
- logmsg(LOG_ERR, _("error reading file %s: %s"),
+ wy_log(LOG_ERR, _("error reading file %s: %s"),
trp->file[file_directive].name, strerror(errno));
free(blurb);
return 1;
@@ -124,7 +124,7 @@ fill_project_name(struct file_triplet *trp)
blurb[size] = 0;
if (extract_plaintext(blurb)) {
- logmsg(LOG_ERR, _("%s: unrecognized format"),
+ wy_log(LOG_ERR, _("%s: unrecognized format"),
trp->file[file_directive].name);
free(blurb);
return 1;
@@ -139,14 +139,14 @@ fill_project_name(struct file_triplet *trp)
}
if (directive_get_value(trp, "directory", &directory)) {
- logmsg(LOG_ERR, _("%s: missing `directory' directive"),
+ wy_log(LOG_ERR, _("%s: missing `directory' directive"),
trp->file[file_directive].name);
return 1;
}
trp->relative_dir = safe_file_name(triplet_strdup(trp, directory));
if (!trp->relative_dir || trp->relative_dir[0] == '/') {
- logmsg(LOG_ERR, _("%s: invalid directory: %s"),
+ wy_log(LOG_ERR, _("%s: invalid directory: %s"),
trp->file[file_directive].name, directory);
return 1;
}
@@ -155,7 +155,7 @@ fill_project_name(struct file_triplet *trp)
if (p) {
size_t len = p - trp->relative_dir;
if (len == 0) {
- logmsg(LOG_ERR, _("%s: empty `directory' directive"),
+ wy_log(LOG_ERR, _("%s: empty `directory' directive"),
trp->file[file_directive].name);
return 1;
}
@@ -220,7 +220,7 @@ verify_directive_file(struct file_triplet *trp, int noath)
rc = dictionary_lookup(dict, md, command);
free(command);
if (rc) {
- logmsg(LOG_ERR, _("cannot get uploaders for %s"),
+ wy_log(LOG_ERR, _("cannot get uploaders for %s"),
trp->name);
dictionary_close(dict, md);
return 1;
@@ -228,7 +228,7 @@ verify_directive_file(struct file_triplet *trp, int noath)
nrows = dictionary_num_rows(dict);
if (nrows == 0) {
- logmsg(LOG_ERR, _("found no uploaders for %s"),
+ wy_log(LOG_ERR, _("found no uploaders for %s"),
trp->name);
dictionary_close(dict, md);
return 1;
@@ -236,7 +236,7 @@ verify_directive_file(struct file_triplet *trp, int noath)
ncols = dictionary_num_cols(dict);
if (ncols < 4) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_
("project-uploader dictionary error: too few columns (%lu)"),
(unsigned long)ncols);
@@ -264,19 +264,19 @@ verify_directive_file(struct file_triplet *trp, int noath)
info.gpg_key = triplet_strdup(trp, p);
if (wy_debug_level > 3) {
- logmsg(LOG_DEBUG, _("name: %s"),
+ wy_log(LOG_DEBUG, _("name: %s"),
SP(info.name));
- logmsg(LOG_DEBUG, _("realname: %s"),
+ wy_log(LOG_DEBUG, _("realname: %s"),
SP(info.realname));
- logmsg(LOG_DEBUG, _("gpg-key: %s"),
+ wy_log(LOG_DEBUG, _("gpg-key: %s"),
SP(info.gpg_key));
- logmsg(LOG_DEBUG, _("email: %s"),
+ wy_log(LOG_DEBUG, _("email: %s"),
SP(info.email));
}
if (!info.name || !info.realname || !info.gpg_key ||
!info.email) {
- logmsg(LOG_ERR,
+ wy_log(LOG_ERR,
_("project-uploader dictionary error: "
"malformed row %lu"),
(unsigned long)i);
@@ -297,7 +297,7 @@ verify_directive_file(struct file_triplet *trp, int noath)
dictionary_close(dict, md);
if (!head) {
- logmsg(LOG_ERR, _("no valid uploaders found for %s"),
+ wy_log(LOG_ERR, _("no valid uploaders found for %s"),
trp->name);
return 1;
}
@@ -307,18 +307,18 @@ verify_directive_file(struct file_triplet *trp, int noath)
if (verify_directive_signature(trp)) {
/*FIXME: Update stats */
- logmsg(LOG_ERR, _("invalid signature for %s"),
+ wy_log(LOG_ERR, _("invalid signature for %s"),
trp->name ? trp->name : "[unknown]");
return 1;
- } else if (wy_debug_level)
- logmsg(LOG_DEBUG, _("%s: directive file signature OK"),
- trp->name);
+ } else
+ wy_debug(1, (_("%s: directive file signature OK"),
+ trp->name));
}
if (wy_debug_level > 1) {
int i;
for (i = 0; trp->directive[i]; i++)
- logmsg(LOG_DEBUG, "directive[%d] = %s", i,
+ wy_log(LOG_DEBUG, "directive[%d] = %s", i,
trp->directive[i]);
}
diff --git a/src/watcher.c b/src/watcher.c
index 1ba7c71..0af885b 100644
--- a/src/watcher.c
+++ b/src/watcher.c
@@ -84,19 +84,15 @@ create_watcher(struct spool *sp, void *data)
return 0;
if (!sp->inotify_enable) {
- if (wy_debug_level > 1)
- logmsg(LOG_DEBUG,
- "disabling inotify support for spool %s",
- sp->tag);
+ wy_debug(2, ("disabling inotify support for spool %s",
+ sp->tag));
return 0;
}
- if (wy_debug_level > 1)
- logmsg(LOG_DEBUG, "spool %s: creating watcher %s", sp->tag,
- path);
+ wy_debug(2, ("spool %s: creating watcher %s", sp->tag, path));
dwp = malloc(sizeof(*dwp));
if (!dwp) {
- logmsg(LOG_ERR, "not enough memory");
+ wy_log(LOG_ERR, "not enough memory");
return 1;
}
dwp->spool = sp;
@@ -106,7 +102,7 @@ create_watcher(struct spool *sp, void *data)
IN_DELETE | IN_CREATE | IN_CLOSE_WRITE |
IN_MOVED_FROM | IN_MOVED_TO);
if (wd == -1) {
- logmsg(LOG_ERR, "cannot set watch on %s: %s", path,
+ wy_log(LOG_ERR, "cannot set watch on %s: %s", path,
strerror(errno));
free(dwp);
return 1;
@@ -123,16 +119,14 @@ watcher_init()
int ifd, rc;
if (!inotify_enable) {
- if (wy_debug_level > 1)
- logmsg(LOG_DEBUG, "disabling inotify support");
+ wy_debug(2, ("disabling inotify support"));
return -1;
}
- if (wy_debug_level > 1)
- logmsg(LOG_DEBUG, "setting up inotify");
+ wy_debug(2, ("setting up inotify"));
ifd = inotify_init();
if (ifd == -1) {
- logmsg(LOG_ERR, "inotify_init: %s", strerror(errno));
+ wy_log(LOG_ERR, "inotify_init: %s", strerror(errno));
return -1;
}
@@ -140,12 +134,11 @@ watcher_init()
if (rc)
exit(EX_OSERR);
if (!dirwatcher_list) {
- if (wy_debug_level > 1)
- logmsg(LOG_DEBUG, "inotify: nothing to watch");
+ wy_debug(2, ("inotify: nothing to watch"));
close(ifd);
ifd = -1;
- } else if (wy_debug_level > 1)
- logmsg(LOG_DEBUG, "inotify initialized successfully");
+ } else
+ wy_debug(2, ("inotify initialized successfully"));
return ifd;
}
@@ -160,7 +153,7 @@ process_event(struct inotify_event *ep)
if (ep->mask & IN_IGNORED)
/* nothing */ ;
else if (ep->mask & IN_Q_OVERFLOW)
- logmsg(LOG_NOTICE, "event queue overflow");
+ wy_log(LOG_NOTICE, "event queue overflow");
else if (ep->mask & IN_UNMOUNT)
/* FIXME: not sure if there's
anything to do. Perhaps we should
@@ -169,29 +162,26 @@ process_event(struct inotify_event *ep)
*/ ;
else if (!dwp) {
if (ep->name)
- logmsg(LOG_NOTICE, "unrecognized event %x for %s",
+ wy_log(LOG_NOTICE, "unrecognized event %x for %s",
ep->mask, ep->name);
else
- logmsg(LOG_NOTICE, "unrecognized event %x", ep->mask);
+ wy_log(LOG_NOTICE, "unrecognized event %x", ep->mask);
} else if (ep->mask & IN_CREATE) {
- if (wy_debug_level > 0)
- logmsg(LOG_DEBUG, "%s/%s created",
- dwp->spool->source_dir, ep->name);
+ wy_debug(1, ("%s/%s created",
+ dwp->spool->source_dir, ep->name));
} else if (ep->mask & (IN_DELETE | IN_MOVED_FROM)) {
- if (wy_debug_level > 0)
- logmsg(LOG_DEBUG, "%s/%s %s", dwp->spool->source_dir,
- ep->name,
- ep->mask & IN_DELETE ? "deleted" : "moved out");
+ wy_debug(1, ("%s/%s %s", dwp->spool->source_dir,
+ ep->name,
+ ep->mask & IN_DELETE ? "deleted" : "moved out"));
triplet_remove_file(dwp->spool, ep->name);
} else if (ep->mask & (IN_CLOSE_WRITE | IN_MOVED_TO)) {
- if (wy_debug_level > 0)
- logmsg(LOG_DEBUG, "%s/%s written",
- dwp->spool->source_dir, ep->name);
+ wy_debug(1, ("%s/%s written",
+ dwp->spool->source_dir, ep->name));
if (spool_add_new_file(dwp->spool, ep->name, 0, NULL) == 0
&& (tp = link_processable_triplets()))
schedule_job(&inotify_spool, getuid(), tp);
} else
- logmsg(LOG_NOTICE, "%s/%s: unexpected event %x",
+ wy_log(LOG_NOTICE, "%s/%s: unexpected event %x",
dwp->spool->source_dir, ep->name, ep->mask);
}
@@ -206,7 +196,7 @@ watcher_run(int ifd)
int rdbytes;
if (ioctl(ifd, FIONREAD, &n)) {
- logmsg(LOG_ERR, "ioctl: %s", strerror(errno));
+ wy_log(LOG_ERR, "ioctl: %s", strerror(errno));
return -1;
}
if (offset + n > sizeof buffer)
@@ -216,12 +206,12 @@ watcher_run(int ifd)
if (rdbytes == -1) {
if (errno == EINTR) {
/*FIXME
- logmsg (LOG_NOTICE, "got signal %d", signo);
+ wy_log (LOG_NOTICE, "got signal %d", signo);
*/
return 0;
}
- logmsg(LOG_NOTICE, "read failed: %s", strerror(errno));
+ wy_log(LOG_NOTICE, "read failed: %s", strerror(errno));
return -1;
}
}
diff --git a/src/wydawca.c b/src/wydawca.c
index 6c342c9..66c6390 100644
--- a/src/wydawca.c
+++ b/src/wydawca.c
@@ -104,7 +104,7 @@ static void (*log_printer) (int prio, const char *fmt, va_list ap) =
stderr_printer;
void
-logmsg(int prio, char *fmt, ...)
+wy_log(int prio, char *fmt, ...)
{
va_list ap;
@@ -124,6 +124,17 @@ logmsg(int prio, char *fmt, ...)
log_printer(prio, fmt, ap);
va_end(ap);
}
+
+void
+wy_dbg(char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ log_printer(LOG_DEBUG, fmt, ap);
+ va_end(ap);
+}
+
static char *stat_name[MAX_STAT] = {
N_("errors"),
@@ -208,7 +219,7 @@ logstats()
if (stat_mask_p(print_stats)) {
for (i = 0; i < MAX_STAT; i++)
if (print_stats & STAT_MASK(i))
- logmsg(LOG_INFO, "%s: %u",
+ wy_log(LOG_INFO, "%s: %u",
gettext(stat_name[i]), wydawca_stat[i]);
}
@@ -246,18 +257,18 @@ grecs_print_diag(grecs_locus_t *locus, int err, int errcode, const char *msg)
if (locstr) {
if (errcode)
- logmsg(err ? LOG_ERR : LOG_WARNING, "%s: %s: %s",
+ wy_log(err ? LOG_ERR : LOG_WARNING, "%s: %s: %s",
locstr, msg, strerror(errcode));
else
- logmsg(err ? LOG_ERR : LOG_WARNING, "%s: %s",
+ wy_log(err ? LOG_ERR : LOG_WARNING, "%s: %s",
locstr, msg);
free(locstr);
} else {
if (errcode)
- logmsg(err ? LOG_ERR : LOG_WARNING, "%s: %s", msg,
+ wy_log(err ? LOG_ERR : LOG_WARNING, "%s: %s", msg,
strerror(errcode));
else
- logmsg(err ? LOG_ERR : LOG_WARNING, "%s", msg);
+ wy_log(err ? LOG_ERR : LOG_WARNING, "%s", msg);
}
}
@@ -277,7 +288,7 @@ collect_uids(int argc, char **argv)
char *p;
unsigned n = strtoul(argv[i], &p, 10);
if (*p) {
- logmsg(LOG_ERR, _("no such user: %s"),
+ wy_log(LOG_ERR, _("no such user: %s"),
argv[i]);
exit(EX_NOUSER);
}
@@ -295,10 +306,10 @@ wydawca_daemon()
{
if (!foreground) {
if (daemon(0, 0)) {
- logmsg(LOG_ERR, "%s", strerror(errno));
+ wy_log(LOG_ERR, "%s", strerror(errno));
exit(EX_OSERR);
}
- logmsg(LOG_NOTICE, _("daemon launched"));
+ wy_log(LOG_NOTICE, _("daemon launched"));
}
check_pidfile();
@@ -339,10 +350,10 @@ main(int argc, char **argv)
p = gpgme_check_version("1.1.0");
if (!p) {
- logmsg(LOG_CRIT, _("GPGMe version check failed"));
+ wy_log(LOG_CRIT, _("GPGMe version check failed"));
exit(EX_UNAVAILABLE);
- } else if (wy_debug_level > 3)
- logmsg(LOG_DEBUG, _("using GPGME version %s"), p);
+ } else
+ wy_debug(4, (_("using GPGME version %s"), p));
if (argc)
collect_uids(argc, argv);
@@ -383,7 +394,7 @@ main(int argc, char **argv)
if (getgid() == 0) {
if (wydawca_uid == 0) {
if (!force_startup) {
- logmsg(LOG_CRIT,
+ wy_log(LOG_CRIT,
_("won't run with root privileges"));
exit(EX_UNAVAILABLE);
}
@@ -395,7 +406,7 @@ main(int argc, char **argv)
wydawca_lock_init();
- logmsg(LOG_NOTICE, _("wydawca (%s) started"), PACKAGE_STRING);
+ wy_log(LOG_NOTICE, _("wydawca (%s) started"), PACKAGE_STRING);
if (!daemon_mode) {
scan_all_spools(uidc, uidv);
@@ -405,7 +416,7 @@ main(int argc, char **argv)
modules_close();
- logmsg(LOG_NOTICE, _("wydawca (%s) finished"), PACKAGE_STRING);
+ wy_log(LOG_NOTICE, _("wydawca (%s) finished"), PACKAGE_STRING);
if (reconfigure) {
int i;
diff --git a/src/wydawca.h b/src/wydawca.h
index 73ff961..ea5705f 100644
--- a/src/wydawca.h
+++ b/src/wydawca.h
@@ -246,7 +246,7 @@ struct spool {
#define ASGN_SPOOL(spool, trp, faction) do { \
spool = (trp)->spool; \
if (!spool) { \
- logmsg (LOG_CRIT, \
+ wy_log (LOG_CRIT, \
_("INTERNAL ERROR at %s:%d: " \
"spool not defined for %s"), \
__FILE__, __LINE__, (trp)->name); \
@@ -413,7 +413,15 @@ char *safe_file_name(char *file_name);
char *safe_file_name_alloc(const char *file_name);
size_t trim_length(const char *str);
size_t trim(char *str);
-void logmsg(int prio, char *fmt, ...) GSC_PRINTFLIKE(2, 3);
+
+void wy_log(int prio, char *fmt, ...) GSC_PRINTFLIKE(2, 3);
+void wy_dbg(char *fmt, ...) GSC_PRINTFLIKE(1, 2);
+#define wy_debug(l,c) do { \
+ if (wy_debug_level >= (l)) \
+ wy_dbg c; \
+ } while(0)
+
+
int test_dir(const char *name, int *ec);
char *create_directory(const char *base, const char *name);
int create_hierarchy(char *dir, size_t baselen);

Return to:

Send suggestions and report system problems to the System administrator.