add basic asterisk 1.6.x package based on 1.6.1-rc1
[openwrt/svn-archive/archive.git] / net / asterisk-1.6.x / patches / 200-uclibc-daemon.patch
1 diff -Nru asterisk-1.6.1-beta4.org/main/asterisk.c asterisk-1.6.1-beta4/main/asterisk.c
2 --- asterisk-1.6.1-beta4.org/main/asterisk.c 2008-12-12 23:05:58.000000000 +0100
3 +++ asterisk-1.6.1-beta4/main/asterisk.c 2008-12-23 15:28:21.000000000 +0100
4 @@ -3295,9 +3295,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);