--- ConsoleKit-0.2.10/src/ck-manager.c.orig 2008-05-08 16:30:52.096394000 +0800 +++ ConsoleKit-0.2.10/src/ck-manager.c 2008-05-08 17:11:32.741068000 +0800 @@ -734,10 +734,19 @@ guint pid) { char *cookie; - - /* FIXME: need a better way to get the cookie */ - - cookie = ck_unix_pid_get_env (pid, "XDG_SESSION_COOKIE"); + guint tmp_pid = pid; + + /* In some cases, the cookie enviroment variable is possibly + * lost when forking a new process. So if current process + * cookie is NULL, try to check its parent process until + * the toppest process. + */ + while (tmp_pid != -1 && tmp_pid != 1) { + cookie = ck_unix_pid_get_env (tmp_pid, "XDG_SESSION_COOKIE"); + if (cookie != NULL) + break; + tmp_pid = ck_unix_pid_get_ppid (tmp_pid); + } return cookie; }