--- a/app.cpp
+++ b/app.cpp
@@ -570,8 +570,13 @@
 		ck.open_session(DisplayName, pw->pw_uid);
 	}
 	catch(Ck::Exception &e) {
+#ifdef USE_PAM
+		logStream << APPNAME << ": Consolekit::" << e << endl;
+		logStream << APPNAME << ": falling back to PAM session" << endl;
+#else
 		logStream << APPNAME << ": " << e << endl;
 		exit(ERR_EXIT);
+#endif
 	}
 #endif
 
@@ -584,18 +589,20 @@
 		char** child_env = pam.getenvlist();
 
 # ifdef USE_CONSOLEKIT
-		char** old_env = child_env;
+		if (ck.get_xdg_session_cookie()) {
+		 char** old_env = child_env;
 
-		/* Grow the copy of the environment for the session cookie */
-		int n;
-		for(n = 0; child_env[n] != NULL ; n++);
-
-		n++;
-
-		child_env = static_cast<char**>(malloc(sizeof(char*)*(n+1)));
-		memcpy(child_env, old_env, sizeof(char*)*n);
-		child_env[n - 1] = StrConcat("XDG_SESSION_COOKIE=", ck.get_xdg_session_cookie());
-		child_env[n] = NULL;
+		  /* Grow the copy of the environment for the session cookie */
+		  int n;
+		  for(n = 0; child_env[n] != NULL ; n++);
+
+		  n++;
+
+		  child_env = static_cast<char**>(malloc(sizeof(char*)*(n+1)));
+		  memcpy(child_env, old_env, sizeof(char*)*n);
+		  child_env[n - 1] = StrConcat("XDG_SESSION_COOKIE=", ck.get_xdg_session_cookie());
+		  child_env[n] = NULL;
+		}
 # endif /* USE_CONSOLEKIT */
 #else
 
@@ -663,7 +670,8 @@
 
 #ifdef USE_CONSOLEKIT
 	try {
-		ck.close_session();
+	  	if (ck.get_xdg_session_cookie())
+	  		ck.close_session();
 	}
 	catch(Ck::Exception &e) {
 		logStream << APPNAME << ": " << e << endl;
