Dear listmembers,
regarding my first posting I found that I was definitively wrong in that the
current solution of wrapper-scripts are no real wrapper scripts as they are
not actually executed but sourced in order to keep track of the path-moves
within mc.
What still remains is the problem that the temp-dir is not cleaned at the end.
IMHO this should not happen.
Therefore I prepared a patch that cures this - the current functionality is
kept as is, however, everything is wiped off TMPDIR/mc-USERNAME after
the last instance of mc has been terminated.
Take care
Dieter Jurzitza
--
---
|
\
/\_/\ |
| ~x~ |/-\ /
\ /- \_/
^^__ _/ _ /
°°__ \- \_/ | |/| |
|| || _| _|_| _|
if you really want to see the pictures above - use some font
with constant spacing like courier! :-)
---
--- lib/mc-wrapper.sh.in
+++ lib/mc-wrapper.sh.in
@@ -1,14 +1,45 @@
-MC_USER=`id | sed 's/[^(]*(//;s/).*//'`
-MC_PWD_FILE=${TMPDIR-/tmp}/mc-$MC_USER/mc.pwd.$$
[EMAIL PROTECTED]@/mc -P $MC_PWD_FILE $@
-
-if test -r $MC_PWD_FILE; then
- MC_PWD=`cat $MC_PWD_FILE`
- if test -n $MC_PWD test -d $MC_PWD; then
- cd $MC_PWD
+# This is only sourced, we will have no new shell - no shell-reference at the top
+export MC_TMPDIR=${TMPDIR-/tmp}/mc-`id -un`
+export MC_PWD_FILE=${MC_TMPDIR}/mc.pwd.$$
+
+# start mc, actually!
[EMAIL PROTECTED]@/mc -P ${MC_PWD_FILE} $@
+
+# go where mc used to be at the end. This is still somewhat tricky
+# as it only works from an alias, not directly!
+if [ -r ${MC_PWD_FILE} ]; then
+ MC_PWD=`cat ${MC_PWD_FILE}`
+ if test -n ${MC_PWD} test -d ${MC_PWD}; then
+ cd ${MC_PWD}
fi
- unset MC_PWD
fi
-rm -f $MC_PWD_FILE
+#
+# Now we have to clean up.
+# If other mc-instances are active, do nothing, otherwise clean the directory!
+# watch out, the instances could be dead!
+#
+# get the list of proc-id's that belong to the corresponding entries in $MC_TMPDIR
+MC_PROCLIST=`cd ${MC_TMPDIR}; ls -c --color=none mc.pipe* 2/dev/null | sed 's/mc\.pipe\.//g'| tr '\n' ' '`
+
+# Test whether those processes are active ones. If yes, do nothing!
+# if only one mc-process is still running, we do nothing!
+for i in ${MC_PROCLIST}; do
+ MC_RESULT=`ps -p $i -o pid= -o comm=`
+ if [ ${MC_RESULT} != ]; then
+ break;
+ fi
+done
+
+# Delete everything in /tmp/mc-USERNAME, but only if no instances of mc run any more!
+if [ ${MC_RESULT} = ]; then
+ /bin/rm -rf ${MC_TMPDIR}
+ mkdir ${MC_TMPDIR}
+fi
+
unset MC_PWD_FILE
+unset MC_PROCLIST
+unset MC_RESULT
+unset MC_TMPDIR
+unset MC_PWD
+# That should be it!
--- lib/mc-wrapper.csh.in
+++ lib/mc-wrapper.csh.in
@@ -1,20 +1,46 @@
-set MC_USER=`id | sed 's/[^(]*(//;s/).*//'`
-
+# This is only sourced, we will have no new shell - no shell-reference at the top
if ($?TMPDIR) then
- setenv MC_PWD_FILE $TMPDIR/mc-$MC_USER/mc.pwd.$$
+ setenv MC_TMPDIR $TMPDIR/mc-`id -un`
else
- setenv MC_PWD_FILE /tmp/mc-$MC_USER/mc.pwd.$$
+ setenv MC_TMPDIR /tmp/mc-`id -un`
endif
+setenv MC_PWD_FILE $MC_TMPDIR/mc.pwd.$$
[EMAIL PROTECTED]@/mc -P $MC_PWD_FILE $*
+/usr/bin/mc -P $MC_PWD_FILE $*
if (-r $MC_PWD_FILE) then
setenv MC_PWD `cat $MC_PWD_FILE`
if ( -d $MC_PWD ) then
cd $MC_PWD
endif
- unsetenv MC_PWD
endif
-rm -f $MC_PWD_FILE
+#
+# Now we have to clean up.
+# If other mc-instances are active, do nothing, otherwise clean the directory!
+# watch out, the instances could be dead!
+#
+# get the list of proc-id's that belong to the corresponding entries in $MC_TMPDIR
+setenv MC_PROCLIST `cd ${MC_TMPDIR}; ls -c --color=none mc.pipe* | sed 's/[^0-9]//g'| tr '\n' ' '`
+
+# Test whether those processes are active ones. If yes, do nothing!
+# if only one mc-process is still running, we do nothing!
+foreach i (${MC_PROCLIST})
+ setenv MC_RESULT `ps -p $i -o pid= -o comm=`
+ if ($?MC_RESULT) then
+ break;
+ endif
+end
+
+# Delete everything in /tmp/mc-USERNAME, but only if no instances of mc run any more!
+if ( ! $?MC_RESULT ) then
+ /bin/rm -rf ${MC_TMPDIR}
+ mkdir ${MC_TMPDIR}
+endif
+
unsetenv MC_PWD_FILE
+unsetenv MC_PROCLIST
+unsetenv MC_RESULT
+unsetenv MC_TMPDIR
+unsetenv MC_PWD
+# That should be it!
___
Mc-devel mailing list
http://mail.gnome.org/mailman/listinfo/mc-devel