:: rt_printf with daemonized task
-------- Original Message --------
Subject: Re: Re : rt_printf with daemonized task (08-Okt-2009 12:16) From: Jan Kiszka <[email protected]> To: [email protected]
Quoted 36 lines
Quoted 29 lines · Gilles Chanteperdrix
Quoted 21 lines · Jan Kiszka
Quoted 11 lines · Gilles Chanteperdrix
Quoted 10 lines · [email protected] wrote:
Quoted 10 lines
Quoted 10 lines
int
main( int arc, char *argv[] ){ int i;
rt_print_auto_init(1);
rt_printf("--------------- TEST RT-PRINTF 1 ------------\n");sleep(1);
daemon(0,0);Quoted 9 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
rt_print_auto_init(1);Ok, understood, at least for the scenario where the
rt_printfeature is initialised befor the fork/daemon call. What I don't understand is, why it does not work if thert_printfeature is initialised after the fork / daemon.From the way I understand your code, you never tried to initialize the
rt_printfeature only after the fork, your code initializes it both before and after.Quoted 6 lines
There are two initializations: The base init done via
__rt_print_initon library loading and the one to be done per-thread viart_print_init(or on firstrt_printf). That printer thread is initialized via the former one. On fork, we do not need to re-run the full__rt_print_init(variables and resources are cloned on fork), we just need to spawn another printer thread.Quoted 5 lines
Unless I am wrong, rtdk also maintains a list of the thread buffers which need to be polled. After the fork, this list will be intact, but the threads to which belong the buffers will no longer exist. So, IMO, the fork handler should also free all these buffers and reset the list to the empty state.
Quoted 8 lines
Famous last words: That should work without tweaking. A
print_bufferonly contains data references, nothing that points to some uncloned thread.Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
To have a fork save rtprint library it's necessary to
1. Reset rtdk thread buffer list
I have no idea where to look at for the rtdk thread buffer list. Inside rt_print.c ?
2. Spawning another printer thread
with code like : pthread_attr_init(&thattr); pthread_attr_setstacksize(&thattr, PTHREAD_STACK_MIN); pthread_create(&__printer_thread, &thattr, printer_loop, NULL);
Is there anything else to do ?
I'm also planning to add a function to the lib like :
rt_print_to_syslog( int priority )
If priority is zero, all messages are going to fprintf() output.
If priority is non-zero, all messages are going to syslog( priority, <message> ) output.
Is it ok to add therefor a new variable to struct print_buffer ?
If everything is coming to work, I would like to send it as a patch.
Oliver
To: [email protected]
[email protected]
Cc: [email protected]
Quoted 52 lines · [email protected] wrote:
-------- Original Message --------
Subject: Re: Re : rt_printf with daemonized task (08-Okt-2009 12:16) From: Jan Kiszka <[email protected]> To: [email protected]Quoted 34 lines
Quoted 28 lines · Gilles Chanteperdrix
Quoted 21 lines · Jan Kiszka
Quoted 11 lines · Gilles Chanteperdrix
Quoted 10 lines · [email protected] wrote:
Quoted 10 lines
Quoted 10 lines
int
main( int arc, char *argv[] ){ int i;
rt_print_auto_init(1);
rt_printf("--------------- TEST RT-PRINTF 1 ------------\n");sleep(1);
daemon(0,0);Quoted 9 lines
Quoted 5 lines
Quoted 1 line
Quoted 1 line
rt_print_auto_init(1);Ok, understood, at least for the scenario where the
rt_printfeature is initialised befor the fork/daemon call. What I don't understand is, why it does not work if thert_printfeature is initialised after the fork / daemon.From the way I understand your code, you never tried to initialize the
rt_printfeature only after the fork, your code initializes it both before and after.Quoted 6 lines
There are two initializations: The base init done via
__rt_print_initon library loading and the one to be done per-thread viart_print_init(or on firstrt_printf). That printer thread is initialized via the former one. On fork, we do not need to re-run the full__rt_print_init(variables and resources are cloned on fork), we just need to spawn another printer thread.Quoted 5 lines
Unless I am wrong, rtdk also maintains a list of the thread buffers which need to be polled. After the fork, this list will be intact, but the threads to which belong the buffers will no longer exist. So, IMO, the fork handler should also free all these buffers and reset the list to the empty state.
Quoted 8 lines
Famous last words: That should work without tweaking. A
print_bufferonly contains data references, nothing that points to some uncloned thread.Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux
Quoted 5 lines
To have a fork save rtprint library it's necessary to
1. Reset rtdk thread buffer list
I have no idea where to look at for the rtdk thread buffer list. Inside
rt_print.c?
It's all there, it's called first_buffer. Just walk that list and call cleanup_buffers on the entries.
Quoted 10 lines
2. Spawning another printer thread
with code like : pthread_attr_init(&thattr); pthread_attr_setstacksize(&thattr, PTHREAD_STACK_MIN); pthread_create(&__printer_thread, &thattr, printer_loop, NULL);Is there anything else to do ?
Probably not, but I was already wrong before. :)
Quoted 4 lines
I'm also planning to add a function to the lib like :
rt_print_to_syslog( int priority )
Better provide some rt_syslog(int priority, char *format, ...), corresponding to the standard service.
Jan
Signature · 2 lines
Siemens AG, Corporate Technology, CT SE 2 Corporate Competence Center Embedded Linux