error_print_progname removed at r13641, but sometimes required

Peter S. Mazinger ps.m at gmx.net
Wed May 17 12:56:51 UTC 2006


On Tue, 16 May 2006, Mike Frysinger wrote:

> On Tuesday 16 May 2006 21:26, Rob McMullen wrote:
> > Working with current svn, and it looks like error_print_progname was
> >
> > removed in this revision:
> > > r13641 | psm | 2006-01-27 14:28:18 -0500 (Fri, 27 Jan 2006) | 1 line
> > >
> > > Disabled NULL error_print_progname, useless
> >
> > but despite it being useless, some programs that check for
> > error_at_line implicitly assume that error_print_progname exists and
> > then fail on linking.
> 
> that's a good thing
> 
> you have a few choices:
>  - add the symbol back in and have runtime bugs
>  - leave the symbol out and have compile bugs
>  - implement the symbol properly
> 
> of the first two choices, the answer is obvious (and is what we're doing 
> now) ... as for the third choice, we take patches ;)
> -mike

attached, Peter

-- 
Peter S. Mazinger <ps dot m at gmx dot net>           ID: 0xA5F059F2
Key fingerprint = 92A4 31E1 56BC 3D5A 2D08  BB6E C389 975E A5F0 59F2
-------------- next part --------------
Index: libc/misc/error/error.c
===================================================================
--- libc/misc/error/error.c	(revision 15101)
+++ libc/misc/error/error.c	(working copy)
@@ -25,6 +25,9 @@
 #include <stdlib.h>
 #include <string.h>
 #include <error.h>
+#ifdef __UCLIBC_HAS_THREADS__
+# include <pthread.h>
+#endif
 
 libc_hidden_proto(strcmp)
 libc_hidden_proto(strerror)
@@ -35,44 +38,54 @@
 libc_hidden_proto(fflush)
 libc_hidden_proto(fputc)
 libc_hidden_proto(__fputc_unlocked)
 
 /* This variable is incremented each time `error' is called.  */
 unsigned int error_message_count = 0;
 /* Sometimes we want to have at most one error per line.  This
    variable controls whether this mode is selected or not.  */
 int error_one_per_line;
 /* If NULL, error will flush stdout, then print on stderr the program
    name, a colon and a space.  Otherwise, error will call this
    function without parameters instead.  */
-/* void (*error_print_progname) (void) = NULL; */
+void (*error_print_progname) (void);
 
 extern __typeof(error) __error attribute_hidden;
 void __error (int status, int errnum, const char *message, ...)
 {
     va_list args;
+    __STDIO_AUTO_THREADLOCK_VAR;
 
     fflush (stdout);
+    __STDIO_AUTO_THREADLOCK(stderr);
 
+    if (error_print_progname)
+	(*error_print_progname) ();
+    else
+	fprintf(stderr, "%s: ", __uclibc_progname);
+
     va_start (args, message);
     vfprintf (stderr, message, args);
     va_end (args);
     ++error_message_count;
     if (errnum) {
 	fprintf (stderr, ": %s", strerror (errnum));
     }
     putc ('\n', stderr);
+    fflush (stderr);
     if (status)
 	exit (status);
+
+    __STDIO_AUTO_THREADUNLOCK(stderr);
 }
 weak_alias(__error,error)
 
-extern __typeof(error_at_line) __error_at_line attribute_hidden;
-void __error_at_line (int status, int errnum, const char *file_name,
+void error_at_line (int status, int errnum, const char *file_name,
 	       unsigned int line_number, const char *message, ...)
 {
     va_list args;
+    __STDIO_AUTO_THREADLOCK_VAR;
 
     if (error_one_per_line) {
 	static const char *old_file_name;
 	static unsigned int old_line_number;
 
@@ -86,7 +104,13 @@
     }
 
     fflush (stdout);
+    __STDIO_AUTO_THREADLOCK(stderr);
 
+    if (error_print_progname)
+	(*error_print_progname) ();
+    else
+	fprintf(stderr, "%s: ", __uclibc_progname);
+
     if (file_name != NULL)
 	fprintf (stderr, "%s:%d: ", file_name, line_number);
 
@@ -94,12 +118,14 @@
     vfprintf (stderr, message, args);
     va_end (args);
 
     ++error_message_count;
     if (errnum) {
 	fprintf (stderr, ": %s", strerror (errnum));
     }
     putc ('\n', stderr);
+    fflush (stderr);
     if (status)
 	exit (status);
+
+    __STDIO_AUTO_THREADUNLOCK(stderr);
 }
-weak_alias(__error_at_line,error_at_line)


More information about the uClibc mailing list