workaround asterisk daemon issue #4071 caused by uclibc 0.29 (thanks to charles.kirsch)
[openwrt/svn-archive/archive.git] / net / asterisk-1.4.x / patches / 035-main-asterisk-uclibc-daemon.patch
1 diff -Nru asterisk-1.4.22.org/main/asterisk.c asterisk-1.4.22/main/asterisk.c
2 --- asterisk-1.4.22.org/main/asterisk.c 2008-07-26 17:31:21.000000000 +0200
3 +++ asterisk-1.4.22/main/asterisk.c 2008-12-20 22:49:58.000000000 +0100
4 @@ -2935,7 +2935,38 @@
5 #if HAVE_WORKING_FORK
6 if (ast_opt_always_fork || !ast_opt_no_fork) {
7 #ifndef HAVE_SBIN_LAUNCHD
8 +#ifndef __UCLIBC__
9 daemon(1, 0);
10 +#else
11 +/*
12 + workaround for uClibc-0.9.29 mipsel bug:
13 + recursive mutexes do not work if uClibc daemon() function has been called,
14 + if parent thread locks a mutex
15 + the child thread cannot acquire a lock with the same name
16 + (same code works if daemon() is not called)
17 + but duplication of uClibc daemon.c code in here does work.
18 +*/
19 + int fd;
20 + switch (fork()) {
21 + case -1:
22 + exit(1);
23 + case 0:
24 + break;
25 + default:
26 + _exit(0);
27 + }
28 + if (setsid() == -1)
29 + exit(1);
30 + if (fork())
31 + _exit(0);
32 + if ((fd = open("/dev/null", O_RDWR, 0)) != -1) {
33 + dup2(fd, STDIN_FILENO);
34 + dup2(fd, STDOUT_FILENO);
35 + dup2(fd, STDERR_FILENO);
36 + if (fd > 2)
37 + close(fd);
38 + }
39 +#endif
40 ast_mainpid = getpid();
41 /* Blindly re-write pid file since we are forking */
42 unlink(ast_config_AST_PID);