Eliminate all of the console output message

Jan-Benedict Glaw jbglaw at lug-owl.de
Tue Sep 26 15:56:47 UTC 2006


On Tue, 2006-09-26 08:47:41 -0700, Sterling Augustine <sterling at tensilica.com> wrote:
> Jan-Benedict Glaw wrote:
> >On Tue, 2006-09-26 17:40:42 +0800, colin <colin at realtek.com.tw> wrote:
> > > I am trying to eliminate all of the console output message of the embedded
> > > application.
> > > What I do is like this:
> > >   #define puts do { } while (0)
> > >
> > > printf and putchar will also be replaced by this way.
> > > Is it safe to do this?
> > Consider:
> > 
> > 	while (1) {
> > 		printf ("Next element: %d\n", n++);
> > 		if (n == 10)
> > 			break;
> > 	}
> > 
> > So generally, this is not save, because you still need to evaluate the
> > arguments.
> > 
> > However, in the Linux kernel uses something similar for embedded
> > systems (linux-2.6.x/include/linux/kernel.h):
> > 
> > 150	static inline int printk(const char *s, ...)
> > 151		__attribute__ ((format (printf, 1, 2)));
> > 152	static inline int printk(const char *s, ...) { return 0; }
> > 
> > You can use something similar to still perform argument evaluation
> > while optimizing out the whole call.  However, if you even miss to
> > include your header containing this define, the program will still
> > pull the function at link time.  Also keep in mind that some libraries
> > will have wrapper macros for these funcions, pointing to actual
> > differently named functions...
> Why not just redirect stdout and stderr to /dev/null? Google for how to 
> do this programmatically, internal to your application. It's not hard.

Well, in embedded land, you're fighting _hard_ for every byte you
don't have in your binary.  It's a common technique to strip off all
and any messages that a program could emit with printf() and puts().

It just needs to be done right[tm].

> The problem you have is that an application could be calling "write" 
> directly, without using any libc calls at all.

As long as STDOUT_FILENO and STDERR_FILENO are pointing to /dev/null,
that's not much of a problem :-)

MfG, JBG

-- 
      Jan-Benedict Glaw      jbglaw at lug-owl.de              +49-172-7608481
 Signature of:                            If it doesn't work, force it.
 the second  :                   If it breaks, it needed replacing anyway.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://lists.busybox.net/pipermail/uclibc/attachments/20060926/f76c4a7a/attachment-0002.pgp 


More information about the uClibc mailing list