Disable Session library under CLI and create a CI singleton to be used by its drivers
diff --git a/system/libraries/Session/Session.php b/system/libraries/Session/Session.php
index e6f6050..9785060 100755
--- a/system/libraries/Session/Session.php
+++ b/system/libraries/Session/Session.php
@@ -69,13 +69,21 @@
 	 * routines in its constructor, and manages flashdata aging.
 	 *
 	 * @param	array	Configuration parameters
+	 * @return	void
 	 */
 	public function __construct(array $params = array())
 	{
+		$CI =& get_instance();
+
+		// No sessions under CLI
+		if ($CI->input->is_cli_request())
+		{
+			return;
+		}
+
 		log_message('debug', 'CI_Session Class Initialized');
 
 		// Get valid drivers list
-		$CI =& get_instance();
 		$this->valid_drivers = array(
 			'Session_native',
 		   	'Session_cookie'
@@ -587,6 +595,23 @@
  */
 abstract class CI_Session_driver extends CI_Driver {
 
+	protected $CI;
+
+	/**
+	 * Constructor
+	 *
+	 * Gets the CI singleton, so that individual drivers
+	 * don't have to do it separately.
+	 *
+	 * @return	void
+	 */
+	public function __construct()
+	{
+		$this->CI =& get_instance();
+	}
+
+	// ------------------------------------------------------------------------
+
 	/**
 	 * Decorate
 	 *
diff --git a/system/libraries/Session/drivers/Session_cookie.php b/system/libraries/Session/drivers/Session_cookie.php
index 4f415cc..fb62c7e 100755
--- a/system/libraries/Session/drivers/Session_cookie.php
+++ b/system/libraries/Session/drivers/Session_cookie.php
@@ -158,13 +158,6 @@
 	public $userdata				= array();
 
 	/**
-	 * Reference to CodeIgniter instance
-	 *
-	 * @var object
-	 */
-	public $CI;
-
-	/**
 	 * Current time
 	 *
 	 * @var int
@@ -197,9 +190,6 @@
 	 */
 	protected function initialize()
 	{
-		// Set the super object to a local variable for use throughout the class
-		$this->CI =& get_instance();
-
 		// Set all the session preferences, which can either be set
 		// manually via the $params array or via the config file
 		$prefs = array(
diff --git a/system/libraries/Session/drivers/Session_native.php b/system/libraries/Session/drivers/Session_native.php
index c97e153..8d5e515 100755
--- a/system/libraries/Session/drivers/Session_native.php
+++ b/system/libraries/Session/drivers/Session_native.php
@@ -46,7 +46,6 @@
 	{
 		// Get config parameters
 		$config = array();
-		$CI =& get_instance();
 		$prefs = array(
 			'sess_cookie_name',
 			'sess_expire_on_close',
@@ -63,7 +62,7 @@
 		{
 			$config[$key] = isset($this->_parent->params[$key])
 				? $this->_parent->params[$key]
-				: $CI->config->item($key);
+				: $this->CI->config->item($key);
 		}
 
 		// Set session name, if specified
@@ -114,13 +113,13 @@
 			$destroy = TRUE;
 		}
 		elseif ($config['sess_match_ip'] === TRUE && isset($_SESSION['ip_address'])
-			&& $_SESSION['ip_address'] !== $CI->input->ip_address())
+			&& $_SESSION['ip_address'] !== $this->CI->input->ip_address())
 		{
 			// IP doesn't match - destroy
 			$destroy = TRUE;
 		}
 		elseif ($config['sess_match_useragent'] === TRUE && isset($_SESSION['user_agent'])
-			&& $_SESSION['user_agent'] !== trim(substr($CI->input->user_agent(), 0, 50)))
+			&& $_SESSION['user_agent'] !== trim(substr($this->CI->input->user_agent(), 0, 50)))
 		{
 			// Agent doesn't match - destroy
 			$destroy = TRUE;
@@ -149,13 +148,13 @@
 		if ($config['sess_match_ip'] === TRUE && ! isset($_SESSION['ip_address']))
 		{
 			// Store user IP address
-			$_SESSION['ip_address'] = $CI->input->ip_address();
+			$_SESSION['ip_address'] = $this->CI->input->ip_address();
 		}
 
 		if ($config['sess_match_useragent'] === TRUE && ! isset($_SESSION['user_agent']))
 		{
 			// Store user agent string
-			$_SESSION['user_agent'] = trim(substr($CI->input->user_agent(), 0, 50));
+			$_SESSION['user_agent'] = trim(substr($this->CI->input->user_agent(), 0, 50));
 		}
 
 		// Make session ID available