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