aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichał Łyszczek <michal.lyszczek@bofc.pl>2020-10-24 15:25:59 +0200
committerMichał Łyszczek <michal.lyszczek@bofc.pl>2020-10-24 17:44:14 +0200
commit8135f33615d31f23f0d9ec7ef1d2778443c81cf6 (patch)
tree1e65445232ce093eee417ebdbf49e40475a39d26
parent400ed4024c2a7419ae1263c1e3a75b0bfb964b0a (diff)
downloadembedlog-8135f33615d31f23f0d9ec7ef1d2778443c81cf6.tar.gz
embedlog-8135f33615d31f23f0d9ec7ef1d2778443c81cf6.tar.bz2
embedlog-8135f33615d31f23f0d9ec7ef1d2778443c81cf6.zip
retab
no_ci Signed-off-by: Michał Łyszczek <michal.lyszczek@bofc.pl>
-rw-r--r--.vimrc3
-rw-r--r--examples/print-memory.c21
-rw-r--r--examples/print-options.c178
-rw-r--r--examples/print-simple.c54
-rw-r--r--examples/print-to-file.c104
-rw-r--r--examples/print-tty.c88
-rw-r--r--include/embedlog.h.in243
-rw-r--r--src/el-decode-number.c52
-rw-r--r--src/el-encode-number.c88
-rw-r--r--src/el-file.c905
-rw-r--r--src/el-flush.c42
-rw-r--r--src/el-lock.c14
-rw-r--r--src/el-options.c904
-rw-r--r--src/el-pbinary.c163
-rw-r--r--src/el-perror.c111
-rw-r--r--src/el-pmemory.c335
-rw-r--r--src/el-print.c574
-rw-r--r--src/el-private.h8
-rw-r--r--src/el-puts.c166
-rw-r--r--src/el-syslog.c132
-rw-r--r--src/el-ts.c291
-rw-r--r--src/el-tty.c124
-rw-r--r--src/el-utils.c19
-rw-r--r--tst/main.c18
-rw-r--r--tst/test-el-file.c2382
-rw-r--r--tst/test-el-options.c567
-rw-r--r--tst/test-el-pbinary.c1244
-rw-r--r--tst/test-el-perror.c74
-rw-r--r--tst/test-el-pmemory.c285
-rw-r--r--tst/test-el-print.c1740
30 files changed, 5151 insertions, 5778 deletions
diff --git a/.vimrc b/.vimrc
index d7f6bd2..25ac74e 100644
--- a/.vimrc
+++ b/.vimrc
@@ -8,5 +8,4 @@
set encoding=utf-8 " utf-8 for the win!
set tabstop=4 " tab character is 4 spaces wide
set shiftwidth=4 " hitting ">>" will move line by 4 spaces
-set expandtab " produce spaces when <tab> is hit
-set softtabstop=4 " when <tab> is hit, produce 4 spaces
+set noexpandtab " produce tabs when <tab> is hit
diff --git a/examples/print-memory.c b/examples/print-memory.c
index 29c770c..77c6b42 100644
--- a/examples/print-memory.c
+++ b/examples/print-memory.c
@@ -7,21 +7,18 @@
int main(void)
{
- char s[] = "some message\0that contains\0null characters";
- char ascii[128];
- int i;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ char s[] = "some message\0that contains\0null characters";
+ char ascii[128];
+ int i;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- for (i = 0; i != 128; ++i)
- {
- ascii[i] = (char)i;
- }
+ for (i = 0; i != 128; ++i) ascii[i] = (char)i;
- el_init();
+ el_init();
- el_pmemory(ELI, ascii, sizeof(ascii));
- el_pmemory(ELI, s, sizeof(s));
+ el_pmemory(ELI, ascii, sizeof(ascii));
+ el_pmemory(ELI, s, sizeof(s));
- return 0;
+ return 0;
}
diff --git a/examples/print-options.c b/examples/print-options.c
index 72269c4..621e92e 100644
--- a/examples/print-options.c
+++ b/examples/print-options.c
@@ -11,97 +11,97 @@ void like_this() { el_print(ELN, "yup, I really like this!"); }
void or_this() { el_print(ELN, "this I like too"); }
void too_long_function_to_present_trimming_but_it_could_be_impossible()
{
- el_print(ELN, "trimmed (I hope) function name");
+ el_print(ELN, "trimmed (I hope) function name");
}
int main(void)
{
- struct el opts;
-
- el_init();
-
- el_option(EL_PRINT_LEVEL, 0);
- el_print(ELI, "We can disable information about log level\b");
- el_print(ELF, "message still will be filtered by log level");
- el_print(ELA, "but there is no way to tell what level message is");
- el_print(ELD, "like this message will not be printed");
-
- el_option(EL_TS, EL_TS_SHORT);
- el_print(ELF, "As every respected logger, we also have timestamps");
- el_print(ELF, "which work well with time from clock()");
- el_option(EL_TS_TM, EL_TS_TM_MONOTONIC);
- el_print(ELF, "or CLOCK_MONOTONIC from POSIX");
- el_option(EL_TS, EL_TS_LONG);
- el_option(EL_TS_TM, EL_TS_TM_TIME);
- el_print(ELF, "we also have long format that works well with time()");
- el_option(EL_TS_TM, EL_TS_TM_REALTIME);
- el_print(ELF, "if higher precision is needed we can use CLOCK_REALTIME");
- el_option(EL_TS, EL_TS_SHORT);
- el_print(ELF, "we can also mix REALTIME with short format");
- el_option(EL_TS_FRACT, EL_TS_FRACT_OFF);
- el_print(ELF, "and iff you don't need high resolution");
- el_print(ELF, "you can disable fractions of seconds to save space!");
- el_option(EL_TS_FRACT, EL_TS_FRACT_MS);
- el_print(ELF, "or enable only millisecond resolution");
- el_option(EL_TS_FRACT, EL_TS_FRACT_US);
- el_print(ELF, "or enable only microsecond resolution");
- el_option(EL_TS_FRACT, EL_TS_FRACT_NS);
- el_print(ELF, "or enable only nanosecond resolution");
- el_option(EL_TS, EL_TS_LONG);
- el_option(EL_TS_TM, EL_TS_TM_CLOCK);
- el_print(ELF, "or long with clock() if you desire");
- el_option(EL_TS, EL_TS_OFF);
- el_print(ELF, "no time information, if your heart desire it");
- el_option(EL_TS_FRACT, EL_TS_FRACT_NS);
-
- el_option(EL_FUNCINFO, 1);
- el_print(ELN, "logs can contain function name from which they were called");
- like_this();
- or_this();
- too_long_function_to_present_trimming_but_it_could_be_impossible();
-
- el_option(EL_FINFO, 1);
- el_print(ELF, "log location is very usefull for debuging");
-
- el_option(EL_TS, EL_TS_LONG);
- el_option(EL_TS_TM, EL_TS_TM_REALTIME);
- el_option(EL_PRINT_LEVEL, 1);
- el_print(ELF, "Different scenarios need different el object");
- el_print(ELA, "So we can mix options however we want");
-
- el_option(EL_PRINT_NL, 0);
- el_print(ELF, "you can also remove printing new line ");
- el_puts("to join el_print and el_puts in a single ");
- el_puts("long line as needed\n");
- el_option(EL_PRINT_NL, 1);
-
- el_option(EL_COLORS, 1);
- el_option(EL_LEVEL, EL_DBG);
- el_print(ELD, "And if we have");
- el_print(ELI, "modern terminal");
- el_print(ELN, "we can enable colors");
- el_print(ELW, "to spot warnings");
- el_print(ELE, "or errors");
- el_print(ELC, "with a quick");
- el_print(ELA, "glance into");
- el_print(ELF, "log file");
-
- el_option(EL_PREFIX, "embedlog: ");
- el_print(ELI, "you can also use prefixes");
- el_print(ELI, "to every message you send");
-
- el_option(EL_PREFIX, NULL);
- el_print(ELI, "set prefix to null to disable it");
-
- el_cleanup();
-
-
- el_oinit(&opts);
- el_ooption(&opts, EL_OUT, EL_OUT_STDERR);
- el_oprint(ELI, &opts, "you can do same thing as about with custom");
- el_oprint(ELI, &opts, "el object for two or more logger.");
- el_oprint(OELE, "and if you define EL_OPTIONS_OBJECT you will be");
- el_oprint(OELF, "able to print messages without passing el object");
- el_oprint(OELW, "each time to print functions");
- el_ocleanup(&opts);
+ struct el opts;
+
+ el_init();
+
+ el_option(EL_PRINT_LEVEL, 0);
+ el_print(ELI, "We can disable information about log level\b");
+ el_print(ELF, "message still will be filtered by log level");
+ el_print(ELA, "but there is no way to tell what level message is");
+ el_print(ELD, "like this message will not be printed");
+
+ el_option(EL_TS, EL_TS_SHORT);
+ el_print(ELF, "As every respected logger, we also have timestamps");
+ el_print(ELF, "which work well with time from clock()");
+ el_option(EL_TS_TM, EL_TS_TM_MONOTONIC);
+ el_print(ELF, "or CLOCK_MONOTONIC from POSIX");
+ el_option(EL_TS, EL_TS_LONG);
+ el_option(EL_TS_TM, EL_TS_TM_TIME);
+ el_print(ELF, "we also have long format that works well with time()");
+ el_option(EL_TS_TM, EL_TS_TM_REALTIME);
+ el_print(ELF, "if higher precision is needed we can use CLOCK_REALTIME");
+ el_option(EL_TS, EL_TS_SHORT);
+ el_print(ELF, "we can also mix REALTIME with short format");
+ el_option(EL_TS_FRACT, EL_TS_FRACT_OFF);
+ el_print(ELF, "and iff you don't need high resolution");
+ el_print(ELF, "you can disable fractions of seconds to save space!");
+ el_option(EL_TS_FRACT, EL_TS_FRACT_MS);
+ el_print(ELF, "or enable only millisecond resolution");
+ el_option(EL_TS_FRACT, EL_TS_FRACT_US);
+ el_print(ELF, "or enable only microsecond resolution");
+ el_option(EL_TS_FRACT, EL_TS_FRACT_NS);
+ el_print(ELF, "or enable only nanosecond resolution");
+ el_option(EL_TS, EL_TS_LONG);
+ el_option(EL_TS_TM, EL_TS_TM_CLOCK);
+ el_print(ELF, "or long with clock() if you desire");
+ el_option(EL_TS, EL_TS_OFF);
+ el_print(ELF, "no time information, if your heart desire it");
+ el_option(EL_TS_FRACT, EL_TS_FRACT_NS);
+
+ el_option(EL_FUNCINFO, 1);
+ el_print(ELN, "logs can contain function name from which they were called");
+ like_this();
+ or_this();
+ too_long_function_to_present_trimming_but_it_could_be_impossible();
+
+ el_option(EL_FINFO, 1);
+ el_print(ELF, "log location is very usefull for debuging");
+
+ el_option(EL_TS, EL_TS_LONG);
+ el_option(EL_TS_TM, EL_TS_TM_REALTIME);
+ el_option(EL_PRINT_LEVEL, 1);
+ el_print(ELF, "Different scenarios need different el object");
+ el_print(ELA, "So we can mix options however we want");
+
+ el_option(EL_PRINT_NL, 0);
+ el_print(ELF, "you can also remove printing new line ");
+ el_puts("to join el_print and el_puts in a single ");
+ el_puts("long line as needed\n");
+ el_option(EL_PRINT_NL, 1);
+
+ el_option(EL_COLORS, 1);
+ el_option(EL_LEVEL, EL_DBG);
+ el_print(ELD, "And if we have");
+ el_print(ELI, "modern terminal");
+ el_print(ELN, "we can enable colors");
+ el_print(ELW, "to spot warnings");
+ el_print(ELE, "or errors");
+ el_print(ELC, "with a quick");
+ el_print(ELA, "glance into");
+ el_print(ELF, "log file");
+
+ el_option(EL_PREFIX, "embedlog: ");
+ el_print(ELI, "you can also use prefixes");
+ el_print(ELI, "to every message you send");
+
+ el_option(EL_PREFIX, NULL);
+ el_print(ELI, "set prefix to null to disable it");
+
+ el_cleanup();
+
+
+ el_oinit(&opts);
+ el_ooption(&opts, EL_OUT, EL_OUT_STDERR);
+ el_oprint(ELI, &opts, "you can do same thing as about with custom");
+ el_oprint(ELI, &opts, "el object for two or more logger.");
+ el_oprint(OELE, "and if you define EL_OPTIONS_OBJECT you will be");
+ el_oprint(OELF, "able to print messages without passing el object");
+ el_oprint(OELW, "each time to print functions");
+ el_ocleanup(&opts);
}
diff --git a/examples/print-simple.c b/examples/print-simple.c
index 3634090..4c28751 100644
--- a/examples/print-simple.c
+++ b/examples/print-simple.c
@@ -7,35 +7,27 @@
int main(void)
{
- /* first we nned to initialize logger to known state, embedlog
- * will print to stdout by default
- */
-
- el_init();
-
- /* now we can simply print messages like we would do it with
- * ordinary printf - we just need to log level macro as a first
- * argument
- */
-
- el_print(ELI, "Info message");
- el_print(ELF, "Fatal message with additional argument %d", 42);
- el_print(ELD, "Debug message that won't be printed due to log level");
-
- /* we can change log level in runtime as we see fit, now enable
- * debug prints
- */
-
- el_option(EL_LEVEL, EL_DBG);
- el_print(ELD, "But now debug will be printed");
-
- /* altough embedlog does not use dynamic allocation by itself,
- * system may allocate some resources (like opened file
- * descriptors when printing to file), with el_cleanup, we can
- * make sure all resources are freed.
- */
-
- el_cleanup();
-
- return 0;
+ /* first we nned to initialize logger to known state, embedlog
+ * will print to stdout by default */
+ el_init();
+
+ /* now we can simply print messages like we would do it with
+ * ordinary printf - we just need to log level macro as a first
+ * argument */
+ el_print(ELI, "Info message");
+ el_print(ELF, "Fatal message with additional argument %d", 42);
+ el_print(ELD, "Debug message that won't be printed due to log level");
+
+ /* we can change log level in runtime as we see fit, now enable
+ * debug prints */
+ el_option(EL_LEVEL, EL_DBG);
+ el_print(ELD, "But now debug will be printed");
+
+ /* altough embedlog does not use dynamic allocation by itself,
+ * system may allocate some resources (like opened file
+ * descriptors when printing to file), with el_cleanup, we can
+ * make sure all resources are freed. */
+ el_cleanup();
+
+ return 0;
}
diff --git a/examples/print-to-file.c b/examples/print-to-file.c
index 3d60825..b141e47 100644
--- a/examples/print-to-file.c
+++ b/examples/print-to-file.c
@@ -13,61 +13,55 @@
int main(void)
{
- el_init();
- el_option(EL_TS, EL_TS_LONG);
- el_option(EL_TS_TM, EL_TS_TM_REALTIME);
- el_option(EL_FINFO, 1);
-
- if (mkdir(WORKDIR, 0755) != 0 && errno != EEXIST)
- {
- fprintf(stderr, "Couldn't create %s, error %s\n",
- WORKDIR, strerror(errno));
-
- goto error;
- }
-
- if (el_option(EL_FPATH, WORKDIR"/log") != 0)
- {
- /* embedlog will try to open file now, this may fail for
- * various of reasons, if opening fails, we cannot log to
- * file - all el_print to files will return error
- */
-
- fprintf(stderr, "Couldn't open file for logging %s\n",
- strerror(errno));
-
- goto error;
- }
-
- /* instruct logger to print into both file and standard error
- */
-
- el_option(EL_OUT, EL_OUT_FILE | EL_OUT_STDERR);
-
- el_print(ELI, "This message will appear both in standard error");
- el_print(ELI, "and in file %s", WORKDIR"/log");
- el_print(ELI, "in this file there might be another logs like this "
- "from consecutive execution if this code, as embedlog "
- "does not truncate logs but append to file");
-
- /* enable file rotation and set file size to small enough value
- * to present how rotation works, in real life, rotate size
- * should be much higher to prevent unnecessary rotation
- */
-
- el_option(EL_FROTATE_NUMBER, 5);
- el_option(EL_FROTATE_SIZE, 512);
- el_print(ELI, "Now we enabled log rotation");
- el_print(ELI, "If log cannot fit in current file");
- el_print(ELI, "it will be stored in new file");
- el_print(ELI, "and if library creates EL_FROTATE_NUMBER files");
- el_print(ELI, "oldest file will be deleted and new file will be created");
- el_print(ELI, "run this program multiple times and see how it works");
-
- el_cleanup();
- return 0;
+ el_init();
+ el_option(EL_TS, EL_TS_LONG);
+ el_option(EL_TS_TM, EL_TS_TM_REALTIME);
+ el_option(EL_FINFO, 1);
+
+ if (mkdir(WORKDIR, 0755) != 0 && errno != EEXIST)
+ {
+ fprintf(stderr, "Couldn't create %s, error %s\n",
+ WORKDIR, strerror(errno));
+
+ goto error;
+ }
+
+ if (el_option(EL_FPATH, WORKDIR"/log") != 0)
+ {
+ /* embedlog will try to open file now, this may fail for
+ * various of reasons, if opening fails, we cannot log to
+ * file - all el_print to files will return error */
+ fprintf(stderr, "Couldn't open file for logging %s\n",
+ strerror(errno));
+
+ goto error;
+ }
+
+ /* instruct logger to print into both file and standard error */
+ el_option(EL_OUT, EL_OUT_FILE | EL_OUT_STDERR);
+
+ el_print(ELI, "This message will appear both in standard error");
+ el_print(ELI, "and in file %s", WORKDIR"/log");
+ el_print(ELI, "in this file there might be another logs like this "
+ "from consecutive execution if this code, as embedlog "
+ "does not truncate logs but append to file");
+
+ /* enable file rotation and set file size to small enough value
+ * to present how rotation works, in real life, rotate size
+ * should be much higher to prevent unnecessary rotation */
+ el_option(EL_FROTATE_NUMBER, 5);
+ el_option(EL_FROTATE_SIZE, 512);
+ el_print(ELI, "Now we enabled log rotation");
+ el_print(ELI, "If log cannot fit in current file");
+ el_print(ELI, "it will be stored in new file");
+ el_print(ELI, "and if library creates EL_FROTATE_NUMBER files");
+ el_print(ELI, "oldest file will be deleted and new file will be created");
+ el_print(ELI, "run this program multiple times and see how it works");
+
+ el_cleanup();
+ return 0;
error:
- el_cleanup();
- return 1;
+ el_cleanup();
+ return 1;
}
diff --git a/examples/print-tty.c b/examples/print-tty.c
index bf13440..e483c14 100644
--- a/examples/print-tty.c
+++ b/examples/print-tty.c
@@ -8,54 +8,42 @@
int main(void)
{
- /* first we nned to initialize logger to known state
- */
-
- el_init();
-
- /* to use logger you need to enable at least one output,
- * without it logs will be printed to /dev/null. Here we set
- * output to serial device.
- */
-
- el_option(EL_OUT, EL_OUT_TTY);
-
- /* enbaling tty output is not enough, we still need to
- * configure which device we want to use and at what speed.
- * Transmission parameters are 8N1 by default. Baudrate should
- * be taken from termios (3).
- */
-
- if (el_option(EL_TTY_DEV, "/dev/ttyUSB1", B9600) != 0)
- {
- perror("tty set failed");
- return 1;
- }
-
- /* now we can simply print messages like we would do it with
- * ordinary printf - we just need to log level macro as a first
- * argument
- */
-
- el_print(ELI, "Info message");
- el_print(ELF, "Fatal message with additional argument %d", 42);
- el_print(ELD, "Debug message that won't be printed due to log level");
-
- /* we can change log level in runtime as we see fit, now enable
- * debug prints
- */
-
- el_option(EL_LEVEL, EL_DBG);
- el_print(ELD, "But now debug will be printed");
-
- /* altough embedlog does not use dynamic allocation by itself,
- * system may allocate some resources (like opened file
- * descriptors when printing to file), with el_cleanup, we can
- * make sure all resources are freed. In this example, this
- * function will close opened tty file descriptor.
- */
-
- el_cleanup();
-
- return 0;
+ /* first we nned to initialize logger to known state */
+ el_init();
+
+ /* to use logger you need to enable at least one output,
+ * without it logs will be printed to /dev/null. Here we set
+ * output to serial device. */
+ el_option(EL_OUT, EL_OUT_TTY);
+
+ /* enbaling tty output is not enough, we still need to
+ * configure which device we want to use and at what speed.
+ * Transmission parameters are 8N1 by default. Baudrate should
+ * be taken from termios (3). */
+ if (el_option(EL_TTY_DEV, "/dev/ttyUSB1", B9600) != 0)
+ {
+ perror("tty set failed");
+ return 1;
+ }
+
+ /* now we can simply print messages like we would do it with
+ * ordinary printf - we just need to log level macro as a first
+ * argument */
+ el_print(ELI, "Info message");
+ el_print(ELF, "Fatal message with additional argument %d", 42);
+ el_print(ELD, "Debug message that won't be printed due to log level");
+
+ /* we can change log level in runtime as we see fit, now enable
+ * debug prints */
+ el_option(EL_LEVEL, EL_DBG);
+ el_print(ELD, "But now debug will be printed");
+
+ /* altough embedlog does not use dynamic allocation by itself,
+ * system may allocate some resources (like opened file
+ * descriptors when printing to file), with el_cleanup, we can
+ * make sure all resources are freed. In this example, this
+ * function will close opened tty file descriptor. */
+ el_cleanup();
+
+ return 0;
}
diff --git a/include/embedlog.h.in b/include/embedlog.h.in
index 752f1a1..a321e14 100644
--- a/include/embedlog.h.in
+++ b/include/embedlog.h.in
@@ -70,112 +70,104 @@ extern "C" {
#endif
/* enum values, new enums can be added, but values of already
- * existing enums *must* stay unchanged, to keep ABI stable!
- */
+ * existing enums *must* stay unchanged, to keep ABI stable! */
enum el_output
{
- EL_OUT_NONE = 0x0000,
- EL_OUT_STDERR = 0x0001,
- EL_OUT_STDOUT = 0x0002,
- EL_OUT_SYSLOG = 0x0004,
- EL_OUT_FILE = 0x0008,
- EL_OUT_NET = 0x0010,
- EL_OUT_TTY = 0x0020,
- EL_OUT_CUSTOM = 0x0040,
- EL_OUT_ALL = 0x7fff
+ EL_OUT_NONE = 0x0000,
+ EL_OUT_STDERR = 0x0001,
+ EL_OUT_STDOUT = 0x0002,
+ EL_OUT_SYSLOG = 0x0004,
+ EL_OUT_FILE = 0x0008,
+ EL_OUT_NET = 0x0010,
+ EL_OUT_TTY = 0x0020,
+ EL_OUT_CUSTOM = 0x0040,
+ EL_OUT_ALL = 0x7fff
};
enum el_level
{
- EL_FATAL = 0,
- EL_ALERT = 1,
- EL_CRIT = 2,
- EL_ERROR = 3,
- EL_WARN = 4,
- EL_NOTICE = 5,
- EL_INFO = 6,
- EL_DBG = 7
+ EL_FATAL = 0,
+ EL_ALERT = 1,
+ EL_CRIT = 2,
+ EL_ERROR = 3,
+ EL_WARN = 4,
+ EL_NOTICE = 5,
+ EL_INFO = 6,
+ EL_DBG = 7
};
enum el_option
{
- EL_LEVEL = 0,
- EL_OUT = 1,
- EL_COLORS = 2,
- EL_TS = 3,
- EL_TS_TM = 4,
- EL_TS_FRACT = 5,
- EL_PRINT_LEVEL = 6,
- EL_PRINT_NL = 7,
- EL_FINFO = 8,
- EL_FUNCINFO = 9,
- EL_CUSTOM_PUTS = 10, /* deprecated */
- EL_CUSTOM_PUT = 10,
- EL_TTY_DEV = 11,
- EL_PREFIX = 12,
-
- EL_FPATH = 13,
- EL_FROTATE_NUMBER = 14,
- EL_FROTATE_SIZE = 15,
- EL_FROTATE_SYMLINK= 19,
- EL_FSYNC_EVERY = 16,
- EL_FSYNC_LEVEL = 17,
- EL_FILE_SYNC_EVERY= 16, /* deprecated */
- EL_FILE_SYNC_LEVEL= 17, /* deprecated */
-
- EL_THREAD_SAFE = 18,
-
- /* internal use only, should represent number of options, if
- * you add option, increment this by one (or by the number of
- * options you add).
- */
-
- EL_OPT_ERROR = 20
+ EL_LEVEL = 0,
+ EL_OUT = 1,
+ EL_COLORS = 2,
+ EL_TS = 3,
+ EL_TS_TM = 4,
+ EL_TS_FRACT = 5,
+ EL_PRINT_LEVEL = 6,
+ EL_PRINT_NL = 7,
+ EL_FINFO = 8,
+ EL_FUNCINFO = 9,
+ EL_CUSTOM_PUTS = 10, /* deprecated */
+ EL_CUSTOM_PUT = 10,
+ EL_TTY_DEV = 11,
+ EL_PREFIX = 12,
+
+ EL_FPATH = 13,
+ EL_FROTATE_NUMBER = 14,
+ EL_FROTATE_SIZE = 15,
+ EL_FROTATE_SYMLINK= 19,
+ EL_FSYNC_EVERY = 16,
+ EL_FSYNC_LEVEL = 17,
+ EL_FILE_SYNC_EVERY= 16, /* deprecated */
+ EL_FILE_SYNC_LEVEL= 17, /* deprecated */
+
+ EL_THREAD_SAFE = 18,
+
+ /* internal use only, should represent number of options, if
+ * you add option, increment this by one (or by the number of
+ * options you add). */
+ EL_OPT_ERROR = 20
};
enum el_option_timestamp
{
- EL_TS_OFF = 0,
- EL_TS_SHORT = 1,
- EL_TS_LONG = 2,
-
- /* internal use only, should represent number of options, if
- * you add option, increment this by one (or by the number of
- * options you add).
- */
-
- EL_TS_ERROR = 3
+ EL_TS_OFF = 0,
+ EL_TS_SHORT = 1,
+ EL_TS_LONG = 2,
+
+ /* internal use only, should represent number of options, if
+ * you add option, increment this by one (or by the number of
+ * options you add). */
+ EL_TS_ERROR = 3
};
enum el_option_timestamp_timer
{
- EL_TS_TM_TIME = 0,
- EL_TS_TM_CLOCK = 1,
- EL_TS_TM_REALTIME = 2,
- EL_TS_TM_MONOTONIC = 3,
-
- /* internal use only, should represent number of options, if
- * you add option, increment this by one (or by the number of
- * options you add).
- */
-
- EL_TS_TM_ERROR = 4
+ EL_TS_TM_TIME = 0,
+ EL_TS_TM_CLOCK = 1,
+ EL_TS_TM_REALTIME = 2,
+ EL_TS_TM_MONOTONIC = 3,
+
+ /* internal use only, should represent number of options, if
+ * you add option, increment this by one (or by the number of
+ * options you add). */
+ EL_TS_TM_ERROR = 4
};
enum el_option_timestamp_fractions
{
- EL_TS_FRACT_OFF = 0,
- EL_TS_FRACT_MS = 1,
- EL_TS_FRACT_US = 2,
- EL_TS_FRACT_NS = 3,
+ EL_TS_FRACT_OFF = 0,
+ EL_TS_FRACT_MS = 1,
+ EL_TS_FRACT_US = 2,
+ EL_TS_FRACT_NS = 3,
- /* internal use only, should represent number of options, if
- * you add option, increment this by one (or by the number of
- * options you add).
- */
+ /* internal use only, should represent number of options, if
+ * you add option, increment this by one (or by the number of
+ * options you add). */
- EL_TS_FRACT_ERROR = 4
+ EL_TS_FRACT_ERROR = 4
};
typedef int (*el_custom_put)(const char *s, size_t slen, void *user);
@@ -192,53 +184,52 @@ typedef int (*el_custom_put)(const char *s, size_t slen, void *user);
* It's generated as #if [0,1] so this is applied system-wide, if
* it were to be defined like #if ENABLE_OUT_FILE, then every
* compilation unit that uses embedlog would have to define that to
- * either 1 or 0. Easy for mistakes and hard to find bugs.
- */
+ * either 1 or 0. Easy for mistakes and hard to find bugs. */
struct el
{
- unsigned int outputs:7;
- unsigned int colors:1;
- unsigned int timestamp:2;
- unsigned int timestamp_timer:3;
- unsigned int timestamp_fractions:2;
- unsigned int print_log_level:1;
- unsigned int print_newline:1;
- unsigned int finfo:1;
- unsigned int funcinfo:1;
- unsigned int level:3;
- unsigned int level_current_msg:3;
+ unsigned int outputs:7;
+ unsigned int colors:1;
+ unsigned int timestamp:2;
+ unsigned int timestamp_timer:3;
+ unsigned int timestamp_fractions:2;
+ unsigned int print_log_level:1;
+ unsigned int print_newline:1;
+ unsigned int finfo:1;
+ unsigned int funcinfo:1;
+ unsigned int level:3;
+ unsigned int level_current_msg:3;
#if @ENABLE_OUT_FILE@
- unsigned int fsync_level:3;
- unsigned int frotate_symlink:1;
- unsigned int frotate_number_count:3;
- unsigned short frotate_number;
- unsigned short fcurrent_rotate;
- unsigned long frotate_size;
- unsigned long fsync_every;
- unsigned long fwritten_after_sync;
- unsigned long fpos;
- FILE *file;
- char *fcurrent_log;
- const char *fname;
+ unsigned int fsync_level:3;
+ unsigned int frotate_symlink:1;
+ unsigned int frotate_number_count:3;
+ unsigned short frotate_number;
+ unsigned short fcurrent_rotate;
+ unsigned long frotate_size;
+ unsigned long fsync_every;
+ unsigned long fwritten_after_sync;
+ unsigned long fpos;
+ FILE *file;
+ char *fcurrent_log;
+ const char *fname;
#endif
#if @ENABLE_OUT_TTY@
- int serial_fd;
+ int serial_fd;
#endif
#if @ENABLE_PREFIX@
- const char *prefix;
+ const char *prefix;
#endif
#if @ENABLE_OUT_CUSTOM@
- el_custom_put custom_put;
- void *custom_put_user;
+ el_custom_put custom_put;
+ void *custom_put_user;
#endif
#if @ENABLE_PTHREAD@
- pthread_mutex_t lock;
- int lock_initialized;
+ pthread_mutex_t lock;
+ int lock_initialized;
#endif
};
@@ -247,15 +238,15 @@ int el_cleanup(void);
int el_option(int option, ...);
int el_puts(const char *string);
int el_print(const char *file, size_t line, const char *func,
- enum el_level level, const char *fmt, ...);
+ enum el_level level, const char *fmt, ...);
int el_vprint(const char *file, size_t line, const char *func,
- enum el_level level, const char *fmt, va_list ap);
+ enum el_level level, const char *fmt, va_list ap);
int el_pmemory(const char *file, size_t line, const char *func,
- enum el_level level, const void *memory, size_t mlen);
+ enum el_level level, const void *memory, size_t mlen);
int el_pmemory_table(const char *file, size_t line, const char *func,
- enum el_level level, const void *memory, size_t mlen);
+ enum el_level level, const void *memory, size_t mlen);
int el_perror(const char *file, size_t line, const char *func,
- enum el_level level, const char *fmt, ...);
+ enum el_level level, const char *fmt, ...);
int el_putb(const void *memory, size_t mlen);
int el_pbinary(enum el_level level, const void *memory, size_t mlen);
const struct el *el_get_el(void);
@@ -269,21 +260,21 @@ int el_ocleanup(struct el *el);
int el_ooption(struct el *el, int option, ...);
int el_oputs(struct el *el, const char *string);
int el_oprint(const char *file, size_t line, const char *func,
- enum el_level level, struct el *el, const char *fnt, ...);
+ enum el_level level, struct el *el, const char *fnt, ...);
int el_ovprint(const char *file, size_t line, const char *func,
- enum el_level level, struct el *el, const char *fmt,
- va_list ap);
+ enum el_level level, struct el *el, const char *fmt,
+ va_list ap);
int el_opmemory(const char *file, size_t line, const char *func,
- enum el_level level, struct el *el, const void *memory,
- size_t mlen);
+ enum el_level level, struct el *el, const void *memory,
+ size_t mlen);
int el_opmemory_table(const char *file, size_t line, const char *func,
- enum el_level level, struct el *el, const void *memory,
- size_t mlen);
+ enum el_level level, struct el *el, const void *memory,
+ size_t mlen);
int el_operror(const char *file, size_t line, const char *func,
- enum el_level level, struct el *el, const char *fmt, ...);
+ enum el_level level, struct el *el, const char *fmt, ...);
int el_oputb(struct el *el, const void *memory, size_t mlen);
int el_opbinary(enum el_level level, struct el *el,
- const void *memory, size_t mlen);
+ const void *memory, size_t mlen);
int el_oflush(struct el *el);
#ifdef __cplusplus
diff --git a/src/el-decode-number.c b/src/el-decode-number.c
index f57d728..260ae1d 100644
--- a/src/el-decode-number.c
+++ b/src/el-decode-number.c
@@ -36,46 +36,42 @@
size_t el_decode_number
(
- const void *number, /* number to decode */
+ const void *number, /* number to decode */
#ifdef LLONG_MAX
- unsigned long long *out /* decoded number */
+ unsigned long long *out /* decoded number */
#else
- unsigned long *out /* decoded number */
+ unsigned long *out /* decoded number */
#endif
)
{
- const unsigned char *n; /* just a 'number' as unsigned cahr */
- size_t i; /* temporary index */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ const unsigned char *n; /* just a 'number' as unsigned cahr */
+ size_t i; /* temporary index */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- i = 0;
- *out = 0;
- n = number;
+ i = 0;
+ *out = 0;
+ n = number;
- do
- {
- /* multiple stuff is happening in this one-liner
- *
- * - first we take 7 bits of number
- * - calculate weigth of current number
- * - set current number into right position of out
- */
+ do
+ {
+ /* multiple stuff is happening in this one-liner
+ *
+ * - first we take 7 bits of number
+ * - calculate weigth of current number
+ * - set current number into right position of out */
#ifdef LLONG_MAX
- *out |= (unsigned long long)(n[i] & 0x7f) << (i * 7);
+ *out |= (unsigned long long)(n[i] & 0x7f) << (i * 7);
#else
- *out |= (unsigned long)(n[i] & 0x7f) << (i * 7);
+ *out |= (unsigned long)(n[i] & 0x7f) << (i * 7);
#endif
- /* we do this until number lacks of continuation bit, which means
- * we are done
- */
- }
- while (n[i++] & 0x80);
+ /* we do this until number lacks of continuation bit, which
+ * means we are done */
+ }
+ while (n[i++] & 0x80);
- /* return number of bytes processed from 'number'
- */
-
- return i;
+ /* return number of bytes processed from 'number' */
+ return i;
}
diff --git a/src/el-encode-number.c b/src/el-encode-number.c
index 60b6c4b..bfe6b5f 100644
--- a/src/el-encode-number.c
+++ b/src/el-encode-number.c
@@ -42,56 +42,48 @@
size_t el_encode_number
(
#ifdef LLONG_MAX
- unsigned long long number, /* value to encode */
+ unsigned long long number, /* value to encode */
#else
- unsigned long number, /* value to encode */
+ unsigned long number, /* value to encode */
#endif
- void *out /* memory where encoded value will be set */
+ void *out /* memory where encoded value will be set */
)
{
- unsigned char *o; /* just 'out' as unsigned char */
- size_t n; /* number of bytes stored in 'out' */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- o = out;
- n = 0;
-
- do
- {
- /* put only youngest 7 bits into out - that's a max number
- * single byte can hold
- */
-
- o[n] = number & 0x7f;
-
- /* remove those 7 bits from number, they are used and no
- * longer needed
- */
-
- number >>= 7;
-
- /* if we didn't process whole number, set oldest bit to 1,
- * this is continuation bit, it will tell decoder that next
- * bytes will hold next 7bits of number
- */
-
- if (number)
- {
- o[n] |= 0x80;
- }
-
- /* increment n to indicate we store a byte in 'out' buffer
- */
-
- ++n;
-
- /* do this until there is anyting else left in number
- */
- }
- while (number);
-
- /* after job's done, return number of bytes stored in 'out'
- */
-
- return n;
+ unsigned char *o; /* just 'out' as unsigned char */
+ size_t n; /* number of bytes stored in 'out' */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+ o = out;
+ n = 0;
+
+ do
+ {
+ /* put only youngest 7 bits into out -
+ * that's a max number single byte can
+ * hold */
+ o[n] = number & 0x7f;
+
+ /* remove those 7 bits from number, they
+ * are used and no longer needed */
+ number >>= 7;
+
+ /* if we didn't process whole number, set
+ * oldest bit to 1, this is continuation
+ * bit, it will tell decoder that next
+ * bytes will hold next 7bits of number */
+ if (number)
+ o[n] |= 0x80;
+
+ /* increment n to indicate we store a byte
+ * in 'out' buffer */
+ ++n;
+
+ /* do this until there is anyting else
+ * left in number */
+ }
+ while (number);
+
+ /* after job's done, return number of bytes
+ * stored in 'out' */
+ return n;
}
diff --git a/src/el-file.c b/src/el-file.c
index 674a49f..7d3419f 100644
--- a/src/el-file.c
+++ b/src/el-file.c
@@ -119,44 +119,34 @@ int file_synced;
static int el_file_exists
(
- const char *path /* file to check */
+ const char *path /* file to check */
)
{
#if HAVE_ACCESS
- /* access is the fastest
- */
-
- return access(path, F_OK) == 0;
+ /* access is the fastest */
+ return access(path, F_OK) == 0;
#elif HAVE_STAT
- /* but if we don't have access (some embedded systems like
- * nuttx don't have users and will always return OK when
- * access is called - wrongly)
- */
-
- struct stat st;
+ /* but if we don't have access (some embedded systems like
+ * nuttx don't have users and will always return OK when
+ * access is called - wrongly) */
+ struct stat st;
- /* if stat return 0 we are sure file exists, -1 is returned for
- * when file doesn't exist or there is other error, in any case
- * we assume file doesn't exist
- */
-
- return stat(path, &st) == 0;
+ /* if stat return 0 we are sure file exists, -1 is returned for
+ * when file doesn't exist or there is other error, in any case
+ * we assume file doesn't exist */
+ return stat(path, &st) == 0;
#else
- /* slowest, worst but highly portable solution, for when there
- * is nothing left but you still want to work
- */
-
- FILE *f;
+ /* slowest, worst but highly portable solution, for when there
+ * is nothing left but you still want to work */
- if ((f = fopen(path, "r")) == NULL)
- {
- return 0;
- }
+ FILE *f;
+ if ((f = fopen(path, "r")) == NULL)
+ return 0;
- fclose(f);
- return 1;
+ fclose(f);
+ return 1;
#endif
}
@@ -182,15 +172,15 @@ static int el_file_exists
static void el_symlink_to_newest_log
(
- struct el *el /* embedlog object to work on */
+ struct el *el /* embedlog object to work on */
)
{
#if HAVE_SYMLINK
- if (el->frotate_symlink)
- {
- (void)remove(el->fname);
- (void)symlink(el_basename(el->fcurrent_log), el->fname);
- }
+ if (el->frotate_symlink)
+ {
+ (void)remove(el->fname);
+ (void)symlink(el_basename(el->fcurrent_log), el->fname);
+ }
#endif
}
@@ -206,100 +196,87 @@ static void el_symlink_to_newest_log
static int el_file_rotate
(
- struct el *el
+ struct el *el
)
{
- unsigned int i; /* simple iterator for loop */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- if (el->file)
- {
- fclose(el->file);
- el->file = NULL;
- }
-
- el->fcurrent_rotate++;
- if (el->fcurrent_rotate == el->frotate_number)
- {
- /* it appears we used all rotating slots, reset counter and
- * rename all files in order (for frotate_number == 4)
- *
- * .1 -> .0
- * .2 -> .1
- * .3 -> .2
- *
- * As we can see, oldest file .0 will be deleted, and file
- * .3 will disapear making space for new log
- */
-
- el->fcurrent_rotate = el->frotate_number - 1;
-
- if (el->frotate_number == 1)
- {
- /* if frotate_number is equal to 1, this means only one
- * file can exist (with suffix .0), so we cannot rotate
- * that (like rename it from .0 to .0, pointless) file
- * and thus we simply skip this foor loop, and later
- * file will just be truncated to 0
- */
-
- goto skip_rotate;
- }
-
- for (i = 1; i != el->frotate_number; ++i)
- {
- char old_name[PATH_MAX + 6]; /* ie .2 suffix */
- char new_name[PATH_MAX + 6]; /* ie .3 suffix */
- int pad_len;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- /* we do not check for overflow here, as overflow is
- * already tested in el_file_open function, there we
- * check opening file with biggest suffix. Assuming if
- * it works there, it will work here as well
- */
-
- pad_len = el->frotate_number_count;
- sprintf(old_name, "%s.%0*d", el->fname, pad_len, i);
- sprintf(new_name, "%s.%0*d", el->fname, pad_len, i - 1);
-
- rename(old_name, new_name);
-
- /* rename can fail, but it is usually because someone
- * removed some logs, like there are logs: .1 .2 .4 .5,
- * so .3 is missing, and if we want to rename .3 to .2,
- * rename will fail, it doesn't really matter, as .4
- * will be renamed to .3, and after full loop there
- * will be .0 .1 .3 .4 .5 and after one more rotation,
- * we'll have .0 .1 .2 .3 .4 .5, so full complet. So
- * such situation will heal by itself over time.
- */
- }
- }
+ unsigned int i; /* simple iterator for loop */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ if (el->file)
+ {
+ fclose(el->file);
+ el->file = NULL;
+ }
+
+ el->fcurrent_rotate++;
+ if (el->fcurrent_rotate == el->frotate_number)
+ {
+ /* it appears we used all rotating slots, reset counter and
+ * rename all files in order (for frotate_number == 4)
+ *
+ * .1 -> .0
+ * .2 -> .1
+ * .3 -> .2
+ *
+ * As we can see, oldest file .0 will be deleted, and file
+ * .3 will disapear making space for new log */
+ el->fcurrent_rotate = el->frotate_number - 1;
+
+ /* if frotate_number is equal to 1, this means only one
+ * file can exist (with suffix .0), so we cannot rotate
+ * that (like rename it from .0 to .0, pointless) file
+ * and thus we simply skip this foor loop, and later
+ * file will just be truncated to 0 */
+ if (el->frotate_number == 1) goto skip_rotate;
+
+ for (i = 1; i != el->frotate_number; ++i)
+ {
+ char old_name[PATH_MAX + 6]; /* ie .2 suffix */
+ char new_name[PATH_MAX + 6]; /* ie .3 suffix */
+ int pad_len;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+ /* we do not check for overflow here, as overflow is
+ * already tested in el_file_open function, there we
+ * check opening file with biggest suffix. Assuming if
+ * it works there, it will work here as well */
+ pad_len = el->frotate_number_count;
+ sprintf(old_name, "%s.%0*d", el->fname, pad_len, i);
+ sprintf(new_name, "%s.%0*d", el->fname, pad_len, i - 1);
+ rename(old_name, new_name);
+
+ /* rename can fail, but it is usually because someone
+ * removed some logs, like there are logs: .1 .2 .4 .5,
+ * so .3 is missing, and if we want to rename .3 to .2,
+ * rename will fail, it doesn't really matter, as .4
+ * will be renamed to .3, and after full loop there
+ * will be .0 .1 .3 .4 .5 and after one more rotation,
+ * we'll have .0 .1 .2 .3 .4 .5, so full complet. So
+ * such situation will heal by itself over time. */
+ }
+ }
skip_rotate:
- /* now we can safely open file with suffix .n, we're sure we
- * won't overwrite anything (well except if someone sets
- * frotate_number to 1, then current .0 file will be
- * truncated). We don't need to check for length of created
- * file, as it is checked in el_file_open and if it passes
- * there, it will pass here as well
- */
-
- sprintf(el->fcurrent_log, "%s.%0*d", el->fname,
- el->frotate_number_count, el->fcurrent_rotate);
-
- if ((el->file = fopen(el->fcurrent_log, "w")) == NULL)
- {
- el->fcurrent_rotate--;
- return -1;
- }
-
- el_symlink_to_newest_log(el);
- el->fpos = 0;
-
- return 0;
+ /* now we can safely open file with suffix .n, we're sure we
+ * won't overwrite anything (well except if someone sets
+ * frotate_number to 1, then current .0 file will be
+ * truncated). We don't need to check for length of created
+ * file, as it is checked in el_file_open and if it passes
+ * there, it will pass here as well */
+ sprintf(el->fcurrent_log, "%s.%0*d", el->fname,
+ el->frotate_number_count, el->fcurrent_rotate);
+
+ if ((el->file = fopen(el->fcurrent_log, "w")) == NULL)
+ {
+ el->fcurrent_rotate--;
+ return -1;
+ }
+
+ el_symlink_to_newest_log(el);
+ el->fpos = 0;
+
+ return 0;
}
@@ -321,241 +298,201 @@ skip_rotate:
int el_file_open
(
- struct el *el /* el object with file information */
+ struct el *el /* el object with file information */
)
{
- /* we need current_log filename for ourself - we modify its
- * last digit when we rotate file. In theory this could be
- * done in struct declaration, but PATH_MAX is such a waste
- * of memory and programs usually do not get even close to
- * that ammount. Allocate enough memory for fname and max
- * of 5 digits for rotate + null character
- *
- * realloc needs to be done each time open() is called, in
- * case log file is being changed via EL_FPATH option.
- */
- el->fcurrent_log = realloc(el->fcurrent_log, strlen(el->fname) + 6);
- if (el->fcurrent_log == NULL)
- {
- errno = ENOMEM;
- return -1;
- }
-
- if (el->file)
- {
- /* to prevent any memory leak in case of double open, we
- * first close already opened file Such situation may
- * happen when library user changes file name using
- * EL_FPATH option,
- */
-
- fclose(el->file);
- el->file = NULL;
- }
-
- if (el->frotate_number)
- {
- FILE *f; /* opened file */
- int i; /* simple interator for loop */
- size_t pathl; /* length of path after snprintf */
- long fsize; /* size of the opened file */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- /* file rotation is enabled, in such case we need to find,
- * oldest rotate file, as app could have been restarted,
- * and we surely don't want to overwrite the newest file.
- * Oldest file has suffix .0 while the newest one has
- * suffix .${frotate_number} (or less if there are less
- * files).
- *
- * Reason for such order is so user could do `cat logs.*`
- * and in result concatenate all logs in order.
- */
-
- for (i = el->frotate_number - 1; i >= 0; --i)
- {
- pathl = snprintf(el->fcurrent_log, strlen(el->fname) + 6,
- "%s.%0*d", el->fname, el->frotate_number_count, i);
-
- if (pathl > PATH_MAX)
- {
- /* path is too long, we cannot safely create file
- * with suffix, return error as opening such
- * truncated file name could result in some data
- * lose on the disk.
- */
-
- el->fcurrent_log[0] = '\0';
- errno = ENAMETOOLONG;
- return -1;
- }
+ size_t pathlen; /* length of log path */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ /* we need current_log filename for ourself - we modify its
+ * last digit when we rotate file. In theory this could be
+ * done in struct declaration, but PATH_MAX is such a waste
+ * of memory and programs usually do not get even close to
+ * that ammount. Allocate enough memory for fname and max
+ * of 5 digits for rotate + null character */
+ pathlen = strlen(el->fname) + 6;
+
+ /* realloc needs to be done each time open() is called, in
+ * case log file is being changed via EL_FPATH option. */
+ el->fcurrent_log = realloc(el->fcurrent_log, pathlen);
+ VALID(ENOMEM, el->fcurrent_log != NULL)
+
+ if (el->file)
+ {
+ /* to prevent any memory leak in case of double open, we
+ * first close already opened file Such situation may
+ * happen when library user changes file name using
+ * EL_FPATH option, */
+ fclose(el->file);
+ el->file = NULL;
+ }
+
+ if (el->frotate_number)
+ {
+ FILE *f; /* opened file */
+ int i; /* simple interator for loop */
+ size_t pathl; /* length of path after snprintf */
+ long fsize; /* size of the opened file */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ /* file rotation is enabled, in such case we need to find,
+ * oldest rotate file, as app could have been restarted,
+ * and we surely don't want to overwrite the newest file.
+ * Oldest file has suffix .0 while the newest one has
+ * suffix .${frotate_number} (or less if there are less
+ * files).
+ *
+ * Reason for such order is so user could do `cat logs.*`
+ * and in result concatenate all logs in order. */
+
+ for (i = el->frotate_number - 1; i >= 0; --i)
+ {
+ pathl = snprintf(el->fcurrent_log, pathlen, "%s.%0*d",
+ el->fname, el->frotate_number_count, i);
+
+ if (pathl > PATH_MAX)
+ {
+ /* path is too long, we cannot safely create file
+ * with suffix, return error as opening such
+ * truncated file name could result in some data
+ * lose on the disk. */
+ el->fcurrent_log[0] = '\0';
+ errno = ENAMETOOLONG;
+ return -1;
+ }
#if HAVE_STAT
- if (i != 0)
- {
- struct stat st; /* file information */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- /* if i is 0, then this is last file to check
- * (there are no logs from embed log in directory)
- * and there is no need to check if file exists or
- * not - we open it unconditionally, thus this path
- * is not taken in such case.
- */
-
- if (el_file_exists(el->fcurrent_log) == 0)
- {
- /* current log file does not exist, this is not
- * the file you are looking for
- */
-
- continue;
- }
-
- if (stat(el->fcurrent_log, &st) != 0)
- {
- /* error while stating file, probably don't
- * have access to that file, or directory, or
- * whatever, something bad has happend and we
- * don't want to pursue this, exit with error
- * from stat.
- */
-
- el->fcurrent_log[0] = '\0';
- return -1;
- }
-
- if (st.st_size == 0)
- {
- /* there is an empty file, maybe we created it
- * and then crashed? Or maybe someone is trying
- * to pull our legs and drops bombs under our
- * feets. Either way, this is definitely not
- * oldest file. We also remove it so it doesn't
- * botter us later
- */
-
- remove(el->fcurrent_log);
- continue;
- }
- }
-
- /* we got our file, let's open it for writing and let's
- * call it a day
- */
-
- if ((f = fopen(el->fcurrent_log, "a")) == NULL)
- {
- /* couldn't open file, probably directory doesn't
- * exist, or we have no permissions to create file
- * here
- */
-
- return -1;
- }
-
- /* we need to check for currently opened file size once
- * again, as if i equal 0 here, we never called stat()
- * on our file and we don't know the size of it
- */
-
- fseek(f, 0, SEEK_END);
- fsize = ftell(f);
+ /* if i is 0, then this is last file to check
+ * (there are no logs from embed log in directory)
+ * and there is no need to check if file exists or
+ * not - we open it unconditionally, thus this path
+ * is not taken in such case. */
+ if (i != 0)
+ {
+ struct stat st; /* file information */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ /* current log file does not exist, this is not
+ * the file you are looking for */
+ if (el_file_exists(el->fcurrent_log) == 0) continue;
+
+ if (stat(el->fcurrent_log, &st) != 0)
+ {
+ /* error while stating file, probably don't
+ * have access to that file, or directory, or
+ * whatever, something bad has happend and we
+ * don't want to pursue this, exit with error
+ * from stat. */
+ el->fcurrent_log[0] = '\0';
+ return -1;
+ }
+
+ if (st.st_size == 0)
+ {
+ /* there is an empty file, maybe we created it
+ * and then crashed? Or maybe someone is trying
+ * to pull our legs and drops bombs under our
+ * feets. Either way, this is definitely not
+ * oldest file. We also remove it so it doesn't
+ * bother us later */
+ remove(el->fcurrent_log);
+ continue;
+ }
+ }
+
+ /* we got our file, let's open it for writing and let's
+ * call it a day */
+
+ /* couldn't open file, probably directory doesn't
+ * exist, or we have no permissions to create file
+ * here */
+ if ((f = fopen(el->fcurrent_log, "a")) == NULL) return -1;
+
+ /* we need to check for currently opened file size once
+ * again, as if i equal 0 here, we never called stat()
+ * on our file and we don't know the size of it */
+ fseek(f, 0, SEEK_END);
+ fsize = ftell(f);
#else /* HAVE_STAT */
- if ((f = fopen(el->fcurrent_log, "a")) == NULL)
- {
- /* if we cannot open file, that means there is some
- * kind of error, like permision denied or system
- * is out of memory, it's pointless to continue
- */
-
- el->fcurrent_log[0] = '\0';
- return -1;
- }
-
- /* position returned by ftell is implementation
- * specific it can be either end or begin of file
- * (check stdio(3))
- */
-
- fseek(f, 0, SEEK_END);
-
- if (i == 0)
- {
- /* this is the last file we check, we don't check
- * for file size here, since even if this file is
- * empty, we are sure this is the oldest file.
- * File is already opened so, we simply return from
- * the function
- */
-
- el->fcurrent_rotate = i;
- el->fpos = ftell(f);
- el->file = f;
- return 0;
- }
-
- if ((fsize = ftell(f)) == 0)
- {
- /* we've created (or opened ) an empty file, this
- * means our file is not the oldest one, i.e. we
- * opened file .6 and oldest could be .3. We remove
- * this file and continue our search for the glory
- * file.
- */
-
- fclose(f);
- remove(el->fcurrent_log);
- continue;
- }
+ if ((f = fopen(el->fcurrent_log, "a")) == NULL)
+ {
+ /* if we cannot open file, that means there is some
+ * kind of error, like permision denied or system
+ * is out of memory, it's pointless to continue */
+ el->fcurrent_log[0] = '\0';
+ return -1;
+ }
+
+ /* position returned by ftell is implementation
+ * specific it can be either end or begin of file
+ * (check stdio(3)) */
+ fseek(f, 0, SEEK_END);
+
+ if (i == 0)
+ {
+ /* this is the last file we check, we don't check
+ * for file size here, since even if this file is
+ * empty, we are sure this is the oldest file.
+ * File is already opened so, we simply return from
+ * the function */
+ el->fcurrent_rotate = i;
+ el->fpos = ftell(f);
+ el->file = f;
+ return 0;
+ }
+
+ if ((fsize = ftell(f)) == 0)
+ {
+ /* we've created (or opened ) an empty file, this
+ * means our file is not the oldest one, i.e. we
+ * opened file .6 and oldest could be .3. We remove
+ * this file and continue our search for the glory
+ * file. */
+ fclose(f);
+ remove(el->fcurrent_log);
+ continue;
+ }
#endif /* HAVE_STAT */
-
- /* oldest file found, file is already opened so we
- * simply update symlink to newest log file and return.
- */
-
- el_symlink_to_newest_log(el);
- el->fcurrent_rotate = i;
- el->fpos = fsize;
- el->file = f;
- return 0;
- }
- }
-
- /* rotation is disabled, simply open file with append flag
- */
-
- if (strlen(el->fname) > PATH_MAX)
- {
- el->fcurrent_log[0] = '\0';
- errno = ENAMETOOLONG;
- return -1;
- }
-
- strcpy(el->fcurrent_log, el->fname);
-
- if ((el->file = fopen(el->fcurrent_log, "a")) == NULL)
- {
- /* we couldn't open file, but don't set clear
- * el->fcurrent_log, we will try to reopen this file each
- * time we print to file. This is usefull when user tries
- * to open log file in not-yet existing directory. Error is
- * of course returned to user is aware of this whole
- * situation
- */
-
- return -1;
- }
-
- fseek(el->file, 0, SEEK_END);
- el->fpos = ftell(el->file);
- return 0;
+ /* oldest file found, file is already opened so we
+ * simply update symlink to newest log file and return. */
+ el_symlink_to_newest_log(el);
+ el->fcurrent_rotate = i;
+ el->fpos = fsize;
+ el->file = f;
+ return 0;
+ }
+ }
+
+ /* rotation is disabled, simply open file with append flag */
+
+ if (strlen(el->fname) > pathlen)
+ {
+ /* path will not fit into our internal buffer */
+ el->fcurrent_log[0] = '\0';
+ errno = ENAMETOOLONG;
+ return -1;
+ }
+
+ strcpy(el->fcurrent_log, el->fname);
+
+ /* in case we couldn't open file, don't set clear
+ * el->fcurrent_log - we will try to reopen this file each time
+ * we print to file. This is usefull when user tries to open
+ * log file in not-yet existing directory. Error is of course
+ * returned to user is aware of this whole situation */
+ if ((el->file = fopen(el->fcurrent_log, "a")) == NULL) return -1;
+
+ fseek(el->file, 0, SEEK_END);
+ el->fpos = ftell(el->file);
+ return 0;
}
@@ -567,103 +504,76 @@ int el_file_open
int el_file_flush
(
- struct el *el /* printing options */
+ struct el *el /* printing options */
)
{
- /* file store operation has particular issue. You can like,
- * write hundreds of megabytes into disk and that data indeed
- * will land into your block device *but* metadata will not!
- * That is if power lose occurs (even after those hundreds of
- * megs), file metadata might not be updated and we will lose
- * whole, I say it again *whole* file. To prevent data lose on
- * power down we try to sync file and its metadata to block
- * device. We do this every configured "sync_every" field since
- * syncing every single write would simply kill performance -
- * its up to user to decide how much data he is willing to
- * lose. It is also possible that altough we sync our file and
- * metadata, parent directory might not get flushed and there
- * will not be entry for our file - meaning file will be lost
- * too, but such situations are ultra rare and there isn't
- * really much we can do about it here but praying.
- */
+ /* file store operation has particular issue. You can like,
+ * write hundreds of megabytes into disk and that data indeed
+ * will land into your block device *but* metadata will not!
+ * That is if power lose occurs (even after those hundreds of
+ * megs), file metadata might not be updated and we will lose
+ * whole, I say it again *whole* file. To prevent data lose on
+ * power down we try to sync file and its metadata to block
+ * device. We do this every configured "sync_every" field since
+ * syncing every single write would simply kill performance -
+ * its up to user to decide how much data he is willing to
+ * lose. It is also possible that altough we sync our file and
+ * metadata, parent directory might not get flushed and there
+ * will not be entry for our file - meaning file will be lost
+ * too, but such situations are ultra rare and there isn't
+ * really much we can do about it here but praying.
+ */
#if HAVE_FSYNC && HAVE_FILENO
- int fd; /* systems file descriptor for el->file */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int fd; /* systems file descriptor for el->file */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#endif /* HAVE_FSYNC && HAVE_FILENO */
- VALID(EINVAL, el);
- VALID(EBADF, el->fcurrent_log);
- VALID(EBADF, el->fcurrent_log[0] != '\0');
-
- if (el->fwritten_after_sync == 0)
- {
- /* if now writes have been performed between consecutive
- * flush, then don't flush - since there is nothing to
- * flush anyway
- */
-
- return 0;
- }
+ VALID(EINVAL, el);
+ VALID(EBADF, el->fcurrent_log);
+ VALID(EBADF, el->fcurrent_log[0] != '\0');
- /* first flush data from stdio library buffers into kernel
- */
+ /* if no writes have been performed between consecutive
+ * flush, then don't flush - since there is nothing to
+ * flush anyway */
+ if (el->fwritten_after_sync == 0) return 0;
- if (fflush(el->file) != 0)
- {
- return -1;
- }
+ /* first flush data from stdio library buffers into kernel */
+ if (fflush(el->file) != 0) return -1;
#if HAVE_FSYNC && HAVE_FILENO
- /* and then sync data into block device
- */
-
- if ((fd = fileno(el->file)) < 0)
- {
- return -1;
- }
-
- if (fsync(fd) != 0)
- {
- return -1;
- }
+ /* and then sync data into block device */
+ if ((fd = fileno(el->file)) < 0) return -1;
+ if (fsync(fd) != 0) return -1;
#else /* HAVE_FSYNC && HAVE_FILENO */
- /* if system does not implement fileno and fsync our only hope
- * lies in closing (which should sync file to block device) and
- * then opening file again. Yup, performance will suck, but
- * hey, its about data safety!
- */
-
- fclose(el->file);
+ /* if system does not implement fileno and fsync our only hope
+ * lies in closing (which should sync file to block device) and
+ * then opening file again. Yup, performance will suck, but
+ * hey, its about data safety! */
+ fclose(el->file);
- if ((el->file = fopen(el->fcurrent_log, "a")) == NULL)
- {
- errno = EBADF;
- return -1;
- }
-
- fseek(el->file, 0, SEEK_END);
- el->fpos = ftell(el->file);
+ el->file = fopen(el->fcurrent_log, "a");
+ VALID(EBADF, el->file);
+ fseek(el->file, 0, SEEK_END);
+ el->fpos = ftell(el->file);
#endif /* HAVE_FSYNC && HAVE_FILENO */
#ifdef RUN_TESTS
- file_synced = 1;
+ file_synced = 1;
#endif /* RUN_TESTS */
- /* after syncing data, update written after sync field, so we
- * don't trigger another flush right after this one
- */
-
- el->fwritten_after_sync = 0;
- return 0;
+ /* after syncing data, update written after sync field, so we
+ * don't trigger another flush right after this one */
+ el->fwritten_after_sync = 0;
+ return 0;
}
@@ -675,80 +585,55 @@ int el_file_flush
int el_file_putb
(
- struct el *el, /* printing el */
- const void *mem, /* memory to 'put' into file */
- size_t mlen /* size of buffer 'mlen' */
-
+ struct el *el, /* printing el */
+ const void *mem, /* memory to 'put' into file */
+ size_t mlen /* size of buffer 'mlen' */
)
{
- VALID(EINVAL, mem);
- VALID(EINVAL, mlen);
- VALID(EINVAL, el);
- VALID(EBADF, el->fcurrent_log);
- VALID(EBADF, el->fcurrent_log[0] != '\0');
-
-
- /* we need to reopen our file if it wasn't opened yet, or was
- * removed due to error or deliberate acion of user
- */
-
- if (el_file_exists(el->fcurrent_log) == 0 || el->file == NULL)
- {
- if (el_file_open(el) != 0)
- {
- return -1;
- }
- }
-
- if (el->frotate_number)
- {
- if (el->fpos != 0 && el->fpos + mlen > el->frotate_size)
- {
- /* we get here only when frotate is enabled, and
- * writing to current file would result in exceding
- * frotate_size of file. In such case we rotate the
- * file by closing the old one and opening new file,
- * and if we already filled frotate_number files, we
- * remove the oldest one.
- */
-
- if (el_file_rotate(el) != 0)
- {
- return -1;
- }
- }
-
- if (mlen > el->frotate_size)
- {
- /* we can't fit message even in an empty file, in such
- * case we need to truncate log, so we don't create
- * file bigger than configured frotate_size
- */
-
- mlen = el->frotate_size;
- }
- }
-
- if (fwrite(mem, mlen, 1, el->file) != 1)
- {
- return -1;
- }
-
- el->fpos += mlen;
- el->fwritten_after_sync += mlen;
-
- if (el->fwritten_after_sync >= el->fsync_every ||
- el->level_current_msg <= el->fsync_level)
- {
- /* we either written enough bytes to trigger flush, or log
- * level is high enough it triggers log flush to block
- * device
- */
-
- return el_file_flush(el);
- }
-
- return 0;
+ VALID(EINVAL, mem);
+ VALID(EINVAL, mlen);
+ VALID(EINVAL, el);
+ VALID(EBADF, el->fcurrent_log);
+ VALID(EBADF, el->fcurrent_log[0] != '\0');
+
+
+ /* we need to reopen our file if it wasn't opened yet, or was
+ * removed due to error or deliberate acion of user */
+ if (el_file_exists(el->fcurrent_log) == 0 || el->file == NULL)
+ if (el_file_open(el) != 0)
+ return -1;
+
+ if (el->frotate_number)
+ {
+ /* we get here only when frotate is enabled. check if
+ * writing to current file would result in exceding
+ * frotate_size of file. if so we rotate the file by
+ * closing the old one and opening new file, and if we
+ * already filled frotate_number files, we remove the
+ * oldest one. */
+ if (el->fpos != 0 && el->fpos + mlen > el->frotate_size)
+ if (el_file_rotate(el) != 0)
+ return -1;
+
+ /* if we can't fit message even in an empty file, we need
+ * to truncate log, so we don't create file bigger than
+ * configured frotate_size */
+ if (mlen > el->frotate_size)
+ mlen = el->frotate_size;
+ }
+
+ if (fwrite(mem, mlen, 1, el->file) != 1) return -1;
+ el->fpos += mlen;
+ el->fwritten_after_sync += mlen;
+
+ /* flush logs to block device if we've written enough bytes
+ * user configured in sync_every or log level is sever enough
+ * to trigger flush. */
+ if (el->fwritten_after_sync >= el->fsync_every ||
+ el->level_current_msg <= el->fsync_level)
+ return el_file_flush(el);
+
+ return 0;
}
@@ -759,16 +644,16 @@ int el_file_putb
int el_file_puts
(
- struct el *el, /* printing options */
- const char *s /* string to 'put' into file */
+ struct el *el, /* printing options */
+ const char *s /* string to 'put' into file */
)
{
- size_t slen; /* size of string 's' */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ size_t slen; /* size of string 's' */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- slen = strlen(s);
- return el_file_putb(el, (unsigned char *)s, slen);
+ slen = strlen(s);
+ return el_file_putb(el, (unsigned char *)s, slen);
}
@@ -779,20 +664,16 @@ int el_file_puts
void el_file_cleanup
(
- struct el *el /* file options */
+ struct el *el /* file options */
)
{
- if (el->file)
- {
- fclose(el->file);
- }
-
- el->file = NULL;
-
- if (el->fcurrent_log)
- {
- el->fcurrent_log[0] = '\0';
- free(el->fcurrent_log);
- el->fcurrent_log = NULL;
- }
+ if (el->file) fclose(el->file);
+ el->file = NULL;
+
+ if (el->fcurrent_log)
+ {
+ el->fcurrent_log[0] = '\0';
+ free(el->fcurrent_log);
+ el->fcurrent_log = NULL;
+ }
}
diff --git a/src/el-flush.c b/src/el-flush.c
index cf1ccc5..f8b0e6f 100644
--- a/src/el-flush.c
+++ b/src/el-flush.c
@@ -47,10 +47,10 @@
/* public api */ int el_flush
(
- void
+ void
)
{
- return el_oflush(&g_el);
+ return el_oflush(&g_el);
}
@@ -61,47 +61,35 @@
/* public api */ int el_oflush
(
- struct el *el /* options defining printing style */
+ struct el *el /* options defining printing style */
)
{
- int rv; /* return value from function */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int rv; /* return value from function */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- VALID(EINVAL, el);
- el_lock(el);
- VALIDC(ENODEV, el->outputs != 0, el_unlock(el));
+ VALID(EINVAL, el);
+ el_lock(el);
+ VALIDC(ENODEV, el->outputs != 0, el_unlock(el));
- rv = 0;
+ rv = 0;
#if ENABLE_OUT_STDERR
- if (el->outputs & EL_OUT_STDERR)
- {
- rv |= fflush(stderr);
- }
+ if (el->outputs & EL_OUT_STDERR) rv |= fflush(stderr);
#endif
#if ENABLE_OUT_STDERR
- if (el->outputs & EL_OUT_STDOUT)
- {
- rv |= fflush(stdout);
- }
+ if (el->outputs & EL_OUT_STDOUT) rv |= fflush(stdout);
#endif
#if ENABLE_OUT_FILE
- if (el->outputs & EL_OUT_FILE)
- {
- rv |= el_file_flush(el);
- }
+ if (el->outputs & EL_OUT_FILE) rv |= el_file_flush(el);
#endif
#if 0
- if (el->outputs & EL_OUT_NET)
- {
- el_net_flush(el);
- }
+ if (el->outputs & EL_OUT_NET) el_net_flush(el);
#endif
- el_unlock(el);
- return rv;
+ el_unlock(el);
+ return rv;
}
diff --git a/src/el-lock.c b/src/el-lock.c
index 3ec91ca..276594a 100644
--- a/src/el-lock.c
+++ b/src/el-lock.c
@@ -43,13 +43,10 @@
void el_lock
(
- struct el *el /* el object to lock */
+ struct el *el /* el object to lock */
)
{
- if (el->lock_initialized)
- {
- pthread_mutex_lock(&el->lock);
- }
+ if (el->lock_initialized) pthread_mutex_lock(&el->lock);
}
@@ -61,11 +58,8 @@ void el_lock
void el_unlock
(
- struct el *el /* el object to unlock */
+ struct el *el /* el object to unlock */
)
{
- if (el->lock_initialized)
- {
- pthread_mutex_unlock(&el->lock);
- }
+ if (el->lock_initialized) pthread_mutex_unlock(&el->lock);
}
diff --git a/src/el-options.c b/src/el-options.c
index 200e4b6..dd802de 100644
--- a/src/el-options.c
+++ b/src/el-options.c
@@ -62,33 +62,33 @@ struct el g_el;
static const int VALID_OUTS = 0
#if ENABLE_OUT_STDERR
- | EL_OUT_STDERR
+ | EL_OUT_STDERR
#endif
#if ENABLE_OUT_STDERR
- | EL_OUT_STDOUT
+ | EL_OUT_STDOUT
#endif
#if ENABLE_OUT_SYSLOG
- | EL_OUT_SYSLOG
+ | EL_OUT_SYSLOG
#endif
#if ENABLE_OUT_FILE
- | EL_OUT_FILE
+ | EL_OUT_FILE
#endif
#if ENABLE_OUT_NET
- | EL_OUT_NET
+ | EL_OUT_NET
#endif
#if ENABLE_OUT_TTY
- | EL_OUT_TTY
+ | EL_OUT_TTY
#endif
#if ENABLE_OUT_CUSTOM
- | EL_OUT_CUSTOM
+ | EL_OUT_CUSTOM
#endif
- ;
+ ;
/* ==========================================================================
@@ -113,577 +113,553 @@ static const int VALID_OUTS = 0
static int el_vooption
(
- struct el *el, /* el object to set option to */
- enum el_option option, /* option to set */
- va_list ap /* option value(s) */
+ struct el *el, /* el object to set option to */
+ enum el_option option, /* option to set */
+ va_list ap /* option value(s) */
)
{
- int ret; /* return code from various functions */
- int value_int; /* ap value treated as integer */
- unsigned long value_ulong; /* ap value treated as unsigned long */
- const char *value_str; /* ap value treated as string */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int ret; /* return code from various functions */
+ int value_int; /* ap value treated as integer */
+ unsigned long value_ulong; /* ap value treated as unsigned long */
+ const char *value_str; /* ap value treated as string */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- VALID(EINVAL, 0 <= option && option < EL_OPT_ERROR);
+ VALID(EINVAL, 0 <= option && option < EL_OPT_ERROR);
- switch (option)
- {
- /* ==================================================================
- __ __
- / /___ _ __ ___ / /
- / // -_)| |/ // -_)/ /
- /_/ \__/ |___/ \__//_/
+ switch (option)
+ {
+ /* ==================================================================
+ __ __
+ / /___ _ __ ___ / /
+ / // -_)| |/ // -_)/ /
+ /_/ \__/ |___/ \__//_/
- ================================================================== */
+ ================================================================== */
- case EL_LEVEL:
- value_int = va_arg(ap, int);
- VALID(EINVAL, value_int <= 7);
- el_lock(el);
- el->level = value_int;
- el_unlock(el);
- return 0;
+ case EL_LEVEL:
+ value_int = va_arg(ap, int);
+ VALID(EINVAL, value_int <= 7);
+ el_lock(el);
+ el->level = value_int;
+ el_unlock(el);
+ return 0;
- /* ==================================================================
- ___ __ __
- / _/___ __ __ ___ ____ / /___ _ __ ___ / /
- / _/(_-</ // // _ \/ __/ / // -_)| |/ // -_)/ /
- /_/ /___/\_, //_//_/\__/ /_/ \__/ |___/ \__//_/
- /___/
- ================================================================== */
+ /* ==================================================================
+ ___ __ __
+ / _/___ __ __ ___ ____ / /___ _ __ ___ / /
+ / _/(_-</ // // _ \/ __/ / // -_)| |/ // -_)/ /
+ /_/ /___/\_, //_//_/\__/ /_/ \__/ |___/ \__//_/
+ /___/
+ ================================================================== */
# if ENABLE_OUT_FILE
- case EL_FSYNC_LEVEL:
- value_int = va_arg(ap, int);
- VALID(EINVAL, value_int <= 7);
- el_lock(el);
- el->fsync_level = value_int;
- el_unlock(el);
- return 0;
+ case EL_FSYNC_LEVEL:
+ value_int = va_arg(ap, int);
+ VALID(EINVAL, value_int <= 7);
+ el_lock(el);
+ el->fsync_level = value_int;
+ el_unlock(el);
+ return 0;
# endif /* ENABLE_OUT_FILE */
- /* ==================================================================
- __
- ___ __ __ / /_
- / _ \/ // // __/
- \___/\_,_/ \__/
+ /* ==================================================================
+ __
+ ___ __ __ / /_
+ / _ \/ // // __/
+ \___/\_,_/ \__/
- ================================================================== */
+ ================================================================== */
- case EL_OUT:
- value_int = va_arg(ap, int);
- value_int = value_int == EL_OUT_ALL ? VALID_OUTS : value_int;
- VALID(EINVAL, (value_int & ~ALL_OUTS) == 0x00);
- VALID(ENODEV, (value_int & ~VALID_OUTS) == 0x00);
- el_lock(el);
- el->outputs = value_int;
- el_unlock(el);
- return 0;
+ case EL_OUT:
+ value_int = va_arg(ap, int);
+ value_int = value_int == EL_OUT_ALL ? VALID_OUTS : value_int;
+ VALID(EINVAL, (value_int & ~ALL_OUTS) == 0x00);
+ VALID(ENODEV, (value_int & ~VALID_OUTS) == 0x00);
+ el_lock(el);
+ el->outputs = value_int;
+ el_unlock(el);
+ return 0;
- /* ==================================================================
- _ __ __ __
- ___ ____ (_)___ / /_ / /___ _ __ ___ / /
- / _ \ / __// // _ \/ __/ / // -_)| |/ // -_)/ /
- / .__//_/ /_//_//_/\__/ /_/ \__/ |___/ \__//_/
- /_/
- ================================================================== */
+ /* ==================================================================
+ _ __ __ __
+ ___ ____ (_)___ / /_ / /___ _ __ ___ / /
+ / _ \ / __// // _ \/ __/ / // -_)| |/ // -_)/ /
+ / .__//_/ /_//_//_/\__/ /_/ \__/ |___/ \__//_/
+ /_/
+ ================================================================== */
- case EL_PRINT_LEVEL:
- value_int = va_arg(ap, int);
- VALID(EINVAL, (value_int & ~1) == 0);
+ case EL_PRINT_LEVEL:
+ value_int = va_arg(ap, int);
+ VALID(EINVAL, (value_int & ~1) == 0);
- el_lock(el);
- el->print_log_level = value_int;
- el_unlock(el);
- return 0;
+ el_lock(el);
+ el->print_log_level = value_int;
+ el_unlock(el);
+ return 0;
- /* ==================================================================
- _ __ __
- ___ ____ (_)___ / /_ ___ / /
- / _ \ / __// // _ \/ __/ / _ \ / /
- / .__//_/ /_//_//_/\__/ /_//_//_/
- /_/
- ================================================================== */
+ /* ==================================================================
+ _ __ __
+ ___ ____ (_)___ / /_ ___ / /
+ / _ \ / __// // _ \/ __/ / _ \ / /
+ / .__//_/ /_//_//_/\__/ /_//_//_/
+ /_/
+ ================================================================== */
- case EL_PRINT_NL:
- value_int = va_arg(ap, int);
- VALID(EINVAL, (value_int & ~1) == 0);
+ case EL_PRINT_NL:
+ value_int = va_arg(ap, int);
+ VALID(EINVAL, (value_int & ~1) == 0);
- el_lock(el);
- el->print_newline = value_int;
- el_unlock(el);
- return 0;
+ el_lock(el);
+ el->print_newline = value_int;
+ el_unlock(el);
+ return 0;
- /* ==================================================================
- ___ _
- ___ ____ ___ / _/(_)__ __
- / _ \ / __// -_)/ _// / \ \ /
- / .__//_/ \__//_/ /_/ /_\_\
- /_/
- ================================================================== */
+ /* ==================================================================
+ ___ _
+ ___ ____ ___ / _/(_)__ __
+ / _ \ / __// -_)/ _// / \ \ /
+ / .__//_/ \__//_/ /_/ /_\_\
+ /_/
+ ================================================================== */
# if ENABLE_PREFIX
- case EL_PREFIX:
- value_str = va_arg(ap, const char *);
- el_lock(el);
- el->prefix = value_str;
- el_unlock(el);
- return 0;
+ case EL_PREFIX:
+ value_str = va_arg(ap, const char *);
+ el_lock(el);
+ el->prefix = value_str;
+ el_unlock(el);
+ return 0;
# endif /* ENABLE_PREFIX */
- /* ==================================================================
- __
- ____ ___ / /___ ____ ___
- / __// _ \ / // _ \ / __/(_-<
- \__/ \___//_/ \___//_/ /___/
+ /* ==================================================================
+ __
+ ____ ___ / /___ ____ ___
+ / __// _ \ / // _ \ / __/(_-<
+ \__/ \___//_/ \___//_/ /___/
- ================================================================== */
+ ================================================================== */
# if ENABLE_COLORS
- case EL_COLORS:
- /*
- * only 1 or 0 is allowed, if any other bit is set return EINVAL
- */
+ case EL_COLORS:
+ /* only 1 or 0 is allowed, if any other bit is set return EINVAL */
- value_int = va_arg(ap, int);
- VALID(EINVAL, (value_int & ~1) == 0);
+ value_int = va_arg(ap, int);
+ VALID(EINVAL, (value_int & ~1) == 0);
- el_lock(el);
- el->colors = value_int;
- el_unlock(el);
- return 0;
+ el_lock(el);
+ el->colors = value_int;
+ el_unlock(el);
+ return 0;
# endif /* ENABLE_COLORS */
- /* ==================================================================
- __
- / /_ ___
- / __/(_-<
- \__//___/
+ /* ==================================================================
+ __
+ / /_ ___
+ / __/(_-<
+ \__//___/
- ================================================================== */
+ ================================================================== */
# if ENABLE_TIMESTAMP
- case EL_TS:
- value_int = va_arg(ap, int);
- VALID(EINVAL, 0 <= value_int && value_int < EL_TS_ERROR);
+ case EL_TS:
+ value_int = va_arg(ap, int);
+ VALID(EINVAL, 0 <= value_int && value_int < EL_TS_ERROR);
- el_lock(el);
- el->timestamp = value_int;
- el_unlock(el);
- return 0;
+ el_lock(el);
+ el->timestamp = value_int;
+ el_unlock(el);
+ return 0;
- /* ==================================================================
- __ ___ __
- / /_ ___ / _/____ ___ _ ____ / /_
- / __/(_-< / _// __// _ `// __// __/
- \__//___/ /_/ /_/ \_,_/ \__/ \__/
+ /* ==================================================================
+ __ ___ __
+ / /_ ___ / _/____ ___ _ ____ / /_
+ / __/(_-< / _// __// _ `// __// __/
+ \__//___/ /_/ /_/ \_,_/ \__/ \__/
- ================================================================== */
+ ================================================================== */
# if ENABLE_FRACTIONS
- case EL_TS_FRACT:
- value_int = va_arg(ap, int);
- VALID(EINVAL, 0 <= value_int && value_int < EL_TS_FRACT_ERROR);
+ case EL_TS_FRACT:
+ value_int = va_arg(ap, int);
+ VALID(EINVAL, 0 <= value_int && value_int < EL_TS_FRACT_ERROR);
- el_lock(el);
- el->timestamp_fractions = value_int;
- el_unlock(el);
- return 0;
+ el_lock(el);
+ el->timestamp_fractions = value_int;
+ el_unlock(el);
+ return 0;
# endif /* ENABLE_FRACTIONS */
- /* ==================================================================
- __ __
- / /_ ___ / /_ __ _
- / __/(_-< / __// ' \
- \__//___/ \__//_/_/_/
+ /* ==================================================================
+ __ __
+ / /_ ___ / /_ __ _
+ / __/(_-< / __// ' \
+ \__//___/ \__//_/_/_/
- ================================================================== */
+ ================================================================== */
- case EL_TS_TM:
- value_int = va_arg(ap, int);
- VALID(EINVAL, 0 <= value_int && value_int < EL_TS_TM_ERROR);
+ case EL_TS_TM:
+ value_int = va_arg(ap, int);
+ VALID(EINVAL, 0 <= value_int && value_int < EL_TS_TM_ERROR);
# if ENABLE_REALTIME == 0
- VALID(ENODEV, value_int != EL_TS_TM_REALTIME);
+ VALID(ENODEV, value_int != EL_TS_TM_REALTIME);
# endif
# if ENABLE_MONOTONIC == 0
- VALID(ENODEV, value_int != EL_TS_TM_MONOTONIC);
+ VALID(ENODEV, value_int != EL_TS_TM_MONOTONIC);
# endif
# if ENABLE_CLOCK == 0
- VALID(ENODEV, value_int != EL_TS_TM_CLOCK);
+ VALID(ENODEV, value_int != EL_TS_TM_CLOCK);
# endif
- el_lock(el);
- el->timestamp_timer = value_int;
- el_unlock(el);
- return 0;
+ el_lock(el);
+ el->timestamp_timer = value_int;
+ el_unlock(el);
+ return 0;
# endif /* ENABLE_TIMESTAMP */
- /* ==================================================================
- ___ _ ___
- / _/(_)___ / _/___
- / _// // _ \ / _// _ \
- /_/ /_//_//_//_/ \___/
+ /* ==================================================================
+ ___ _ ___
+ / _/(_)___ / _/___
+ / _// // _ \ / _// _ \
+ /_/ /_//_//_//_/ \___/
- ================================================================== */
+ ================================================================== */
# if ENABLE_FINFO
- case EL_FINFO:
- value_int = va_arg(ap, int);
- VALID(EINVAL, (value_int & ~1) == 0);
+ case EL_FINFO:
+ value_int = va_arg(ap, int);
+ VALID(EINVAL, (value_int & ~1) == 0);
- el_lock(el);
- el->finfo = value_int;
- el_unlock(el);
- return 0;
+ el_lock(el);
+ el->finfo = value_int;
+ el_unlock(el);
+ return 0;
# endif /* ENABLE_FINFO */
- /* ==================================================================
- ___ _ ___
- / _/__ __ ___ ____ (_)___ / _/___
- / _// // // _ \/ __// // _ \ / _// _ \
- /_/ \_,_//_//_/\__//_//_//_//_/ \___/
+ /* ==================================================================
+ ___ _ ___
+ / _/__ __ ___ ____ (_)___ / _/___
+ / _// // // _ \/ __// // _ \ / _// _ \
+ /_/ \_,_//_//_/\__//_//_//_//_/ \___/
- ================================================================== */
+ ================================================================== */
# if ENABLE_FUNCINFO
- case EL_FUNCINFO:
+ case EL_FUNCINFO:
# if (__STDC_VERSION__ < 199901L)
- /* funcinfo is only supported on c99 compilers
- */
-
- errno = ENOSYS;
- return -1;
+ /* funcinfo is only supported on c99 compilers */
+ errno = ENOSYS;
+ return -1;
# else /* __STDC_VERSION__ < 199901L */
- value_int = va_arg(ap, int);
- VALID(EINVAL, (value_int & ~1) == 0);
+ value_int = va_arg(ap, int);
+ VALID(EINVAL, (value_int & ~1) == 0);
- el_lock(el);
- el->funcinfo = value_int;
- el_unlock(el);
- return 0;
+ el_lock(el);
+ el->funcinfo = value_int;
+ el_unlock(el);
+ return 0;
# endif /* __STDC_VERSION__ < 199901L */
# endif /* ENABLE_FUNCINFO */
- /* ==================================================================
- ___ __ __
- / _/___ ___ _ / /_ / /
- / _// _ \/ _ `// __// _ \
- /_/ / .__/\_,_/ \__//_//_/
- /_/
- ================================================================== */
+ /* ==================================================================
+ ___ __ __
+ / _/___ ___ _ / /_ / /
+ / _// _ \/ _ `// __// _ \
+ /_/ / .__/\_,_/ \__//_//_/
+ /_/
+ ================================================================== */
# if ENABLE_OUT_FILE
- case EL_FPATH:
- value_str = va_arg(ap, const char *);
- VALID(EINVAL, value_str);
- el_lock(el);
- el->fname = value_str;
- ret = el_file_open(el);
- el_unlock(el);
- return ret;
-
-
- /* ==================================================================
- ___ __ __ __
- / _/____ ___ / /_ ___ _ / /_ ___ ___ __ __ __ _ / / ___ ____
- / _// __// _ \/ __// _ `// __// -_) / _ \/ // // ' \ / _ \/ -_)/ __/
- /_/ /_/ \___/\__/ \_,_/ \__/ \__/ /_//_/\_,_//_/_/_//_.__/\__//_/
+ case EL_FPATH:
+ value_str = va_arg(ap, const char *);
+ VALID(EINVAL, value_str);
+ el_lock(el);
+ el->fname = value_str;
+ ret = el_file_open(el);
+ el_unlock(el);
+ return ret;
+
- ================================================================== */
+ /* ==================================================================
+ ___ __ __ __
+ / _/____ ___ / /_ ___ _ / /_ ___ ___ __ __ __ _ / / ___ ____
+ / _// __// _ \/ __// _ `// __// -_) / _ \/ // // ' \ / _ \/ -_)/ __/
+ /_/ /_/ \___/\__/ \_,_/ \__/ \__/ /_//_/\_,_//_/_/_//_.__/\__//_/
+ ================================================================== */
- case EL_FROTATE_NUMBER:
- {
- int previous_frotate; /* previous value of frotate number */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ case EL_FROTATE_NUMBER:
+ {
+ int previous_frotate; /* previous value of frotate number */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- value_int = va_arg(ap, int);
- VALID(EINVAL, 0 <= value_int && value_int <= USHRT_MAX);
- el_lock(el);
- previous_frotate = el->frotate_number;
- el->frotate_number = (unsigned short)value_int;
- if (value_int > 0)
- {
- /* count number of digits in value_int */
- value_int--;
- el->frotate_number_count = 1;
- while ((value_int /= 10))
- el->frotate_number_count++;
- }
+ value_int = va_arg(ap, int);
+ VALID(EINVAL, 0 <= value_int && value_int <= USHRT_MAX);
+ el_lock(el);
+ previous_frotate = el->frotate_number;
+ el->frotate_number = (unsigned short)value_int;
+ ret = 0;
- ret = 0;
- if (previous_frotate == 0 && el->file)
- {
- /* user turned on file rotation when file is already
- * opened without rotation. To prevent weird situations
- * and even data loss, we reopen file as opening with
- * log rotation is a bit different. el_file_open()
- * function will close file before reopening
- */
+ if (value_int > 0)
+ {
+ /* count number of digits in value_int */
+ value_int--;
+ el->frotate_number_count = 1;
+ while ((value_int /= 10)) el->frotate_number_count++;
+ }
- ret = el_file_open(el);
- }
+ /* if user turned on file rotation when file is already
+ * opened without rotation then to prevent weird situations
+ * and even data loss, we reopen file as opening with log
+ * rotation is a bit different. el_file_open() function
+ * will close file before reopening */
+ if (previous_frotate == 0 && el->file) ret = el_file_open(el);
- el_unlock(el);
- return ret;
- }
+ el_unlock(el);
+ return ret;
+ }
- /* ==================================================================
- ___ __ __ _
- / _/____ ___ / /_ ___ _ / /_ ___ ___ (_)___ ___
- / _// __// _ \/ __// _ `// __// -_) (_-< / //_ // -_)
- /_/ /_/ \___/\__/ \_,_/ \__/ \__/ /___//_/ /__/\__/
+ /* ==================================================================
+ ___ __ __ _
+ / _/____ ___ / /_ ___ _ / /_ ___ ___ (_)___ ___
+ / _// __// _ \/ __// _ `// __// -_) (_-< / //_ // -_)
+ /_/ /_/ \___/\__/ \_,_/ \__/ \__/ /___//_/ /__/\__/
- ================================================================== */
+ ================================================================== */
- case EL_FROTATE_SIZE:
- value_ulong = va_arg(ap, unsigned long);
- VALID(EINVAL, value_ulong >= 1);
- el_lock(el);
- el->frotate_size = value_ulong;
- el_unlock(el);
- return 0;
+ case EL_FROTATE_SIZE:
+ value_ulong = va_arg(ap, unsigned long);
+ VALID(EINVAL, value_ulong >= 1);
+ el_lock(el);
+ el->frotate_size = value_ulong;
+ el_unlock(el);
+ return 0;
- /* ==================================================================
- ___ __ __ __ _ __
- / _/____ ___ / /_ ___ _ / /_ ___ ___ __ __ __ _ / /(_)___ / /__
- / _// __// _ \/ __// _ `// __// -_) (_-</ // // ' \ / // // _ \ / '_/
- /_/ /_/ \___/\__/ \_,_/ \__/ \__/ /___/\_, //_/_/_//_//_//_//_//_/\_\
- /___/
- ================================================================== */
+ /* ==================================================================
+ ___ __ __ __ _ __
+ / _/____ ___ / /_ ___ _ / /_ ___ ___ __ __ __ _ / /(_)___ / /__
+ / _// __// _ \/ __// _ `// __// -_) (_-</ // // ' \ / // // _ \ / '_/
+ _/ /_/ \___/\__/ \_,_/ \__/ \__/ /___/\_, //_/_/_//_//_//_//_//_/\_\
+ /___/
+ ================================================================== */
- case EL_FROTATE_SYMLINK:
- value_int = va_arg(ap, int);
- VALID(EINVAL, (value_int & ~1) == 0);
+ case EL_FROTATE_SYMLINK:
+ value_int = va_arg(ap, int);
+ VALID(EINVAL, (value_int & ~1) == 0);
- el_lock(el);
- el->frotate_symlink = value_int;
- el_unlock(el);
- return 0;
+ el_lock(el);
+ el->frotate_symlink = value_int;
+ el_unlock(el);
+ return 0;
- /* ==================================================================
- ___
- / _/___ __ __ ___ ____ ___ _ __ ___ ____ __ __
- / _/(_-</ // // _ \/ __/ / -_)| |/ // -_)/ __// // /
- /_/ /___/\_, //_//_/\__/ \__/ |___/ \__//_/ \_, /
- /___/ /___/
- ================================================================== */
+ /* ==================================================================
+ ___
+ / _/___ __ __ ___ ____ ___ _ __ ___ ____ __ __
+ / _/(_-</ // // _ \/ __/ / -_)| |/ // -_)/ __// // /
+ /_/ /___/\_, //_//_/\__/ \__/ |___/ \__//_/ \_, /
+ /___/ /___/
+ ================================================================== */
- case EL_FSYNC_EVERY:
- value_ulong = va_arg(ap, unsigned long);
- VALID(EINVAL, value_ulong >= 0);
- el_lock(el);
- el->fsync_every = value_ulong;
- el_unlock(el);
- return 0;
+ case EL_FSYNC_EVERY:
+ value_ulong = va_arg(ap, unsigned long);
+ VALID(EINVAL, value_ulong >= 0);
+ el_lock(el);
+ el->fsync_every = value_ulong;
+ el_unlock(el);
+ return 0;
# endif /* ENABLE_OUT_FILE */
- /* ==================================================================
- __ __ __
- / /_ / /_ __ __ ___/ /___ _ __
- / __// __// // / / _ // -_)| |/ /
- \__/ \__/ \_, / \_,_/ \__/ |___/
- /___/
- ================================================================== */
+ /* ==================================================================
+ __ __ __
+ / /_ / /_ __ __ ___/ /___ _ __
+ / __// __// // / / _ // -_)| |/ /
+ \__/ \__/ \_, / \_,_/ \__/ |___/
+ /___/
+ ================================================================== */
# if ENABLE_OUT_TTY
- case EL_TTY_DEV:
- {
- unsigned int speed;
+ case EL_TTY_DEV:
+ {
+ unsigned int speed;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- value_str = va_arg(ap, const char *); /* serial tty to open */
- speed = va_arg(ap, unsigned int);
- VALID(EINVAL, value_str);
+ value_str = va_arg(ap, const char *); /* serial tty to open */
+ speed = va_arg(ap, unsigned int);
- el_lock(el);
- ret = el_tty_open(el, value_str, speed);
- el_unlock(el);
- return ret;
- }
+ VALID(EINVAL, value_str);
+
+ el_lock(el);
+ ret = el_tty_open(el, value_str, speed);
+ el_unlock(el);
+ return ret;
+ }
# endif /* ENABLE_OUT_TTY */
- /* ==================================================================
- __ __
- ____ __ __ ___ / /_ ___ __ _ ___ __ __ / /_ ___
- / __// // /(_-</ __// _ \ / ' \ / _ \/ // // __/(_-<
- \__/ \_,_//___/\__/ \___//_/_/_/ / .__/\_,_/ \__//___/
- /_/
- ================================================================== */
+ /* ==================================================================
+ __ __
+ ____ __ __ ___ / /_ ___ __ _ ___ __ __ / /_ ___
+ / __// // /(_-</ __// _ \ / ' \ / _ \/ // // __/(_-<
+ \__/ \_,_//___/\__/ \___//_/_/_/ / .__/\_,_/ \__//___/
+ /_/
+ ================================================================== */
# if ENABLE_OUT_CUSTOM
- case EL_CUSTOM_PUTS:
- el_lock(el);
- el->custom_put = va_arg(ap, el_custom_put);
- el->custom_put_user = va_arg(ap, void *);
- el_unlock(el);
- return 0;
+ case EL_CUSTOM_PUTS:
+ el_lock(el);
+ el->custom_put = va_arg(ap, el_custom_put);
+ el->custom_put_user = va_arg(ap, void *);
+ el_unlock(el);
+ return 0;
# endif /* ENABLE_OUT_CUSTOM */
- /* ==================================================================
- __ __ __ ___
- / /_ / / ____ ___ ___ _ ___/ / ___ ___ _ / _/___
- / __// _ \ / __// -_)/ _ `// _ / (_-</ _ `// _// -_)
- \__//_//_//_/ \__/ \_,_/ \_,_/ /___/\_,_//_/ \__/
+ /* ==================================================================
+ __ __ __ ___
+ / /_ / / ____ ___ ___ _ ___/ / ___ ___ _ / _/___
+ / __// _ \ / __// -_)/ _ `// _ / (_-</ _ `// _// -_)
+ \__//_//_//_/ \__/ \_,_/ \_,_/ /___/\_,_//_/ \__/
- ==================================================================
- param
- int [0,1]
+ ==================================================================
+ param
+ int [0,1]
- description
- initializes or destroys lock for given "el" object,
- function does make sure not to double initialize or
- destroy mutex. This case must be called when no
- other threads are accessing any of "el" fields.
- ================================================================== */
+ description
+ initializes or destroys lock for given "el" object,
+ function does make sure not to double initialize or
+ destroy mutex. This case must be called when no
+ other threads are accessing any of "el" fields.
+ ================================================================== */
# if ENABLE_PTHREAD
- case EL_THREAD_SAFE:
- value_int = va_arg(ap, int);
-
- if (value_int)
- {
- if (el->lock_initialized)
- {
- /* lock is already initialized, don't initialize
- * it again, as this will result in undefined
- * behaviour
- */
-
- return 0;
- }
-
- /* lock not initialized, do it now
- */
-
- ret = pthread_mutex_init(&el->lock, NULL);
- if (ret > 0)
- {
- /* pthread does not need to set errno, and it
- * returns errno value as return value from
- * function, convert it to our standard error
- * reporting
- */
-
- errno = ret;
- return -1;
- }
-
- el->lock_initialized = 1;
- return 0;
- }
-
- /* user wants to disable thread safety
- */
-
- if (el->lock_initialized == 0)
- {
- /* but lock is not initialized, can't destroy what has
- * no yet been created.
- */
-
- return 0;
- }
-
- pthread_mutex_destroy(&el->lock);
- el->lock_initialized = 0;
- return 0;
+ case EL_THREAD_SAFE:
+ value_int = va_arg(ap, int);
+
+ if (value_int)
+ {
+ /* if lock is already initialized, don't initialize it
+ * again, as this will result in undefined behaviour */
+ if (el->lock_initialized) return 0;
+
+ /* lock not initialized, do it now */
+ ret = pthread_mutex_init(&el->lock, NULL);
+ if (ret > 0)
+ {
+ /* pthread does not need to set errno, and it
+ * returns errno value as return value from
+ * function, convert it to our standard error
+ * reporting */
+ errno = ret;
+ return -1;
+ }
+
+ el->lock_initialized = 1;
+ return 0;
+ }
+
+ /* user wants to disable thread safety but lock was not
+ * initialized, can't destroy what has no yet been created. */
+ if (el->lock_initialized == 0) return 0;
+
+ pthread_mutex_destroy(&el->lock);
+ el->lock_initialized = 0;
+ return 0;
# endif /* ENABLE_PTHREAD */
- /* ==================================================================
- __ ___ __ __
- ___/ /___ / _/___ _ __ __ / // /_
- / _ // -_)/ _// _ `// // // // __/
- \_,_/ \__//_/ \_,_/ \_,_//_/ \__/
+ /* ==================================================================
+ __ ___ __ __
+ ___/ /___ / _/___ _ __ __ / // /_
+ / _ // -_)/ _// _ `// // // // __/
+ \_,_/ \__//_/ \_,_/ \_,_//_/ \__/
- ================================================================== */
+ ================================================================== */
- default:
- /* if we get here, user used option that was disabled
- * during compilation time and is not implemented
- */
+ default:
+ /* if we get here, user used option that was disabled
+ * during compilation time and is not implemented
+ */
- errno = ENOSYS;
- return -1;
- }
+ errno = ENOSYS;
+ return -1;
+ }
- (void)value_str;
- (void)value_int;
- (void)value_ulong;
+ /* (void) all args here to silent compiler in case some
+ * var is not used due to #if being false */
+ (void)value_str;
+ (void)value_int;
+ (void)value_ulong;
}
@@ -704,10 +680,10 @@ static int el_vooption
/* public api */ int el_init
(
- void
+ void
)
{
- return el_oinit(&g_el);
+ return el_oinit(&g_el);
}
@@ -721,33 +697,33 @@ static int el_vooption
/* public api */ int el_oinit
(
- struct el *el /* el object */
+ struct el *el /* el object */
)
{
- VALID(EINVAL, el);
+ VALID(EINVAL, el);
- memset(el, 0, sizeof(struct el));
- el->outputs = EL_OUT_STDERR;
- el->print_log_level = 1;
- el->print_newline = 1;
- el->level = EL_INFO;
- el->level_current_msg = EL_DBG;
+ memset(el, 0, sizeof(struct el));
+ el->outputs = EL_OUT_STDERR;
+ el->print_log_level = 1;
+ el->print_newline = 1;
+ el->level = EL_INFO;
+ el->level_current_msg = EL_DBG;
#if ENABLE_OUT_TTY
- el->serial_fd = -1;
+ el->serial_fd = -1;
#endif
#if ENABLE_OUT_FILE
- el->fsync_every = 32768;
- el->fsync_level = EL_FATAL;
- el->frotate_symlink = 1;
+ el->fsync_every = 32768;
+ el->fsync_level = EL_FATAL;
+ el->frotate_symlink = 1;
#endif
#if ENABLE_PTHREAD
- el->lock_initialized = 0;
+ el->lock_initialized = 0;
#endif
- return 0;
+ return 0;
}
@@ -762,22 +738,18 @@ static int el_vooption
/* public api */ struct el *el_new
(
- void
+ void
)
{
- struct el *el;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ struct el *el;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- el = malloc(sizeof(*el));
- if (el == NULL)
- {
- errno = ENOMEM;
- return NULL;
- }
+ el = malloc(sizeof(*el));
+ VALIDR(ENOMEM, NULL, el);
- el_oinit(el);
- return el;
+ el_oinit(el);
+ return el;
}
@@ -790,10 +762,10 @@ static int el_vooption
/* public api */ int el_cleanup
(
- void
+ void
)
{
- return el_ocleanup(&g_el);
+ return el_ocleanup(&g_el);
}
@@ -809,30 +781,24 @@ static int el_vooption
/* public api */ int el_ocleanup
(
- struct el *el /* el object */
+ struct el *el /* el object */
)
{
- VALID(EINVAL, el);
+ VALID(EINVAL, el);
- el->outputs = 0;
+ el->outputs = 0;
#if ENABLE_OUT_FILE
- el_file_cleanup(el);
+ el_file_cleanup(el);
#endif
#if ENABLE_OUT_TTY
- if (el->serial_fd != -1)
- {
- el_tty_close(el);
- }
+ if (el->serial_fd != -1) el_tty_close(el);
#endif
#if ENABLE_PTHREAD
- if (el->lock_initialized)
- {
- pthread_mutex_destroy(&el->lock);
- }
+ if (el->lock_initialized) pthread_mutex_destroy(&el->lock);
#endif
- return 0;
+ return 0;
}
@@ -844,16 +810,12 @@ static int el_vooption
/* public api */ int el_destroy
(
- struct el *el /* el object */
+ struct el *el /* el object */
)
{
- if (el_ocleanup(el) != 0)
- {
- return -1;
- }
-
- free(el);
- return 0;
+ if (el_ocleanup(el) != 0) return -1;
+ free(el);
+ return 0;
}
@@ -865,11 +827,11 @@ static int el_vooption
int el_log_allowed
(
- struct el *el, /* el object */
- enum el_level level /* log level to check */
+ struct el *el, /* el object */
+ enum el_level level /* log level to check */
)
{
- return el->level >= (int)level;
+ return el->level >= (int)level;
}
@@ -880,19 +842,19 @@ int el_log_allowed
/* public api */ int el_option
(
- int option, /* option to set */
- ... /* option value */
+ int option, /* option to set */
+ ... /* option value */
)
{
- va_list ap; /* variadic arguments */
- int rc; /* return code from el_voooption */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ va_list ap; /* variadic arguments */
+ int rc; /* return code from el_voooption */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- va_start(ap, (int)option);
- rc = el_vooption(&g_el, option, ap);
- va_end(ap);
+ va_start(ap, (int)option);
+ rc = el_vooption(&g_el, option, ap);
+ va_end(ap);
- return rc;
+ return rc;
}
@@ -903,21 +865,21 @@ int el_log_allowed
/* public api */ int el_ooption
(
- struct el *el, /* el object to set option to */
- int option, /* option to set */
- ... /* option value(s) */
+ struct el *el, /* el object to set option to */
+ int option, /* option to set */
+ ... /* option value(s) */
)
{
- va_list ap; /* variadic arguments */
- int rc; /* return code from el_voooption */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ va_list ap; /* variadic arguments */
+ int rc; /* return code from el_voooption */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- va_start(ap, option);
- rc = el_vooption(el, option, ap);
- va_end(ap);
+ va_start(ap, option);
+ rc = el_vooption(el, option, ap);
+ va_end(ap);
- return rc;
+ return rc;
}
@@ -929,8 +891,8 @@ int el_log_allowed
/* public api */ const struct el *el_get_el
(
- void
+ void
)
{
- return (const struct el *)&g_el;
+ return (const struct el *)&g_el;
}
diff --git a/src/el-pbinary.c b/src/el-pbinary.c
index 48f96cf..ae46fd1 100644
--- a/src/el-pbinary.c
+++ b/src/el-pbinary.c
@@ -82,31 +82,29 @@
static size_t el_flags
(
- enum el_level level,
- struct el *el,
- unsigned char *buf
+ enum el_level level,
+ struct el *el,
+ unsigned char *buf
)
{
- *buf = 0;
+ *buf = 0;
#if ENABLE_TIMESTAMP
- if (el->timestamp != EL_TS_OFF)
- {
- *buf |= FLAG_TS;
+ if (el->timestamp != EL_TS_OFF)
+ {
+ *buf |= FLAG_TS;
# if ENABLE_FRACTIONS
- /* fraction of seconds can be printed only when timestamp
- * is on
- */
+ /* fraction of seconds can be printed only when timestamp
+ * is on */
- *buf |= el->timestamp_fractions << FLAG_TS_FRACT_SHIFT;
+ *buf |= el->timestamp_fractions << FLAG_TS_FRACT_SHIFT;
# endif
- }
+ }
#endif
- *buf |= level << FLAG_LEVEL_SHIFT;
-
- return 1;
+ *buf |= level << FLAG_LEVEL_SHIFT;
+ return 1;
}
@@ -162,73 +160,69 @@ static size_t el_flags
/* public api */ int el_opbinary
(
- enum el_level level, /* log severity level */
- struct el *el, /* el object with info how to print */
- const void *memory, /* binary data to store to print */
- size_t mlen /* length of "memory" buffer */
+ enum el_level level, /* log severity level */
+ struct el *el, /* el object with info how to print */
+ const void *memory, /* binary data to store to print */
+ size_t mlen /* length of "memory" buffer */
)
{
- unsigned char buf[EL_BUF_MAX]; /* buffer for message to print */
- size_t l; /* length of encoded mlen */
- size_t w; /* bytes written to buf */
- int e; /* cache for errno */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- VALID(EINVAL, mlen);
- VALID(EINVAL, memory);
- VALID(EINVAL, el);
- el_lock(el);
- VALIDC(ENODEV, el->outputs, el_unlock(el));
- VALIDC(ERANGE, el_log_allowed(el, level), el_unlock(el));
-
- e = 0;
- w = el_flags(level, el, buf);
- w += el_timestamp(el, buf + w, TS_BINARY);
-
- /* encode mlen to know how much bytes we are going to need
- */
-
- l = el_encode_number(mlen, buf + w);
-
- if (w + l + mlen > sizeof(buf))
- {
- /* user tries to print more that than we can hold in our
- * buffer, buffer overflow attack? Not going to happen! We
- * truncate it.
- */
-
- mlen = EL_BUF_MAX - w - l;
- e = ENOBUFS;
- }
-
- /* now that we know real value of mlen, we can encode mlen
- * again
- */
-
- w += el_encode_number(mlen, buf + w);
- memcpy(buf + w, memory, mlen);
- el->level_current_msg = level;
- w += mlen;
-
- if (el_oputb_nb(el, buf, w) != 0)
- {
- el->level_current_msg = EL_DBG;
- el_unlock(el);
- return -1;
- }
-
- el->level_current_msg = EL_DBG;
-
- if (e)
- {
- errno = e;
- el_unlock(el);
- return -1;
- }
-
- el_unlock(el);
- return 0;
+ unsigned char buf[EL_BUF_MAX]; /* buffer for message to print */
+ size_t l; /* length of encoded mlen */
+ size_t w; /* bytes written to buf */
+ int e; /* cache for errno */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ VALID(EINVAL, mlen);
+ VALID(EINVAL, memory);
+ VALID(EINVAL, el);
+ el_lock(el);
+ VALIDC(ENODEV, el->outputs, el_unlock(el));
+ VALIDC(ERANGE, el_log_allowed(el, level), el_unlock(el));
+
+ e = 0;
+ w = el_flags(level, el, buf);
+ w += el_timestamp(el, buf + w, TS_BINARY);
+
+ /* encode mlen to know how much bytes we are
+ * going to need */
+ l = el_encode_number(mlen, buf + w);
+
+ if (w + l + mlen > sizeof(buf))
+ {
+ /* user tries to print more that than we
+ * can hold in our buffer, buffer overflow
+ * attack? Not going to happen! We
+ * truncate it. */
+ mlen = EL_BUF_MAX - w - l;
+ e = ENOBUFS;
+ }
+
+ /* now that we know real value of mlen, we can
+ * encode mlen again */
+ w += el_encode_number(mlen, buf + w);
+ memcpy(buf + w, memory, mlen);
+ el->level_current_msg = level;
+ w += mlen;
+
+ if (el_oputb_nb(el, buf, w) != 0)
+ {
+ el->level_current_msg = EL_DBG;
+ el_unlock(el);
+ return -1;
+ }
+
+ el->level_current_msg = EL_DBG;
+
+ if (e)
+ {
+ errno = e;
+ el_unlock(el);
+ return -1;
+ }
+
+ el_unlock(el);
+ return 0;
}
@@ -239,11 +233,10 @@ static size_t el_flags
/* public api */ int el_pbinary
(
-
- enum el_level level, /* log severity level */
- const void *memory, /* binary data to store to print */
- size_t mlen /* length of "memory" buffer */
+ enum el_level level, /* log severity level */
+ const void *memory, /* binary data to store to print */
+ size_t mlen /* length of "memory" buffer */
)
{
- return el_opbinary(level, &g_el, memory, mlen);
+ return el_opbinary(level, &g_el, memory, mlen);
}
diff --git a/src/el-perror.c b/src/el-perror.c
index a9b7372..a9ee759 100644
--- a/src/el-perror.c
+++ b/src/el-perror.c
@@ -45,47 +45,38 @@
static int el_ovperror
(
- const char *file, /* file name where log is printed */
- size_t num, /* line number where log is printed */
- const char *func, /* function name to print */
- enum el_level level, /* log level to print message with */
- struct el *el, /* el defining printing style */
- const char *fmt, /* message format (see printf (3)) */
- va_list ap /* additional parameters for fmt */
+ const char *file, /* file name where log is printed */
+ size_t num, /* line number where log is printed */
+ const char *func, /* function name to print */
+ enum el_level level, /* log level to print message with */
+ struct el *el, /* el defining printing style */
+ const char *fmt, /* message format (see printf (3)) */
+ va_list ap /* additional parameters for fmt */
)
{
- int rc; /* return code from el_print() */
- unsigned long e; /* errno from upper layer */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int rc; /* return code from el_print() */
+ unsigned long e; /* errno from upper layer */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ /* there is not need to el_lock() mutex here, as el_ovprint()
+ * and el_oprint() will do it for us */
- VALID(EINVAL, el);
+ VALID(EINVAL, el);
- e = errno;
- rc = 0;
+ e = errno;
+ rc = 0;
- /* there is not need to el_lock() mutex here, as el_ovprint()
- * and el_oprint() will do it for us
- */
+ /* we print formatted message only when it is supplied by
+ * the user, otherwise only errno message will be printed */
+ if (fmt) rc |= el_ovprint(file, num, func, level, el, fmt, ap);
- if (fmt)
- {
- /* we print formatted message only when it is supplied by
- * the user, otherwise only errno message will be printed
- */
+ rc |= el_oprint(file, num, func, level, el,
+ "errno num: %lu, strerror: %s", e, strerror(e));
- rc |= el_ovprint(file, num, func, level, el, fmt, ap);
- }
-
- rc |= el_oprint(file, num, func, level, el,
- "errno num: %lu, strerror: %s", e, strerror(e));
-
- /* in case errno has been modified return it to value from
- * before this call
- */
-
- errno = e;
- return rc;
+ /* in case errno has been modified return it to value from
+ * before this call */
+ errno = e;
+ return rc;
}
@@ -107,24 +98,24 @@ static int el_ovperror
/* public api */ int el_perror
(
- const char *file, /* file name where log is printed */
- size_t num, /* line number where log is printed */
- const char *func, /* function name to print */
- enum el_level level, /* log level to print message with */
- const char *fmt, /* message format (see printf (3)) */
- ... /* additional parameters for fmt */
+ const char *file, /* file name where log is printed */
+ size_t num, /* line number where log is printed */
+ const char *func, /* function name to print */
+ enum el_level level, /* log level to print message with */
+ const char *fmt, /* message format (see printf (3)) */
+ ... /* additional parameters for fmt */
)
{
- int rc; /* return code from el_operror() */
- va_list ap; /* argument pointer for variadic variables */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int rc; /* return code from el_operror() */
+ va_list ap; /* argument pointer for variadic variables */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- va_start(ap, fmt);
- rc = el_ovperror(file, num, func, level, &g_el, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ rc = el_ovperror(file, num, func, level, &g_el, fmt, ap);
+ va_end(ap);
- return rc;
+ return rc;
}
@@ -135,23 +126,23 @@ static int el_ovperror
/* public api */ int el_operror
(
- const char *file, /* file name where log is printed */
- size_t num, /* line number where log is printed*/
- const char *func, /* function name to print */
- enum el_level level, /* log level to print message with */
- struct el *el, /* el defining printing style */
- const char *fmt, /* message format (see printf (3)) */
- ... /* additional parameters for fmt */
+ const char *file, /* file name where log is printed */
+ size_t num, /* line number where log is printed*/
+ const char *func, /* function name to print */
+ enum el_level level, /* log level to print message with */
+ struct el *el, /* el defining printing style */
+ const char *fmt, /* message format (see printf (3)) */
+ ... /* additional parameters for fmt */
)
{
- int rc; /* return code from el_operror() */
- va_list ap; /* argument pointer for variadic variables */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int rc; /* return code from el_operror() */
+ va_list ap; /* argument pointer for variadic variables */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- va_start(ap, fmt);
- rc = el_ovperror(file, num, func, level, el, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ rc = el_ovperror(file, num, func, level, el, fmt, ap);
+ va_end(ap);
- return rc;
+ return rc;
}
diff --git a/src/el-pmemory.c b/src/el-pmemory.c
index c221ae0..979d3c7 100644
--- a/src/el-pmemory.c
+++ b/src/el-pmemory.c
@@ -59,60 +59,49 @@
static int el_print_line
(
- const char *file, /* file name where log is printed */
- size_t num, /* line number where log is printed */
- const char *func, /* function name to print */
- enum el_level level, /* log level to print message with */
- struct el *el, /* el defining printing style */
- const unsigned char *buf, /* memory location to print */
- size_t line_size, /* size of line in bytes */
- size_t line_number /* line number beign processed */
+ const char *file, /* file name where log is printed */
+ size_t num, /* line number where log is printed */
+ const char *func, /* function name to print */
+ enum el_level level, /* log level to print message with */
+ struct el *el, /* el defining printing style */
+ const unsigned char *buf, /* memory location to print */
+ size_t line_size, /* size of line in bytes */
+ size_t line_number /* line number beign processed */
)
{
- /* buffers to hold whole line of bytes representation in hex
- * and char
- */
+ /* buffers to hold whole line of bytes
+ * representation in hex and char */
+ char hex_data[EL_MEM_HEX_LEN + 1] = {0};
+ char char_data[EL_MEM_CHAR_LEN + 1] = {0};
- char hex_data[EL_MEM_HEX_LEN + 1] = {0};
- char char_data[EL_MEM_CHAR_LEN + 1] = {0};
+ /* calculate buf offset value */
+ const unsigned int offset = EL_MEM_LINE_SIZE * line_number;
- /* calculate buf offset value
- */
+ size_t bn; /* byte number */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- const unsigned int offset = EL_MEM_LINE_SIZE * line_number;
- /* fill data buffers with representation of bytes
- */
+ /* fill data buffers with representation of bytes */
+ for (bn = 0; bn < line_size; ++bn)
+ {
+ unsigned char current_byte;
+ char *current_hex_pos;
+ char *current_char_pos;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- size_t bn; /* byte number */
- for (bn = 0; bn < line_size; ++bn)
- {
- unsigned char current_byte;
- char *current_hex_pos;
- char *current_char_pos;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ current_byte = *buf++;
+ current_hex_pos = hex_data + bn * EL_MEM_SINGLE_HEX_LEN;
+ current_char_pos = char_data + bn;
+ sprintf(current_hex_pos, "%02x ", current_byte);
+ if (isprint(current_byte) == 0) current_byte = '.';
+ *current_char_pos = current_byte;
+ }
- current_byte = *buf++;
- current_hex_pos = hex_data + bn * EL_MEM_SINGLE_HEX_LEN;
- current_char_pos = char_data + bn;
-
- sprintf(current_hex_pos, "%02x ", current_byte);
-
- if (isprint(current_byte) == 0)
- {
- current_byte = '.';
- }
-
- *current_char_pos = current_byte;
- }
-
- /* print constructed line
- */
-
- return el_oprint_nb(file, num, func, level, el, "0x%04x %-*s %s",
- offset, EL_MEM_HEX_LEN, hex_data, char_data);
+ /* print constructed line */
+ return el_oprint_nb(file, num, func, level, el, "0x%04x %-*s %s",
+ offset, EL_MEM_HEX_LEN, hex_data, char_data);
}
@@ -147,115 +136,99 @@ static int el_print_line
static int el_pmem
(
- const char *file, /* file name where log is printed */
- size_t num, /* line number where log is printed */
- const char *func, /* function name to print */
- enum el_level level, /* log level to print message with */
- struct el *el, /* el defining printing style */
- const void *mem, /* memory location to print */
- size_t mlen, /* number of bytes to print */
- int table /* print table? or not to print table? */
+ const char *file, /* file name where log is printed */
+ size_t num, /* line number where log is printed */
+ const char *func, /* function name to print */
+ enum el_level level, /* log level to print message with */
+ struct el *el, /* el defining printing style */
+ const void *mem, /* memory location to print */
+ size_t mlen, /* number of bytes to print */
+ int table /* print table? or not to print table? */
)
{
- /* String needed to print separator for array-like formating
- */
-
- static const char *separator =
-"-----------------------------------------------------------------------------";
-
- /* calculate some constants for this call based on mlen
- */
-
- const size_t msg_size = mlen;
- const size_t lines_count = msg_size / EL_MEM_LINE_SIZE;
- const size_t last_line_size = msg_size % EL_MEM_LINE_SIZE;
-
- size_t line_number; /* current line number being printed */
- int rv; /* return value of print functions */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- rv = 0;
-
- /* let's first check if logs are enabled for passed level, if
- * not, there is no need to waste cycles on useless string
- * preparation
- */
-
- VALID(EINVAL, mem);
- VALID(EINVAL, mlen);
- VALID(EINVAL, el);
- el_lock(el);
- VALIDC(ERANGE, el_log_allowed(el, level), el_unlock(el));
-
-
- /* print log table preamble that is:
- *
- * ------ ----------------------------------------------- ----------------
- * offset hex ascii
- * ------ ----------------------------------------------- ----------------
- */
-
- if (table)
- {
- rv = 0;
- rv |= el_oprint_nb(file, num, func, level, el, "%.*s %.*s %.*s",
- EL_MEM_OFFSET_LEN - 2, separator,
- EL_MEM_HEX_LEN - 1, separator,
- EL_MEM_CHAR_LEN, separator);
-
- rv |= el_oprint_nb(file, num, func, level, el, "%-*s%-*s%s",
- EL_MEM_OFFSET_LEN, "offset",
- EL_MEM_HEX_LEN + 1, "hex", "ascii");
-
- rv |= el_oprint_nb(file, num, func, level, el, "%.*s %.*s %.*s",
- EL_MEM_OFFSET_LEN - 2, separator,
- EL_MEM_HEX_LEN - 1, separator,
- EL_MEM_CHAR_LEN, separator);
- }
-
- /* print all lines that contains EL_MEM_LINE_SIZE bytes,
- * meaning we print all whole lines
- */
-
- for (line_number = 0; line_number < lines_count; ++line_number)
- {
- rv |= el_print_line(file, num, func, level, el,
- mem, EL_MEM_LINE_SIZE, line_number);
-
- /* move memory pointer to point to next chunk of data to
- * print
- */
-
- mem = (const unsigned char *)mem + EL_MEM_LINE_SIZE;
- }
-
- /* if buflen is not divisible by EL_MEM_LINE_SIZE we still need
- * to print last line which has less bytes then
- * EL_MEM_LINE_SIZE.
- */
-
- if (last_line_size)
- {
- rv |= el_print_line(file, num, func, level, el,
- mem, last_line_size, line_number);
- }
-
- /* print ending line
- *
- * ------ ----------------------------------------------- ----------------
- */
-
- if (table)
- {
- rv |= el_oprint_nb(file, num, func, level, el, "%.*s %.*s %.*s",
- EL_MEM_OFFSET_LEN - 2, separator,
- EL_MEM_HEX_LEN - 1, separator,
- EL_MEM_CHAR_LEN, separator);
- }
-
- el_unlock(el);
- return rv;
+ /* String needed to print separator for array-like formating */
+ static const char *separator =
+ "-----------------------------------------------------------------------------";
+
+ /* calculate some constants for this call based on mlen */
+ const size_t msg_size = mlen;
+ const size_t lines_count = msg_size / EL_MEM_LINE_SIZE;
+ const size_t last_line_size = msg_size % EL_MEM_LINE_SIZE;
+
+ size_t line_number; /* current line number being printed */
+ int rv; /* return value of print functions */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ rv = 0;
+
+ /* let's first check if logs are enabled for passed level, if
+ * not, there is no need to waste cycles on useless string
+ * preparation */
+ VALID(EINVAL, mem);
+ VALID(EINVAL, mlen);
+ VALID(EINVAL, el);
+ el_lock(el);
+ VALIDC(ERANGE, el_log_allowed(el, level), el_unlock(el));
+
+
+ /* print log table preamble that is:
+ *
+ * ------ ----------------------------------------------- ----------------
+ * offset hex ascii
+ * ------ ----------------------------------------------- ----------------
+ */
+
+ if (table)
+ {
+ rv = 0;
+ rv |= el_oprint_nb(file, num, func, level, el, "%.*s %.*s %.*s",
+ EL_MEM_OFFSET_LEN - 2, separator,
+ EL_MEM_HEX_LEN - 1, separator,
+ EL_MEM_CHAR_LEN, separator);
+
+ rv |= el_oprint_nb(file, num, func, level, el, "%-*s%-*s%s",
+ EL_MEM_OFFSET_LEN, "offset",
+ EL_MEM_HEX_LEN + 1, "hex", "ascii");
+
+ rv |= el_oprint_nb(file, num, func, level, el, "%.*s %.*s %.*s",
+ EL_MEM_OFFSET_LEN - 2, separator,
+ EL_MEM_HEX_LEN - 1, separator,
+ EL_MEM_CHAR_LEN, separator);
+ }
+
+ /* print all lines that contains EL_MEM_LINE_SIZE bytes,
+ * meaning we print all whole lines */
+ for (line_number = 0; line_number < lines_count; ++line_number)
+ {
+ rv |= el_print_line(file, num, func, level, el,
+ mem, EL_MEM_LINE_SIZE, line_number);
+
+ /* move memory pointer to point to next chunk of data to
+ * print */
+ mem = (const unsigned char *)mem + EL_MEM_LINE_SIZE;
+ }
+
+ /* if buflen is not divisible by EL_MEM_LINE_SIZE we still need
+ * to print last line which has less bytes then
+ * EL_MEM_LINE_SIZE. */
+ if (last_line_size)
+ rv |= el_print_line(file, num, func, level, el,
+ mem, last_line_size, line_number);
+
+ /* print ending line
+ *
+ * ------ ----------------------------------------------- ----------------
+ */
+
+ if (table)
+ rv |= el_oprint_nb(file, num, func, level, el, "%.*s %.*s %.*s",
+ EL_MEM_OFFSET_LEN - 2, separator,
+ EL_MEM_HEX_LEN - 1, separator,
+ EL_MEM_CHAR_LEN, separator);
+
+ el_unlock(el);
+ return rv;
}
@@ -276,16 +249,16 @@ static int el_pmem
/* public api */ int el_opmemory_table
(
- const char *file, /* file name where log is printed */
- size_t num, /* line number where log is printed */
- const char *func, /* function name to print */
- enum el_level level, /* log level to print message with */
- struct el *el, /* el defining printing style */
- const void *mem, /* memory location to print */
- size_t mlen /* number of bytes to print */
+ const char *file, /* file name where log is printed */
+ size_t num, /* line number where log is printed */
+ const char *func, /* function name to print */
+ enum el_level level, /* log level to print message with */
+ struct el *el, /* el defining printing style */
+ const void *mem, /* memory location to print */
+ size_t mlen /* number of bytes to print */
)
{
- return el_pmem(file, num, func, level, el, mem, mlen, 1);
+ return el_pmem(file, num, func, level, el, mem, mlen, 1);
}
@@ -296,15 +269,15 @@ static int el_pmem
/* public api */ int el_pmemory_table
(
- const char *file, /* file name where log is printed */
- size_t num, /* line number where log is printed */
- const char *func, /* function name to print */
- enum el_level level, /* log level to print message with */
- const void *mem, /* memory location to print */
- size_t mlen /* number of bytes to print */
+ const char *file, /* file name where log is printed */
+ size_t num, /* line number where log is printed */
+ const char *func, /* function name to print */
+ enum el_level level, /* log level to print message with */
+ const void *mem, /* memory location to print */
+ size_t mlen /* number of bytes to print */
)
{
- return el_pmem(file, num, func, level, &g_el, mem, mlen, 1);
+ return el_pmem(file, num, func, level, &g_el, mem, mlen, 1);
}
/* ==========================================================================
@@ -314,16 +287,16 @@ static int el_pmem
/* public api */ int el_opmemory
(
- const char *file, /* file name where log is printed */
- size_t num, /* line number where log is printed */
- const char *func, /* function name to print */
- enum el_level level, /* log level to print message with */
- struct el *el, /* el defining printing style */
- const void *mem, /* memory location to print */
- size_t mlen /* number of bytes to print */
+ const char *file, /* file name where log is printed */
+ size_t num, /* line number where log is printed */
+ const char *func, /* function name to print */
+ enum el_level level, /* log level to print message with */
+ struct el *el, /* el defining printing style */
+ const void *mem, /* memory location to print */
+ size_t mlen /* number of bytes to print */
)
{
- return el_pmem(file, num, func, level, el, mem, mlen, 0);
+ return el_pmem(file, num, func, level, el, mem, mlen, 0);
}
@@ -334,13 +307,13 @@ static int el_pmem
/* public api */ int el_pmemory
(
- const char *file, /* file name where log is printed */
- size_t num, /* line number where log is printed */
- const char *func, /* function name to print */
- enum el_level level, /* log level to print message with */
- const void *mem, /* memory location to print */
- size_t mlen /* number of bytes to print */
+ const char *file, /* file name where log is printed */
+ size_t num, /* line number where log is printed */
+ const char *func, /* function name to print */
+ enum el_level level, /* log level to print message with */
+ const void *mem, /* memory location to print */
+ size_t mlen /* number of bytes to print */
)
{
- return el_pmem(file, num, func, level, &g_el, mem, mlen, 0);
+ return el_pmem(file, num, func, level, &g_el, mem, mlen, 0);
}
diff --git a/src/el-print.c b/src/el-print.c
index 5f0e6e2..cf91585 100644
--- a/src/el-print.c
+++ b/src/el-print.c
@@ -65,27 +65,24 @@ static const char char_level[8] = { 'f', 'a', 'c', 'e', 'w', 'n', 'i', 'd' };
#if ENABLE_COLORS
-/* colors indexes are synced with log level
- */
+/* colors indexes are synced with log level */
#if ENABLE_COLORS_EXTENDED
/* for those that like more colors, there are definitions with more
* colors! this will enable light version of some levels, but this
- * is not supported on all terminal! You have been warned!
- */
-
+ * is not supported on all terminal! You have been warned! */
static const char *color[] =
{
- "\033[91m", /* fatal light red */
- "\033[31m", /* alert red */
- "\033[95m", /* critical light magenta */
- "\033[35m", /* error magenta */
- "\033[93m", /* warning light yellow */
- "\033[92m", /* notice light green */
- "\033[32m", /* information green */
- "\033[34m", /* debug blue */
- "\033[0m" /* remove all formats */
+ "\033[91m", /* fatal light red */
+ "\033[31m", /* alert red */
+ "\033[95m", /* critical light magenta */
+ "\033[35m", /* error magenta */
+ "\033[93m", /* warning light yellow */
+ "\033[92m", /* notice light green */
+ "\033[32m", /* information green */
+ "\033[34m", /* debug blue */
+ "\033[0m" /* remove all formats */
};
#else
@@ -93,20 +90,18 @@ static const char *color[] =
/* not all terminal can support extended colors with light version
* of them, for those who want to be more standard compliant there
* is this shortened version of colors. On downside is that some
- * level will have same colors.
- */
-
+ * level will have same colors. */
static const char *color[] =
{
- "\033[31m", /* fatal red */
- "\033[31m", /* alert red */
- "\033[35m", /* critical magenta */
- "\033[35m", /* error magenta */
- "\033[33m", /* warning yellow */
- "\033[32m", /* notice green */
- "\033[32m", /* information green */
- "\033[34m", /* debug blue */
- "\033[0m" /* remove all formats */
+ "\033[31m", /* fatal red */
+ "\033[31m", /* alert red */
+ "\033[35m", /* critical magenta */
+ "\033[35m", /* error magenta */
+ "\033[33m", /* warning yellow */
+ "\033[32m", /* notice green */
+ "\033[32m", /* information green */
+ "\033[34m", /* debug blue */
+ "\033[0m" /* remove all formats */
};
#endif /* COLORS_EXTENDED */
@@ -136,31 +131,24 @@ static const char *color[] =
static size_t el_color
(
- struct el *el, /* el defining printing style */
- char *buf, /* buffer where to store color info */
- int level /* log level or 8 for reset */
+ struct el *el, /* el defining printing style */
+ char *buf, /* buffer where to store color info */
+ int level /* log level or 8 for reset */
)
{
#if ENABLE_COLORS
- if (el->colors == 0)
- {
- /*
- * no colors, you got it!
- */
+ if (el->colors == 0) return 0;
- return 0;
- }
-
- strcpy(buf, color[level]);
- return strlen(color[level]);
+ strcpy(buf, color[level]);
+ return strlen(color[level]);
#else
- (void)el;
- (void)buf;
- (void)level;
- return 0;
+ (void)el;
+ (void)buf;
+ (void)level;
+ return 0;
#endif
}
@@ -175,56 +163,43 @@ static size_t el_color
static size_t el_finfo
(
- struct el *el, /* el defining printing style */
- char *buf, /* location whre to store file information */
- const char *file, /* path to file - will be basenamed */
- int num /* line number (max 99999) */
+ struct el *el, /* el defining printing style */
+ char *buf, /* location whre to store file information */
+ const char *file, /* path to file - will be basenamed */
+ int num /* line number (max 99999) */
)
{
#if ENABLE_FINFO
- const char *base; /* basenem of the 'file' */
- size_t fl; /* number of bytes stored in 'buf' */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- if (el->finfo == 0 || file == NULL || num == 0)
- {
- /* no file info for this caller
- */
+ const char *base; /* basenem of the 'file' */
+ size_t fl; /* number of bytes stored in 'buf' */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- return 0;
- }
+ /* do not print file info if user do not wish it */
+ if (el->finfo == 0 || file == NULL || num == 0) return 0;
- if (num > EL_PRE_FINFO_LINE_MAX_NUM)
- {
- /* line number is too large and may overflow buffer, limit
- * it to max value
- */
+ /* if line number is too large and may
+ * overflow buffer, limit it to max value */
+ if (num > EL_PRE_FINFO_LINE_MAX_NUM)
+ num = EL_PRE_FINFO_LINE_MAX_NUM;
- num = EL_PRE_FINFO_LINE_MAX_NUM;
- }
+ base = el_basename(file);
- base = el_basename(file);
+ buf[0] = '[';
+ buf[1] = '\0';
+ strncat(buf, base, EL_FLEN_MAX);
+ fl = strlen(buf);
+ fl += sprintf(buf + fl, ":%d", num);
- buf[0] = '[';
- buf[1] = '\0';
- strncat(buf, base, EL_FLEN_MAX);
- fl = strlen(buf);
- fl += sprintf(buf + fl, ":%d", num);
+ /* when function info is printed, we don't close ']', to
+ * let it print function in same [] brackets, we close it
+ * only when there is no function info (and thus finfo
+ * being last info in [] brackets */
+ if (el->funcinfo == 0) buf[fl++] = ']';
- if (el->funcinfo == 0)
- {
- /* when function info is printed, we don't close ']', to
- * let it print function in same [] brackets, we close it
- * only when there is no finfo
- */
-
- buf[fl++] = ']';
- }
-
- return fl;
+ return fl;
#else
- return 0;
+ return 0;
#endif /* ENABLE_FINFO */
}
@@ -236,64 +211,48 @@ static size_t el_finfo
static size_t el_funcinfo
(
- struct el *el, /* el defining printing style */
- char *buf, /* location whre to store file information */
- const char *func /* function name to print */
+ struct el *el, /* el defining printing style */
+ char *buf, /* location whre to store file information */
+ const char *func /* function name to print */
)
{
#if ENABLE_FUNCINFO
- size_t fl; /* number of bytes stored in 'buf' */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- if (el->funcinfo == 0 || func == NULL)
- {
- /* no function print for this caller
- */
+ size_t fl; /* number of bytes stored in 'buf' */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- return 0;
- }
+ if (el->funcinfo == 0 || func == NULL) return 0;
- /* if finfo is enabled, we need to add ':' to delimit ourselfs
- * from fifno, but, if there is no file info, we need to open
- * '[' bracket, as it was not already opened by finfo
- */
+ /* if finfo is enabled, we need to add ':' to delimit ourselfs
+ * from fifno, but, if there is no file info, we need to open
+ * '[' bracket, as it was not already opened by finfo */
+ buf[0] = el->finfo ? ':' : '[';
- buf[0] = el->finfo ? ':' : '[';
+ /* copy function name to buffer */
+ strncpy(buf + 1, func, EL_FUNCLEN_MAX);
- /* copy function name to buffer
- */
+ /* in case func is too big, nullify EL_FUNCLEN_MAXth character,
+ * to prevent strlen showing bad results, 1 is because of
+ * previous ':'/'[' characters */
+ buf[1 + EL_FUNCLEN_MAX] = '\0';
+ fl = strlen(buf);
- strncpy(buf + 1, func, EL_FUNCLEN_MAX);
+ /* and add leading "()" to indicate it is a function name */
+ buf[fl++] = '(';
+ buf[fl++] = ')';
- /* in case func is too big, nullify EL_FUNCLEN_MAXth character,
- * to prevent strlen showing bad results, 1 is because of
- * previous ':'/'[' characters
- */
-
- buf[1 + EL_FUNCLEN_MAX] = '\0';
- fl = strlen(buf);
-
- /* and add leading "()" to indicate it is a function name
- */
-
- buf[fl++] = '(';
- buf[fl++] = ')';
-
- /* close ']' bracket, it doesn't matter if finfo is enabled or
- * not, we print always print last so it's our responsibility
- * to close it
- */
-
- buf[fl++] = ']';
- return fl;
+ /* close ']' bracket, it doesn't matter if finfo is enabled or
+ * not, we print always print last so it's our responsibility
+ * to close it */
+ buf[fl++] = ']';
+ return fl;
#else
- (void)el;
- (void)buf;
- (void)func;
- return 0;
+ (void)el;
+ (void)buf;
+ (void)func;
+ return 0;
#endif
}
@@ -316,24 +275,24 @@ static size_t el_funcinfo
/* public api */ int el_print
(
- const char *file, /* file name where log is printed */
- size_t num, /* line number where log is printed */
- const char *func, /* function name to print */
- enum el_level level, /* log level to print message with */
- const char *fmt, /* message format (see printf (3)) */
- ... /* additional parameters for fmt */
+ const char *file, /* file name where log is printed */
+ size_t num, /* line number where log is printed */
+ const char *func, /* function name to print */
+ enum el_level level, /* log level to print message with */
+ const char *fmt, /* message format (see printf (3)) */
+ ... /* additional parameters for fmt */
)
{
- va_list ap; /* arguments '...' for 'fmt' */
- int rc; /* return code from el_printfv() */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ va_list ap; /* arguments '...' for 'fmt' */
+ int rc; /* return code from el_printfv() */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- va_start(ap, fmt);
- rc = el_ovprint(file, num, func, level, &g_el, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ rc = el_ovprint(file, num, func, level, &g_el, fmt, ap);
+ va_end(ap);
- return rc;
+ return rc;
}
@@ -344,25 +303,25 @@ static size_t el_funcinfo
/* public api */ int el_oprint
(
- const char *file, /* file name to print in log */
- size_t num, /* line number to print in log */
- const char *func, /* function name to print */
- enum el_level level, /* log level to print log with */
- struct el *el, /* printing style el */
- const char *fmt, /* message format (man printf) */
- ... /* additional params for fmt */
+ const char *file, /* file name to print in log */
+ size_t num, /* line number to print in log */
+ const char *func, /* function name to print */
+ enum el_level level, /* log level to print log with */
+ struct el *el, /* printing style el */
+ const char *fmt, /* message format (man printf) */
+ ... /* additional params for fmt */
)
{
- va_list ap; /* arguments '...' for 'fmt' */
- int rc; /* return code from el_printfv() */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ va_list ap; /* arguments '...' for 'fmt' */
+ int rc; /* return code from el_printfv() */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- va_start(ap, fmt);
- rc = el_ovprint(file, num, func, level, el, fmt, ap);
- va_end(ap);
+ va_start(ap, fmt);
+ rc = el_ovprint(file, num, func, level, el, fmt, ap);
+ va_end(ap);
- return rc;
+ return rc;
}
@@ -373,24 +332,24 @@ static size_t el_funcinfo
int el_oprint_nb
(
- const char *file, /* file name to print in log */
- size_t num, /* line number to print in log */
- const char *func, /* function name to print */
- enum el_level level, /* log level to print log with */
- struct el *el, /* printing style el */
- const char *fmt, /* message format (man printf) */
- ... /* additional params for fmt */
+ const char *file, /* file name to print in log */
+ size_t num, /* line number to print in log */
+ const char *func, /* function name to print */
+ enum el_level level, /* log level to print log with */
+ struct el *el, /* printing style el */
+ const char *fmt, /* message format (man printf) */
+ ... /* additional params for fmt */
)
{
- va_list ap; /* arguments '...' for 'fmt' */
- int ret; /* return code from el_printfv() */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ va_list ap; /* arguments '...' for 'fmt' */
+ int ret; /* return code from el_printfv() */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- va_start(ap, fmt);
- ret = el_ovprint_nb(file, num, func, level, el, fmt, ap);
- va_end(ap);
- return ret;
+ va_start(ap, fmt);
+ ret = el_ovprint_nb(file, num, func, level, el, fmt, ap);
+ va_end(ap);
+ return ret;
}
@@ -401,15 +360,15 @@ int el_oprint_nb
/* public api */ int el_vprint
(
- const char *file, /* file name where log is printed */
- size_t num, /* line number where log is printed */
- const char *func, /* function name to print */
- enum el_level level, /* log level to print message with */
- const char *fmt, /* message format (see printf (3)) */
- va_list ap /* additional parameters for fmt */
+ const char *file, /* file name where log is printed */
+ size_t num, /* line number where log is printed */
+ const char *func, /* function name to print */
+ enum el_level level, /* log level to print message with */
+ const char *fmt, /* message format (see printf (3)) */
+ va_list ap /* additional parameters for fmt */
)
{
- return el_ovprint(file, num, func, level, &g_el, fmt, ap);
+ return el_ovprint(file, num, func, level, &g_el, fmt, ap);
}
@@ -420,24 +379,24 @@ int el_oprint_nb
/* public api */ int el_ovprint
(
- const char *file, /* file name to print in log */
- size_t num, /* line number to print in log */
- const char *func, /* function name to print */
- enum el_level level, /* log level to print log with */
- struct el *el, /* el defining print style */
- const char *fmt, /* message format (man printf) */
- va_list ap /* additional params for fmt */
+ const char *file, /* file name to print in log */
+ size_t num, /* line number to print in log */
+ const char *func, /* function name to print */
+ enum el_level level, /* log level to print log with */
+ struct el *el, /* el defining print style */
+ const char *fmt, /* message format (man printf) */
+ va_list ap /* additional params for fmt */
)
{
- int ret; /* return from el_ovprint_nb() */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int ret; /* return from el_ovprint_nb() */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- VALID(EINVAL, el);
- el_lock(el);
- ret = el_ovprint_nb(file, num, func, level, el, fmt, ap);
- el_unlock(el);
- return ret;
+ VALID(EINVAL, el);
+ el_lock(el);
+ ret = el_ovprint_nb(file, num, func, level, el, fmt, ap);
+ el_unlock(el);
+ return ret;
}
@@ -459,151 +418,116 @@ int el_oprint_nb
int el_ovprint_nb
(
- const char *file, /* file name to print in log */
- size_t num, /* line number to print in log */
- const char *func, /* function name to print */
- enum el_level level, /* log level to print log with */
- struct el *el, /* el defining print style */
- const char *fmt, /* message format (man printf) */
- va_list ap /* additional params for fmt */
+ const char *file, /* file name to print in log */
+ size_t num, /* line number to print in log */
+ const char *func, /* function name to print */
+ enum el_level level, /* log level to print log with */
+ struct el *el, /* el defining print style */
+ const char *fmt, /* message format (man printf) */
+ va_list ap /* additional params for fmt */
)
{
- char buf[EL_BUF_MAX + 2]; /* buffer for message to print */
- size_t w; /* bytes written to buf */
- size_t flen; /* length of the fmt output */
- int e; /* error code */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- VALID(EINVAL, fmt);
- VALID(EINVAL, el);
- VALID(ERANGE, el_log_allowed(el, level));
- VALID(ENODEV, el->outputs);
-
- e = 0;
-
- if (level > EL_DBG)
- {
- /* level is larger than predefined and we don't have colors
- * for those log levels, so we force colors to be of EL_DBG
- * level, since every level larger than EL_DBG is threaded
- * as more verbose debug anyway.
- */
-
- level = EL_DBG;
- }
-
- /* add preamble and colors to log line buf
- */
-
- buf[0] = '\0';
- w = el_color(el, buf, level);
- w += el_timestamp(el, buf + w, TS_STRING);
- w += el_finfo(el, buf + w, file, num);
- w += el_funcinfo(el, buf + w, func);
-
- if (w != 0 && buf[w - 1] == ']')
- {
- /* at least one preamble has been added, add space beetween
- * current preamble and log level
- */
-
- *(buf + w) = ' ';
- ++w;
- }
-
- if (el->print_log_level)
- {
- w += sprintf(buf + w, "%c/", char_level[level]);
- }
+ char buf[EL_BUF_MAX + 2]; /* buffer for message to print */
+ size_t w; /* bytes written to buf */
+ size_t flen; /* length of the fmt output */
+ int e; /* error code */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-#if ENABLE_PREFIX
- if (el->prefix)
- {
- /* there is a case where buf[w] will point to something
- * different than '\0'. This is not wrong but will confuse
- * strncat function and logs will be printed incorectly.
- */
-
- buf[w] = '\0';
- strncat(buf + w, el->prefix, EL_PREFIX_LEN);
-
- if ((flen = strlen(el->prefix)) > EL_PREFIX_LEN)
- {
- /* dodge a bullet - overflow would have occured
- */
-
- flen = EL_PREFIX_LEN;
- }
-
- w += flen;
- }
-#endif
-
- /* add requested log from format, we add + 1 to include null
- * termination
- */
-
- flen = vsnprintf(buf + w, EL_LOG_MAX + 1, fmt, ap);
-
- if (flen > EL_LOG_MAX)
- {
- /* overflow would have occur, not all bytes have been
- * copied, output will truncated. Correct flen to number of
- * bytes actually stored in buf.
- */
-
- flen = EL_LOG_MAX;
- e = ENOBUFS;
- }
-
- w += flen;
- /* add terminal formatting reset sequence
- */
+ VALID(EINVAL, fmt);
+ VALID(EINVAL, el);
+ VALID(ERANGE, el_log_allowed(el, level));
+ VALID(ENODEV, el->outputs);
- w += el_color(el, buf + w, 8 /* reset colors */);
+ e = 0;
- if (el->print_newline)
- {
- /* add new line to log
- */
+ /* in case when level is larger than predefined max level
+ * (debug), we don't have colors for those log levels, so we
+ * force colors to be of EL_DBG level, since every level larger
+ * than EL_DBG is threaded as more verbose debug anyway. */
+ if (level > EL_DBG) level = EL_DBG;
- buf[w++] = '\n';
- }
+ /* add preamble and colors to log line buf */
+ buf[0] = '\0';
+ w = el_color(el, buf, level);
+ w += el_timestamp(el, buf + w, TS_STRING);
+ w += el_finfo(el, buf + w, file, num);
+ w += el_funcinfo(el, buf + w, func);
- buf[w++] = '\0';
+ /* if at least one preamble has been added, add
+ * space beetween current preamble and log level */
+ if (w != 0 && buf[w - 1] == ']') *(buf + w++) = ' ';
- /* some modules (like el-file) needs to know level of message
- * they are printing, and such information may not be available
- * from string, thus we set it here in a 'object global'
- * variable
- */
+ if (el->print_log_level)
+ w += sprintf(buf + w, "%c/", char_level[level]);
- el->level_current_msg = level;
-
- if (el_oputs_nb(el, buf) != 0)
- {
- el->level_current_msg = EL_DBG;
- return -1;
- }
-
- /* after message is printed set current messasge level to
- * debug, as next call might be using el_puts, which does not
- * contain log level, and we thread all el_puts messages as
- * they were debug. Note, it does not apply to log filtering,
- * el_puts does not filter messages, but modules like el-file,
- * will need this information to determin wheter fsync() data
- * to file or not.
- */
-
- el->level_current_msg = EL_DBG;
-
- if (e)
- {
- errno = e;
- return -1;
- }
+#if ENABLE_PREFIX
+ if (el->prefix)
+ {
+ /* there is a case where buf[w] will point to something
+ * different than '\0'. This is not wrong but will confuse
+ * strncat function and logs will be printed incorectly. */
+ buf[w] = '\0';
+ strncat(buf + w, el->prefix, EL_PREFIX_LEN);
+
+ /* if user's prefix is too long, strncat() will not copy
+ * all of it from el->prefix - note that in flen. */
+ if ((flen = strlen(el->prefix)) > EL_PREFIX_LEN)
+ flen = EL_PREFIX_LEN;
+
+ w += flen;
+ }
+#endif
- return 0;
+ /* add requested log from format, we add + 1 to include null
+ * termination */
+ flen = vsnprintf(buf + w, EL_LOG_MAX + 1, fmt, ap);
+
+ if (flen > EL_LOG_MAX)
+ {
+ /* overflow would have occured, not all bytes have been
+ * copied, output will truncated. Correct flen to number of
+ * bytes actually stored in buf. */
+
+ flen = EL_LOG_MAX;
+ e = ENOBUFS;
+ }
+
+ w += flen;
+
+ /* add terminal formatting reset sequence */
+ w += el_color(el, buf + w, 8 /* reset colors */);
+
+ /* terminate log line */
+ if (el->print_newline) buf[w++] = '\n';
+ buf[w++] = '\0';
+
+ /* some modules (like el-file) needs to know level of message
+ * they are printing, and such information may not be available
+ * from string, thus we set it here in a 'object global'
+ * variable */
+ el->level_current_msg = level;
+
+ if (el_oputs_nb(el, buf) != 0)
+ {
+ el->level_current_msg = EL_DBG;
+ return -1;
+ }
+
+ /* after message is printed set current messasge level to
+ * debug, as next call might be using el_puts, which does not
+ * contain log level, and we thread all el_puts messages as
+ * they were debug. Note, it does not apply to log filtering,
+ * el_puts does not filter messages, but modules like el-file,
+ * will need this information to determin wheter fsync() data
+ * to file or not. */
+ el->level_current_msg = EL_DBG;
+
+ if (e)
+ {
+ errno = e;
+ return -1;
+ }
+
+ return 0;
}
diff --git a/src/el-private.h b/src/el-private.h
index 93cc6f5..240ba2f 100644
--- a/src/el-private.h
+++ b/src/el-private.h
@@ -19,8 +19,8 @@
# include <stddef.h>
# include <stdarg.h>
- int snprintf(char *str, size_t str_m, const char *fmt, ...);
- int vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap);
+int snprintf(char *str, size_t str_m, const char *fmt, ...);
+int vsnprintf(char *str, size_t str_m, const char *fmt, va_list ap);
#endif
@@ -323,9 +323,9 @@ int el_file_flush(struct el *el);
int el_oputb_nb(struct el *el, const void *mem, size_t mlen);
int el_oputs_nb(struct el *el, const char *s);
int el_ovprint_nb(const char *file, size_t num, const char *func,
- enum el_level level, struct el *el, const char *fmt, va_list ap);
+ enum el_level level, struct el *el, const char *fmt, va_list ap);
int el_oprint_nb(const char *file, size_t num, const char *func,
- enum el_level level, struct el *el, const char *fmt, ...);
+ enum el_level level, struct el *el, const char *fmt, ...);
#if ENABLE_PTHREAD
diff --git a/src/el-puts.c b/src/el-puts.c
index 1ddb42c..0a6b9bb 100644
--- a/src/el-puts.c
+++ b/src/el-puts.c
@@ -52,10 +52,10 @@
/* public api */ int el_puts
(
- const char *s /* string to put into output */
+ const char *s /* string to put into output */
)
{
- return el_oputs(&g_el, s);
+ return el_oputs(&g_el, s);
}
@@ -66,18 +66,18 @@
/* public api */ int el_oputs
(
- struct el *el, /* el defining printing style */
- const char *s /* string to put into output */
+ struct el *el, /* el defining printing style */
+ const char *s /* string to put into output */
)
{
- int ret; /* return from el_oputs_nb() */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int ret; /* return from el_oputs_nb() */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- el_lock(el);
- ret = el_oputs_nb(el, s);
- el_unlock(el);
- return ret;
+ el_lock(el);
+ ret = el_oputs_nb(el, s);
+ el_unlock(el);
+ return ret;
}
@@ -90,69 +90,56 @@
int el_oputs_nb
(
- struct el *el, /* el defining printing style */
- const char *s /* string to put into output */
+ struct el *el, /* el defining printing style */
+ const char *s /* string to put into output */
)
{
- int rv; /* return value from function */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int rv; /* return value from function */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- VALID(EINVAL, s);
- VALID(EINVAL, el);
- VALID(ENODEV, el->outputs != 0);
- rv = 0;
+ VALID(EINVAL, s);
+ VALID(EINVAL, el);
+ VALID(ENODEV, el->outputs != 0);
+
+ rv = 0;
#if ENABLE_OUT_STDERR
- if (el->outputs & EL_OUT_STDERR)
- {
- rv |= fputs(s, stderr) == EOF ? -1 : 0;
- }
+ if (el->outputs & EL_OUT_STDERR)
+ rv |= fputs(s, stderr) == EOF ? -1 : 0;
#endif
#if ENABLE_OUT_STDERR
- if (el->outputs & EL_OUT_STDOUT)
- {
- rv |= fputs(s, stdout) == EOF ? -1 : 0;
- }
+ if (el->outputs & EL_OUT_STDOUT)
+ rv |= fputs(s, stdout) == EOF ? -1 : 0;
#endif
#if ENABLE_OUT_SYSLOG
- if (el->outputs & EL_OUT_SYSLOG)
- {
- syslog(el->level, s);
- }
+ if (el->outputs & EL_OUT_SYSLOG)
+ syslog(el->level, s);
#endif
#if ENABLE_OUT_FILE
- if (el->outputs & EL_OUT_FILE)
- {
- rv |= el_file_puts(el, s);
- }
+ if (el->outputs & EL_OUT_FILE)
+ rv |= el_file_puts(el, s);
#endif
#if 0
- if (el->outputs & EL_OUT_NET)
- {
- el_puts_net(s);
- }
+ if (el->outputs & EL_OUT_NET)
+ el_puts_net(s);
#endif
#if ENABLE_OUT_TTY
- if (el->outputs & EL_OUT_TTY)
- {
- rv |= el_tty_puts(el, s);
- }
+ if (el->outputs & EL_OUT_TTY)
+ rv |= el_tty_puts(el, s);
#endif
#if ENABLE_OUT_CUSTOM
- if (el->outputs & EL_OUT_CUSTOM && el->custom_put)
- {
- rv |= el->custom_put(s, strlen(s) + 1, el->custom_put_user);
- }
+ if (el->outputs & EL_OUT_CUSTOM && el->custom_put)
+ rv |= el->custom_put(s, strlen(s) + 1, el->custom_put_user);
#endif
- return rv;
+ return rv;
}
@@ -164,11 +151,11 @@ int el_oputs_nb
/* public api */ int el_putb
(
- const void *mem, /* memory location to 'print' */
- size_t mlen /* size of the mem buffer */
+ const void *mem, /* memory location to 'print' */
+ size_t mlen /* size of the mem buffer */
)
{
- return el_oputb(&g_el, mem, mlen);
+ return el_oputb(&g_el, mem, mlen);
}
@@ -179,19 +166,19 @@ int el_oputs_nb
/* public api */ int el_oputb
(
- struct el *el, /* el defining printing style */
- const void *mem, /* memory location to 'print' */
- size_t mlen /* size of the mem buffer */
+ struct el *el, /* el defining printing style */
+ const void *mem, /* memory location to 'print' */
+ size_t mlen /* size of the mem buffer */
)
{
- int ret; /* return value from el_oputb_nb() */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int ret; /* return value from el_oputb_nb() */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- el_lock(el);
- ret = el_oputb_nb(el, mem, mlen);
- el_unlock(el);
- return ret;
+ el_lock(el);
+ ret = el_oputb_nb(el, mem, mlen);
+ el_unlock(el);
+ return ret;
}
@@ -205,49 +192,48 @@ int el_oputs_nb
int el_oputb_nb
(
- struct el *el, /* el defining printing style */
- const void *mem, /* memory location to 'print' */
- size_t mlen /* size of the mem buffer */
+ struct el *el, /* el defining printing style */
+ const void *mem, /* memory location to 'print' */
+ size_t mlen /* size of the mem buffer */
)
{
- int rv; /* return value from function */
- int called; /* at least one output was called */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int rv; /* return value from function */
+ int called; /* at least one output was called */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- VALID(EINVAL, mem);
- VALID(EINVAL, mlen);
- VALID(EINVAL, el);
- VALID(ENODEV, el->outputs != 0);
+ VALID(EINVAL, mem);
+ VALID(EINVAL, mlen);
+ VALID(EINVAL, el);
+ VALID(ENODEV, el->outputs != 0);
- rv = 0;
- called = 0;
+ rv = 0;
+ called = 0;
#if ENABLE_OUT_FILE
- if (el->outputs & EL_OUT_FILE)
- {
- called = 1;
- rv |= el_file_putb(el, mem, mlen);
- }
+ if (el->outputs & EL_OUT_FILE)
+ {
+ called = 1;
+ rv |= el_file_putb(el, mem, mlen);
+ }
#endif
#if ENABLE_OUT_CUSTOM
- if (el->outputs & EL_OUT_CUSTOM && el->custom_put)
- {
- called = 1;
- rv |= el->custom_put(mem, mlen, el->custom_put_user);
- }
+ if (el->outputs & EL_OUT_CUSTOM && el->custom_put)
+ {
+ called = 1;
+ rv |= el->custom_put(mem, mlen, el->custom_put_user);
+ }
#endif
- if (called == 0)
- {
- /* couldn't find any supported output for binary logging
- */
-
- errno = ENODEV;
- return -1;
- }
+ if (called == 0)
+ {
+ /* couldn't find any supported output for
+ * binary logging */
+ errno = ENODEV;
+ return -1;
+ }
- return rv;
+ return rv;
}
diff --git a/src/el-syslog.c b/src/el-syslog.c
index 390605e..8b24f69 100644
--- a/src/el-syslog.c
+++ b/src/el-syslog.c
@@ -49,86 +49,82 @@
int el_tty_open
(
- struct el *el, /* store serial file descriptor here */
- const char *dev, /* device to open like /dev/ttyS0 */
- speed_t speed /* serial port baud rate */
+ struct el *el, /* store serial file descriptor here */
+ const char *dev, /* device to open like /dev/ttyS0 */
+ speed_t speed /* serial port baud rate */
)
{
- struct termios tty; /* serial port settings */
- int e; /* holder for errno */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ struct termios tty; /* serial port settings */
+ int e; /* holder for errno */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- /*
- * it is possible to reopen serial device (like changing output device
- * with EL_TTY_DEV again) during runtime, so we need to close previous
- * socket first
- */
+ /* it is possible to reopen serial device (like changing output device
+ * with EL_TTY_DEV again) during runtime, so we need to close previous
+ * socket first */
- el_tty_close(el);
+ el_tty_close(el);
- if ((el->serial_fd = open(dev, O_WRONLY | O_NOCTTY | O_SYNC)) < 0)
- {
- return -1;
- }
+ if ((el->serial_fd = open(dev, O_WRONLY | O_NOCTTY | O_SYNC)) < 0)
+ return -1;
#if HAVE_TERMIOS_H
- /*
- * if termios is not available, simply open device without reconfiguring
- * it. Some embedded OSes might configure tty during compilation and
- * have termios disabled to save memory.
- */
-
- if (speed == B0)
- {
- /*
- * normally with B0 we should terminate transmission, it is used
- * with modem lines, but since we do not use modem lines, and in
- * logger terminating connection does not make any sense, we use
- * this to tell embedlog *not* to change any settings but only open
- * serial
- */
-
- return 0;
- }
-
- if (tcgetattr(el->serial_fd, &tty) != 0)
- {
- goto error;
- }
-
- if (cfsetispeed(&tty, speed) != 0)
- {
- goto error;
- }
-
- tty.c_cflag &= ~CSIZE; /* apply size mask */
- tty.c_cflag |= CS8; /* 8bit transmission */
- tty.c_cflag &= ~PARENB; /* no parity check */
- tty.c_cflag &= ~CSTOPB; /* set one stop bit */
-
- tty.c_cflag |= CLOCAL; /* ignore modem lines */
- tty.c_cflag &= ~CREAD; /* disable receiver - we only send data */
- tty.c_oflag |= OPOST | ONLCR; /* enable output post-processing by OS */
-
- if (tcsetattr(el->serial_fd, TCSANOW, &tty) != 0)
- {
- goto error;
- }
-
- return 0;
+ /*
+ * if termios is not available, simply open device without reconfiguring
+ * it. Some embedded OSes might configure tty during compilation and
+ * have termios disabled to save memory.
+ */
+
+ if (speed == B0)
+ {
+ /*
+ * normally with B0 we should terminate transmission, it is used
+ * with modem lines, but since we do not use modem lines, and in
+ * logger terminating connection does not make any sense, we use
+ * this to tell embedlog *not* to change any settings but only open
+ * serial
+ */
+
+ return 0;
+ }
+
+ if (tcgetattr(el->serial_fd, &tty) != 0)
+ {
+ goto error;
+ }
+
+ if (cfsetispeed(&tty, speed) != 0)
+ {
+ goto error;
+ }
+
+ tty.c_cflag &= ~CSIZE; /* apply size mask */
+ tty.c_cflag |= CS8; /* 8bit transmission */
+ tty.c_cflag &= ~PARENB; /* no parity check */
+ tty.c_cflag &= ~CSTOPB; /* set one stop bit */
+
+ tty.c_cflag |= CLOCAL; /* ignore modem lines */
+ tty.c_cflag &= ~CREAD; /* disable receiver - we only send data */
+ tty.c_oflag |= OPOST | ONLCR; /* enable output post-processing by OS */
+
+ if (tcsetattr(el->serial_fd, TCSANOW, &tty) != 0)
+ {
+ goto error;
+ }
+
+ return 0;
error:
- e = errno;
- close(el->serial_fd);
- el->serial_fd = -1;
- errno = e;
- return -1;
+ e = errno;
+ close(el->serial_fd);
+ el->serial_fd = -1;
+ errno = e;
+ return -1;
#else
- (void)tty;
- (void)e;
- return 0;
+ (void)tty;
+ (void)e;
+ return 0;
#endif
}
diff --git a/src/el-ts.c b/src/el-ts.c
index 39166f6..6bee5dd 100644
--- a/src/el-ts.c
+++ b/src/el-ts.c
@@ -53,24 +53,25 @@
static void el_ts_clock
(
- time_t *s, /* seconds will be stored here */
- long *ns /* nanoseconds will be stored here */
+ time_t *s, /* seconds will be stored here */
+ long *ns /* nanoseconds will be stored here */
)
{
- clock_t clk; /* clock value */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ clock_t clk; /* clock value */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- clk = clock();
+ clk = clock();
- *s = clk / CLOCKS_PER_SEC;
- *ns = clk % CLOCKS_PER_SEC; /* [cps] */
- *ns *= (1000000L / CLOCKS_PER_SEC); /* [ms] */
- *ns *= 1000L; /* [ns] */
+ *s = clk / CLOCKS_PER_SEC;
+ *ns = clk % CLOCKS_PER_SEC; /* [cps] */
+ *ns *= (1000000L / CLOCKS_PER_SEC); /* [ms] */
+ *ns *= 1000L; /* [ns] */
}
#endif /* ENABLE_CLOCK */
#endif /* ENABLE_TIMESTAMP */
+
/* ==========================================================================
returns seconds and nanoseconds calculated from time() function.
========================================================================== */
@@ -80,12 +81,12 @@ static void el_ts_clock
static void el_ts_time
(
- time_t *s, /* seconds will be stored here */
- long *ns /* nanoseconds will be stored here */
+ time_t *s, /* seconds will be stored here */
+ long *ns /* nanoseconds will be stored here */
)
{
- *s = time(NULL);
- *ns = 0;
+ *s = time(NULL);
+ *ns = 0;
}
#endif /* ENABLE_TIMESTAMP */
@@ -100,18 +101,18 @@ static void el_ts_time
static void el_ts_clock_gettime
(
- time_t *s, /* seconds will be stored here */
- long *ns, /* nanoseconds will be stored here */
- clockid_t clkid /* clock id */
+ time_t *s, /* seconds will be stored here */
+ long *ns, /* nanoseconds will be stored here */
+ clockid_t clkid /* clock id */
)
{
- struct timespec tp; /* clock value */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ struct timespec tp; /* clock value */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- clock_gettime(clkid, &tp);
+ clock_gettime(clkid, &tp);
- *s = tp.tv_sec;
- *ns = tp.tv_nsec;
+ *s = tp.tv_sec;
+ *ns = tp.tv_nsec;
}
#endif /* ENABLE_REALTIME || ENABLE_MONOTONIC */
@@ -128,205 +129,181 @@ static void el_ts_clock_gettime
size_t el_timestamp
(
- struct el *el, /* el defining printing style */
- void *b, /* buffer where timestamp will be stored */
- int binary /* 1 if timestamp should be binary */
+ struct el *el, /* el defining printing style */
+ void *b, /* buffer where timestamp will be stored */
+ int binary /* 1 if timestamp should be binary */
)
{
#if ENABLE_TIMESTAMP
- time_t s; /* timestamp seconds */
- long ns; /* timestamp nanoseconds */
- size_t tl; /* timestamp length */
- char *buf; /* b threated as known type */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- if (el->timestamp == EL_TS_OFF)
- {
- /* user doesn't want us to print timestamp, that's fine
- */
+ time_t s; /* timestamp seconds */
+ long ns; /* timestamp nanoseconds */
+ size_t tl; /* timestamp length */
+ char *buf; /* b threated as known type */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- return 0;
- }
+ if (el->timestamp == EL_TS_OFF) return 0;
- buf = b;
+ buf = b;
- /* first we get seconds and nanoseconds from proper timer
- */
-
- switch (el->timestamp_timer)
- {
+ /* first we get seconds and nanoseconds from proper timer */
+ switch (el->timestamp_timer)
+ {
# if ENABLE_REALTIME
- case EL_TS_TM_REALTIME:
- el_ts_clock_gettime(&s, &ns, CLOCK_REALTIME);
- break;
+ case EL_TS_TM_REALTIME:
+ el_ts_clock_gettime(&s, &ns, CLOCK_REALTIME);
+ break;
# endif
# if ENABLE_MONOTONIC
- case EL_TS_TM_MONOTONIC:
- el_ts_clock_gettime(&s, &ns, CLOCK_MONOTONIC);
- break;
+ case EL_TS_TM_MONOTONIC:
+ el_ts_clock_gettime(&s, &ns, CLOCK_MONOTONIC);
+ break;
# endif
- case EL_TS_TM_TIME:
- el_ts_time(&s, &ns);
- break;
+ case EL_TS_TM_TIME:
+ el_ts_time(&s, &ns);
+ break;
# if ENABLE_CLOCK
- case EL_TS_TM_CLOCK:
- el_ts_clock(&s, &ns);
- break;
+ case EL_TS_TM_CLOCK:
+ el_ts_clock(&s, &ns);
+ break;
# endif
- default:
- /* bad timer means no timer
- */
-
- return 0;
- }
+ default:
+ /* bad timer means no timer */
+ return 0;
+ }
# if ENABLE_BINARY_LOGS
- if (binary)
- {
- /* put encoded seconds timestamp in buf
- */
+ if (binary)
+ {
+ /* put encoded seconds timestamp in buf
+ */
# ifdef LLONG_MAX
- tl = el_encode_number((unsigned long long)s, (unsigned char *)buf);
+ tl = el_encode_number((unsigned long long)s, (unsigned char *)buf);
# else
- tl = el_encode_number((unsigned long)s, (unsigned char*)buf);
+ tl = el_encode_number((unsigned long)s, (unsigned char*)buf);
# endif
- /* put encoded nano/micro/milli seconds in buf if enabled
- */
+ /* put encoded nano/micro/milli seconds in buf if enabled */
# if ENABLE_FRACTIONS
- switch (el->timestamp_fractions)
- {
- case EL_TS_FRACT_OFF:
- /* we don't add fractions, so simply return what has
- * been already stored (only seconds)
- */
+ switch (el->timestamp_fractions)
+ {
+ case EL_TS_FRACT_OFF:
+ /* we don't add fractions, so simply return what has
+ * been already stored (only seconds) */
+ return tl;
- return tl;
+ case EL_TS_FRACT_MS:
+ tl += el_encode_number(ns / 1000000, buf + tl);
+ return tl;
- case EL_TS_FRACT_MS:
- tl += el_encode_number(ns / 1000000, buf + tl);
- return tl;
+ case EL_TS_FRACT_US:
+ tl += el_encode_number(ns / 1000, buf + tl);
+ return tl;
- case EL_TS_FRACT_US:
- tl += el_encode_number(ns / 1000, buf + tl);
- return tl;
+ case EL_TS_FRACT_NS:
+ tl += el_encode_number(ns, buf + tl);
+ return tl;
- case EL_TS_FRACT_NS:
- tl += el_encode_number(ns, buf + tl);
- return tl;
-
- default:
- /* something went somehere seriously wrong, act like no
- * timestamp has been configured
- */
-
- return 0;
- }
+ default:
+ /* something went somehere seriously wrong, act like no
+ * timestamp has been configured */
+ return 0;
+ }
# else /* ENABLE_FRACTIONS */
- return tl;
+ return tl;
# endif /* ENABLE_FRACTIONS */
- }
- else
+ }
+ else
# endif /* ENABLE_BINARY_LOGS */
- {
- /* then convert retrieved time into string timestamp
- */
-
- if (el->timestamp == EL_TS_LONG)
- {
- struct tm tm; /* timestamp splitted */
- struct tm *tmp; /* timestamp splitted pointer */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ {
+ /* then convert retrieved time into string timestamp */
+ if (el->timestamp == EL_TS_LONG)
+ {
+ struct tm tm; /* timestamp splitted */
+ struct tm *tmp; /* timestamp splitted pointer */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
# if ENABLE_REENTRANT
- tmp = gmtime_r(&s, &tm);
+ tmp = gmtime_r(&s, &tm);
# else
- tmp = gmtime(&s);
+ tmp = gmtime(&s);
# endif
- tl = strftime(buf, 21, "[%Y-%m-%d %H:%M:%S", tmp);
- }
- else
- {
+ tl = strftime(buf, 21, "[%Y-%m-%d %H:%M:%S", tmp);
+ }
+ else
+ {
# ifdef LLONG_MAX
- tl = sprintf(buf, "[%lld", (long long)s);
+ tl = sprintf(buf, "[%lld", (long long)s);
# else
- /* if long long is not available, code may be suscible
- * to 2038 bug. If you are sure your compiler does
- * support long long type, but doesn't define
- * LLONG_MAX, define this value to enable long long.
- */
-
- tl = sprintf(buf, "[%ld", (long)s);
+ /* if long long is not available, code may be suscible
+ * to 2038 bug. If you are sure your compiler does
+ * support long long type, but doesn't define
+ * LLONG_MAX, define this value to enable long long. */
+ tl = sprintf(buf, "[%ld", (long)s);
# endif
- }
+ }
- /* if requested, add proper fractions of seconds
- */
# if ENABLE_FRACTIONS
- switch (el->timestamp_fractions)
- {
- case EL_TS_FRACT_OFF:
- /* we don't add fractions, so simply close opening
- * bracker '['
- */
-
- buf[tl++] = ']';
- return tl;
-
- case EL_TS_FRACT_MS:
- tl += sprintf(buf + tl, ".%03ld]", ns / 1000000);
- return tl;
-
- case EL_TS_FRACT_US:
- tl += sprintf(buf + tl, ".%06ld]", ns / 1000);
- return tl;
-
- case EL_TS_FRACT_NS:
- tl += sprintf(buf + tl, ".%09ld]", ns);
- return tl;
-
- default:
- /* something went somehere seriously wrong, act like no
- * timestamp has been configured
- */
-
- return 0;
- }
+ /* if requested, add proper fractions of seconds */
+ switch (el->timestamp_fractions)
+ {
+ case EL_TS_FRACT_OFF:
+ /* we don't add fractions, so simply close opening
+ * bracker '[' */
+ buf[tl++] = ']';
+ return tl;
+
+ case EL_TS_FRACT_MS:
+ tl += sprintf(buf + tl, ".%03ld]", ns / 1000000);
+ return tl;
+
+ case EL_TS_FRACT_US:
+ tl += sprintf(buf + tl, ".%06ld]", ns / 1000);
+ return tl;
+
+ case EL_TS_FRACT_NS:
+ tl += sprintf(buf + tl, ".%09ld]", ns);
+ return tl;
+
+ default:
+ /* something went somehere seriously wrong, act like no
+ * timestamp has been configured */
+ return 0;
+ }
# else /* ENABLE_FRACTIONS */
- buf[tl++] = ']';
- return tl;
+ buf[tl++] = ']';
+ return tl;
# endif /* ENABLE_FRACTIONS */
- }
+ }
#else /* ENABLE_TIMESTAMP */
- (void)el;
- (void)b;
- (void)binary;
- return 0;
+ (void)el;
+ (void)b;
+ (void)binary;
+ return 0;
#endif /* ENABLE_TIMESTAMP */
}
diff --git a/src/el-tty.c b/src/el-tty.c
index c43f3c9..42f335b 100644
--- a/src/el-tty.c
+++ b/src/el-tty.c
@@ -56,83 +56,63 @@
int el_tty_open
(
- struct el *el, /* store serial file descriptor here */
- const char *dev, /* device to open like /dev/ttyS0 */
- unsigned int speed /* serial port baud rate */
+ struct el *el, /* store serial file descriptor here */
+ const char *dev, /* device to open like /dev/ttyS0 */
+ unsigned int speed /* serial port baud rate */
)
{
#if HAVE_TERMIOS_H
- struct termios tty; /* serial port settings */
- int e; /* holder for errno */
+ struct termios tty; /* serial port settings */
+ int e; /* holder for errno */
#endif
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- /* it is possible to reopen serial device (like changing output
- * device with EL_TTY_DEV again) during runtime, so we need to
- * close previous socket first
- */
+ /* it is possible to reopen serial device (like changing output
+ * device with EL_TTY_DEV again) during runtime, so we need to
+ * close previous socket first */
+ el_tty_close(el);
+ if ((el->serial_fd = open(dev, O_WRONLY | O_NOCTTY | O_SYNC)) < 0)
+ return -1;
- el_tty_close(el);
+#if HAVE_TERMIOS_H
- if ((el->serial_fd = open(dev, O_WRONLY | O_NOCTTY | O_SYNC)) < 0)
- {
- return -1;
- }
+ /* normally with B0 we should terminate transmission, it is
+ * used with modem lines, but since we do not use modem
+ * lines, and in logger terminating connection does not
+ * make any sense, we use this to tell embedlog *not* to
+ * change any settings but only open serial */
+ if (speed == B0) return 0;
-#if HAVE_TERMIOS_H
- /* if termios is not available, simply open device without
- * reconfiguring it. Some embedded OSes might configure tty
- * during compilation and have termios disabled to save memory.
- */
-
- if (speed == B0)
- {
- /* normally with B0 we should terminate transmission, it is
- * used with modem lines, but since we do not use modem
- * lines, and in logger terminating connection does not
- * make any sense, we use this to tell embedlog *not* to
- * change any settings but only open serial
- */
-
- return 0;
- }
-
- if (tcgetattr(el->serial_fd, &tty) != 0)
- {
- goto error;
- }
-
- if (cfsetispeed(&tty, (speed_t)speed) != 0)
- {
- goto error;
- }
-
- tty.c_cflag &= ~CSIZE; /* apply size mask */
- tty.c_cflag |= CS8; /* 8bit transmission */
- tty.c_cflag &= ~PARENB; /* no parity check */
- tty.c_cflag &= ~CSTOPB; /* set one stop bit */
-
- tty.c_cflag |= CLOCAL; /* ignore modem lines */
- tty.c_cflag &= ~CREAD; /* disable receiver - we only send data */
- tty.c_oflag |= OPOST | ONLCR; /* enable output post-processing by OS */
-
- if (tcsetattr(el->serial_fd, TCSANOW, &tty) != 0)
- {
- goto error;
- }
-
- return 0;
+ if (tcgetattr(el->serial_fd, &tty) != 0) goto error;
+ if (cfsetispeed(&tty, (speed_t)speed) != 0) goto error;
+
+ tty.c_cflag &= ~CSIZE; /* apply size mask */
+ tty.c_cflag |= CS8; /* 8bit transmission */
+ tty.c_cflag &= ~PARENB; /* no parity check */
+ tty.c_cflag &= ~CSTOPB; /* set one stop bit */
+
+ tty.c_cflag |= CLOCAL; /* ignore modem lines */
+ tty.c_cflag &= ~CREAD; /* disable receiver - we only send data */
+ tty.c_oflag |= OPOST | ONLCR; /* enable output post-processing by OS */
+
+ if (tcsetattr(el->serial_fd, TCSANOW, &tty) != 0) goto error;
+ return 0;
error:
- e = errno;
- close(el->serial_fd);
- el->serial_fd = -1;
- errno = e;
- return -1;
+ e = errno;
+ close(el->serial_fd);
+ el->serial_fd = -1;
+ errno = e;
+ return -1;
#else
- return 0;
+
+ /* if termios is not available, simply open device without
+ * reconfiguring it. Some embedded OSes might configure tty
+ * during compilation and have termios disabled to save memory. */
+ return 0;
+
#endif
}
@@ -144,14 +124,14 @@ error:
int el_tty_close
(
- struct el *el /* el object with serial descriptor */
+ struct el *el /* el object with serial descriptor */
)
{
- VALID(EINVAL, el->serial_fd != -1);
+ VALID(EINVAL, el->serial_fd != -1);
- close(el->serial_fd);
- el->serial_fd = -1;
- return 0;
+ close(el->serial_fd);
+ el->serial_fd = -1;
+ return 0;
}
@@ -162,9 +142,9 @@ int el_tty_close
int el_tty_puts
(
- struct el *el, /* el object with serial descriptor */
- const char *s /* string to send */
+ struct el *el, /* el object with serial descriptor */
+ const char *s /* string to send */
)
{
- return write(el->serial_fd, s, strlen(s));
+ return write(el->serial_fd, s, strlen(s));
}
diff --git a/src/el-utils.c b/src/el-utils.c
index 503c35b..c473c1f 100644
--- a/src/el-utils.c
+++ b/src/el-utils.c
@@ -53,21 +53,16 @@
const char *el_basename
(
- const char *s /* string to basename */
+ const char *s /* string to basename */
)
{
- const char *base; /* pointer to base name of path */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ const char *base; /* pointer to base name of path */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- base = s;
- for (; *s; ++s)
- {
- if (s[0] == '/' && s[1] != '\0')
- {
- base = s + 1;
- }
- }
+ for (base = s; *s; ++s)
+ if (s[0] == '/' && s[1] != '\0')
+ base = s + 1;
- return base;
+ return base;
}
diff --git a/tst/main.c b/tst/main.c
index f47482a..5763313 100644
--- a/tst/main.c
+++ b/tst/main.c
@@ -10,14 +10,14 @@ mt_defs(); /* definitions for mtest */
int main(void)
{
- (void)mt_prepare_test;
- (void)mt_cleanup_test;
+ (void)mt_prepare_test;
+ (void)mt_cleanup_test;
- el_options_test_group();
- el_print_test_group();
- el_file_test_group();
- el_perror_test_group();
- el_pmemory_test_group();
- el_pbinary_test_group();
- mt_return();
+ el_options_test_group();
+ el_print_test_group();
+ el_file_test_group();
+ el_perror_test_group();
+ el_pmemory_test_group();
+ el_pbinary_test_group();
+ mt_return();
}
diff --git a/tst/test-el-file.c b/tst/test-el-file.c
index ec73673..1f7b3f4 100644
--- a/tst/test-el-file.c
+++ b/tst/test-el-file.c
@@ -40,9 +40,7 @@
#ifdef RUN_TESTS
/* variable is set in el-file.c when we successfully executed fsync
- * path of the code
- */
-
+ * path of the code */
extern int file_synced;
#endif
@@ -79,27 +77,24 @@ mt_defs_ext();
static int file_check
(
- const char *f,
- const char *s
+ const char *f,
+ const char *s
)
{
- char fc[128];
- int fd;
- ssize_t r;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ char fc[128];
+ int fd;
+ ssize_t r;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- fd = open(f, O_RDONLY);
- r = read(fd, fc, sizeof(fc));
- close(fd);
+ fd = open(f, O_RDONLY);
+ r = read(fd, fc, sizeof(fc));
+ close(fd);
- fc[r] = '\0';
- if(strcmp(s, fc) != 0)
- {
- return -1;
- }
+ fc[r] = '\0';
+ if(strcmp(s, fc) != 0) return -1;
- return 0;
+ return 0;
}
@@ -109,27 +104,23 @@ static int file_check
static int symlink_check
(
- const char *t,
- const char *n
+ const char *t,
+ const char *n
)
{
- char dst[PATH_MAX];
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
+ char dst[PATH_MAX];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- /* if target does not exist, link 'n' should not exist too */
- if (t == NULL)
- return -!access(n, F_OK);
+ /* if target does not exist, link 'n' should not exist too */
- memset(dst, 0, sizeof(dst));
- if (readlink(n, dst, sizeof(dst)) == -1)
- return -1;
+ if (t == NULL) return -!access(n, F_OK);
- if (strcmp(t, dst) != 0)
- return -1;
+ memset(dst, 0, sizeof(dst));
+ if (readlink(n, dst, sizeof(dst)) == -1) return -1;
+ if (strcmp(t, dst) != 0) return -1;
- return 0;
+ return 0;
}
@@ -140,14 +131,14 @@ static int symlink_check
static void test_prepare(void)
{
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FROTATE_SIZE, 16);
- el_option(EL_FROTATE_NUMBER, 0);
- el_option(EL_FPATH, WORKDIR"/log");
- el_option(EL_FSYNC_EVERY, 0);
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FROTATE_SIZE, 16);
+ el_option(EL_FROTATE_NUMBER, 0);
+ el_option(EL_FPATH, WORKDIR"/log");
+ el_option(EL_FSYNC_EVERY, 0);
#ifdef RUN_TESTS
- file_synced = 0;
+ file_synced = 0;
#endif
}
@@ -159,32 +150,32 @@ static void test_prepare(void)
static void test_cleanup(void)
{
- int i;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int i;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- /* remove any file that might have been created during tests.
- * We ignore unlink return code, as we expected that some files
- * won't exist, as in are not needed by tests and thus are not
- * created
- */
+ /* remove any file that might have been created during tests.
+ * We ignore unlink return code, as we expected that some files
+ * won't exist, as in are not needed by tests and thus are not
+ * created
+ */
- unlink(WORKDIR"/log");
- unlink(WORKDIR"/log-another");
+ unlink(WORKDIR"/log");
+ unlink(WORKDIR"/log-another");
- for (i = 0; i != 5; ++i)
- {
- char path1[PATH_MAX] = WORKDIR"/log.";
- char path2[PATH_MAX] = WORKDIR"/log-another.";
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ for (i = 0; i != 5; ++i)
+ {
+ char path1[PATH_MAX] = WORKDIR"/log.";
+ char path2[PATH_MAX] = WORKDIR"/log-another.";
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- path1[strlen(path1)] = '0' + i;
- path2[strlen(path2)] = '0' + i;
- unlink(path1);
- unlink(path2);
- }
+ path1[strlen(path1)] = '0' + i;
+ path2[strlen(path2)] = '0' + i;
+ unlink(path1);
+ unlink(path2);
+ }
- el_cleanup();
+ el_cleanup();
}
@@ -200,8 +191,8 @@ static void test_cleanup(void)
static void file_single_message(void)
{
- el_puts(s9);
- mt_fok(file_check(WORKDIR"/log", s9));
+ el_puts(s9);
+ mt_fok(file_check(WORKDIR"/log", s9));
}
@@ -211,10 +202,10 @@ static void file_single_message(void)
static void file_multi_message(void)
{
- el_puts(s9);
- el_puts(s8);
- el_puts(s5);
- mt_fok(file_check(WORKDIR"/log", s9 s8 s5));
+ el_puts(s9);
+ el_puts(s8);
+ el_puts(s5);
+ mt_fok(file_check(WORKDIR"/log", s9 s8 s5));
}
@@ -224,18 +215,18 @@ static void file_multi_message(void)
static void file_reopen(void)
{
- el_puts(s9);
- el_cleanup();
+ el_puts(s9);
+ el_cleanup();
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FROTATE_SIZE, 16);
- el_option(EL_FROTATE_NUMBER, 0);
- el_option(EL_FPATH, WORKDIR"/log");
- el_option(EL_FSYNC_EVERY, 0);
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FROTATE_SIZE, 16);
+ el_option(EL_FROTATE_NUMBER, 0);
+ el_option(EL_FPATH, WORKDIR"/log");
+ el_option(EL_FSYNC_EVERY, 0);
- el_puts(s8);
- mt_fok(file_check(WORKDIR"/log", s9 s8));
+ el_puts(s8);
+ mt_fok(file_check(WORKDIR"/log", s9 s8));
}
@@ -245,19 +236,19 @@ static void file_reopen(void)
static void file_reopen_different_file(void)
{
- el_puts(s9);
- el_cleanup();
+ el_puts(s9);
+ el_cleanup();
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FROTATE_SIZE, 16);
- el_option(EL_FROTATE_NUMBER, 0);
- el_option(EL_FPATH, WORKDIR"/log-another");
- el_option(EL_FSYNC_EVERY, 0);
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FROTATE_SIZE, 16);
+ el_option(EL_FROTATE_NUMBER, 0);
+ el_option(EL_FPATH, WORKDIR"/log-another");
+ el_option(EL_FSYNC_EVERY, 0);
- el_puts(s8);
- mt_fok(file_check(WORKDIR"/log", s9));
- mt_fok(file_check(WORKDIR"/log-another", s8));
+ el_puts(s8);
+ mt_fok(file_check(WORKDIR"/log", s9));
+ mt_fok(file_check(WORKDIR"/log-another", s8));
}
@@ -267,10 +258,10 @@ static void file_reopen_different_file(void)
static void file_unexpected_third_party_delete(void)
{
- el_puts(s9);
- unlink(WORKDIR"/log");
- el_puts(s8);
- mt_fok(file_check(WORKDIR"/log", s8));
+ el_puts(s9);
+ unlink(WORKDIR"/log");
+ el_puts(s8);
+ mt_fok(file_check(WORKDIR"/log", s8));
}
@@ -280,11 +271,11 @@ static void file_unexpected_third_party_delete(void)
static void file_directory_deleted(void)
{
- el_puts(s9);
- unlink(WORKDIR"/log");
- rmdir(WORKDIR);
- mt_ferr(el_puts(s9), ENOENT);
- mkdir(WORKDIR, 0755);
+ el_puts(s9);
+ unlink(WORKDIR"/log");
+ rmdir(WORKDIR);
+ mt_ferr(el_puts(s9), ENOENT);
+ mkdir(WORKDIR, 0755);
}
@@ -294,13 +285,13 @@ static void file_directory_deleted(void)
static void file_directory_reappear_after_delete(void)
{
- el_puts(s9);
- unlink(WORKDIR"/log");
- rmdir(WORKDIR);
- mt_ferr(el_puts(s9), ENOENT);
- mkdir(WORKDIR, 0755);
- mt_fok(el_puts(s9));
- mt_fok(file_check(WORKDIR"/log", s9));
+ el_puts(s9);
+ unlink(WORKDIR"/log");
+ rmdir(WORKDIR);
+ mt_ferr(el_puts(s9), ENOENT);
+ mkdir(WORKDIR, 0755);
+ mt_fok(el_puts(s9));
+ mt_fok(file_check(WORKDIR"/log", s9));
}
@@ -310,22 +301,22 @@ static void file_directory_reappear_after_delete(void)
static void file_write_after_failed_open(void)
{
- /*
- * mt_prepare_test not running here
- */
+ /*
+ * mt_prepare_test not running here
+ */
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FSYNC_EVERY, 0);
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FSYNC_EVERY, 0);
- rmdir(WORKDIR);
- mt_ferr(el_option(EL_FPATH, WORKDIR"/log"), ENOENT);
- mkdir(WORKDIR, 0755);
- mt_fok(el_puts(s9));
- mt_fok(file_check(WORKDIR"/log", s9));
+ rmdir(WORKDIR);
+ mt_ferr(el_option(EL_FPATH, WORKDIR"/log"), ENOENT);
+ mkdir(WORKDIR, 0755);
+ mt_fok(el_puts(s9));
+ mt_fok(file_check(WORKDIR"/log", s9));
- unlink(WORKDIR"/log");
- el_cleanup();
+ unlink(WORKDIR"/log");
+ el_cleanup();
}
@@ -335,23 +326,23 @@ static void file_write_after_failed_open(void)
static void file_write_after_failed_open_to_existing_file(void)
{
- /*
- * mt_prepare_test not running here
- */
+ /*
+ * mt_prepare_test not running here
+ */
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FSYNC_EVERY, 0);
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FSYNC_EVERY, 0);
- rmdir(WORKDIR);
- mt_ferr(el_option(EL_FPATH, WORKDIR"/log"), ENOENT);
- mkdir(WORKDIR, 0755);
- mt_fok(system("echo test > \""WORKDIR"/log\""));
- mt_fok(el_puts(s9));
- mt_fok(file_check(WORKDIR"/log", "test\n"s9));
+ rmdir(WORKDIR);
+ mt_ferr(el_option(EL_FPATH, WORKDIR"/log"), ENOENT);
+ mkdir(WORKDIR, 0755);
+ mt_fok(system("echo test > \""WORKDIR"/log\""));
+ mt_fok(el_puts(s9));
+ mt_fok(file_check(WORKDIR"/log", "test\n"s9));
- unlink(WORKDIR"/log");
- el_cleanup();
+ unlink(WORKDIR"/log");
+ el_cleanup();
}
@@ -361,14 +352,14 @@ static void file_write_after_failed_open_to_existing_file(void)
static void file_and_directory_reapear(void)
{
- el_puts(s9);
- unlink(WORKDIR"/log");
- rmdir(WORKDIR);
- mt_ferr(el_puts(s9), ENOENT);
- mkdir(WORKDIR, 0755);
- mt_fok(system("echo test > \""WORKDIR"/log\""));
- mt_fok(el_puts(s9));
- mt_fok(file_check(WORKDIR"/log", "test\n"s9));
+ el_puts(s9);
+ unlink(WORKDIR"/log");
+ rmdir(WORKDIR);
+ mt_ferr(el_puts(s9), ENOENT);
+ mkdir(WORKDIR, 0755);
+ mt_fok(system("echo test > \""WORKDIR"/log\""));
+ mt_fok(el_puts(s9));
+ mt_fok(file_check(WORKDIR"/log", "test\n"s9));
}
@@ -378,13 +369,13 @@ static void file_and_directory_reapear(void)
static void file_filename_too_long(void)
{
- char path[8192];
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ char path[8192];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- memset(path, 'a', sizeof(path));
- path[sizeof(path) - 1] = '\0';
- mt_ferr(el_option(EL_FPATH, path), ENAMETOOLONG);
+ memset(path, 'a', sizeof(path));
+ path[sizeof(path) - 1] = '\0';
+ mt_ferr(el_option(EL_FPATH, path), ENAMETOOLONG);
}
@@ -394,19 +385,19 @@ static void file_filename_too_long(void)
static void file_path_too_long(void)
{
- char path[PATH_MAX + 2];
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ char path[PATH_MAX + 2];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- memset(path, 'a', sizeof(path));
- path[0] = '/';
- path[sizeof(path) - 5] = '/';
- path[sizeof(path) - 4] = 'f';
- path[sizeof(path) - 4] = 'i';
- path[sizeof(path) - 3] = 'l';
- path[sizeof(path) - 2] = 'e';
- path[sizeof(path) - 1] = '\0';
- mt_ferr(el_option(EL_FPATH, path), ENAMETOOLONG);
+ memset(path, 'a', sizeof(path));
+ path[0] = '/';
+ path[sizeof(path) - 5] = '/';
+ path[sizeof(path) - 4] = 'f';
+ path[sizeof(path) - 4] = 'i';
+ path[sizeof(path) - 3] = 'l';
+ path[sizeof(path) - 2] = 'e';
+ path[sizeof(path) - 1] = '\0';
+ mt_ferr(el_option(EL_FPATH, path), ENAMETOOLONG);
}
@@ -416,15 +407,15 @@ static void file_path_too_long(void)
static void file_print_after_cleanup(void)
{
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FROTATE_SIZE, 16);
- el_option(EL_FROTATE_NUMBER, 0);
- el_option(EL_FPATH, WORKDIR"/log");
- el_option(EL_FSYNC_EVERY, 0);
- el_cleanup();
- mt_ferr(el_puts("whatev"), ENODEV);
- unlink(WORKDIR"/log");
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FROTATE_SIZE, 16);
+ el_option(EL_FROTATE_NUMBER, 0);
+ el_option(EL_FPATH, WORKDIR"/log");
+ el_option(EL_FSYNC_EVERY, 0);
+ el_cleanup();
+ mt_ferr(el_puts("whatev"), ENODEV);
+ unlink(WORKDIR"/log");
}
@@ -434,13 +425,13 @@ static void file_print_after_cleanup(void)
static void file_print_without_setting_file(void)
{
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FROTATE_SIZE, 16);
- el_option(EL_FROTATE_NUMBER, 0);
- el_option(EL_FSYNC_EVERY, 0);
- mt_ferr(el_puts("no file set"), EBADF);
- el_cleanup();
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FROTATE_SIZE, 16);
+ el_option(EL_FROTATE_NUMBER, 0);
+ el_option(EL_FSYNC_EVERY, 0);
+ mt_ferr(el_puts("no file set"), EBADF);
+ el_cleanup();
}
@@ -450,10 +441,10 @@ static void file_print_without_setting_file(void)
static void file_rotate_1_no_rotate(void)
{
- el_option(EL_FROTATE_NUMBER, 1);
- el_puts(s9);
- mt_fok(file_check(WORKDIR"/log.0", s9));
- mt_fok(symlink_check("log.0", WORKDIR"/log"));
+ el_option(EL_FROTATE_NUMBER, 1);
+ el_puts(s9);
+ mt_fok(file_check(WORKDIR"/log.0", s9));
+ mt_fok(symlink_check("log.0", WORKDIR"/log"));
}
@@ -463,13 +454,13 @@ static void file_rotate_1_no_rotate(void)
static void file_rotate_1_exact_print(void)
{
- el_option(EL_FROTATE_NUMBER, 1);
- el_puts(s8);
- el_puts(s8);
- mt_fok(file_check(WORKDIR"/log.0", s8 s8));
- mt_fok(file_check(WORKDIR"/log", s8 s8));
- mt_fok(symlink_check("log.0", WORKDIR"/log"));
- mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
+ el_option(EL_FROTATE_NUMBER, 1);
+ el_puts(s8);
+ el_puts(s8);
+ mt_fok(file_check(WORKDIR"/log.0", s8 s8));
+ mt_fok(file_check(WORKDIR"/log", s8 s8));
+ mt_fok(symlink_check("log.0", WORKDIR"/log"));
+ mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
}
@@ -479,12 +470,12 @@ static void file_rotate_1_exact_print(void)
static void file_rotate_1_overflow_but_no_rotate(void)
{
- el_option(EL_FROTATE_NUMBER, 1);
- el_puts(s9 s5 s5);
- mt_fok(file_check(WORKDIR"/log.0", s9 s5 "qw"));
- mt_fok(file_check(WORKDIR"/log", s9 s5 "qw"));
- mt_fok(symlink_check("log.0", WORKDIR"/log"));
- mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
+ el_option(EL_FROTATE_NUMBER, 1);
+ el_puts(s9 s5 s5);
+ mt_fok(file_check(WORKDIR"/log.0", s9 s5 "qw"));
+ mt_fok(file_check(WORKDIR"/log", s9 s5 "qw"));
+ mt_fok(symlink_check("log.0", WORKDIR"/log"));
+ mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
}
@@ -494,14 +485,14 @@ static void file_rotate_1_overflow_but_no_rotate(void)
static void file_rotate_1_overflow(void)
{
- el_option(EL_FROTATE_NUMBER, 1);
- el_puts(s9);
- el_puts(s9);
- el_puts(s3);
- mt_fok(file_check(WORKDIR"/log.0", s9 s3));
- mt_fok(file_check(WORKDIR"/log", s9 s3));
- mt_fok(symlink_check("log.0", WORKDIR"/log"));
- mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
+ el_option(EL_FROTATE_NUMBER, 1);
+ el_puts(s9);
+ el_puts(s9);
+ el_puts(s3);
+ mt_fok(file_check(WORKDIR"/log.0", s9 s3));
+ mt_fok(file_check(WORKDIR"/log", s9 s3));
+ mt_fok(symlink_check("log.0", WORKDIR"/log"));
+ mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
}
@@ -511,14 +502,14 @@ static void file_rotate_1_overflow(void)
static void file_rotate_1_overflow_exact(void)
{
- el_option(EL_FROTATE_NUMBER, 1);
- el_puts(s8);
- el_puts(s8);
- el_puts(s5);
- mt_fok(file_check(WORKDIR"/log.0", s5));
- mt_fok(file_check(WORKDIR"/log", s5));
- mt_fok(symlink_check("log.0", WORKDIR"/log"));
- mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
+ el_option(EL_FROTATE_NUMBER, 1);
+ el_puts(s8);
+ el_puts(s8);
+ el_puts(s5);
+ mt_fok(file_check(WORKDIR"/log.0", s5));
+ mt_fok(file_check(WORKDIR"/log", s5));
+ mt_fok(symlink_check("log.0", WORKDIR"/log"));
+ mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
}
@@ -528,22 +519,22 @@ static void file_rotate_1_overflow_exact(void)
static void file_rotate_1_reopen(void)
{
- el_option(EL_FROTATE_NUMBER, 1);
- el_puts(s5);
+ el_option(EL_FROTATE_NUMBER, 1);
+ el_puts(s5);
- el_cleanup();
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FROTATE_SIZE, 16);
- el_option(EL_FROTATE_NUMBER, 1);
- el_option(EL_FPATH, WORKDIR"/log");
- el_option(EL_FSYNC_EVERY, 0);
+ el_cleanup();
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FROTATE_SIZE, 16);
+ el_option(EL_FROTATE_NUMBER, 1);
+ el_option(EL_FPATH, WORKDIR"/log");
+ el_option(EL_FSYNC_EVERY, 0);
- el_puts(s8);
- mt_fok(file_check(WORKDIR"/log.0", s5 s8));
- mt_fok(file_check(WORKDIR"/log", s5 s8));
- mt_fok(symlink_check("log.0", WORKDIR"/log"));
- mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
+ el_puts(s8);
+ mt_fok(file_check(WORKDIR"/log.0", s5 s8));
+ mt_fok(file_check(WORKDIR"/log", s5 s8));
+ mt_fok(symlink_check("log.0", WORKDIR"/log"));
+ mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
}
@@ -553,16 +544,16 @@ static void file_rotate_1_reopen(void)
static void file_rotate_1_unexpected_third_party_remove(void)
{
- el_option(EL_FROTATE_NUMBER, 1);
- el_puts(s5);
- el_puts(s8);
- unlink(WORKDIR"/log.0");
- el_puts(s3);
- el_puts(s8);
- mt_fok(file_check(WORKDIR"/log.0", s3 s8));
- mt_fok(file_check(WORKDIR"/log", s3 s8));
- mt_fok(symlink_check("log.0", WORKDIR"/log"));
- mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
+ el_option(EL_FROTATE_NUMBER, 1);
+ el_puts(s5);
+ el_puts(s8);
+ unlink(WORKDIR"/log.0");
+ el_puts(s3);
+ el_puts(s8);
+ mt_fok(file_check(WORKDIR"/log.0", s3 s8));
+ mt_fok(file_check(WORKDIR"/log", s3 s8));
+ mt_fok(symlink_check("log.0", WORKDIR"/log"));
+ mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
}
@@ -572,16 +563,16 @@ static void file_rotate_1_unexpected_third_party_remove(void)
static void file_rotate_1_change_size_up(void)
{
- el_option(EL_FROTATE_NUMBER, 1);
- el_puts(s9);
- el_puts(s5);
- el_option(EL_FROTATE_SIZE, 32);
- el_puts(s9);
- el_puts(s8);
- mt_fok(file_check(WORKDIR"/log.0", s9 s5 s9 s8));
- mt_fok(file_check(WORKDIR"/log", s9 s5 s9 s8));
- mt_fok(symlink_check("log.0", WORKDIR"/log"));
- mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
+ el_option(EL_FROTATE_NUMBER, 1);
+ el_puts(s9);
+ el_puts(s5);
+ el_option(EL_FROTATE_SIZE, 32);
+ el_puts(s9);
+ el_puts(s8);
+ mt_fok(file_check(WORKDIR"/log.0", s9 s5 s9 s8));
+ mt_fok(file_check(WORKDIR"/log", s9 s5 s9 s8));
+ mt_fok(symlink_check("log.0", WORKDIR"/log"));
+ mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
}
@@ -591,14 +582,14 @@ static void file_rotate_1_change_size_up(void)
static void file_rotate_1_change_size_down(void)
{
- el_option(EL_FROTATE_NUMBER, 1);
- el_puts(s9);
- el_option(EL_FROTATE_SIZE, 8);
- el_puts(s5);
- mt_fok(file_check(WORKDIR"/log.0", s5));
- mt_fok(file_check(WORKDIR"/log", s5));
- mt_fok(symlink_check("log.0", WORKDIR"/log"));
- mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
+ el_option(EL_FROTATE_NUMBER, 1);
+ el_puts(s9);
+ el_option(EL_FROTATE_SIZE, 8);
+ el_puts(s5);
+ mt_fok(file_check(WORKDIR"/log.0", s5));
+ mt_fok(file_check(WORKDIR"/log", s5));
+ mt_fok(symlink_check("log.0", WORKDIR"/log"));
+ mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
}
@@ -608,12 +599,12 @@ static void file_rotate_1_change_size_down(void)
static void file_rotate_2_no_rotate(void)
{
- el_option(EL_FROTATE_NUMBER, 2);
- el_puts(s9);
- mt_fok(file_check(WORKDIR"/log.0", s9));
- mt_fok(file_check(WORKDIR"/log", s9));
- mt_fok(symlink_check("log.0", WORKDIR"/log"));
- mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
+ el_option(EL_FROTATE_NUMBER, 2);
+ el_puts(s9);
+ mt_fok(file_check(WORKDIR"/log.0", s9));
+ mt_fok(file_check(WORKDIR"/log", s9));
+ mt_fok(symlink_check("log.0", WORKDIR"/log"));
+ mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
}
@@ -623,13 +614,13 @@ static void file_rotate_2_no_rotate(void)
static void file_rotate_2_exact_print(void)
{
- el_option(EL_FROTATE_NUMBER, 2);
- el_puts(s8);
- el_puts(s8);
- mt_fok(file_check(WORKDIR"/log.0", s8 s8));
- mt_fok(file_check(WORKDIR"/log", s8 s8));
- mt_fok(symlink_check("log.0", WORKDIR"/log"));
- mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
+ el_option(EL_FROTATE_NUMBER, 2);
+ el_puts(s8);
+ el_puts(s8);
+ mt_fok(file_check(WORKDIR"/log.0", s8 s8));
+ mt_fok(file_check(WORKDIR"/log", s8 s8));
+ mt_fok(symlink_check("log.0", WORKDIR"/log"));
+ mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
}
@@ -639,12 +630,12 @@ static void file_rotate_2_exact_print(void)
static void file_rotate_2_overflow_but_no_rotate(void)
{
- el_option(EL_FROTATE_NUMBER, 2);
- el_puts(s9 s5 s5);
- mt_fok(file_check(WORKDIR"/log.0", s9 s5 "qw"));
- mt_fok(file_check(WORKDIR"/log", s9 s5 "qw"));
- mt_fok(symlink_check("log.0", WORKDIR"/log"));
- mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
+ el_option(EL_FROTATE_NUMBER, 2);
+ el_puts(s9 s5 s5);
+ mt_fok(file_check(WORKDIR"/log.0", s9 s5 "qw"));
+ mt_fok(file_check(WORKDIR"/log", s9 s5 "qw"));
+ mt_fok(symlink_check("log.0", WORKDIR"/log"));
+ mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
}
@@ -654,14 +645,14 @@ static void file_rotate_2_overflow_but_no_rotate(void)
static void file_rotate_2_overflow(void)
{
- el_option(EL_FROTATE_NUMBER, 2);
- el_puts(s9);
- el_puts(s9);
- el_puts(s3);
- mt_fok(file_check(WORKDIR"/log.0", s9));
- mt_fok(file_check(WORKDIR"/log.1", s9 s3));
- mt_fok(file_check(WORKDIR"/log", s9 s3));
- mt_fok(symlink_check("log.1", WORKDIR"/log"));
+ el_option(EL_FROTATE_NUMBER, 2);
+ el_puts(s9);
+ el_puts(s9);
+ el_puts(s3);
+ mt_fok(file_check(WORKDIR"/log.0", s9));
+ mt_fok(file_check(WORKDIR"/log.1", s9 s3));
+ mt_fok(file_check(WORKDIR"/log", s9 s3));
+ mt_fok(symlink_check("log.1", WORKDIR"/log"));
}
@@ -671,14 +662,14 @@ static void file_rotate_2_overflow(void)
static void file_rotate_2_overflow_exact(void)
{
- el_option(EL_FROTATE_NUMBER, 2);
- el_puts(s8);
- el_puts(s8);
- el_puts(s5);
- mt_fok(file_check(WORKDIR"/log.0", s8 s8));
- mt_fok(file_check(WORKDIR"/log.1", s5));
- mt_fok(file_check(WORKDIR"/log", s5));
- mt_fok(symlink_check("log.1", WORKDIR"/log"));
+ el_option(EL_FROTATE_NUMBER, 2);
+ el_puts(s8);
+ el_puts(s8);
+ el_puts(s5);
+ mt_fok(file_check(WORKDIR"/log.0", s8 s8));
+ mt_fok(file_check(WORKDIR"/log.1", s5));
+ mt_fok(file_check(WORKDIR"/log", s5));
+ mt_fok(symlink_check("log.1", WORKDIR"/log"));
}
@@ -688,23 +679,23 @@ static void file_rotate_2_overflow_exact(void)
static void file_rotate_2_reopen(void)
{
- el_option(EL_FROTATE_NUMBER, 2);
- el_puts(s9);
- el_puts(s8);
+ el_option(EL_FROTATE_NUMBER, 2);
+ el_puts(s9);
+ el_puts(s8);
- el_cleanup();
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FROTATE_SIZE, 16);
- el_option(EL_FROTATE_NUMBER, 2);
- el_option(EL_FPATH, WORKDIR"/log");
- el_option(EL_FSYNC_EVERY, 0);
+ el_cleanup();
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FROTATE_SIZE, 16);
+ el_option(EL_FROTATE_NUMBER, 2);
+ el_option(EL_FPATH, WORKDIR"/log");
+ el_option(EL_FSYNC_EVERY, 0);
- el_puts(s5);
- mt_fok(file_check(WORKDIR"/log.0", s9));
- mt_fok(file_check(WORKDIR"/log.1", s8 s5));
- mt_fok(file_check(WORKDIR"/log", s8 s5));
- mt_fok(symlink_check("log.1", WORKDIR"/log"));
+ el_puts(s5);
+ mt_fok(file_check(WORKDIR"/log.0", s9));
+ mt_fok(file_check(WORKDIR"/log.1", s8 s5));
+ mt_fok(file_check(WORKDIR"/log", s8 s5));
+ mt_fok(symlink_check("log.1", WORKDIR"/log"));
}
@@ -714,17 +705,17 @@ static void file_rotate_2_reopen(void)
static void file_rotate_2_unexpected_third_party_remove(void)
{
- el_option(EL_FROTATE_NUMBER, 2);
- el_puts(s5);
- el_puts(s8);
- unlink(WORKDIR"/log.0");
- el_puts(s3);
- el_puts(s8);
- el_puts(s9);
- mt_fok(file_check(WORKDIR"/log.0", s3 s8));
- mt_fok(file_check(WORKDIR"/log.1", s9));
- mt_fok(file_check(WORKDIR"/log", s9));
- mt_fok(symlink_check("log.1", WORKDIR"/log"));
+ el_option(EL_FROTATE_NUMBER, 2);
+ el_puts(s5);
+ el_puts(s8);
+ unlink(WORKDIR"/log.0");
+ el_puts(s3);
+ el_puts(s8);
+ el_puts(s9);
+ mt_fok(file_check(WORKDIR"/log.0", s3 s8));
+ mt_fok(file_check(WORKDIR"/log.1", s9));
+ mt_fok(file_check(WORKDIR"/log", s9));
+ mt_fok(symlink_check("log.1", WORKDIR"/log"));
}
@@ -734,17 +725,17 @@ static void file_rotate_2_unexpected_third_party_remove(void)
static void file_rotate_2_change_size_up(void)
{
- el_option(EL_FROTATE_NUMBER, 2);
- el_puts(s9);
- el_puts(s5);
- el_puts(s9);
- el_option(EL_FROTATE_SIZE, 32);
- el_puts(s9);
- el_puts(s8);
- mt_fok(file_check(WORKDIR"/log.0", s9 s5));
- mt_fok(file_check(WORKDIR"/log.1", s9 s9 s8));
- mt_fok(file_check(WORKDIR"/log", s9 s9 s8));
- mt_fok(symlink_check("log.1", WORKDIR"/log"));
+ el_option(EL_FROTATE_NUMBER, 2);
+ el_puts(s9);
+ el_puts(s5);
+ el_puts(s9);
+ el_option(EL_FROTATE_SIZE, 32);
+ el_puts(s9);
+ el_puts(s8);
+ mt_fok(file_check(WORKDIR"/log.0", s9 s5));
+ mt_fok(file_check(WORKDIR"/log.1", s9 s9 s8));
+ mt_fok(file_check(WORKDIR"/log", s9 s9 s8));
+ mt_fok(symlink_check("log.1", WORKDIR"/log"));
}
@@ -754,15 +745,15 @@ static void file_rotate_2_change_size_up(void)
static void file_rotate_2_change_size_down(void)
{
- el_option(EL_FROTATE_NUMBER, 2);
- el_puts(s9);
- el_puts(s9);
- el_option(EL_FROTATE_SIZE, 8);
- el_puts(s5);
- mt_fok(file_check(WORKDIR"/log.0", s9));
- mt_fok(file_check(WORKDIR"/log.1", s5));
- mt_fok(file_check(WORKDIR"/log", s5));
- mt_fok(symlink_check("log.1", WORKDIR"/log"));
+ el_option(EL_FROTATE_NUMBER, 2);
+ el_puts(s9);
+ el_puts(s9);
+ el_option(EL_FROTATE_SIZE, 8);
+ el_puts(s5);
+ mt_fok(file_check(WORKDIR"/log.0", s9));
+ mt_fok(file_check(WORKDIR"/log.1", s5));
+ mt_fok(file_check(WORKDIR"/log", s5));
+ mt_fok(symlink_check("log.1", WORKDIR"/log"));
}
@@ -772,17 +763,17 @@ static void file_rotate_2_change_size_down(void)
static void file_rotate_2_many_rotates(void)
{
- el_option(EL_FROTATE_NUMBER, 2);
- el_puts(s9);
- el_puts(s8);
- el_puts(s5);
- el_puts(s5);
- el_puts(s3);
- el_puts(s9);
- mt_fok(file_check(WORKDIR"/log.0", s5 s3));
- mt_fok(file_check(WORKDIR"/log.1", s9));
- mt_fok(file_check(WORKDIR"/log", s9));
- mt_fok(symlink_check("log.1", WORKDIR"/log"));
+ el_option(EL_FROTATE_NUMBER, 2);
+ el_puts(s9);
+ el_puts(s8);
+ el_puts(s5);
+ el_puts(s5);
+ el_puts(s3);
+ el_puts(s9);
+ mt_fok(file_check(WORKDIR"/log.0", s5 s3));
+ mt_fok(file_check(WORKDIR"/log.1", s9));
+ mt_fok(file_check(WORKDIR"/log", s9));
+ mt_fok(symlink_check("log.1", WORKDIR"/log"));
}
@@ -792,12 +783,12 @@ static void file_rotate_2_many_rotates(void)
static void file_rotate_5_no_rotate(void)
{
- el_option(EL_FROTATE_NUMBER, 5);
- el_puts(s9);
- mt_fok(file_check(WORKDIR"/log.0", s9));
- mt_fok(file_check(WORKDIR"/log", s9));
- mt_fok(symlink_check("log.0", WORKDIR"/log"));
- mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
+ el_option(EL_FROTATE_NUMBER, 5);
+ el_puts(s9);
+ mt_fok(file_check(WORKDIR"/log.0", s9));
+ mt_fok(file_check(WORKDIR"/log", s9));
+ mt_fok(symlink_check("log.0", WORKDIR"/log"));
+ mt_fail(access(WORKDIR"/log.1", F_OK) == -1);
}
@@ -807,15 +798,15 @@ static void file_rotate_5_no_rotate(void)
static void file_rotate_5_exact_print_rotate(void)
{
- el_option(EL_FROTATE_NUMBER, 5);
- el_puts(s8);
- el_puts(s8);
- el_puts(s8);
- el_puts(s8);
- mt_fok(file_check(WORKDIR"/log.0", s8 s8));
- mt_fok(file_check(WORKDIR"/log.1", s8 s8));
- mt_fok(file_check(WORKDIR"/log", s8 s8));
- mt_fok(symlink_check("log.1", WORKDIR"/log"));
+ el_option(EL_FROTATE_NUMBER, 5);
+ el_puts(s8);
+ el_puts(s8);
+ el_puts(s8);
+ el_puts(s8);
+ mt_fok(file_check(WORKDIR"/log.0", s8 s8));
+ mt_fok(file_check(WORKDIR"/log.1", s8 s8));
+ mt_fok(file_check(WORKDIR"/log", s8 s8));
+ mt_fok(symlink_check("log.1", WORKDIR"/log"));
}
@@ -825,14 +816,14 @@ static void file_rotate_5_exact_print_rotate(void)
static void file_rotate_5_overflow_but_no_rotate(void)
{
- el_option(EL_FROTATE_NUMBER, 5);
- el_puts(s8);
- el_puts(s8);
- el_puts(s9 s5 s5);
- mt_fok(file_check(WORKDIR"/log.0", s8 s8));
- mt_fok(file_check(WORKDIR"/log.1", s9 s5 "qw"));
- mt_fok(file_check(WORKDIR"/log", s9 s5 "qw"));
- mt_fok(symlink_check("log.1", WORKDIR"/log"));
+ el_option(EL_FROTATE_NUMBER, 5);
+ el_puts(s8);
+ el_puts(s8);
+ el_puts(s9 s5 s5);
+ mt_fok(file_check(WORKDIR"/log.0", s8 s8));
+ mt_fok(file_check(WORKDIR"/log.1", s9 s5 "qw"));
+ mt_fok(file_check(WORKDIR"/log", s9 s5 "qw"));
+ mt_fok(symlink_check("log.1", WORKDIR"/log"));
}
@@ -842,20 +833,20 @@ static void file_rotate_5_overflow_but_no_rotate(void)
static void file_rotate_5_overflow(void)
{
- el_option(EL_FROTATE_NUMBER, 5);
- el_puts(s9);
- el_puts(s9);
- el_puts(s3);
- el_puts(s3);
- el_puts(s8);
- el_puts(s5);
- el_puts(s9);
- mt_fok(file_check(WORKDIR"/log.0", s9));
- mt_fok(file_check(WORKDIR"/log.1", s9 s3 s3));
- mt_fok(file_check(WORKDIR"/log.2", s8 s5));
- mt_fok(file_check(WORKDIR"/log.3", s9));
- mt_fok(file_check(WORKDIR"/log", s9));
- mt_fok(symlink_check("log.3", WORKDIR"/log"));
+ el_option(EL_FROTATE_NUMBER, 5);
+ el_puts(s9);
+ el_puts(s9);
+ el_puts(s3);
+ el_puts(s3);
+ el_puts(s8);
+ el_puts(s5);
+ el_puts(s9);
+ mt_fok(file_check(WORKDIR"/log.0", s9));
+ mt_fok(file_check(WORKDIR"/log.1", s9 s3 s3));
+ mt_fok(file_check(WORKDIR"/log.2", s8 s5));
+ mt_fok(file_check(WORKDIR"/log.3", s9));
+ mt_fok(file_check(WORKDIR"/log", s9));
+ mt_fok(symlink_check("log.3", WORKDIR"/log"));
}
@@ -865,17 +856,17 @@ static void file_rotate_5_overflow(void)
static void file_rotate_5_overflow_exact(void)
{
- el_option(EL_FROTATE_NUMBER, 5);
- el_puts(s8);
- el_puts(s8);
- el_puts(s8);
- el_puts(s8);
- el_puts(s5);
- mt_fok(file_check(WORKDIR"/log.0", s8 s8));
- mt_fok(file_check(WORKDIR"/log.1", s8 s8));
- mt_fok(file_check(WORKDIR"/log.2", s5));
- mt_fok(file_check(WORKDIR"/log", s5));
- mt_fok(symlink_check("log.2", WORKDIR"/log"));
+ el_option(EL_FROTATE_NUMBER, 5);
+ el_puts(s8);
+ el_puts(s8);
+ el_puts(s8);
+ el_puts(s8);
+ el_puts(s5);
+ mt_fok(file_check(WORKDIR"/log.0", s8 s8));
+ mt_fok(file_check(WORKDIR"/log.1", s8 s8));
+ mt_fok(file_check(WORKDIR"/log.2", s5));
+ mt_fok(file_check(WORKDIR"/log", s5));
+ mt_fok(symlink_check("log.2", WORKDIR"/log"));
}
@@ -885,32 +876,32 @@ static void file_rotate_5_overflow_exact(void)
static void file_rotate_5_reopen(void)
{
- el_option(EL_FROTATE_NUMBER, 5);
+ el_option(EL_FROTATE_NUMBER, 5);
- el_puts(s9);
- el_puts(s9);
- el_puts(s3);
- el_puts(s3);
- el_puts(s8);
- el_puts(s5);
+ el_puts(s9);
+ el_puts(s9);
+ el_puts(s3);
+ el_puts(s3);
+ el_puts(s8);
+ el_puts(s5);
- el_cleanup();
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FROTATE_SIZE, 16);
- el_option(EL_FROTATE_NUMBER, 5);
- el_option(EL_FPATH, WORKDIR"/log");
- el_option(EL_FSYNC_EVERY, 0);
+ el_cleanup();
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FROTATE_SIZE, 16);
+ el_option(EL_FROTATE_NUMBER, 5);
+ el_option(EL_FPATH, WORKDIR"/log");
+ el_option(EL_FSYNC_EVERY, 0);
- el_puts(s9);
- el_puts(s8);
- mt_fok(file_check(WORKDIR"/log.0", s9));
- mt_fok(file_check(WORKDIR"/log.1", s9 s3 s3));
- mt_fok(file_check(WORKDIR"/log.2", s8 s5));
- mt_fok(file_check(WORKDIR"/log.3", s9));
- mt_fok(file_check(WORKDIR"/log.4", s8));
- mt_fok(file_check(WORKDIR"/log", s8));
- mt_fok(symlink_check("log.4", WORKDIR"/log"));
+ el_puts(s9);
+ el_puts(s8);
+ mt_fok(file_check(WORKDIR"/log.0", s9));
+ mt_fok(file_check(WORKDIR"/log.1", s9 s3 s3));
+ mt_fok(file_check(WORKDIR"/log.2", s8 s5));
+ mt_fok(file_check(WORKDIR"/log.3", s9));
+ mt_fok(file_check(WORKDIR"/log.4", s8));
+ mt_fok(file_check(WORKDIR"/log", s8));
+ mt_fok(symlink_check("log.4", WORKDIR"/log"));
}
@@ -920,73 +911,73 @@ static void file_rotate_5_reopen(void)
static void file_rotate_5_hole_in_log_rotate(void)
{
- el_option(EL_FROTATE_NUMBER, 5);
- el_option(EL_FROTATE_SIZE, 3);
- el_puts("qaz");
- el_puts("wsx");
- el_puts("edc");
- el_puts("rfv");
- el_puts("tgb");
+ el_option(EL_FROTATE_NUMBER, 5);
+ el_option(EL_FROTATE_SIZE, 3);
+ el_puts("qaz");
+ el_puts("wsx");
+ el_puts("edc");
+ el_puts("rfv");
+ el_puts("tgb");
- mt_fok(file_check(WORKDIR"/log.0", "qaz"));
- mt_fok(file_check(WORKDIR"/log.1", "wsx"));
- mt_fok(file_check(WORKDIR"/log.2", "edc"));
- mt_fok(file_check(WORKDIR"/log.3", "rfv"));
- mt_fok(file_check(WORKDIR"/log.4", "tgb"));
- mt_fok(file_check(WORKDIR"/log", "tgb"));
- mt_fok(symlink_check("log.4", WORKDIR"/log"));
+ mt_fok(file_check(WORKDIR"/log.0", "qaz"));
+ mt_fok(file_check(WORKDIR"/log.1", "wsx"));
+ mt_fok(file_check(WORKDIR"/log.2", "edc"));
+ mt_fok(file_check(WORKDIR"/log.3", "rfv"));
+ mt_fok(file_check(WORKDIR"/log.4", "tgb"));
+ mt_fok(file_check(WORKDIR"/log", "tgb"));
+ mt_fok(symlink_check("log.4", WORKDIR"/log"));
- unlink(WORKDIR"/log.1");
- unlink(WORKDIR"/log.4");
+ unlink(WORKDIR"/log.1");
+ unlink(WORKDIR"/log.4");
- el_puts("123");
+ el_puts("123");
- mt_fok(file_check(WORKDIR"/log.0", "qaz"));
- mt_fok(file_check(WORKDIR"/log.2", "edc"));
- mt_fok(file_check(WORKDIR"/log.3", "rfv"));
- mt_fok(file_check(WORKDIR"/log.4", "123"));
- mt_fok(file_check(WORKDIR"/log", "123"));
- mt_fok(symlink_check("log.4", WORKDIR"/log"));
+ mt_fok(file_check(WORKDIR"/log.0", "qaz"));
+ mt_fok(file_check(WORKDIR"/log.2", "edc"));
+ mt_fok(file_check(WORKDIR"/log.3", "rfv"));
+ mt_fok(file_check(WORKDIR"/log.4", "123"));
+ mt_fok(file_check(WORKDIR"/log", "123"));
+ mt_fok(symlink_check("log.4", WORKDIR"/log"));
- el_puts("456");
+ el_puts("456");
- mt_fok(file_check(WORKDIR"/log.0", "qaz"));
- mt_fok(file_check(WORKDIR"/log.1", "edc"));
- mt_fok(file_check(WORKDIR"/log.2", "rfv"));
- mt_fok(file_check(WORKDIR"/log.3", "123"));
- mt_fok(file_check(WORKDIR"/log.4", "456"));
- mt_fok(file_check(WORKDIR"/log", "456"));
- mt_fok(symlink_check("log.4", WORKDIR"/log"));
+ mt_fok(file_check(WORKDIR"/log.0", "qaz"));
+ mt_fok(file_check(WORKDIR"/log.1", "edc"));
+ mt_fok(file_check(WORKDIR"/log.2", "rfv"));
+ mt_fok(file_check(WORKDIR"/log.3", "123"));
+ mt_fok(file_check(WORKDIR"/log.4", "456"));
+ mt_fok(file_check(WORKDIR"/log", "456"));
+ mt_fok(symlink_check("log.4", WORKDIR"/log"));
- el_puts("789");
+ el_puts("789");
- mt_fok(file_check(WORKDIR"/log.0", "edc"));
- mt_fok(file_check(WORKDIR"/log.1", "rfv"));
- mt_fok(file_check(WORKDIR"/log.2", "123"));
- mt_fok(file_check(WORKDIR"/log.3", "456"));
- mt_fok(file_check(WORKDIR"/log.4", "789"));
- mt_fok(file_check(WORKDIR"/log", "789"));
- mt_fok(symlink_check("log.4", WORKDIR"/log"));
+ mt_fok(file_check(WORKDIR"/log.0", "edc"));
+ mt_fok(file_check(WORKDIR"/log.1", "rfv"));
+ mt_fok(file_check(WORKDIR"/log.2", "123"));
+ mt_fok(file_check(WORKDIR"/log.3", "456"));
+ mt_fok(file_check(WORKDIR"/log.4", "789"));
+ mt_fok(file_check(WORKDIR"/log", "789"));
+ mt_fok(symlink_check("log.4", WORKDIR"/log"));
- el_puts("qwe");
+ el_puts("qwe");
- mt_fok(file_check(WORKDIR"/log.0", "rfv"));
- mt_fok(file_check(WORKDIR"/log.1", "123"));
- mt_fok(file_check(WORKDIR"/log.2", "456"));
- mt_fok(file_check(WORKDIR"/log.3", "789"));
- mt_fok(file_check(WORKDIR"/log.4", "qwe"));
- mt_fok(file_check(WORKDIR"/log", "qwe"));
- mt_fok(symlink_check("log.4", WORKDIR"/log"));
+ mt_fok(file_check(WORKDIR"/log.0", "rfv"));
+ mt_fok(file_check(WORKDIR"/log.1", "123"));
+ mt_fok(file_check(WORKDIR"/log.2", "456"));
+ mt_fok(file_check(WORKDIR"/log.3", "789"));
+ mt_fok(file_check(WORKDIR"/log.4", "qwe"));
+ mt_fok(file_check(WORKDIR"/log", "qwe"));
+ mt_fok(symlink_check("log.4", WORKDIR"/log"));
- el_puts("asd");
+ el_puts("asd");
- mt_fok(file_check(WORKDIR"/log.0", "123"));
- mt_fok(file_check(WORKDIR"/log.1", "456"));
- mt_fok(file_check(WORKDIR"/log.2", "789"));
- mt_fok(file_check(WORKDIR"/log.3", "qwe"));
- mt_fok(file_check(WORKDIR"/log.4", "asd"));
- mt_fok(file_check(WORKDIR"/log", "asd"));
- mt_fok(symlink_check("log.4", WORKDIR"/log"));
+ mt_fok(file_check(WORKDIR"/log.0", "123"));
+ mt_fok(file_check(WORKDIR"/log.1", "456"));
+ mt_fok(file_check(WORKDIR"/log.2", "789"));
+ mt_fok(file_check(WORKDIR"/log.3", "qwe"));
+ mt_fok(file_check(WORKDIR"/log.4", "asd"));
+ mt_fok(file_check(WORKDIR"/log", "asd"));
+ mt_fok(symlink_check("log.4", WORKDIR"/log"));
}
@@ -996,37 +987,37 @@ static void file_rotate_5_hole_in_log_rotate(void)
static void file_rotate_5_rename_file_halfway(void)
{
- el_option(EL_FROTATE_NUMBER, 5);
- el_option(EL_FROTATE_SIZE, 3);
- el_puts("qaz");
- el_puts("wsx");
- el_puts("edc");
- el_puts("rfv");
- el_puts("tgb");
+ el_option(EL_FROTATE_NUMBER, 5);
+ el_option(EL_FROTATE_SIZE, 3);
+ el_puts("qaz");
+ el_puts("wsx");
+ el_puts("edc");
+ el_puts("rfv");
+ el_puts("tgb");
- el_option(EL_FPATH, WORKDIR"/log-another");
+ el_option(EL_FPATH, WORKDIR"/log-another");
- el_puts("123");
- el_puts("456");
- el_puts("789");
- el_puts("qwe");
- el_puts("asd");
+ el_puts("123");
+ el_puts("456");
+ el_puts("789");
+ el_puts("qwe");
+ el_puts("asd");
- mt_fok(file_check(WORKDIR"/log.0", "qaz"));
- mt_fok(file_check(WORKDIR"/log.1", "wsx"));
- mt_fok(file_check(WORKDIR"/log.2", "edc"));
- mt_fok(file_check(WORKDIR"/log.3", "rfv"));
- mt_fok(file_check(WORKDIR"/log.4", "tgb"));
- mt_fok(file_check(WORKDIR"/log", "tgb"));
- mt_fok(symlink_check("log.4", WORKDIR"/log"));
+ mt_fok(file_check(WORKDIR"/log.0", "qaz"));
+ mt_fok(file_check(WORKDIR"/log.1", "wsx"));
+ mt_fok(file_check(WORKDIR"/log.2", "edc"));
+ mt_fok(file_check(WORKDIR"/log.3", "rfv"));
+ mt_fok(file_check(WORKDIR"/log.4", "tgb"));
+ mt_fok(file_check(WORKDIR"/log", "tgb"));
+ mt_fok(symlink_check("log.4", WORKDIR"/log"));
- mt_fok(file_check(WORKDIR"/log-another.0", "123"));
- mt_fok(file_check(WORKDIR"/log-another.1", "456"));
- mt_fok(file_check(WORKDIR"/log-another.2", "789"));
- mt_fok(file_check(WORKDIR"/log-another.3", "qwe"));
- mt_fok(file_check(WORKDIR"/log-another.4", "asd"));
- mt_fok(file_check(WORKDIR"/log-another", "asd"));
- mt_fok(symlink_check("log-another.4", WORKDIR"/log-another"));
+ mt_fok(file_check(WORKDIR"/log-another.0", "123"));
+ mt_fok(file_check(WORKDIR"/log-another.1", "456"));
+ mt_fok(file_check(WORKDIR"/log-another.2", "789"));
+ mt_fok(file_check(WORKDIR"/log-another.3", "qwe"));
+ mt_fok(file_check(WORKDIR"/log-another.4", "asd"));
+ mt_fok(file_check(WORKDIR"/log-another", "asd"));
+ mt_fok(symlink_check("log-another.4", WORKDIR"/log-another"));
}
@@ -1036,30 +1027,30 @@ static void file_rotate_5_rename_file_halfway(void)
static void file_rotate_directory_deleted(void)
{
- /*
- * mt_prepare_test not running here
- */
+ /*
+ * mt_prepare_test not running here
+ */
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FSYNC_EVERY, 0);
- el_option(EL_FROTATE_SIZE, 3);
- el_option(EL_FROTATE_NUMBER, 5);
- mt_fok(el_option(EL_FPATH, WORKDIR"/log"));
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FSYNC_EVERY, 0);
+ el_option(EL_FROTATE_SIZE, 3);
+ el_option(EL_FROTATE_NUMBER, 5);
+ mt_fok(el_option(EL_FPATH, WORKDIR"/log"));
- el_puts("qaz");
- el_puts("wsx");
- el_puts("edc");
+ el_puts("qaz");
+ el_puts("wsx");
+ el_puts("edc");
- unlink(WORKDIR"/log.0");
- unlink(WORKDIR"/log.1");
- unlink(WORKDIR"/log.2");
- unlink(WORKDIR"/log");
- rmdir(WORKDIR);
- mt_ferr(el_puts("rfv"), ENOENT);
+ unlink(WORKDIR"/log.0");
+ unlink(WORKDIR"/log.1");
+ unlink(WORKDIR"/log.2");
+ unlink(WORKDIR"/log");
+ rmdir(WORKDIR);
+ mt_ferr(el_puts("rfv"), ENOENT);
- mkdir(WORKDIR, 0755);
- el_cleanup();
+ mkdir(WORKDIR, 0755);
+ el_cleanup();
}
@@ -1069,47 +1060,47 @@ static void file_rotate_directory_deleted(void)
static void file_rotate_directory_reappear_after_delete(void)
{
- /*
- * mt_prepare_test not running here
- */
+ /*
+ * mt_prepare_test not running here
+ */
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FSYNC_EVERY, 0);
- el_option(EL_FROTATE_SIZE, 3);
- el_option(EL_FROTATE_NUMBER, 5);
- mt_fok(el_option(EL_FPATH, WORKDIR"/log"));
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FSYNC_EVERY, 0);
+ el_option(EL_FROTATE_SIZE, 3);
+ el_option(EL_FROTATE_NUMBER, 5);
+ mt_fok(el_option(EL_FPATH, WORKDIR"/log"));
- el_puts("qaz");
- el_puts("wsx");
- el_puts("edc");
+ el_puts("qaz");
+ el_puts("wsx");
+ el_puts("edc");
- unlink(WORKDIR"/log.0");
- unlink(WORKDIR"/log.1");
- unlink(WORKDIR"/log.2");
- unlink(WORKDIR"/log");
- rmdir(WORKDIR);
- mt_ferr(el_puts("rfv"), ENOENT);
+ unlink(WORKDIR"/log.0");
+ unlink(WORKDIR"/log.1");
+ unlink(WORKDIR"/log.2");
+ unlink(WORKDIR"/log");
+ rmdir(WORKDIR);
+ mt_ferr(el_puts("rfv"), ENOENT);
- mkdir(WORKDIR, 0755);
+ mkdir(WORKDIR, 0755);
- mt_fok(el_puts("rfv"));
- mt_fok(el_puts("tgb"));
- mt_fok(el_puts("yhn"));
- mt_fok(el_puts("ujm"));
- mt_fok(file_check(WORKDIR"/log.0", "rfv"));
- mt_fok(file_check(WORKDIR"/log.1", "tgb"));
- mt_fok(file_check(WORKDIR"/log.2", "yhn"));
- mt_fok(file_check(WORKDIR"/log.3", "ujm"));
- mt_fok(file_check(WORKDIR"/log", "ujm"));
- mt_fok(symlink_check("log.3", WORKDIR"/log"));
- unlink(WORKDIR"/log.0");
- unlink(WORKDIR"/log.1");
- unlink(WORKDIR"/log.2");
- unlink(WORKDIR"/log.3");
- unlink(WORKDIR"/log.4");
- unlink(WORKDIR"/log");
- el_cleanup();
+ mt_fok(el_puts("rfv"));
+ mt_fok(el_puts("tgb"));
+ mt_fok(el_puts("yhn"));
+ mt_fok(el_puts("ujm"));
+ mt_fok(file_check(WORKDIR"/log.0", "rfv"));
+ mt_fok(file_check(WORKDIR"/log.1", "tgb"));
+ mt_fok(file_check(WORKDIR"/log.2", "yhn"));
+ mt_fok(file_check(WORKDIR"/log.3", "ujm"));
+ mt_fok(file_check(WORKDIR"/log", "ujm"));
+ mt_fok(symlink_check("log.3", WORKDIR"/log"));
+ unlink(WORKDIR"/log.0");
+ unlink(WORKDIR"/log.1");
+ unlink(WORKDIR"/log.2");
+ unlink(WORKDIR"/log.3");
+ unlink(WORKDIR"/log.4");
+ unlink(WORKDIR"/log");
+ el_cleanup();
}
@@ -1119,27 +1110,27 @@ static void file_rotate_directory_reappear_after_delete(void)
static void file_rotate_write_after_failed_open(void)
{
- /*
- * mt_prepare_test not running here
- */
+ /*
+ * mt_prepare_test not running here
+ */
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FSYNC_EVERY, 0);
- el_option(EL_FROTATE_SIZE, 3);
- el_option(EL_FROTATE_NUMBER, 5);
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FSYNC_EVERY, 0);
+ el_option(EL_FROTATE_SIZE, 3);
+ el_option(EL_FROTATE_NUMBER, 5);
- rmdir(WORKDIR);
- mt_ferr(el_option(EL_FPATH, WORKDIR"/log"), ENOENT);
- mkdir(WORKDIR, 0755);
- mt_fok(el_puts("qaz"));
- mt_fok(file_check(WORKDIR"/log.0", "qaz"));
- mt_fok(file_check(WORKDIR"/log", "qaz"));
- mt_fok(symlink_check("log.0", WORKDIR"/log"));
+ rmdir(WORKDIR);
+ mt_ferr(el_option(EL_FPATH, WORKDIR"/log"), ENOENT);
+ mkdir(WORKDIR, 0755);
+ mt_fok(el_puts("qaz"));
+ mt_fok(file_check(WORKDIR"/log.0", "qaz"));
+ mt_fok(file_check(WORKDIR"/log", "qaz"));
+ mt_fok(symlink_check("log.0", WORKDIR"/log"));
- unlink(WORKDIR"/log.0");
- unlink(WORKDIR"/log");
- el_cleanup();
+ unlink(WORKDIR"/log.0");
+ unlink(WORKDIR"/log");
+ el_cleanup();
}
@@ -1149,33 +1140,33 @@ static void file_rotate_write_after_failed_open(void)
static void file_rotate_write_after_failed_open_to_existing_file(void)
{
- /*
- * mt_prepare_test not running here
- */
+ /*
+ * mt_prepare_test not running here
+ */
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FSYNC_EVERY, 0);
- el_option(EL_FROTATE_SIZE, 3);
- el_option(EL_FROTATE_NUMBER, 5);
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FSYNC_EVERY, 0);
+ el_option(EL_FROTATE_SIZE, 3);
+ el_option(EL_FROTATE_NUMBER, 5);
- rmdir(WORKDIR);
- mt_ferr(el_option(EL_FPATH, WORKDIR"/log"), ENOENT);
- mkdir(WORKDIR, 0755);
- mt_fok(system("echo qa > \""WORKDIR"/log.0\""));
- mt_fok(system("echo w > \""WORKDIR"/log.1\""));
- mt_fok(el_puts("edc"));
- mt_fok(file_check(WORKDIR"/log.0", "qa\n"));
- mt_fok(file_check(WORKDIR"/log.1", "w\n"));
- mt_fok(file_check(WORKDIR"/log.2", "edc"));
- mt_fok(file_check(WORKDIR"/log", "edc"));
- mt_fok(symlink_check("log.2", WORKDIR"/log"));
+ rmdir(WORKDIR);
+ mt_ferr(el_option(EL_FPATH, WORKDIR"/log"), ENOENT);
+ mkdir(WORKDIR, 0755);
+ mt_fok(system("echo qa > \""WORKDIR"/log.0\""));
+ mt_fok(system("echo w > \""WORKDIR"/log.1\""));
+ mt_fok(el_puts("edc"));
+ mt_fok(file_check(WORKDIR"/log.0", "qa\n"));
+ mt_fok(file_check(WORKDIR"/log.1", "w\n"));
+ mt_fok(file_check(WORKDIR"/log.2", "edc"));
+ mt_fok(file_check(WORKDIR"/log", "edc"));
+ mt_fok(symlink_check("log.2", WORKDIR"/log"));
- unlink(WORKDIR"/log.0");
- unlink(WORKDIR"/log.1");
- unlink(WORKDIR"/log.2");
- unlink(WORKDIR"/log");
- el_cleanup();
+ unlink(WORKDIR"/log.0");
+ unlink(WORKDIR"/log.1");
+ unlink(WORKDIR"/log.2");
+ unlink(WORKDIR"/log");
+ el_cleanup();
}
@@ -1185,39 +1176,39 @@ static void file_rotate_write_after_failed_open_to_existing_file(void)
static void file_rotate_write_after_failed_open_to_existing_file_with_holes(void)
{
- /*
- * mt_prepare_test not running here
- */
+ /*
+ * mt_prepare_test not running here
+ */
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FSYNC_EVERY, 0);
- el_option(EL_FROTATE_SIZE, 3);
- el_option(EL_FROTATE_NUMBER, 5);
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FSYNC_EVERY, 0);
+ el_option(EL_FROTATE_SIZE, 3);
+ el_option(EL_FROTATE_NUMBER, 5);
- rmdir(WORKDIR);
- mt_ferr(el_option(EL_FPATH, WORKDIR"/log"), ENOENT);
- mkdir(WORKDIR, 0755);
- mt_fok(system("echo qa > \""WORKDIR"/log.0\""));
- mt_fok(system("echo ws > \""WORKDIR"/log.2\""));
- mt_fok(system("echo e > \""WORKDIR"/log.4\""));
- mt_fok(el_puts("123"));
- mt_fok(el_puts("456"));
+ rmdir(WORKDIR);
+ mt_ferr(el_option(EL_FPATH, WORKDIR"/log"), ENOENT);
+ mkdir(WORKDIR, 0755);
+ mt_fok(system("echo qa > \""WORKDIR"/log.0\""));
+ mt_fok(system("echo ws > \""WORKDIR"/log.2\""));
+ mt_fok(system("echo e > \""WORKDIR"/log.4\""));
+ mt_fok(el_puts("123"));
+ mt_fok(el_puts("456"));
- mt_fok(file_check(WORKDIR"/log.0", "ws\n"));
- mt_fok(file_check(WORKDIR"/log.2", "e\n"));
- mt_fok(file_check(WORKDIR"/log.3", "123"));
- mt_fok(file_check(WORKDIR"/log.4", "456"));
- mt_fok(file_check(WORKDIR"/log", "456"));
- mt_fok(symlink_check("log.4", WORKDIR"/log"));
+ mt_fok(file_check(WORKDIR"/log.0", "ws\n"));
+ mt_fok(file_check(WORKDIR"/log.2", "e\n"));
+ mt_fok(file_check(WORKDIR"/log.3", "123"));
+ mt_fok(file_check(WORKDIR"/log.4", "456"));
+ mt_fok(file_check(WORKDIR"/log", "456"));
+ mt_fok(symlink_check("log.4", WORKDIR"/log"));
- unlink(WORKDIR"/log.0");
- unlink(WORKDIR"/log.1");
- unlink(WORKDIR"/log.2");
- unlink(WORKDIR"/log.3");
- unlink(WORKDIR"/log.4");
- unlink(WORKDIR"/log");
- el_cleanup();
+ unlink(WORKDIR"/log.0");
+ unlink(WORKDIR"/log.1");
+ unlink(WORKDIR"/log.2");
+ unlink(WORKDIR"/log.3");
+ unlink(WORKDIR"/log.4");
+ unlink(WORKDIR"/log");
+ el_cleanup();
}
@@ -1227,40 +1218,40 @@ static void file_rotate_write_after_failed_open_to_existing_file_with_holes(void
static void file_rotate_write_after_failed_open_to_existing_file_with_holes2(void)
{
- /*
- * mt_prepare_test not running here
- */
+ /*
+ * mt_prepare_test not running here
+ */
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FSYNC_EVERY, 0);
- el_option(EL_FROTATE_SIZE, 3);
- el_option(EL_FROTATE_NUMBER, 5);
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FSYNC_EVERY, 0);
+ el_option(EL_FROTATE_SIZE, 3);
+ el_option(EL_FROTATE_NUMBER, 5);
- rmdir(WORKDIR);
- mt_ferr(el_option(EL_FPATH, WORKDIR"/log"), ENOENT);
- mkdir(WORKDIR, 0755);
- mt_fok(system("echo qa > \""WORKDIR"/log.0\""));
- mt_fok(system("echo ws > \""WORKDIR"/log.3\""));
- mt_fok(system("echo e > \""WORKDIR"/log.4\""));
- mt_fok(el_puts("123"));
- mt_fok(el_puts("456"));
+ rmdir(WORKDIR);
+ mt_ferr(el_option(EL_FPATH, WORKDIR"/log"), ENOENT);
+ mkdir(WORKDIR, 0755);
+ mt_fok(system("echo qa > \""WORKDIR"/log.0\""));
+ mt_fok(system("echo ws > \""WORKDIR"/log.3\""));
+ mt_fok(system("echo e > \""WORKDIR"/log.4\""));
+ mt_fok(el_puts("123"));
+ mt_fok(el_puts("456"));
- mt_fok(file_check(WORKDIR"/log.0", "qa\n"));
- mt_fok(file_check(WORKDIR"/log.1", "ws\n"));
- mt_fok(file_check(WORKDIR"/log.2", "e\n"));
- mt_fok(file_check(WORKDIR"/log.3", "123"));
- mt_fok(file_check(WORKDIR"/log.4", "456"));
- mt_fok(file_check(WORKDIR"/log", "456"));
- mt_fok(symlink_check("log.4", WORKDIR"/log"));
+ mt_fok(file_check(WORKDIR"/log.0", "qa\n"));
+ mt_fok(file_check(WORKDIR"/log.1", "ws\n"));
+ mt_fok(file_check(WORKDIR"/log.2", "e\n"));
+ mt_fok(file_check(WORKDIR"/log.3", "123"));
+ mt_fok(file_check(WORKDIR"/log.4", "456"));
+ mt_fok(file_check(WORKDIR"/log", "456"));
+ mt_fok(symlink_check("log.4", WORKDIR"/log"));
- unlink(WORKDIR"/log.0");
- unlink(WORKDIR"/log.1");
- unlink(WORKDIR"/log.2");
- unlink(WORKDIR"/log.3");
- unlink(WORKDIR"/log.4");
- unlink(WORKDIR"/log");
- el_cleanup();
+ unlink(WORKDIR"/log.0");
+ unlink(WORKDIR"/log.1");
+ unlink(WORKDIR"/log.2");
+ unlink(WORKDIR"/log.3");
+ unlink(WORKDIR"/log.4");
+ unlink(WORKDIR"/log");
+ el_cleanup();
}
@@ -1270,40 +1261,40 @@ static void file_rotate_write_after_failed_open_to_existing_file_with_holes2(voi
static void file_rotate_write_after_failed_open_to_existing_file_with_holes3(void)
{
- /*
- * mt_prepare_test not running here
- */
+ /*
+ * mt_prepare_test not running here
+ */
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FSYNC_EVERY, 0);
- el_option(EL_FROTATE_SIZE, 3);
- el_option(EL_FROTATE_NUMBER, 5);
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FSYNC_EVERY, 0);
+ el_option(EL_FROTATE_SIZE, 3);
+ el_option(EL_FROTATE_NUMBER, 5);
- rmdir(WORKDIR);
- mt_ferr(el_option(EL_FPATH, WORKDIR"/log"), ENOENT);
- mkdir(WORKDIR, 0755);
- mt_fok(system("echo qa > \""WORKDIR"/log.1\""));
- mt_fok(system("echo ws > \""WORKDIR"/log.3\""));
- mt_fok(system("echo e > \""WORKDIR"/log.4\""));
- mt_fok(el_puts("123"));
- mt_fok(el_puts("456"));
- mt_fok(el_puts("789"));
- mt_fok(file_check(WORKDIR"/log.0", "ws\n"));
- mt_fok(file_check(WORKDIR"/log.1", "e\n"));
- mt_fok(file_check(WORKDIR"/log.2", "123"));
- mt_fok(file_check(WORKDIR"/log.3", "456"));
- mt_fok(file_check(WORKDIR"/log.4", "789"));
- mt_fok(file_check(WORKDIR"/log", "789"));
- mt_fok(symlink_check("log.4", WORKDIR"/log"));
+ rmdir(WORKDIR);
+ mt_ferr(el_option(EL_FPATH, WORKDIR"/log"), ENOENT);
+ mkdir(WORKDIR, 0755);
+ mt_fok(system("echo qa > \""WORKDIR"/log.1\""));
+ mt_fok(system("echo ws > \""WORKDIR"/log.3\""));
+ mt_fok(system("echo e > \""WORKDIR"/log.4\""));
+ mt_fok(el_puts("123"));
+ mt_fok(el_puts("456"));
+ mt_fok(el_puts("789"));
+ mt_fok(file_check(WORKDIR"/log.0", "ws\n"));
+ mt_fok(file_check(WORKDIR"/log.1", "e\n"));
+ mt_fok(file_check(WORKDIR"/log.2", "123"));
+ mt_fok(file_check(WORKDIR"/log.3", "456"));
+ mt_fok(file_check(WORKDIR"/log.4", "789"));
+ mt_fok(file_check(WORKDIR"/log", "789"));
+ mt_fok(symlink_check("log.4", WORKDIR"/log"));
- unlink(WORKDIR"/log.0");
- unlink(WORKDIR"/log.1");
- unlink(WORKDIR"/log.2");
- unlink(WORKDIR"/log.3");
- unlink(WORKDIR"/log.4");
- unlink(WORKDIR"/log");
- el_cleanup();
+ unlink(WORKDIR"/log.0");
+ unlink(WORKDIR"/log.1");
+ unlink(WORKDIR"/log.2");
+ unlink(WORKDIR"/log.3");
+ unlink(WORKDIR"/log.4");
+ unlink(WORKDIR"/log");
+ el_cleanup();
}
@@ -1313,49 +1304,49 @@ static void file_rotate_write_after_failed_open_to_existing_file_with_holes3(voi
static void file_rotate_and_directory_reappear(void)
{
- /*
- * mt_prepare_test not running here
- */
+ /*
+ * mt_prepare_test not running here
+ */
- el_init();
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FSYNC_EVERY, 0);
- el_option(EL_FROTATE_SIZE, 3);
- el_option(EL_FROTATE_NUMBER, 5);
- mt_fok(el_option(EL_FPATH, WORKDIR"/log"));
+ el_init();
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FSYNC_EVERY, 0);
+ el_option(EL_FROTATE_SIZE, 3);
+ el_option(EL_FROTATE_NUMBER, 5);
+ mt_fok(el_option(EL_FPATH, WORKDIR"/log"));
- mt_fok(el_puts("123"));
- mt_fok(el_puts("456"));
- mt_fok(el_puts("789"));
+ mt_fok(el_puts("123"));
+ mt_fok(el_puts("456"));
+ mt_fok(el_puts("789"));
- unlink(WORKDIR"/log.0");
- unlink(WORKDIR"/log.1");
- unlink(WORKDIR"/log.2");
- unlink(WORKDIR"/log");
+ unlink(WORKDIR"/log.0");
+ unlink(WORKDIR"/log.1");
+ unlink(WORKDIR"/log.2");
+ unlink(WORKDIR"/log");
- rmdir(WORKDIR);
- mt_ferr(el_puts(s9), ENOENT);
- mkdir(WORKDIR, 0755);
+ rmdir(WORKDIR);
+ mt_ferr(el_puts(s9), ENOENT);
+ mkdir(WORKDIR, 0755);
- mt_fok(system("echo 12 > \""WORKDIR"/log.0\""));
- mt_fok(system("echo 45 > \""WORKDIR"/log.1\""));
- mt_fok(system("echo 78 > \""WORKDIR"/log.2\""));
+ mt_fok(system("echo 12 > \""WORKDIR"/log.0\""));
+ mt_fok(system("echo 45 > \""WORKDIR"/log.1\""));
+ mt_fok(system("echo 78 > \""WORKDIR"/log.2\""));
- mt_fok(el_puts("qaz"));
- mt_fok(file_check(WORKDIR"/log.0", "12\n"));
- mt_fok(file_check(WORKDIR"/log.1", "45\n"));
- mt_fok(file_check(WORKDIR"/log.2", "78\n"));
- mt_fok(file_check(WORKDIR"/log.3", "qaz"));
- mt_fok(file_check(WORKDIR"/log", "qaz"));
- mt_fok(symlink_check("log.3", WORKDIR"/log"));
+ mt_fok(el_puts("qaz"));
+ mt_fok(file_check(WORKDIR"/log.0", "12\n"));
+ mt_fok(file_check(WORKDIR"/log.1", "45\n"));
+ mt_fok(file_check(WORKDIR"/log.2", "78\n"));
+ mt_fok(file_check(WORKDIR"/log.3", "qaz"));
+ mt_fok(file_check(WORKDIR"/log", "qaz"));
+ mt_fok(symlink_check("log.3", WORKDIR"/log"));
- unlink(WORKDIR"/log.0");
- unlink(WORKDIR"/log.1");
- unlink(WORKDIR"/log.2");
- unlink(WORKDIR"/log.3");
- unlink(WORKDIR"/log.4");
- unlink(WORKDIR"/log");
- el_cleanup();
+ unlink(WORKDIR"/log.0");
+ unlink(WORKDIR"/log.1");
+ unlink(WORKDIR"/log.2");
+ unlink(WORKDIR"/log.3");
+ unlink(WORKDIR"/log.4");
+ unlink(WORKDIR"/log");
+ el_cleanup();
}
@@ -1365,23 +1356,23 @@ static void file_rotate_and_directory_reappear(void)
static void file_multi_message_on_el_new(void)
{
- struct el *el;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ struct el *el;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- mt_assert((el = el_new()) != NULL);
- el_ooption(el, EL_OUT, EL_OUT_FILE);
- el_ooption(el, EL_FSYNC_EVERY, 0);
- el_ooption(el, EL_FROTATE_NUMBER, 0);
- mt_fok(el_ooption(el, EL_FPATH, WORKDIR"/log"));
+ mt_assert((el = el_new()) != NULL);
+ el_ooption(el, EL_OUT, EL_OUT_FILE);
+ el_ooption(el, EL_FSYNC_EVERY, 0);
+ el_ooption(el, EL_FROTATE_NUMBER, 0);
+ mt_fok(el_ooption(el, EL_FPATH, WORKDIR"/log"));
- el_oputs(el, s9);
- el_oputs(el, s8);
- el_oputs(el, s5);
- mt_fok(file_check(WORKDIR"/log", s9 s8 s5));
+ el_oputs(el, s9);
+ el_oputs(el, s8);
+ el_oputs(el, s5);
+ mt_fok(file_check(WORKDIR"/log", s9 s8 s5));
- unlink(WORKDIR"/log");
- mt_fok(el_destroy(el));
+ unlink(WORKDIR"/log");
+ mt_fok(el_destroy(el));
}
@@ -1391,8 +1382,8 @@ static void file_multi_message_on_el_new(void)
static void file_no_dir_for_logs(void)
{
- mt_ferr(el_option(EL_FPATH, WORKDIR"/i-dont/exist"), ENOENT);
- mt_ferr(el_puts("whatever"), ENOENT);
+ mt_ferr(el_option(EL_FPATH, WORKDIR"/i-dont/exist"), ENOENT);
+ mt_ferr(el_puts("whatever"), ENOENT);
}
@@ -1402,12 +1393,12 @@ static void file_no_dir_for_logs(void)
static void file_dir_removed_after_open_then_created_back_again(void)
{
- mt_fok(el_puts(s8));
- unlink(WORKDIR"/log");
- rmdir(WORKDIR);
- mt_ferr(el_puts(s3), ENOENT);
- mkdir(WORKDIR, 0755);
- mt_fok(el_puts(s8));
+ mt_fok(el_puts(s8));
+ unlink(WORKDIR"/log");
+ rmdir(WORKDIR);
+ mt_ferr(el_puts(s3), ENOENT);
+ mkdir(WORKDIR, 0755);
+ mt_fok(el_puts(s8));
}
@@ -1417,24 +1408,24 @@ static void file_dir_removed_after_open_then_created_back_again(void)
static void file_dir_no_access(void)
{
- mkdir(WORKDIR"/embedlog-no-write", 0555);
- if (getuid() == 0)
- {
- /*
- * root just doesn't give a fuck about no-write-permissions
- */
+ mkdir(WORKDIR"/embedlog-no-write", 0555);
+ if (getuid() == 0)
+ {
+ /*
+ * root just doesn't give a fuck about no-write-permissions
+ */
- mt_fok(el_option(EL_FPATH, WORKDIR"/embedlog-no-write/log"));
- mt_fok(el_puts(s3));
- mt_fok(file_check(WORKDIR"/embedlog-no-write/log", s3));
- }
- else
- {
- mt_ferr(el_option(EL_FPATH, WORKDIR"/embedlog-no-write/log"), EACCES);
- mt_ferr(el_puts(s3), EACCES);
- }
- unlink(WORKDIR"/embedlog-no-write/log");
- rmdir(WORKDIR"/embedlog-no-write");
+ mt_fok(el_option(EL_FPATH, WORKDIR"/embedlog-no-write/log"));
+ mt_fok(el_puts(s3));
+ mt_fok(file_check(WORKDIR"/embedlog-no-write/log", s3));
+ }
+ else
+ {
+ mt_ferr(el_option(EL_FPATH, WORKDIR"/embedlog-no-write/log"), EACCES);
+ mt_ferr(el_puts(s3), EACCES);
+ }
+ unlink(WORKDIR"/embedlog-no-write/log");
+ rmdir(WORKDIR"/embedlog-no-write");
}
@@ -1444,27 +1435,27 @@ static void file_dir_no_access(void)
static void file_no_access_to_file(void)
{
- int fd;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int fd;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- mkdir(WORKDIR"/embedlog-no-write", 0755);
- fd = open(WORKDIR"/embedlog-no-write/log", O_CREAT, 0444);
- close(fd);
+ mkdir(WORKDIR"/embedlog-no-write", 0755);
+ fd = open(WORKDIR"/embedlog-no-write/log", O_CREAT, 0444);
+ close(fd);
- if (getuid() == 0)
- {
- mt_fok(el_option(EL_FPATH, WORKDIR"/embedlog-no-write/log"));
- mt_fok(el_puts(s5));
- mt_fok(file_check(WORKDIR"/embedlog-no-write/log", s5));
- }
- else
- {
- mt_ferr(el_option(EL_FPATH, WORKDIR"/embedlog-no-write/log"), EACCES);
- mt_ferr(el_puts("whatever"), EACCES);
- }
- unlink(WORKDIR"/embedlog-no-write/log");
- rmdir(WORKDIR"/embedlog-no-write");
+ if (getuid() == 0)
+ {
+ mt_fok(el_option(EL_FPATH, WORKDIR"/embedlog-no-write/log"));
+ mt_fok(el_puts(s5));
+ mt_fok(file_check(WORKDIR"/embedlog-no-write/log", s5));
+ }
+ else
+ {
+ mt_ferr(el_option(EL_FPATH, WORKDIR"/embedlog-no-write/log"), EACCES);
+ mt_ferr(el_puts("whatever"), EACCES);
+ }
+ unlink(WORKDIR"/embedlog-no-write/log");
+ rmdir(WORKDIR"/embedlog-no-write");
}
@@ -1474,9 +1465,9 @@ static void file_no_access_to_file(void)
static void file_rotate_no_dir_for_logs(void)
{
- el_option(EL_FROTATE_NUMBER, 5);
- mt_ferr(el_option(EL_FPATH, WORKDIR"/i-dont/exist"), ENOENT);
- mt_ferr(el_puts("whatever"), ENOENT);
+ el_option(EL_FROTATE_NUMBER, 5);
+ mt_ferr(el_option(EL_FPATH, WORKDIR"/i-dont/exist"), ENOENT);
+ mt_ferr(el_puts("whatever"), ENOENT);
}
@@ -1486,49 +1477,49 @@ static void file_rotate_no_dir_for_logs(void)
static void file_rotate_dir_removed_after_open_then_created_back_again(void)
{
- el_option(EL_FROTATE_NUMBER, 5);
- mt_fok(el_puts(s8));
- mt_fok(el_puts(s8));
- mt_fok(el_puts(s8));
- mt_fok(el_puts(s8));
- mt_fok(el_puts(s8));
- unlink(WORKDIR"/log");
- unlink(WORKDIR"/log.0");
- unlink(WORKDIR"/log.1");
- unlink(WORKDIR"/log.2");
- rmdir(WORKDIR);
- mt_ferr(el_puts(s3), ENOENT);
- mkdir(WORKDIR, 0755);
- mt_fok(el_puts(s8));
- mt_fok(el_puts(s5));
+ el_option(EL_FROTATE_NUMBER, 5);
+ mt_fok(el_puts(s8));
+ mt_fok(el_puts(s8));
+ mt_fok(el_puts(s8));
+ mt_fok(el_puts(s8));
+ mt_fok(el_puts(s8));
+ unlink(WORKDIR"/log");
+ unlink(WORKDIR"/log.0");
+ unlink(WORKDIR"/log.1");
+ unlink(WORKDIR"/log.2");
+ rmdir(WORKDIR);
+ mt_ferr(el_puts(s3), ENOENT);
+ mkdir(WORKDIR, 0755);
+ mt_fok(el_puts(s8));
+ mt_fok(el_puts(s5));
- mt_fok(file_check(WORKDIR"/log.0", s8 s5));
- mt_fok(file_check(WORKDIR"/log", s8 s5));
+ mt_fok(file_check(WORKDIR"/log.0", s8 s5));
+ mt_fok(file_check(WORKDIR"/log", s8 s5));
- mt_fok(el_puts(s8));
- mt_fok(el_puts(s3));
- mt_fok(el_puts(s5));
+ mt_fok(el_puts(s8));
+ mt_fok(el_puts(s3));
+ mt_fok(el_puts(s5));
- mt_fok(file_check(WORKDIR"/log.0", s8 s5));
- mt_fok(file_check(WORKDIR"/log.1", s8 s3 s5));
- mt_fok(file_check(WORKDIR"/log", s8 s3 s5));
+ mt_fok(file_check(WORKDIR"/log.0", s8 s5));
+ mt_fok(file_check(WORKDIR"/log.1", s8 s3 s5));
+ mt_fok(file_check(WORKDIR"/log", s8 s3 s5));
- mt_fok(el_puts(s9));
- mt_fok(el_puts(s5));
+ mt_fok(el_puts(s9));
+ mt_fok(el_puts(s5));
- mt_fok(file_check(WORKDIR"/log.0", s8 s5));
- mt_fok(file_check(WORKDIR"/log.1", s8 s3 s5));
- mt_fok(file_check(WORKDIR"/log.2", s9 s5));
- mt_fok(file_check(WORKDIR"/log", s9 s5));
+ mt_fok(file_check(WORKDIR"/log.0", s8 s5));
+ mt_fok(file_check(WORKDIR"/log.1", s8 s3 s5));
+ mt_fok(file_check(WORKDIR"/log.2", s9 s5));
+ mt_fok(file_check(WORKDIR"/log", s9 s5));
- mt_fok(el_puts(s3));
- mt_fok(el_puts(s8));
+ mt_fok(el_puts(s3));
+ mt_fok(el_puts(s8));
- mt_fok(file_check(WORKDIR"/log.0", s8 s5));
- mt_fok(file_check(WORKDIR"/log.1", s8 s3 s5));
- mt_fok(file_check(WORKDIR"/log.2", s9 s5));
- mt_fok(file_check(WORKDIR"/log.3", s3 s8));
- mt_fok(file_check(WORKDIR"/log", s3 s8));
+ mt_fok(file_check(WORKDIR"/log.0", s8 s5));
+ mt_fok(file_check(WORKDIR"/log.1", s8 s3 s5));
+ mt_fok(file_check(WORKDIR"/log.2", s9 s5));
+ mt_fok(file_check(WORKDIR"/log.3", s3 s8));
+ mt_fok(file_check(WORKDIR"/log", s3 s8));
}
@@ -1538,23 +1529,23 @@ static void file_rotate_dir_removed_after_open_then_created_back_again(void)
static void file_rotate_dir_no_access(void)
{
- el_option(EL_FROTATE_NUMBER, 5);
- mkdir(WORKDIR"/embedlog-no-write", 0555);
+ el_option(EL_FROTATE_NUMBER, 5);
+ mkdir(WORKDIR"/embedlog-no-write", 0555);
- if (getuid() == 0)
- {
- mt_fok(el_option(EL_FPATH, WORKDIR"/embedlog-no-write/log"));
- mt_fok(el_puts(s3));
- mt_fok(file_check(WORKDIR"/embedlog-no-write/log.0", s3));
- }
- else
- {
- mt_ferr(el_option(EL_FPATH, WORKDIR"/embedlog-no-write/log"), EACCES);
- mt_ferr(el_puts(s3), EACCES);
- }
+ if (getuid() == 0)
+ {
+ mt_fok(el_option(EL_FPATH, WORKDIR"/embedlog-no-write/log"));
+ mt_fok(el_puts(s3));
+ mt_fok(file_check(WORKDIR"/embedlog-no-write/log.0", s3));
+ }
+ else
+ {
+ mt_ferr(el_option(EL_FPATH, WORKDIR"/embedlog-no-write/log"), EACCES);
+ mt_ferr(el_puts(s3), EACCES);
+ }
- unlink(WORKDIR"/embedlog-no-write/log.0");
- rmdir(WORKDIR"/embedlog-no-write");
+ unlink(WORKDIR"/embedlog-no-write/log.0");
+ rmdir(WORKDIR"/embedlog-no-write");
}
@@ -1564,29 +1555,29 @@ static void file_rotate_dir_no_access(void)
static void file_rotate_no_access_to_file(void)
{
- int fd;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int fd;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- el_option(EL_FROTATE_NUMBER, 5);
- mkdir(WORKDIR"/embedlog-no-write", 0755);
- fd = open(WORKDIR"/embedlog-no-write/log.0", O_CREAT, 0444);
- close(fd);
+ el_option(EL_FROTATE_NUMBER, 5);
+ mkdir(WORKDIR"/embedlog-no-write", 0755);
+ fd = open(WORKDIR"/embedlog-no-write/log.0", O_CREAT, 0444);
+ close(fd);
- if (getuid() == 0)
- {
- mt_fok(el_option(EL_FPATH, WORKDIR"/embedlog-no-write/log"));
- mt_fok(el_puts(s8));
- mt_fok(file_check(WORKDIR"/embedlog-no-write/log.0", s8));
- }
- else
- {
- mt_ferr(el_option(EL_FPATH, WORKDIR"/embedlog-no-write/log"), EACCES);
- mt_ferr(el_puts("whatever"), EACCES);
- }
+ if (getuid() == 0)
+ {
+ mt_fok(el_option(EL_FPATH, WORKDIR"/embedlog-no-write/log"));
+ mt_fok(el_puts(s8));
+ mt_fok(file_check(WORKDIR"/embedlog-no-write/log.0", s8));
+ }
+ else
+ {
+ mt_ferr(el_option(EL_FPATH, WORKDIR"/embedlog-no-write/log"), EACCES);
+ mt_ferr(el_puts("whatever"), EACCES);
+ }
- unlink(WORKDIR"/embedlog-no-write/log.0");
- rmdir(WORKDIR"/embedlog-no-write");
+ unlink(WORKDIR"/embedlog-no-write/log.0");
+ rmdir(WORKDIR"/embedlog-no-write");
}
@@ -1596,14 +1587,14 @@ static void file_rotate_no_access_to_file(void)
static void file_rotate_filename_too_long(void)
{
- char path[8192];
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ char path[8192];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- memset(path, 'a', sizeof(path));
- path[sizeof(path) - 1] = '\0';
- el_option(EL_FROTATE_NUMBER, 5);
- mt_ferr(el_option(EL_FPATH, path), ENAMETOOLONG);
+ memset(path, 'a', sizeof(path));
+ path[sizeof(path) - 1] = '\0';
+ el_option(EL_FROTATE_NUMBER, 5);
+ mt_ferr(el_option(EL_FPATH, path), ENAMETOOLONG);
}
@@ -1613,20 +1604,20 @@ static void file_rotate_filename_too_long(void)
static void file_rotate_path_too_long(void)
{
- char path[PATH_MAX + 2];
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ char path[PATH_MAX + 2];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- memset(path, 'a', sizeof(path));
- path[0] = '/';
- path[sizeof(path) - 5] = '/';
- path[sizeof(path) - 4] = 'f';
- path[sizeof(path) - 4] = 'i';
- path[sizeof(path) - 3] = 'l';
- path[sizeof(path) - 2] = 'e';
- path[sizeof(path) - 1] = '\0';
- el_option(EL_FROTATE_NUMBER, 5);
- mt_ferr(el_option(EL_FPATH, path), ENAMETOOLONG);
+ memset(path, 'a', sizeof(path));
+ path[0] = '/';
+ path[sizeof(path) - 5] = '/';
+ path[sizeof(path) - 4] = 'f';
+ path[sizeof(path) - 4] = 'i';
+ path[sizeof(path) - 3] = 'l';
+ path[sizeof(path) - 2] = 'e';
+ path[sizeof(path) - 1] = '\0';
+ el_option(EL_FROTATE_NUMBER, 5);
+ mt_ferr(el_option(EL_FPATH, path), ENAMETOOLONG);
}
@@ -1636,18 +1627,18 @@ static void file_rotate_path_too_long(void)
static void file_rotate_fail(void)
{
- el_option(EL_FROTATE_NUMBER, 5);
- mt_fok(el_puts(s8));
- mt_fok(el_puts(s8));
- unlink(WORKDIR"/log");
- unlink(WORKDIR"/log.0");
- rmdir(WORKDIR);
- mt_ferr(el_puts(s3), ENOENT);
- mkdir(WORKDIR, 0755);
- mt_fok(el_puts(s8));
+ el_option(EL_FROTATE_NUMBER, 5);
+ mt_fok(el_puts(s8));
+ mt_fok(el_puts(s8));
+ unlink(WORKDIR"/log");
+ unlink(WORKDIR"/log.0");
+ rmdir(WORKDIR);
+ mt_ferr(el_puts(s3), ENOENT);
+ mkdir(WORKDIR, 0755);
+ mt_fok(el_puts(s8));
- mt_fok(file_check(WORKDIR"/log.0", s8));
- mt_fok(file_check(WORKDIR"/log", s8));
+ mt_fok(file_check(WORKDIR"/log.0", s8));
+ mt_fok(file_check(WORKDIR"/log", s8));
}
@@ -1658,9 +1649,9 @@ static void file_rotate_fail(void)
#ifdef RUN_TESTS
static void file_sync_always(void)
{
- el_option(EL_FSYNC_EVERY, 0);
- mt_fok(el_puts(s8));
- mt_fail(file_synced == 1);
+ el_option(EL_FSYNC_EVERY, 0);
+ mt_fok(el_puts(s8));
+ mt_fail(file_synced == 1);
}
#endif
@@ -1672,11 +1663,11 @@ static void file_sync_always(void)
#ifdef RUN_TESTS
static void file_sync_via_flush_function(void)
{
- el_option(EL_FSYNC_EVERY, 16);
- mt_fok(el_puts(s8));
- mt_fail(file_synced == 0);
- mt_fok(el_flush());
- mt_fail(file_synced == 1);
+ el_option(EL_FSYNC_EVERY, 16);
+ mt_fok(el_puts(s8));
+ mt_fail(file_synced == 0);
+ mt_fok(el_flush());
+ mt_fail(file_synced == 1);
}
#endif
@@ -1688,20 +1679,20 @@ static void file_sync_via_flush_function(void)
#ifdef RUN_TESTS
static void file_consecutive_sync_with_flush_function(void)
{
- el_option(EL_FSYNC_EVERY, 16);
- mt_fok(el_puts(s8));
- mt_fail(file_synced == 0);
- mt_fok(el_flush());
- mt_fail(file_synced == 1);
- file_synced = 0;
- mt_fok(el_flush());
- mt_fail(file_synced == 0);
- mt_fok(el_flush());
- mt_fail(file_synced == 0);
- mt_fok(el_puts(s8));
- mt_fail(file_synced == 0);
- mt_fok(el_flush());
- mt_fail(file_synced == 1);
+ el_option(EL_FSYNC_EVERY, 16);
+ mt_fok(el_puts(s8));
+ mt_fail(file_synced == 0);
+ mt_fok(el_flush());
+ mt_fail(file_synced == 1);
+ file_synced = 0;
+ mt_fok(el_flush());
+ mt_fail(file_synced == 0);
+ mt_fok(el_flush());
+ mt_fail(file_synced == 0);
+ mt_fok(el_puts(s8));
+ mt_fail(file_synced == 0);
+ mt_fok(el_flush());
+ mt_fail(file_synced == 1);
}
#endif
@@ -1713,23 +1704,23 @@ static void file_consecutive_sync_with_flush_function(void)
#ifdef RUN_TESTS
static void file_sync_periodic(void)
{
- el_option(EL_FSYNC_EVERY, 8);
- mt_fok(el_puts(s5));
- mt_fail(file_synced == 0);
- mt_fok(el_puts(s3));
- mt_fail(file_synced == 1);
- file_synced = 0;
+ el_option(EL_FSYNC_EVERY, 8);
+ mt_fok(el_puts(s5));
+ mt_fail(file_synced == 0);
+ mt_fok(el_puts(s3));
+ mt_fail(file_synced == 1);
+ file_synced = 0;
- mt_fok(el_puts(s5));
- mt_fail(file_synced == 0);
- mt_fok(el_puts(s8));
- mt_fail(file_synced == 1);
- file_synced = 0;
+ mt_fok(el_puts(s5));
+ mt_fail(file_synced == 0);
+ mt_fok(el_puts(s8));
+ mt_fail(file_synced == 1);
+ file_synced = 0;
- mt_fok(el_puts(s5));
- mt_fail(file_synced == 0);
- mt_fok(el_puts(s5));
- mt_fail(file_synced == 1);
+ mt_fok(el_puts(s5));
+ mt_fail(file_synced == 0);
+ mt_fok(el_puts(s5));
+ mt_fail(file_synced == 1);
}
#endif
@@ -1741,49 +1732,49 @@ static void file_sync_periodic(void)
#ifdef RUN_TESTS
static void file_sync_level(void)
{
- el_option(EL_FSYNC_EVERY, 1024);
- el_option(EL_FSYNC_LEVEL, EL_ERROR);
- el_option(EL_LEVEL, EL_DBG);
- mt_fok(el_print(ELW, s8));
- mt_fail(file_synced == 0);
- mt_fok(el_print(ELW, s8));
- mt_fail(file_synced == 0);
- mt_fok(el_puts(s5));
- mt_fail(file_synced == 0);
+ el_option(EL_FSYNC_EVERY, 1024);
+ el_option(EL_FSYNC_LEVEL, EL_ERROR);
+ el_option(EL_LEVEL, EL_DBG);
+ mt_fok(el_print(ELW, s8));
+ mt_fail(file_synced == 0);
+ mt_fok(el_print(ELW, s8));
+ mt_fail(file_synced == 0);
+ mt_fok(el_puts(s5));
+ mt_fail(file_synced == 0);
- mt_fok(el_print(ELE, s1));
- mt_fail(file_synced == 1);
- file_synced = 0;
+ mt_fok(el_print(ELE, s1));
+ mt_fail(file_synced == 1);
+ file_synced = 0;
- mt_fok(el_print(ELC, s1));
- mt_fail(file_synced == 1);
- file_synced = 0;
+ mt_fok(el_print(ELC, s1));
+ mt_fail(file_synced == 1);
+ file_synced = 0;
- mt_fok(el_print(ELA, s1));
- mt_fail(file_synced == 1);
- file_synced = 0;
+ mt_fok(el_print(ELA, s1));
+ mt_fail(file_synced == 1);
+ file_synced = 0;
- mt_fok(el_print(ELF, s1));
- mt_fail(file_synced == 1);
- file_synced = 0;
+ mt_fok(el_print(ELF, s1));
+ mt_fail(file_synced == 1);
+ file_synced = 0;
- mt_fok(el_print(ELW, s1));
- mt_fail(file_synced == 0);
+ mt_fok(el_print(ELW, s1));
+ mt_fail(file_synced == 0);
- mt_fok(el_print(ELN, s1));
- mt_fail(file_synced == 0);
+ mt_fok(el_print(ELN, s1));
+ mt_fail(file_synced == 0);
- mt_fok(el_print(ELI, s1));
- mt_fail(file_synced == 0);
+ mt_fok(el_print(ELI, s1));
+ mt_fail(file_synced == 0);
- mt_fok(el_print(ELD, s1));
- mt_fail(file_synced == 0);
+ mt_fok(el_print(ELD, s1));
+ mt_fail(file_synced == 0);
- mt_fok(el_pmemory_table(ELI, s8, sizeof(s8)));
- mt_fail(file_synced == 0);
+ mt_fok(el_pmemory_table(ELI, s8, sizeof(s8)));
+ mt_fail(file_synced == 0);
- mt_fok(el_pmemory_table(ELF, s8, sizeof(s8)));
- mt_fail(file_synced == 1);
+ mt_fok(el_pmemory_table(ELF, s8, sizeof(s8)));
+ mt_fail(file_synced == 1);
}
#endif
@@ -1794,63 +1785,56 @@ static void file_sync_level(void)
static void file_rotate_with_padding_in_name
(
- int *arg
+ int *arg
)
{
- int i;
- int rotate_number_count;
- int rotate_number;
- struct dirent *dirent;
- DIR *dir;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int i;
+ int rotate_number_count;
+ int rotate_number;
+ struct dirent *dirent;
+ DIR *dir;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- /* rotate number = 10, will produce single digit number
- * from .0 to .9. Smart counting logic is in production
- * code so avoid it here to make sure we do not make
- * same bug in prod and test code which could make test
- * do false pasitive.
- */
- rotate_number = *arg;
- if (rotate_number <= 10)
- rotate_number_count = 1;
- else if (rotate_number <= 100)
- rotate_number_count = 2;
- else if (rotate_number <= 1000)
- rotate_number_count = 3;
- else if (rotate_number <= 10000)
- rotate_number_count = 4;
+ /* rotate number = 10, will produce single digit number
+ * from .0 to .9. Smart counting logic is in production
+ * code so avoid it here to make sure we do not make
+ * same bug in prod and test code which could make test
+ * do false pasitive. */
+ rotate_number = *arg;
+ if (rotate_number <= 10) rotate_number_count = 1;
+ else if (rotate_number <= 100) rotate_number_count = 2;
+ else if (rotate_number <= 1000) rotate_number_count = 3;
+ else if (rotate_number <= 10000) rotate_number_count = 4;
- el_option(EL_FROTATE_SIZE, 1);
- el_option(EL_FROTATE_NUMBER, rotate_number);
+ el_option(EL_FROTATE_SIZE, 1);
+ el_option(EL_FROTATE_NUMBER, rotate_number);
- /* perform some more rotation to make sure we create all
- * possible files
- */
- for (i = 0; i != rotate_number + 5; ++i)
- el_puts(s1);
+ /* perform some more rotation to make sure we create all
+ * possible files */
+ for (i = 0; i != rotate_number + 5; ++i) el_puts(s1);
- for (i = 0; i != rotate_number; ++i)
- {
- char expected_file[PATH_MAX];
+ for (i = 0; i != rotate_number; ++i)
+ {
+ char expected_file[PATH_MAX];
- sprintf(expected_file, WORKDIR"/log.%0*d", rotate_number_count, i);
- mt_fail(access(expected_file, F_OK) == 0);
- unlink(expected_file);
- }
+ sprintf(expected_file, WORKDIR"/log.%0*d", rotate_number_count, i);
+ mt_fail(access(expected_file, F_OK) == 0);
+ unlink(expected_file);
+ }
- unlink(WORKDIR"/log");
+ unlink(WORKDIR"/log");
- dir = opendir(WORKDIR);
- while ((dirent = readdir(dir)))
- {
- if (strcmp(dirent->d_name, ".") == 0 ||
- strcmp(dirent->d_name, "..") == 0)
- continue;
- mt_fail(0 && "unexpected file left in WORKDIR");
- fprintf(stderr, "# %s\n", dirent->d_name);
- }
- system("rm -f "WORKDIR"/*");
+ dir = opendir(WORKDIR);
+ while ((dirent = readdir(dir)))
+ {
+ if (strcmp(dirent->d_name, ".") == 0 ||
+ strcmp(dirent->d_name, "..") == 0)
+ continue;
+ mt_fail(0 && "unexpected file left in WORKDIR");
+ fprintf(stderr, "# %s\n", dirent->d_name);
+ }
+ system("rm -f "WORKDIR"/*");
}
@@ -1870,161 +1854,147 @@ static void file_rotate_with_padding_in_name
static int print_check(void)
{
- char line[line_length + 1];
- char expected[line_length + 1];
- FILE *f;
- int curr_tid;
- int curr_mid;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- /* concat and sort files, let's take shortcut with system tools,
- * because why not?
- */
-
- system("cat "WORKDIR"/log* | sort > "WORKDIR"/result");
-
- f = fopen(WORKDIR"/result", "r");
- if (f == NULL)
- {
- fprintf(stderr, WORKDIR"/result does not exist\n");
- return -1;
- }
-
- curr_tid = 0;
- curr_mid = 0;
- for (;;)
- {
- line[sizeof(line) - 1] = 0x55;
-
- if (fgets(line, sizeof(line), f) == NULL)
- {
- if (feof(f))
- {
- /* got all lines without errors
- */
-
- break;
- }
-
- perror("fgets()");
- fclose(f);
- return -1;
- }
-
- if (line[sizeof(line) - 1] == '\0' && line[sizeof(line) - 2] != '\n')
- {
- fprintf(stderr, "line is too long '%s', thread interlacing?\n",
- line);
- fclose(f);
- return -1;
- }
-
- sprintf(expected, "%02d%04d\n", curr_tid, curr_mid);
- if (strcmp(expected, line) != 0)
- {
- fprintf(stderr, "expected different than line: %s != %s\n",
- expected, line);
- fclose(f);
- return -1;
- }
-
- if (++curr_mid == prints_per_thread)
- {
- ++curr_tid;
- curr_mid = 0;
- }
- }
-
- if (curr_tid != number_of_threads || curr_mid != 0)
- {
- fprintf(stderr, "file didn't contain all entries, tid: %d, mid: %d\n",
- curr_tid, curr_mid);
- fclose(f);
- return -1;
- }
-
- fclose(f);
- return 0;
+ char line[line_length + 1];
+ char expected[line_length + 1];
+ FILE *f;
+ int curr_tid;
+ int curr_mid;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ /* concat and sort files, let's take shortcut with system tools,
+ * because why not? */
+ system("cat "WORKDIR"/log* | sort > "WORKDIR"/result");
+
+ f = fopen(WORKDIR"/result", "r");
+ if (f == NULL)
+ {
+ fprintf(stderr, WORKDIR"/result does not exist\n");
+ return -1;
+ }
+
+ curr_tid = 0;
+ curr_mid = 0;
+ for (;;)
+ {
+ line[sizeof(line) - 1] = 0x55;
+
+ if (fgets(line, sizeof(line), f) == NULL)
+ {
+ if (feof(f)) break; /* got all lines without errors */
+
+ perror("fgets()");
+ fclose(f);
+ return -1;
+ }
+
+ if (line[sizeof(line) - 1] == '\0' && line[sizeof(line) - 2] != '\n')
+ {
+ fprintf(stderr, "line is too long '%s', thread interlacing?\n",
+ line);
+ fclose(f);
+ return -1;
+ }
+
+ sprintf(expected, "%02d%04d\n", curr_tid, curr_mid);
+ if (strcmp(expected, line) != 0)
+ {
+ fprintf(stderr, "expected different than line: %s != %s\n",
+ expected, line);
+ fclose(f);
+ return -1;
+ }
+
+ if (++curr_mid == prints_per_thread)
+ {
+ ++curr_tid;
+ curr_mid = 0;
+ }
+ }
+
+ if (curr_tid != number_of_threads || curr_mid != 0)
+ {
+ fprintf(stderr, "file didn't contain all entries, tid: %d, mid: %d\n",
+ curr_tid, curr_mid);
+ fclose(f);
+ return -1;
+ }
+
+ fclose(f);
+ return 0;
}
static void *print_t
(
- void *arg
+ void *arg
)
{
- char msg[line_length + 1];
- int i;
- int n;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ char msg[line_length + 1];
+ int i;
+ int n;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- n = *(int *)arg;
+ n = *(int *)arg;
- for (i = 0; i != prints_per_thread; ++i)
- {
- sprintf(msg, "%02d%04d", n, i);
- el_print(ELN, "%s", msg);
- }
+ for (i = 0; i != prints_per_thread; ++i)
+ {
+ sprintf(msg, "%02d%04d", n, i);
+ el_print(ELN, "%s", msg);
+ }
- return NULL;
+ return NULL;
}
static void file_print_threaded(void)
{
- pthread_t pt[number_of_threads];
- int i, n[number_of_threads];;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- el_init();
+ pthread_t pt[number_of_threads];
+ int i, n[number_of_threads];;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- el_option(EL_THREAD_SAFE, 1);
- el_option(EL_PRINT_LEVEL, 0);
- el_option(EL_OUT, EL_OUT_FILE);
- /* rotate around 200kB, line is 7 bytes long, so this will
- * get us 28571 prints before rotation
- */
+ el_init();
- el_option(EL_FROTATE_SIZE, max_file_size);
- el_option(EL_FROTATE_NUMBER, 99);
- el_option(EL_FROTATE_SYMLINK, 0);
- el_option(EL_FPATH, WORKDIR"/log");
- el_option(EL_FSYNC_EVERY, max_file_size / 4);
+ el_option(EL_THREAD_SAFE, 1);
+ el_option(EL_PRINT_LEVEL, 0);
+ el_option(EL_OUT, EL_OUT_FILE);
- for (i = 0; i != number_of_threads; ++i)
- {
- n[i] = i;
- pthread_create(&pt[i], NULL, print_t, &n[i]);
- }
+ /* rotate around 200kB, line is 7 bytes long, so this will
+ * get us 28571 prints before rotation */
+ el_option(EL_FROTATE_SIZE, max_file_size);
+ el_option(EL_FROTATE_NUMBER, 99);
+ el_option(EL_FROTATE_SYMLINK, 0);
+ el_option(EL_FPATH, WORKDIR"/log");
+ el_option(EL_FSYNC_EVERY, max_file_size / 4);
- for (i = 0; i != number_of_threads; ++i)
- {
- pthread_join(pt[i], NULL);
- }
+ for (i = 0; i != number_of_threads; ++i)
+ {
+ n[i] = i;
+ pthread_create(&pt[i], NULL, print_t, &n[i]);
+ }
- /* do it before print_check() so any buffered data is flushed
- * to disk, otherwise files will be incomplete
- */
+ for (i = 0; i != number_of_threads; ++i)
+ pthread_join(pt[i], NULL);
- el_flush();
+ /* do it before print_check() so any buffered data is flushed
+ * to disk, otherwise files will be incomplete */
+ el_flush();
- mt_fok(print_check());
+ mt_fok(print_check());
- for (i = 0; i != 99; ++i)
- {
- char path[PATH_MAX];
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ for (i = 0; i != 99; ++i)
+ {
+ char path[PATH_MAX];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- sprintf(path, WORKDIR"/log.%02d", i);
- unlink(path);
- }
+ sprintf(path, WORKDIR"/log.%02d", i);
+ unlink(path);
+ }
- unlink(WORKDIR"/result");
- el_cleanup();
+ unlink(WORKDIR"/result");
+ el_cleanup();
}
#endif /* ENABLE_PTHREAD */
@@ -2042,107 +2012,107 @@ static void file_print_threaded(void)
void el_file_test_group(void)
{
- int arg; /* argument for tests */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int arg; /* argument for tests */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
#if ENABLE_OUT_FILE
- mkdir(WORKDIR, 0755);
+ mkdir(WORKDIR, 0755);
#if ENABLE_PTHREAD
- mt_run(file_print_threaded);
+ mt_run(file_print_threaded);
#endif
- mt_run(file_print_after_cleanup);
- mt_run(file_print_without_setting_file);
- mt_run(file_write_after_failed_open);
- mt_run(file_write_after_failed_open_to_existing_file);
- mt_run(file_rotate_directory_deleted);
- mt_run(file_rotate_directory_reappear_after_delete);
- mt_run(file_rotate_write_after_failed_open);
- mt_run(file_rotate_write_after_failed_open_to_existing_file);
- mt_run(file_rotate_write_after_failed_open_to_existing_file_with_holes);
- mt_run(file_rotate_write_after_failed_open_to_existing_file_with_holes2);
- mt_run(file_rotate_write_after_failed_open_to_existing_file_with_holes3);
- mt_run(file_rotate_and_directory_reappear);
- mt_run(file_multi_message_on_el_new);
-
- mt_prepare_test = &test_prepare;
- mt_cleanup_test = &test_cleanup;
+ mt_run(file_print_after_cleanup);
+ mt_run(file_print_without_setting_file);
+ mt_run(file_write_after_failed_open);
+ mt_run(file_write_after_failed_open_to_existing_file);
+ mt_run(file_rotate_directory_deleted);
+ mt_run(file_rotate_directory_reappear_after_delete);
+ mt_run(file_rotate_write_after_failed_open);
+ mt_run(file_rotate_write_after_failed_open_to_existing_file);
+ mt_run(file_rotate_write_after_failed_open_to_existing_file_with_holes);
+ mt_run(file_rotate_write_after_failed_open_to_existing_file_with_holes2);
+ mt_run(file_rotate_write_after_failed_open_to_existing_file_with_holes3);
+ mt_run(file_rotate_and_directory_reappear);
+ mt_run(file_multi_message_on_el_new);
+
+ mt_prepare_test = &test_prepare;
+ mt_cleanup_test = &test_cleanup;
#define FILE_ROTATE_WITH_PADDING_IN_NAME(ARG) \
- arg = ARG; \
- mt_run_param_named(file_rotate_with_padding_in_name, &arg, \
- "file_rotate_with_padding_in_name_" #ARG);
- FILE_ROTATE_WITH_PADDING_IN_NAME(4);
- FILE_ROTATE_WITH_PADDING_IN_NAME(9);
- FILE_ROTATE_WITH_PADDING_IN_NAME(10);
- FILE_ROTATE_WITH_PADDING_IN_NAME(11);
- FILE_ROTATE_WITH_PADDING_IN_NAME(41);
- FILE_ROTATE_WITH_PADDING_IN_NAME(99);
- FILE_ROTATE_WITH_PADDING_IN_NAME(100);
- FILE_ROTATE_WITH_PADDING_IN_NAME(101);
- FILE_ROTATE_WITH_PADDING_IN_NAME(242);
- FILE_ROTATE_WITH_PADDING_IN_NAME(999);
- FILE_ROTATE_WITH_PADDING_IN_NAME(1000);
- FILE_ROTATE_WITH_PADDING_IN_NAME(1001);
-
- mt_run(file_single_message);
- mt_run(file_multi_message);
- mt_run(file_reopen);
- mt_run(file_reopen_different_file);
- mt_run(file_unexpected_third_party_delete);
- mt_run(file_directory_deleted);
- mt_run(file_directory_reappear_after_delete);
- mt_run(file_and_directory_reapear);
- mt_run(file_filename_too_long);
- mt_run(file_path_too_long);
- mt_run(file_rotate_1_no_rotate);
- mt_run(file_rotate_1_exact_print);
- mt_run(file_rotate_1_overflow_but_no_rotate);
- mt_run(file_rotate_1_overflow);
- mt_run(file_rotate_1_overflow_exact);
- mt_run(file_rotate_1_reopen);
- mt_run(file_rotate_1_unexpected_third_party_remove);
- mt_run(file_rotate_1_change_size_up);
- mt_run(file_rotate_1_change_size_down);
- mt_run(file_rotate_2_no_rotate);
- mt_run(file_rotate_2_exact_print);
- mt_run(file_rotate_2_overflow_but_no_rotate);
- mt_run(file_rotate_2_overflow);
- mt_run(file_rotate_2_overflow_exact);
- mt_run(file_rotate_2_reopen);
- mt_run(file_rotate_2_unexpected_third_party_remove);
- mt_run(file_rotate_2_change_size_up);
- mt_run(file_rotate_2_change_size_down);
- mt_run(file_rotate_2_many_rotates);
- mt_run(file_rotate_5_no_rotate);
- mt_run(file_rotate_5_exact_print_rotate);
- mt_run(file_rotate_5_overflow_but_no_rotate);
- mt_run(file_rotate_5_overflow);
- mt_run(file_rotate_5_overflow_exact);
- mt_run(file_rotate_5_reopen);
- mt_run(file_rotate_5_hole_in_log_rotate);
- mt_run(file_rotate_5_rename_file_halfway);
- mt_run(file_no_dir_for_logs);
- mt_run(file_dir_removed_after_open_then_created_back_again);
- mt_run(file_dir_no_access);
- mt_run(file_no_access_to_file);
- mt_run(file_rotate_no_dir_for_logs);
- mt_run(file_rotate_dir_removed_after_open_then_created_back_again);
- mt_run(file_rotate_dir_no_access);
- mt_run(file_rotate_no_access_to_file);
- mt_run(file_rotate_filename_too_long);
- mt_run(file_rotate_path_too_long);
- mt_run(file_rotate_fail);
+ arg = ARG; \
+ mt_run_param_named(file_rotate_with_padding_in_name, &arg, \
+ "file_rotate_with_padding_in_name_" #ARG);
+ FILE_ROTATE_WITH_PADDING_IN_NAME(4);
+ FILE_ROTATE_WITH_PADDING_IN_NAME(9);
+ FILE_ROTATE_WITH_PADDING_IN_NAME(10);
+ FILE_ROTATE_WITH_PADDING_IN_NAME(11);
+ FILE_ROTATE_WITH_PADDING_IN_NAME(41);
+ FILE_ROTATE_WITH_PADDING_IN_NAME(99);
+ FILE_ROTATE_WITH_PADDING_IN_NAME(100);
+ FILE_ROTATE_WITH_PADDING_IN_NAME(101);
+ FILE_ROTATE_WITH_PADDING_IN_NAME(242);
+ FILE_ROTATE_WITH_PADDING_IN_NAME(999);
+ FILE_ROTATE_WITH_PADDING_IN_NAME(1000);
+ FILE_ROTATE_WITH_PADDING_IN_NAME(1001);
+
+ mt_run(file_single_message);
+ mt_run(file_multi_message);
+ mt_run(file_reopen);
+ mt_run(file_reopen_different_file);
+ mt_run(file_unexpected_third_party_delete);
+ mt_run(file_directory_deleted);
+ mt_run(file_directory_reappear_after_delete);
+ mt_run(file_and_directory_reapear);
+ mt_run(file_filename_too_long);
+ mt_run(file_path_too_long);
+ mt_run(file_rotate_1_no_rotate);
+ mt_run(file_rotate_1_exact_print);
+ mt_run(file_rotate_1_overflow_but_no_rotate);
+ mt_run(file_rotate_1_overflow);
+ mt_run(file_rotate_1_overflow_exact);
+ mt_run(file_rotate_1_reopen);
+ mt_run(file_rotate_1_unexpected_third_party_remove);
+ mt_run(file_rotate_1_change_size_up);
+ mt_run(file_rotate_1_change_size_down);
+ mt_run(file_rotate_2_no_rotate);
+ mt_run(file_rotate_2_exact_print);
+ mt_run(file_rotate_2_overflow_but_no_rotate);
+ mt_run(file_rotate_2_overflow);
+ mt_run(file_rotate_2_overflow_exact);
+ mt_run(file_rotate_2_reopen);
+ mt_run(file_rotate_2_unexpected_third_party_remove);
+ mt_run(file_rotate_2_change_size_up);
+ mt_run(file_rotate_2_change_size_down);
+ mt_run(file_rotate_2_many_rotates);
+ mt_run(file_rotate_5_no_rotate);
+ mt_run(file_rotate_5_exact_print_rotate);
+ mt_run(file_rotate_5_overflow_but_no_rotate);
+ mt_run(file_rotate_5_overflow);
+ mt_run(file_rotate_5_overflow_exact);
+ mt_run(file_rotate_5_reopen);
+ mt_run(file_rotate_5_hole_in_log_rotate);
+ mt_run(file_rotate_5_rename_file_halfway);
+ mt_run(file_no_dir_for_logs);
+ mt_run(file_dir_removed_after_open_then_created_back_again);
+ mt_run(file_dir_no_access);
+ mt_run(file_no_access_to_file);
+ mt_run(file_rotate_no_dir_for_logs);
+ mt_run(file_rotate_dir_removed_after_open_then_created_back_again);
+ mt_run(file_rotate_dir_no_access);
+ mt_run(file_rotate_no_access_to_file);
+ mt_run(file_rotate_filename_too_long);
+ mt_run(file_rotate_path_too_long);
+ mt_run(file_rotate_fail);
#ifdef RUN_TESTS
- mt_run(file_sync_always);
- mt_run(file_sync_periodic);
- mt_run(file_sync_level);
- mt_run(file_sync_via_flush_function);
- mt_run(file_consecutive_sync_with_flush_function);
+ mt_run(file_sync_always);
+ mt_run(file_sync_periodic);
+ mt_run(file_sync_level);
+ mt_run(file_sync_via_flush_function);
+ mt_run(file_consecutive_sync_with_flush_function);
#endif
- rmdir(WORKDIR);
+ rmdir(WORKDIR);
#endif
}
diff --git a/tst/test-el-options.c b/tst/test-el-options.c
index 074548a..ec67700 100644
--- a/tst/test-el-options.c
+++ b/tst/test-el-options.c
@@ -47,7 +47,7 @@ extern struct el g_el; /* global embedlog el */
static void test_prepare(void)
{
- el_init();
+ el_init();
}
@@ -57,7 +57,7 @@ static void test_prepare(void)
static void test_cleanup(void)
{
- el_cleanup();
+ el_cleanup();
}
@@ -73,56 +73,56 @@ static void test_cleanup(void)
static void options_init(void)
{
- struct el default_el; /* expected default el */
- struct el el; /* custom el to init */
- struct el *elp; /* heap allocated el */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- memset(&default_el, 0, sizeof(default_el));
- default_el.outputs = EL_OUT_STDERR;
- default_el.level = EL_INFO;
- default_el.level_current_msg = EL_DBG;
- default_el.colors = 0;
- default_el.timestamp = EL_TS_OFF;
- default_el.timestamp_timer = EL_TS_TM_TIME;
- default_el.timestamp_fractions = EL_TS_FRACT_OFF;
- default_el.print_log_level = 1;
- default_el.print_newline = 1;
+ struct el default_el; /* expected default el */
+ struct el el; /* custom el to init */
+ struct el *elp; /* heap allocated el */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ memset(&default_el, 0, sizeof(default_el));
+ default_el.outputs = EL_OUT_STDERR;
+ default_el.level = EL_INFO;
+ default_el.level_current_msg = EL_DBG;
+ default_el.colors = 0;
+ default_el.timestamp = EL_TS_OFF;
+ default_el.timestamp_timer = EL_TS_TM_TIME;
+ default_el.timestamp_fractions = EL_TS_FRACT_OFF;
+ default_el.print_log_level = 1;
+ default_el.print_newline = 1;
#if ENABLE_OUT_FILE
- default_el.fsync_level = EL_FATAL;
- default_el.funcinfo = 0;
- default_el.finfo = 0;
- default_el.frotate_number = 0;
- default_el.fcurrent_rotate = 0;
- default_el.frotate_size = 0;
- default_el.frotate_symlink = 1;
- default_el.fpos = 0;
- default_el.file = NULL;
- default_el.fsync_every = 32768;
- default_el.fname = NULL;
+ default_el.fsync_level = EL_FATAL;
+ default_el.funcinfo = 0;
+ default_el.finfo = 0;
+ default_el.frotate_number = 0;
+ default_el.fcurrent_rotate = 0;
+ default_el.frotate_size = 0;
+ default_el.frotate_symlink = 1;
+ default_el.fpos = 0;
+ default_el.file = NULL;
+ default_el.fsync_every = 32768;
+ default_el.fname = NULL;
#endif
#if ENABLE_OUT_TTY
- default_el.serial_fd = -1;
+ default_el.serial_fd = -1;
#endif
#if ENABLE_OUT_CUSTOM
- default_el.custom_put = NULL;
+ default_el.custom_put = NULL;
#endif
- mt_fail(el_oinit(&el) == 0);
- mt_fail(memcmp(&el, &default_el, sizeof(el)) == 0);
- mt_fail(el_ocleanup(&el) == 0);
+ mt_fail(el_oinit(&el) == 0);
+ mt_fail(memcmp(&el, &default_el, sizeof(el)) == 0);
+ mt_fail(el_ocleanup(&el) == 0);
- mt_fail(el_init() == 0);
- mt_fail(memcmp(&g_el, &default_el, sizeof(default_el)) == 0);
- mt_fail(el_cleanup() == 0);
+ mt_fail(el_init() == 0);
+ mt_fail(memcmp(&g_el, &default_el, sizeof(default_el)) == 0);
+ mt_fail(el_cleanup() == 0);
- mt_fail((elp = el_new()) != NULL);
- mt_fail(memcmp(elp, &default_el, sizeof(*elp)) == 0);
- mt_fok(el_destroy(elp));
+ mt_fail((elp = el_new()) != NULL);
+ mt_fail(memcmp(elp, &default_el, sizeof(*elp)) == 0);
+ mt_fok(el_destroy(elp));
}
@@ -132,9 +132,9 @@ static void options_init(void)
static void options_init_einval(void)
{
- errno = 0;
- mt_fail(el_oinit(NULL) == -1);
- mt_fail(errno == EINVAL);
+ errno = 0;
+ mt_fail(el_oinit(NULL) == -1);
+ mt_fail(errno == EINVAL);
}
@@ -144,23 +144,23 @@ static void options_init_einval(void)
static void options_level_set(void)
{
- int i;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- for (i = 0; i != 16; ++i)
- {
- if (i <= EL_DBG)
- {
- mt_fail(el_option(EL_LEVEL, i) == 0);
- mt_fail(g_el.level == i);
- }
- else
- {
- mt_ferr(el_option(EL_LEVEL, i), EINVAL);
- mt_fail(g_el.level == EL_DBG);
- }
- }
+ int i;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ for (i = 0; i != 16; ++i)
+ {
+ if (i <= EL_DBG)
+ {
+ mt_fail(el_option(EL_LEVEL, i) == 0);
+ mt_fail(g_el.level == i);
+ }
+ else
+ {
+ mt_ferr(el_option(EL_LEVEL, i), EINVAL);
+ mt_fail(g_el.level == EL_DBG);
+ }
+ }
}
@@ -170,27 +170,27 @@ static void options_level_set(void)
static void options_fsync_level_set(void)
{
- int i;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int i;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- for (i = 0; i != 16; ++i)
- {
+ for (i = 0; i != 16; ++i)
+ {
#if ENABLE_OUT_FILE
- if (i <= EL_DBG)
- {
- mt_fail(el_option(EL_FSYNC_LEVEL, i) == 0);
- mt_fail(g_el.fsync_level == i);
- }
- else
- {
- mt_ferr(el_option(EL_FSYNC_LEVEL, i), EINVAL);
- mt_fail(g_el.fsync_level == EL_DBG);
- }
+ if (i <= EL_DBG)
+ {
+ mt_fail(el_option(EL_FSYNC_LEVEL, i) == 0);
+ mt_fail(g_el.fsync_level == i);
+ }
+ else
+ {
+ mt_ferr(el_option(EL_FSYNC_LEVEL, i), EINVAL);
+ mt_fail(g_el.fsync_level == EL_DBG);
+ }
#else
- mt_ferr(el_option(EL_FSYNC_LEVEL, i), ENOSYS);
+ mt_ferr(el_option(EL_FSYNC_LEVEL, i), ENOSYS);
#endif
- }
+ }
}
@@ -200,88 +200,67 @@ static void options_fsync_level_set(void)
static void options_output(void)
{
- int i;
- int valid_outs = ALL_OUTS;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int i;
+ int valid_outs = ALL_OUTS;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- for (i = 0; i != ALL_OUTS + 100; ++i)
- {
- int ok = 1;
+ for (i = 0; i != ALL_OUTS + 100; ++i)
+ {
+ int ok = 1;
- if (i > ALL_OUTS)
- {
- mt_ferr(el_option(EL_OUT, i), EINVAL);
- continue;
- }
+ if (i > ALL_OUTS)
+ {
+ mt_ferr(el_option(EL_OUT, i), EINVAL);
+ continue;
+ }
#ifndef ENABLE_OUT_STDERR
- valid_outs &= ~EL_OUT_STDERR;
- if (i & EL_OUT_STDERR)
- {
- ok = 0;
- }
+ valid_outs &= ~EL_OUT_STDERR;
+ if (i & EL_OUT_STDERR) ok = 0;
#endif
#ifndef ENABLE_OUT_STDERR
- valid_outs &= ~EL_OUT_STDOUT;
- if (i & EL_OUT_STDOUT)
- {
- ok = 0;
- }
+ valid_outs &= ~EL_OUT_STDOUT;
+ if (i & EL_OUT_STDOUT) ok = 0;
#endif
#ifndef ENABLE_OUT_SYSLOG
- valid_outs &= ~EL_OUT_SYSLOG;
- if (i & EL_OUT_SYSLOG)
- {
- ok = 0;
- }
+ valid_outs &= ~EL_OUT_SYSLOG;
+ if (i & EL_OUT_SYSLOG) ok = 0;
#endif
#ifndef ENABLE_OUT_FILE
- valid_outs &= ~EL_OUT_FILE;
- if (i & EL_OUT_FILE)
- {
- ok = 0;
- }
+ valid_outs &= ~EL_OUT_FILE;
+ if (i & EL_OUT_FILE) ok = 0;
#endif
#ifndef ENABLE_OUT_NET
- valid_outs &= ~EL_OUT_NET;
- if (i & EL_OUT_NET)
- {
- ok = 0;
- }
+ valid_outs &= ~EL_OUT_NET;
+ if (i & EL_OUT_NET) ok = 0;
#endif
#ifndef ENABLE_OUT_TTY
- valid_outs &= ~EL_OUT_TTY;
- if (i & EL_OUT_TTY)
- {
- ok = 0;
- }
+ valid_outs &= ~EL_OUT_TTY;
+ if (i & EL_OUT_TTY) ok = 0;
#endif
#ifndef ENABLE_OUT_CUSTOM
- valid_outs &= ~EL_OUT_CUSTOM;
- if (i & EL_OUT_CUSTOM)
- {
- ok = 0;
- }
+ valid_outs &= ~EL_OUT_CUSTOM;
+ if (i & EL_OUT_CUSTOM) ok = 0;
#endif
- if (ok)
- {
- mt_fok(el_option(EL_OUT, i));
- continue;
- }
+ if (ok)
+ {
+ mt_fok(el_option(EL_OUT, i));
+ continue;
+ }
- mt_ferr(el_option(EL_OUT, i), ENODEV);
- }
+ mt_ferr(el_option(EL_OUT, i), ENODEV);
+ }
- mt_fok(el_option(EL_OUT, EL_OUT_ALL));
- mt_fail(g_el.outputs == valid_outs);
+ mt_fok(el_option(EL_OUT, EL_OUT_ALL));
+ mt_fail(g_el.outputs == valid_outs);
}
@@ -291,17 +270,17 @@ static void options_output(void)
static void options_log_allowed(void)
{
- g_el.level = EL_ERROR;
- g_el.outputs = EL_OUT_STDERR;
-
- mt_fail(el_log_allowed(&g_el, EL_FATAL) == 1);
- mt_fail(el_log_allowed(&g_el, EL_ALERT) == 1);
- mt_fail(el_log_allowed(&g_el, EL_CRIT) == 1);
- mt_fail(el_log_allowed(&g_el, EL_ERROR) == 1);
- mt_fail(el_log_allowed(&g_el, EL_WARN) == 0);
- mt_fail(el_log_allowed(&g_el, EL_NOTICE) == 0);
- mt_fail(el_log_allowed(&g_el, EL_INFO) == 0);
- mt_fail(el_log_allowed(&g_el, EL_DBG) == 0);
+ g_el.level = EL_ERROR;
+ g_el.outputs = EL_OUT_STDERR;
+
+ mt_fail(el_log_allowed(&g_el, EL_FATAL) == 1);
+ mt_fail(el_log_allowed(&g_el, EL_ALERT) == 1);
+ mt_fail(el_log_allowed(&g_el, EL_CRIT) == 1);
+ mt_fail(el_log_allowed(&g_el, EL_ERROR) == 1);
+ mt_fail(el_log_allowed(&g_el, EL_WARN) == 0);
+ mt_fail(el_log_allowed(&g_el, EL_NOTICE) == 0);
+ mt_fail(el_log_allowed(&g_el, EL_INFO) == 0);
+ mt_fail(el_log_allowed(&g_el, EL_DBG) == 0);
}
@@ -311,17 +290,17 @@ static void options_log_allowed(void)
static void options_opt_print_level(void)
{
- mt_fail(el_option(EL_PRINT_LEVEL, 0) == 0);
- mt_fail(g_el.print_log_level == 0);
- mt_fail(el_option(EL_PRINT_LEVEL, 1) == 0);
- mt_fail(g_el.print_log_level == 1);
-
- errno = 0;
- mt_fail(el_option(EL_PRINT_LEVEL, 2) == -1);
- mt_fail(errno == EINVAL);
- errno = 0;
- mt_fail(el_option(EL_PRINT_LEVEL, 3) == -1);
- mt_fail(errno == EINVAL);
+ mt_fail(el_option(EL_PRINT_LEVEL, 0) == 0);
+ mt_fail(g_el.print_log_level == 0);
+ mt_fail(el_option(EL_PRINT_LEVEL, 1) == 0);
+ mt_fail(g_el.print_log_level == 1);
+
+ errno = 0;
+ mt_fail(el_option(EL_PRINT_LEVEL, 2) == -1);
+ mt_fail(errno == EINVAL);
+ errno = 0;
+ mt_fail(el_option(EL_PRINT_LEVEL, 3) == -1);
+ mt_fail(errno == EINVAL);
}
@@ -332,18 +311,18 @@ static void options_opt_print_level(void)
static void options_opt_colors(void)
{
#if ENABLE_COLORS
- mt_fok(el_option(EL_COLORS, 0));
- mt_fail(g_el.colors == 0);
- mt_fok(el_option(EL_COLORS, 1));
- mt_fail(g_el.colors == 1);
+ mt_fok(el_option(EL_COLORS, 0));
+ mt_fail(g_el.colors == 0);
+ mt_fok(el_option(EL_COLORS, 1));
+ mt_fail(g_el.colors == 1);
- mt_ferr(el_option(EL_COLORS, 2), EINVAL);
- mt_ferr(el_option(EL_COLORS, 3), EINVAL);
+ mt_ferr(el_option(EL_COLORS, 2), EINVAL);
+ mt_ferr(el_option(EL_COLORS, 3), EINVAL);
#else
- mt_ferr(el_option(EL_COLORS, 0), ENOSYS);
- mt_ferr(el_option(EL_COLORS, 1), ENOSYS);
- mt_ferr(el_option(EL_COLORS, 2), ENOSYS);
- mt_ferr(el_option(EL_COLORS, 3), ENOSYS);
+ mt_ferr(el_option(EL_COLORS, 0), ENOSYS);
+ mt_ferr(el_option(EL_COLORS, 1), ENOSYS);
+ mt_ferr(el_option(EL_COLORS, 2), ENOSYS);
+ mt_ferr(el_option(EL_COLORS, 3), ENOSYS);
#endif
}
@@ -354,23 +333,23 @@ static void options_opt_colors(void)
static void options_opt_timestamp(void)
{
- int i;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int i;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- for (i = EL_TS_OFF; i != EL_TS_ERROR; ++i)
- {
+ for (i = EL_TS_OFF; i != EL_TS_ERROR; ++i)
+ {
#if ENABLE_TIMESTAMP
- mt_fok(el_option(EL_TS, i));
- mt_fail(g_el.timestamp == i);
+ mt_fok(el_option(EL_TS, i));
+ mt_fail(g_el.timestamp == i);
#else
- mt_ferr(el_option(EL_TS, i), ENOSYS);
+ mt_ferr(el_option(EL_TS, i), ENOSYS);
#endif
- }
+ }
#if ENABLE_TIMESTAMP
- mt_ferr(el_option(EL_TS, i), EINVAL);
+ mt_ferr(el_option(EL_TS, i), EINVAL);
#else
- mt_ferr(el_option(EL_TS, i), ENOSYS);
+ mt_ferr(el_option(EL_TS, i), ENOSYS);
#endif
}
@@ -382,48 +361,48 @@ static void options_opt_timestamp(void)
static void options_opt_timestamp_timer(void)
{
- int i;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int i;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- for (i = EL_TS_TM_CLOCK; i != EL_TS_TM_ERROR; ++i)
- {
+ for (i = EL_TS_TM_CLOCK; i != EL_TS_TM_ERROR; ++i)
+ {
#if ENABLE_TIMESTAMP
# ifndef ENABLE_REALTIME
- if (i == EL_TS_TM_REALTIME)
- {
- mt_ferr(el_option(EL_TS_TM, i), ENODEV);
- continue;
- }
+ if (i == EL_TS_TM_REALTIME)
+ {
+ mt_ferr(el_option(EL_TS_TM, i), ENODEV);
+ continue;
+ }
# endif
# ifndef ENABLE_MONOTONIC
- if (i == EL_TS_TM_MONOTONIC)
- {
- mt_ferr(el_option(EL_TS_TM, i), ENODEV);
- continue;
- }
+ if (i == EL_TS_TM_MONOTONIC)
+ {
+ mt_ferr(el_option(EL_TS_TM, i), ENODEV);
+ continue;
+ }
# endif
# if ENABLE_CLOCK == 0
- if (i == EL_TS_TM_CLOCK)
- {
- mt_ferr(el_option(EL_TS_TM, i), ENODEV);
- continue;
- }
+ if (i == EL_TS_TM_CLOCK)
+ {
+ mt_ferr(el_option(EL_TS_TM, i), ENODEV);
+ continue;
+ }
# endif
- mt_fok(el_option(EL_TS_TM, i));
- mt_fail(g_el.timestamp_timer == i);
+ mt_fok(el_option(EL_TS_TM, i));
+ mt_fail(g_el.timestamp_timer == i);
#else
- mt_ferr(el_option(EL_TS, i), ENOSYS);
+ mt_ferr(el_option(EL_TS, i), ENOSYS);
#endif
- }
+ }
#if ENABLE_TIMESTAMP
- mt_ferr(el_option(EL_TS_TM, i), EINVAL);
+ mt_ferr(el_option(EL_TS_TM, i), EINVAL);
#else
- mt_ferr(el_option(EL_TS_TM, i), ENOSYS);
+ mt_ferr(el_option(EL_TS_TM, i), ENOSYS);
#endif
}
@@ -434,24 +413,24 @@ static void options_opt_timestamp_timer(void)
static void options_opt_timestamp_fraction(void)
{
- int i;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int i;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- for (i = EL_TS_FRACT_OFF; i != EL_TS_FRACT_ERROR; ++i)
- {
+ for (i = EL_TS_FRACT_OFF; i != EL_TS_FRACT_ERROR; ++i)
+ {
#if ENABLE_FRACTIONS && ENABLE_TIMESTAMP
- mt_fok(el_option(EL_TS_FRACT, i));
- mt_fail(g_el.timestamp_fractions == i);
+ mt_fok(el_option(EL_TS_FRACT, i));
+ mt_fail(g_el.timestamp_fractions == i);
#else
- mt_ferr(el_option(EL_TS_FRACT, i), ENOSYS);
+ mt_ferr(el_option(EL_TS_FRACT, i), ENOSYS);
#endif
- }
+ }
#if ENABLE_FRACTIONS && ENABLE_TIMESTAMP
- mt_ferr(el_option(EL_TS_FRACT, i), EINVAL);
+ mt_ferr(el_option(EL_TS_FRACT, i), EINVAL);
#else
- mt_ferr(el_option(EL_TS_FRACT, i), ENOSYS);
+ mt_ferr(el_option(EL_TS_FRACT, i), ENOSYS);
#endif
}
@@ -461,17 +440,17 @@ static void options_opt_timestamp_fraction(void)
static void options_ooption_test(void)
{
- struct el opts;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ struct el opts;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- el_oinit(&opts);
+ el_oinit(&opts);
#if ENABLE_TIMESTAMP
- el_ooption(&opts, EL_TS_TM, EL_TS_TM_TIME);
- mt_fail(opts.timestamp_timer == EL_TS_TM_TIME);
+ el_ooption(&opts, EL_TS_TM, EL_TS_TM_TIME);
+ mt_fail(opts.timestamp_timer == EL_TS_TM_TIME);
#else
- mt_ferr(el_ooption(&opts, EL_TS_TM, EL_TS_TM_TIME), ENOSYS);
+ mt_ferr(el_ooption(&opts, EL_TS_TM, EL_TS_TM_TIME), ENOSYS);
#endif
}
@@ -483,13 +462,13 @@ static void options_ooption_test(void)
static void options_prefix(void)
{
#if ENABLE_PREFIX
- mt_fok(el_option(EL_PREFIX, "prefix"));
- mt_fok(strcmp("prefix", g_el.prefix));
- mt_fok(el_option(EL_PREFIX, NULL));
- mt_fail(g_el.prefix == NULL);
+ mt_fok(el_option(EL_PREFIX, "prefix"));
+ mt_fok(strcmp("prefix", g_el.prefix));
+ mt_fok(el_option(EL_PREFIX, NULL));
+ mt_fail(g_el.prefix == NULL);
#else
- mt_ferr(el_option(EL_PREFIX, "prefix"), ENOSYS);
- mt_ferr(el_option(EL_PREFIX, NULL), ENOSYS);
+ mt_ferr(el_option(EL_PREFIX, "prefix"), ENOSYS);
+ mt_ferr(el_option(EL_PREFIX, NULL), ENOSYS);
#endif
}
@@ -501,7 +480,7 @@ static void options_prefix(void)
static void options_einval(void)
{
- mt_ferr(el_option(10000, 5), EINVAL);
+ mt_ferr(el_option(10000, 5), EINVAL);
}
@@ -511,59 +490,57 @@ static void options_einval(void)
static void options_global_el_after_el_cleanup(void)
{
- struct el default_el; /* expected default el */
- struct el el; /* custom el to init */
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- memset(&default_el, 0, sizeof(default_el));
- default_el.outputs = EL_OUT_STDERR;
- default_el.level = EL_INFO;
- default_el.level_current_msg = EL_DBG;
- default_el.colors = 0;
- default_el.timestamp = EL_TS_OFF;
- default_el.timestamp_timer = EL_TS_TM_TIME;
- default_el.timestamp_fractions = EL_TS_FRACT_OFF;
- default_el.print_log_level = 1;
- default_el.print_newline = 1;
+ struct el default_el; /* expected default el */
+ struct el el; /* custom el to init */
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ memset(&default_el, 0, sizeof(default_el));
+ default_el.outputs = EL_OUT_STDERR;
+ default_el.level = EL_INFO;
+ default_el.level_current_msg = EL_DBG;
+ default_el.colors = 0;
+ default_el.timestamp = EL_TS_OFF;
+ default_el.timestamp_timer = EL_TS_TM_TIME;
+ default_el.timestamp_fractions = EL_TS_FRACT_OFF;
+ default_el.print_log_level = 1;
+ default_el.print_newline = 1;
#if ENABLE_OUT_FILE
- default_el.fsync_level = EL_FATAL;
- default_el.funcinfo = 0;
- default_el.finfo = 0;
- default_el.frotate_number = 0;
- default_el.fcurrent_rotate = 0;
- default_el.frotate_size = 0;
- default_el.frotate_symlink = 1;
- default_el.fpos = 0;
- default_el.file = NULL;
- default_el.fsync_every = 32768;
- default_el.fname = NULL;
+ default_el.fsync_level = EL_FATAL;
+ default_el.funcinfo = 0;
+ default_el.finfo = 0;
+ default_el.frotate_number = 0;
+ default_el.fcurrent_rotate = 0;
+ default_el.frotate_size = 0;
+ default_el.frotate_symlink = 1;
+ default_el.fpos = 0;
+ default_el.file = NULL;
+ default_el.fsync_every = 32768;
+ default_el.fname = NULL;
#endif
#if ENABLE_OUT_TTY
- default_el.serial_fd = -1;
+ default_el.serial_fd = -1;
#endif
#if ENABLE_OUT_CUSTOM
- default_el.custom_put = NULL;
+ default_el.custom_put = NULL;
#endif
- el_init();
- el_oinit(&el);
- mt_fail(memcmp(&g_el, &default_el, sizeof(default_el)) == 0);
- mt_fail(g_el.outputs == EL_OUT_STDERR);
- mt_fail(el.outputs == EL_OUT_STDERR);
+ el_init();
+ el_oinit(&el);
+ mt_fail(memcmp(&g_el, &default_el, sizeof(default_el)) == 0);
+ mt_fail(g_el.outputs == EL_OUT_STDERR);
+ mt_fail(el.outputs == EL_OUT_STDERR);
- el_ocleanup(&el);
+ el_ocleanup(&el);
- /* global el should not be altered when el_ocleanup is called
- */
-
- mt_fail(memcmp(&g_el, &default_el, sizeof(default_el)) == 0);
- mt_fail(el.outputs == 0);
+ /* global el should not be altered when el_ocleanup is called */
+ mt_fail(memcmp(&g_el, &default_el, sizeof(default_el)) == 0);
+ mt_fail(el.outputs == 0);
}
@@ -574,18 +551,18 @@ static void options_global_el_after_el_cleanup(void)
static void options_set_funcinfo(void)
{
#if ENABLE_FUNCINFO && (__STDC_VERSION__ >= 199901L)
- mt_fok(el_option(EL_FUNCINFO, 0));
- mt_fail(g_el.funcinfo == 0);
- mt_fok(el_option(EL_FUNCINFO, 1));
- mt_fail(g_el.funcinfo == 1);
+ mt_fok(el_option(EL_FUNCINFO, 0));
+ mt_fail(g_el.funcinfo == 0);
+ mt_fok(el_option(EL_FUNCINFO, 1));
+ mt_fail(g_el.funcinfo == 1);
- mt_ferr(el_option(EL_FUNCINFO, 2), EINVAL);
- mt_ferr(el_option(EL_FUNCINFO, 3), EINVAL);
+ mt_ferr(el_option(EL_FUNCINFO, 2), EINVAL);
+ mt_ferr(el_option(EL_FUNCINFO, 3), EINVAL);
#else
- mt_ferr(el_option(EL_FUNCINFO, 0), ENOSYS);
- mt_ferr(el_option(EL_FUNCINFO, 1), ENOSYS);
- mt_ferr(el_option(EL_FUNCINFO, 2), ENOSYS);
- mt_ferr(el_option(EL_FUNCINFO, 3), ENOSYS);
+ mt_ferr(el_option(EL_FUNCINFO, 0), ENOSYS);
+ mt_ferr(el_option(EL_FUNCINFO, 1), ENOSYS);
+ mt_ferr(el_option(EL_FUNCINFO, 2), ENOSYS);
+ mt_ferr(el_option(EL_FUNCINFO, 3), ENOSYS);
#endif
}
@@ -596,11 +573,11 @@ static void options_set_funcinfo(void)
static void options_get_global_el(void)
{
- const struct el *opts;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ const struct el *opts;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- opts = el_get_el();
- mt_fail(opts == &g_el);
+ opts = el_get_el();
+ mt_fail(opts == &g_el);
}
@@ -616,25 +593,25 @@ static void options_get_global_el(void)
void el_options_test_group(void)
{
- mt_run(options_init);
- mt_run(options_init_einval);
-
- mt_prepare_test = &test_prepare;
- mt_cleanup_test = &test_cleanup;
-
- mt_run(options_level_set);
- mt_run(options_fsync_level_set);
- mt_run(options_output);
- mt_run(options_log_allowed);
- mt_run(options_opt_print_level);
- mt_run(options_opt_colors);
- mt_run(options_opt_timestamp);
- mt_run(options_opt_timestamp_timer);
- mt_run(options_opt_timestamp_fraction);
- mt_run(options_ooption_test);
- mt_run(options_einval);
- mt_run(options_prefix);
- mt_run(options_global_el_after_el_cleanup);
- mt_run(options_set_funcinfo);
- mt_run(options_get_global_el);
+ mt_run(options_init);
+ mt_run(options_init_einval);
+
+ mt_prepare_test = &test_prepare;
+ mt_cleanup_test = &test_cleanup;
+
+ mt_run(options_level_set);
+ mt_run(options_fsync_level_set);
+ mt_run(options_output);
+ mt_run(options_log_allowed);
+ mt_run(options_opt_print_level);
+ mt_run(options_opt_colors);
+ mt_run(options_opt_timestamp);
+ mt_run(options_opt_timestamp_timer);
+ mt_run(options_opt_timestamp_fraction);
+ mt_run(options_ooption_test);
+ mt_run(options_einval);
+ mt_run(options_prefix);
+ mt_run(options_global_el_after_el_cleanup);
+ mt_run(options_set_funcinfo);
+ mt_run(options_get_global_el);
}
diff --git a/tst/test-el-pbinary.c b/tst/test-el-pbinary.c
index b84ad02..69948fb 100644
--- a/tst/test-el-pbinary.c
+++ b/tst/test-el-pbinary.c
@@ -44,9 +44,9 @@
struct log_message
{
- const unsigned char *msg;
- size_t msglen;
- int level;
+ const unsigned char *msg;
+ size_t msglen;
+ int level;
};
@@ -76,19 +76,19 @@ static unsigned char d8[] = { 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00 };
static int print_mix
(
- const char *s,
- size_t slen,
- void *user
+ const char *s,
+ size_t slen,
+ void *user
)
{
- int pos;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int pos;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- pos = *(int *)user;
- memcpy(logbuf + pos, s, slen);
- *(int *)user += slen;
- return 0;
+ pos = *(int *)user;
+ memcpy(logbuf + pos, s, slen);
+ *(int *)user += slen;
+ return 0;
}
@@ -102,275 +102,236 @@ static int print_mix
static int pbinary_check(void)
{
- struct log_message expected;
- struct stat st;
- unsigned char *msg;
- unsigned char *msgsave;
- int fd;
- unsigned char tmp[1024];
- int i;
- int slevel;
- size_t msglen;
- size_t len;
- unsigned char flags;
+ struct log_message expected;
+ struct stat st;
+ unsigned char *msg;
+ unsigned char *msgsave;
+ int fd;
+ unsigned char tmp[1024];
+ int i;
+ int slevel;
+ size_t msglen;
+ size_t len;
+ unsigned char flags;
#ifdef LLONG_MAX
- unsigned long long val;
+ unsigned long long val;
#else
- unsigned long val;
+ unsigned long val;
#endif
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- if (store_to_file)
- {
- stat(logpath, &st);
- fd = open(logpath, O_RDONLY);
- msg = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
- msgsave = msg;
- }
- else
- {
- msg = (unsigned char *)logbuf;
- }
-
- while (rb_read(expected_logs, &expected, 1) == 1)
- {
- slevel = expected.level > EL_DBG ? EL_DBG : expected.level;
-
- if (expected.level > g_el.level)
- {
- /* log should not have been printed due to current log
- * level restriction. We just continue here, because if
- * log was indeed printed, next checks will fail
- * anyway.
- */
-
- continue;
- }
-
- /* read flags
- */
-
- flags = *msg++;
-
- /* check if level is added to flags
- */
-
- if ((flags >> 3) != expected.level)
- {
- /* no, its not set correctly
- */
-
- fprintf(stderr, "wrong level, exp: %d, got: %d\n",
- expected.level, flags >> 3);
- goto error;
- }
-
- /* check printing timestamp
- */
-
- if (g_el.timestamp != EL_TS_OFF)
- {
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ if (store_to_file)
+ {
+ stat(logpath, &st);
+ fd = open(logpath, O_RDONLY);
+ msg = mmap(NULL, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0);
+ msgsave = msg;
+ }
+ else
+ {
+ msg = (unsigned char *)logbuf;
+ }
+
+ while (rb_read(expected_logs, &expected, 1) == 1)
+ {
+ slevel = expected.level > EL_DBG ? EL_DBG : expected.level;
+
+ /* log should not have been printed due to current log
+ * level restriction. We just continue here, because if
+ * log was indeed printed, next checks will fail
+ * anyway. */
+ if (expected.level > g_el.level) continue;
+
+ /* read flags */
+ flags = *msg++;
+
+ /* check if level is added to flags */
+ if ((flags >> 3) != expected.level)
+ {
+ /* no, its not set correctly */
+ fprintf(stderr, "wrong level, exp: %d, got: %d\n",
+ expected.level, flags >> 3);
+ goto error;
+ }
+
+ /* check printing timestamp */
+ if (g_el.timestamp != EL_TS_OFF)
+ {
# ifdef LLONG_MAX
- unsigned long long tmp;
+ unsigned long long tmp;
# else
- unsigned long tmp;
+ unsigned long tmp;
# endif
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- len = el_decode_number(msg, &tmp);
- msg += len;
-
- /* we don't know exact time embedlog put into log file,
- * so we have to trust the size
- */
-
- if ((flags & 0x01) != 0x01)
- {
- /* expected timestamp flag to be set
- */
-
- fprintf(stderr, "flag timestamp not set: %d\n", flags);
- goto error;
- }
-
- /* fraction of seconds checks makes sense only when ts
- * is set
- */
-
- if (g_el.timestamp_fractions == EL_TS_FRACT_OFF)
- {
- if (flags & 0x06)
- {
- /* fraction flags set, and should not be
- */
-
- fprintf(stderr, "fraction flag set (should not be): %d\n",
- flags);
- goto error;
- }
- }
- else
- {
- len = el_decode_number(msg, &tmp);
- msg += len;
- }
-
- if (g_el.timestamp_fractions == EL_TS_FRACT_MS)
- {
- if (tmp > 999)
- {
- fprintf(stderr, "msec set, but value > 999: %ld\n",
- (long)tmp);
- goto error;
- }
-
- if (((flags & 0x06) >> 1) != 1)
- {
- fprintf(stderr, "msec flag not set: %d\n", flags);
- goto error;
- }
- }
-
- if (g_el.timestamp_fractions == EL_TS_FRACT_US)
- {
- if (tmp > 999999l)
- {
- fprintf(stderr, "usec set, but value > 999999: %ld\n",
- (long)tmp);
- goto error;
- }
-
- if (((flags & 0x06) >> 1) != 2)
- {
- fprintf(stderr, "usec flag not set: %d\n", flags);
- goto error;
- }
- }
-
- if (g_el.timestamp_fractions == EL_TS_FRACT_NS)
- {
- if (tmp > 999999999l)
- {
- fprintf(stderr, "nsec set, but value > 999999999: %ld\n",
- (long)tmp);
- goto error;
- }
-
- if (((flags & 0x06) >> 1) != 3)
- {
- fprintf(stderr, "nsec flag not set: %d\n", flags);
- goto error;
- }
- }
-
- }
- else
- {
- if (flags & 0x01)
- {
- /* we didn't expect timestamp flag to be set
- */
-
- fprintf(stderr, "timestamp flag set (shouldn't be): %d\n",
- flags);
- goto error;
- }
-
- if (flags & 0x06)
- {
- /* when timestamp is not set, we expect fraction of
- * seconds to not be set as well
- */
-
- fprintf(stderr, "timestamp flag not set but fraction is: %d\n",
- flags);
- goto error;
- }
- }
-
- /* now we can check printed data
- */
-
- if (truncate_test)
- {
- int i;
- int written;
- char expect[EL_BUF_MAX];
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- for (i = 0; i != sizeof(expect); ++i)
- {
- expect[i] = (unsigned char)i;
- }
-
- written = msg - msgsave;
-
- len = el_decode_number(msg, &val);
-
- if (val != EL_BUF_MAX - written - len)
- {
- /* truncated message has wrong length
- */
-
- fprintf(stderr, "truncated message wrong length "
- "exp: %lu, got %lu\n", EL_BUF_MAX - written - len,
- (long)val);
- return -1;
- }
-
- msg += len;
-
- if (memcmp(msg, expect, val) != 0)
- {
- /* data is incorrect
- */
-
- fprintf(stderr, "data is incorrect\n");
- return -1;
- }
-
- /* point to next message
- */
-
- msg += val;
- }
- else
- {
- len = el_decode_number(msg, &val);
- msg += len;
-
- if (memcmp(msg, expected.msg, val) != 0)
- {
- /* data different than expected
- */
-
- fprintf(stderr, "data different than expected\n");
- goto error;
- }
-
- /* finally set msg to point to next message
- */
-
- msg += val;
- }
- }
-
- if (store_to_file)
- {
- munmap(msgsave, st.st_size);
- close(fd);
- }
- return 0;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+ len = el_decode_number(msg, &tmp);
+ msg += len;
+
+ /* we don't know exact time embedlog put into log file,
+ * so we have to trust the size */
+ if ((flags & 0x01) != 0x01)
+ {
+ /* expected timestamp flag to be set */
+ fprintf(stderr, "flag timestamp not set: %d\n", flags);
+ goto error;
+ }
+
+ /* fraction of seconds checks makes sense only when ts
+ * is set */
+ if (g_el.timestamp_fractions == EL_TS_FRACT_OFF)
+ {
+ if (flags & 0x06)
+ {
+ /* fraction flags set, and should not be */
+ fprintf(stderr, "fraction flag set (should not be): %d\n",
+ flags);
+ goto error;
+ }
+ }
+ else
+ {
+ len = el_decode_number(msg, &tmp);
+ msg += len;
+ }
+
+ if (g_el.timestamp_fractions == EL_TS_FRACT_MS)
+ {
+ if (tmp > 999)
+ {
+ fprintf(stderr, "msec set, but value > 999: %ld\n",
+ (long)tmp);
+ goto error;
+ }
+
+ if (((flags & 0x06) >> 1) != 1)
+ {
+ fprintf(stderr, "msec flag not set: %d\n", flags);
+ goto error;
+ }
+ }
+
+ if (g_el.timestamp_fractions == EL_TS_FRACT_US)
+ {
+ if (tmp > 999999l)
+ {
+ fprintf(stderr, "usec set, but value > 999999: %ld\n",
+ (long)tmp);
+ goto error;
+ }
+
+ if (((flags & 0x06) >> 1) != 2)
+ {
+ fprintf(stderr, "usec flag not set: %d\n", flags);
+ goto error;
+ }
+ }
+
+ if (g_el.timestamp_fractions == EL_TS_FRACT_NS)
+ {
+ if (tmp > 999999999l)
+ {
+ fprintf(stderr, "nsec set, but value > 999999999: %ld\n",
+ (long)tmp);
+ goto error;
+ }
+
+ if (((flags & 0x06) >> 1) != 3)
+ {
+ fprintf(stderr, "nsec flag not set: %d\n", flags);
+ goto error;
+ }
+ }
+
+ }
+ else
+ {
+ if (flags & 0x01)
+ {
+ /* we didn't expect timestamp flag to be set */
+ fprintf(stderr, "timestamp flag set (shouldn't be): %d\n",
+ flags);
+ goto error;
+ }
+
+ if (flags & 0x06)
+ {
+ /* when timestamp is not set, we expect fraction of
+ * seconds to not be set as well */
+ fprintf(stderr, "timestamp flag not set but fraction is: %d\n",
+ flags);
+ goto error;
+ }
+ }
+
+ /* now we can check printed data */
+ if (truncate_test)
+ {
+ int i;
+ int written;
+ char expect[EL_BUF_MAX];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+ for (i = 0; i != sizeof(expect); ++i)
+ expect[i] = (unsigned char)i;
+
+ written = msg - msgsave;
+
+ len = el_decode_number(msg, &val);
+
+ if (val != EL_BUF_MAX - written - len)
+ {
+ /* truncated message has wrong length */
+ fprintf(stderr, "truncated message wrong length "
+ "exp: %lu, got %lu\n", EL_BUF_MAX - written - len,
+ (long)val);
+ return -1;
+ }
+
+ msg += len;
+
+ if (memcmp(msg, expect, val) != 0)
+ {
+ /* data is incorrect */
+ fprintf(stderr, "data is incorrect\n");
+ return -1;
+ }
+
+ /* point to next message */
+ msg += val;
+ }
+ else
+ {
+ len = el_decode_number(msg, &val);
+ msg += len;
+
+ if (memcmp(msg, expected.msg, val) != 0)
+ {
+ /* data different than expected */
+ fprintf(stderr, "data different than expected\n");
+ goto error;
+ }
+
+ /* finally set msg to point to next message */
+ msg += val;
+ }
+ }
+
+ if (store_to_file)
+ {
+ munmap(msgsave, st.st_size);
+ close(fd);
+ }
+ return 0;
error:
- if (store_to_file)
- {
- munmap(msgsave, st.st_size);
- close(fd);
- }
- return 1;
+ if (store_to_file)
+ {
+ munmap(msgsave, st.st_size);
+ close(fd);
+ }
+ return 1;
}
@@ -382,20 +343,20 @@ error:
static void add_log
(
- enum el_level level,
- const void *mem,
- size_t mlen
+ enum el_level level,
+ const void *mem,
+ size_t mlen
)
{
- struct log_message expected;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ struct log_message expected;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- expected.level = level;
- expected.msg = mem;
- expected.msglen = mlen;
- rb_write(expected_logs, &expected, 1);
- el_pbinary(level, mem, mlen);
+ expected.level = level;
+ expected.msg = mem;
+ expected.msglen = mlen;
+ rb_write(expected_logs, &expected, 1);
+ el_pbinary(level, mem, mlen);
}
@@ -407,20 +368,20 @@ static void add_log
static void test_prepare(void)
{
- el_init();
- unlink(logpath);
- el_option(EL_PRINT_LEVEL, 0);
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_PREFIX, NULL);
- el_option(EL_COLORS, 0);
- el_option(EL_TS, EL_TS_OFF);
- el_option(EL_TS_FRACT, EL_TS_FRACT_OFF);
- el_option(EL_PRINT_LEVEL, 0);
- el_option(EL_FROTATE_NUMBER, 0);
- el_option(EL_FSYNC_EVERY, 1024);
- el_option(EL_FPATH, logpath);
- truncate_test = 0;
- expected_logs = rb_new(1024, sizeof(struct log_message), 0);
+ el_init();
+ unlink(logpath);
+ el_option(EL_PRINT_LEVEL, 0);
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_PREFIX, NULL);
+ el_option(EL_COLORS, 0);
+ el_option(EL_TS, EL_TS_OFF);
+ el_option(EL_TS_FRACT, EL_TS_FRACT_OFF);
+ el_option(EL_PRINT_LEVEL, 0);
+ el_option(EL_FROTATE_NUMBER, 0);
+ el_option(EL_FSYNC_EVERY, 1024);
+ el_option(EL_FPATH, logpath);
+ truncate_test = 0;
+ expected_logs = rb_new(1024, sizeof(struct log_message), 0);
}
@@ -431,9 +392,9 @@ static void test_prepare(void)
static void test_cleanup(void)
{
- el_cleanup();
- rb_destroy(expected_logs);
- unlink(logpath);
+ el_cleanup();
+ rb_destroy(expected_logs);
+ unlink(logpath);
}
@@ -449,8 +410,8 @@ static void test_cleanup(void)
static void pbinary_simple_message(void)
{
- add_log(EL_FATAL, d5, 5);
- mt_fok(pbinary_check());
+ add_log(EL_FATAL, d5, 5);
+ mt_fok(pbinary_check());
}
@@ -460,11 +421,11 @@ static void pbinary_simple_message(void)
static void pbinary_simple_multiple_message(void)
{
- add_log(EL_FATAL, d1, 1);
- add_log(EL_FATAL, d2, 2);
- add_log(EL_FATAL, d5, 5);
- add_log(EL_FATAL, d8, 8);
- mt_fok(pbinary_check());
+ add_log(EL_FATAL, d1, 1);
+ add_log(EL_FATAL, d2, 2);
+ add_log(EL_FATAL, d5, 5);
+ add_log(EL_FATAL, d8, 8);
+ mt_fok(pbinary_check());
}
@@ -474,12 +435,12 @@ static void pbinary_simple_multiple_message(void)
static void pbinary_ts_without_fractions(void)
{
- el_option(EL_TS_FRACT, EL_TS_FRACT_OFF);
- add_log(EL_FATAL, d1, 1);
- add_log(EL_FATAL, d2, 2);
- add_log(EL_FATAL, d5, 5);
- add_log(EL_FATAL, d8, 8);
- mt_fok(pbinary_check());
+ el_option(EL_TS_FRACT, EL_TS_FRACT_OFF);
+ add_log(EL_FATAL, d1, 1);
+ add_log(EL_FATAL, d2, 2);
+ add_log(EL_FATAL, d5, 5);
+ add_log(EL_FATAL, d8, 8);
+ mt_fok(pbinary_check());
}
@@ -489,12 +450,12 @@ static void pbinary_ts_without_fractions(void)
static void pbinary_ts_fractions_ms(void)
{
- el_option(EL_TS_FRACT, EL_TS_FRACT_MS);
- add_log(EL_FATAL, d1, 1);
- add_log(EL_FATAL, d2, 2);
- add_log(EL_FATAL, d5, 5);
- add_log(EL_FATAL, d8, 8);
- mt_fok(pbinary_check());
+ el_option(EL_TS_FRACT, EL_TS_FRACT_MS);
+ add_log(EL_FATAL, d1, 1);
+ add_log(EL_FATAL, d2, 2);
+ add_log(EL_FATAL, d5, 5);
+ add_log(EL_FATAL, d8, 8);
+ mt_fok(pbinary_check());
}
@@ -504,12 +465,12 @@ static void pbinary_ts_fractions_ms(void)
static void pbinary_ts_fractions_us(void)
{
- el_option(EL_TS_FRACT, EL_TS_FRACT_US);
- add_log(EL_FATAL, d1, 1);
- add_log(EL_FATAL, d2, 2);
- add_log(EL_FATAL, d5, 5);
- add_log(EL_FATAL, d8, 8);
- mt_fok(pbinary_check());
+ el_option(EL_TS_FRACT, EL_TS_FRACT_US);
+ add_log(EL_FATAL, d1, 1);
+ add_log(EL_FATAL, d2, 2);
+ add_log(EL_FATAL, d5, 5);
+ add_log(EL_FATAL, d8, 8);
+ mt_fok(pbinary_check());
}
@@ -519,12 +480,12 @@ static void pbinary_ts_fractions_us(void)
static void pbinary_ts_fractions_ns(void)
{
- el_option(EL_TS_FRACT, EL_TS_FRACT_NS);
- add_log(EL_FATAL, d1, 1);
- add_log(EL_FATAL, d2, 2);
- add_log(EL_FATAL, d5, 5);
- add_log(EL_FATAL, d8, 8);
- mt_fok(pbinary_check());
+ el_option(EL_TS_FRACT, EL_TS_FRACT_NS);
+ add_log(EL_FATAL, d1, 1);
+ add_log(EL_FATAL, d2, 2);
+ add_log(EL_FATAL, d5, 5);
+ add_log(EL_FATAL, d8, 8);
+ mt_fok(pbinary_check());
}
@@ -534,11 +495,11 @@ static void pbinary_ts_fractions_ns(void)
static void pbinary_timestamp_short(void)
{
- el_option(EL_TS, EL_TS_SHORT);
- add_log(EL_FATAL, d2, 2);
- add_log(EL_FATAL, d5, 5);
- add_log(EL_FATAL, d8, 8);
- mt_fok(pbinary_check());
+ el_option(EL_TS, EL_TS_SHORT);
+ add_log(EL_FATAL, d2, 2);
+ add_log(EL_FATAL, d5, 5);
+ add_log(EL_FATAL, d8, 8);
+ mt_fok(pbinary_check());
}
@@ -548,11 +509,11 @@ static void pbinary_timestamp_short(void)
static void pbinary_timestamp_long(void)
{
- el_option(EL_TS, EL_TS_LONG);
- add_log(EL_FATAL, d2, 2);
- add_log(EL_FATAL, d5, 5);
- add_log(EL_FATAL, d8, 8);
- mt_fok(pbinary_check());
+ el_option(EL_TS, EL_TS_LONG);
+ add_log(EL_FATAL, d2, 2);
+ add_log(EL_FATAL, d5, 5);
+ add_log(EL_FATAL, d8, 8);
+ mt_fok(pbinary_check());
}
@@ -562,12 +523,12 @@ static void pbinary_timestamp_long(void)
static void pbinary_timestamp_short_no_fractions(void)
{
- el_option(EL_TS_FRACT, EL_TS_FRACT_OFF);
- el_option(EL_TS, EL_TS_SHORT);
- add_log(EL_FATAL, d2, 2);
- add_log(EL_FATAL, d5, 5);
- add_log(EL_FATAL, d8, 8);
- mt_fok(pbinary_check());
+ el_option(EL_TS_FRACT, EL_TS_FRACT_OFF);
+ el_option(EL_TS, EL_TS_SHORT);
+ add_log(EL_FATAL, d2, 2);
+ add_log(EL_FATAL, d5, 5);
+ add_log(EL_FATAL, d8, 8);
+ mt_fok(pbinary_check());
}
@@ -577,12 +538,12 @@ static void pbinary_timestamp_short_no_fractions(void)
static void pbinary_timestamp_long_no_fractions(void)
{
- el_option(EL_TS_FRACT, EL_TS_FRACT_OFF);
- el_option(EL_TS, EL_TS_LONG);
- add_log(EL_FATAL, d2, 2);
- add_log(EL_FATAL, d5, 5);
- add_log(EL_FATAL, d8, 8);
- mt_fok(pbinary_check());
+ el_option(EL_TS_FRACT, EL_TS_FRACT_OFF);
+ el_option(EL_TS, EL_TS_LONG);
+ add_log(EL_FATAL, d2, 2);
+ add_log(EL_FATAL, d5, 5);
+ add_log(EL_FATAL, d8, 8);
+ mt_fok(pbinary_check());
}
@@ -592,20 +553,20 @@ static void pbinary_timestamp_long_no_fractions(void)
static void pbinary_different_clocks(void)
{
- int i;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- for (i = EL_TS_TM_CLOCK; i != EL_TS_TM_ERROR; ++i)
- {
- test_prepare();
- el_option(EL_TS_TM, i);
- el_option(EL_TS, EL_TS_LONG);
- add_log(EL_FATAL, d8, 8);
- add_log(EL_FATAL, d8, 8);
- mt_fok(pbinary_check());
- test_cleanup();
- }
+ int i;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ for (i = EL_TS_TM_CLOCK; i != EL_TS_TM_ERROR; ++i)
+ {
+ test_prepare();
+ el_option(EL_TS_TM, i);
+ el_option(EL_TS, EL_TS_LONG);
+ add_log(EL_FATAL, d8, 8);
+ add_log(EL_FATAL, d8, 8);
+ mt_fok(pbinary_check());
+ test_cleanup();
+ }
}
@@ -615,77 +576,77 @@ static void pbinary_different_clocks(void)
static void pbinary_mix_of_everything_check(void)
{
- mt_fok(pbinary_check());
+ mt_fok(pbinary_check());
}
static void pbinary_mix_of_everything(void)
{
- int level;
- int ts;
- int printlevel;
- int finfo;
- int funcinfo;
- int colors;
- int prefix;
- int ts_fract;
- int nl;
- int ts_tm;
- char tname[512];
- int pos;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- expected_logs = rb_new(16, sizeof(struct log_message), 0);
- truncate_test = 0;
-
- for (level = 0; level <= EL_DBG; ++level)
- for (colors = 0; colors <= 1; ++colors)
- for (ts = 0; ts != EL_TS_ERROR; ++ts)
- for (ts_tm = 0; ts_tm <= EL_TS_TM_ERROR; ++ts_tm)
- for (ts_fract = 0; ts_fract != EL_TS_FRACT_ERROR; ++ts_fract)
- for (printlevel = 0; printlevel <= 1; ++printlevel)
- for (nl = 0; nl <= 1; ++nl)
- for (finfo = 0; finfo <= 1; ++finfo)
- for (funcinfo = 0; funcinfo <= 1; ++funcinfo)
- for (prefix = 0; prefix <= 1; ++prefix)
- {
- el_init();
-
- el_option(EL_LEVEL, level);
- el_option(EL_COLORS, colors);
- el_option(EL_TS, ts);
- el_option(EL_TS_TM, ts_tm);
- el_option(EL_TS_FRACT, ts_fract);
- el_option(EL_PRINT_LEVEL, printlevel);
- el_option(EL_PRINT_NL, nl);
- el_option(EL_FINFO, finfo);
- el_option(EL_FUNCINFO, funcinfo);
- el_option(EL_PREFIX, prefix ? "prefix" : NULL);
- el_option(EL_CUSTOM_PUT, print_mix, &pos);
- el_option(EL_OUT, EL_OUT_CUSTOM);
-
- pos = 0;
- add_log(EL_FATAL, d1, 1);
- add_log(EL_ALERT, d1, 1);
- add_log(EL_CRIT, d1, 1);
- add_log(EL_ERROR, d5, 5);
- add_log(EL_WARN, d1, 1);
- add_log(EL_NOTICE, d2, 2);
- add_log(EL_INFO, d1, 1);
- add_log(EL_DBG, d8, 8);
-
- el_cleanup();
-
- sprintf(tname, "pbinary_mix_of_everything: level: %d, colors: %d, "
- "ts: %d, ts_tm: %d, ts_fract: %d, print_level: %d, "
- "nl: %d, finfo: %d, funcinfo: %d, prefix: %d",
- level, colors, ts, ts_tm, ts_fract, printlevel, nl,
- finfo, funcinfo, prefix);
-
- mt_run_named(pbinary_mix_of_everything_check, tname);
- rb_clear(expected_logs, 0);
- }
-
- rb_destroy(expected_logs);
+ int level;
+ int ts;
+ int printlevel;
+ int finfo;
+ int funcinfo;
+ int colors;
+ int prefix;
+ int ts_fract;
+ int nl;
+ int ts_tm;
+ char tname[512];
+ int pos;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+ expected_logs = rb_new(16, sizeof(struct log_message), 0);
+ truncate_test = 0;
+
+ for (level = 0; level <= EL_DBG; ++level)
+ for (colors = 0; colors <= 1; ++colors)
+ for (ts = 0; ts != EL_TS_ERROR; ++ts)
+ for (ts_tm = 0; ts_tm <= EL_TS_TM_ERROR; ++ts_tm)
+ for (ts_fract = 0; ts_fract != EL_TS_FRACT_ERROR; ++ts_fract)
+ for (printlevel = 0; printlevel <= 1; ++printlevel)
+ for (nl = 0; nl <= 1; ++nl)
+ for (finfo = 0; finfo <= 1; ++finfo)
+ for (funcinfo = 0; funcinfo <= 1; ++funcinfo)
+ for (prefix = 0; prefix <= 1; ++prefix)
+ {
+ el_init();
+
+ el_option(EL_LEVEL, level);
+ el_option(EL_COLORS, colors);
+ el_option(EL_TS, ts);
+ el_option(EL_TS_TM, ts_tm);
+ el_option(EL_TS_FRACT, ts_fract);
+ el_option(EL_PRINT_LEVEL, printlevel);
+ el_option(EL_PRINT_NL, nl);
+ el_option(EL_FINFO, finfo);
+ el_option(EL_FUNCINFO, funcinfo);
+ el_option(EL_PREFIX, prefix ? "prefix" : NULL);
+ el_option(EL_CUSTOM_PUT, print_mix, &pos);
+ el_option(EL_OUT, EL_OUT_CUSTOM);
+
+ pos = 0;
+ add_log(EL_FATAL, d1, 1);
+ add_log(EL_ALERT, d1, 1);
+ add_log(EL_CRIT, d1, 1);
+ add_log(EL_ERROR, d5, 5);
+ add_log(EL_WARN, d1, 1);
+ add_log(EL_NOTICE, d2, 2);
+ add_log(EL_INFO, d1, 1);
+ add_log(EL_DBG, d8, 8);
+
+ el_cleanup();
+
+ sprintf(tname, "pbinary_mix_of_everything: level: %d, colors: %d, "
+ "ts: %d, ts_tm: %d, ts_fract: %d, print_level: %d, "
+ "nl: %d, finfo: %d, funcinfo: %d, prefix: %d",
+ level, colors, ts, ts_tm, ts_fract, printlevel, nl,
+ finfo, funcinfo, prefix);
+
+ mt_run_named(pbinary_mix_of_everything_check, tname);
+ rb_clear(expected_logs, 0);
+ }
+
+ rb_destroy(expected_logs);
}
@@ -695,8 +656,8 @@ static void pbinary_mix_of_everything(void)
static void pbinary_with_no_output_available(void)
{
- el_option(EL_OUT, EL_OUT_NONE);
- mt_ferr(el_pbinary(EL_INFO, d2, 2), ENODEV);
+ el_option(EL_OUT, EL_OUT_NONE);
+ mt_ferr(el_pbinary(EL_INFO, d2, 2), ENODEV);
}
@@ -706,7 +667,7 @@ static void pbinary_with_no_output_available(void)
static void pbinary_level_not_high_enough(void)
{
- mt_ferr(el_pbinary(EL_DBG, d8, 8), ERANGE);
+ mt_ferr(el_pbinary(EL_DBG, d8, 8), ERANGE);
}
@@ -716,9 +677,9 @@ static void pbinary_level_not_high_enough(void)
static void pbinary_null(void)
{
- mt_ferr(el_pbinary(EL_ALERT, NULL, 0), EINVAL);
- mt_ferr(el_pbinary(EL_ALERT, NULL, 5), EINVAL);
- mt_ferr(el_pbinary(EL_ALERT, d5, 0), EINVAL);
+ mt_ferr(el_pbinary(EL_ALERT, NULL, 0), EINVAL);
+ mt_ferr(el_pbinary(EL_ALERT, NULL, 5), EINVAL);
+ mt_ferr(el_pbinary(EL_ALERT, d5, 0), EINVAL);
}
@@ -728,25 +689,20 @@ static void pbinary_null(void)
static void pbinary_truncate(void)
{
- int i;
- char msg[EL_BUF_MAX + 3];
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int i;
+ char msg[EL_BUF_MAX + 3];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- for (i = 0; i != sizeof(msg); ++i)
- {
- msg[i] = (unsigned char)i;
- }
+ for (i = 0; i != sizeof(msg); ++i)
+ msg[i] = (unsigned char)i;
- el_option(EL_TS, EL_TS_LONG);
- el_option(EL_TS_FRACT, EL_TS_FRACT_NS);
- add_log(EL_INFO, msg, sizeof(msg));
+ el_option(EL_TS, EL_TS_LONG);
+ el_option(EL_TS_FRACT, EL_TS_FRACT_NS);
+ add_log(EL_INFO, msg, sizeof(msg));
- /*
- * tell checker that this is truncate test
- */
-
- truncate_test = 1;
- mt_fok(pbinary_check());
+ /* tell checker that this is truncate test */
+ truncate_test = 1;
+ mt_fok(pbinary_check());
}
@@ -766,205 +722,183 @@ static void pbinary_truncate(void)
static int sort_pbinary
(
- const void *p1,
- const void *p2
+ const void *p1,
+ const void *p2
)
{
- int m1[2];
- int m2[2];
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- memcpy(m1, (unsigned char *)p1 + 2, sizeof(m1));
- memcpy(m2, (unsigned char *)p2 + 2, sizeof(m2));
-
- if (m1[0] < m2[0])
- {
- return -1;
- }
-
- if (m1[0] > m2[0])
- {
- return 1;
- }
-
- /* thread id equal, let message id decide euqualness
- */
-
- if (m1[1] < m2[1])
- {
- return -1;
- }
-
- if (m1[1] > m2[1])
- {
- return 1;
- }
-
- /* everything is equal, there is bug, upper layer will
- * take care of it
- */
-
- fprintf(stderr, "sort_pbinary, m1 == m2\n");
- return 0;
+ int m1[2];
+ int m2[2];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+ memcpy(m1, (unsigned char *)p1 + 2, sizeof(m1));
+ memcpy(m2, (unsigned char *)p2 + 2, sizeof(m2));
+
+ if (m1[0] < m2[0]) return -1;
+ if (m1[0] > m2[0]) return 1;
+
+ /* thread id equal, let message id decide euqualness */
+ if (m1[1] < m2[1]) return -1;
+ if (m1[1] > m2[1]) return 1;
+
+ /* everything is equal, there is bug, upper layer will
+ * take care of it */
+ fprintf(stderr, "sort_pbinary, m1 == m2\n");
+ return 0;
}
static int print_check(void)
{
- struct stat st;
- unsigned char *msg;
- unsigned char *msgsave;
- int fd;
- unsigned char flags;
- unsigned char len;
- int tid;
- int mid;
- int curr_tid;
- int curr_mid;
- unsigned i;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- stat(logpath, &st);
-
- if (st.st_size != file_size)
- {
- fprintf(stderr, "file size different than expected\n");
- return -1;
- }
-
- fd = open(logpath, O_RDONLY);
- msg = mmap(NULL, st.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
- msgsave = msg;
- curr_tid = 0;
- curr_mid = 0;
-
-
- qsort(msg, total_prints, line_length, sort_pbinary);
-
- for (i = 0; i < file_size; i += line_length)
- {
- flags = msg[i + 0];
- len = msg[i + 1];
- memcpy(&tid, &msg[i + 2], sizeof(tid));
- memcpy(&mid, &msg[i + 6], sizeof(mid));
-
- /* flag should contain only severity level (info == 6)
- */
-
- if (flags != 6 << 3)
- {
- fprintf(stderr, "incorect flags: %d\n", flags);
- munmap(msgsave, st.st_size);
- close(fd);
- return -1;
- }
-
- if (len != 2 * sizeof(int))
- {
- fprintf(stderr, "incorect line length: %d\n", len);
- munmap(msgsave, st.st_size);
- close(fd);
- return -1;
- }
-
- if (tid != curr_tid)
- {
- fprintf(stderr, "msg_tid (%d) != curr_tid (%d)\n",
- tid, curr_tid);
- munmap(msgsave, st.st_size);
- close(fd);
- return -1;
- }
-
- if (mid != curr_mid)
- {
- fprintf(stderr, "msg_mid (%d) != curr_mid (%d)\n",
- mid, curr_mid);
- munmap(msgsave, st.st_size);
- close(fd);
- return -1;
- }
-
- if (++curr_mid == prints_per_thread)
- {
- ++curr_tid;
- curr_mid = 0;
- }
- }
-
- if (curr_tid != number_of_threads || curr_mid != 0)
- {
- fprintf(stderr, "file didn't contain all entries, tid: %d, mid: %d\n",
- curr_tid, curr_mid);
- munmap(msgsave, st.st_size);
- close(fd);
- return -1;
- }
-
- munmap(msgsave, st.st_size);
- close(fd);
- return 0;
+ struct stat st;
+ unsigned char *msg;
+ unsigned char *msgsave;
+ int fd;
+ unsigned char flags;
+ unsigned char len;
+ int tid;
+ int mid;
+ int curr_tid;
+ int curr_mid;
+ unsigned i;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ stat(logpath, &st);
+
+ if (st.st_size != file_size)
+ {
+ fprintf(stderr, "file size different than expected\n");
+ return -1;
+ }
+
+ fd = open(logpath, O_RDONLY);
+ msg = mmap(NULL, st.st_size, PROT_READ | PROT_WRITE, MAP_PRIVATE, fd, 0);
+ msgsave = msg;
+ curr_tid = 0;
+ curr_mid = 0;
+
+
+ qsort(msg, total_prints, line_length, sort_pbinary);
+
+ for (i = 0; i < file_size; i += line_length)
+ {
+ flags = msg[i + 0];
+ len = msg[i + 1];
+ memcpy(&tid, &msg[i + 2], sizeof(tid));
+ memcpy(&mid, &msg[i + 6], sizeof(mid));
+
+ /* flag should contain only severity level (info == 6) */
+ if (flags != 6 << 3)
+ {
+ fprintf(stderr, "incorect flags: %d\n", flags);
+ munmap(msgsave, st.st_size);
+ close(fd);
+ return -1;
+ }
+
+ if (len != 2 * sizeof(int))
+ {
+ fprintf(stderr, "incorect line length: %d\n", len);
+ munmap(msgsave, st.st_size);
+ close(fd);
+ return -1;
+ }
+
+ if (tid != curr_tid)
+ {
+ fprintf(stderr, "msg_tid (%d) != curr_tid (%d)\n",
+ tid, curr_tid);
+ munmap(msgsave, st.st_size);
+ close(fd);
+ return -1;
+ }
+
+ if (mid != curr_mid)
+ {
+ fprintf(stderr, "msg_mid (%d) != curr_mid (%d)\n",
+ mid, curr_mid);
+ munmap(msgsave, st.st_size);
+ close(fd);
+ return -1;
+ }
+
+ if (++curr_mid == prints_per_thread)
+ {
+ ++curr_tid;
+ curr_mid = 0;
+ }
+ }
+
+ if (curr_tid != number_of_threads || curr_mid != 0)
+ {
+ fprintf(stderr, "file didn't contain all entries, tid: %d, mid: %d\n",
+ curr_tid, curr_mid);
+ munmap(msgsave, st.st_size);
+ close(fd);
+ return -1;
+ }
+
+ munmap(msgsave, st.st_size);
+ close(fd);
+ return 0;
}
static void *print_t
(
- void *arg
+ void *arg
)
{
- int msg[2];
- int i;
- int n;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int msg[2];
+ int i;
+ int n;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- n = *(int *)arg;
+ n = *(int *)arg;
- for (i = 0; i != prints_per_thread; ++i)
- {
- msg[0] = n;
- msg[1] = i;
- el_pbinary(EL_INFO, msg, sizeof(msg));
- }
+ for (i = 0; i != prints_per_thread; ++i)
+ {
+ msg[0] = n;
+ msg[1] = i;
+ el_pbinary(EL_INFO, msg, sizeof(msg));
+ }
- return NULL;
+ return NULL;
}
static void prbinary_threaded(void)
{
- pthread_t pt[number_of_threads];
- int i, j, n[number_of_threads];
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- unlink(logpath);
- el_init();
-
- el_option(EL_THREAD_SAFE, 1);
- el_option(EL_PRINT_LEVEL, 0);
- el_option(EL_OUT, EL_OUT_FILE);
- el_option(EL_FROTATE_NUMBER, 0);
- el_option(EL_FPATH, logpath);
- el_option(EL_FSYNC_EVERY, file_size / 4);
-
- for (i = 0; i != number_of_threads; ++i)
- {
- n[i] = i;
- pthread_create(&pt[i], NULL, print_t, &n[i]);
- }
-
- for (i = 0; i != number_of_threads; ++i)
- {
- pthread_join(pt[i], NULL);
- }
-
- /* do it before print_check() so any buffered data is flushed
- * to disk, otherwise files will be incomplete
- */
-
- el_flush();
- mt_fok(print_check());
- el_cleanup();
+ pthread_t pt[number_of_threads];
+ int i, j, n[number_of_threads];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ unlink(logpath);
+ el_init();
+
+ el_option(EL_THREAD_SAFE, 1);
+ el_option(EL_PRINT_LEVEL, 0);
+ el_option(EL_OUT, EL_OUT_FILE);
+ el_option(EL_FROTATE_NUMBER, 0);
+ el_option(EL_FPATH, logpath);
+ el_option(EL_FSYNC_EVERY, file_size / 4);
+
+ for (i = 0; i != number_of_threads; ++i)
+ {
+ n[i] = i;
+ pthread_create(&pt[i], NULL, print_t, &n[i]);
+ }
+
+ for (i = 0; i != number_of_threads; ++i)
+ pthread_join(pt[i], NULL);
+
+ /* do it before print_check() so any buffered data is flushed
+ * to disk, otherwise files will be incomplete
+ */
+
+ el_flush();
+ mt_fok(print_check());
+ el_cleanup();
}
#endif /* ENABLE_PTHREAD */
@@ -985,34 +919,34 @@ static void prbinary_threaded(void)
void el_pbinary_test_group(void)
{
#if ENABLE_BINARY_LOGS
- pbinary_mix_of_everything();
+ pbinary_mix_of_everything();
- store_to_file = 1;
+ store_to_file = 1;
#if ENABLE_PTHREAD
- mt_run(prbinary_threaded);
+ mt_run(prbinary_threaded);
#endif
- mt_run(pbinary_different_clocks);
-
- mt_prepare_test = &test_prepare;
- mt_cleanup_test = &test_cleanup;
-
- mt_run(pbinary_simple_message);
- mt_run(pbinary_simple_multiple_message);
- mt_run(pbinary_ts_without_fractions);
- mt_run(pbinary_timestamp_short);
- mt_run(pbinary_timestamp_long);
- mt_run(pbinary_ts_fractions_ms);
- mt_run(pbinary_ts_fractions_us);
- mt_run(pbinary_ts_fractions_ns);
- mt_run(pbinary_timestamp_short_no_fractions);
- mt_run(pbinary_timestamp_long_no_fractions);
- mt_run(pbinary_with_no_output_available);
- mt_run(pbinary_level_not_high_enough);
- mt_run(pbinary_null);
- mt_run(pbinary_truncate);
+ mt_run(pbinary_different_clocks);
+
+ mt_prepare_test = &test_prepare;
+ mt_cleanup_test = &test_cleanup;
+
+ mt_run(pbinary_simple_message);
+ mt_run(pbinary_simple_multiple_message);
+ mt_run(pbinary_ts_without_fractions);
+ mt_run(pbinary_timestamp_short);
+ mt_run(pbinary_timestamp_long);
+ mt_run(pbinary_ts_fractions_ms);
+ mt_run(pbinary_ts_fractions_us);
+ mt_run(pbinary_ts_fractions_ns);
+ mt_run(pbinary_timestamp_short_no_fractions);
+ mt_run(pbinary_timestamp_long_no_fractions);
+ mt_run(pbinary_with_no_output_available);
+ mt_run(pbinary_level_not_high_enough);
+ mt_run(pbinary_null);
+ mt_run(pbinary_truncate);
#endif
}
diff --git a/tst/test-el-perror.c b/tst/test-el-perror.c
index f4ac3a0..359fc1b 100644
--- a/tst/test-el-perror.c
+++ b/tst/test-el-perror.c
@@ -53,13 +53,13 @@ static char logbuf[1024 * 1024]; /* output simulation */
static int print_to_buffer
(
- const char *s,
- size_t slen,
- void *user
+ const char *s,
+ size_t slen,
+ void *user
)
{
- strcat(user, s);
- return 0;
+ strcat(user, s);
+ return 0;
}
@@ -69,11 +69,11 @@ static int print_to_buffer
static void test_prepare(void)
{
- el_init();
- el_option(EL_CUSTOM_PUTS, print_to_buffer, logbuf);
- el_option(EL_PRINT_LEVEL, 0);
- el_option(EL_OUT, EL_OUT_CUSTOM);
- logbuf[0] = '\0';
+ el_init();
+ el_option(EL_CUSTOM_PUTS, print_to_buffer, logbuf);
+ el_option(EL_PRINT_LEVEL, 0);
+ el_option(EL_OUT, EL_OUT_CUSTOM);
+ logbuf[0] = '\0';
}
@@ -83,7 +83,7 @@ static void test_prepare(void)
static void test_cleanup(void)
{
- el_cleanup();
+ el_cleanup();
}
@@ -99,15 +99,13 @@ static void test_cleanup(void)
static void perror_no_message(void)
{
- errno = 1;
- el_perror(ELF, NULL);
+ errno = 1;
+ el_perror(ELF, NULL);
- /* as different implementations might have different values for
- * strerror(errno), we check only first part of message that we
- * are sure, will be printed.
- */
-
- mt_fok(strncmp(logbuf, "errno num: 1, strerror: ", 24));
+ /* as different implementations might have different values for
+ * strerror(errno), we check only first part of message that we
+ * are sure, will be printed. */
+ mt_fok(strncmp(logbuf, "errno num: 1, strerror: ", 24));
}
@@ -117,10 +115,10 @@ static void perror_no_message(void)
static void perror_user_message(void)
{
- errno = 1;
- el_perror(ELF, "additional message");
- mt_fok(strncmp(logbuf, "additional message\n"
- "errno num: 1, strerror: ", 43));
+ errno = 1;
+ el_perror(ELF, "additional message");
+ mt_fok(strncmp(logbuf, "additional message\n"
+ "errno num: 1, strerror: ", 43));
}
@@ -130,19 +128,19 @@ static void perror_user_message(void)
static void perror_custom_el_user_message(void)
{
- struct el el;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ struct el el;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- el_oinit(&el);
- el_ooption(&el, EL_CUSTOM_PUTS, print_to_buffer, logbuf);
- el_ooption(&el, EL_PRINT_LEVEL, 0);
- el_ooption(&el, EL_OUT, EL_OUT_CUSTOM);
+ el_oinit(&el);
+ el_ooption(&el, EL_CUSTOM_PUTS, print_to_buffer, logbuf);
+ el_ooption(&el, EL_PRINT_LEVEL, 0);
+ el_ooption(&el, EL_OUT, EL_OUT_CUSTOM);
- errno = 1;
- el_operror(ELF, &el, "additional message");
- mt_fok(strncmp(logbuf, "additional message\n"
- "errno num: 1, strerror: ", 43));
+ errno = 1;
+ el_operror(ELF, &el, "additional message");
+ mt_fok(strncmp(logbuf, "additional message\n"
+ "errno num: 1, strerror: ", 43));
}
@@ -158,10 +156,10 @@ static void perror_custom_el_user_message(void)
void el_perror_test_group(void)
{
- mt_prepare_test = &test_prepare;
- mt_cleanup_test = &test_cleanup;
+ mt_prepare_test = &test_prepare;
+ mt_cleanup_test = &test_cleanup;
- mt_run(perror_no_message);
- mt_run(perror_user_message);
- mt_run(perror_custom_el_user_message);
+ mt_run(perror_no_message);
+ mt_run(perror_user_message);
+ mt_run(perror_custom_el_user_message);
}
diff --git a/tst/test-el-pmemory.c b/tst/test-el-pmemory.c
index aceeedb..42b9fbe 100644
--- a/tst/test-el-pmemory.c
+++ b/tst/test-el-pmemory.c
@@ -57,13 +57,13 @@ static char ascii[128];
static int print_to_buffer
(
- const char *s,
- size_t slen,
- void *user
+ const char *s,
+ size_t slen,
+ void *user
)
{
- strcat(user, s);
- return 0;
+ strcat(user, s);
+ return 0;
}
@@ -73,11 +73,11 @@ static int print_to_buffer
static void test_prepare(void)
{
- el_init();
- el_option(EL_CUSTOM_PUTS, print_to_buffer, logbuf);
- el_option(EL_PRINT_LEVEL, 0);
- el_option(EL_OUT, EL_OUT_CUSTOM);
- logbuf[0] = '\0';
+ el_init();
+ el_option(EL_CUSTOM_PUTS, print_to_buffer, logbuf);
+ el_option(EL_PRINT_LEVEL, 0);
+ el_option(EL_OUT, EL_OUT_CUSTOM);
+ logbuf[0] = '\0';
}
@@ -87,7 +87,7 @@ static void test_prepare(void)
static void test_cleanup(void)
{
- el_cleanup();
+ el_cleanup();
}
@@ -103,12 +103,12 @@ static void test_cleanup(void)
static void pmemory_one_byte(void)
{
- static const char c = 'a';
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ static const char c = 'a';
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- el_pmemory(ELI, &c, sizeof(c));
- mt_fok(strcmp(logbuf,
+ el_pmemory(ELI, &c, sizeof(c));
+ mt_fok(strcmp(logbuf,
"0x0000 61 a\n"));
}
@@ -119,11 +119,11 @@ static void pmemory_one_byte(void)
static void pmemory_one_line_not_full(void)
{
- static const char *s = "test string";
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ static const char *s = "test string";
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- el_pmemory(ELI, s, strlen(s));
- mt_fok(strcmp(logbuf,
+ el_pmemory(ELI, s, strlen(s));
+ mt_fok(strcmp(logbuf,
"0x0000 74 65 73 74 20 73 74 72 69 6e 67 test string\n"));
}
@@ -134,12 +134,12 @@ static void pmemory_one_line_not_full(void)
static void pmemory_one_line_full(void)
{
- static const char *s = "qwertyuiopasdfgh";
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ static const char *s = "qwertyuiopasdfgh";
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- el_pmemory(ELI, s, strlen(s));
- mt_fok(strcmp(logbuf,
+ el_pmemory(ELI, s, strlen(s));
+ mt_fok(strcmp(logbuf,
"0x0000 71 77 65 72 74 79 75 69 6f 70 61 73 64 66 67 68 qwertyuiopasdfgh\n"));
}
@@ -150,12 +150,12 @@ static void pmemory_one_line_full(void)
static void pmemory_two_line_not_full(void)
{
- static const char *s = "first line i am and i am 2";
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ static const char *s = "first line i am and i am 2";
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- el_pmemory(ELI, s, strlen(s));
- mt_fok(strcmp(logbuf,
+ el_pmemory(ELI, s, strlen(s));
+ mt_fok(strcmp(logbuf,
"0x0000 66 69 72 73 74 20 6c 69 6e 65 20 69 20 61 6d 20 first line i am \n"
"0x0010 61 6e 64 20 69 20 61 6d 20 32 and i am 2\n"));
}
@@ -167,12 +167,12 @@ static void pmemory_two_line_not_full(void)
static void pmemory_two_line_full(void)
{
- static const char *s = "first line i am and i am 2nd lin";
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ static const char *s = "first line i am and i am 2nd lin";
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- el_pmemory(ELI, s, strlen(s));
- mt_fok(strcmp(logbuf,
+ el_pmemory(ELI, s, strlen(s));
+ mt_fok(strcmp(logbuf,
"0x0000 66 69 72 73 74 20 6c 69 6e 65 20 69 20 61 6d 20 first line i am \n"
"0x0010 61 6e 64 20 69 20 61 6d 20 32 6e 64 20 6c 69 6e and i am 2nd lin\n"));
}
@@ -180,15 +180,15 @@ static void pmemory_two_line_full(void)
static void pmemory_binary_data_with_nulls(void)
{
- static const unsigned char data[] = {
- 0x05, 0x02, 0x10, 0x50, 0x53, 0x8f, 0xff, 0x3d,
- 0x00, 0x00, 0x4a, 0xab, 0xfc, 0x04, 0x00, 0xfa,
- 0xfd, 0xfa, 0x7f, 0x80 };
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ static const unsigned char data[] = {
+ 0x05, 0x02, 0x10, 0x50, 0x53, 0x8f, 0xff, 0x3d,
+ 0x00, 0x00, 0x4a, 0xab, 0xfc, 0x04, 0x00, 0xfa,
+ 0xfd, 0xfa, 0x7f, 0x80 };
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- el_pmemory(ELI, data, sizeof(data));
- mt_fok(strcmp(logbuf,
+ el_pmemory(ELI, data, sizeof(data));
+ mt_fok(strcmp(logbuf,
"0x0000 05 02 10 50 53 8f ff 3d 00 00 4a ab fc 04 00 fa ...PS..=..J.....\n"
"0x0010 fd fa 7f 80 ....\n"));
}
@@ -199,8 +199,8 @@ static void pmemory_binary_data_with_nulls(void)
static void pmemory_print_ascii_table(void)
{
- el_pmemory(ELI, ascii, sizeof(ascii));
- mt_fok(strcmp(logbuf,
+ el_pmemory(ELI, ascii, sizeof(ascii));
+ mt_fok(strcmp(logbuf,
"0x0000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................\n"
"0x0010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f ................\n"
"0x0020 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f !\"#$%&'()*+,-./\n"
@@ -218,8 +218,8 @@ static void pmemory_print_ascii_table(void)
static void pmemory_print_ascii_table_with_table(void)
{
- el_pmemory_table(ELI, ascii, sizeof(ascii));
- mt_fok(strcmp(logbuf,
+ el_pmemory_table(ELI, ascii, sizeof(ascii));
+ mt_fok(strcmp(logbuf,
"------ ----------------------------------------------- ----------------\n"
"offset hex ascii\n"
"------ ----------------------------------------------- ----------------\n"
@@ -241,18 +241,18 @@ static void pmemory_print_ascii_table_with_table(void)
static void pmemory_print_ascii_table_option(void)
{
- struct el el;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ struct el el;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- el_oinit(&el);
- el_ooption(&el, EL_CUSTOM_PUTS, print_to_buffer, logbuf);
- el_ooption(&el, EL_PRINT_LEVEL, 0);
- el_ooption(&el, EL_OUT, EL_OUT_CUSTOM);
- logbuf[0] = '\0';
+ el_oinit(&el);
+ el_ooption(&el, EL_CUSTOM_PUTS, print_to_buffer, logbuf);
+ el_ooption(&el, EL_PRINT_LEVEL, 0);
+ el_ooption(&el, EL_OUT, EL_OUT_CUSTOM);
+ logbuf[0] = '\0';
- el_opmemory(ELI, &el, ascii, sizeof(ascii));
- mt_fok(strcmp(logbuf,
+ el_opmemory(ELI, &el, ascii, sizeof(ascii));
+ mt_fok(strcmp(logbuf,
"0x0000 00 01 02 03 04 05 06 07 08 09 0a 0b 0c 0d 0e 0f ................\n"
"0x0010 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f ................\n"
"0x0020 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f !\"#$%&'()*+,-./\n"
@@ -262,7 +262,7 @@ static void pmemory_print_ascii_table_option(void)
"0x0060 60 61 62 63 64 65 66 67 68 69 6a 6b 6c 6d 6e 6f `abcdefghijklmno\n"
"0x0070 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~.\n"));
- el_ocleanup(&el);
+ el_ocleanup(&el);
}
@@ -272,18 +272,18 @@ static void pmemory_print_ascii_table_option(void)
static void pmemory_print_ascii_table_with_table_option(void)
{
- struct el el;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ struct el el;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- el_oinit(&el);
- el_ooption(&el, EL_CUSTOM_PUTS, print_to_buffer, logbuf);
- el_ooption(&el, EL_PRINT_LEVEL, 0);
- el_ooption(&el, EL_OUT, EL_OUT_CUSTOM);
- logbuf[0] = '\0';
+ el_oinit(&el);
+ el_ooption(&el, EL_CUSTOM_PUTS, print_to_buffer, logbuf);
+ el_ooption(&el, EL_PRINT_LEVEL, 0);
+ el_ooption(&el, EL_OUT, EL_OUT_CUSTOM);
+ logbuf[0] = '\0';
- el_opmemory_table(ELI, &el, ascii, sizeof(ascii));
- mt_fok(strcmp(logbuf,
+ el_opmemory_table(ELI, &el, ascii, sizeof(ascii));
+ mt_fok(strcmp(logbuf,
"------ ----------------------------------------------- ----------------\n"
"offset hex ascii\n"
"------ ----------------------------------------------- ----------------\n"
@@ -297,7 +297,7 @@ static void pmemory_print_ascii_table_with_table_option(void)
"0x0070 70 71 72 73 74 75 76 77 78 79 7a 7b 7c 7d 7e 7f pqrstuvwxyz{|}~.\n"
"------ ----------------------------------------------- ----------------\n"));
- el_ocleanup(&el);
+ el_ocleanup(&el);
}
@@ -325,88 +325,78 @@ static const char expected_out[] =
static int print_check(void)
{
- int i;
- char *msg;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- /* all we care about is that there are no interlaces
- */
-
- for (msg = logbuf, i = 0; i != number_of_prints; ++i, msg += print_length)
- {
- if (strncmp(msg, expected_out, print_length) != 0)
- {
- fprintf(stderr, "message does not match (pass %d) msg: %s\n",
- i, msg);
- return -1;
- }
- }
-
- if (*msg != '\0')
- {
- fprintf(stderr, "expected null terminator on last msg byte\n");
- return -1;
- }
-
- return 0;
+ int i;
+ char *msg;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ /* all we care about is that there are no interlaces
+ */
+
+ for (msg = logbuf, i = 0; i != number_of_prints; ++i, msg += print_length)
+ {
+ if (strncmp(msg, expected_out, print_length) != 0)
+ {
+ fprintf(stderr, "message does not match (pass %d) msg: %s\n",
+ i, msg);
+ return -1;
+ }
+ }
+
+ if (*msg != '\0')
+ {
+ fprintf(stderr, "expected null terminator on last msg byte\n");
+ return -1;
+ }
+
+ return 0;
}
static void *print_t
(
- void *arg
+ void *arg
)
{
- int i;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int i;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- (void)arg;
+ (void)arg;
+ for (i = 0; i != prints_per_thread; ++i)
+ el_pmemory(ELN, ascii, sizeof(ascii));
- for (i = 0; i != prints_per_thread; ++i)
- {
- el_pmemory(ELN, ascii, sizeof(ascii));
- }
-
- return NULL;
+ return NULL;
}
static void pmemory_print_threaded(void)
{
- pthread_t pt[number_of_threads];
- int i;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- el_init();
- el_option(EL_THREAD_SAFE, 1);
- el_option(EL_CUSTOM_PUTS, print_to_buffer, logbuf);
- el_option(EL_PRINT_LEVEL, 0);
- el_option(EL_OUT, EL_OUT_CUSTOM);
- logbuf[0] = '\0';
+ pthread_t pt[number_of_threads];
+ int i;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- for (i = 0; i != number_of_threads; ++i)
- {
- pthread_create(&pt[i], NULL, print_t, NULL);
- }
- for (i = 0; i != number_of_threads; ++i)
- {
- pthread_join(pt[i], NULL);
- }
+ el_init();
+ el_option(EL_THREAD_SAFE, 1);
+ el_option(EL_CUSTOM_PUTS, print_to_buffer, logbuf);
+ el_option(EL_PRINT_LEVEL, 0);
+ el_option(EL_OUT, EL_OUT_CUSTOM);
+ logbuf[0] = '\0';
- /* do it before print_check() so any buffered data is flushed
- * to disk, otherwise files will be incomplete
- */
+ for (i = 0; i != number_of_threads; ++i)
+ pthread_create(&pt[i], NULL, print_t, NULL);
- el_flush();
+ for (i = 0; i != number_of_threads; ++i)
+ pthread_join(pt[i], NULL);
- mt_fok(print_check());
+ /* do it before print_check() so any buffered data is flushed
+ * to disk, otherwise files will be incomplete */
- el_cleanup();
+ el_flush();
+ mt_fok(print_check());
+ el_cleanup();
}
#endif /* ENABLE_PTHREAD */
@@ -418,7 +408,7 @@ static void pmemory_print_threaded(void)
static void pmemory_null_memory(void)
{
- mt_ferr(el_pmemory(ELI, NULL, 10), EINVAL);
+ mt_ferr(el_pmemory(ELI, NULL, 10), EINVAL);
}
@@ -428,11 +418,11 @@ static void pmemory_null_memory(void)
static void pmemory_zero_size(void)
{
- static const char *s = "some data";
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ static const char *s = "some data";
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- mt_ferr(el_pmemory(ELI, s, 0), EINVAL);
+ mt_ferr(el_pmemory(ELI, s, 0), EINVAL);
}
@@ -448,33 +438,30 @@ static void pmemory_zero_size(void)
void el_pmemory_test_group(void)
{
- int i;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int i;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- for (i = 0; i != 0x80; ++i)
- {
- ascii[i] = (char)i;
- }
+ for (i = 0; i != 0x80; ++i) ascii[i] = (char)i;
#if ENABLE_PTHREAD
- mt_run(pmemory_print_threaded);
+ mt_run(pmemory_print_threaded);
#endif
- mt_run(pmemory_print_ascii_table_option);
- mt_run(pmemory_print_ascii_table_with_table_option);
-
- mt_prepare_test = &test_prepare;
- mt_cleanup_test = &test_cleanup;
-
- mt_run(pmemory_one_byte);
- mt_run(pmemory_one_line_not_full);
- mt_run(pmemory_one_line_full);
- mt_run(pmemory_two_line_not_full);
- mt_run(pmemory_two_line_full);
- mt_run(pmemory_binary_data_with_nulls);
- mt_run(pmemory_print_ascii_table);
- mt_run(pmemory_print_ascii_table_with_table);
- mt_run(pmemory_null_memory);
- mt_run(pmemory_zero_size);
+ mt_run(pmemory_print_ascii_table_option);
+ mt_run(pmemory_print_ascii_table_with_table_option);
+
+ mt_prepare_test = &test_prepare;
+ mt_cleanup_test = &test_cleanup;
+
+ mt_run(pmemory_one_byte);
+ mt_run(pmemory_one_line_not_full);
+ mt_run(pmemory_one_line_full);
+ mt_run(pmemory_two_line_not_full);
+ mt_run(pmemory_two_line_full);
+ mt_run(pmemory_binary_data_with_nulls);
+ mt_run(pmemory_print_ascii_table);
+ mt_run(pmemory_print_ascii_table_with_table);
+ mt_run(pmemory_null_memory);
+ mt_run(pmemory_zero_size);
}
diff --git a/tst/test-el-print.c b/tst/test-el-print.c
index 1bcfcfa..d4d4b30 100644
--- a/tst/test-el-print.c
+++ b/tst/test-el-print.c
@@ -42,11 +42,11 @@
struct log_message
{
- const char *file;
- size_t line;
- const char *func;
- int level;
- const char *msg;
+ const char *file;
+ size_t line;
+ const char *func;
+ int level;
+ const char *msg;
};
@@ -93,34 +93,26 @@ static struct log_message expected_msgs[number_of_threads];
static int thread_str_to_int
(
- const char *msg
+ const char *msg
)
{
- char *tids;
- char mcpy[1024];
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ char *tids;
+ char mcpy[1024];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- /* msg is in format "msg [TTT:III]" where TTT is thread id
- */
+ /* msg is in format "msg [TTT:III]" where TTT is thread id */
+ strcpy(mcpy, msg);
- strcpy(mcpy, msg);
+ /* turn : into null */
+ tids = strrchr(mcpy, ':');
+ *tids = '\0';
- /* turn : into null
- */
+ /* point tids to beginning of thread id */
+ tids = strrchr(mcpy, '[') + 1;
- tids = strrchr(mcpy, ':');
- *tids = '\0';
-
- /* point tids to beginning of thread id
- */
-
- tids = strrchr(mcpy, '[') + 1;
-
- /* convert thread id to int
- */
-
- return atoi(tids);
+ /* convert thread id to int */
+ return atoi(tids);
}
@@ -133,31 +125,31 @@ static int thread_str_to_int
static int print_to_buffer
(
- const char *s,
- size_t slen,
- void *user
+ const char *s,
+ size_t slen,
+ void *user
)
{
- strcat(user, s);
+ strcat(user, s);
#if ENABLE_PTHREAD
- if (thread_test)
- {
- int tid;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ if (thread_test)
+ {
+ int tid;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- /* we can now add previously cached log info to expected logs.
- * We do it here, so we can be sure it will go into the list
- * in the same order as "s" into "user" (log_buf).
- */
+ /* we can now add previously cached log info to expected logs.
+ * We do it here, so we can be sure it will go into the list
+ * in the same order as "s" into "user" (log_buf).
+ */
- tid = thread_str_to_int(s);
- rb_write(expected_logs, &expected_msgs[tid], 1);
- }
+ tid = thread_str_to_int(s);
+ rb_write(expected_logs, &expected_msgs[tid], 1);
+ }
#endif
- return 0;
+ return 0;
}
@@ -172,448 +164,385 @@ static int print_to_buffer
static int print_check(void)
{
#define IS_DIGIT() if (!isdigit(*msg++)) { \
- fprintf(stderr, "%c not a digit in %s\n", *(msg - 1), line); \
- return -1; \
+ fprintf(stderr, "%c not a digit in %s\n", *(msg - 1), line); \
+ return -1; \
}
#define IS_CHAR(c) if (*msg++ != c) { \
- fprintf(stderr, "%c not a char %c in %s\n", *(msg - 1), c, line); \
- return -1; \
+ fprintf(stderr, "%c not a char %c in %s\n", *(msg - 1), c, line); \
+ return -1; \
}
- static const char *levelstr = "facewnid";
- struct log_message expected;
- char *msg;
- char line[1024];
- char tmp[1024];
- int i;
- int slevel;
- size_t msglen;
-#if ENABLE_COLORS_EXTENDED
- static const char *color[] =
- {
- "\033[91m", /* fatal light red */
- "\033[31m", /* alert red */
- "\033[95m", /* critical light magenta */
- "\033[35m", /* error magenta */
- "\033[93m", /* warning light yellow */
- "\033[92m", /* notice light green */
- "\033[32m", /* information green */
- "\033[34m", /* debug blue */
- "\033[0m" /* remove all formats */
- };
-#else
- static const char *color[] =
- {
- "\033[31m", /* fatal light red */
- "\033[31m", /* alert red */
- "\033[35m", /* critical light magenta */
- "\033[35m", /* error magenta */
- "\033[33m", /* warning light yellow */
- "\033[32m", /* notice light green */
- "\033[32m", /* information green */
- "\033[34m", /* debug blue */
- "\033[0m" /* remove all formats */
- };
-#endif
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- msg = logbuf;
- while (rb_read(expected_logs, &expected, 1) == 1)
- {
- slevel = expected.level > EL_DBG ? EL_DBG : expected.level;
-
- /* put current line into buf, we will print in in event of error
- */
-
- {
- char *nl;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- strncpy(line, msg, sizeof(line));
- line[sizeof(line) - 1] = '\0';
- nl = strchr(line, '\n');
-
- if (nl != NULL)
- {
- *nl = '\0';
- }
- }
-
-
- if (expected.level > g_el.level)
- {
- /* log should not have been printed due to current log
- * level restriction. We just continue here, because if
- * log was indeed printed, next checks will fail
- * anyway.
- */
-
- continue;
- }
-
- if (g_el.colors)
- {
- if (strncmp(msg, color[slevel], 5) != 0)
- {
- /* no color information or el_print generated wrong
- * color
- */
-
- fprintf(stderr, "no color info in %s\n", line);
- return -1;
- }
-
- /* move msg by 5 bytes - begging of color is always
- * 5char long
- */
-
- msg += 5;
- }
-
- /* check printing timestamp
- */
-
- if (g_el.timestamp == EL_TS_LONG)
- {
- IS_CHAR('[');
- IS_DIGIT();
- IS_DIGIT();
- IS_DIGIT();
- IS_DIGIT();
- IS_CHAR('-');
- IS_DIGIT();
- IS_DIGIT();
- IS_CHAR('-');
- IS_DIGIT();
- IS_DIGIT();
- IS_CHAR(' ');
- IS_DIGIT();
- IS_DIGIT();
- IS_CHAR(':');
- IS_DIGIT();
- IS_DIGIT();
- IS_CHAR(':');
- IS_DIGIT();
- IS_DIGIT();
-
- if (g_el.timestamp_fractions)
- {
- IS_CHAR('.');
-
- for (i = 0; i != 3 * g_el.timestamp_fractions; ++i)
- {
- IS_DIGIT();
- }
- }
-
- IS_CHAR(']');
-
- }
- else if (g_el.timestamp == EL_TS_SHORT)
- {
- IS_CHAR('[');
-
- if (g_el.timestamp_fractions)
- {
- while (*msg != '.')
- {
- IS_DIGIT();
- }
-
- ++msg; /* skip the '.' character */
-
- for (i = 0; i != 3 * g_el.timestamp_fractions; ++i)
- {
- IS_DIGIT();
- }
- }
- else
- {
- while (*msg != ']')
- {
- IS_DIGIT();
- }
- }
-
- IS_CHAR(']');
- }
- else if (g_el.timestamp == EL_TS_OFF)
- {
- /* we check for nothing here
- */
- }
- else
- {
- /* wrong timestamp option value
- */
-
- fprintf(stderr, "wrong timestamp opton value in %s\n", line);
- return -1;
- }
-
- /* check printing file information
- */
-
- if (g_el.finfo && expected.file != NULL && expected.line != 0)
- {
- char expected_file[8192];
- char f_func_info_separator;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- IS_CHAR('[');
- i = 0;
-
- while (*msg != ':')
- {
- tmp[i] = *msg++;
- if (i++ == EL_FLEN_MAX)
- {
- /* we didn't find ':' character withing maximum
- * lenght of file - file is too long
- */
-
- fprintf(stderr, "':' not found in finfo in %s\n", line);
- return -1;
- }
- }
-
- msg++; /* skip ':' character */
- tmp[i] = '\0';
- strcpy(expected_file, expected.file);
-
- if (strncmp(tmp, basename(expected_file), EL_FLEN_MAX) != 0)
- {
- /*
- * file name in printed log is different than what we set
- */
-
- fprintf(stderr, "wrong filename %s != %s in %s\n",
- tmp, expected_file, line);
- return -1;
- }
-
- i = 0;
-
- /* when funcinfo is enabled, there should be ':' instead
- * of closing bracked as print will look like this:
- *
- * [file.c:2:foo()] instead of [file.c:2]
- */
-
- f_func_info_separator = g_el.funcinfo ? ':' : ']';
-
- while (*msg != f_func_info_separator)
- {
- tmp[i] = *msg;
- if (i++ == EL_PRE_FINFO_LINE_MAX_LEN)
- {
- /* file line lenght is too large, or ending ']'
- * is missing
- */
-
- fprintf(stderr, "']' not found in finfo in %s\n", line);
- return -1;
- }
-
- /* file line should be a number ;-)
- */
-
- IS_DIGIT();
-
- }
-
- msg++; /* skip ']' or ':' character */
- tmp[i] = '\0';
-
- if (expected.line > EL_PRE_FINFO_LINE_MAX_NUM)
- {
- expected.line = EL_PRE_FINFO_LINE_MAX_NUM;
- }
-
- if ((size_t)atoi(tmp) != expected.line)
- {
- /* line number in printed log is different than
- * what was set
- */
-
- fprintf(stderr, "wrong line number %ld != %ld in %s\n",
- (long)atoi(tmp), (long)expected.line, line);
- return -1;
- }
-
- }
-
- /* check for function information
- */
-
- if (g_el.funcinfo && expected.func != NULL)
- {
- if (g_el.finfo == 0 || expected.file == NULL ||
- expected.line == 0)
- {
- /* file info was not printed, so check for opening
- * '[' character
- */
-
- if (*msg++ != '[')
- {
- fprintf(stderr, "missing '[' in %s\n", line);
- return -1;
- }
- }
-
- i = 0;
-
- /* search until we hit appended "()"
- */
-
- while (*msg != '(')
- {
- tmp[i] = *msg++;
- if (i++ == EL_FUNCLEN_MAX)
- {
- /* function is too long or ending (
- * is missing
- */
-
- fprintf(stderr, "missing ( in funcinfo in %s\n", line);
- return -1;
- }
- }
-
- tmp[i] = '\0';
- if (strncmp(tmp, expected.func, EL_FUNCLEN_MAX) != 0)
- {
- /* function is different than what we expected
- */
-
- fprintf(stderr, "function is wrong %s != %s in %s\n",
- tmp, expected.func, line);
- return -1;
- }
-
- /* check closing stuff, we should see ()]
- */
-
- IS_CHAR('(');
- IS_CHAR(')');
- IS_CHAR(']');
- }
-
- if ((g_el.finfo && expected.file != NULL && expected.line != 0) ||
- g_el.timestamp != EL_TS_OFF ||
- (g_el.funcinfo && expected.func != NULL))
- {
- /* prefix or timestamp information is enabled, in that
- * case we check for additional space between info and
- * log message
- */
-
- if (*msg++ != ' ')
- {
- fprintf(stderr, "missing space delimiter in %s\n", line);
- return -1;
- }
- }
-
- /* check printing log level
- */
-
- if (g_el.print_log_level)
- {
- if (*msg++ != levelstr[slevel])
- {
- fprintf(stderr, "wrong level char %c != %c in %s\n",
- *(msg - 1), levelstr[slevel], line);
- return -1;
- }
-
- if (*msg++ != '/')
- {
- fprintf(stderr, "missing '/' near log level in %s\n", line);
- return -1;
- }
- }
-
- /* check for prefix
- */
-
-#if ENABLE_PREFIX
- if (g_el.prefix)
- {
- char expected_prefix[EL_PREFIX_LEN + 1] = {0};
- size_t expected_prefix_len;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
- strncat(expected_prefix, g_el.prefix, EL_PREFIX_LEN);
- expected_prefix_len = strlen(expected_prefix);
-
- if (strncmp(expected_prefix, msg, expected_prefix_len) != 0)
- {
- fprintf(stderr, "wrong prefix expected %s in %s\n",
- expected_prefix, line);
- return -1;
- }
-
- msg += expected_prefix_len;
- }
-#endif
-
- msglen = strlen(expected.msg);
-
- if (strncmp(msg, expected.msg, msglen) != 0)
- {
- fprintf(stderr, "log msg is bad, expected %s in %s\n",
- expected.msg, line);
- return -1;
- }
-
- msg += msglen;
-
- if (g_el.colors)
- {
- if (strncmp(msg, color[8], 4) != 0)
- {
- /* expected end of color, got some shit
- */
-
- fprintf(stderr, "missing color ending code in %s\n", line);
- return -1;
- }
-
- /* end of color is always 4 bytes long
- */
-
- msg += 4;
- }
-
- if (g_el.print_newline)
- {
- if (*msg != '\n')
- {
- /* when new line is enabled, log should end with
- * new line
- */
-
- fprintf(stderr, "missing new line char in %s\n", line);
- return -1;
- }
-
- /* set msg to point to next message, there is no need
- * to move msg pointer if newline is not printed as msg
- * already points to next message
- */
-
- ++msg;
- }
- }
-
- return 0;
-
-#undef IS_CHAR
-#undef IS_DIGIT
+ static const char *levelstr = "facewnid";
+ struct log_message expected;
+ char *msg;
+ char line[1024];
+ char tmp[1024];
+ int i;
+ int slevel;
+ size_t msglen;
+ #if ENABLE_COLORS_EXTENDED
+ static const char *color[] =
+ {
+ "\033[91m", /* fatal light red */
+ "\033[31m", /* alert red */
+ "\033[95m", /* critical light magenta */
+ "\033[35m", /* error magenta */
+ "\033[93m", /* warning light yellow */
+ "\033[92m", /* notice light green */
+ "\033[32m", /* information green */
+ "\033[34m", /* debug blue */
+ "\033[0m" /* remove all formats */
+ };
+ #else
+ static const char *color[] =
+ {
+ "\033[31m", /* fatal light red */
+ "\033[31m", /* alert red */
+ "\033[35m", /* critical light magenta */
+ "\033[35m", /* error magenta */
+ "\033[33m", /* warning light yellow */
+ "\033[32m", /* notice light green */
+ "\033[32m", /* information green */
+ "\033[34m", /* debug blue */
+ "\033[0m" /* remove all formats */
+ };
+ #endif
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+ msg = logbuf;
+ while (rb_read(expected_logs, &expected, 1) == 1)
+ {
+ slevel = expected.level > EL_DBG ? EL_DBG : expected.level;
+
+ /* put current line into buf, we will print in in event of error */
+ {
+ char *nl;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ strncpy(line, msg, sizeof(line));
+ line[sizeof(line) - 1] = '\0';
+ nl = strchr(line, '\n');
+
+ if (nl != NULL) *nl = '\0';
+ }
+
+
+ /* log should not have been printed due to current log
+ * level restriction. We just continue here, because if
+ * log was indeed printed, next checks will fail
+ * anyway. */
+ if (expected.level > g_el.level) continue;
+
+ if (g_el.colors)
+ {
+ if (strncmp(msg, color[slevel], 5) != 0)
+ {
+ /* no color information or el_print generated wrong
+ * color */
+ fprintf(stderr, "no color info in %s\n", line);
+ return -1;
+ }
+
+ /* move msg by 5 bytes - begging of color is always
+ * 5char long */
+ msg += 5;
+ }
+
+ /* check printing timestamp */
+ if (g_el.timestamp == EL_TS_LONG)
+ {
+ IS_CHAR('[');
+ IS_DIGIT();
+ IS_DIGIT();
+ IS_DIGIT();
+ IS_DIGIT();
+ IS_CHAR('-');
+ IS_DIGIT();
+ IS_DIGIT();
+ IS_CHAR('-');
+ IS_DIGIT();
+ IS_DIGIT();
+ IS_CHAR(' ');
+ IS_DIGIT();
+ IS_DIGIT();
+ IS_CHAR(':');
+ IS_DIGIT();
+ IS_DIGIT();
+ IS_CHAR(':');
+ IS_DIGIT();
+ IS_DIGIT();
+
+ if (g_el.timestamp_fractions)
+ {
+ IS_CHAR('.');
+
+ for (i = 0; i != 3 * g_el.timestamp_fractions; ++i)
+ IS_DIGIT();
+ }
+
+ IS_CHAR(']');
+
+ }
+ else if (g_el.timestamp == EL_TS_SHORT)
+ {
+ IS_CHAR('[');
+
+ if (g_el.timestamp_fractions)
+ {
+ while (*msg != '.')
+ IS_DIGIT();
+
+ ++msg; /* skip the '.' character */
+
+ for (i = 0; i != 3 * g_el.timestamp_fractions; ++i)
+ IS_DIGIT();
+ }
+ else
+ {
+ while (*msg != ']')
+ IS_DIGIT();
+ }
+
+ IS_CHAR(']');
+ }
+ else if (g_el.timestamp == EL_TS_OFF)
+ {
+ /* we check for nothing here */
+ }
+ else
+ {
+ /* wrong timestamp option value */
+ fprintf(stderr, "wrong timestamp opton value in %s\n", line);
+ return -1;
+ }
+
+ /* check printing file information
+ */
+
+ if (g_el.finfo && expected.file != NULL && expected.line != 0)
+ {
+ char expected_file[8192];
+ char f_func_info_separator;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ IS_CHAR('[');
+ i = 0;
+
+ while (*msg != ':')
+ {
+ tmp[i] = *msg++;
+ if (i++ == EL_FLEN_MAX)
+ {
+ /* we didn't find ':' character withing maximum
+ * lenght of file - file is too long */
+ fprintf(stderr, "':' not found in finfo in %s\n", line);
+ return -1;
+ }
+ }
+
+ msg++; /* skip ':' character */
+ tmp[i] = '\0';
+ strcpy(expected_file, expected.file);
+
+ if (strncmp(tmp, basename(expected_file), EL_FLEN_MAX) != 0)
+ {
+ /* file name in printed log is different than what
+ * we set */
+
+ fprintf(stderr, "wrong filename %s != %s in %s\n",
+ tmp, expected_file, line);
+ return -1;
+ }
+
+ i = 0;
+
+ /* when funcinfo is enabled, there should be ':' instead
+ * of closing bracked as print will look like this:
+ *
+ * [file.c:2:foo()] instead of [file.c:2] */
+
+ f_func_info_separator = g_el.funcinfo ? ':' : ']';
+
+ while (*msg != f_func_info_separator)
+ {
+ tmp[i] = *msg;
+ if (i++ == EL_PRE_FINFO_LINE_MAX_LEN)
+ {
+ /* file line lenght is too large, or ending ']'
+ * is missing */
+
+ fprintf(stderr, "']' not found in finfo in %s\n", line);
+ return -1;
+ }
+
+ /* file line should be a number ;-) */
+ IS_DIGIT();
+
+ }
+
+ msg++; /* skip ']' or ':' character */
+ tmp[i] = '\0';
+
+ if (expected.line > EL_PRE_FINFO_LINE_MAX_NUM)
+ expected.line = EL_PRE_FINFO_LINE_MAX_NUM;
+
+ if ((size_t)atoi(tmp) != expected.line)
+ {
+ /* line number in printed log is different than
+ * what was set */
+ fprintf(stderr, "wrong line number %ld != %ld in %s\n",
+ (long)atoi(tmp), (long)expected.line, line);
+ return -1;
+ }
+
+ }
+
+ /* check for function information */
+ if (g_el.funcinfo && expected.func != NULL)
+ {
+ if (g_el.finfo == 0 || expected.file == NULL ||
+ expected.line == 0)
+ {
+ /* file info was not printed, so check for opening
+ * '[' character */
+ if (*msg++ != '[')
+ {
+ fprintf(stderr, "missing '[' in %s\n", line);
+ return -1;
+ }
+ }
+
+ i = 0;
+
+ /* search until we hit appended "()" */
+ while (*msg != '(')
+ {
+ tmp[i] = *msg++;
+ if (i++ == EL_FUNCLEN_MAX)
+ {
+ /* function is too long or ending (
+ * is missing */
+ fprintf(stderr, "missing ( in funcinfo in %s\n", line);
+ return -1;
+ }
+ }
+
+ tmp[i] = '\0';
+ if (strncmp(tmp, expected.func, EL_FUNCLEN_MAX) != 0)
+ {
+ /* function is different than what we expected */
+ fprintf(stderr, "function is wrong %s != %s in %s\n",
+ tmp, expected.func, line);
+ return -1;
+ }
+
+ /* check closing stuff, we should see ()] */
+ IS_CHAR('(');
+ IS_CHAR(')');
+ IS_CHAR(']');
+ }
+
+ if ((g_el.finfo && expected.file != NULL && expected.line != 0) ||
+ g_el.timestamp != EL_TS_OFF ||
+ (g_el.funcinfo && expected.func != NULL))
+ {
+ /* prefix or timestamp information is enabled, in that
+ * case we check for additional space between info and
+ * log message */
+ if (*msg++ != ' ')
+ {
+ fprintf(stderr, "missing space delimiter in %s\n", line);
+ return -1;
+ }
+ }
+
+ /* check printing log level */
+ if (g_el.print_log_level)
+ {
+ if (*msg++ != levelstr[slevel])
+ {
+ fprintf(stderr, "wrong level char %c != %c in %s\n",
+ *(msg - 1), levelstr[slevel], line);
+ return -1;
+ }
+
+ if (*msg++ != '/')
+ {
+ fprintf(stderr, "missing '/' near log level in %s\n", line);
+ return -1;
+ }
+ }
+
+ /* check for prefix */
+ #if ENABLE_PREFIX
+ if (g_el.prefix)
+ {
+ char expected_prefix[EL_PREFIX_LEN + 1] = {0};
+ size_t expected_prefix_len;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+ strncat(expected_prefix, g_el.prefix, EL_PREFIX_LEN);
+ expected_prefix_len = strlen(expected_prefix);
+
+ if (strncmp(expected_prefix, msg, expected_prefix_len) != 0)
+ {
+ fprintf(stderr, "wrong prefix expected %s in %s\n",
+ expected_prefix, line);
+ return -1;
+ }
+
+ msg += expected_prefix_len;
+ }
+ #endif
+
+ msglen = strlen(expected.msg);
+
+ if (strncmp(msg, expected.msg, msglen) != 0)
+ {
+ fprintf(stderr, "log msg is bad, expected %s in %s\n",
+ expected.msg, line);
+ return -1;
+ }
+
+ msg += msglen;
+
+ if (g_el.colors)
+ {
+ if (strncmp(msg, color[8], 4) != 0)
+ {
+ /* expected end of color, got some shit */
+ fprintf(stderr, "missing color ending code in %s\n", line);
+ return -1;
+ }
+
+ /* end of color is always 4 bytes long */
+ msg += 4;
+ }
+
+ if (g_el.print_newline)
+ {
+ if (*msg != '\n')
+ {
+ /* when new line is enabled, log should end with
+ * new line */
+
+ fprintf(stderr, "missing new line char in %s\n", line);
+ return -1;
+ }
+
+ /* set msg to point to next message, there is no need
+ * to move msg pointer if newline is not printed as msg
+ * already points to next message */
+ ++msg;
+ }
+ }
+
+ return 0;
+
+ #undef IS_CHAR
+ #undef IS_DIGIT
}
@@ -625,59 +554,56 @@ static int print_check(void)
static void add_log
(
- const char *file,
- size_t line,
- const char *func,
- enum el_level level,
- const char *msg
+ const char *file,
+ size_t line,
+ const char *func,
+ enum el_level level,
+ const char *msg
)
{
#if ENABLE_PTHREAD
- if (thread_test == 0)
+ if (thread_test == 0)
#endif
- {
- struct log_message expected;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- expected.file = file;
- expected.line = line;
- expected.func = func;
- expected.level = level;
- expected.msg = msg;
- rb_write(expected_logs, &expected, 1);
- }
+ {
+ struct log_message expected;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ expected.file = file;
+ expected.line = line;
+ expected.func = func;
+ expected.level = level;
+ expected.msg = msg;
+ rb_write(expected_logs, &expected, 1);
+ }
#if ENABLE_PTHREAD
- else
- {
- int tid;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- /* when threaded test is performed, cache expected logs and
- * add them in custom print function. This is due to the
- * fact, that multiple threads can get here, and expected
- * logs buffer can be in different order than logs in
- * log_buf. Custom print function should be protected with
- * mutexes so no such situation should happen there.
- *
- * msg is in format "msg [TTT:III]" where TTT is thread id
- */
-
- tid = thread_str_to_int(msg);
-
- /* now cache entries
- */
-
- expected_msgs[tid].file = file;
- expected_msgs[tid].line = line;
- expected_msgs[tid].func = func;
- expected_msgs[tid].level = level;
- expected_msgs[tid].msg = msg;
- }
+ else
+ {
+ int tid;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ /* when threaded test is performed, cache expected logs and
+ * add them in custom print function. This is due to the
+ * fact, that multiple threads can get here, and expected
+ * logs buffer can be in different order than logs in
+ * log_buf. Custom print function should be protected with
+ * mutexes so no such situation should happen there.
+ *
+ * msg is in format "msg [TTT:III]" where TTT is thread id */
+
+ tid = thread_str_to_int(msg);
+
+ /* now cache entries */
+ expected_msgs[tid].file = file;
+ expected_msgs[tid].line = line;
+ expected_msgs[tid].func = func;
+ expected_msgs[tid].level = level;
+ expected_msgs[tid].msg = msg;
+ }
#endif
- el_print(file, line, func, level, msg);
+ el_print(file, line, func, level, msg);
}
@@ -689,12 +615,12 @@ static void add_log
static void test_prepare(void)
{
- el_init();
- logbuf = calloc(1, 1024 * 1024);
- el_option(EL_CUSTOM_PUTS, print_to_buffer, logbuf);
- el_option(EL_PRINT_LEVEL, 0);
- el_option(EL_OUT, EL_OUT_CUSTOM);
- expected_logs = rb_new(1024, sizeof(struct log_message), 0);
+ el_init();
+ logbuf = calloc(1, 1024 * 1024);
+ el_option(EL_CUSTOM_PUTS, print_to_buffer, logbuf);
+ el_option(EL_PRINT_LEVEL, 0);
+ el_option(EL_OUT, EL_OUT_CUSTOM);
+ expected_logs = rb_new(1024, sizeof(struct log_message), 0);
}
@@ -705,9 +631,9 @@ static void test_prepare(void)
static void test_cleanup(void)
{
- el_cleanup();
- free(logbuf);
- rb_destroy(expected_logs);
+ el_cleanup();
+ free(logbuf);
+ rb_destroy(expected_logs);
}
@@ -723,8 +649,8 @@ static void test_cleanup(void)
static void print_simple_message(void)
{
- add_log(ELF, "print_simple_message");
- mt_fok(print_check());
+ add_log(ELF, "print_simple_message");
+ mt_fok(print_check());
}
@@ -734,10 +660,10 @@ static void print_simple_message(void)
static void print_simple_message_no_newline(void)
{
- el_option(EL_PRINT_NL, 0);
- add_log(ELF, "print simple no newline");
- add_log(ELF, "print simple no newline second");
- mt_fok(print_check());
+ el_option(EL_PRINT_NL, 0);
+ add_log(ELF, "print simple no newline");
+ add_log(ELF, "print simple no newline second");
+ mt_fok(print_check());
}
@@ -747,10 +673,10 @@ static void print_simple_message_no_newline(void)
static void print_simple_multiple_message(void)
{
- add_log(ELF, "print_simple_multiple_message first");
- add_log(ELF, "print_simple_multiple_message second");
- add_log(ELF, "print_simple_multiple_message third");
- mt_fok(print_check());
+ add_log(ELF, "print_simple_multiple_message first");
+ add_log(ELF, "print_simple_multiple_message second");
+ add_log(ELF, "print_simple_multiple_message third");
+ mt_fok(print_check());
}
@@ -760,17 +686,17 @@ static void print_simple_multiple_message(void)
static void print_log_level(void)
{
- el_option(EL_PRINT_LEVEL, 1);
- el_option(EL_LEVEL, EL_DBG);
- add_log(ELF, "print_log_level fatal message");
- add_log(ELA, "print_log_level alert message");
- add_log(ELC, "print_log_level critical message");
- add_log(ELE, "print_log_level error message");
- add_log(ELW, "print_log_level warning message");
- add_log(ELN, "print_log_level notice message");
- add_log(ELI, "print_log_level info message");
- add_log(ELD, "print_log_level debug message");
- mt_fok(print_check());
+ el_option(EL_PRINT_LEVEL, 1);
+ el_option(EL_LEVEL, EL_DBG);
+ add_log(ELF, "print_log_level fatal message");
+ add_log(ELA, "print_log_level alert message");
+ add_log(ELC, "print_log_level critical message");
+ add_log(ELE, "print_log_level error message");
+ add_log(ELW, "print_log_level warning message");
+ add_log(ELN, "print_log_level notice message");
+ add_log(ELI, "print_log_level info message");
+ add_log(ELD, "print_log_level debug message");
+ mt_fok(print_check());
}
@@ -780,19 +706,19 @@ static void print_log_level(void)
static void print_colorful_output(void)
{
- el_option(EL_COLORS, 1);
- el_option(EL_LEVEL, EL_DBG);
- add_log(ELF, "print_colorful_output fatal message");
- add_log(ELA, "print_colorful_output alert message");
- add_log(ELC, "print_colorful_output critical message");
- add_log(ELE, "print_colorful_output error message");
- add_log(ELW, "print_colorful_output warning message");
- add_log(ELN, "print_colorful_output notice message");
- add_log(ELI, "print_colorful_output info message");
- add_log(ELD, "print_colorful_output debug message");
- add_log(ELD + 1, "print_colorful_output debug + 1 message");
- add_log(ELD + 2, "print_colorful_output debug + 2 message");
- mt_fok(print_check());
+ el_option(EL_COLORS, 1);
+ el_option(EL_LEVEL, EL_DBG);
+ add_log(ELF, "print_colorful_output fatal message");
+ add_log(ELA, "print_colorful_output alert message");
+ add_log(ELC, "print_colorful_output critical message");
+ add_log(ELE, "print_colorful_output error message");
+ add_log(ELW, "print_colorful_output warning message");
+ add_log(ELN, "print_colorful_output notice message");
+ add_log(ELI, "print_colorful_output info message");
+ add_log(ELD, "print_colorful_output debug message");
+ add_log(ELD + 1, "print_colorful_output debug + 1 message");
+ add_log(ELD + 2, "print_colorful_output debug + 2 message");
+ mt_fok(print_check());
}
@@ -802,12 +728,12 @@ static void print_colorful_output(void)
static void print_custom_log_level(void)
{
- el_option(EL_PRINT_LEVEL, 1);
- el_option(EL_LEVEL, EL_DBG);
- add_log(ELD + 4, "print_custom_log_level custom debug 4");
- add_log(ELD + 5, "print_custom_log_level custom debug 5");
- add_log(ELD + 6, "print_custom_log_level custom debug 6");
- mt_fok(print_check());
+ el_option(EL_PRINT_LEVEL, 1);
+ el_option(EL_LEVEL, EL_DBG);
+ add_log(ELD + 4, "print_custom_log_level custom debug 4");
+ add_log(ELD + 5, "print_custom_log_level custom debug 5");
+ add_log(ELD + 6, "print_custom_log_level custom debug 6");
+ mt_fok(print_check());
}
@@ -817,10 +743,10 @@ static void print_custom_log_level(void)
static void print_timestamp_short(void)
{
- el_option(EL_TS, EL_TS_SHORT);
- add_log(ELF, "print_timestamp_short first");
- add_log(ELF, "print_timestamp_short second");
- mt_fok(print_check());
+ el_option(EL_TS, EL_TS_SHORT);
+ add_log(ELF, "print_timestamp_short first");
+ add_log(ELF, "print_timestamp_short second");
+ mt_fok(print_check());
}
@@ -830,10 +756,10 @@ static void print_timestamp_short(void)
static void print_timestamp_long(void)
{
- el_option(EL_TS, EL_TS_LONG);
- add_log(ELF, "print_timestamp_long first");
- add_log(ELF, "print_timestamp_long second");
- mt_fok(print_check());
+ el_option(EL_TS, EL_TS_LONG);
+ add_log(ELF, "print_timestamp_long first");
+ add_log(ELF, "print_timestamp_long second");
+ mt_fok(print_check());
}
@@ -843,11 +769,11 @@ static void print_timestamp_long(void)
static void print_timestamp_short_no_fractions(void)
{
- el_option(EL_TS_FRACT, EL_TS_FRACT_OFF);
- el_option(EL_TS, EL_TS_SHORT);
- add_log(ELF, "first meaningless message");
- add_log(ELF, "second stupid log");
- mt_fok(print_check());
+ el_option(EL_TS_FRACT, EL_TS_FRACT_OFF);
+ el_option(EL_TS, EL_TS_SHORT);
+ add_log(ELF, "first meaningless message");
+ add_log(ELF, "second stupid log");
+ mt_fok(print_check());
}
@@ -857,11 +783,11 @@ static void print_timestamp_short_no_fractions(void)
static void print_timestamp_long_no_fractions(void)
{
- el_option(EL_TS_FRACT, EL_TS_FRACT_OFF);
- el_option(EL_TS, EL_TS_LONG);
- add_log(ELF, "they don't even care");
- add_log(ELF, "what I put in here");
- mt_fok(print_check());
+ el_option(EL_TS_FRACT, EL_TS_FRACT_OFF);
+ el_option(EL_TS, EL_TS_LONG);
+ add_log(ELF, "they don't even care");
+ add_log(ELF, "what I put in here");
+ mt_fok(print_check());
}
@@ -871,11 +797,11 @@ static void print_timestamp_long_no_fractions(void)
static void print_timestamp_short_fractions_ms(void)
{
- el_option(EL_TS_FRACT, EL_TS_FRACT_MS);
- el_option(EL_TS, EL_TS_SHORT);
- add_log(ELF, "first meaningless message");
- add_log(ELF, "second stupid log");
- mt_fok(print_check());
+ el_option(EL_TS_FRACT, EL_TS_FRACT_MS);
+ el_option(EL_TS, EL_TS_SHORT);
+ add_log(ELF, "first meaningless message");
+ add_log(ELF, "second stupid log");
+ mt_fok(print_check());
}
@@ -885,11 +811,11 @@ static void print_timestamp_short_fractions_ms(void)
static void print_timestamp_long_fractions_ms(void)
{
- el_option(EL_TS_FRACT, EL_TS_FRACT_MS);
- el_option(EL_TS, EL_TS_LONG);
- add_log(ELF, "they don't even care");
- add_log(ELF, "what I put in here");
- mt_fok(print_check());
+ el_option(EL_TS_FRACT, EL_TS_FRACT_MS);
+ el_option(EL_TS, EL_TS_LONG);
+ add_log(ELF, "they don't even care");
+ add_log(ELF, "what I put in here");
+ mt_fok(print_check());
}
@@ -899,11 +825,11 @@ static void print_timestamp_long_fractions_ms(void)
static void print_timestamp_short_fractions_us(void)
{
- el_option(EL_TS_FRACT, EL_TS_FRACT_US);
- el_option(EL_TS, EL_TS_SHORT);
- add_log(ELF, "first meaningless message");
- add_log(ELF, "second stupid log");
- mt_fok(print_check());
+ el_option(EL_TS_FRACT, EL_TS_FRACT_US);
+ el_option(EL_TS, EL_TS_SHORT);
+ add_log(ELF, "first meaningless message");
+ add_log(ELF, "second stupid log");
+ mt_fok(print_check());
}
@@ -913,11 +839,11 @@ static void print_timestamp_short_fractions_us(void)
static void print_timestamp_long_fractions_us(void)
{
- el_option(EL_TS_FRACT, EL_TS_FRACT_US);
- el_option(EL_TS, EL_TS_LONG);
- add_log(ELF, "they don't even care");
- add_log(ELF, "what I put in here");
- mt_fok(print_check());
+ el_option(EL_TS_FRACT, EL_TS_FRACT_US);
+ el_option(EL_TS, EL_TS_LONG);
+ add_log(ELF, "they don't even care");
+ add_log(ELF, "what I put in here");
+ mt_fok(print_check());
}
@@ -927,11 +853,11 @@ static void print_timestamp_long_fractions_us(void)
static void print_timestamp_short_fractions_ns(void)
{
- el_option(EL_TS_FRACT, EL_TS_FRACT_NS);
- el_option(EL_TS, EL_TS_SHORT);
- add_log(ELF, "first meaningless message");
- add_log(ELF, "second stupid log");
- mt_fok(print_check());
+ el_option(EL_TS_FRACT, EL_TS_FRACT_NS);
+ el_option(EL_TS, EL_TS_SHORT);
+ add_log(ELF, "first meaningless message");
+ add_log(ELF, "second stupid log");
+ mt_fok(print_check());
}
@@ -941,11 +867,11 @@ static void print_timestamp_short_fractions_ns(void)
static void print_timestamp_long_fractions_ns(void)
{
- el_option(EL_TS_FRACT, EL_TS_FRACT_NS);
- el_option(EL_TS, EL_TS_LONG);
- add_log(ELF, "they don't even care");
- add_log(ELF, "what I put in here");
- mt_fok(print_check());
+ el_option(EL_TS_FRACT, EL_TS_FRACT_NS);
+ el_option(EL_TS, EL_TS_LONG);
+ add_log(ELF, "they don't even care");
+ add_log(ELF, "what I put in here");
+ mt_fok(print_check());
}
@@ -955,10 +881,10 @@ static void print_timestamp_long_fractions_ns(void)
static void print_finfo(void)
{
- el_option(EL_FINFO, 1);
- add_log(ELF, "print_finfo first");
- add_log(ELF, "print_finfo second");
- mt_fok(print_check());
+ el_option(EL_FINFO, 1);
+ add_log(ELF, "print_finfo first");
+ add_log(ELF, "print_finfo second");
+ mt_fok(print_check());
}
@@ -970,74 +896,72 @@ static void print_finfo(void)
static void *print_t
(
- void *arg
+ void *arg
)
{
- int i;
- int n;
- char *m;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ int i;
+ int n;
+ char *m;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- n = *(int *)arg;
+ n = *(int *)arg;
- for (i = 0; i != prints_per_thread; ++i)
- {
- m = msgs[n][i];
- sprintf(m, "print_t [%d:%d]", n, i);
- add_log(ELF, m);
- }
+ for (i = 0; i != prints_per_thread; ++i)
+ {
+ m = msgs[n][i];
+ sprintf(m, "print_t [%d:%d]", n, i);
+ add_log(ELF, m);
+ }
- return NULL;
+ return NULL;
}
static void print_threaded(void)
{
- pthread_t pt[number_of_threads];
- int i, n[number_of_threads];
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- el_init();
-
- /* allocate memory that can hold all messages with full
- * pre information (timestamp, file info) and message of length
- * 31 characters
- */
-
- logbuf = calloc(1, number_of_messages *
- (EL_PRE_LEN + EL_COLORS_LEN + msg_size));
- expected_logs = rb_new(number_of_messages, sizeof(struct log_message), 0);
-
- el_option(EL_CUSTOM_PUTS, print_to_buffer, logbuf);
- el_option(EL_PRINT_LEVEL, 1);
- el_option(EL_TS, EL_TS_LONG);
- el_option(EL_TS_TM, EL_TS_TM_REALTIME);
- el_option(EL_TS_FRACT, EL_TS_FRACT_US);
- el_option(EL_FINFO, 1);
- el_option(EL_FUNCINFO, 1);
- el_option(EL_COLORS, 1);
- el_option(EL_PREFIX, "thread-test");
- el_option(EL_OUT, EL_OUT_CUSTOM);
- el_option(EL_LEVEL, EL_DBG);
- el_option(EL_THREAD_SAFE, 1);
-
- for (i = 0; i != number_of_threads; ++i)
- {
- n[i] = i;
- pthread_create(&pt[i], NULL, print_t, &n[i]);
- }
-
- for (i = 0; i != number_of_threads; ++i)
- {
- pthread_join(pt[i], NULL);
- }
-
- mt_fok(print_check());
- rb_destroy(expected_logs);
- free(logbuf);
-
- el_cleanup();
+ pthread_t pt[number_of_threads];
+ int i, n[number_of_threads];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ el_init();
+
+ /* allocate memory that can hold all messages with full
+ * pre information (timestamp, file info) and message of length
+ * 31 characters
+ */
+
+ logbuf = calloc(1, number_of_messages *
+ (EL_PRE_LEN + EL_COLORS_LEN + msg_size));
+ expected_logs = rb_new(number_of_messages, sizeof(struct log_message), 0);
+
+ el_option(EL_CUSTOM_PUTS, print_to_buffer, logbuf);
+ el_option(EL_PRINT_LEVEL, 1);
+ el_option(EL_TS, EL_TS_LONG);
+ el_option(EL_TS_TM, EL_TS_TM_REALTIME);
+ el_option(EL_TS_FRACT, EL_TS_FRACT_US);
+ el_option(EL_FINFO, 1);
+ el_option(EL_FUNCINFO, 1);
+ el_option(EL_COLORS, 1);
+ el_option(EL_PREFIX, "thread-test");
+ el_option(EL_OUT, EL_OUT_CUSTOM);
+ el_option(EL_LEVEL, EL_DBG);
+ el_option(EL_THREAD_SAFE, 1);
+
+ for (i = 0; i != number_of_threads; ++i)
+ {
+ n[i] = i;
+ pthread_create(&pt[i], NULL, print_t, &n[i]);
+ }
+
+ for (i = 0; i != number_of_threads; ++i)
+ pthread_join(pt[i], NULL);
+
+ mt_fok(print_check());
+ rb_destroy(expected_logs);
+ free(logbuf);
+
+ el_cleanup();
}
#endif /* ENABLE_PTHREAD */
@@ -1049,19 +973,19 @@ static void print_threaded(void)
static void print_different_clocks(void)
{
- int i;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- for (i = EL_TS_TM_CLOCK; i != EL_TS_TM_ERROR; ++i)
- {
- test_prepare();
- el_option(EL_TS_TM, i);
- el_option(EL_TS, EL_TS_LONG);
- add_log(ELI, "clock test");
- mt_fok(print_check());
- test_cleanup();
- }
+ int i;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ for (i = EL_TS_TM_CLOCK; i != EL_TS_TM_ERROR; ++i)
+ {
+ test_prepare();
+ el_option(EL_TS_TM, i);
+ el_option(EL_TS, EL_TS_LONG);
+ add_log(ELI, "clock test");
+ mt_fok(print_check());
+ test_cleanup();
+ }
}
@@ -1071,66 +995,66 @@ static void print_different_clocks(void)
static void print_mix_of_everything_check(void)
{
- mt_fok(print_check());
+ mt_fok(print_check());
}
static void print_mix_of_everything(void)
{
- int level;
- int ts;
- int printlevel;
- int finfo;
- int funcinfo;
- int colors;
- int prefix;
- int ts_fract;
- int nl;
- int ts_tm;
- char tname[512];
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- for (level = 0; level <= EL_DBG; ++level)
- for (colors = 0; colors <= 1; ++colors)
- for (ts = 0; ts != EL_TS_ERROR; ++ts)
- for (ts_tm = 0; ts_tm <= EL_TS_TM_ERROR; ++ts_tm)
- for (ts_fract = 0; ts_fract != EL_TS_FRACT_ERROR; ++ts_fract)
- for (printlevel = 0; printlevel <= 1; ++printlevel)
- for (nl = 0; nl <= 1; ++nl)
- for (finfo = 0; finfo <= 1; ++finfo)
- for (funcinfo = 0; funcinfo <= 1; ++funcinfo)
- for (prefix = 0; prefix <= 1; ++prefix)
- {
- test_prepare();
- el_option(EL_LEVEL, level);
- el_option(EL_COLORS, colors);
- el_option(EL_TS, ts);
- el_option(EL_TS_TM, ts_tm);
- el_option(EL_TS_FRACT, ts_fract);
- el_option(EL_PRINT_LEVEL, printlevel);
- el_option(EL_PRINT_NL, nl);
- el_option(EL_FINFO, finfo);
- el_option(EL_FUNCINFO, funcinfo);
- el_option(EL_PREFIX, prefix ? "prefix" : NULL);
-
- add_log(ELF, "fatal message");
- add_log(ELA, "alert message");
- add_log(ELC, "critical message");
- add_log(ELE, "error message");
- add_log(ELW, "warning message");
- add_log(ELN, "notice message");
- add_log(ELI, "info message");
- add_log(ELD, "debug message");
-
- sprintf(tname, "print_mix_of_everything: level: %d, colors: %d, "
- "ts: %d, ts_tm: %d, ts_fract: %d, print_level: %d, "
- "nl: %d, finfo: %d, funcinfo: %d, prefix: %d",
- level, colors, ts, ts_tm, ts_fract, printlevel, nl,
- finfo, funcinfo, prefix);
- mt_run_named(print_mix_of_everything_check, tname);
-
- test_cleanup();
- }
+ int level;
+ int ts;
+ int printlevel;
+ int finfo;
+ int funcinfo;
+ int colors;
+ int prefix;
+ int ts_fract;
+ int nl;
+ int ts_tm;
+ char tname[512];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ for (level = 0; level <= EL_DBG; ++level)
+ for (colors = 0; colors <= 1; ++colors)
+ for (ts = 0; ts != EL_TS_ERROR; ++ts)
+ for (ts_tm = 0; ts_tm <= EL_TS_TM_ERROR; ++ts_tm)
+ for (ts_fract = 0; ts_fract != EL_TS_FRACT_ERROR; ++ts_fract)
+ for (printlevel = 0; printlevel <= 1; ++printlevel)
+ for (nl = 0; nl <= 1; ++nl)
+ for (finfo = 0; finfo <= 1; ++finfo)
+ for (funcinfo = 0; funcinfo <= 1; ++funcinfo)
+ for (prefix = 0; prefix <= 1; ++prefix)
+ {
+ test_prepare();
+ el_option(EL_LEVEL, level);
+ el_option(EL_COLORS, colors);
+ el_option(EL_TS, ts);
+ el_option(EL_TS_TM, ts_tm);
+ el_option(EL_TS_FRACT, ts_fract);
+ el_option(EL_PRINT_LEVEL, printlevel);
+ el_option(EL_PRINT_NL, nl);
+ el_option(EL_FINFO, finfo);
+ el_option(EL_FUNCINFO, funcinfo);
+ el_option(EL_PREFIX, prefix ? "prefix" : NULL);
+
+ add_log(ELF, "fatal message");
+ add_log(ELA, "alert message");
+ add_log(ELC, "critical message");
+ add_log(ELE, "error message");
+ add_log(ELW, "warning message");
+ add_log(ELN, "notice message");
+ add_log(ELI, "info message");
+ add_log(ELD, "debug message");
+
+ sprintf(tname, "print_mix_of_everything: level: %d, colors: %d, "
+ "ts: %d, ts_tm: %d, ts_fract: %d, print_level: %d, "
+ "nl: %d, finfo: %d, funcinfo: %d, prefix: %d",
+ level, colors, ts, ts_tm, ts_fract, printlevel, nl,
+ finfo, funcinfo, prefix);
+ mt_run_named(print_mix_of_everything_check, tname);
+
+ test_cleanup();
+ }
}
@@ -1140,30 +1064,29 @@ static void print_mix_of_everything(void)
static void print_too_long_print_truncate(void)
{
- char msg[EL_LOG_MAX + 3];
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ char msg[EL_LOG_MAX + 3];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- memset(msg, 'a', sizeof(msg));
- msg[sizeof(msg) - 1] = '\0';
- msg[sizeof(msg) - 2] = '3';
- msg[sizeof(msg) - 3] = '2';
- msg[sizeof(msg) - 4] = '1';
- msg[sizeof(msg) - 5] = '0';
+ memset(msg, 'a', sizeof(msg));
+ msg[sizeof(msg) - 1] = '\0';
+ msg[sizeof(msg) - 2] = '3';
+ msg[sizeof(msg) - 3] = '2';
+ msg[sizeof(msg) - 4] = '1';
+ msg[sizeof(msg) - 5] = '0';
- add_log(ELI, "not truncated");
- add_log(ELI, msg);
+ add_log(ELI, "not truncated");
+ add_log(ELI, msg);
- /* while el_print will make copy of msg, our test print_check
- * function will just use pointer to our msg here, and since we
- * expect message to be truncated, we truncate it here and
- * print_check will take this truncated message as expected
- * one.
- */
+ /* while el_print will make copy of msg, our test print_check
+ * function will just use pointer to our msg here, and since we
+ * expect message to be truncated, we truncate it here and
+ * print_check will take this truncated message as expected
+ * one. */
- msg[sizeof(msg) - 3] = '\0';
+ msg[sizeof(msg) - 3] = '\0';
- mt_fok(print_check());
+ mt_fok(print_check());
}
@@ -1173,31 +1096,30 @@ static void print_too_long_print_truncate(void)
static void print_too_long_print_truncate_no_newline(void)
{
- char msg[EL_LOG_MAX + 3];
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ char msg[EL_LOG_MAX + 3];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- el_option(EL_PRINT_NL, 0);
- memset(msg, 'a', sizeof(msg));
- msg[sizeof(msg) - 1] = '\0';
- msg[sizeof(msg) - 2] = '3';
- msg[sizeof(msg) - 3] = '2';
- msg[sizeof(msg) - 4] = '1';
- msg[sizeof(msg) - 5] = '0';
+ el_option(EL_PRINT_NL, 0);
+ memset(msg, 'a', sizeof(msg));
+ msg[sizeof(msg) - 1] = '\0';
+ msg[sizeof(msg) - 2] = '3';
+ msg[sizeof(msg) - 3] = '2';
+ msg[sizeof(msg) - 4] = '1';
+ msg[sizeof(msg) - 5] = '0';
- add_log(ELI, "not truncated");
- add_log(ELI, msg);
+ add_log(ELI, "not truncated");
+ add_log(ELI, msg);
- /* while el_print will make copy of msg, our test print_check
- * function will just use pointer to our msg here, and since we
- * expect message to be truncated, we truncate it here and
- * print_check will take this truncated message as expected
- * one.
- */
+ /* while el_print will make copy of msg, our test print_check
+ * function will just use pointer to our msg here, and since we
+ * expect message to be truncated, we truncate it here and
+ * print_check will take this truncated message as expected
+ * one. */
- msg[sizeof(msg) - 3] = '\0';
+ msg[sizeof(msg) - 3] = '\0';
- mt_fok(print_check());
+ mt_fok(print_check());
}
@@ -1207,24 +1129,24 @@ static void print_too_long_print_truncate_no_newline(void)
static void print_truncate_with_date(void)
{
- char msg[EL_LOG_MAX + 3];
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+ char msg[EL_LOG_MAX + 3];
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
- el_option(EL_TS, EL_TS_LONG);
- memset(msg, 'a', sizeof(msg));
- msg[sizeof(msg) - 1] = '\0';
- msg[sizeof(msg) - 2] = '3';
- msg[sizeof(msg) - 3] = '2';
- msg[sizeof(msg) - 4] = '1';
- msg[sizeof(msg) - 4] = '0';
+ el_option(EL_TS, EL_TS_LONG);
+ memset(msg, 'a', sizeof(msg));
+ msg[sizeof(msg) - 1] = '\0';
+ msg[sizeof(msg) - 2] = '3';
+ msg[sizeof(msg) - 3] = '2';
+ msg[sizeof(msg) - 4] = '1';
+ msg[sizeof(msg) - 4] = '0';
- add_log(ELI, "not truncated");
- add_log(ELI, msg);
+ add_log(ELI, "not truncated");
+ add_log(ELI, msg);
- msg[sizeof(msg) - 3] = '\0';
+ msg[sizeof(msg) - 3] = '\0';
- mt_fok(print_check());
+ mt_fok(print_check());
}
@@ -1234,43 +1156,43 @@ static void print_truncate_with_date(void)
static void print_truncate_with_all_options(void)
{
- char msg[EL_LOG_MAX + 3];
- char finfo[EL_FLEN_MAX + 3];
- char funcinfo[EL_FUNCLEN_MAX + 3];
- char prefix[EL_PREFIX_MAX + 3];
- size_t fline;
- /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
-
-
- el_option(EL_TS, EL_TS_LONG);
- el_option(EL_TS_FRACT, EL_TS_FRACT_NS);
- el_option(EL_TS_TM, EL_TS_TM_REALTIME);
- el_option(EL_FINFO, 1);
- el_option(EL_FUNCINFO, 1);
- el_option(EL_COLORS, 1);
- el_option(EL_PREFIX, prefix);
- el_option(EL_PRINT_LEVEL, 1);
- memset(msg, 'a', sizeof(msg));
- memset(finfo, 'b', sizeof(finfo));
- memset(prefix, 'c', sizeof(prefix));
- memset(funcinfo, 'f', sizeof(funcinfo));
- finfo[sizeof(finfo) - 1] = '\0';
- prefix[sizeof(prefix) - 1] = '\0';
- funcinfo[sizeof(funcinfo) - 1] = '\0';
- fline = (size_t)pow(10, EL_PRE_FINFO_LINE_MAX_LEN + 2) - 1;
- msg[sizeof(msg) - 1] = '\0';
- msg[sizeof(msg) - 2] = '3';
- msg[sizeof(msg) - 3] = '2';
- msg[sizeof(msg) - 4] = '1';
- msg[sizeof(msg) - 4] = '0';
-
- add_log(ELI, "not truncated");
- add_log(finfo, fline, funcinfo, EL_FATAL, msg);
-
- msg[sizeof(msg) - 3] = '\0';
- puts(logbuf);
-
- mt_fok(print_check());
+ char msg[EL_LOG_MAX + 3];
+ char finfo[EL_FLEN_MAX + 3];
+ char funcinfo[EL_FUNCLEN_MAX + 3];
+ char prefix[EL_PREFIX_MAX + 3];
+ size_t fline;
+ /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
+
+
+ el_option(EL_TS, EL_TS_LONG);
+ el_option(EL_TS_FRACT, EL_TS_FRACT_NS);
+ el_option(EL_TS_TM, EL_TS_TM_REALTIME);
+ el_option(EL_FINFO, 1);
+ el_option(EL_FUNCINFO, 1);
+ el_option(EL_COLORS, 1);
+ el_option(EL_PREFIX, prefix);
+ el_option(EL_PRINT_LEVEL, 1);
+ memset(msg, 'a', sizeof(msg));
+ memset(finfo, 'b', sizeof(finfo));
+ memset(prefix, 'c', sizeof(prefix));
+ memset(funcinfo, 'f', sizeof(funcinfo));
+ finfo[sizeof(finfo) - 1] = '\0';
+ prefix[sizeof(prefix) - 1] = '\0';
+ funcinfo[sizeof(funcinfo) - 1] = '\0';
+ fline = (size_t)pow(10, EL_PRE_FINFO_LINE_MAX_LEN + 2) - 1;
+ msg[sizeof(msg) - 1] = '\0';
+ msg[sizeof(msg) - 2] = '3';
+ msg[sizeof(msg) - 3] = '2';
+ msg[sizeof(msg) - 4] = '1';
+ msg[sizeof(msg) - 4] = '0';
+
+ add_log(ELI, "not truncated");
+ add_log(finfo, fline, funcinfo, EL_FATAL, msg);
+
+ msg[sizeof(msg) - 3] = '\0';
+ puts(logbuf);
+
+ mt_fok(print_check());
}
@@ -1280,8 +1202,8 @@ static void print_truncate_with_all_options(void)
static void print_with_no_output_available(void)
{
- el_option(EL_OUT, EL_OUT_NONE);
- mt_ferr(el_print(ELI, "i'll be back"), ENODEV);
+ el_option(EL_OUT, EL_OUT_NONE);
+ mt_ferr(el_print(ELI, "i'll be back"), ENODEV);
}
@@ -1291,7 +1213,7 @@ static void print_with_no_output_available(void)
static void print_level_not_high_enough(void)
{
- mt_ferr(el_print(ELD, "i won't be printed"), ERANGE);
+ mt_ferr(el_print(ELD, "i won't be printed"), ERANGE);
}
@@ -1301,10 +1223,10 @@ static void print_level_not_high_enough(void)
static void print_finfo_path(void)
{
- el_option(EL_FINFO, 1);
- add_log("source/code/file.c", 10, "print_finfo_path", EL_ALERT,
- "some message");
- mt_fok(print_check());
+ el_option(EL_FINFO, 1);
+ add_log("source/code/file.c", 10, "print_finfo_path", EL_ALERT,
+ "some message");
+ mt_fok(print_check());
}
@@ -1314,9 +1236,9 @@ static void print_finfo_path(void)
static void print_nofinfo(void)
{
- el_option(EL_FINFO, 1);
- add_log(NULL, 0, NULL, EL_ALERT, "no file info");
- mt_fok(print_check());
+ el_option(EL_FINFO, 1);
+ add_log(NULL, 0, NULL, EL_ALERT, "no file info");
+ mt_fok(print_check());
}
@@ -1326,7 +1248,7 @@ static void print_nofinfo(void)
static void print_null(void)
{
- mt_ferr(el_print(ELA, NULL), EINVAL);
+ mt_ferr(el_print(ELA, NULL), EINVAL);
}
@@ -1336,9 +1258,9 @@ static void print_null(void)
static void print_prefix(void)
{
- el_option(EL_PREFIX, "prefix");
- add_log(ELI, "message with prefix");
- mt_fok(print_check());
+ el_option(EL_PREFIX, "prefix");
+ add_log(ELI, "message with prefix");
+ mt_fok(print_check());
}
@@ -1348,17 +1270,15 @@ static void print_prefix(void)
static void print_prefix_full(void)
{
- char p[EL_PREFIX_LEN + 1] = {0};
- int i;
+ char p[EL_PREFIX_LEN + 1] = {0};
+ int i;
- for (i = 0; i != EL_PREFIX_LEN; ++i)
- {
- p[i] = '0' + (i % 32);
- }
+ for (i = 0; i != EL_PREFIX_LEN; ++i)
+ p[i] = '0' + (i % 32);
- el_option(EL_PREFIX, p);
- add_log(ELI, "message with fill prefix");
- mt_fok(print_check());
+ el_option(EL_PREFIX, p);
+ add_log(ELI, "message with fill prefix");
+ mt_fok(print_check());
}
@@ -1368,17 +1288,15 @@ static void print_prefix_full(void)
static void print_prefix_overflow(void)
{
- char p[EL_PREFIX_LEN + 10] = {0};
- int i;
+ char p[EL_PREFIX_LEN + 10] = {0};
+ int i;
- for (i = 0; i != sizeof(p) - 1; ++i)
- {
- p[i] = '0' + (i % 32);
- }
+ for (i = 0; i != sizeof(p) - 1; ++i)
+ p[i] = '0' + (i % 32);
- el_option(EL_PREFIX, p);
- add_log(ELI, "message with overflown prefix");
- mt_fok(print_check());
+ el_option(EL_PREFIX, p);
+ add_log(ELI, "message with overflown prefix");
+ mt_fok(print_check());
}
@@ -1395,44 +1313,44 @@ static void print_prefix_overflow(void)
void el_print_test_group(void)
{
#if ENABLE_PTHREAD
- thread_test = 1;
- mt_run(print_threaded);
- thread_test = 0;
+ thread_test = 1;
+ mt_run(print_threaded);
+ thread_test = 0;
#endif
- mt_run(print_different_clocks);
- print_mix_of_everything();
-
- mt_prepare_test = &test_prepare;
- mt_cleanup_test = &test_cleanup;
-
- mt_run(print_simple_message);
- mt_run(print_simple_message_no_newline);
- mt_run(print_simple_multiple_message);
- mt_run(print_log_level);
- mt_run(print_colorful_output);
- mt_run(print_custom_log_level);
- mt_run(print_timestamp_short);
- mt_run(print_timestamp_long);
- mt_run(print_timestamp_short_no_fractions);
- mt_run(print_timestamp_long_no_fractions);
- mt_run(print_timestamp_short_fractions_ms);
- mt_run(print_timestamp_long_fractions_ms);
- mt_run(print_timestamp_short_fractions_us);
- mt_run(print_timestamp_long_fractions_us);
- mt_run(print_timestamp_short_fractions_ns);
- mt_run(print_timestamp_long_fractions_ns);
- mt_run(print_finfo);
- mt_run(print_too_long_print_truncate);
- mt_run(print_too_long_print_truncate_no_newline);
- mt_run(print_truncate_with_date);
- mt_run(print_truncate_with_all_options);
- mt_run(print_with_no_output_available);
- mt_run(print_level_not_high_enough);
- mt_run(print_finfo_path);
- mt_run(print_nofinfo);
- mt_run(print_null);
- mt_run(print_prefix);
- mt_run(print_prefix_full);
- mt_run(print_prefix_overflow);
+ mt_run(print_different_clocks);
+ print_mix_of_everything();
+
+ mt_prepare_test = &test_prepare;
+ mt_cleanup_test = &test_cleanup;
+
+ mt_run(print_simple_message);
+ mt_run(print_simple_message_no_newline);
+ mt_run(print_simple_multiple_message);
+ mt_run(print_log_level);
+ mt_run(print_colorful_output);
+ mt_run(print_custom_log_level);
+ mt_run(print_timestamp_short);
+ mt_run(print_timestamp_long);
+ mt_run(print_timestamp_short_no_fractions);
+ mt_run(print_timestamp_long_no_fractions);
+ mt_run(print_timestamp_short_fractions_ms);
+ mt_run(print_timestamp_long_fractions_ms);
+ mt_run(print_timestamp_short_fractions_us);
+ mt_run(print_timestamp_long_fractions_us);
+ mt_run(print_timestamp_short_fractions_ns);
+ mt_run(print_timestamp_long_fractions_ns);
+ mt_run(print_finfo);
+ mt_run(print_too_long_print_truncate);
+ mt_run(print_too_long_print_truncate_no_newline);
+ mt_run(print_truncate_with_date);
+ mt_run(print_truncate_with_all_options);
+ mt_run(print_with_no_output_available);
+ mt_run(print_level_not_high_enough);
+ mt_run(print_finfo_path);
+ mt_run(print_nofinfo);
+ mt_run(print_null);
+ mt_run(print_prefix);
+ mt_run(print_prefix_full);
+ mt_run(print_prefix_overflow);
}