Tuesday, April 15, 2008

nixCraft Linux Sys Admin Blog

nixCraft Linux Sys Admin Blog

Link to nixCraft Linux Sys Admin Blog

valgrind - Linux Tools For Debugging And Profiling Programs ( bug reporting tool )

Posted: 15 Apr 2008 07:21 PM CDT

Few days back I wrote about strace tool for reporting and finding bug in program. Today I'm going to talk about another interesting tool called valgrind.

Valgrind is a flexible program for debugging and profiling Linux executables. It consists of a core, which provides a synthetic CPU in software, and a series of "tools", each of which is a debugging or profiling tool. The architecture is modular, so that new tools can be created easily and without disturbing the existing structure. There are Valgrind tools that can automatically detect many memory management and threading bugs, and profile your programs in detail. You can also use Valgrind to build new tools.

The Valgrind distribution currently includes five production-quality tools:

  • a memory error detector
  • a thread error detector
  • a cache and branch-prediction profiler
  • a call-graph generating cache profiler
  • a heap profiler

It also includes two experimental tools:

  • a data race detector
  • an instant memory leak detector.

It runs on the following platforms:

  • X86/Linux
  • AMD64/Linux
  • PPC32/Linux
  • PPC64/Linux

How do I use valgrind?

Valgrind is typically run as follows:
$ valgrind command-name arg1 arg2 argN
$ valgrind program args
$ valgrind ./myapp -d /tmp -f 120

You can select tool using the --tool=TOOLName option. For example use memcheck which is a fine-grained memory checker. To generate trace back for command called myapp, enter:
$ valgrind --tool=memcheck -v --log-file=myapp.dbg --num-callers=8 ./myapp -d /tmp -f 120
Where,

  • --tool=memcheck : Run the Valgrind tool called memcheck
  • -v : Verbose output
  • --log-file=myapp.dbg : Specifies that Valgrind should send all of its messages to the specified file.
  • --num-callers=8 : By default, Valgrind shows twelve levels of function call names to help you identify program locations. You can change that number with this option. This can help in determining the program’s location in deeply-nested call chains.

The --leak-check option turns on the detailed memory leak detector:
$ valgrind --tool=memcheck -v --log-file=myapp.dbg --num-callers=8 --leak-check=yes ./myapp -d /tmp -f 120

Further readings:

Continue reading rest of the How to report / Find a bug under Linux series.

Contents
  1. Debugging Tip: Trace the Process and See What It is Doing with strace
  2. valgrind - Linux Tools For Debugging And Profiling Programs ( bug reporting tool )

Related Posts:



© valgrind - Linux Tools For Debugging And Profiling Programs ( bug reporting tool ) - nixCraft - Support nixCraft when you shop at amazon. Thanks!

mod_secdownload - Lighttpd Create Secure Download Area with Unique Download URL

Posted: 15 Apr 2008 06:35 PM CDT

Lighttpd handle secured download mechanisms using mod_secdownload modules. It uses the lighttpd webserver and the internal HTTP authentication using secrete password. This module use the concept called authenticated URL for a specified time. Each unique url remains valid for a specified time.

Your application has to generate a token and a timestamp which are checked by the webserver before it allows the file to be downloaded by the webserver.

URL Format

The generated URL has to have the format:

<uri-prefix>/<token>/<timestamp-in-hex>/<rel-path>

Which looks like
http://theos.in/dl/6262df3adba2bc85846e05440fcc3895/4804f986/file.zip

is an MD5 of

  • a secret string (user supplied)
  • <rel-path> (starts with /)
  • <timestamp-in-hex>

Understanding filesystem layout

  • Domain name: theos.in
  • Webroot : /home/lighttpd/theos.in/http/
  • Download location : /home/lighttpd/download-area/ (you must upload all download files here)
  • Download url : http://theos.in/dl/<token>/<timestamp-in-hex>/file.zip

Make sure /home/lighttpd/download-area/ directory exists:
# mkdir -p /home/lighttpd/download-area/
# chown lighttpd:lighttpd /home/lighttpd/download-area/

Configuration

Open lighttpd.conf file:
# vi /etc/lighttpd/lighttpd.conf
Append following configuration:

secdownload.secret          = "MySecretSecurePassword" secdownload.document-root   = "/home/lighttpd/download-area/" secdownload.uri-prefix      = "/dl/" secdownload.timeout         = 3600

Where.

  • secdownload.secret : Your password; it must not be shared with anyone else
  • secdownload.document-root : Download file system location, must be outside domain webroot / documentroot
  • secdownload.uri-prefix : url prefix such as /dl/ or /download/
  • secdownload.timeout : Set timeout for each unique url in seconds

Save and close the file. Restart lighttpd:
# service lighttpd restart

Sample PHP Download Script

<?php $secret = "MySecretSecurePassword"; $uri_prefix = "/dl/";   # set filename $f = "/file.zip";   # set current timestamp $t = time(); $t_hex = sprintf("%08x", $t); $m = md5($secret.$f.$t_hex); # finally generate link and display back on screen printf('<a href="%s%s/%s%s" class="broken_link">%s</a>',$uri_prefix, $m, $t_hex, $f, $f); ?>

410 Gone HTTP Error Code

After timeout; unique url will be gone and end user will get 410 http status code. It indicates that the resource requested is no longer available and will not be available again. So if anybody deeplinked or hotlinked your content it will be gone after timeout.

Further readings:

Related Posts:



© mod_secdownload - Lighttpd Create Secure Download Area with Unique Download URL - nixCraft - Support nixCraft when you shop at amazon. Thanks!

The missing five-minute Linux manual for morons

Posted: 15 Apr 2008 04:32 PM CDT

From the article:

Stob It is time to wake up and smell the elephant in the room. Vista is struggling to achieve escape velocity. Microsoft finds itself the butt an international joke, but does not seem able to get a grip. The issue of choice of platform is once more up for grabs.
Of course there is an alternative; a popular computing platform whose design attracts universal admiration. But although we all look forward to literally punching in the numbers, the Wii does not yet quite hack it (use of a dread phrase coming up) 'in the enterprise'.
So, for the time being, I'm afraid we are all back on re-evaluation-of-Linux duty. Never mind. I've already done the spadework. Let me lead you through a few simple steps to a full-on Open Source experience.

=> The missing five-minute Linux manual for morons

Related Posts:



© The missing five-minute Linux manual for morons - nixCraft - Support nixCraft when you shop at amazon. Thanks!

No comments: