All of lore.kernel.org
 help / color / mirror / Atom feed
* [Xenomai-help] Re-2:  rt_printf with daemonized task
@ 2009-10-07 13:13 oliver.schlenker
  2009-10-07 13:16 ` Gilles Chanteperdrix
  2009-10-07 13:38 ` Andreas Glatz
  0 siblings, 2 replies; 6+ messages in thread
From: oliver.schlenker @ 2009-10-07 13:13 UTC (permalink / raw)
  To: gilles.chanteperdrix; +Cc: xenomai





After tracking down the issue a little bit further, it seems not to be a problem of daemonizing a server task,
but to change a line of code in rtprint.c

What I would like to achieve :
- My server process is setting up two Xenomai threads
- Both Xenomai should report some messages with rt_printf()
- rt_printf-function should write not to stdout or stderr but to the syslog

Therefor I changed the code for output the message in rt_print.c from
   fprintf(head->dest, "%s", head->text); 
to
   syslog( LOG_ERR | LOG_LOCAL4, head->text ); 

Problem :
The syslog() call is not doing any output the syslog file, it doesn't matter
if the process is daemonized or not.




Oliver

To: gilles.chanteperdrix@xenomai.org
Cc: xenomai@xenomai.org




^ permalink raw reply	[flat|nested] 6+ messages in thread
* [Xenomai-help] Re-2: :: rt_printf with daemonized task
@ 2009-10-21 12:06 oliver.schlenker
  2009-10-22 16:34 ` Jan Kiszka
  0 siblings, 1 reply; 6+ messages in thread
From: oliver.schlenker @ 2009-10-21 12:06 UTC (permalink / raw)
  To: jan.kiszka; +Cc: xenomai




-------- Original Message --------
Subject: Re: :: rt_printf with daemonized task (19-Okt-2009 16:00)
From:    Jan Kiszka <jan.kiszka@siemens.com>
To:      oliver.schlenker@smmotioncontrol.de

> If you move the definition of print_to_buffer right below this prototype
> block, you would avoid having to add this prototype and you would have
> likely generated a more reviewable patch. The large code movement below
> is very hard to check regarding correctness as I do not see the actually
> modified lines.

Ok, moved back definition of print_to_buffer to avoid large code movement

> 
> >  static void cleanup_buffer(struct print_buffer *buffer);
> >  static void print_buffers(void);
> > +static void forked_child_init(void);
> 
> Stray prototype.

deleted

> >  
> > +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);
> > +
> > +	return;
> 
> Unneeded return.

Deleted

> 
> > +}
> > +
> > +void rt_vsyslog(int priority, char *format, va_list args )
> > +{
> > +	print_to_buffer(RT_PRINT_SYSLOG_STREAM, priority, format, args);
> > +
> > +	return;
> 
> Here too.

Also deleted

> 
> > +}
> > +
> >  static void set_buffer_name(struct print_buffer *buffer, const char *name)
> >  {
> >  	int n;
> >                      
> >  
> >  /* *** Deferred Output Management *** */
> >  
> > +static int print_to_buffer(FILE *stream, int priority,
> > +							const char *format,va_list args)
> 
> When moving this function, please also indent this properly and take
> care for a space after the ','.

should be correct now.

> 
> > 
> 
> Jan
> 
> -- 
> Siemens AG, Corporate Technology, CT SE 2
> Corporate Competence Center Embedded Linux


when patches are acked by you, should I do something with the patches
like sending to a special mailing list or is it ok to have them posted in
this list ?


Oliver



----------------------------------------------------------------------------------------------

Subject : Syslog extension of rt_print

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 <at> sm motion control.de>
---


--- rtdk.h.original	2007-12-09 11:46:36.000000000 +0100
+++ rtdk.h	2009-10-09 16:30:57.759836300 +0200
                 
 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); 


--- rt_print.c.forkonly	2009-10-16 16:19:25.949289800 +0200
+++ rt_print.c.wsyslog	2009-10-21 13:46:35.580985700 +0200
                 
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <syslog.h>
 
 #include <rtdk.h>
 #include <asm/xenomai/system.h>
                  
 
 #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));
 
                 
 
 /* *** 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;
                   
 			/* 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 */
                   
 	/* 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 */
                   
 		/* 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;
                    
 	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);
                    
 	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;
                   
 
 /* *** Deferred Output Management *** */
 
+
 static void cleanup_buffer(struct print_buffer *buffer)
 {
 	struct print_buffer *prev, *next;
                    
 
 		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 */ 



To: jan.kiszka@siemens.com
Cc: gilles.chanteperdrix@xenomai.org
    xenomai-help@gna.org

^ permalink raw reply	[flat|nested] 6+ messages in thread
* Re: [Xenomai-help] Re-2: :: rt_printf with daemonized task
@ 2009-10-23  7:24 oliver.schlenker
  0 siblings, 0 replies; 6+ messages in thread
From: oliver.schlenker @ 2009-10-23  7:24 UTC (permalink / raw)
  To: jan.kiszka; +Cc: xenomai

[-- Attachment #1: Type: text/plain, Size: 1289 bytes --]






-------- Original Message --------
Subject: Re: Re-2: :: rt_printf with daemonized task (22-Okt-2009 18:34)
From:    Jan Kiszka <jan.kiszka@siemens.com>
To:      oliver.schlenker@smmotioncontrol.de

> 
> I was about to apply them to my tree and send out a git pull request to
> Philippe. Unfortunately I missed so far that your mail client or gateway
> damaged the patch format seriously (the '> So if you have a clean "diff -up" of your changes, please sent them in a
> tarball to me or via a proper mail client / account that keeps emails
> intact. Otherwise I would have to reconstruct all changes by hand...
> 
> Jan
> 
> -- 
> Siemens AG, Corporate Technology, CT SE 2
> Corporate Competence Center Embedded Linux

I wasn't aware of such a behaviour of my mail client, but it's indeed
like that. All 'commands and filtered out of the mail. I could'nt find a possibility to switch off
this features ...
Therefor I did attach to this mail a tarball with all changes. These patches
have been created with "diff -up". Former ones have been created with just
"diff -u".

Hopefully it's possible now to integrate it without any further problems.


Oliver

To: jan.kiszka@siemens.com
Cc: gilles.chanteperdrix@xenomai.org
    xenomai-help@gna.org


[-- Attachment #2: rt_print.patch.tgz --]
[-- Type: application/octet-stream, Size: 1852 bytes --]

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2009-10-23  7:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-07 13:13 [Xenomai-help] Re-2: rt_printf with daemonized task oliver.schlenker
2009-10-07 13:16 ` Gilles Chanteperdrix
2009-10-07 13:38 ` Andreas Glatz
  -- strict thread matches above, loose matches on Subject: below --
2009-10-21 12:06 [Xenomai-help] Re-2: :: " oliver.schlenker
2009-10-22 16:34 ` Jan Kiszka
2009-10-23  7:24 oliver.schlenker

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.