summaryrefslogtreecommitdiff
path: root/testing/glibc/glibc-2.15-fmtmsg-locking.patch
blob: f5976abd97c5f367a18f8699a4a2fcb6b3a9103f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
diff --git a/stdlib/fmtmsg.c b/stdlib/fmtmsg.c
index 9203317..4c02302 100644
--- a/stdlib/fmtmsg.c
+++ b/stdlib/fmtmsg.c
@@ -103,7 +103,6 @@ fmtmsg (long int classification, const char *label, int severity,
 	const char *text, const char *action, const char *tag)
 {
   __libc_once_define (static, once);
-  int result = MM_OK;
   struct severity_info *severity_rec;
 
   /* Make sure everything is initialized.  */
@@ -124,17 +123,6 @@ fmtmsg (long int classification, const char *label, int severity,
 	return MM_NOTOK;
     }
 
-  for (severity_rec = severity_list; severity_rec != NULL;
-       severity_rec = severity_rec->next)
-    if (severity == severity_rec->severity)
-      /* Bingo.  */
-      break;
-
-  /* If we don't know anything about the severity level return an error.  */
-  if (severity_rec == NULL)
-    return MM_NOTOK;
-
-
 #ifdef __libc_ptf_call
   /* We do not want this call to be cut short by a thread
      cancellation.  Therefore disable cancellation for now.  */
@@ -143,54 +131,73 @@ fmtmsg (long int classification, const char *label, int severity,
 		   0);
 #endif
 
-  /* Now we can print.  */
-  if (classification & MM_PRINT)
-    {
-      int do_label = (print & label_mask) && label != MM_NULLLBL;
-      int do_severity = (print & severity_mask) && severity != MM_NULLSEV;
-      int do_text = (print & text_mask) && text != MM_NULLTXT;
-      int do_action = (print & action_mask) && action != MM_NULLACT;
-      int do_tag = (print & tag_mask) && tag != MM_NULLTAG;
-
-      if (__fxprintf (stderr, "%s%s%s%s%s%s%s%s%s%s\n",
-		      do_label ? label : "",
-		      do_label && (do_severity | do_text | do_action | do_tag)
-		      ? ": " : "",
-		      do_severity ? severity_rec->string : "",
-		      do_severity && (do_text | do_action | do_tag)
-		      ? ": " : "",
-		      do_text ? text : "",
-		      do_text && (do_action | do_tag) ? "\n" : "",
-		      do_action ? "TO FIX: " : "",
-		      do_action ? action : "",
-		      do_action && do_tag ? "  " : "",
-		      do_tag ? tag : "") < 0)
-	/* Oh, oh.  An error occurred during the output.  */
-	result = MM_NOMSG;
-    }
+  __libc_lock_lock (lock);
 
-  if (classification & MM_CONSOLE)
+  for (severity_rec = severity_list; severity_rec != NULL;
+       severity_rec = severity_rec->next)
+    if (severity == severity_rec->severity)
+      /* Bingo.  */
+      break;
+
+  /* If we don't know anything about the severity level return an error.  */
+  int result = MM_NOTOK;
+  if (severity_rec != NULL)
     {
-      int do_label = label != MM_NULLLBL;
-      int do_severity = severity != MM_NULLSEV;
-      int do_text = text != MM_NULLTXT;
-      int do_action = action != MM_NULLACT;
-      int do_tag = tag != MM_NULLTAG;
-
-      syslog (LOG_ERR, "%s%s%s%s%s%s%s%s%s%s\n",
-	      do_label ? label : "",
-	      do_label && (do_severity | do_text | do_action | do_tag)
-	      ? ": " : "",
-	      do_severity ? severity_rec->string : "",
-	      do_severity && (do_text | do_action | do_tag) ? ": " : "",
-	      do_text ? text : "",
-	      do_text && (do_action | do_tag) ? "\n" : "",
-	      do_action ? "TO FIX: " : "",
-	      do_action ? action : "",
-	      do_action && do_tag ? "  " : "",
-	      do_tag ? tag : "");
+      result = MM_OK;
+
+      /* Now we can print.  */
+      if (classification & MM_PRINT)
+	{
+	  int do_label = (print & label_mask) && label != MM_NULLLBL;
+	  int do_severity = (print & severity_mask) && severity != MM_NULLSEV;
+	  int do_text = (print & text_mask) && text != MM_NULLTXT;
+	  int do_action = (print & action_mask) && action != MM_NULLACT;
+	  int do_tag = (print & tag_mask) && tag != MM_NULLTAG;
+	  int need_colon = (do_label
+			    && (do_severity | do_text | do_action | do_tag));
+
+	  if (__fxprintf (stderr, "%s%s%s%s%s%s%s%s%s%s\n",
+			  do_label ? label : "",
+			  need_colon ? ": " : "",
+			  do_severity ? severity_rec->string : "",
+			  do_severity && (do_text | do_action | do_tag)
+			  ? ": " : "",
+			  do_text ? text : "",
+			  do_text && (do_action | do_tag) ? "\n" : "",
+			  do_action ? "TO FIX: " : "",
+			  do_action ? action : "",
+			  do_action && do_tag ? "  " : "",
+			  do_tag ? tag : "") < 0)
+	    /* Oh, oh.  An error occurred during the output.  */
+	    result = MM_NOMSG;
+	}
+
+      if (classification & MM_CONSOLE)
+	{
+	  int do_label = label != MM_NULLLBL;
+	  int do_severity = severity != MM_NULLSEV;
+	  int do_text = text != MM_NULLTXT;
+	  int do_action = action != MM_NULLACT;
+	  int do_tag = tag != MM_NULLTAG;
+	  int need_colon = (do_label
+			    && (do_severity | do_text | do_action | do_tag));
+
+	  syslog (LOG_ERR, "%s%s%s%s%s%s%s%s%s%s\n",
+		  do_label ? label : "",
+		  need_colon ? ": " : "",
+		  do_severity ? severity_rec->string : "",
+		  do_severity && (do_text | do_action | do_tag) ? ": " : "",
+		  do_text ? text : "",
+		  do_text && (do_action | do_tag) ? "\n" : "",
+		  do_action ? "TO FIX: " : "",
+		  do_action ? action : "",
+		  do_action && do_tag ? "  " : "",
+		  do_tag ? tag : "");
+	}
     }
 
+  __libc_lock_unlock (lock);
+
 #ifdef __libc_ptf_call
   __libc_ptf_call (pthread_setcancelstate, (state, NULL), 0);
 #endif