Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions docs/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,18 @@ noinst_HEADERS = mainpage.h
dist_man_MANS = man8/qb-blackbox.8
if HAVE_DOXYGEN
inc_dir = $(top_srcdir)/include/qb
dependant_headers = $(wildcard $(inc_dir)/qb*.h)
dist_man_MANS += man3/qbipcc.h.3 man3/qbipcs.h.3 man3/qbatomic.h.3 \
man3/qbhdb.h.3 man3/qbipc_common.h.3 man3/qblist.h.3 \
man3/qbloop.h.3 man3/qbutil.h.3 man3/qbarray.h.3 \
man3/qblog.h.3 man3/qbmap.h.3

dependent_headers = $(subst $(inc_dir),,$(shell \
printf 'include $(inc_dir)/Makefile.am\n\n%%.var:\n\t@echo $$($$*)' \
| ${MAKE} --no-print-directory -f - inst_HEADERS.var \
|| echo $(inc_dir)/qb*.h))
dependent_headers_omit = qbconfig.h

$(dist_man_MANS): man.dox $(dependant_headers)
dist_man_MANS += $(patsubst %,man3/%.3,$(filter-out \
$(dependent_headers_omit),$(dependent_headers) \
))

$(dist_man_MANS): man.dox $(dependent_headers:%=$(inc_dir)/%)
mkdir -p man3
doxygen man.dox

Expand Down
7 changes: 4 additions & 3 deletions lib/log_format.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,11 @@ qb_log_target_format_static(int32_t target, const char * format,
break;

case 'H':
if (gethostname(tmp_buf, 255) == 0) {
tmp_buf[254] = '\0';
if (gethostname(tmp_buf, sizeof(tmp_buf)) == 0) {
tmp_buf[sizeof(tmp_buf) - 1] = '\0';
} else {
(void)strlcpy(tmp_buf, "localhost", 255);
(void)strlcpy(tmp_buf, "localhost",
sizeof(tmp_buf));
}
p = tmp_buf;
break;
Expand Down
13 changes: 9 additions & 4 deletions tests/check_log.c
Original file line number Diff line number Diff line change
Expand Up @@ -450,8 +450,10 @@ static const char *_test_tags_stringify(uint32_t tags)
START_TEST(test_log_format)
{
int32_t t;
char cmp_str[256];
/* following size/length related equation holds in the context of use:
strlen(cmp_str) = strlen(host_str) + X; X ~ 20 < sizeof(host_str) */
char host_str[256];
char cmp_str[2 * sizeof(host_str)];

qb_log_init("test", LOG_USER, LOG_DEBUG);
qb_log_ctl(QB_LOG_SYSLOG, QB_LOG_CONF_ENABLED, QB_FALSE);
Expand Down Expand Up @@ -498,16 +500,19 @@ START_TEST(test_log_format)

qb_log_tags_stringify_fn_set(NULL);

gethostname(host_str, 256);
gethostname(host_str, sizeof(host_str));
host_str[sizeof(host_str) - 1] = '\0';

qb_log_format_set(t, "%P %H %N %b");
qb_log(LOG_INFO, "Angus");
snprintf(cmp_str, 256, "%d %s test Angus", getpid(), host_str);
snprintf(cmp_str, sizeof(cmp_str), "%d %s test Angus", getpid(),
host_str);
ck_assert_str_eq(test_buf, cmp_str);

qb_log_format_set(t, "%3N %H %P %b");
qb_log(LOG_INFO, "Angus");
snprintf(cmp_str, 256, "tes %s %d Angus", host_str, getpid());
snprintf(cmp_str, sizeof(cmp_str), "tes %s %d Angus", host_str,
getpid());
ck_assert_str_eq(test_buf, cmp_str);
}
END_TEST
Expand Down