Ticket #4071: asterisk-uclib-patch

File asterisk-uclib-patch, 1.1 KB (added by charles.kirsch@…, 7 years ago)
Line 
1--- asterisk-1.6.0-rc6/main/asterisk.c.orig     2008-07-28 18:13:34.000000000 +0200
2+++ asterisk-1.6.0-rc6/main/asterisk.c  2008-09-21 14:21:40.000000000 +0200
3@@ -3218,7 +3218,38 @@
4 #if HAVE_WORKING_FORK
5        if (ast_opt_always_fork || !ast_opt_no_fork) {
6 #ifndef HAVE_SBIN_LAUNCHD
7+#ifndef __UCLIBC__
8                daemon(1, 0);
9+#else
10+/*
11+   workaround for uClibc-0.9.29 mipsel bug:
12+   recursive mutexes do not work if uClibc daemon() function has been called,
13+     if parent thread locks a mutex
14+     the child thread cannot acquire a lock with the same name
15+     (same code works if daemon() is not called)
16+   but duplication of uClibc daemon.c code in here does work.
17+*/
18+       int fd;
19+       switch (fork()) {
20+               case -1:
21+                       exit(1);
22+               case 0:
23+                       break;
24+               default:
25+                       _exit(0);
26+       }
27+       if (setsid() == -1)
28+               exit(1);
29+       if (fork())
30+               _exit(0);
31+       if ((fd = open("/dev/null", O_RDWR, 0)) != -1) {
32+               dup2(fd, STDIN_FILENO);
33+               dup2(fd, STDOUT_FILENO);
34+               dup2(fd, STDERR_FILENO);
35+               if (fd > 2)
36+                       close(fd);
37+       }
38+#endif
39                ast_mainpid = getpid();
40                /* Blindly re-write pid file since we are forking */
41                unlink(ast_config_AST_PID);