This repository was archived by the owner on Mar 28, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +23
-9
lines changed Expand file tree Collapse file tree 3 files changed +23
-9
lines changed Original file line number Diff line number Diff line change @@ -269,16 +269,9 @@ static void exitSignalHandler(int sig) {
269
269
270
270
static void installExitSignalHandlers (void ) {
271
271
unsigned I ;
272
- struct sigaction sigact ;
273
- int err ;
274
272
for (I = 0 ; I < lprofCurFilename .NumExitSignals ; ++ I ) {
275
- memset (& sigact , 0 , sizeof (sigact ));
276
- sigact .sa_handler = exitSignalHandler ;
277
- err = sigaction (lprofCurFilename .ExitOnSignals [I ], & sigact , NULL );
278
- if (err )
279
- PROF_WARN (
280
- "Unable to install an exit signal handler for %d (errno = %d).\n" ,
281
- lprofCurFilename .ExitOnSignals [I ], err );
273
+ lprofInstallSignalHandler (lprofCurFilename .ExitOnSignals [I ],
274
+ exitSignalHandler );
282
275
}
283
276
}
284
277
Original file line number Diff line number Diff line change 26
26
#include <sys/utsname.h>
27
27
#endif
28
28
29
+ #include <signal.h>
29
30
#include <stdlib.h>
30
31
#include <string.h>
31
32
@@ -245,3 +246,21 @@ COMPILER_RT_VISIBILITY void lprofRestoreSigKill() {
245
246
prctl (PR_SET_PDEATHSIG , SIGKILL );
246
247
#endif
247
248
}
249
+
250
+ COMPILER_RT_VISIBILITY void lprofInstallSignalHandler (int sig ,
251
+ void (* handler )(int )) {
252
+ #ifdef _WIN32
253
+ void (* err )(int ) = signal (sig , handler );
254
+ if (err == SIG_ERR )
255
+ PROF_WARN ("Unable to install an exit signal handler for %d (errno = %d).\n" ,
256
+ sig , errno );
257
+ #else
258
+ struct sigaction sigact ;
259
+ memset (& sigact , 0 , sizeof (sigact ));
260
+ sigact .sa_handler = handler ;
261
+ int err = sigaction (sig , & sigact , NULL );
262
+ if (err )
263
+ PROF_WARN ("Unable to install an exit signal handler for %d (errno = %d).\n" ,
264
+ sig , err );
265
+ #endif
266
+ }
Original file line number Diff line number Diff line change @@ -59,4 +59,6 @@ int lprofSuspendSigKill();
59
59
/* Restore previously suspended SIGKILL. */
60
60
void lprofRestoreSigKill ();
61
61
62
+ void lprofInstallSignalHandler (int sig , void (* handler )(int ));
63
+
62
64
#endif /* PROFILE_INSTRPROFILINGUTIL_H */
You can’t perform that action at this time.
0 commit comments