summaryrefslogtreecommitdiff
path: root/recipes/glibc/glibc-2.3.2/syslog-backrev.patch
blob: a3bed2e302799cc4bf88e1720f1c606a3af05b72 (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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
--- misc/syslog.c	2003-07-17 22:14:44.000000000 +0000
+++ /skole/tjener/home0/jbailey/cvstree/libc/misc/syslog.c	2003-07-17 22:05:59.000000000 +0000
@@ -41,7 +41,6 @@
 #include <fcntl.h>
 #include <paths.h>
 #include <stdio.h>
-#include <stdio_ext.h>
 #include <string.h>
 #include <time.h>
 #include <unistd.h>
@@ -75,27 +74,9 @@
 static void openlog_internal(const char *, int, int) internal_function;
 static void closelog_internal(void);
 static void sigpipe_handler (int);
-
-
-struct cleanup_arg
-{
-  void *buf;
-  struct sigaction *oldaction;
-};
-
-static void
-cancel_handler (void *ptr)
-{
-  /* Restore the old signal handler.  */
-  struct cleanup_arg *clarg = (struct cleanup_arg *) ptr;
-
-  if (clarg != NULL && clarg->oldaction != NULL)
-    __sigaction (SIGPIPE, clarg->oldaction, NULL);
-
-  /* Free the lock.  */
-  __libc_lock_unlock (syslog_lock);
-}
-
+#ifdef _LIBC_REENTRANT
+static void cancel_handler (void *);
+#endif
 
 /*
  * syslog, vsyslog --
@@ -137,6 +118,7 @@
 	size_t bufsize = 0;
 	size_t prioff, msgoff;
  	struct sigaction action, oldaction;
+	struct sigaction *oldaction_ptr = NULL;
  	int sigpipe;
 	int saved_errno = errno;
 	char failbuf[3 * sizeof (pid_t) + sizeof "out of memory []"];
@@ -183,7 +165,6 @@
 	  }
 	else
 	  {
-	    __fsetlocking (f, FSETLOCKING_BYCALLER);
 	    prioff = fprintf (f, "<%d>", pri);
 	    (void) time (&now);
 #ifdef USE_IN_LIBIO
@@ -201,12 +182,9 @@
 	    if (LogTag != NULL)
 	      fputs_unlocked (LogTag, f);
 	    if (LogStat & LOG_PID)
-	      fprintf (f, "[%d]", (int) __getpid ());
+	      fprintf (f, "[%d]", __getpid ());
 	    if (LogTag != NULL)
-	      {
-		putc_unlocked (':', f);
-		putc_unlocked (' ', f);
-	      }
+	      putc_unlocked (':', f), putc_unlocked (' ', f);
 
 	    /* Restore errno for %m format.  */
 	    __set_errno (saved_errno);
@@ -234,22 +212,16 @@
 		    v->iov_base = (char *) "\n";
 		    v->iov_len = 1;
 		  }
-
-		__libc_cleanup_push (free, buf);
-
-		/* writev is a cancellation point.  */
 		(void)__writev(STDERR_FILENO, iov, v - iov + 1);
-
-		__libc_cleanup_pop (0);
 	}
 
+#ifdef _LIBC_REENTRANT
 	/* Prepare for multiple users.  We have to take care: open and
 	   write are cancellation points.  */
-	struct cleanup_arg clarg;
-	clarg.buf = buf;
-	clarg.oldaction = NULL;
-	__libc_cleanup_push (cancel_handler, &clarg);
+	__libc_cleanup_region_start (1, (void (*) (void *)) cancel_handler,
+				     &oldaction_ptr);
 	__libc_lock_lock (syslog_lock);
+#endif
 
 	/* Prepare for a broken connection.  */
  	memset (&action, 0, sizeof (action));
@@ -257,7 +229,7 @@
  	sigemptyset (&action.sa_mask);
  	sigpipe = __sigaction (SIGPIPE, &action, &oldaction);
 	if (sigpipe == 0)
-	  clarg.oldaction = &oldaction;
+	  oldaction_ptr = &oldaction;
 
 	/* Get connected, output the message to the local logger. */
 	if (!connected)
@@ -299,9 +271,11 @@
 	if (sigpipe == 0)
 		__sigaction (SIGPIPE, &oldaction, (struct sigaction *) NULL);
 
+#ifdef _LIBC_REENTRANT
 	/* End of critical section.  */
-	__libc_cleanup_pop (0);
+	__libc_cleanup_region_end (0);
 	__libc_lock_unlock (syslog_lock);
+#endif
 
 	free (buf);
 }
@@ -309,7 +283,6 @@
 
 static struct sockaddr SyslogAddr;	/* AF_UNIX address of local logger */
 
-
 static void
 internal_function
 openlog_internal(const char *ident, int logstat, int logfac)
@@ -339,9 +312,8 @@
 			    == -1)
 			{
 				int saved_errno = errno;
-				int fd = LogFile;
+				(void)__close(LogFile);
 				LogFile = -1;
-				(void)__close(fd);
 				if (LogType == SOCK_DGRAM
 				    && saved_errno == EPROTOTYPE)
 				{
@@ -357,16 +329,28 @@
 	}
 }
 
+
+static void
+log_cleanup (void *arg)
+{
+  __libc_lock_unlock (syslog_lock);
+}
+
 void
 openlog (const char *ident, int logstat, int logfac)
 {
-  /* Protect against multiple users and cancellation.  */
-  __libc_cleanup_push (cancel_handler, NULL);
+#ifdef _LIBC_REENTRANT
+  /* Protect against multiple users.  */
+  __libc_cleanup_region_start (1, log_cleanup, NULL);
   __libc_lock_lock (syslog_lock);
+#endif
 
   openlog_internal (ident, logstat, logfac);
 
-  __libc_cleanup_pop (1);
+#ifdef _LIBC_REENTRANT
+  /* Free the lock.  */
+  __libc_cleanup_region_end (1);
+#endif
 }
 
 static void
@@ -389,17 +373,36 @@
 void
 closelog ()
 {
-  /* Protect against multiple users and cancellation.  */
-  __libc_cleanup_push (cancel_handler, NULL);
+#ifdef _LIBC_REENTRANT
+  /* Protect against multiple users.  */
+  __libc_cleanup_region_start (1, log_cleanup, NULL);
   __libc_lock_lock (syslog_lock);
+#endif
 
   closelog_internal ();
   LogTag = NULL;
   LogType = SOCK_DGRAM; /* this is the default */
 
+#ifdef _LIBC_REENTRANT
+  /* Free the lock.  */
+  __libc_cleanup_region_end (1);
+#endif
+}
+
+#ifdef _LIBC_REENTRANT
+static void
+cancel_handler (void *ptr)
+{
+  /* Restore the old signal handler.  */
+  struct sigaction *oldaction = *((struct sigaction **) ptr);
+
+  if (oldaction != (struct sigaction *) NULL)
+    __sigaction (SIGPIPE, oldaction, (struct sigaction *) NULL);
+
   /* Free the lock.  */
-  __libc_cleanup_pop (1);
+  __libc_lock_unlock (syslog_lock);
 }
+#endif
 
 /* setlogmask -- set the log mask level */
 int