[php-maint] Bug#792239: sessionclean does not support tiered session directory structure

Justin Pasher justinp at distribion.com
Mon Jul 13 03:18:27 UTC 2015

Package: php5
Version: 5.6.9+dfsg-0+deb8u1

The new session cleanup script in Jessie (/usr/lib/php5/sessionclean) 
has a few limitations in it.

1. It does not support a tiered directory structure (e.g. 
2. It does not support a symlinked session directory
3. (not a limitation, but parameter warning) The find command uses the 
-ignore_readdir_race option after a non-option argument

I've attached a patch to fix all of these.

1. Adjust sed to remove the "N;" or "N;MODE;" prefix from session.save_path
2. Add a / to the end of $save_path to look inside the symlinked 
directory. It should still work with regular directories.
3. Move the -ignore_readdir_race parameter

Changed lines:

14: save_path=$(echo "$session_config" | sed -ne 
29: find -O3 "$save_path/" -depth -ignore_readdir_race -mindepth 1 -name 
'sess_*' -type f -cmin "+$gc_maxlifetime" -delete
-------------- next part --------------
--- sessionclean.org	2015-07-12 22:09:59.104104600 -0500
+++ sessionclean	2015-07-12 20:56:30.909853124 -0500
@@ -11,7 +11,7 @@
         # Get all session variables once so we don't need to start PHP to get each config option
         session_config=$(php5 -c /etc/php5/${conf_dir}/php.ini -d "error_reporting='~E_ALL'" -r 'foreach(ini_get_all("session") as $k => $v) echo "$k=".$v["local_value"]."\n";')
         save_handler=$(echo "$session_config" | sed -ne 's/^session\.save_handler=\(.*\)$/\1/p')
-        save_path=$(echo "$session_config" | sed -ne 's/^session\.save_path=\(.*\)$/\1/p')
+        save_path=$(echo "$session_config" | sed -ne 's/^session\.save_path=\(.*;\)\?\(.*\)$/\2/p')
         gc_maxlifetime=$(($(echo "$session_config" | sed -ne 's/^session\.gc_maxlifetime=\(.*\)$/\1/p')/60))
         if [ "$save_handler" = "files" -a -d "$save_path" ]; then
@@ -26,7 +26,7 @@
 ) | sort -rn -t: -k2,2 | sort -u -t: -k 1,1 | while IFS=: read -r save_path gc_maxlifetime; do
     # find all files older then maxlifetime and delete them
-    find -O3 "$save_path" -depth -mindepth 1 -name 'sess_*' -ignore_readdir_race -type f -cmin "+$gc_maxlifetime" -delete
+    find -O3 "$save_path/" -depth -ignore_readdir_race -mindepth 1 -name 'sess_*' -type f -cmin "+$gc_maxlifetime" -delete
 exit 0

More information about the pkg-php-maint mailing list