On 09/02/14 18:48, Colin Ian King wrote:
> On 09/02/14 18:13, Nicolas Boulenguez wrote:
>> # pidof thermald
>> 20988
>> # strace -f -p 20988
>> [pid 20991] poll([{fd=7, events=POLLIN}, {fd=0, events=0}, {fd=0, events=0}, 
>> {fd=0, events=0}, {fd=0, events=0}, {fd=0, events=0}, {fd=0, events=0}, 
>> {fd=0, events=0}, {fd=0, events=0}, {fd=5, events=POLLIN}], 10, 4000) = 8 
>> ([{fd=0, revents=POLLERR|POLLHUP}, {fd=0, revents=POLLERR|POLLHUP}, {fd=0, 
>> revents=POLLERR|POLLHUP}, {fd=0, revents=POLLERR|POLLHUP}, {fd=0, 
>> revents=POLLERR|POLLHUP}, {fd=0, revents=POLLERR|POLLHUP}, {fd=0, 
>> revents=POLLERR|POLLHUP}, {fd=0, revents=POLLERR|POLLHUP}])
>> # ls -al /proc/20988/fd
>> total 0
>> dr-x------ 2 root root  0 févr.  9 19:07 .
>> dr-xr-xr-x 9 root root  0 févr.  9 19:06 ..
>> lrwx------ 1 root root 64 févr.  9 19:07 0 -> /dev/pts/6 (deleted)
>> lrwx------ 1 root root 64 févr.  9 19:07 1 -> /dev/pts/6 (deleted)
>> lrwx------ 1 root root 64 févr.  9 19:07 2 -> /dev/pts/6 (deleted)
>> lrwx------ 1 root root 64 févr.  9 19:07 3 -> anon_inode:[eventfd]
>> lrwx------ 1 root root 64 févr.  9 19:07 4 -> socket:[237532]
>> lr-x------ 1 root root 64 févr.  9 19:07 5 -> pipe:[238275]
>> l-wx------ 1 root root 64 févr.  9 19:07 6 -> pipe:[238275]
>> lrwx------ 1 root root 64 févr.  9 19:07 7 -> socket:[238276]
>> # ls -al /proc/20991/fd
>> total 0
>> dr-x------ 2 root root  0 févr.  9 19:07 .
>> dr-xr-xr-x 9 root root  0 févr.  9 19:07 ..
>> lrwx------ 1 root root 64 févr.  9 19:07 0 -> /dev/pts/6 (deleted)
>> lrwx------ 1 root root 64 févr.  9 19:07 1 -> /dev/pts/6 (deleted)
>> lrwx------ 1 root root 64 févr.  9 19:07 2 -> /dev/pts/6 (deleted)
>> lrwx------ 1 root root 64 févr.  9 19:07 3 -> anon_inode:[eventfd]
>> lrwx------ 1 root root 64 févr.  9 19:07 4 -> socket:[237532]
>> lr-x------ 1 root root 64 févr.  9 19:07 5 -> pipe:[238275]
>> l-wx------ 1 root root 64 févr.  9 19:07 6 -> pipe:[238275]
>> lrwx------ 1 root root 64 févr.  9 19:07 7 -> socket:[238276]
>>
> Thanks, I can see the problem, and I can now reproduce this. The polling
> on the deleted fd 0 is causing the poll to spin. I think I have a fix,
> I'll discuss this with the thermald upstream developer on Monday and
> hopefully get this sorted out pretty soon.
> 
> Thank you for your help.
> 

Attached is my proposed fix that I've sent to Intel.


>From f4c6318a9f9d1e3dff83bed1aa753d037213b2ac Mon Sep 17 00:00:00 2001
From: Colin Ian King <colin.k...@canonical.com>
Date: Sun, 9 Feb 2014 18:56:07 +0000
Subject: [PATCH] Redirect stderr, stdout and stdin to /dev/null to stop poll()
 spinning

If one starts thermald from a tty and logs out the associated /dev/tty
on fd 0 is removed causing the poll in thd_engine_thread() to spin
rapidly, strace shows this as:

[pid 20991] poll([{fd=7, events=POLLIN}, {fd=0, events=0}, {fd=0, events=0},
{fd=0, events=0}, {fd=0, events=0}, {fd=0, events=0}, {fd=0, events=0},
{fd=0, events=0}, {fd=0, events=0}, {fd=5, events=POLLIN}], 10, 4000) = 8
([{fd=0, revents=POLLERR|POLLHUP}, {fd=0, revents=POLLERR|POLLHUP},
{fd=0, revents=POLLERR|POLLHUP}, {fd=0, revents=POLLERR|POLLHUP},
{fd=0, revents=POLLERR|POLLHUP}, {fd=0, revents=POLLERR|POLLHUP},
{fd=0, revents=POLLERR|POLLHUP}, {fd=0, revents=POLLERR|POLLHUP}])

add infinitum.  The return revents shows fd0 is returning a poll error, and
looking at /proc/$pid/fd for this process shows:

lrwx------ 1 root root 64 Feb  9 18:51 0 -> /dev/pts/6 (deleted)
lrwx------ 1 root root 64 Feb  9 18:51 1 -> /dev/pts/6 (deleted)
lrwx------ 1 root root 64 Feb  9 18:51 2 -> /dev/pts/6 (deleted)

The simple fix is to associate fd 0..2 /dev/null by calling
daemonize appropriately.  Fixes Debian thermald bug #737093.

Signed-off-by: Colin Ian King <colin.k...@canonical.com>
---
 src/main.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/main.cpp b/src/main.cpp
index a026501..5e1b369 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -271,7 +271,7 @@ static int thd_dbus_server_proc(gboolean no_daemon) {
 				"thermald ver %s: Ready to serve requests: Daemonizing..\n",
 				TD_DIST_VERSION);
 
-		if (daemon(0, 1) != 0) {
+		if (daemon(0, 0) != 0) {
 			thd_log_error("Failed to daemonize.\n");
 			return THD_FATAL_ERROR;
 		}
-- 
1.9.rc1

Reply via email to