Proposal to patch qblist.h
by Виноградов Василий
Linux kernel provides some helpful macros for iterating over lists. We had included 2 of them in qblist.h to use libqb in our projects. So we submit you the following patch to make quarterback lists more attractive not only for us:
diff -Naur libqb-orig/include/qb/qblist.h libqb/include/qb/qblist.h
--- libqb-orig/include/qb/qblist.h 2011-05-26 13:29:07.000000000 +0400
+++ libqb/include/qb/qblist.h 2011-05-26 13:48:25.000000000 +0400
@@ -197,6 +197,32 @@
pos = qb_list_entry(pos->member.prev, typeof(*pos), member))
/**
+ * Iterate over list of given type safe against removal of list entry
+ * @param pos: the type * to use as a loop cursor.
+ * @param n: another type * to use as temporary storage
+ * @param head: the head for your list.
+ * @param member: the name of the list_struct within the struct.
+ */
+#define qb_list_for_each_entry_safe(pos, n, head, member) \
+ for (pos = qb_list_entry((head)->next, typeof(*pos), member), \
+ n = qb_list_entry(pos->member.next, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, n = qb_list_entry(n->member.next, typeof(*n), member))
+
+/**
+ * Iterate backwards over list safe against removal
+ * @param pos: the type * to use as a loop cursor.
+ * @param n: another type * to use as temporary storage
+ * @param head: the head for your list.
+ * @param member: the name of the list_struct within the struct.
+ */
+#define qb_list_for_each_entry_safe_reverse(pos, n, head, member) \
+ for (pos = qb_list_entry((head)->prev, typeof(*pos), member), \
+ n = qb_list_entry(pos->member.prev, typeof(*pos), member); \
+ &pos->member != (head); \
+ pos = n, n = qb_list_entry(n->member.prev, typeof(*n), member))
+
+/**
* Count the number of items in the list.
* @param head: the head for your list.
* @return length of the list.
12 years, 10 months
[PATCH 1/2] TEST: make sure make-log-test appends a bracket
by Angus Salkeld
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
tests/make-log-test | 1 +
1 files changed, 1 insertions(+), 0 deletions(-)
diff --git a/tests/make-log-test b/tests/make-log-test
index 8cf1a54..0dba275 100755
--- a/tests/make-log-test
+++ b/tests/make-log-test
@@ -30,4 +30,5 @@ do
fi
done < /usr/share/dict/words
+echo "}"
--
1.7.5.1
12 years, 10 months
[PATCH] qb_rb_write_to_file clean-up
by Jim Meyering
* lib/ringbuffer.c (qb_rb_write_to_file): Remove dead initialization
and redundant "result < 0" tests.
---
Since the following tests already treat any returned size that
is not equal to sizeof(...) as an error, adding the weaker
"result < 0" disjunct has no effect. So I removed them.
I also removed the so-called "dead" initialization of "result",
since an analyzer like clang would warn about it.
lib/ringbuffer.c | 13 ++++++-------
1 files changed, 6 insertions(+), 7 deletions(-)
diff --git a/lib/ringbuffer.c b/lib/ringbuffer.c
index ea76300..7004369 100644
--- a/lib/ringbuffer.c
+++ b/lib/ringbuffer.c
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2010 Red Hat, Inc.
+ * Copyright (C) 2010-2011 Red Hat, Inc.
*
* Author: Angus Salkeld <asalkeld(a)redhat.com>
*
@@ -518,21 +518,20 @@ static void qb_rb_chunk_check(qb_ringbuffer_t * rb, uint32_t pointer)
ssize_t qb_rb_write_to_file(qb_ringbuffer_t * rb, int32_t fd)
{
- ssize_t result = 0;
+ ssize_t result;
ssize_t written_size = 0;
print_header(rb);
result = write(fd, &rb->shared_hdr->size, sizeof(uint32_t));
- if ((result < 0) || (result != sizeof(uint32_t))) {
+ if (result != sizeof(uint32_t)) {
return -errno;
}
written_size += result;
result = write(fd, rb->shared_data,
rb->shared_hdr->size * sizeof(uint32_t));
- if ((result < 0)
- || (result != rb->shared_hdr->size * sizeof(uint32_t))) {
+ if (result != rb->shared_hdr->size * sizeof(uint32_t)) {
return -errno;
}
written_size += result;
@@ -541,12 +540,12 @@ ssize_t qb_rb_write_to_file(qb_ringbuffer_t * rb, int32_t fd)
* store the read & write pointers
*/
result = write(fd, (void *)&rb->shared_hdr->write_pt, sizeof(uint32_t));
- if ((result < 0) || (result != sizeof(uint32_t))) {
+ if (result != sizeof(uint32_t)) {
return -errno;
}
written_size += result;
result = write(fd, (void *)&rb->shared_hdr->read_pt, sizeof(uint32_t));
- if ((result < 0) || (result != sizeof(uint32_t))) {
+ if (result != sizeof(uint32_t)) {
return -errno;
}
written_size += result;
--
1.7.5.2.1.g56b30
12 years, 10 months
[PATCH] adjust .gitignore so "git status" ignores all build artifacts
by Jim Meyering
---
Without this, "git status" after a build
would point out some build artifacts.
I also sorted tests/.gitignore.
.gitignore | 1 +
tests/.gitignore | 9 +++++++--
2 files changed, 8 insertions(+), 2 deletions(-)
diff --git a/.gitignore b/.gitignore
index c7e6fb6..6d212db 100644
--- a/.gitignore
+++ b/.gitignore
@@ -33,3 +33,4 @@ lib/run_splint.sh
.version
.tarball-version
libqb.spec
+include/qb/stamp-h2
diff --git a/tests/.gitignore b/tests/.gitignore
index aa81bbd..cc0533b 100644
--- a/tests/.gitignore
+++ b/tests/.gitignore
@@ -1,10 +1,15 @@
*.test
+bench-log
bmc
bmcpt
bms
+check_array
+check_ipc
+check_log
+check_loop
+check_rb
+loop
rbreader
rbwriter
-loop
simple-log
-bench-log
write_logs.c
--
1.7.5.2.1.g56b30
12 years, 10 months
[PATCH] use latest git-version-gen from gnulib
by Jim Meyering
---
I noticed that you're using git-version-gen,
the master version of which is provided by gnulib,
yet minus a bug fix or two. This updates it.
The second change-set
build-aux/git-version-gen | 73 ++++++++++++++++++++++++++-------------------
1 files changed, 42 insertions(+), 31 deletions(-)
diff --git a/build-aux/git-version-gen b/build-aux/git-version-gen
index 795a98b..686f703 100755
--- a/build-aux/git-version-gen
+++ b/build-aux/git-version-gen
@@ -1,8 +1,8 @@
#!/bin/sh
# Print a version string.
-scriptversion=2010-10-13.20; # UTC
+scriptversion=2011-02-19.19; # UTC
-# Copyright (C) 2007-2010 Free Software Foundation, Inc.
+# Copyright (C) 2007-2011 Free Software Foundation, Inc.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -80,19 +80,20 @@ nl='
# Avoid meddling by environment variable of the same name.
v=
+v_from_git=
# First see if there is a tarball-only version file.
# then try "git describe", then default.
if test -f $tarball_version_file
then
- v=`cat $tarball_version_file` || exit 1
+ v=`cat $tarball_version_file` || v=
case $v in
- *$nl*) v= ;; # reject multi-line output
- [0-9]*) ;;
- *) v= ;;
+ *$nl*) v= ;; # reject multi-line output
+ [0-9]*) ;;
+ *) v= ;;
esac
test -z "$v" \
- && echo "$0: WARNING: $tarball_version_file seems to be damaged" 1>&2
+ && echo "$0: WARNING: $tarball_version_file is missing or damaged" 1>&2
fi
if test -n "$v"
@@ -103,11 +104,11 @@ then
# derive a version string.
elif test "`git log -1 --pretty=format:x . 2>&1`" = x \
&& v=`git describe --abbrev=4 --match='v*' HEAD 2>/dev/null \
- || git describe --abbrev=4 HEAD 2>/dev/null` \
+ || git describe --abbrev=4 HEAD 2>/dev/null` \
&& v=`printf '%s\n' "$v" | sed "$tag_sed_script"` \
&& case $v in
- v[0-9]*) ;;
- *) (exit 1) ;;
+ v[0-9]*) ;;
+ *) (exit 1) ;;
esac
then
# Is this a new git that lists number of commits since the last
@@ -115,39 +116,49 @@ then
# Newer: v6.10-77-g0f8faeb
# Older: v6.10-g0f8faeb
case $v in
- *-*-*) : git describe is okay three part flavor ;;
- *-*)
- : git describe is older two part flavor
- # Recreate the number of commits and rewrite such that the
- # result is the same as if we were using the newer version
- # of git describe.
- vtag=`echo "$v" | sed 's/-.*//'`
- numcommits=`git rev-list "$vtag"..HEAD | wc -l`
- v=`echo "$v" | sed "s/\(.*\)-\(.*\)/\1-$numcommits-\2/"`;
- ;;
+ *-*-*) : git describe is okay three part flavor ;;
+ *-*)
+ : git describe is older two part flavor
+ # Recreate the number of commits and rewrite such that the
+ # result is the same as if we were using the newer version
+ # of git describe.
+ vtag=`echo "$v" | sed 's/-.*//'`
+ commit_list=`git rev-list "$vtag"..HEAD 2>/dev/null` \
+ || { commit_list=failed;
+ echo "$0: WARNING: git rev-list failed" 1>&2; }
+ numcommits=`echo "$commit_list" | wc -l`
+ v=`echo "$v" | sed "s/\(.*\)-\(.*\)/\1-$numcommits-\2/"`;
+ test "$commit_list" = failed && v=UNKNOWN
+ ;;
esac
# Change the first '-' to a '.', so version-comparing tools work properly.
# Remove the "g" in git describe's output string, to save a byte.
v=`echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/'`;
+ v_from_git=1
else
v=UNKNOWN
fi
v=`echo "$v" |sed 's/^v//'`
-# Don't declare a version "dirty" merely because a time stamp has changed.
-git update-index --refresh > /dev/null 2>&1
+# Test whether to append the "-dirty" suffix only if the version
+# string we're using came from git. I.e., skip the test if it's "UNKNOWN"
+# or if it came from .tarball-version.
+if test -n "$v_from_git"; then
+ # Don't declare a version "dirty" merely because a time stamp has changed.
+ git update-index --refresh > /dev/null 2>&1
-dirty=`sh -c 'git diff-index --name-only HEAD' 2>/dev/null` || dirty=
-case "$dirty" in
- '') ;;
- *) # Append the suffix only if there isn't one already.
- case $v in
- *-dirty) ;;
- *) v="$v-dirty" ;;
- esac ;;
-esac
+ dirty=`exec 2>/dev/null;git diff-index --name-only HEAD` || dirty=
+ case "$dirty" in
+ '') ;;
+ *) # Append the suffix only if there isn't one already.
+ case $v in
+ *-dirty) ;;
+ *) v="$v-dirty" ;;
+ esac ;;
+ esac
+fi
# Omit the trailing newline, so that m4_esyscmd can use the result directly.
echo "$v" | tr -d "$nl"
--
1.7.5.2.1.g56b30
12 years, 10 months
"make check" on f14 during "make check"
by Angus Salkeld
Hi
Some of you have noticed that "make rpm" fails on Fedora 14 during
the "make check" (This is only in master).
rpm building adds the following compiler flags:
-O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions
-fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic
After trying different combinations of these it looks like
-Wp,-D_FORTIFY_SOURCE=2 does not like any optimisation.
The simplist way to make this fail is:
$ ( CFLAGS="-O2 -Wp,-D_FORTIFY_SOURCE=2" ./configure )
$ make clean && make check
I'll try see what -D_FORTIFY_SOURCE=2 is getting unhappy about.
If anyone is familiar with this problem or -D_FORTIFY_SOURCE
it would good to hear from you.
-Angus
12 years, 10 months
[PATCH] LOG: add a rwlock to protect the lists.
by Angus Salkeld
On a sparc I was getting corrupt lists in log.c with
the threadded log test.
This fixes it. It does slightly impact the performance.
I was hoping the rw locks would perform better - o well
better than crashing.
Signed-off-by: Angus Salkeld <asalkeld(a)redhat.com>
---
lib/log.c | 36 ++++++++++++++++++++++++++++++++++--
1 files changed, 34 insertions(+), 2 deletions(-)
diff --git a/lib/log.c b/lib/log.c
index 9eeb2b5..368f2a9 100644
--- a/lib/log.c
+++ b/lib/log.c
@@ -22,7 +22,7 @@
#include <ctype.h>
#include <link.h>
#include <stdarg.h>
-
+#include <pthread.h>
#include <dlfcn.h>
#include <qb/qbdefs.h>
@@ -35,6 +35,7 @@
static struct qb_log_target conf[32];
static int32_t in_logger = QB_FALSE;
static int32_t logger_inited = QB_FALSE;
+static pthread_rwlock_t _listlock;
static QB_LIST_DECLARE(active_targets);
static QB_LIST_DECLARE(tags_head);
@@ -119,6 +120,7 @@ static void _log_real_msg(struct qb_log_callsite *cs, const char *msg)
*/
found_threaded = QB_FALSE;
+ pthread_rwlock_rdlock(&_listlock);
for (pos = active_targets.next; pos != &active_targets; pos = pos->next) {
t = qb_list_entry(pos, struct qb_log_target, active_list);
if (t->threaded) {
@@ -131,6 +133,8 @@ static void _log_real_msg(struct qb_log_callsite *cs, const char *msg)
}
}
}
+ pthread_rwlock_unlock(&_listlock);
+
if (found_threaded) {
qb_log_thread_log_post(cs, tv.tv_sec, msg);
}
@@ -143,6 +147,7 @@ void qb_log_thread_log_write(struct qb_log_callsite *cs,
struct qb_log_target *t;
struct qb_list_head *pos;
+ pthread_rwlock_rdlock(&_listlock);
for (pos = active_targets.next; pos != &active_targets; pos = pos->next) {
t = qb_list_entry(pos, struct qb_log_target, active_list);
if (t->threaded) {
@@ -152,6 +157,7 @@ void qb_log_thread_log_write(struct qb_log_callsite *cs,
t->logger(t, cs, timestamp, buffer);
}
}
+ pthread_rwlock_unlock(&_listlock);
}
void qb_log_from_external_source(const char *function,
@@ -174,6 +180,7 @@ void qb_log_from_external_source(const char *function,
assert(cs != NULL);
if (new_dcs) {
+ pthread_rwlock_rdlock(&_listlock);
for (t_item = active_targets.next; t_item != &active_targets; t_item = t_item->next) {
t = qb_list_entry(t_item, struct qb_log_target, active_list);
for (f_item = t->filter_head.next; f_item != &t->filter_head; f_item = f_item->next) {
@@ -191,6 +198,7 @@ void qb_log_from_external_source(const char *function,
} else {
cs->tags = tags;
}
+ pthread_rwlock_unlock(&_listlock);
}
_log_real_msg(cs, msg);
}
@@ -222,11 +230,14 @@ int32_t qb_log_callsites_register(struct qb_log_callsite *_start, struct qb_log_
return -EINVAL;
}
+ pthread_rwlock_rdlock(&_listlock);
qb_list_for_each_entry(sect, &callsite_sections, list) {
if (sect->start == _start || sect->stop == _stop) {
+ pthread_rwlock_unlock(&_listlock);
return -EEXIST;
}
}
+ pthread_rwlock_unlock(&_listlock);
sect = calloc(1, sizeof(struct callsite_section));
if (sect == NULL) {
@@ -235,6 +246,8 @@ int32_t qb_log_callsites_register(struct qb_log_callsite *_start, struct qb_log_
sect->start = _start;
sect->stop = _stop;
qb_list_init(§->list);
+
+ pthread_rwlock_wrlock(&_listlock);
qb_list_add(§->list, &callsite_sections);
/*
@@ -250,6 +263,8 @@ int32_t qb_log_callsites_register(struct qb_log_callsite *_start, struct qb_log_
_log_filter_apply(sect, flt->new_value, flt->conf,
flt->type, flt->text, flt->priority);
}
+ pthread_rwlock_unlock(&_listlock);
+
return 0;
}
@@ -257,8 +272,10 @@ void qb_log_callsites_dump(void)
{
struct callsite_section *sect;
struct qb_log_callsite *cs;
- int32_t l = qb_list_length(&callsite_sections);
+ int32_t l;
+ pthread_rwlock_rdlock(&_listlock);
+ l = qb_list_length(&callsite_sections);
printf("Callsite Database [%d]\n", l);
printf("---------------------\n");
qb_list_for_each_entry(sect, &callsite_sections, list) {
@@ -272,6 +289,7 @@ void qb_log_callsites_dump(void)
cs->targets, cs->tags);
}
}
+ pthread_rwlock_unlock(&_listlock);
}
static int32_t _log_filter_exists(struct qb_list_head *list_head,
@@ -443,14 +461,17 @@ int32_t qb_log_filter_ctl(int32_t t, enum qb_log_filter_conf c,
c > QB_LOG_TAG_CLEAR_ALL) {
return -EINVAL;
}
+ pthread_rwlock_wrlock(&_listlock);
rc = _log_filter_store(t, c, type, text, priority);
if (rc < 0) {
+ pthread_rwlock_unlock(&_listlock);
return rc;
}
qb_list_for_each_entry(sect, &callsite_sections, list) {
_log_filter_apply(sect, t, c, type, text, priority);
}
+ pthread_rwlock_unlock(&_listlock);
return 0;
}
@@ -500,6 +521,8 @@ void qb_log_init(const char *name, int32_t facility, uint8_t priority)
int32_t i;
qb_log_dcs_init();
+ i = pthread_rwlock_init(&_listlock, NULL);
+ assert(i == 0);
for (i = 0; i < 32; i++) {
conf[i].pos = i;
@@ -541,8 +564,12 @@ void qb_log_fini(void)
struct qb_list_head *next;
struct qb_list_head *next2;
+ if (!logger_inited) {
+ return;
+ }
logger_inited = QB_FALSE;
qb_log_thread_stop();
+ pthread_rwlock_destroy(&_listlock);
qb_list_for_each_safe(iter, next, &active_targets) {
t = qb_list_entry(iter, struct qb_log_target, active_list);
@@ -610,8 +637,11 @@ static int32_t _log_target_enable(struct qb_log_target *t)
rc = qb_log_blackbox_open(t);
}
if (rc == 0) {
+ pthread_rwlock_wrlock(&_listlock);
t->state = QB_LOG_STATE_ENABLED;
+ qb_list_init(&t->active_list);
qb_list_add(&t->active_list, &active_targets);
+ pthread_rwlock_unlock(&_listlock);
}
return rc;
}
@@ -621,6 +651,7 @@ static void _log_target_disable(struct qb_log_target *t)
if (t->state != QB_LOG_STATE_ENABLED) {
return;
}
+ pthread_rwlock_wrlock(&_listlock);
t->state = QB_LOG_STATE_DISABLED;
qb_list_del(&t->active_list);
if (t->close) {
@@ -628,6 +659,7 @@ static void _log_target_disable(struct qb_log_target *t)
t->close(t);
in_logger = QB_FALSE;
}
+ pthread_rwlock_unlock(&_listlock);
}
int32_t qb_log_ctl(int32_t t, enum qb_log_conf c, int32_t arg)
--
1.7.5
12 years, 10 months