* [Xenomai-core] [PATCH 0/2] fork-safe rt_print, rt_syslog extension
@ 2009-10-24 8:03 Jan Kiszka
2009-10-24 8:03 ` [Xenomai-core] [PATCH 1/2] Fork-safe rt_print Jan Kiszka
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Jan Kiszka @ 2009-10-24 8:03 UTC (permalink / raw)
To: Philippe Gerum; +Cc: xenomai, Oliver Schlenker
Please pull Oliver's rt_print patches from
git://xenomai.org/xenomai-jki.git for-upstream
Oliver Schlenker (2):
Fork-safe rt_print
Syslog extension of rt_print
include/rtdk.h | 2 +
src/rtdk/rt_print.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++-----
2 files changed, 67 insertions(+), 7 deletions(-)
PS: Trying to manage patches by hand is doomed to fail. I can only
recommend anyone investing the time to get familiar with basic git
commands. It quickly pays off, even for managing only private changes.
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Xenomai-core] [PATCH 2/2] Syslog extension of rt_print
2009-10-24 8:03 [Xenomai-core] [PATCH 0/2] fork-safe rt_print, rt_syslog extension Jan Kiszka
2009-10-24 8:03 ` [Xenomai-core] [PATCH 1/2] Fork-safe rt_print Jan Kiszka
@ 2009-10-24 8:03 ` Jan Kiszka
2009-10-24 16:38 ` [Xenomai-core] [PATCH 0/2] fork-safe rt_print, rt_syslog extension Philippe Gerum
2 siblings, 0 replies; 5+ messages in thread
From: Jan Kiszka @ 2009-10-24 8:03 UTC (permalink / raw)
To: Philippe Gerum; +Cc: xenomai, Oliver Schlenker
From: Oliver Schlenker <oliver.schlenker@domain.hid>
Extension of rt_print library with rt_syslog() and rt_vsyslog() to print
messages rt-safe directly to syslog.
Signed-off-by: Oliver Schlenker <oliver.schlenker@domain.hid>
Signed-off-by: Jan Kiszka <jan.kiszka@domain.hid>
---
include/rtdk.h | 2 ++
src/rtdk/rt_print.c | 39 ++++++++++++++++++++++++++++++++++++---
2 files changed, 38 insertions(+), 3 deletions(-)
diff --git a/include/rtdk.h b/include/rtdk.h
index 981bfda..9129ccb 100644
--- a/include/rtdk.h
+++ b/include/rtdk.h
@@ -52,6 +52,8 @@ int rt_vfprintf(FILE *stream, const char *format, va_list args);
int rt_vprintf(const char *format, va_list args);
int rt_fprintf(FILE *stream, const char *format, ...);
int rt_printf(const char *format, ...);
+void rt_syslog(int priority, char *format, ...);
+void rt_vsyslog(int priority, char *format, va_list args);
int rt_print_init(size_t buffer_size, const char *name);
void rt_print_cleanup(void);
diff --git a/src/rtdk/rt_print.c b/src/rtdk/rt_print.c
index dca9689..c6b5c55 100644
--- a/src/rtdk/rt_print.c
+++ b/src/rtdk/rt_print.c
@@ -25,6 +25,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <syslog.h>
#include <rtdk.h>
#include <asm/xenomai/system.h>
@@ -37,9 +38,12 @@
#define RT_PRINT_LINE_BREAK 256
+#define RT_PRINT_SYSLOG_STREAM NULL
+
struct entry_head {
FILE *dest;
uint32_t seq_no;
+ int priority;
char text[1];
} __attribute__((packed));
@@ -76,7 +80,8 @@ static void print_buffers(void);
/* *** rt_print API *** */
-int rt_vfprintf(FILE *stream, const char *format, va_list args)
+static int print_to_buffer(FILE *stream, int priority, const char *format,
+ va_list args)
{
struct print_buffer *buffer = pthread_getspecific(buffer_key);
off_t write_pos, read_pos;
@@ -115,6 +120,7 @@ int rt_vfprintf(FILE *stream, const char *format, va_list args)
/* Write out empty entry */
head = buffer->ring + write_pos;
head->seq_no = seq_no;
+ head->priority = 0;
head->text[0] = 0;
/* Forward to the ring buffer start */
@@ -148,6 +154,7 @@ int rt_vfprintf(FILE *stream, const char *format, va_list args)
/* If we were able to write some text, finalise the entry */
if (len > 0) {
head->seq_no = ++seq_no;
+ head->priority = priority;
head->dest = stream;
/* Move forward by text and head length */
@@ -160,6 +167,7 @@ int rt_vfprintf(FILE *stream, const char *format, va_list args)
/* An empty entry marks the wrap-around */
head = buffer->ring + write_pos;
head->seq_no = seq_no;
+ head->priority = priority;
head->text[0] = 0;
write_pos = 0;
@@ -173,6 +181,11 @@ int rt_vfprintf(FILE *stream, const char *format, va_list args)
return res;
}
+int rt_vfprintf(FILE *stream, const char *format, va_list args)
+{
+ return print_to_buffer(stream, 0, format, args);
+}
+
int rt_vprintf(const char *format, va_list args)
{
return rt_vfprintf(stdout, format, args);
@@ -202,6 +215,20 @@ int rt_printf(const char *format, ...)
return n;
}
+void rt_syslog(int priority, char *format, ...)
+{
+ va_list args;
+
+ va_start(args, format);
+ print_to_buffer(RT_PRINT_SYSLOG_STREAM, priority, format, args);
+ va_end(args);
+}
+
+void rt_vsyslog(int priority, char *format, va_list args)
+{
+ print_to_buffer(RT_PRINT_SYSLOG_STREAM, priority, format, args);
+}
+
static void set_buffer_name(struct print_buffer *buffer, const char *name)
{
int n;
@@ -311,7 +338,6 @@ const char *rt_print_buffer_name(void)
return buffer->name;
}
-
/* *** Deferred Output Management *** */
static void cleanup_buffer(struct print_buffer *buffer)
@@ -384,7 +410,14 @@ static void print_buffers(void)
if (len) {
/* Print out non-empty entry and proceed */
- fprintf(head->dest, "%s", head->text);
+ /* Check if output goes to syslog */
+ if (head->dest == RT_PRINT_SYSLOG_STREAM) {
+ syslog(head->priority, "%s", head->text);
+ } else {
+ /* Output goes to specified stream */
+ fprintf(head->dest, "%s", head->text);
+ }
+
read_pos += sizeof(*head) + len;
} else {
/* Emptry entries mark the wrap-around */
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [Xenomai-core] [PATCH 1/2] Fork-safe rt_print
2009-10-24 8:03 [Xenomai-core] [PATCH 0/2] fork-safe rt_print, rt_syslog extension Jan Kiszka
@ 2009-10-24 8:03 ` Jan Kiszka
2009-10-24 8:03 ` [Xenomai-core] [PATCH 2/2] Syslog extension of rt_print Jan Kiszka
2009-10-24 16:38 ` [Xenomai-core] [PATCH 0/2] fork-safe rt_print, rt_syslog extension Philippe Gerum
2 siblings, 0 replies; 5+ messages in thread
From: Jan Kiszka @ 2009-10-24 8:03 UTC (permalink / raw)
To: Philippe Gerum; +Cc: xenomai, Oliver Schlenker
From: Oliver Schlenker <oliver.schlenker@domain.hid>
Fork-safe initialisation of rt_print library, necessary child initialisation are
done via pthread_atfork() when child process is started.
Signed-off-by: Oliver Schlenker <oliver.schlenker@domain.hid>
Signed-off-by: Jan Kiszka <jan.kiszka@domain.hid>
---
src/rtdk/rt_print.c | 33 +++++++++++++++++++++++++++++----
1 files changed, 29 insertions(+), 4 deletions(-)
diff --git a/src/rtdk/rt_print.c b/src/rtdk/rt_print.c
index 0615247..dca9689 100644
--- a/src/rtdk/rt_print.c
+++ b/src/rtdk/rt_print.c
@@ -417,9 +417,35 @@ static void *printer_loop(void *arg)
}
}
-void __rt_print_init(void)
+static void spawn_printer_thread(void)
{
pthread_attr_t thattr;
+
+ pthread_attr_init(&thattr);
+ pthread_attr_setstacksize(&thattr, PTHREAD_STACK_MIN);
+ pthread_create(&printer_thread, &thattr, printer_loop, NULL);
+}
+
+static void forked_child_init(void)
+{
+ struct print_buffer *my_buffer = pthread_getspecific(buffer_key);
+ struct print_buffer **pbuffer = &first_buffer;
+
+ /* re-init to avoid finding it locked by some parent thread */
+ pthread_mutex_init(&buffer_lock, NULL);
+
+ while (*pbuffer) {
+ if (*pbuffer == my_buffer)
+ pbuffer = &(*pbuffer)->next;
+ else
+ cleanup_buffer(*pbuffer);
+ }
+
+ spawn_printer_thread();
+}
+
+void __rt_print_init(void)
+{
const char *value_str;
unsigned long long period;
@@ -456,7 +482,6 @@ void __rt_print_init(void)
pthread_cond_init(&printer_wakeup, NULL);
- pthread_attr_init(&thattr);
- pthread_attr_setstacksize(&thattr, PTHREAD_STACK_MIN);
- pthread_create(&printer_thread, &thattr, printer_loop, NULL);
+ spawn_printer_thread();
+ pthread_atfork(NULL, NULL, forked_child_init);
}
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [Xenomai-core] [PATCH 0/2] fork-safe rt_print, rt_syslog extension
2009-10-24 8:03 [Xenomai-core] [PATCH 0/2] fork-safe rt_print, rt_syslog extension Jan Kiszka
2009-10-24 8:03 ` [Xenomai-core] [PATCH 1/2] Fork-safe rt_print Jan Kiszka
2009-10-24 8:03 ` [Xenomai-core] [PATCH 2/2] Syslog extension of rt_print Jan Kiszka
@ 2009-10-24 16:38 ` Philippe Gerum
2009-10-26 8:14 ` Jan Kiszka
2 siblings, 1 reply; 5+ messages in thread
From: Philippe Gerum @ 2009-10-24 16:38 UTC (permalink / raw)
To: Jan Kiszka; +Cc: xenomai, Oliver Schlenker
On Sat, 2009-10-24 at 10:03 +0200, Jan Kiszka wrote:
> Please pull Oliver's rt_print patches from
>
> git://xenomai.org/xenomai-jki.git for-upstream
>
>
> Oliver Schlenker (2):
> Fork-safe rt_print
> Syslog extension of rt_print
>
> include/rtdk.h | 2 +
> src/rtdk/rt_print.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++-----
> 2 files changed, 67 insertions(+), 7 deletions(-)
>
> PS: Trying to manage patches by hand is doomed to fail. I can only
> recommend anyone investing the time to get familiar with basic git
> commands. It quickly pays off, even for managing only private changes.
Please, make sure to provide a prefix in your short log; this makes
sorting the short logs for changes by topic a bit easier. E.g.
rtdk: fork-safe rt_print
rtdk: syslog extension of rt_print
--
Philippe.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [Xenomai-core] [PATCH 0/2] fork-safe rt_print, rt_syslog extension
2009-10-24 16:38 ` [Xenomai-core] [PATCH 0/2] fork-safe rt_print, rt_syslog extension Philippe Gerum
@ 2009-10-26 8:14 ` Jan Kiszka
0 siblings, 0 replies; 5+ messages in thread
From: Jan Kiszka @ 2009-10-26 8:14 UTC (permalink / raw)
To: Philippe Gerum; +Cc: xenomai, Oliver Schlenker
[-- Attachment #1: Type: text/plain, Size: 1013 bytes --]
Philippe Gerum wrote:
> On Sat, 2009-10-24 at 10:03 +0200, Jan Kiszka wrote:
>> Please pull Oliver's rt_print patches from
>>
>> git://xenomai.org/xenomai-jki.git for-upstream
>>
>>
>> Oliver Schlenker (2):
>> Fork-safe rt_print
>> Syslog extension of rt_print
>>
>> include/rtdk.h | 2 +
>> src/rtdk/rt_print.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++-----
>> 2 files changed, 67 insertions(+), 7 deletions(-)
>>
>> PS: Trying to manage patches by hand is doomed to fail. I can only
>> recommend anyone investing the time to get familiar with basic git
>> commands. It quickly pays off, even for managing only private changes.
>
> Please, make sure to provide a prefix in your short log; this makes
> sorting the short logs for changes by topic a bit easier. E.g.
>
> rtdk: fork-safe rt_print
> rtdk: syslog extension of rt_print
>
As you already merged it - too late to fix. Sorry, will try to avoid
forgetting this in the future.
Jan
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 257 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2009-10-26 8:14 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-24 8:03 [Xenomai-core] [PATCH 0/2] fork-safe rt_print, rt_syslog extension Jan Kiszka
2009-10-24 8:03 ` [Xenomai-core] [PATCH 1/2] Fork-safe rt_print Jan Kiszka
2009-10-24 8:03 ` [Xenomai-core] [PATCH 2/2] Syslog extension of rt_print Jan Kiszka
2009-10-24 16:38 ` [Xenomai-core] [PATCH 0/2] fork-safe rt_print, rt_syslog extension Philippe Gerum
2009-10-26 8:14 ` Jan Kiszka
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.