Sherlock.h still defines log() alias to UCW's msg().
Lib/math.h has been moved to sherlock/math.h.
#undef LOCAL_DEBUG
#include "sherlock/sherlock.h"
-#include "lib/math.h"
+#include "sherlock/math.h"
#include "images/images.h"
#include "images/color.h"
#include "images/error.h"
void
image_context_msg_default(struct image_context *ctx)
{
- log(ctx->msg_code >> 24, "%s", ctx->msg);
+ msg(ctx->msg_code >> 24, "%s", ctx->msg);
}
void
#include "lib/lib.h"
#include "lib/mempool.h"
-#include "lib/math.h"
#include <stdlib.h>
#include <stdio.h>
+#include <math.h>
static struct mempool *pool;
static uns display_base64;
static uns display_base224;
-#define MSG(x...) do{ if (verbose) log(L_INFO, ##x); }while(0)
+#define MSG(x...) do{ if (verbose) msg(L_INFO, ##x); }while(0)
#define TRY(x) do{ if (!(x)) exit(1); }while(0)
static void
color_make_rgb(color, (v >> 16) & 255, (v >> 8) & 255, v & 255);
}
-#define MSG(x...) do{ if (verbose) log(L_INFO, ##x); }while(0)
+#define MSG(x...) do{ if (verbose) msg(L_INFO, ##x); }while(0)
int
main(int argc, char **argv)
#undef LOCAL_DEBUG
#include "lib/lib.h"
-#include "lib/math.h"
#include "images/math.h"
#include "images/images.h"
#include "images/signature.h"
#undef LOCAL_DEBUG
#include "sherlock/sherlock.h"
+#include "sherlock/math.h"
#include "lib/fastbuf.h"
#include "lib/conf.h"
-#include "lib/math.h"
#include "images/images.h"
#include "images/math.h"
#include "images/error.h"
getopt
LIBUCW_INCLUDES= \
- lib.h config.h threads.h math.h \
+ lib.h config.h threads.h \
mempool.h pagecache.h \
sorter.h sorter-globals.h arraysort.h \
lists.h clists.h slists.h simple-lists.h \
b->maxn = maxn;
b->max_m_mult = (0xffffffff / m) * m;
bzero(b->array, mbytes);
- log(L_DEBUG, "Initialized bitsig array with l=%d, m=%u (%u KB), expecting %d items", b->l, b->m, (mbytes+1023)/1024, maxn);
+ msg(L_DEBUG, "Initialized bitsig array with l=%d, m=%u (%u KB), expecting %d items", b->l, b->m, (mbytes+1023)/1024, maxn);
return b;
}
}
}
if (!was && b->n++ == b->maxn+1)
- log(L_ERROR, "bitsig: Too many items inserted, error rate will be higher than estimated!");
+ msg(L_ERROR, "bitsig: Too many items inserted, error rate will be higher than estimated!");
return was;
}
}
static byte *
-get_token(uns is_command_name, byte **msg)
+get_token(uns is_command_name, byte **err)
{
- *msg = NULL;
+ *err = NULL;
while (1) {
if (!*line || *line == '#') {
- if (!is_command_name || !get_line(msg))
+ if (!is_command_name || !get_line(err))
return NULL;
} else if (*line == ';') {
- *msg = get_word(0);
- if (!is_command_name || *msg)
+ *err = get_word(0);
+ if (!is_command_name || *err)
return NULL;
} else if (*line == '\\' && !line[1]) {
- if (!get_line(msg)) {
- if (!*msg)
- *msg = "Last line ends by a backslash";
+ if (!get_line(err)) {
+ if (!*err)
+ *err = "Last line ends by a backslash";
return NULL;
}
if (!*line || *line == '#')
- log(L_WARN, "The line %s:%d following a backslash is empty", name_parse_fb ? : (byte*) "", line_num);
+ msg(L_WARN, "The line %s:%d following a backslash is empty", name_parse_fb ? : (byte*) "", line_num);
} else {
split_grow(&word_buf, words+1);
uns start = copied;
word_buf.ptr[words++] = copied;
- *msg = get_word(is_command_name);
- return *msg ? NULL : copy_buf.ptr + start;
+ *err = get_word(is_command_name);
+ return *err ? NULL : copy_buf.ptr + start;
}
}
}
static byte *
parse_fastbuf(const byte *name_fb, struct fastbuf *fb, uns depth)
{
- byte *msg;
+ byte *err;
name_parse_fb = name_fb;
parse_fb = fb;
line_num = 0;
*line = 0;
while (1)
{
- msg = split_command();
- if (msg)
+ err = split_command();
+ if (err)
goto error;
if (!words)
return NULL;
if (!strcasecmp(name, "include"))
{
if (words != 2)
- msg = "Expecting one filename";
+ err = "Expecting one filename";
else if (depth > 8)
- msg = "Too many nested files";
+ err = "Too many nested files";
else if (*line && *line != '#') // because the contents of line_buf is not re-entrant and will be cleared
- msg = "The input command must be the last one on a line";
- if (msg)
+ err = "The input command must be the last one on a line";
+ if (err)
goto error;
struct fastbuf *new_fb = bopen_try(pars[0], O_RDONLY, 1<<14);
if (!new_fb) {
- msg = cf_printf("Cannot open file %s: %m", pars[0]);
+ err = cf_printf("Cannot open file %s: %m", pars[0]);
goto error;
}
uns ll = line_num;
- msg = parse_fastbuf(stk_strdup(pars[0]), new_fb, depth+1);
+ err = parse_fastbuf(stk_strdup(pars[0]), new_fb, depth+1);
line_num = ll;
bclose(new_fb);
- if (msg)
+ if (err)
goto error;
parse_fb = fb;
continue;
default: op = OP_SET; break;
}
if (strcasecmp(c, cf_op_names[op])) {
- msg = cf_printf("Unknown operation %s", c);
+ err = cf_printf("Unknown operation %s", c);
goto error;
}
}
if (ends_by_brace)
op |= OP_OPEN;
- msg = cf_interpret_line(name, op, words-1, pars);
- if (msg)
+ err = cf_interpret_line(name, op, words-1, pars);
+ if (err)
goto error;
}
error:
if (name_fb)
- log(L_ERROR, "File %s, line %d: %s", name_fb, line_num, msg);
+ msg(L_ERROR, "File %s, line %d: %s", name_fb, line_num, err);
else if (line_num == 1)
- log(L_ERROR, "Manual setting of configuration: %s", msg);
+ msg(L_ERROR, "Manual setting of configuration: %s", err);
else
- log(L_ERROR, "Manual setting of configuration, line %d: %s", line_num, msg);
+ msg(L_ERROR, "Manual setting of configuration, line %d: %s", line_num, err);
return "included from here";
}
cf_init_stack();
struct fastbuf *fb = bopen_try(file, O_RDONLY, 1<<14);
if (!fb) {
- log(L_ERROR, "Cannot open %s: %m", file);
+ msg(L_ERROR, "Cannot open %s: %m", file);
return 1;
}
- byte *msg = parse_fastbuf(file, fb, 0);
+ byte *err_msg = parse_fastbuf(file, fb, 0);
bclose(fb);
- int err = !!msg || done_stack();
+ int err = !!err_msg || done_stack();
if (!err)
cf_def_file = NULL;
return err;
cf_check_stack(void)
{
if (level > 0) {
- log(L_ERROR, "Unterminated block");
+ msg(L_ERROR, "Unterminated block");
return 1;
}
return 0;
for (struct cf_item *ci=sec->cfg; ci->cls; ci++)
if (ci->cls == CC_SECTION) {
if ((err = commit_section(ci->u.sec, ptr + (uintptr_t) ci->ptr, commit_all))) {
- log(L_ERROR, "Cannot commit section %s: %s", ci->name, err);
+ msg(L_ERROR, "Cannot commit section %s: %s", ci->name, err);
return "commit of a subsection failed";
}
} else if (ci->cls == CC_LIST) {
uns idx = 0;
CLIST_FOR_EACH(cnode *, n, * (clist*) (ptr + (uintptr_t) ci->ptr))
if (idx++, err = commit_section(ci->u.sec, n, commit_all)) {
- log(L_ERROR, "Cannot commit node #%d of list %s: %s", idx, ci->name, err);
+ msg(L_ERROR, "Cannot commit node #%d of list %s: %s", idx, ci->name, err);
return "commit of a list failed";
}
}
{
case 1:
if (unlink(f->name) < 0)
- log(L_ERROR, "unlink(%s): %m", f->name);
+ msg(L_ERROR, "unlink(%s): %m", f->name);
case 0:
close(FB_FILE(f)->fd);
}
{
bflush(b);
if (fsync(FB_FILE(b)->fd) < 0)
- log(L_ERROR, "fsync(%s) failed: %m", b->name);
+ msg(L_ERROR, "fsync(%s) failed: %m", b->name);
}
#ifdef TEST
{
case 1:
if (unlink(f->name) < 0)
- log(L_ERROR, "unlink(%s): %m", f->name);
+ msg(L_ERROR, "unlink(%s): %m", f->name);
case 0:
close(F->fd);
}
struct tm;
extern void (*log_switch_hook)(struct tm *tm);
-void log_msg(uns cat, const char *msg, ...) FORMAT_CHECK(printf,2,3);
-#define log log_msg
-void vlog_msg(uns cat, const char *msg, va_list args);
+void msg(uns cat, const char *fmt, ...) FORMAT_CHECK(printf,2,3);
+void vmsg(uns cat, const char *fmt, va_list args);
void die(const char *, ...) NONRET FORMAT_CHECK(printf,1,2);
void log_init(const char *argv0);
void log_file(const char *name);
#define COMPILE_ASSERT(name,x) typedef char _COMPILE_ASSERT_##name[!!(x)-1]
#ifdef LOCAL_DEBUG
-#define DBG(x,y...) log(L_DEBUG, x,##y)
+#define DBG(x,y...) msg(L_DEBUG, x,##y)
#else
#define DBG(x,y...) do { } while(0)
#endif
}
else
{
- log(L_ERROR, "SIGSEGV caught in lizard_decompress()");
+ msg(L_ERROR, "SIGSEGV caught in lizard_decompress()");
ptr = NULL;
errno = EFAULT;
}
void (*log_switch_hook)(struct tm *tm);
void
-vlog_msg(unsigned int cat, const char *msg, va_list args)
+vmsg(unsigned int cat, const char *fmt, va_list args)
{
struct timeval tv;
struct tm tm;
l0 = p - buf + 1;
r = buflen - l0;
va_copy(args2, args);
- l = vsnprintf(p, r, msg, args2);
+ l = vsnprintf(p, r, fmt, args2);
va_end(args2);
if (l < 0)
l = r;
}
void
-log_msg(unsigned int cat, const char *msg, ...)
+msg(unsigned int cat, const char *fmt, ...)
{
va_list args;
- va_start(args, msg);
- vlog_msg(cat, msg, args);
+ va_start(args, fmt);
+ vmsg(cat, fmt, args);
va_end(args);
}
void
-die(const char *msg, ...)
+die(const char *fmt, ...)
{
va_list args;
- va_start(args, msg);
- vlog_msg(L_FATAL, msg, args);
+ va_start(args, fmt);
+ vmsg(L_FATAL, fmt, args);
va_end(args);
if (log_die_hook)
log_die_hook();
void
assert_failed(const char *assertion, const char *file, int line)
{
- log(L_FATAL, "Assertion `%s' failed at %s:%d", assertion, file, line);
+ msg(L_FATAL, "Assertion `%s' failed at %s:%d", assertion, file, line);
abort();
}
main_file_cnt++;
main_poll_table_obsolete = 1;
if (fcntl(fi->fd, F_SETFL, O_NONBLOCK) < 0)
- log(L_ERROR, "Error setting fd %d to non-blocking mode: %m. Keep fingers crossed.", fi->fd);
+ msg(L_ERROR, "Error setting fd %d to non-blocking mode: %m. Keep fingers crossed.", fi->fd);
}
void
main_debug(void)
{
#ifdef CONFIG_DEBUG
- log(L_DEBUG, "### Main loop status on %lld", (long long)main_now);
- log(L_DEBUG, "\tActive timers:");
+ msg(L_DEBUG, "### Main loop status on %lld", (long long)main_now);
+ msg(L_DEBUG, "\tActive timers:");
struct main_timer *tm;
CLIST_WALK(tm, main_timer_list)
- log(L_DEBUG, "\t\t%p (expires %lld, data %p)", tm, (long long)(tm->expires ? tm->expires-main_now : 999999), tm->data);
+ msg(L_DEBUG, "\t\t%p (expires %lld, data %p)", tm, (long long)(tm->expires ? tm->expires-main_now : 999999), tm->data);
struct main_file *fi;
- log(L_DEBUG, "\tActive files:");
+ msg(L_DEBUG, "\tActive files:");
CLIST_WALK(fi, main_file_list)
- log(L_DEBUG, "\t\t%p (fd %d, rh %p, wh %p, eh %p, expires %lld, data %p)",
+ msg(L_DEBUG, "\t\t%p (fd %d, rh %p, wh %p, eh %p, expires %lld, data %p)",
fi, fi->fd, fi->read_handler, fi->write_handler, fi->error_handler,
(long long)(fi->timer.expires ? fi->timer.expires-main_now : 999999), fi->data);
- log(L_DEBUG, "\tActive hooks:");
+ msg(L_DEBUG, "\tActive hooks:");
struct main_hook *ho;
CLIST_WALK(ho, main_hook_list)
- log(L_DEBUG, "\t\t%p (func %p, data %p)", ho, ho->handler, ho->data);
- log(L_DEBUG, "\tActive processes:");
+ msg(L_DEBUG, "\t\t%p (func %p, data %p)", ho, ho->handler, ho->data);
+ msg(L_DEBUG, "\tActive processes:");
struct main_process *pr;
CLIST_WALK(pr, main_process_list)
- log(L_DEBUG, "\t\t%p (pid %d, data %p)", pr, pr->pid, pr->data);
+ msg(L_DEBUG, "\t\t%p (pid %d, data %p)", pr, pr->pid, pr->data);
#endif
}
+++ /dev/null
-/*
- * UCW Library -- Stub for including math.h, avoiding name collisions
- *
- * (c) 2003 Martin Mares <mj@ucw.cz>
- *
- * This software may be freely distributed and used according to the terms
- * of the GNU Lesser General Public License.
- */
-
-#undef log
-#define log libm_log
-#define exception math_exception
-#include <math.h>
-#undef log
-#define log log_msg
-#undef exception
-
-#ifdef CONFIG_LINUX
-float logf(float);
-#endif
goto unlock_and_fail;
qache_unlock(q, 0);
- log(L_INFO, "Cache %s: using existing data", q->file_name);
+ msg(L_INFO, "Cache %s: using existing data", q->file_name);
return 1;
unlock_and_fail:
qache_unlock(q, 0);
munmap(q->mmap_data, q->file_size);
close_and_fail:
- log(L_INFO, "Cache %s: ignoring old contents (%s)", q->file_name, err);
+ msg(L_INFO, "Cache %s: ignoring old contents (%s)", q->file_name, err);
close(q->fd);
return 0;
}
ASSERT(btell(fb) == (sh_off_t)par->cache_size);
bclose(fb);
- log(L_INFO, "Cache %s: created (%d bytes, %d slots, %d buckets)", q->file_name, par->cache_size, h.max_entries, h.hash_size);
+ msg(L_INFO, "Cache %s: created (%d bytes, %d slots, %d buckets)", q->file_name, par->cache_size, h.max_entries, h.hash_size);
if ((q->mmap_data = mmap(NULL, par->cache_size, PROT_READ | PROT_WRITE, MAP_SHARED, q->fd, 0)) == MAP_FAILED)
die("Cache %s: mmap failed (%m)", par->file_name);
munmap(q->mmap_data, q->file_size);
close(q->fd);
if (!retain_data && unlink(q->file_name) < 0)
- log(L_ERROR, "Cache %s: unlink failed (%m)", q->file_name);
+ msg(L_ERROR, "Cache %s: unlink failed (%m)", q->file_name);
xfree(q->file_name);
xfree(q);
}
void
qache_debug(struct qache *q)
{
- log(L_DEBUG, "Cache %s: block_size=%d (%d data), num_blocks=%d (%d first data), %d slots, %d hash buckets",
+ msg(L_DEBUG, "Cache %s: block_size=%d (%d data), num_blocks=%d (%d first data), %d slots, %d hash buckets",
q->file_name, q->hdr->block_size, q->hdr->block_size, q->hdr->num_blocks, q->hdr->first_data_block,
q->hdr->max_entries, q->hdr->hash_size);
- log(L_DEBUG, "Table of cache entries:");
- log(L_DEBUG, "\tEntry\tLruPrev\tLruNext\tDataLen\tDataBlk\tHashNxt\tKey");
+ msg(L_DEBUG, "Table of cache entries:");
+ msg(L_DEBUG, "\tEntry\tLruPrev\tLruNext\tDataLen\tDataBlk\tHashNxt\tKey");
for (uns e=0; e<q->hdr->max_entries; e++)
{
struct qache_entry *ent = &q->entry_table[e];
- log(L_DEBUG, "\t%d\t%d\t%d\t%d\t%d\t%d\t%s", e, ent->lru_prev, ent->lru_next, ent->data_len,
+ msg(L_DEBUG, "\t%d\t%d\t%d\t%d\t%d\t%d\t%s", e, ent->lru_prev, ent->lru_next, ent->data_len,
ent->first_data_block, ent->hash_next, format_key(&ent->key));
}
- log(L_DEBUG, "Hash table:");
+ msg(L_DEBUG, "Hash table:");
for (uns h=0; h<q->hdr->hash_size; h++)
- log(L_DEBUG, "\t%04x\t%d", h, q->hash_table[h]);
+ msg(L_DEBUG, "\t%04x\t%d", h, q->hash_table[h]);
- log(L_DEBUG, "Next pointers:");
+ msg(L_DEBUG, "Next pointers:");
for (uns blk=q->hdr->first_data_block; blk<q->hdr->num_blocks; blk++)
- log(L_DEBUG, "\t%d\t%d", blk, q->next_table[blk]);
+ msg(L_DEBUG, "\t%d\t%d", blk, q->next_table[blk]);
}
void
execv(cmd, argv);
byte echo[256];
echo_command_v(echo, sizeof(echo), cmd, args);
- log(L_ERROR, "Cannot execute %s: %m", echo);
+ msg(L_ERROR, "Cannot execute %s: %m", echo);
exit(255);
}
pid_t p = fork();
if (p < 0)
{
- log(L_ERROR, "fork() failed: %m");
+ msg(L_ERROR, "fork() failed: %m");
return 0;
}
else if (!p)
else
{
int stat;
- byte msg[EXIT_STATUS_MSG_SIZE];
+ byte status_msg[EXIT_STATUS_MSG_SIZE];
p = waitpid(p, &stat, 0);
if (p < 0)
die("waitpid() failed: %m");
- if (format_exit_status(msg, stat))
+ if (format_exit_status(status_msg, stat))
{
byte echo[256];
echo_command_v(echo, sizeof(echo), cmd, args);
- log(L_ERROR, "`%s' failed: %s", echo, msg);
+ msg(L_ERROR, "`%s' failed: %s", echo, status_msg);
return 0;
}
return 1;
else
log_init(argv[1]);
if (argc > 3)
- log(argv[2][0], argv[3]);
+ msg(argv[2][0], argv[3]);
else
while (fgets(buf, sizeof(buf), stdin))
{
c = strchr(buf, '\n');
if (c)
*c = 0;
- log(argv[2][0], buf);
+ msg(argv[2][0], buf);
}
return 0;
}
bclose(in1);
bclose(in2);
if (sorter_trace)
- log(L_INFO, "Pass %d: %d runs, %d+%d KB", sorter_pass_counter, run_count,
+ msg(L_INFO, "Pass %d: %d runs, %d+%d KB", sorter_pass_counter, run_count,
(out1 ? (int)((btell(out1) + 1023) / 1024) : 0),
(out2 ? (int)((btell(out2) + 1023) / 1024) : 0));
*fb1 = P(flush_out)(out1);
bclose(in);
if (sorter_trace)
- log(L_INFO, "Pass 0: %d runs, %d+%d KB",
+ msg(L_INFO, "Pass 0: %d runs, %d+%d KB",
run_count,
(out1 ? (int)((btell(out1) + 1023) / 1024) : 0),
(out2 ? (int)((btell(out2) + 1023) / 1024) : 0));
bclose(in);
if (sorter_trace)
- log(L_INFO, "Pass 0: %d runs (%d giants, %d splits), %d+%d KB",
+ msg(L_INFO, "Pass 0: %d runs (%d giants, %d splits), %d+%d KB",
run_count, giant_count, split_count,
(out1 ? (int)((btell(out1) + 1023) / 1024) : 0),
(out2 ? (int)((btell(out2) + 1023) / 1024) : 0));
if (err >= 0)
return;
err:
- log(L_ERROR, "Unable to sync directory %s: %m", name);
+ msg(L_ERROR, "Unable to sync directory %s: %m", name);
}