Wednesday, June 15, 2011

valgrind - dowloading, building and installing

First, I need to post all the links that will allow you to get to the creators information:

* WWW: http://valgrind.org
* Manual: http://valgrind.org/docs/manual/valgrind_manual.pdf
* Source: http://valgrind.org/downloads
* Building Instruction: http://valgrind.org/docs/manual/dist.readme.html

Building
* Download the source and put into your home account. Let's assume it is the valgrind-3.6.1 version.
Run these commands:

vver=valgrind-3.6.1
tar xf $vver.tar.bz2
cd $vver
ulimit -u 100 # ./configure has a bug ...
./configure --prefix=$HOME/valgrind # You need that in order to run make install without root privileges
make
make install
cd $HOME/valgrind/bin
./valgrind ls -l # see if it bombs out. If it does not you are good to go


Now, what you have is a $HOME/valgrind directory. If this is place where you want to use it then you are ready. The only one thing you need to do is set your path: export PATH=$HOME/valgrind/bin:$PATH

Ok... and what about if you need this valgrind now on a machine that does not have gcc?
The only thing you need to do is to pack the whole $HOME/valgrind directory, and copy it over to the destination machine.
The only caveat is that it has to be put into exactly the same directory as it was built in or else you will see this nice message:
valgrind: failed to start tool 'memcheck' for platform 'amd64-linux': No such file or directory

Solution - ln -s $HOME/valgrind path-to-valgrind-on-the-build-machine
Example: ln -s $HOME/valgrind /home/myhome/valgrind

Sunday, May 16, 2010

Internal Server Error when password protecting directory

Do you see something like that:???

Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.

Please contact the server administrator, webmaster@blahblah and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.


There is a very simple explanation but it took me lots of time to discover the reason. Well, I'm not as good as I would like to be ;)

The reason -> FILE PERMISSION!!!

All directories have to have +xr access for the web server. You may have to make o+xr them.
Also the .htpasswd and .htaccess have to be accessible for the web browser.

Here is my .htaccess in the directory I want to have password protected:

AuthUserFile /home/myhome/.htpasswds/.htpasswd
AuthName "Login Area"
AuthType Basic
require valid-user


Since the web server is 'hosted', so the best thing to do is to run the phpinfo() on the web browser (create p.php file and put <?php phpinfo(); ?> in it) and look for DOCUMENT_ROOT to see where really are your web files located.
Make sure that all the directories leading to .htpasswd and .htaccess are having proper 'read/execute' attributes (644)

Tuesday, May 11, 2010

Google Calendar compatible Catholic Calendar in US

http://www.google.com/calendar/embed?src=vfc9s2tq7ugm3qutnm823pu9ec@group.calendar.google.com&ctz=America/New_York

Thursday, January 14, 2010

ls using boost

Want to use boost and get list of files matching a mask. The same list you would obtain running ls in the command prompt?

The idea is to have something like this:


BOOST_FOREACH( const std::string& fname, ls( "./*.cpp" ))
std::cout << fname << std::endl ;


So here is the solution. One function and one helper function (to_regex_copy()):


std::string to_regex_copy( std::string mask )
{
std::string rv = boost::regex_replace( boost::regex_replace( boost::regex_replace( mask, boost::regex( "\\." ), "\\\\." ), boost::regex( "\\?" ), "\\." ), boost::regex( "\\*" ), "\\.*" ) ;
return rv ;
}

std::vector< std::string > ls( const char* pcszMask )
{
namespace fs = boost::filesystem ;
boost::filesystem::path path ;
boost::regex mask ;
if ( fs::is_directory( pcszMask ))
{
path = pcszMask ;
mask = ".*" ;
}
else
{
path = fs::path( pcszMask ).remove_filename() ;
mask = to_regex_copy( fs::path( pcszMask ).filename()) ;
}

std::vector< std::string > rv ;
try
{
for ( fs::directory_iterator p(path), e; p!=e; ++p)
{
if ( boost::regex_match( p->filename(), mask ))
rv.push_back( p->filename()) ;
}
}
catch( ... )
{
}

return rv ;
}

Tuesday, January 12, 2010

Profiling shared library on Linux using sprof

It's not as easy as one would/should expect. (Read here about valgrind if you don't want to use sprof.)

First - FORGET ABOUT gprof. gprof is used for the applications but will NOT WORK for shared libraries. Sorry about that. I learned about it the hard way. What you need to use is sprof.

Second - sprof may make you bite your fingers if your glibc library is not up-to-date. It will be displaying the nasty message: "sprof: failed to load shared object"
If this is what you see then you HAVE TO update your glibc. Read about the bug: here. It may not be as simple to upgrade as well... If I have time I will write how to do it through the .iso file (if you have one.)

Third - Yes, as it is not enough, there is an other surprize! The -pg option works well for gprof, but screws up things for sprof! You need to remove this option in order to get proper results from the shared libraries. Otherwise you will get only zeroes as the execution time for the functions.

So, at the end, what to do?

Assuming you have the patch installed or you have glibc-2.5-34 or newer version installed do as follows (the best, in my opinion, way, assuming you have write access to the current directory.)

1) Compile your shared library (libmylib.so) in debug (-g) mode. No -pg.
2) export LD_PROFILE_OUTPUT=`pwd`
3) export LD_PROFILE=libmylib.so
4) rm -f $LD_PROFILE.profile
4) execute your program that loads libmylib.so
5) sprof PATH-TO-LIB/$LD_PROFILE $LD_PROFILE.profile -p >log
6) See the log.

I hope it will help you.

Friday, October 9, 2009

ssh, scp password-less connection

Below is possibly the simplest way it can be accomplished.
Simply enter username@ip-address, when asked after running this one-liner below:
printf "enter username@ip-address: " ; read UIP ; ssh $UIP "mkdir .ssh 2>/dev/null ; echo $(cat $HOME/.ssh/id_rsa.pub) >>.ssh/authorized_keys ; chmod 700 .ssh ; chmod 600 .ssh/authorized_keys" ; echo "hostname=$(ssh $UIP hostname)"
You should be done.
If everything was okay you should see the hostname command result run on the target.
From this moment, you can run your commands on the remote host by executing like this:
ssh username@ip-address "your command"
or copying files like that:
scp myfile username@ip-address:

Thursday, September 25, 2008

How do I find the name of the current shell that I am working in

There is a command that will work on all platforms I tested (HP-UX, SunOS, Linux, MacOS) and shells (sh,ksh,bash,csh,zsh)

ps -p $$ | grep $$ | awk '{ print $NF }'

Be aware that the shell name can be bash or -bash