16 October 2013

Dance around /tmp

Using WindowZ as development environment may be uncomfortably due lack of pretty handy command line tools, easy accessible in normal *nix environment. To achieve certain degree of freedom people usually install CygWin that mimics a friendly environment there. Yes, it brings you everything you may need to feel more less confident with old known shell. But it may put some unexpected obstacles on your way that hard to anticipate.

In desperate attempt to look on internals of web application I had misfortune to maintain, I have connected by Mission Control only after opening remote management port. I did what I have to, but was intrigued why it was so hard to see the the Tomcat JVM running locally, despite other ones were in the list.

Quick googling of this problem brings spots about java.io.tmpdir that has to point to the temporary folder. Surprisingly it is used for discovery JVMs running locally. That make more sense, I had no chance to think about how they did this. So, taking this advice on arms I tried to run both the Tomcat and monitoring tool with that property provided. I was aware about options passed to a launcher, so used -J prefix in the last, but... Imagine my wonder, that doesn't help. I still had a list of local JVMs w/o any trace of Tomcat, sought for.

Culprit of this was identified when I tried to do the same within native WindowZ' command shell. Yeah, it was working there. Obviously a poor CygWin does something weird indeed. Short investigation lead to the /etc/profile where some magic around the default temporary folder was found:

# TMP and TEMP as defined in the Windows environment must be kept
# for windows apps, even if started from cygwin. However, leaving
# them set to the default Windows temporary directory or unset
# can have unexpected consequences for cygwin apps, so we define 
# our own to match GNU/Linux behaviour.
ORIGINAL_TMP=$TMP
ORIGINAL_TEMP=$TEMP
unset TMP TEMP
tmp=$(cygpath -w "$ORIGINAL_TMP" 2> /dev/null)
temp=$(cygpath -w "$ORIGINAL_TEMP" 2> /dev/null)
TMP="/tmp"
TEMP="/tmp"

It is still unclear for me why it is there, and what stands behind comment quoted above. But when I comment out manipulation with TMP/TEMP variables, I managed to observe the Tomcat in a local JVM's list in JConsole, JVisualVM and Mission Control.

Funny. It seems like it is in my past life I had a discussion with one smart guy about virtual FS vs disk abstraction... And why a thought that design mistakes are most expensive mistakes in this world doesn't leave the mind? :)

No comments: