#4809 closed defect (wontfix)
uClibc daemon/pthred fix (need on 0.9.29 and 0.9.30)
| Reported by: | Luigi 'Comio' Mantellini <luigi.mantellini@…> | Owned by: | nbd |
|---|---|---|---|
| Priority: | highest | Milestone: | Barrier Breaker 14.07 |
| Component: | toolchain | Version: | |
| Keywords: | daemon uclibc | Cc: |
Description
Dear,
the last uclibc has a broken "daemon" function implementation. "daemon" calls a wrong "fork" function (libc instead linuxthreads version) breaking the pthread environment.
This trivial patch permits a correct linking with the pthread "fork" implementation making the daemon call usable also with the last uClibc.
Best regards,
luigi
Attachments (1)
Change History (15)
Changed 9 years ago by Luigi 'Comio' Mantellini <luigi.mantellini@…>
comment:1 Changed 9 years ago by luigi.mantellini@…
comment:2 follow-up: ↓ 5 Changed 9 years ago by olistudent
Are you sure that your patch fixes the problem. I tested with the simple test case from https://bugs.busybox.net/show_bug.cgi?id=193. But it still hangs.
Nevertheless your assumption seems to be correct that the wrong fork function is used. I replaced fork in daemon.c with fork and then it works for me.
I'm not using the OpenWRT toolchain. Perhaps this is the reason why your patch doesn't work for me?
comment:3 Changed 9 years ago by olistudent
Sorry, didn't use the preview function. I replaced fork() with __fork().
comment:4 follow-up: ↓ 6 Changed 9 years ago by olistudent
-
libc/unistd/daemon.c
old new 54 54 libc_hidden_proto(dup2) 55 55 libc_hidden_proto(setsid) 56 56 libc_hidden_proto(chdir) 57 libc_hidden_proto(fork)58 57 59 58 int daemon( int nochdir, int noclose ) 60 59 { 61 60 int fd; 62 61 63 switch ( fork()) {62 switch (__fork()) { 64 63 case -1: 65 64 return(-1); 66 65 case 0: … … 74 73 75 74 /* Make certain we are not a session leader, or else we 76 75 * might reacquire a controlling terminal */ 77 if ( fork())76 if (__fork()) 78 77 _exit(0); 79 78 80 79 if (!nochdir)
comment:5 in reply to: ↑ 2 Changed 9 years ago by luigi.mantellini@…
Replying to olistudent:
Are you sure that your patch fixes the problem. I tested with the simple test case from https://bugs.busybox.net/show_bug.cgi?id=193. But it still hangs.
The real problem is that the pthread implementation is really ugly. I'm waiting for the last nptl implementation.
Nevertheless your assumption seems to be correct that the wrong fork function is used. I replaced fork in daemon.c with fork and then it works for me.
I debugged using the jtag interface and I checked the complete execution flow... discovering the issue.
I'm not using the OpenWRT toolchain. Perhaps this is the reason why your patch doesn't work for me?
may be.
comment:6 in reply to: ↑ 4 Changed 9 years ago by anonymous
I think that this is not a solution, because the pthread support is optional and you need to use a weak linking.
luigi
Replying to olistudent:
...
+ switch (fork()) {
...
}}}
comment:7 Changed 9 years ago by olistudent
Wondering why here is no reference to #4915...
I did further research on this topic and recognized that your patch fixes this problem for dynamic linked libpthread but not for static version. Can you confirm this?
comment:8 Changed 9 years ago by Luigi 'Comio' Mantellini <luigi.mantellini@…>
I'm using only dynamic libs. I'm sorry I cannot confirm.
A better solution may be to choose the correct fork implementation by means of #ifdef/#else/#endef construct.
best regards,
luigi
comment:9 Changed 9 years ago by nbd
fix added in r15344, static library issue still pending.
i don't think #ifdef would work, since the same daemon() implementation would be used for both pthread and non-pthread variants, thus can't really be separated.
no idea what a real solution would look like, though.
comment:10 Changed 8 years ago by thepeople
- Owner changed from developers to nbd
comment:11 Changed 8 years ago by nbd
- Resolution set to worksforme
- Status changed from new to closed
comment:12 Changed 6 years ago by mcy@…
- Resolution worksforme deleted
- Status changed from closed to reopened
Hello,
The problem is still present in OpenWrt 10.03.1 for static linking. Is there any progress here? If you need me to do some tests, I would be happy to help.
Cheers,
Matteo
comment:13 Changed 6 years ago by jow
- Resolution set to wontfix
- Status changed from reopened to closed
Try trunk with ntpl, we're not going to fix this for backfire. If you find this to be still an issue open a separate ticket.
comment:14 Changed 4 years ago by jow
- Milestone changed from Attitude Adjustment 12.09 to Barrier Breaker 14.07
Milestone Attitude Adjustment 12.09 deleted

This patch covers changes like: /changeset/13712.html and many other.
Let me say that the final solution is to switch to nptl (when it will be available... mena carmelo!)
ciao
luigi