Re: svn commit: r1002263 - /tomcat/trunk/bin/catalina.sh

2010-09-29 Thread Rainer Jung

On 28.09.2010 19:41, Mladen Turk wrote:

Next the code
  echo Tomact stopped but PID file could not be removed ($CATALINA_PID).

Will fail on shells that handle ( ...) like ` ... `


Just as an info: you can use

echo 'Tomcat stopped but PID file could not be removed ('$CATALINA_PID').'

(one line).

Inside single quotation marks shells do not make any substitution. Since 
the variable needs a substitution you can switch from the single 
quotation marks to double ones or none at all on the same line (and back).


I'm not sure though, which shells really handle (..) or [...] inside 
a string as above in a special way. I would expect most bigger shell 
scripts to fail then exactly because this is so common in log outputs. 
So in my opinion the above was already safe. I only know about the 
$((...)) idiom in ksh.


Regards,

Rainer

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Re: svn commit: r1002263 - /tomcat/trunk/bin/catalina.sh

2010-09-29 Thread Mladen Turk

On 09/29/2010 10:51 AM, Rainer Jung wrote:

On 28.09.2010 19:41, Mladen Turk wrote:

Next the code
 echo Tomact stopped but PID file could not be removed ($CATALINA_PID).

Will fail on shells that handle ( ...) like ` ... `


Just as an info: you can use

echo 'Tomcat stopped but PID file could not be removed ('$CATALINA_PID').'



Or since this is a file name variable:
echo Tomcat stopped but PID file could not be removed \`$CATALINA_PID'.

The notion `file.name' is a usual way of reporting the paths.
Most of the coreutils behave like that.



I'm not sure though, which shells really handle (..) or [...] inside a 
string as above in a special way. I would expect most bigger shell scripts to fail then exactly 
because this is so common in log outputs. So in my opinion the above was already
safe. I only know about the $((...)) idiom in ksh.


Think one of the Solaris shells behaves weird in those cases.
Anyhow, since braces are usually used for subshell section, a good
practice would be to avoid them entirely.



Regards
--
^TM

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Re: svn commit: r1002263 - /tomcat/trunk/bin/catalina.sh

2010-09-28 Thread Mladen Turk

On 09/28/2010 06:59 PM, ma...@apache.org wrote:

Author: markt
Date: Tue Sep 28 16:59:54 2010
New Revision: 1002263

URL: http://svn.apache.org/viewvc?rev=1002263view=rev
Log:
Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=49728
Improve PID file handling, particularly when another process creates it and 
Tomcat is unable to write to the file.



Why not creating a function that would manage a pid file?
Seems to me there are lots of redundant code here.



+  if [ -w $CATALINA_PID ]; then
+echo Removing stale PID file.
+rm $CATALINA_PID
+  else
+echo Unable to remove stale PID file. Start aborted.
+exit 1
+  fi


Also I would rater check the return value from rm $CATALINA_PID
then checking if the file is writable.
File can be writable, but locked, so the rm would fail.
Also ro files and trigger rm interactive mode
'rm: remove write-protected regular file 'file' ?'
Using rm -f $CATALINA_PID and checking for $? != 0 would
handle all the cases..

eg, instead the upper code use:

rm -f $CATALINA_PID 2/dev/null
if [ $? != 0 ]; then
  echo Unable to remove stale PID file. Start aborted.
  exit 1
fi


Next the code
 echo Tomact stopped but PID file could not be removed ($CATALINA_PID).

Will fail on shells that handle ( ...) like ` ... `




Regards
--
^TM

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org



Re: svn commit: r1002263 - /tomcat/trunk/bin/catalina.sh

2010-09-28 Thread Mladen Turk

On 09/28/2010 06:59 PM, ma...@apache.org wrote:

Author: markt
+PID=`cat $CATALINA_PID`
+if ps -p $PID  /dev/null; then
+  echo Tomcat appears to still be running with PID $PID. Start 
aborted.
+  exit 1


if $CATALINA_PID points to the file that has invalid content
the following will be shown:

ERROR: Process ID list syntax error.
* simple selection *  * selection by list *
-A all processes  -C by command name
-N negate selection   -G by real group ID (supports names)
-a all w/ tty except session leaders  -U by real user ID (supports names)
-d all except session leaders -g by session OR by effective group name
-e all processes  -p by process ID
T  all processes on this terminal -s processes in the sessions given
a  all w/ tty, including other users  -t by tty
g  OBSOLETE -- DO NOT USE -u by effective user ID (supports names)
r  only running processes U  processes for specified users
x  processes w/o controlling ttys t  by tty
*** output format **  *** long options ***
-o,o user-defined  -f full--Group --User --pid --cols --ppid
-j,j job control   s  signal  --group --user --sid --rows --info
-O,O preloaded -o  v  virtual memory  --cumulative --format --deselect
-l,l long  u  user-oriented   --sort --tty --forest --version
-F   extra fullX  registers   --heading --no-heading --context
* misc options *
-V,V  show version  L  list format codes  f  ASCII art forest
-m,m,-L,-T,H  threads   S  children in sum-y change -l format
-M,Z  security data c  true command name  -c scheduling class
-w,w  wide output   n  numeric WCHAN,UID  -H process hierarchy


The code should actually be
ps -p $PID  /dev/null 21
if [ $? -ne 0 ]; then ...

This is to be consistent with the remaining of the tests
and to not get junk from the ps output in  case of failure.



Regards
--
^TM

-
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org