old-www/LDP/LG/issue81/TWDT.html

8135 lines
318 KiB
HTML
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE> Linux Gazette Table of Contents LG #81</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#0000AF"
ALINK="#FF0000" >
<center>
<!-- A HREF="http://www.linuxgazette.com/">
<H1><IMG SRC="../gx/newlogo.jpg" ALT="LINUX GAZETTE" border="0"></H1></A> -->
<A HREF="http://www.linuxgazette.com/">
<H1><IMG ALT="LINUX GAZETTE" SRC="../gx/lglogo.png"
WIDTH="600" HEIGHT="124" border="0"></H1></A>
<H2>August 2002, Issue 81 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
Published by <I>Linux Journal</I></H2>
<A HREF="../index.html">Front Page</A> &nbsp;|&nbsp;
<A HREF="../index.html">Back Issues</A> &nbsp;|&nbsp;
<A HREF="../lg_faq.html">FAQ</A> &nbsp;|&nbsp;
<A HREF="../mirrors.html">Mirrors</A> <!-- &nbsp;|&nbsp; --><BR>
<A HREF="../tag/kb.html">The Answer Gang knowledge base</A> (your Linux questions here!) <!-- &nbsp;|&nbsp; --><BR>
<A HREF="http://www.linuxgazette.com/search.html">Search (www.linuxgazette.com)</A>
<!-- *** BEGIN mirror site search link *** -->
<!-- &nbsp; <A HREF="http://www.linuxgazette.com/search.html">(SITE.COM
mirror)</A> -->
<!-- *** END mirror site search link *** -->
</CENTER>
<HR NOSHADE>
<!--=================================================================-->
<!-- H1><font color="#BB0000">Table of Contents:</font></H1 -->
<!-- *** BEGIN toc *** -->
<UL>
<LI> <a HREF="lg_mail.html">The MailBag</A>
<LI> <a HREF="lg_tips.html">More 2-Cent Tips</A>
<LI> <a HREF="lg_answer.html">The Answer Gang</A>
<LI> <a HREF="lg_bytes.html">News Bytes</A>
<LI> <a HREF="adam.html">The Weekend Mechanic</A> , <EM>by Thomas Adam</EM>
<LI> <a HREF="adam2.html">Introduction to Programming Ada</A> , <EM>by Thomas Adam</EM>
<LI> <a HREF="arndt.html">Office Linux: Ideas for a Desktop Distribution</A> , <EM>by Matthias Arndt</EM>
<LI> <a HREF="durodola.html">Playing DVDs on Linux</A> , <EM>by Tunji Durodola</EM>
<LI> <a HREF="kurup.html">Is Your Memory Not What It Used To Be?</A> , <EM>by Madhu M Kurup</EM>
<LI> <a HREF="padala.html">Exploring Perl Modules - Part 1: On-The-Fly Graphics with GD</A> , <EM>by Pradeep Padala</EM>
<LI> <a HREF="ramankutty.html">Programming in Ruby, part 1</A> , <EM>by Hiran Ramankutty</EM>
<LI> <a HREF="sandeep.html">Process Tracing Using Ptrace</A> , <EM>by Sandeep S</EM>
<LI> <a HREF="sevenich.html">Secure and Robust Computer Systems for Primary and Secondary Schools</A> , <EM>by Richard A Sevenich and Michael P Angelo</EM>
<LI> <a HREF="tougher.html">Creating Reusable Software Libraries</A> , <EM>by Rob Tougher</EM>
<LI> <a HREF="vikas.html">SysRq: The Process-nuke</A> , <EM>by Vikas G P</EM>
<LI> <a HREF="lg_backpage.html">The Back Page</A>
</UL>
<!-- *** END toc *** -->
<HR NOSHADE>
<!--=================================================================-->
<H3 ALIGN="center"><EM>Linux Gazette</EM> Staff and The Answer Gang</H3>
<BLOCKQUOTE>
<STRONG>Editor:</STRONG> Michael Orr<BR>
<STRONG>Technical Editor:</STRONG> Heather Stern<BR>
<STRONG>Senior Contributing Editor:</STRONG> Jim Dennis<BR>
<STRONG>Contributing Editors:</STRONG>
Ben Okopnik, Dan Wilder, Don Marti
</BLOCKQUOTE>
<HR NOSHADE>
<!--=================================================================-->
<A HREF="TWDT.txt.gz">TWDT 1 (gzipped text file)</A><BR>
<A HREF="TWDT.html">TWDT 2 (HTML file)</A><BR>
are files containing the entire issue: one in text format, one in HTML.
They are provided
strictly as a way to save the contents as one file for later printing in
the format of your choice;
there is no guarantee of working links in the HTML version.
<HR NOSHADE>
<!--=================================================================-->
<center>
<I>Linux Gazette</I><img alt="[tm]" src="../gx/tm.gif">,
<A HREF="http://www.linuxgazette.com/">http://www.linuxgazette.com/</A><BR>
This page maintained by the Editor of <I>Linux Gazette</I>,
<A HREF="mailto: gazette@ssc.com"> gazette@ssc.com</A>
<P>
<H5>Copyright &copy; 1996-2002 Specialized Systems Consultants, Inc.</H5>
</center>
<HR NOSHADE>
<!--=================================================================-->
<center>
<H1><A NAME="wanted"><IMG ALIGN=MIDDLE ALT="" SRC="../gx/mailbox.gif">
The Mailbag</A></H1> <BR>
<!-- BEGIN wanted -->
</center>
<P> <hr> <P>
<!-- =================================================================== -->
<center><H3><font color="maroon">HELP WANTED : Article Ideas</font></H3></center>
<P>
<P> Send tech-support questions, Tips, answers and article ideas to The Answer Gang
&lt;<A HREF="mailto:linux-questions-only@ssc.com"
>linux-questions-only@ssc.com</A>&gt;. Other mail (including
questions or comments about the <EM>Gazette</EM> itself) should go to
&lt;<A HREF="mailto:gazette@ssc.com">gazette@ssc.com</A>&gt;. All material
sent to either of these addresses will be considered for publication in the
next issue. <EM>Please send answers to the original querent too, so that s/he
can get the answer without waiting for the next issue.</EM>
<P> Unanswered questions might appear here. Questions with
answers--or answers only--appear in The Answer Gang, 2-Cent Tips, or here,
depending on their content. There is no guarantee that questions will
<em>ever</em> be answered, especially if not related to Linux.
<P> <STRONG>Before asking a question, please check the
<A HREF="../faq/index.html"><I>Linux Gazette</I> FAQ</A> (for questions about the
Gazette) or <A HREF="../tag/kb.html">The Answer Gang Knowledge Base</A> (for
questions about Linux) to see if it has been
answered there.</STRONG>
<P> <HR> <P>
<!--====================================================================-->
<!-- BEGIN HELP WANTED : Article Ideas -->
<UL>
<!-- index_text begins -->
<li><A HREF="#wanted/1"
><strong>Linux terminal services server can't connect to internet via network</strong></a>
<li><A HREF="#wanted/2"
><strong>Pls Help (Squid/2000)</strong></a>
<li><A HREF="#wanted/3"
><strong>suggestion for link...</strong></a>
<li><A HREF="#wanted/4"
><strong>Finding a Windows user's home directory from Linux</strong></a>
<li><A HREF="#wanted/5"
><strong>article idea - making the minidistro</strong></a>
<!-- index_text ends -->
</UL>
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="wanted/1"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">Linux terminal services server can't connect to internet via network</FONT></H3>
Tue, 02 Jul 2002 12:22:11 -0500
<BR>pat ring (<a href="mailto:linux-questions-only@ssc.com?cc=pat_ring@hotmail.com&subject=%20Re%3A%20%5BLG%2081%5D%20help%20wanted%20%231">pat_ring from hotmail.com</a>)
<!-- sig -->
<!-- sig -->
<P>
Great eZine. I think the typos, editorial asides and comments, and rough
edits are endearing and "personalizing" experience for the linux
enthusiasts. Your nitpicking detractors obviously are ignorant of the fact
that LG is a labor of love in what seems to be in the spirit of the open
source environment. I know this is a terribly long-winded question, so I
apologize in advance.
</P>
<blockquote><font color="#000066">Thanks, Pat. As for long questions, it's okay. We like that you
actually made some effort ahead of time. In fact since we didn't reply
to your detailed request I have to assume we're stumped, so I'm letting
the readers take a crack at it.
-- Heather</font></blockquote>
<P>
I have a stumper that I can't seem to get answered. I suspect this is more
of a two-NIC network question than a LTSP or K12LTSP question.
</P>
<P>
I have been testing terminal services. I couldn't really get the actual
LTSP working properly (something wrong with X on the client that I couldn't
figure out,) so I downloaded and installed the K12LTSP version of Redhat7.2.
</P>
<P>
This is a great version that offers LTSP as an install option and it works
great right out of the box. My clients log right in and can utilize
terminal services perfectly. However, on my normal installations of Redhat,
I can assign a static IP to the linux PC and use my Win2K gateway to surf
the internet. But when I install the LTSP'ized version with two NICs, I can
ping the gateway, the gateway can ping the LTSP server, but I can't surf the
internet. I think I've tried just about everything to try and use the
gateway for internet access. If I can get the LTSP server on the internet
via the gateway, then I believe the LTSP clients will fall into place, as
well.
</P>
<P>
Some details.
</P>
<P>
My network "server" is actually a Win2k PC with internet connection sharing.
</P>
<P>
I use VNC to virtually connect to the gateway to open and close dial in
connections to the internet. I have to use win2k because I need an
"internet answering machine" to answer the phone when I am online and there
is no linux support in this area (living in the sticks, as I do, also makes
separate lines very much cost prohibitive for dial in access to the
internet.)
</P>
<P>
The terminal services PC has two NICs. ETH0 attached to the terminal
services clients via a 3com switch. ETH1 is attached via an additional
switch to my network.
</P>
<P>
I might have a problem with the way the subnets are setup:
</P>
<P><BLOCKQuote>
ETH0 is assigned by the K12LTSP default install to 192.168.0.254 and serves
the LTSP clients .100 to .253.
</BLOCKQuote></P>
<P>
ETH1 also gets its 192.168.0.x IP address either manually or through DHCP
from the network. It doesn't matter if I manually assign the IP or let DHCP
handle the IP asignment, but I have known for years that if I let DHCP
handle the assignment, I can't surf, so I just use 192.168.0.88. This may
be because the DHCP services via Windows Internet COnnection Sharing aren't
really full DHCP.
</P>
<P>
My win2k gateway PC is 192.168.0.1 and I always enter this address as the
DNS server.
</P>
<P>
I tried to manually change the LTSP subnet on ETH0 to 192.168.1.254, etc.,
but I'm not sure this is the problem. Does the fact that the two subnets
are using the same subnet scheme create the problem? I could see if the
clients couldn't surf, then that may be the case, but the LTSP gateway can't
surf.
</P>
<P>
After about 30 installs, different configurations, etc., I'm not sure where
to go further with this issue. Can I provide some conf files that might
give you an idea of where I need to go? Is this DNS or a route problem?
Can the same IP adress scheme be used because the subnets are on different
NICs, or is this the problem? Can you push me in the right direction of
where to get some help?
</P>
<P>
Thanks for your help.
</P>
<!-- end 1 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="wanted/2"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">Pls Help (Squid/2000)</FONT></H3>
Tue, 16 Jul 2002 17:03:21 +0530
<BR>Vikas Kanodia (<a href="mailto:linux-questions-only@ssc.com?cc=vikas@rocsearch.com&subject=%20Re%3A%20%5BLG%2081%5D%20help%20wanted%20%232">vikas from rocsearch.com</a>)
<!-- sig -->
<!-- sig -->
<P>
Hello ,
</P>
<P>
I've installed Squid-2.5.PRE8 &amp; Samba 2.2.5 on RedHat Linux 7.1.So i wanted
to authenticate windows 2000 users in Squid.So i've install the Winbind &amp;
configure as per the documentation available on the net , link is attached
pls see(Authentication tab).
<A HREF="http://www.squid-cache.org/Doc/FAQ/FAQ-23.html#ss23.5"
>http://www.squid-cache.org/Doc/FAQ/FAQ-23.html#ss23.5</A>
&lt;<A HREF="http://www.squid-cache.org/Doc/FAQ/FAQ-23.html#ss23.5&gt"
>http://www.squid-cache.org/Doc/FAQ/FAQ-23.html#ss23.5&gt</A>;
</P>
<P>
After doing all the things successfully...when i run the squid it gives the
message like this...
</P>
<blockquote><pre>[root@gnspl-prx bin]# ./squid
2002/07/15 10:46:23| Parsing Config File: Unknown authentication scheme 'ntlm'.
2002/07/15 10:46:23| Parsing Config File: Unknown authentication scheme 'ntlm'.
2002/07/15 10:46:23| Parsing Config File: Unknown authentication scheme 'ntlm'.
2002/07/15 10:46:23| Parsing Config File: Unknown authentication scheme 'ntlm'.
2002/07/15 10:46:23| squid.conf line 1746: http_access allow manager localhost localh
2002/07/15 10:46:23| aclParseAccessLine: ACL name 'localh' not found.
2002/07/15 10:46:23| aclParseAclLine: IGNORING: Proxy Auth ACL 'acl AuthorizedUsers
proxy_auth REQUIRED' because no authentication schemes are fully configured.
2002/07/15 10:46:23| aclParseAclLine: IGNORING invalid ACL: acl AuthorizedUsers
proxy_auth REQUIRED
2002/07/15 10:46:23| squid.conf line 1751: http_access allow all AuthorizedUsers
2002/07/15 10:46:23| aclParseAccessLine: ACL name 'AuthorizedUsers' not found.
2002/07/15 10:46:23| Squid is already running! Process ID 9957
[root@gnspl-prx bin]#
</pre></blockquote>
<P>
Pls guide me...
</P>
<P>
Thanks.
</P>
<P>
Regards,
<BR>Vikas Kanodia
</P>
<blockquote><font color="#000066">This is a bit more complicated than the stuff Thomas' "Weekend Mechanic"
column covered in issue 78
(<A HREF="../issue78/adam.html"
>http://www.linuxgazette.com/issue78/adam.html</A>) -- anybody care to help
him out?
</font></blockquote>
<blockquote><font color="#000066">Some articles on living the life of a Windows server when you're really
a Linux box would be cool, too.
-- Heather</font></blockquote>
<!-- end 2 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="wanted/3"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">suggestion for link...</FONT></H3>
28 Jul 2002 23:10:53 -0400
<BR>D. Goel (<a href="mailto:linux-questions-only@ssc.com?cc=deego@glue.umd.edu&subject=%20Re%3A%20%5BLG%2081%5D%20help%20wanted%20%233">deego from glue.umd.edu</a>)
<P>
hi
</P>
<P>
i went to www.linuxgazette.com and tried to find a 'subscribe to paper
version' link to send to a coworker, but could not find one.
</P>
<P>
if you could please let me know of such a site, and include a link to
it on the main page..
<IMG SRC="../gx/dennis/smily.gif" ALT=":)"
height="24" width="20" align="middle">
</P>
<P>
DG
</P>
<blockquote><font color="#000066">Maybe we should put a link on the mirrors page about paper copies to the
FAQ entry for which formats <EM>LG</EM> isn't available in, since it describes
how to make quality printouts.
-- Heather</font></blockquote>
<blockquote><font color="#001F3F">Attention publishers, there continues to be high demand for a print version
of <EM>LG</EM> .
</font></blockquote>
<blockquote><font color="#001F3F"><EM>LG</EM> is not available in printed format. Since it's freely redistributable,
anybody has the right to offer this service. Since nobody has done this in the
six years <EM>LG</EM> has been in existence, even though there have been numerous
requests, one has to consider why. It costs money to print and deliver a paper
version, and the subscription rate would be higher than most people would be
willing to pay. Those outside the publisher's own country or region can forget
it; the mailing cost alone would be prohibitably high. Plus there's the
labor-intensive world of "subscription fulfillment": taking down names and
addresses, processing payments, updating addresses, etc. It can't all be
automated, unless you can somehow wave a wand and get everybody to fill out the
forms perfectly correctly every time.
</font></blockquote>
<blockquote><font color="#001F3F">Commercial magazines can justify all these costs by building a business around
selling advertisement space, but <EM>LG</EM> does not accept advertisements.
<EM>Consumer Reports</EM> don't accept advertising either, but again they have built a whole
business around it. One can't see the incentive for building such a business
around <EM>Linux Gazette</EM> , especially since Linux print magazines are already
available. (Unashamed plug for <EM>Linux Journal</EM> .)
-- Mike</font></blockquote>
<!-- end 3 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="wanted/4"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">Finding a Windows user's home directory from Linux</FONT></H3>
Wed, 10 Jul 2002 11:13:39 -0600
<BR>Dee Abson (<a href="mailto:linux-questions-only@ssc.com?cc=dee.abson@sait.ab.ca&subject=%20Re%3A%20%5BLG%2081%5D%20help%20wanted%20%234">dee.abson from sait.ab.ca</a>)
<!-- sig -->
<!-- sig -->
<P>
Greetings,
</P>
<P>
I've decided to try and integrate a RedHat 7.3 computer into our Windows NT
domain based network, going for that brass ring of single sign-on and
integrating the Windows necessities - access to Windows print queues and
Windows file servers.
</P>
<P>
I have successfully implemented winbind (and samba, natch) under RedHat 7.3
and am now able to log on using a Windows domain based user name and
password. Through a little more research and such, I have Linux configured
so the user directory is setup automatically when the Windows user logs in
for the first time, printconf makes it easy to connect to an SMB-based print
queue and LinNeighborhood helps locate and mount SMB file shares. The only
missing piece of the puzzle, as far as I'm concerned at the moment, is
mapping the Windows user's home directory (which is a share on an SMB
server) to a subfolder under their Linux home directory. I'm certain that I
can accomplish the automatic mapping using the PAM module pam_mount
(available at <A HREF="http://pam-mount.conectevil.com"
>http://pam-mount.conectevil.com</A> if anyone's interested in a
look), it's retrieving the user's Windows home directory that eludes me.
</P>
<P>
Thus my question is this: How can I retrieve the Windows user's home
directory, that elusive little string that will complete my puzzle, from my
<A HREF="http://www.redhat.com/">Red Hat</A> system?
</P>
<P>
Many thanks,
<BR>Dee Abson, MCSE
</P>
<blockquote><font color="#000066">Okay, this question has two parts. As an MCSE he may already know where
MSwin keeps this valuable information stored; what he needs to know is
how to make Linux properly ask for it, or dig it up across the shares.
</font></blockquote>
<blockquote><font color="#000066">It wouldn't be as easy as running 'grep' against some plaintext file, or
maybe in a pipeline combined with 'strings'... would it? If it would,
is that a security problem?
</font></blockquote>
<blockquote><font color="#000066">p.s. Don't attach HTML along with the plaintext. It's so messy and sent
3 times the text for the exact same message.
-- Heather</font></blockquote>
<!-- end 4 -->
<!-- . . . . . . . . . . . . . . . . . . . -->
<HR WIDTH="40%" ALIGN="center">
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">article idea - making the minidistro</FONT></H3>
Mon, 8 Jul 2002 14:25:24 -0400
<BR>Tony Tonchev (<a href="mailto:linux-questions-only@ssc.com?cc=tony@stclaire.com&subject=%20Re%3A%20%5BLG%2081%5D%20help%20wanted%20%235">tony from stclaire.com</a>)
<!-- sig -->
<!-- sig -->
<P>
Hi,
</P>
<P>
This article idea may sound silly. I don't even know how to describe the
topic, but here it goes...
</P>
<P>
For some time now, I've been thinking of developing a minimal/modular
Linux distribution designed to allow small businesses to use Linux for
their server needs rather then the M$ solutions. This idea is inspired
partially by PizzaBox file server that Kyzo
(<A HREF="http://www.kyzo.com/free_stuff.html"
>http://www.kyzo.com/free_stuff.html</A>) made available a few years ago,
but their product is crippled and not Open Source. The same is partially
true for <A HREF="http://www.guardiandigital.com"
>http://www.guardiandigital.com</A> and their excellent product.
</P>
<P>
Anyway, my problem is that I don't know where to start. I've looked at
"Linux From Scratch" and "BYO Linux", but the most helpful information
came from "Building Tiny Linux Systems with Busybox" Parts 1 through 3,
published in ELJ. The three articles did help me understand some
fundamentals and allowed me to actually plan my next step more
intelligently.
</P>
<P>
Imagine having a modular Linux-based server that consists of a core and
modules. The core will contain the basic services (kernel, security,
networking, dhcp, etc. Web-based administration of all services should
be available as well as equivalent console-based administration. Typical
Modules will be a Web Server module, Workgroup File Server module, Mail
Server module, Firewall module, FTP module, etc. All modules should be
independent of each other and include their respective web and
console-based administration components.
</P>
<P>
In other words if I want just a file server, then I install the core and
file server module only. If I want a file and mail server then I install
the core, file and mail modules and that's it.
</P>
<P>
Here is yet another requirement: The core and all modules must have the
smallest possible memory footprint reasonably possible. I like uClibc,
BusyBox and TinyLogin because they all fit on a floppy. Why can't the
core and each installable module fit on one or two installation
floppies? That will be easy to download and install unlike a 600meg ISO.
</P>
<P>
As you can probably tell, I know where I want to go, but don't know how
to get there. Maybe my whole idea is flawed due to my lack of knowledge.
An article or articles on how to build that unique Linux
mini-distribution will be great.
</P>
<P>
Whew...
</P>
<P>
Thanks for the time
</P>
<P>
Tony Tonchev
</P>
<blockquote><font color="#000066">Hmm, let me see if I have this right. You want to be able to do all
these cool things, where maybe the real core fits on one floppy, and
maybe each "module" as you put it (not to be confused with kernel
modules) fits on a floppy of its own. Load up enough of them and you
have the dream server, which fit in your lunchbox or purse.
</font></blockquote>
<blockquote><font color="#000066">I note that a 196 MB cd-rom fits in the same space as one floppy (except
that it's slimmer). But you're right - watching someone take us through
this process of development would be a great article.
</font></blockquote>
<blockquote><font color="#000066">You may want to keep an eye on current development in the LNX-BBC
project. Nope, it has nothing to do with Britain's prime television station.
It's what happens when you use cloop compression to cram a fairly usable
Linux setup on a 50 MB "bootable business card" . Think LNX = squished
LiNuX. Since you're interested in rolling your own, I recommend reading
about the new GAR setup and, quite literally, checking it out.
(<A HREF="http://www.lnx-bbc.org"
>http://www.lnx-bbc.org</A>)
</font></blockquote>
<blockquote><font color="#000066">There are piles of specialized "mini distros" out there. This request
clearly aims towards the general use setup. A making-of article for any of
the minis might be fun to see, though.
-- Heather</font></blockquote>
<!-- end 5 -->
<a name="mailbag"></a>
<P> <hr> <P>
<!-- =================================================================== -->
<center><H3><font color="maroon">GENERAL MAIL</font></H3></center>
<P> <HR> <P>
<!--====================================================================-->
<!-- BEGIN GENERAL MAIL -->
<UL>
<!-- index_text begins -->
<li><A HREF="#mailbag/1"
><strong>IMAP</strong></a>
<li><A HREF="#mailbag/2"
><strong>LG #80: add to `Red Hat and USB devices'</strong></a>
<li><A HREF="#mailbag/4"
><strong>Using debug to write fresh MBR</strong></a>
<li><A HREF="#mailbag/5"
><strong>Mirrors</strong></a>
<li><A HREF="#mailbag/6"
><strong>Re: [LG 76] mailbag #1 cybercoffee shop</strong></a>
<li><A HREF="#mailbag/7"
><strong>Sweet...</strong></a>
<li><A HREF="#mailbag/8"
><strong>Ideas, huh?</strong></a>
<!-- index_text ends -->
</UL>
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="mailbag/1"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">IMAP</FONT></H3>
Mon, 1 Jul 2002 08:37:14 -0400
<BR>Scott Sharkey (<a href="mailto:gazette@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%20mailbag%20%231%20IMAP">ssharkey from linuxunlimited.com</a>)
<P>
Hi Heather,
</P>
<P>
Just read your TAG about IMAP. You're right that Courier-IMAP is the
best.... run ith with Postfix instead of sendmail and you'll be even
happier. Then mix in Sqwebmail (from Courier's author) and you'll
be REALLY spoiled.
</P>
<P>
Just for grins, I mixed in OpenLDAP, and now have a server with
no Unix accounts, full IMAP/Pop/WebMail capability, and very
easy to maintain.
</P>
<P>
I use sylpheed as a mail client so far -- gotta try Evolution
sometime. The OpenLDAP handles the address book too.
</P>
<P>
-Scott
</P>
<!-- end 1 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="mailbag/2"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">LG #80: add to `Red Hat and USB devices'</FONT></H3>
Mon, 01 Jul 2002 14:39:17 +0100
<BR>Daniel Baumann (<a href="mailto:gazette@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%20mailbag%20%232%20Red%20Hat%20and%20USB">danielbaumann from linuxmail.org</a>)
<P>
hi lg team,
</P>
<P>
i have a little add to the article `<A HREF="http://www.redhat.com/">Red Hat</A> and USB devices' in you current issue.
</P>
<P>
the missed kernel config files from the different redhat default kernels are located
in <TT>/usr/src/linux-*/configs.</TT>
</P>
<P>
greetings,
daniel
</P>
<blockquote><font color="#000066">Normally I don't leave sig blocks in, but since we occasionally get
requests asking us about free ISPs who cater to linux users... this
isn't specifically an endorsement, but you're all welcome to go look.
-- Heather</font></blockquote>
<P>
Get your free email from www.linuxmail.org
</P>
<!-- end 2 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="mailbag/4"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">Using debug to write fresh MBR</FONT></H3>
Wed, 3 Jul 2002 18:53:23 -0400
<BR>Ben Okopnik (<a href="mailto:gazette@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%20mailbag%20%234%20MBR%20rewrite">the <em>LG</em> Answer Gang</a>)
<P>
A recent follow-up to my MBR-rewriting article: a guy who had an E:
drive (yup, Wind*ws) that he wanted to blow off contacted me - seems
that Partition Magic wouldn't touch it as it was. He either didn't want
to or didn't know how to open up the machine and swap cables, so I
tweaked that debug program for him:
</P>
<blockquote><pre>Original
-----------
mov dx,9000
mov es,dx
xor bx,bx
mov cx,0001
mov dx,0080
mov ax,0301
int 13
int 20
-----------
</pre></blockquote>
<P>
Change the numbers in "mov dx,0080" for the appropriate drive:
</P>
<blockquote><pre>hda C: 0080
hdb D: 0081
hdc E: 0082
</pre></blockquote>
<P>
Worked like a charm, according to the very happy fella.
</P>
<!-- end 4 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="mailbag/5"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">Mirrors</FONT></H3>
Sat, 06 Jul 2002 00:45:22 +0000
<BR>Daniel Young (<a href="mailto:gazette@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%20mailbag%20%235%20mirrors">alandanielyoung from hotmail.com</a>)
<P>
A question.
Do you pay your Mirrors?
</P>
<blockquote><font color="#000066">No.
</font></blockquote>
<blockquote><font color="#000066">They don't pay us, either.
</font></blockquote>
<blockquote><font color="#000066">-- Dan Wilder
</font></blockquote>
<blockquote><font color="#001F3F">No. The mirrors are run by people who want to host a mirror.
</font></blockquote>
<blockquote><font color="#001F3F">You didn't ask, but none of the LG staff is paid either, we're all volunteers.
I'm the only one who's "paid", but paid in the sense that SSC donates some
of my work time to LG. (I normally do web application and sysadmin stuff for
<I>Linux Journal</I>.)
</font></blockquote>
<blockquote><font color="#001F3F">-- Mike Orr, Editor, Linux Gazette
</font></blockquote>
<!-- end 5 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="mailbag/6"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">Re: [LG 76] mailbag #1 cybercoffee shop</FONT></H3>
Wed, 10 Jul 2002 13:43:00 -0700
<BR>sandra (<a href="mailto:gazette@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%20mailbag%20%236%20cybercoffee%20shop">sfg from peak.org</a>)
<P>
I just want to make a small mention of our own little cybercafe... we're
not gurus but we're definitely geeks here.
<IMG SRC="../gx/dennis/smily.gif" ALT=":)"
height="24" width="20" align="middle">
</P>
<P>
Sandra Guzdek (waving hi to Heather Stern)
<br>Sip N Surf Cybercafe
<br>Eugene, OR
</P>
<blockquote><font color="#000066">Hi Sandra! (Sandra is the webmaster at one of my client sites.)
Thanks to Sandra I also found a really cool search engine specific to hunting
up internet coffeshops and kiosks - <A HREF="http://cybercaptive.com"
>http://cybercaptive.com</A> - which may be
a little spotty since it relies on visitor reports, but at least it's
international in scope. I was kind of amused when I looked up San Jose and
had to pick through the entries checking that I was finding places in California.
-- Heather</font></blockquote>
<!-- end 6 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="mailbag/7"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">Sweet...</FONT></H3>
Wed, 17 Jul 2002 19:59:29 -0500
<BR>Tim Chase (<a href="mailto:gazette@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%20mailbag%20%237%20sweet">gumnos from hotmail.com</a>)
<P>
As a long time self-taught user of Linux/Unix/Ultrix (and several other
flavours), I've become addicted to such handy tools as vi, grep, sed, awk,
ctags, and the bazillion other little utilities that can be so artisticly
chained together to produce the desired results. I've stumbled across your
LG archives, and all I can say is "WOAH!" I'm going to have to find myself
a text-to-speech translator so I can read/listen-to all of this good stuff
whilst at work, because there's just so much in here. Thanks for such a
fabulous (and fun!) resource...
</P>
<P>
-tim chase
</P>
<blockquote><font color="#000066">On behald of everbody here, THANKS! BTW, I've heard festival
(<A HREF="http://www.cstr.ed.ac.uk/projects/festival"
>http://www.cstr.ed.ac.uk/projects/festival</A>) is pretty
nice. Lots of things at Freshmeat that are supposed to use speech
really use either it or ViaVoice under the hood.
-- Heather</font></blockquote>
<!-- end 7 -->
<!-- . . . . . . . . . . . . . . . . . . . -->
<HR WIDTH="40%" ALIGN="center">
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/envelope.gif">
<FONT COLOR="navy">Ideas, huh?</FONT></H3>
Fri, 19 Jul 2002 22:12:14 -0700
<BR>The Gaijin (<a href="mailto:gazette@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%20mailbag%20%238%20homebrew%20hardware">blades from inreach.com</a>)
<P>
Home-brew hardware plans! Genertic GPL motherboard designs, SCSI
cards, video, audio, PCI modems, NICs...everything Microsoft is trying
to corner the market on. Some people feel Linux has only ten good years
left if the current trend continues.
</P>
<blockquote><font color="#1F1F1F">Some people believe that the Moon is made of green cheese and that
big-bellied Santa Claus (with a sack of presents, no less) comes down a
foot-wide chimney. "Other people are/think/do" is a very poor reason for
doing something; I prefer to believe that people are _not_ sheep.
-- Ben</font></blockquote>
<P>
Since the anti-trust suit,
Microsoft's political contribution budget has gone from $100,000 per
year to over $6.1 million, and now they're trying to get manufacturers
to implement Microsoft-specific anti-piracy security measures directly
at the hardware level (called "Paladium").
</P>
<blockquote><font color="#1F1F1F">And those who do will end up in the same toilet as the winmodem/
winprinter manufacturers: the domain of the ignorant. I think that
lesson has been well ingrained. There's a small market out there that
sells to the gullible, but the whole world certainly isn't about to
switch <EM>en masse</EM>.
-- Ben</font></blockquote>
<P>
The only true solution I can see is to go back to the days of
bread-boarding our own hardware in Dad's garage...public domain circuit
designs from electronic hobbyist magazines and soldering irons. We've
"de-marketized" software. Why not the hardware, too? If we can create
the greatest operating system on the planet, imagine what Linux users
can do with computers themselves. It would be nice to have something no
organization or agency can legally touch or ruin for a buck. A
collection of Linux-friendly hardware diagrams in the public domain that
anyone can produce for the cost of parts alone. Our own hardware would
completely end our dependency on third-party drivers and vulnerability
to corporate rail-roading. I think creating our own hardware database
would be the best move we could ever make.
</P>
<P>
Regards
</P>
<blockquote><font color="#1F1F1F">I believe that you're seriously underestimating the difficulty and the
complexity of what you propose. Even if Joe Average did have the
necessary soldering, etc. skills (and I assure you that soldering
multi-layer PCboards _is_ a skill, one that takes time and patience to
acquire), where would he get the boards themselves? The average
mainboard today is at least a six- or a seven-layer type; there's no way
for the average experimenter to make one of those. Besides all that,
there's the troubleshooting of the finished board - I can assure you
that this will be required in most cases. How many people are capable of
it? How many of them will burn a trace just as they're about to wrap up
the project (i.e., after they've sunk hours into it?) How many have an
oscilloscope, which is what's necessary for troubleshooting high-speed
digital electronics?
</font></blockquote>
<blockquote><font color="#1F1F1F">I suggest that mainboard manufacture is the province of highly
skilled, highly knowledgeable people - not something that can be
retailed to Joe Average. I suggest that a much better tactic would be to
create a Linux certification authority, someone who can brand hardware
"100% Linux-compatible" in bright red ink; a goal that manufacturers
could strive for and easily achieve, given how much hardware support
already exists in Linux.
-- Ben</font></blockquote>
<blockquote><font color="#000066">There is a thing called "open-hardware". AFAIR they got open pci, agp,
bridges and stuff. For a short time they even had a open-processor
(arm clone) but that was pulled when arm pissed them off. So, the
designs are there, but who is going to build the stuff? Writing 0.18um
structures in your kitchen isn't that easy
<IMG SRC="../gx/dennis/smily.gif" ALT=";-)"
height="24" width="20" align="middle">
</font></blockquote>
<blockquote><font color="#000066">I think that the problem lies not with us linux users, we KNOW that M$
is up to something "bad". But what about those windows dau's that
simple stick to win "because it`s all so easy". Do you think they will
go through much trouble to make their own computer? No, if the thing
is cheap and it's easy (like in sharing your whole hdd with other
kazaa users
<IMG SRC="../gx/dennis/smily.gif" ALT=";-)"
height="24" width="20" align="middle"> they even let the government spy on them and allow ms
to know what dvd they watch and how ofter.
</font></blockquote>
<blockquote><font color="#000066">When such M$ hardware with the fritz chip arise these people will buy
them (in large numbers) so that it will be hard to get hardware that
does not feature these chips. But I think there will be a small market
(for us linux users and some intelligent win users) and where there is
a market there will be a seller.
</font></blockquote>
<blockquote><font color="#000066">Lets hope for the best
</font></blockquote>
<blockquote><font color="#000066">-- Robos
</font></blockquote>
<blockquote><font color="#000066">While I'm a big fan of the make it yourself philosphy, remember that
the widespread presence of all the good toys ... cars, and computers
themselves come to mind ... came not from the individual skilled
crafstmen, but from the assembly line. I find it far easier to maintain
an old 386 for ten years past its expected lifespan, than to figure out
how I'd compose a replacement out of loose copper wire and transistors.
Given that I'm among those whom Ben describes as able to wield a
soldering iron and knowing what an oscilloscope is (I don't own one, but
I know where to borrow a few) I just don't think garage made P7-oids
are going to happen real soon.
</font></blockquote>
<blockquote><font color="#000066">The buzzword you're looking for is "economy of scale". We haven't
"de-marketized" software ... we've shown there's a growing market for a
much greater variety of software.
</font></blockquote>
<blockquote><font color="#000066">Speaking of "so easy" ... the ease is mostly an illusion, fostered by
all those strong-arm OEM deals that resulted in nearly all systems being
preloaded with MSwin. Now that Linux, and perhaps rarely, occasional
others, are also being pre-loaded you'll see that particular bubble pop.
It's mostly flat already, since reinstalling MSwin after it crashes too
many times is so painful.
</font></blockquote>
<blockquote><font color="#000066">In countries where someone cannot simply wander into a department store,
buy a few new couch pillows, tortilla chips and salsa, and a box of the
latest rev of MSwin on special, buying into an expensive foreign
standards probably won't happen either. Indeed, here's looking to a long
and profitable time for companies that don't buy into the "palladiium"
chip game. Can you say "sink the Clipper chip?" Knew you could.
-- Heather</font></blockquote>
<blockquote><font color="#1F1F1F">A better solution might be to join the struggle to give some of the power
back to the people through the establishment of public campaign financing.
It should help to fight many more problems than just M$ taking over.
</font></blockquote>
<blockquote><font color="#1F1F1F">Some URL's to check for more info about this are:
</font></blockquote>
<blockquote><font color="#1F1F1F"><A HREF="http://www.angelfire.com/al/10avs/links.html#campfin"
>http://www.angelfire.com/al/10avs/links.html#campfin</A>
</font></blockquote>
<blockquote><font color="#1F1F1F"><A HREF="http://www.sonic.net/~doretk/Issues/96-04%20APRIL/alliance.html"
>http://www.sonic.net/~doretk/Issues/96-04%20APRIL/alliance.html</A>
</font></blockquote>
<blockquote><font color="#1F1F1F"><A HREF="http://www.thealliancefordemocracy.org"
>http://www.thealliancefordemocracy.org</A>
</font></blockquote>
<blockquote><font color="#1F1F1F">-- John Karns
</font></blockquote>
<!-- end 8 -->
<P> <hr> </p>
<!-- *** BEGIN copyright *** -->
<H5 align="center">This page edited and maintained by the Editors
of <I>Linux Gazette</I>
<a href="http://www.linuxgazette.com/copying.html"
>Copyright &copy;</a> 2002
<BR>Published in issue 81 of <I>Linux Gazette</I> August 2002</H5>
<H6 ALIGN="center">HTML script maintained by
<A HREF="mailto:star@starshine.org">Heather Stern</a> of
Starshine Technical Services,
<A HREF="http://www.starshine.org/">http://www.starshine.org/</A>
</H6>
<!-- *** END copyright *** -->
<center>
<H1><A NAME="tips"><IMG ALIGN=MIDDLE ALT="" SRC="../gx/twocent.jpg">
More 2&cent; Tips!</A></H1> <BR>
<!-- BEGIN tips -->
Send Linux Tips and Tricks to <A HREF="mailto:linux-questions-only@ssc.com">linux-questions-only@ssc.com</A></center>
</center>
<UL>
<!-- index_text begins -->
<li><A HREF="#tips/1"
><strong>Spam comments</strong></a>
<li><A HREF="#tips/2"
><strong>Playing CD Music Digital Output</strong></a>
<li><A HREF="#tips/3"
><strong>Getchar and loops...</strong></a>
<li><A HREF="#tips/4"
><strong>epoch</strong></a>
<li><A HREF="#tips/5"
><strong>crypt undefined</strong></a>
<li><A HREF="#tips/6"
><strong>diald</strong></a>
<li><A HREF="#tips/7"
><strong>Killing GUI applications under KDE</strong></a>
<li><A HREF="#tips/8"
><strong>GRUB - Window XP can not load</strong></a>
<li><A HREF="#tips/9"
><strong>Kylix</strong></a>
<li><A HREF="#tips/10"
><strong>use an .rpm without installing it</strong></a>
<li><I>Linux Journal's</I> Weekly News Notes
<a href="#tips/lj">Tech Tips</a>
<ul>
<LI>Watching multiple log files at once
<LI>Switching to Maildir format mailboxes
<LI>Running screen-oriented programs directly
<LI>Your running processes
<li><A HREF="http://noframes.linuxjournal.com/subscribe/lja-sub.html"
>subscribe</A> to LJWNN
</ul>
<!-- index_text ends -->
</UL>
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/1"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">Spam comments</FONT></H3>
4 Jul 2002 15:52:02 -0400
<BR>Karl Vogel (<a href="mailto:linux-questions-only@ssc.com?cc=vogelke@dnaco.net&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%231">vogelke from dnaco.net</a>)
<blockquote>This is in reply to the <a href="../issue80/lg_answer.html#tag/greeting"
><em>LG</em> issue 80 TAG blurb</a>.</blockquote>
<P><STRONG><FONT COLOR="#000066"><EM>
In LG 80, Heather was rumored to have said:
</EM></FONT></STRONG></P>
<P><STRONG><FONT COLOR="#000066"><EM>
Almost the only spam that escapes Dan's traps anymore are those dratted
conman scams telling me about how their late uncle <TT>/</TT> business partner /
revered general or whatever left them a quadzillion dollars <TT>/</TT> francs or
whatever and they can't get at any of it unless you as a friend /
distant relative <TT>/</TT> confidant <TT>/</TT> conveniently uninvolved sucker open your
bank account to help them launder it.
</EM></FONT></STRONG></P>
<P>
Do you use "ifile"? That nails just about all the spam I get, including
those stupid laundering schemes. The best part is that it gets smarter
with time; the more spam you feed it, the better it weeds out crap.
</P>
<P><DL><DT>
Source:
<DD><A HREF="http://www.ai.mit.edu/~jrennie/ifile"
>http://www.ai.mit.edu/~jrennie/ifile</A>
</DL></P>
<P><DL><DT>
Mailing list:
<DD><A HREF="http://groups.yahoo.com/group/ifile-discuss"
>http://groups.yahoo.com/group/ifile-discuss</A>
</DL></P>
<P><DL><DT>
Some tips plus a nice procmail setup and ifile database:
<DD><A HREF="http://www2.picante.com:81/~gtaylor/spam"
>http://www2.picante.com:81/~gtaylor/spam</A>
</DL></P>
<P>
My .procmailrc is below.
</P>
<P>
-- Karl Vogel
</P>
<p align="center">See attached <tt><a href="misc/tips/vogel.procmailrc.txt">vogel.procmailrc.txt</a></tt></p>
<!-- end 1 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/2"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">Playing CD Music Digital Output</FONT></H3>
Tue, 2 Jul 2002 11:17:04 -0400 (VET)
<BR>Ernesto Hernandez-Novich (<a href="mailto:linux-questions-only@ssc.com?cc=emhn@telcel.net.ve&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%232">emhn from telcel.net.ve</a>)
<blockquote>This is in reply to the <a href="../issue79/lg_mail.html#wanted/2"
><em>LG</em> issue 79, help wanted #2</a>.</blockquote>
<P>
Hi,
</P>
<P>
Regarding Bill Parks question on the June issue, as to how to play
CD audio <EM>without</EM> the analog cable usually connecting CD-ROMs to
audio cards, a similar situation happens if you have one of the latest
iBooks. There is no way to tweak the sound driver to do what he wants,
but XMMS can be of help. He should try using the "CD Audio Player"
Input Plugin (select it via Preferences -&gt; Audio I/O Plugins) and
configure it accordingly, say have <TT>/dev/hdc</TT> (the "real" CD-ROM device,
not <TT>/dev/cdrom</TT> which is usually a symlink) and <TT>/cdrom.</TT> Then, put the
audio CD, and open a "Playlist" in XMMS but instead of selecting a File,
select the <TT>/cdrom</TT> directory; he'll see the audio tracks there and be
able to play and listen to them.
</P>
<P>
That's right, the system will be doing CDDA extraction from the CD
into XMMS, which then plays it through OSS/ESD/ARTS. Ugly, but works.
</P>
<blockquote><code><font color="#000033"><br>Ernesto Hern<72>ndez-Novich
<br>GPG Key Fingerprint = 438C 49A2 A8C7 E7D7 1500 C507 96D6 A3D6 2F4C 85E3
</font></code></blockquote>
<!-- end 2 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/3"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">Getchar and loops...</FONT></H3>
Mon, 8 Jul 2002 08:34:35 -0500 (CDT)
<BR>Jay R. Ashworth, Pradeep (<a href="mailto:linux-questions-only@ssc.com?cc=zaikxtox@yahoo.com&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%233">the <em>LG</em> Answer Gang</a>)
<BR>Question by Zaikxtox (<a href="mailto:linux-questions-only@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%233">zaikxtox@yahoo.com</a>)
<P>
Hello. I'm trying to write a very simple C program
that needs to attend the user input without blocking a
loop. I have porgrammed many time on pascal, and there
the code will be something like:
</P>
<blockquote><pre>begin
while not keypressed
writeln('hello! i'm still alive');
end.
</pre></blockquote>
<P>
well... when i use C code i try the getchar function,
but it waits until a key is pressed blocking the
program.
</P>
<P>
How can i know if there is a key into the buffer
without blocking the execution of my programs?
</P>
<P>
Thanks in advance
<IMG SRC="../gx/dennis/smily.gif" ALT=":)"
height="24" width="20" align="middle">
Zaikxtox
</P>
<BLOCKQUOTE>
[jra]
Well, you can, but it's not exactly trivial, and how you do it depends
on which environment you're coding: raw-C for the glass-tty,
curses/termcap, X, <A HREF="http://www.kde.org/">KDE</A>, Gnome, etc.
</BLOCKQUOTE>
<BLOCKQUOTE>
This is more generic C stuff than Linux stuff; I'd recommend you look
into books like The Unix Programming Environment, by (I think)
Kernighan and Pike, and the Stevens books.
</BLOCKQUOTE>
<BLOCKQUOTE>
[pradeep]
As the other poster mentioned, it depends on where you want this
behaviour. Assuming that you want to do this on a console, ncurses is a
great library to use. It gives you the right abstraction.
</BLOCKQUOTE>
<BLOCKQUOTE><DL><DT>
Read my howto at
<DD><A HREF="http://tldp.org/HOWTO/NCURSES-Programming-HOWTO"
>http://tldp.org/HOWTO/NCURSES-Programming-HOWTO</A>
</DL></BLOCKQUOTE>
<BLOCKQUOTE>
Particularly the function <TT> halfdelay()</TT> should help you for non-blocking key
input.
</BLOCKQUOTE>
<!-- end 3 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/4"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">epoch</FONT></H3>
Sun, 30 Jun 2002 02:22:29 -0700
<BR>Heather Stern (<a href="mailto:linux-questions-only@ssc.com?cc=star@starshine.org&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%234"><em>Linux Gazette</em> Technical Editor</a>)
<!-- sig -->
<P>
Recently one of the gang mentioned renaming an rpm file to a much
higher version number before running alien, so that the <A HREF="http://www.debian.org/">Debian</A> package
system would not want to overwrite the result.
</P>
<P>
The key to doing that "the right way" is a value that the Debian
maintaineers call the epoch.
</P>
<P>
Of course people are used to seeing package versions like 1.2 or even
1.4.3p1.
</P>
<P>
In the Debian world that might be 1.4.3p1-2 meaning that this is the
second time the Debian maintainer had to build the same version.
Probably he or she has patches in it.
</P>
<P>
But to handle programs whose version numbers don't go constantly up
like time goes forward ... a certain typesetting package comes to
mind ...
</P>
<blockquote><font color="#000066">Must have been some other package. According to its FAQ, TeX's version
number asymptotically approaches pi, growing digits along the way.
-- Heather</font></blockquote>
<P>
... they invented an epoch. epochs start at the invisible "1"
and go up to 99.
</P>
<P>
So a version:
</P>
<blockquote><code><font color="#000033"><br> 99:1.4.3p1-local
</font></code></blockquote>
<P>
Would be 98 epochs ahead of a mere:
</P>
<blockquote><code><font color="#000033"><br> 1.4.3p1-12
</font></code></blockquote>
<P>
and the same number of epochs ahead of:
</P>
<blockquote><code><font color="#000033"><br> 2.1.12-1
</font></code></blockquote>
<P>
If you want your package and the Debian one to live together in
harmony, then rename yours to something before the version number that
does not overlap:
</P>
<blockquote><code><font color="#000033"><br> mtools4flash-3.9.7-1fp
<br> mtools-3.9.7-2
</font></code></blockquote>
<P>
Of course that's safest if the files inside their file list don't
overlap either!
</P>
<blockquote><font color="#1F1F1F">That was the problem, of course; the filesets were exactly the same.
-- Ben</font></blockquote>
<P>
Using either of these methods is safer than setting a hold on the
package, which is sometimes recommended, but which I've seen fail before.
</P>
<!-- end 4 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/5"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">crypt undefined
</FONT></H3>
Tue, 2 Jul 2002 16:48:03 +0200
<BR>Chris Niekel (<a href="mailto:linux-questions-only@ssc.com?cc=chris@niekel.net&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%235">chris from niekel.net</a>)
<blockquote>This is in reply to the <a href="../issue80/lg_tips.html#tips/8"
><em>LG</em> issue 80, 2c Tips #8</a>.</blockquote>
<P><STRONG>
g++ -lcrypt server.c
Error: 'crypt' undefined
</STRONG></P>
<P>
The order of the arguments matter. You should try:
</P>
<blockquote><code><font color="#000033"><br>g++ server.c -lcrypt
</font></code></blockquote>
<P>
The linker links from left to right and is a bit dumb.
After compiling server.c, the crypt call is undefined. Then libcrypt.a
is tried, and crypt is defined in there. So it will be resolved.
</P>
<P>
In your case, libcrypt.a doesn't match any undefined symbols (YET!), so
it is not linked into the executable. Then server.o is linked, and that
has an unresolved symbol (crypt). The linker isn't smart enough to go
back to libcrypt.a.
</P>
<P>
The answerer of the questions talks about the name mangling. If you mix
C and C++ code, you have to tell the compiler what is C. That is usually
done by doing:
</P>
<blockquote><code><font color="#000033"><br>extern "C" void foo(int);
</font></code></blockquote>
<P>
This tells the compiler that function foo takes an int, returns nothing
and is a C function. But all standard libraries already do that for you,
so it's very safe to call <TT> crypt()</TT> from C++ code.
</P>
<P>
Greetings,
</P>
<P>
Chris Niekel
</P>
<!-- end 5 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/6"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">diald
</FONT></H3>
Mon, 15 Jul 2002 14:07:38 -0400
<BR>LF11 (<a href="mailto:linux-questions-only@ssc.com?cc=lf11@naisp.net&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%236">lf11 from naisp.net</a>)
<blockquote>This is in reply to the <a href="../issue80/lg_tips.html#tips/10"
><em>LG</em> issue 80, 2c Tips #10</a>.</blockquote>
<P><STRONG>
I've mainly been connecting to the internet using diald, but I've noticed
that I'm only getting about 3.5 KBps , whereas on W98 I get about 5KBps. A
little experimentation shows that dialling with kppp gives about 5KBps as
well.
</STRONG></P>
<P><STRONG>
kppp seems to use an initialisation string of ATM1L1, but changing MODEM_INIT
to "ATM1L1" in <TT>/etc/diald/connect</TT>, didn't improve the performance.
</STRONG></P>
<P><STRONG>
MODEM_INIT started out as "ATZ&amp;C1&amp;D2%C0". I changed "%C0" to "%C3" to ensure
that compression was enabled, but this made no difference. I can't find an
option in diald to log exactly what's sent to the modem and I can't see any
conflicting options in the configuration for pppd.
</STRONG></P>
<P><STRONG>
Any suggestions for how to track down why kppp gets better performance than
diald would be appreciated.
</STRONG></P>
<P><STRONG>
The modem is an MRI 56K internal modem.
</STRONG></P>
<P>
Check the port speeds. It's likely that diald is using a port speed of
28.8KBps or 56KBps. Try to have something well above the actual speed of the
modem, as the data coming from the modem may be substantially higher in
volume than the actual modem's capability (due to hardware compression).
</P>
<P>
The only exception to this is with a USR 56k Faxmodem I have when used with
WvDial; it must be at 56k, and I don't know why. If the computer port speed
is set higher than that, what comes across the line from the modem seems to
be escaped characters of some sort, along the lines of
</P>
<blockquote><code><font color="#000033"><br>CONNECT 49333/ARQ
<br>f [18] f [18] `[1e]~[1e]~[1e][06][1e]x[1e][18]x
</font></code></blockquote>
<P>
And pppd says "LCP timeout sending Config-Requests" in syslog. Just thought
I'd let you know about this problem in case you have it.
</P>
<P>
HTH,
-cj
</P>
<BLOCKQUOTE>
[Neil]
Beware, it doesn't read <TT>/etc/diald/diald.conf.</TT> According to the man page
"diald reads options first from <TT>/etc/diald/diald.defs</TT>, then from
<TT>/etc/diald/diald.options</TT>".
</BLOCKQUOTE>
<BLOCKQUOTE>
Putting speed 115200 in diald.options gave me a
throughput 4.9KBps downloading Mozilla 1.1 alpha.
</BLOCKQUOTE>
<!-- end 6 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/7"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">Killing GUI applications under KDE</FONT></H3>
04 Jul 2002 08:17:43 +0530
<BR>Ashwin N (<a href="mailto:linux-questions-only@ssc.com?cc=ashwin_n@gmx.net&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%237">ashwin_n from gmx.net</a>)
<!-- sig -->
<!-- sig -->
<P>
Here's a quick way of killing a GUI application that has hung or is not
quitting (or you just want to kill for fun
<IMG SRC="../gx/dennis/smily.gif" ALT=":-)"
height="24" width="20" align="middle">. Press Ctrl-Alt-Esc and
your mouse pointer turns into skull-and-bones. Now, click on the
offending application to kill it. This works only under <A HREF="http://www.kde.org/">KDE</A>.
</P>
<P>
Of course, "xkill" command does the same thing, but this is much easier
and faster to use.
</P>
<P>
Ashwin
</P>
<BLOCKQUOTE>
[Ben]
Good tip, Ashwin! Under IceWM, I have "xkill" tied to "Alt-Ctrl-K" for
the same functionality:
</BLOCKQUOTE>
<BLOCKQUOTE><BLOCKQuote>
(from "~/.icewm/keys")
</BLOCKQuote></BLOCKQUOTE>
<blockquote><code><font color="#000033"><br>key "Alt+Ctrl+k" /usr/bin/X11/xkill
</font></code></blockquote>
<!-- end 7 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/8"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">GRUB - Window XP can not load</FONT></H3>
Fri, 28 Jun 2002 16:43:08 +0100
<BR>Neil Youngman (<a href="mailto:linux-questions-only@ssc.com?cc=orion982@yahoo.com&cc=n.youngman@ntlworld.com&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%238">n.youngman from ntlworld.com</a>)
<BR>Question by Soufian Widjaja (<a href="mailto:linux-questions-only@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%238">orion982@yahoo.com</a>)
<P><STRONG>
I find some info online that we can overwrite
the boot loader and then install boot loader
for Window by
run fdisk <TT>/</TT> MBR on Windows
If this is the way, how can I do that?
What to do with my Linux once we overwrite
the MBR?
</STRONG></P>
<P>
I think what's needed is to experiment with the GRUB command line mode. When
the menu comes up press 'c' to go to command line mode and try a few
variations on the command sequence you've got in <TT>/boot/grub/menu.last</TT>
When you come up with a command sequence that works, then edit your GRUB
config to match.
</P>
<P>
2 things to try are:
</P>
<P><BLOCKQuote>
1 After the rootnoverify command add the command makeactive.
2 Try varying the partition numbers in the rootnoverify command.
</BLOCKQuote></P>
<P><DL><DT>
There's lots of handy info in Linux Journal #85, see
<DD><A HREF="http://www.linuxjournal.com/article.php?sid=4622"
>http://www.linuxjournal.com/article.php?sid=4622</A>
</DL></P>
<P>
Hope That Helps
</P>
<!-- end 8 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/9"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">Kylix
</FONT></H3>
Wed, 3 Jul 2002 20:04:57 GMT
<BR>Chirag Wazir (<a href="mailto:linux-questions-only@ssc.com?cc=oam@mail.cosett.com.bo&cc=wazir@vsnl.com&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%239">wazir from vsnl.com</a>)
<BR>Question by Octavio Aguilar (<a href="mailto:linux-questions-only@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%239">oam@mail.cosett.com.bo</a>)
<blockquote>This is in reply to the <a href="../issue80/lg_mail.html#wanted/1"
><em>LG</em> issue 80, Help Wanted #1</a>.</blockquote>
<P><STRONG><FONT COLOR="#000066"><EM>
Does anybody know how to run a program that's compiled in Kylix,
but without having the Kylix environment around at runtime?
</EM></FONT></STRONG></P>
<P>
If you want to run a compiled Kylix program outside the IDE you need to run
</P>
<blockquote><code><font color="#000033"><br> source /usr/local/kylix2/bin/kylixpath
</font></code></blockquote>
<P>
first, or add it to your <TT>/etc/profile</TT>
</P>
<P>
I had the same problem initially - so I presume that's what the question is
about - my Spanish is non-existent.
</P>
<P>
The alternative interpretation could be about making a distribution package
to run on machines where Kyilx isn't installed - I haven't tried that yet.
</P>
<P>
Chirag Wazir
</P>
<!-- end 9 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/10"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy">use an .rpm without installing it
</FONT></H3>
Sat, 6 Jul 2002 13:40:26 -0500 (COT)
<BR>RE Otta (<a href="mailto:linux-questions-only@ssc.com?cc=ashwin_n@gmx.net&cc=obob@qwest.net&subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%2310">obob from qwest.net</a>)
<BR>Previous Tip by Ashwin M (<a href="mailto:linux-questions-only@ssc.com?subject=%20Re%3A%20%5BLG%2081%5D%202c%20Tips%20%2310">ashwin_n@gmx.net</a>)
<blockquote>This is in reply to the <a href="../issue80/lg_answer.html#tips/18"
><em>LG</em> issue 80, 2c Tip #18</a>.</blockquote>
<P>
It is simpler to use Midnight Commander. Click on the rpm file like you
would a directory and transverse the rpm as you would a branch of the
directory tree. Locate the file or files and copy them to an actual
directory with the copy button. Simple and effective!
</P>
<BLOCKQUOTE>
[John Karns]
I've found that some mc versions changed the rpm handling behavior. I had
grown quite accustomed to viewing rpm contents and copying parts via mc,
then after installing <A HREF="http://www.suse.com/">SuSE</A> 7.1 on my laptop, was no longer able to view
more than a partial list of the files in the rpm; specifically the rpm
headers (description, etc.). I was able to correct the problem finding
the mc scripts used for rpm handling, and changing one to agree with a
previous mc version script.
</BLOCKQUOTE>
<BLOCKQUOTE>
One other point is that for very large rpm files (over 2 or 3 MB), the
process can be very slow. When dealing with rpm files containing large
tar balls of source code, I usually just "install" the rpm, which copies
the desired file to <TT>/usr/src/packages/SOURCES.</TT>
</BLOCKQUOTE>
<!-- end 10 -->
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<P> <A NAME="tips/lj"><HR WIDTH="75%" ALIGN="center"></A> <P>
<H3><IMG ALIGN=BOTTOM ALT="" SRC="../gx/lil2cent.gif">
<FONT COLOR="navy"><em>Linux Journal</em> Weekly News Notes tech tips</FONT></H3>
<h4 align="center"><br>Watching multiple log files at once
</h4>
<P>
Recent versions of the GNU tail command let you tail multiple files
with the same command. Combined with the -f option, you can watch
multiple log files. For example:
</P>
<blockquote><code><font color="#000033"><br> tail -f /var/log/httpd/access_log /var/log/httpd/error_log
</font></code></blockquote>
<P>
will monitor the <A HREF="http://www.apache.org/">Apache</A> access and error logs.
</P>
<HR width="10%" align="center">
<h4 align="center"><br>Switching to Maildir format mailboxes
</h4>
<P>
If you're moving from old-style mailboxes to Maildir directories for
your mail, you can force Mutt to create Maildir directories by default
with:
</P>
<blockquote><code><font color="#000033"><br> :set mbox_type=Maildir
</font></code></blockquote>
<P>
in your .muttrc file.
</P>
<P>
To get Procmail to deliver to directories as Maildir and not MH
folders, put a <TT>/</TT> after the directory name in your recipes, like this:
</P>
<blockquote><code><font color="#000033"><br># Dump mail from Microsoft viruses into a trash Maildir
<br>:0 Bf
<br>* Content-Type: application/octet-stream;
<br>trash/
</font></code></blockquote>
<HR width="10%" align="center">
<h4 align="center"><br>Running screen-oriented programs directly
</h4>
<P>
To run a screen-based program such as top remotely with one ssh
command, use the -t (terminal) option to ssh, like this:
</P>
<blockquote><code><font color="#000033"><br> ssh -t myserver top
</font></code></blockquote>
<HR width="10%" align="center">
<h4 align="center"><br>Your running processes
</h4>
<P>
For an easy-to-understand, compact view of what's running on your
system now, try the pstree command. A handy option is -u, which shows
the name of the user running each process. Option -p shows the process
ID, so if you want to memorize only one option combination, try:
</P>
<blockquote><code><font color="#000033"><br> pstree -pu
</font></code></blockquote>
<P>
(No pun intended.)
</P>
<P>
pstree is a good way to make sure that privilege separation is working
in your upgraded ssh install--you did upgrade sshd, didn't you?
</P>
<!-- end 12 -->
<P> <hr> </p>
<!-- *** BEGIN copyright *** -->
<H5 align="center">This page edited and maintained by the Editors
of <I>Linux Gazette</I>
<a href="http://www.linuxgazette.com/copying.html"
>Copyright &copy;</a> 2002
<BR>Published in issue 81 of <I>Linux Gazette</I> August 2002</H5>
<H6 ALIGN="center">HTML script maintained by
<A HREF="mailto:star@starshine.org">Heather Stern</a> of
Starshine Technical Services,
<A HREF="http://www.starshine.org/">http://www.starshine.org/</A>
</H6>
<!-- *** END copyright *** -->
<A HREF="http://www.linuxgazette.com/"
><H1 align="center"><IMG ALT="LINUX GAZETTE" SRC="../gx/../gx/lglogo.jpg"
WIDTH="600" HEIGHT="124" border="0"></H1></A>
<P>
<P> <hr> <P>
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<center>
<H1><A NAME="answer">
<img src="../gx/dennis/qbubble.gif" alt="(?)"
border="0" align="middle">
<font color="#B03060">The Answer Gang</font>
<img src="../gx/dennis/bbubble.gif" alt="(!)"
border="0" align="middle">
</A></H1>
<BR>
<H4>By Jim Dennis, Ben Okopnik, Dan Wilder, Breen, Chris, and...
(<a href="tag/bios.html">meet the Gang</a>) ...
the Editors of Linux Gazette...
and You!
<br>Send questions (or interesting answers) to
The Answer Gang
for possible publication
(but read the <a href="../tag/ask-the-gang.html">guidelines</a> first)
</H4>
</center>
<!-- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: -->
<p><hr><p>
<H3>Contents:</H3>
<dl>
<dt><a href="#tag/greeting"
><strong>&para;: Greetings From Heather Stern</strong></A></dl>
<DL>
<!-- index_text begins -->
<dt><A HREF="tag/1.html"
><img src="../gx/dennis/qbub.gif" height="28" width="50"
alt="(?)" border="0"
></a>Can't See Boot Messages Even Though RedHat 7.2 Boots OK --or--
<dd><A HREF="tag/1.html"
><strong>Shedding Light On A Monitor's Troubles</strong></a>
<br>We're still in the dark, here.
<dt><A HREF="tag/2.html"
><img src="../gx/dennis/qbub.gif" height="28" width="50"
alt="(?)" border="0"
><strong>ide-scsi emulation for IDE IOMEGA ZIP 250MB</strong></a>
<dt><A HREF="tag/3.html"
><img src="../gx/dennis/qbub.gif" height="28" width="50"
alt="(?)" border="0"
><strong>Sound</strong></a>
<dt><A HREF="tag/4.html"
><img src="../gx/dennis/qbub.gif" height="28" width="50"
alt="(?)" border="0"
><strong>Version incompatibility</strong></a>
<!-- index_text ends -->
</DL>
<!-- .~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~.~~. -->
<A NAME="tag/greeting"><HR WIDTH="75%" ALIGN="center"></A>
<H3 align="left"><img src="../gx/dennis/hbubble.gif"
height="50" width="60" alt="(&para;) " border="0"
>Greetings from Heather Stern</H3>
<!-- begin hgreeting -->
<blockQuote>
It's been a slow month here at the Gazette, with some days actually being so light that
some gang members piped up with "did I fall off the list?" Not so slow that we didn't
get tips and threads, though. And not quite so slow that I'm publishing all the threads
we got or anything like that.
</blockQuote>
<blockQuote>
Readers are being very helpful to each other and I'm glad that the Help Wanteds are
popular. Andy Fore tells us that with so much fuss over the Alcatel Speedtouch and
its gory details, it now has a HOWTO of its very own (although not by him). Here it
is:
</blockQuote>
<blockQuote><BLOCKQuote>
<A HREF="http://linux-usb.sourceforge.net/SpeedTouch/howto.html"
>http://linux-usb.sourceforge.net/SpeedTouch/howto.html</A>
</BLOCKQuote></blockQuote>
<blockQuote>
I'm glad to see that with enough people's work on tiny bits here and there, we all
grow richer for it.
</blockQuote>
<blockQuote>
The Peeve Of The Month this time around is some fellow who, not getting more than
raw guesses from The Answer Gang, and figuring it out himself, instead of chiming in
with it decided to tell us off how stupid and flatfooted we all are, not to mention
how dare <EM>we</EM> ask <EM>him</EM> for the answer. I'll save you all the grumpy replies. Let's
just say that we didn't promise you our rose garden wouldn't have thorns, bugs, or
that we'd have an instant gauze bandage (brand-name or otherwise) handy if you get
bit. We try our best, when we've got a few moments free. That's all we can really do.
</blockQuote>
<blockQuote>
Which brings me to the topic of my babbling this month. I certainly say it often
enough face to face...
</blockQuote>
<h4 align="center"><br> When Did Your Important Data Become Important To You?
</h4>
<blockQuote>
With the sub-thought... and perhaps you should decide what really is important,
instead of discovering it in emergency. Take a good look at your own day for a week
or two, and notice the things and people that you need the most.
</blockQuote>
<blockQuote>
Unfortunately the financial world continues to be slow too. While Linux increasingly
creeps onto people's desktops and has pretty much taken root in their LAN closers -
especially places still small enough to use closets instead of glass houses and cardkey
setups - there continues this persistent and patently false feeling that those free
software zealots have no interest in spending money.
</blockQuote>
<blockQuote>
Not true in the slightest. If it was there wouldn't be all these shows on our topic,
like this month's LinuxWorldExpo in San Francisco (<A HREF="http://www.linuxworldexpo.com"
>http://www.linuxworldexpo.com</A>).
We just want to get our money's worth when we do.
</blockQuote>
<blockQuote>
Take this example. Just last week the news that <em>Linux Weekly News</em>
(<a href="http://www.lwn.net/">LWN.net</a>) was almost out of money - again -
resulted in another heartening rush of help for them from readers eager to keep getting
their dose of Linux events... enough for them to consider that a web based subscription
model might not fall <EM>plop</EM> on its rear, after all.
</blockQuote>
<blockQuote>
Free projects are good, but many of the finer ones have their commercial support avenues
too, and not always with the obviosu product name placed in their URLs, either.
Berkeley DB has Sleepycat (<A HREF="http://www.sleepycat.com"
>http://www.sleepycat.com</A>), and so on. Without noting anybody in
particular - I'm sure you all have different things you really use your computers for out
there - I'd like to encourage everyone to continue to put their money where their mouth
is. Pick up a distro at an installfest, and decide it doesn't drive you as batty as some
other distro or OS you tried before? Buy their next version. Like an incredibly cool
free software project that never asks a dime and says "we're doing this 'cuz it works,
not 'cuz we need the bucks" ? Send something in thought of a thank you to one of the
organizations that defend making it easy to pass these things around. The tops on
my list are the <A HREF="http://www.debian.org/">Debian</A> project (<A HREF="http://www.debian.org"
>http://www.debian.org</A>), the Free Software Foundation
(<A HREF="http://www.fsf.org"
>http://www.fsf.org</A>), and the EFF (<A HREF="http://www.eff.org"
>http://www.eff.org</A>) but you probably already
guessed that, and I'm sure there are others.
</blockQuote>
<blockQuote>
Don't be afraid to thow kudos in package authors' directions either -
that's at least some pay in "The Coin of The Realm"
(<A HREF="http://www.linuxgazette.org/issue64/lg_answer64.html#tag/greeting"
>http://www.linuxgazette.org/issue64/lg_answer64.html#tag/greeting</A>). If your
life with a package isn't quite perfect but you like it anyway, then pitch in with
some elbow grease, being willing to fuss with ltrace, strace or waste a bit of disk
space on some more verbose logging so your bug reports can be more useful, and even
more importantly, be willing to try the new code when they think they've got some
sort of fix for you.
</blockQuote>
<blockQuote>
Err, don't forget to turn off all the traces and debug stacks when you're done, or
you'll find yourself buying terabyte storage to go with it.
</blockQuote>
<blockQuote>
If you <EM>have</EM> terabyte storage and nothing better to do with it, or at least don't
mind, consider mirroring some projects that your site uses and enjoys the benefits
from. You get a local download, crosslinks, and that's one less chance the project
might disappear on you just because some poor fellow loses his job or completes his
college curriculum and has to move... or that some poor company who was primary-hosting
it will go the way of the dodo and the dotbomb.
</blockQuote>
<blockQuote>
And what people usually mean when they say that fun little phrase:
</blockQuote>
<blockQuote><ol>
<li> don't forget to make backups!
<br>&nbsp;
<li> They aren't bloody well helpful if they don't <EM>work</EM>, so check the
restore procedures once in a while. Go ahead. Grab a spare machine and
try it. Figure out if it really only takes you an hour and a half or
all afternoon to bring the mail server or accounting department back up if
that last power surge fries the UPS and a computer with it.
<br>&nbsp;
<br>(You laugh now, but I have seen a UPS blow out and take the machine with it. I can
still smell the burning plastic and hear that horrible squeal. Thank goodness we
cut off the real power before a <EM>real</EM> fire started. Ugh!)
<br>&nbsp;
<li> Make sure that you've rescued the human-generated work that goes into a
system, not just the grubby details that make it able to boot up. People
are limited in what they can regenerate, and people stressed from losing a
lot of work, even more so.
</ul></blockQuote>
<blockQuote>
Did I mention that we just passed Sysadmins Appreciation Day? It's the
fourth Friday in July. (<A HREF="http://SysAdminDay.boxke.be"
>http://SysAdminDay.boxke.be</A>) From the website:
"Let's face it, System Administrators get no respect 364 days a year..."
</blockQuote>
<blockQuote>
It's a tough world out there, folks. We've got to stand together these days.
If we can't all be heroes, we can at least put our own sense of what heroism is
to good use.
</blockQuote>
<blockQuote>
Have a great August, folks. Now, enjoy the threads
<IMG SRC="../gx/dennis/smily.gif" ALT=":)"
height="24" width="20" align="middle">
</blockQuote>
<!--endcut ========================================================= -->
<!-- end hgreeting -->
<P> <hr> </p>
<!-- *** BEGIN copyright *** -->
<H5 align="center">This page edited and maintained by the Editors
of <I>Linux Gazette</I>
<a href=""
>Copyright &copy;</a> 2002
<BR>Published in issue 81 of <I>Linux Gazette</I> August 2002</H5>
<H6 ALIGN="center">HTML script maintained by
<A HREF="mailto:star@starshine.org">Heather Stern</a> of
Starshine Technical Services,
<A HREF="http://www.starshine.org/">http://www.starshine.org/</A>
</H6>
<!-- *** END copyright *** -->
<P>
<H4 ALIGN="center">"Linux Gazette...<I>making Linux just a little more fun!</I>"</H4>
<HR>
<center>
<table cellpadding=7><tr><td>
<IMG SRC="../gx/bytes.gif" border=1 ALT="News Bytes">
</td><td>
<H3>Contents:</H3>
<ul>
<li><a HREF="#leg">Legislation and More Legislation</a>
<li><a HREF="#links">Linux Links</a>
<li><a HREF="#conferences">Conferences and Events</a>
<li><a HREF="#general">News in General</a>
<li><a HREF="#distro">Distro News</A>
<li><a HREF="#commercial">Software and Product News</a>
</ul>
</td></tr></table>
<STRONG>Selected and formatted by <A HREF="mailto:michael.conry@softhome.net">Michael Conry</A> and Mike Orr</STRONG>
</center>
<P> Submitters, send your News Bytes items in
<FONT SIZE="+2"><STRONG>PLAIN TEXT</STRONG></FONT>
format. Other formats may be rejected without reading. You have been
warned! A one- or two-paragraph summary plus URL gets you a better
announcement than an entire press release. Submit items to
<A HREF="mailto:gazette@ssc.com">gazette@ssc.com</A>
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<font color="green">
August 2002 <I>Linux Journal</I> -- 100th issue!
</font>
</H3>
<IMG ALT="[issue 100 cover image]" SRC="misc/bytes/lj-cover100.png" WIDTH=200 HEIGHT=268
ALIGN="left" HSPACE="20">
The August issue of <A HREF="http://www.linuxjournal.com/"><I>Linux
Journal</I></A> is on newsstands now.
This issue focuses on LJ's 100th issue. Click
<A HREF="http://www.linuxjournal.com/modules.php?op=modload&name=NS-lj-issues/issue100&file=index">here</A>
to view the table of contents, or
<A HREF="http://www.linuxjournal.com/subscribe/">here</A>
to subscribe.
<P>
<FONT COLOR="green">All articles through December 2001 are available for
public reading at
<A HREF="http://www.linuxjournal.com/magazine.php">http://www.linuxjournal.com/magazine.php</A></FONT>.
Recent articles are available on-line for subscribers only at
<A HREF="http://interactive.linuxjournal.com">http://interactive.linuxjournal.com/</A>.
<BR CLEAR="all">
<!-- =================================================================== -->
<a name="leg"></a>
<p><hr><p>
<!-- =================================================================== -->
<center><H3><font color="green">Legislation and More Legislation</font></H3></center>
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">JPEG
</FONT>
</H3>
<P>
It emerged during the past month, to the dismay of everyone interested in
open file formats and free software, that the JPEG image compression scheme
may be subject to patent royalties. As
<a href="http://www.theregister.co.uk/content/4/26272.html">
reported</a>
by The Register,
<a href="http://www.forgent.com/">
Forgent Networks</a> have recently come into possession of a
<a href="http://patft.uspto.gov/netacgi/nph-Parser?Sect1=PTO1&Sect2=HITOFF&d=PALL&p=1&u=/netahtml/srchnum.htm&r=1&f=G&l=50&s1='4,698,672'.WKU.&OS=PN/4,698,672&RS=PN/4,698,672">
patent</a> which they claim covers the transmission of JPEG images, and
have even managed to claim royalties from two companies. If this patent
proves to be enforceable, the ISO have said that they will
<a href="http://www.theregister.co.uk/content/4/26339.html">
withdraw JPEG as a standard</a> (the licencing terms being enforced by
Forgent are not compatible with ISO regulations for standards).
Hopefully the patent will not stand up. To make sure of this, the JPEG
committee is
<a href="http://www.jpeg.org/newsrel1.html">
seeking examples of prior art</a> which would render the patent null
and void.
If the worst comes to the worst, it appears that the patent will
expire in 2004 in any case.
<P>
The
<a href="http://swpat.ffii.org/group/index.en.html">
Software Patent Working Group of the FFII</a>,
has pointed out that there are also
<a href="http://swpat.ffii.org/patente/wirkungen/jpeg/index.en.html">
European Patents in existence</a>
which could be used to put a lean on JPEG compression.
A small step can be taken against EU software patents by signing
the <a href="http://www.noepatents.org/index_html?LANG=en">
Petition for a Software Patent Free Europe</a>.
<P>
A webpage bringing together many links on this story is the new
<a href="http://burnalljpegs.org/">
Burn All .JPEGs!</a> website.
Forgent's website also has a
<a href="http://www.forgent.com/company/press_room/in_the_news.shtml">
list</a> of recent appearances of the company in the news, which has a
couple of links to stories regarding the JPEG patent.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Perens and DMCA
</FONT>
</H3>
<P>
<a href="http://perens.com/">
Bruce Perens</a>
generated some publicity this month by
<a href="http://www.infoworld.com/articles/hn/xml/02/07/23/020723hnperens.xml">
threatening</a>
to violate the DMCA
<a href="http://conferences.oreillynet.com/cs/os2002/view/e_sess/3111">
live on stage</a> at the
<a href="http://conferences.oreillynet.com/os2002/">
O'Reilly Open Source Convention</a>.
<a href="http://yro.slashdot.org/comments.pl?sid=36633&cid=3946881">
The plan</a>
was to demonstrate how to remove the region-code control built into a DVD
player. However
<a href="http://www.siliconvalley.com/mld/siliconvalley/business/columnists/dan_gillmor/ejournal/3735855.htm">
as reported by Dan Gilmore</a> and
<a href="http://yro.slashdot.org/article.pl?sid=02/07/26/1739207&mode=nested&tid=153">
by Slashdot</a>,
Bruce backed down from openly breaking the law
following a request from his employers,
<a href="http://www.hp.com/">HP</a>.
<P>
There are several good links regarding this story on the
<a href="http://www.oreillynet.com/oscon2002/">
O'Reilly Open Source Convention Conference Coverage page</a>.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">More DRM (sigh)
</FONT>
</H3>
<P>
A bill proposed by US Senator Biden would make certain kinds of Digital
Rights Management circumvention a
<A HREF="http://thomas.loc.gov/cgi-bin/bdquery/z?d107:s.02395:">felony</A>
(capital crime).
<A HREF="http://zdnet.com.com/2100-1107-946890.html">ZDNet coverage</A> states
that the bill was originally intended to combat large-scale piracy (e.g., fake
Windows holograms), but was quietly rewritten to include DRM. (Courtesy
Slashdot)
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Open source: EU, US, Peru and Pakistan
</FONT>
</H3>
<P>
It was reported in various locations
(<a href="http://www.theregister.co.uk/content/4/26102.html">in The Register</a>,
<a href="http://slashdot.org/article.pl?sid=02/07/09/1739246&mode=nested&tid=99">
on Slashdot</a> and
<a href="http://news.zdnet.co.uk/story/0,,t269-s2118707,00.html">
in ZDNet</a>), that a recent EU report has called for
wider open-source adoption, in order to have greater exchange of software
between different administrative branches, and also between countries.
The
<a href="http://slashdot.org/article.pl?sid=02/07/09/1739246&mode=nested&tid=99">
Slashdot story</a> has links to the original EU report in various formats.
<P>
On a not unrelated theme,
Sam Williams at O'Reilly.net
<a href="http://linux.oreillynet.com/pub/a/linux/2002/07/16/linux_in_govt.html">
has taken a look</a>
at the impact of open source software in government--both inside and
outside the U.S.
<P>
Wired <A HREF="http://www.wired.com/news/business/0,1367,54141,00.html">reports</A>
that the US Ambassador to Peru has come out against Peruvian Congressman
Villanueva's bill advocating usage of open-source software in
gonvernment computers. Also, Bill Gates personally delivered
Peru's president Alejandro Tolero a donation estimated at $550,000
for the national school system. Not surprisingly, the money is
to go to the same schools Villanueva's bill targets.
Villanueva said he believes Microsoft isn't worried so much about
losing the small Peruvian market as the cascading effect that might
happen if other Latin American countries follow suit. Similar bills
are pending in Argentina, Mexico and Brazil, and Spain's Extremadura
region has
<A HREF=http://www.wired.com/news/business/0,1367,51994,00.html"">
already adoped Linux</A> as the official operating system of
its public schools and offices.
<P>
<A HREF="http://www.linuxjournal.com/article.php?sid=6204">Pakistan</A> is
getting into the Open Source game too. 50,000 Pentium IIs running GNU/Linux
are being installed in schools and colleges all over Pakistan, at a cost of
less than US$100 each. "Proprietary software for these PCs would cost a
small fortune. Surely more than what the computers cost!"
<a name="links"></a>
<p><hr><p>
<!-- =================================================================== -->
<center><H3><font color="green">Linux Links</font></H3></center>
<P>
The Register have an
<a href="http://www.theregister.co.uk/content/6/26275.html">
excellent report</a> (originally from NewsForge) by Grant Gross on a
public workshop on digital rights management. It would appear that "fair
use" advocates got less than a warm reception from Hollywood and Dept. of
Commerce representatives.
<P>
Marcelo Tosatti, maintainer of the stable kernel branch
<a href="http://news.zdnet.co.uk/story/0,,t269-s2118919,00.html">
in an interview</a> with ZDNet.
<P>
From <a href="http://www.lwn.net/">LWN</a>, come links to reports
<a href="http://news.com.com/2100-1023-944715.html">
in CNET</a> and
<a href="http://techupdate.zdnet.com/techupdate/stories/main/0,14179,2874933,00.html">
in ZDNet</a> of
the Netherlands' NAH6 plans to release a Secure
Notebook incorporating a program that encrypts files transparently.
The user runs applications on Windows, which is installed in a VMWare
virtual machine. VMWare is run on Debian GNU/Linux, which keeps files
encrypted in case the laptop is stolen or mislaid.
<P>
A few links from
<a href="http://www.linuxjournal.com/"><em>Linux Journal</em></a>
which might be of interest:
<ul>
<li>
An account of
<a href="http://www.linuxjournal.com/article.php?sid=5837">
setting up an old 386</a> on a home network.
</li>
<li>
A Dutch court says
<a href="http://www.linuxjournal.com/article.php?sid=6235">
opt-out is a good enough policy for spam</a>.
(meaning you get the messages unless you specifically request to be removed
from the list), and that if the level of spam gets objectionable, you can
always get a new e-mail address.
</li>
<li>
Doc Searls
<a href="http://www.linuxjournal.com/article.php?sid=6218">
writes</a>
about CARP and suggests that RIAA et al's motive isn't to extract money
from Internet radio stations but rather to shut them down through
royalty rates no station can afford, to protect their CD market.
</li>
<li>
Linux Journal's
<a href="http://www.linuxjournal.com/modules.php?op=modload&name=NS-lj-issues/issue100&file=index">
100th issue</a>.
</li>
<li>
<a href="http://www.linuxjournal.com/article.php?sid=6000">
Linux timeline</a>.
By
<a href="http://www.lwn.net">LWN</a> and
<a href="http://www.linuxjournal.com">LJ</a> staff.
</li>
</ul>
<P>
Some interesting links from
<a href="http://www.theregister.co.uk">The Register</a>
over the past month:
<ul>
<li>
A
<a href="http://www.theregister.co.uk/content/4/25993.html">
$200k prize has been offered</a>
for getting Linux to run legally on Xbox. The first program
<a href="http://www.theregister.co.uk/content/4/26078.html">
isn't much to look at though</a>.
</li>
<li>
European antitrust investigation
<a href="http://www.theregister.co.uk/content/4/25988.html">
considers Palladium</a>, while Microsoft tells us it's
<a href="http://www.theregister.co.uk/content/4/26231.html">
not so bad as it looks</a>, but
<a href="http://www.theregister.co.uk/content/54/26085.html">
not everyone is convinced</a>.
</li>
<li>
2600
<a href="http://www.theregister.co.uk/content/4/26038.html">
withdraws Supreme Court appeal</a> in DeCSS case.
</li>
<li>
<a href="http://www.theregister.co.uk/content/4/26289.html">
Forbes reports on Linux</a>.
</li>
<li>
UK government
<a href="http://www.theregister.co.uk/content/4/26335.html">
cautiously accepts</a>
Open Source.
</li>
<li>
<a href="http://www.theregister.co.uk/content/6/26357.html">
Cracking legal</a> for copyright enforcement?
</li>
<li>
<a href="http://www.theregister.co.uk/content/4/26382.html">
Danger</a>
of the UCITA.
</li>
<li>
NVidia edges towards open source, and opens parts of its compiler
<a href="http://www.theregister.co.uk/content/4/26351.html">
technology to the public</a>.
</li>
</ul>
<P>
DesktopLinux.com are
<a href="http://www.desktoplinux.com/news/NS6907557337.html">
publishing the winning essays</a> from their wIndependence Day contest.
<P>
<a href="http://www.privacyinternational.org">
Privacy International</a> have
<a href="http://www.privacyinternational.org/issues/idcard/uk/">
an FAQ and other information</a>
on proposals to introduce ID cards to
the UK. Probably of quite wide interest.
<P>
A couple of links from
<a href="http://slashdot.org/">
Slashdot</a> which might interest you:
<ul>
<LI>
<A HREF="http://www.msnbc.com/news/785970.asp">USB 2.0</A> is being
backported to Linux kernel 2.4.19. This means the stable Linux kernel
will have access to the upcoming generation of USB devices running 40
times faster than currently. The speedup makes USB CR-RW drives and
network cards practical, and gives performance comparable to FireWire
(but cheaper). This is only the first step: the specific device drivers
still need to be written. Linux users can rejoice that the delay in
getting USB 2.0 support is much less than was the case with USB 1.0, and
that the rate of progress is quite competitive with that of proprietary OSes.
(Another interesting point is that the article was published on MSNBC,
which is half owned by Microsoft but continues to publish pro-Linux articles.)
<LI>
Summary of articles about Secure Computing's SELinux and its
<A HREF="http://slashdot.org/articles/02/07/27/0224224.shtml?tid=155">
patented content</A>.
<li>
A
<a href="http://linuxdailynews.net/">
new portal:
<em>LinuxDailyNews</em></a> has
<a href="http://slashdot.org/articles/02/07/02/1158217.shtml?tid6">
been launched</a>, founded by several existing
Linux portal sites.
</li>
<li>
<a href="http://slashdot.org/articles/02/07/25/0237238.shtml?tid2">
Linux Beer Hike Goes to Ireland</a>.
</li>
</ul>
How Marty Roesch
<a href="http://newsforge.com/article.pl?sid=02/06/29/2127239&mode=thread&tid=3">
made the journey</a> from obsessive gamer to successful open source
developer and entrepreneur.
<P>
<a href="http://www.advogato.org/article/512.html">
The binary nature of freedom</a>, at Advogato (with
<a href="http://newsvac.newsforge.com/article.pl?sid=02/07/05/134242&mode=thread&tid=19">
talkbacks at NewsForge</a>).
<P>
NewsForge have
<a href="http://newsforge.com/article.pl?sid=02/07/12/0137212&mode=thread&tid=23">
a report</a> on the various instant messaging options available to Linux
users.
<P>
Howard Wen at O'Reilly
<a href="http://linux.oreillynet.com/pub/a/linux/2002/03/21/linuxps2.html">
takes a look</a>
at Sony's upcoming Linux distribution kit
for the PlayStation 2.
<P>
Some interesting links from
<a href="http://www.linuxtoday.com/">Linux Today</a>
<ul>
<li>
A detailed
<a href="http://www.nsa.gov/selinux/doc/freenix01/freenix01.html">
white paper</a> from the NSA, on Security-Enhanced Linux.
</li>
<li>
<a href="http://www-106.ibm.com/developerworks/linux/library/l-clutil/?t=gr,lnxw02=CLUtil">
Developing a Linux command-line utility</a> (at IBM developerWorks).
</li>
<li>
CrossNodes have
<a href="http://networking.earthweb.com/netsecur/article/0,,12084_1429131,00.html">
an introduction</a>
to auditing your LAN using nmap.
</li>
</ul>
<P> NewsForge article on
<a href="http://newsforge.com/article.pl?sid=02/07/19/1957242&mode=thread&tid=11">
the game theory of open code</a>.
<P>
Timo Hannay of Nature
<a href="http://www.oreillynet.com/pub/a/network/2002/07/17/timo.html">
compares</a> [O'Reilly]
the scientific method
to the mechanics of open source development.
<a name="conferences"></a>
<p><hr><p>
<!-- =================================================================== -->
<center><H3><font color="green">Upcoming conferences and events</font></H3></center>
<P> Listings courtesy <EM>Linux Journal</EM>. See <EM>LJ</EM>'s
<A HREF="http://www.linuxjournal.com/events.php">Events</A> page for the
latest goings-on.
<!-- *** BEGIN events table [this line needed by Linux Gazette events.py *** -->
<table cellpadding=5 border=0 width=100%>
<tr><td colspan=2><HR size=5 width=100% noshade align=center></td></tr>
<tr><td valign=top>
<b>USENIX Securty Symposium (USENIX)</b><BR>
<td valign=top>August 5-9, 2002<BR>San Francisco, CA<BR>
<a href="http://www.usenix.org/events/sec02/" target="_blank">
http://www.usenix.org/events/sec02/</A><BR>
<tr><td colspan=2><HR size=5 width=100% noshade align=center></td></tr>
<tr><td valign=top>
<b>LinuxWorld Conference & Expo (IDG)</b><BR>
<td valign=top>August 12-15, 2002<BR>San Francisco, CA<BR>
<a href="http://www.linuxworldexpo.com" target="_blank">
http://www.linuxworldexpo.com</A><BR>
<tr><td colspan=2><HR size=5 width=100% noshade align=center></td></tr>
<tr><td valign=top>
<b>LinuxWorld Conference & Expo Australia (IDG)</b><BR>
<td valign=top>August 14 - 16, 2002<BR>Australia<BR>
<a href="http://www.idgexpoasia.com/" target="_blank">
http://www.idgexpoasia.com/</A><BR>
<tr><td colspan=2><HR size=5 width=100% noshade align=center></td></tr>
<tr><td valign=top>
<b>Communications Design Conference (CMP)</b><BR>
<td valign=top>September 23-26, 2002<BR>San Jose, California<BR>
<a href="http://www.commdesignconference.com/" target="_blank">
http://www.commdesignconference.com/</A><BR>
<tr><td colspan=2><HR size=5 width=100% noshade align=center></td></tr>
<tr><td valign=top>
<b>IBM eServer pSeries (RS/6000) and Linux Technical University</b><BR>
<td valign=top>October 14-18, 2002<BR>Dallas, TX<BR>
<a href="http://www-3.ibm.com/services/learning/conf/us/pseries/" target="_blank">
http://www-3.ibm.com/services/learning/conf/us/pseries/</A><BR>
<tr><td colspan=2><HR size=5 width=100% noshade align=center></td></tr>
<tr><td valign=top>
<b>Software Development Conference & Expo, East (CMP)</b><BR>
<td valign=top>November 18-22, 2002<BR>Boston, MA<BR>
<a href="http://www.sdexpo.com/" target="_blank">
http://www.sdexpo.com/</A><BR>
<tr><td colspan=2><HR size=5 width=100% noshade align=center></td></tr>
</table>
<!-- *** END events table [this line needed by Linux Gazette events.py *** -->
<a name="general"></a>
<p><hr><p>
<!-- =================================================================== -->
<center><H3><font color="green">News in General</font></H3></center>
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green"><EM>Linux Journal</EM> articles available for documentation
</FONT>
</H3>
<P>
<P> <EM>Linux Journal</EM>
<A HREF="http://www.linuxjournal.com/article.php?sid=6240">has changed its
author contract</A> to clarify that any author may include his/her articles as
freely-redistributable documentation in a free software project or free
documentation project after the article has been published. Authors have
always had this right since the founding of <EM>LJ</EM>, but some did not
realize they had it. Motivations for doing so are to make the information
available to all users of a program, in a convenient location, and so that the
project can use the article as primary documentation if desired, updating it as
the program evolves.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Linux Weekly News
</FONT>
</H3>
<P>
It looked like the end of the road for
<a href="http://www.lwn.net/">
Linux Weekly News</a>
earlier this month, when they
<a href="http://lwn.net/Articles/5052/">
announced</a>
that the August 1st edition would be the last ever. The basic cause for
this decision was lack of money, and the absence of any plan which could
generate money.
Following the announcement, many disappointed readers put their money on
the table and contributed to LWN's donation scheme. This quickly raised
$12000, leading to a
<a href="http://lwn.net/Articles/5838/">rethink of LWN's future</a>.
A final decision on the magazine's fate has not been made.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Mandrake at Walmart
</FONT>
</H3>
<P>
Following last month's
<a href="http://newsforge.com/article.pl?sid=02/06/14/1316203&mode=thread&tid=23">
launch</a> [NewsForge]
by
<a href="http://www.walmart.com/">
Wal-Mart</a> of PC's with
<a href="http://www.lindows.com">
Lindows</a>
pre-installed, comes a
<a href="http://www.mandrakesoft.com/company/press/pr?n=/pr/products/2315&lg=en">
new announcement of</a>
the availability of
<a href="http://www.linux-mandrake.com/">Mandrake</a>-equipped versions.
The Wal-Mart catalogue contains full details and prices of both the
<a href="http://www.walmart.com/catalog/product_listing.gsp?cat=96356&dept=3944&path=0%3A3944%3A3951%3A41937%3A86796%3A96356">
Lindows</a> and
<a href="http://www.walmart.com/catalog/product_listing.gsp?cat=102252&dept=3944&path=0%3A3944%3A3951%3A41937%3A86796%3A102252">
Mandrake</a> PC product lines.
<P>
NewsForge have
<a href="http://newsforge.com/article.pl?sid=02/07/15/0147230&mode=thread&tid=23">
reported on this story</a>, as
<a href="http://www.theregister.co.uk/content/4/26192.html">has The
Register</a>.
Hopefully the Mandrake version of this product will prove more satisfactory
than the earlier Lindows offering, which received
<a href="http://newsforge.com/article.pl?sid=02/07/02/1247234&mode=thread&tid=23">
a very lukewarm review</a>
from NewsForge.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Ogg and Real
</FONT>
</H3>
<P>
Congratulations to the folk behind the
<a href="http://www.xiph.org/ogg/vorbis/">
Ogg Vorbis</a>
project, who have
<a href="http://www.ogg.org/ogg/vorbis/index.html">
released a version 1.0</a>.
As linked
<a href="http://lwn.net/Articles/5057/">from LWN</a>,
there are currently various news items related to the 1.0 release on
<a href="http://www.vorbis.com/news.psp">
Ogg Vorbis News</a>.
This story was also reported
<a href="http://www.theregister.co.uk/content/4/26176.html">
by The Register</a> and
<a href="http://news.com.com/2100-1023-945228.html">
by CNET</a>,
<P>
<a href="http://www.xiph.org/ogg/vorbis/">Ogg Vorbis</a> and
<a href="http://www.xiph.org/">Xiph.org</a> have also been in the news this
month due to the links being forged between the open source format and the
new
<a href="http://www.realnetworks.com/info/helix/index.html">
Helix</a>
software of
<a href="http://www.realnetworks.com/">RealNetworks</a>. This development
should see some parts of RealNetworks' software
<a href="http://linuxtoday.com/news_story.php3?ltsn=2002-07-24-016-26-NW-DT-SW">
being released</a>
under "a community and open source licence". Inclusion of the Ogg Vorbis
codec into RealNetworks products should follow.
<P>
Bruce Perens has written an
<a href="http://newsforge.com/article.pl?sid=02/07/23/0032247&mode=thread&tid=11">
in-depth account</a>
of the issues surrounding the RealNetworks-Xiph link-up, and has criticised
many features of the deal, such as the fact that Real's codecs will remain
proprietary, and the use of community licencing (rather than opensource)
for parts of their software.
Rob Lanphier of RealNetworks has
<a href="http://slashdot.org/comments.pl?cid=3933287&sid=36511&tid=126">
replied to Bruce</a> on Slashdot, and asked for good will to be shown to
the company's open source contribution.
The Register has also
<a href="http://www.theregister.co.uk/content/4/26314.html">
reported on</a>
Real's open source experiment,
<a href="http://news.com.com/2100-1023-945406.html">
as has CNET</a>.
The
<a href="http://www.helixcommunity.org/">
Helix Community website</a> should report future developments in the open
source development of the RealNetworks Helix project, and also contains
copies of the
<a href="http://www.helixcommunity.org/content/licenses.html">
licences</a> the software will be released under (comments are invited).
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">GNU Scientific Library (GSL) 1.2 is Released
</FONT>
</H3>
<P>
Version 1.2 of the GNU Scientific Library is now available.
The GNU Scientific Library is a collection of routines for numerical
computing in C.
This release is backwards compatible with previous 1.x releases.
The project home page is at
<a href="http://www.gnu.org/software/gsl/">
http://www.gnu.org/software/gsl/</a>.
Information for developers is at
<a href="http://sources.redhat.com/gsl/">
http://sources.redhat.com/gsl/</a>.
<a name="distro"></a>
<p><hr><p>
<!-- =================================================================== -->
<center><H3><font color="green">Distro News</font></H3></center>
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Debian
</FONT>
</H3>
<P>
Big news in the Debian world this month,
Debian GNU/Linux 3.0 (Woody) has
<a href="http://www.debian.org/News/2002/20020719">
been released</a>!
Debian GNU/Linux now supports a total of eleven processor architectures,
includes KDE and GNOME desktop environments, features cryptographic
software, is compatible with the FHS v2.2 and supports software developed
for the LSB. This was also
<a href="http://www.theregister.co.uk/content/4/26323.html">
reported by The Register</a>. As
<a href="http://www.debian.org/News/weekly/2002/28/">
reported by Debian Weekly News</a>,
the new testing distribution
<a href="http://lists.debian.org/debian-devel-announce-0207/msg00011.html">
will be called "sarge"</a>.
<P>
<hr noshade width="20%">
<P>
A new revision of Potato, 2.2r7, was also
<a href="http://www.debian.org/News/2002/20020713">
released</a>. Main changes were security updates, and a couple of
corrections.
<P>
<hr noshade width="20%">
<P>
<a href="http://www.debian.org/News/weekly/2002/28/">
Debian Weekly News reported</a> that the patent claims being made against
the jpeg image compression scheme could require the movement of
libjpeg62 and everything compiled against it into non-free.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Gentoo
</FONT>
</H3>
<a href="http:/www.tinyminds.org">tinyminds.org</a>
have published an
<a href="http://www.tinyminds.org/modules.php?op=modload&name=News&file=article&sid=429&mode=thread&order=0&thold=0">
interview</a> with Daniel Robbins of
<a href="http://www.gentoo.org/">
Gentoo Linux</a>.
There are a
<a href="http://newsvac.newsforge.com/newsvac/02/07/27/152253.shtml?tid=23">
few talkbacks</a> on NewsForge.
<P>
<hr width="20%" noshade>
<P>
LinuxPlanet have a
<a href="http://www.linuxplanet.com/linuxplanet/reviews/4302/1/">
recent review</a>
of Gentoo Linux 1.2.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">RedFlag
</FONT>
</H3>
<P>
<a href="http://www.redflag-linux.com">
Redflag Software Technologies Co., Ltd</a>
and
<a href="http://www.opera.com">
Opera Software</a>
have made a strategic announcement, and are looking forward to working
together on embedded browser solutions for the Chinese market.
RedFlag will seek to join as an Opera reseller, with joint development
and market efforts to tailor Opera for the Chinese embedded market.
<P> With Opera included, RedFlag will be able to offer original equipment
manufacturers (OEMs) and hardware manufacturers Web-enabled solutions
customised to fit with Red Flag's current product line.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">SuSE
</FONT>
</H3>
<P>
<a href="http://www.suse.de/en">SuSE Linux</a> has
announced the availability of the
<a href="http://www.suse.de/en/products/suse_business/email_server/">
SuSE Linux eMail Server 3.1</a>
with expanded system functionalities. SuSE's
e-mail solution which assists in managing appointments, tasks, and
resources, is aimed specifically at small and medium-scale enterprises as
well as workgroups and public administrations.
<P>
<hr noshade width="20%">
<P>
<a href="http://www.suse.de/en/">
SuSE Linux</a>
has also announced its participation in
<a href="http://www.tsanet.org">
TSANet</a> - the "Technical
Support Alliance Network". TSANet is a global support platform
that hosts more than 150 hardware and software providers. Within
the scope of TSANet, various manufacturers cooperate in providing
solutions for problems their enterprise customers encounter in
connection with their applications.
<P> For detailed information on the support offer of SuSE, please
check
<a href="http://support.suse.de/en/">
http://support.suse.de/en/</a>
<a name="commercial"></a>
<p><hr><p>
<!-- =================================================================== -->
<center><H3><font color="green">Software and Product News</font></H3></center>
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Opera
</FONT>
</H3>
<P>
<a href="http://www.opera.com">
Opera Software</a>
has announced the
release of Opera 6.02 for Linux. The new version includes important fixes
to the document and user interface, with special emphasis on the display of
Asian characters, making this a useful upgrade for Linux users all over
the world.
Opera 6 opened up Asian markets to Opera, because of its added ability
to display non- Western characters, and the Linux version has proved to be
especially popular in this region.
<P>
Opera 6.02 for Linux is available for free in a ad-supported version at
<a href="http://www.opera.com">
www.opera.com</a>.
Users can purchase a banner-free version for USD 39. Discounts apply.
<P>
<hr width="20%" noshade>
<P>
<a href="http://www.opera.com">
Opera Software ASA</a>
has also announced that
<a href="http://www.suse.de/en">
SuSE</a>
will distribute the popular Opera for Linux Web browser in their Linux
distribution. The deal is Opera's first major Linux distribution agreement.
Opera is available in SuSE Linux 8.0.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Random Factory
</FONT>
</H3>
<P>
<a href="http://www.randomfactory.com/">
The Random Factory</a>, have a range of scientific software for Linux,
covering subjects such as astronomy, chemistry, and biotechnology. Also
available are Linux workstations, preloaded with a choice of Random Factory
products.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Magic Software
</FONT>
</H3>
<P>
<a href="http://www.magicsoftware.com/edeveloper">
Magic Software Enterprises</a>, a provider of
application development technology and business solutions announced today
the introduction of
<a href="http://www.magicsoftware.com/edeveloper">
Magic eDeveloper</a>
into the Chinese market.
Magic Software
<a href="http://www.magicsoftware.com/bin/en.jsp?enPage=InnerPage&enDisplay=view&enDispWhat=object&enDispWho=tech%5El4%5EsLinux&enZone=tech&enVersion=0&enretain=branch&">
support Linux</a>
on some of their product lines.
<P> <hr> <P>
<!-- =================================================================== -->
<H3><IMG ALT=" " SRC="../gx/bolt.gif">
<FONT COLOR="green">Other software
</FONT>
</H3>
<P>
<a href="http://www.varicad.com">
VariCAD</a>
has announced the release of a new VariCAD 8.2.0.2 Update for both Windows
and Linux operating systems. This mechanical 3D/2D CAD package offers tools
for 3D modelling, 2D drafting, libraries of mechanical components,
calculations, BOM's, and many others. It is priced $399.
Free trial versions for Windows 98/NT/200/XP and Linux (RedHat, Mandrake,
SuSE) are available for downloading at
<a href="http://www.varicad.com">
http://www.varicad.com</a>
<P>
Linux Game Publishing is looking for beta testers for Mindrover 1.07b. You
can register your interest at <a
href=http://betas.linuxgamepublishing.com/>betas website</a>. Successful
applicants will be notified by e-mail.
<!-- *** BEGIN copyright *** -->
<P> <hr> <P>
<H5 ALIGN=center>
Copyright &copy; 2002, Michael Conry and
the Editors of <A HREF="mailto:gazette@ssc.com"><I>Linux Gazette</I></A>.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<i>making Linux just a little more <font COLOR="red">lovable!</font></i>"
<img ALT="" SRC="../gx/adam/heart.png" WIDTH="30" HEIGHT="25">
</h4>
<p> <hr> <p> <!--===================================================================-->
<p ALIGN=CENTER><img ALT="[picture of mechanic]" SRC="../gx/adam/mechanic.png" ALT="Weekend Mechanic Logo" ALIGN=BOTTOM WIDTH=399 HEIGHT=135 BORDER=0></p>
<h1 ALIGN=CENTER><font COLOR="maroon">The Weekend Mechanic</font></h1>
<h4 ALIGN=CENTER>By <a HREF="mailto:thomas_adam16@yahoo.com">Thomas
Adam</a></h4>
<p> <hr> <p> <!--===================================================================-->
<!-- END header -->
<!-- =======================================================================-->
<!-- --------------- -->
<!-- BEGIN: contents -->
<!-- --------------- -->
<UL>
<LI><A HREF="#preamble">Welcome to the July edition</A></LI>
<LI><A HREF="#quotas">A Brief Introduction: Quotas</A></LI>
<LI><A HREF="#dansg">A Brief Introduction: DansGuardian</A></LI>
<LI><A HREF="#touchrec">Touchrec: Recursively touches files in a
directory</A></LI>
<LI><A HREF="#gnufind">GNU Find: Evaluating its effectiveness</A></LI>
<LI><A HREF="#intjf">Interview: John M. Fisk</A></LI>
<LI><A HREF="#closet">Closing Time</A></LI>
</UL>
<!-- --------------- -->
<!-- END: contents -->
<!-- --------------- -->
<HR>
<! -- ======================================================================= -->
<! -- --------------- -->
<! -- BEGIN: preamble -->
<! -- --------------- -->
<H2><A NAME="preamble">Welcome to the July edition</A></H2>
<P>Well Howdy. Glad you could all make it. How are you all??? Still keeping
up the pace with the rest of the LG thus far? I hope so, 'cos I can't see
that this article is going to be any different :-)</P>
<P>News for this month?? Well, I have installed myself in my house now.
When I get the chance, I'll get some pictures together for you all to have
a sneak preview into the isolated, but pretty corner of Somerset that I
now reside in when I am not at University, that is.</P>
<P>I also have a new job!! I work in a small factory, which produces eight
different types of luxury dessert for a chain-store called <I>Waitrose</I>.
For those of you who don't know who this company is, <I>Waitrose</I> is
part of the <I>John Lewis Partnership, plc</I>. They specialise in nice,
high quality food. For the really curious among you, here is a list of the
desserts I make:</P>
<UL>
<LI>Chocolate Mousse</LI>
<LI>Zabaglioni (Amorretti biscuit-base mousse)</LI>
<LI>Lemon Dessert</LI>
<LI>Rhubarb Syllabub</LI>
<LI>Blackberry Syllabub</LI>
<LI>Creme Brulee</LI>
<LI>Creme Brulee with Chocolate and Grand Marnier</LI>
<LI>Creme Brulee with Raspberry Compote</LI>
</UL>
<P>I start at 6:00am :-) That's the only the drawback. However it does
mean that I finish around 2-4 in the afternoon.</P>
<P>That's about as exciting as my life gets really, I think it is time to
move on to some proper material.<B> Linux.....</B></P>
<!-- ============= -->
<!-- END: preamble -->
<!-- ============= -->
<HR>
<!-- ======================================================================== -->
<!-- ============= -->
<!-- BEGIN: Quotas -->
<!-- ============= -->
<H2><A NAME="quotas"></A>A Brief Introduction: Quotas</H2>
<!-- ====================== -->
<!-- BEGIN: Content Listing -->
<!-- ====================== -->
<UL>
<LI><A HREF="#Q-wiq">What is Quota?</A></LI>
<LI><A HREF="#Q-inst">Installation</A></LI>
<LI><A HREF="#Q-sq">Setting Quotas</A></LI>
<LI><A HREF="#Q-an">An Example</A></LI>
</UL>
<!-- ==================== -->
<!-- END: Content Listing -->
<!-- ==================== -->
<HR>
<!-- ============================ -->
<!-- BEGIN: Quotas: What is Quota -->
<!-- ============================ -->
<H2><A NAME="Q-wiq">What is Quota?</A></H2>
<P>Way, way back in <A HREF="../issue13/slew.html">
issue 13</A> Jim Dennis wrote a small article about how to set up your
Linux machine so that it would tell you if you were going to run out of
disk space. (SLEW). I read this article, and decided that you can make sure that
your users do not run amok on disk space by enforcing a set <B>rules</B>
by either specifying the number of inodes or blocks that a particular
user cannot exceed.</P>
<P>Quota is handled on a per-user basis though, and is only active on one
file system at a time. Thus, if a user has access to more than one file
system, and you wish to enforce quotas on each of them, then you must do so
separately.</P>
<P>So in short, quota is a way of setting maximum disk space that a user
can consume, at any one time</P>
<HR WIDTH=25%>
<!-- ========================== -->
<!-- END: Quotas: What is Quota -->
<!-- ========================== -->
<!-- ========================== -->
<!-- =========================== -->
<!-- BEGIN: Quotas: Installation -->
<!-- =========================== -->
<H2><A NAME="Q-inst">Installation</A></H2>
<P>As of Kernel version >=2.0, Quota support has been bundled in with the
kernel, and as such, if you come from the dark ages, and have a kernel
version <2.0, then obtain the latest source (<A
HREF="http://www.kernel.org">www.kernel.org</A>) NOW!!</P>
<P>And as for the rest of the GNU/Linux planet, you should find that you
already have quota support enabled by default in the kernel anyway. If you
<I>think</I> you have not, then download the latest stable release and
re-compile. It can't hurt.....much :-). For instructions on how to do this,
please refer to the INSTALL file, under the source directory.</P>
<P>Incidentally, for those users running a nice shiny SuSE Box, Quota
automatically comes compiled into the kernel :-)</P>
<P>But the fun-and-games continue, since Quota is not directly runnable
from the kernel itself (i.e. it is not a self-contained module). You have
to either install an RPM for Source file.</P>
<P>The RPM file (should you be using a distribution that uses this system
of package handling) in question is:</P>
<B>quota-1.70-263.rpm</B>
<P>And the tarball file is called:</P>
<B>all.tar.gz</B>
<P>Both of which are available from the following FTP repository:</P>
<A HREF="ftp://ftp.funet.fi/pub/Linux/PEOPLE/Linus/subsystems/quota/">
ftp://ftp.funet.fi/pub/Linux/PEOPLE/Linus/subsystems/quota/</A>
<P><U>To install the RPM file:</U></P>
<P>Issue the command:</P>
<B>su - -c'rpm -i /path/to/quota-1.70-263.rpm'</B>
<P><U>To install the source file</U></P>
<PRE>
1. <B>su -</B>
2. <B>cd /path/to/tarball/</B>
3. <B>tar xzvfm ./all.tar.gz</B>
4. <B>./configure</B></PRE><I>[ Allow for configure script to run ]</I>
<PRE>
5. <B>make && make install</B>
6. <B>logout</B></PRE><I>[ To exit out of root's &quot;su;ed&quot; account
]</I>
<P>That's all there is to it :-) Now the <I><B>real</B></I> fun begins</P>
<!-- ======================== -->
<!-- END: Quota: Installation -->
<!-- ======================== -->
<HR WIDTH=25%>
<!-- ============================ -->
<!-- BEGIN: Quota: Setting Quotas -->
<!-- ============================ -->
<H2><A NAME="Q-sq">Setting Quotas</A></H2>
<P>The first step in configuring this, is to have a logical idea in your
head as to how you are going to organise this. Quota gives you the option
of either specifying a single user, or a group (which has been assigned to
specific users), or both. If you are on a large network, then perhaps a
mixture of the two is preferable. Think about it :-)</P>
<P>Group version is usually good, if you assign <B>all</B> users to that
specific group. Makes life easier, <EM>n'est pas?</EM></P>
<P>But the first actual step is to make some system-wide changes. For
this, log in as user <B>root</B>. Please though, do not simply
&quot;su&quot; in, as this simply changed your effective UID, and does
nothing about export variables, etc.</P>
<P>We must first modify &quot;/etc/fstab&quot; so that the kernel knows
that the filesystem mount point will make use of the quota support. A
typical &quot;/etc/fstab&quot; file looks like the following:</P>
<PRE>
/dev/hda1 /boot ext2 defaults 1 2
/dev/hda2 swap swap defaults 0 2
/dev/hda3 / ext2 defaults 1 1
/dev/cdrom /cdrom auto ro,noauto,user,exec 0 0
/dev/fd0 /floppy auto noauto,user 0 0
proc /proc proc defaults 0 0
usbdevfs /proc/bus/usb usbdevfs defaults 0 0
devpts /dev/pts devpts defaults 0 0
#NFS clients....
#Updated: Thomas Adam, Tuesday 03:45am??? -- Can't remember.
server:/etc /mnt/etc nfs rw,user,rsize=1024,wsize=1024,hard,intr 0 0
server:/home /mnt/home nfs rw,user,rsize=1024,wsize=1024,hard,intr 0 0
server:/usr/doc/lg/lg/lwm /mnt/lwm nfs rw,user,hard,intr 0 0
#server:/usr /mnt/usr nfs rw,user,hard,intr 0 0
server:/cdrom /cdrom nfs ro,user,rsize=1024,wsize=1024,hard,intr 0 0
server:/dev /mnt/dev nfs ro,user,rsize=1024,wsize=1024,hard,intr 0 0
</PRE>
<P>What we are concerned with, is not the last part of the file <I>[ ** although
<B>quota</B> can be used with <B><I>nfs</I></B> exported file types -- see
&quot;man rquota&quot; ** ]</I>, but with
which mount point is to be issued with quota support. This will depend
upon where your user's $HOME directories are located. Unless you have got a
separate partition or drive for this, then typically the mount points you
will want to use is either &quot;/&quot; or &quot;/usr&quot; (if
<B>/home</B> is a symlink to &quot;/usr/local/home/&quot; -- and
&quot;/usr&quot; is on a separate drive or partition.)</P>
<P>Now I come back to my original question that I first posed at the
beginning of this section. How are the users going to be managed? If you
have decided to do it just on a user by user basis, then add
<B>usrquota</B> to your fstab file. If you are going to do it by group then
add <B>grpquota</B>. If you are going to use a mixture of the two, then add
them both.</P>
<P>Thus, we are now concerned with adding to the fourth field the
following:</P>
<PRE>
/dev/hda3 / ext2 defaults,<B>usrquota,grpquota</B> 1 1
</PRE>
<P>Change as appropriate for your version of fstab. If you are unsure as to
which quota to use, I recommend that you include both in the fstab file,
since it means that should you need to swap, you'll already have it set up.
Now save the file.</P>
<P>OK. The next thing we have to do is to make sure that for whichever
option you chose (i.e. namely <B>usrquota</B> or <B>grpquota</B>), that you
create the necessary file(s) on the root of the partition that you changed
in the fstab file. To do this, enter the following commands (still as user
<B>root</B>)</P>
<PRE>
touch /top/of/partition/quota.user && chmod 600
/top/of/partition/quota.user
touch /top/of/partition/quota.group && chmod 600
/top/of/partition/quota.group
</PRE>
<P>Lastly, you have to ensure that when your system boots up, that quotas
are enabled along with it. For those of you who installed <B>Quota</B> from
an RPM/.DEB, etc should find that they already have a script named
&quot;quota&quot; or something similar in &quot;/etc/init.d/&quot;. If you
installed from source however, this might not be the case, which means that
you will have to add the following script into your main init-script AFTER
the mounting of all files in &quot;/etc/fstab&quot; has taken place.</P>
<PRE>
<A HREF="misc/adam/quota.sh.txt">(text version)</A>
#Check quotas
[ -x /usr/sbin/quotacheck ] && {
echo "Checking Quotas (please wait)...
/usr/sbin/quotacheck -avug
echo "Done."
} || {
echo "Checking Quotas FAILED"
}
[ -x /usr/sbin/quotaon ] && {
echo "Initialising Quotas..."
/usr/sbin/quotaon -avug
echo " Done."
} || {
echo "Turning Quotas On: FAILED
}
</PRE>
<P>What the above does, is runs a test on the named file, for the
&quot;-x&quot; flag which means that it is checking to ensure that the file
is executable, before it processes the rest of the script. It checks to see
what quotas are defined (if any), and then goes on to enable them.</P>
<P>Once you have done that, issue:</P>
<PRE>
<B>init 6</B>
</PRE>
<P>And wait for your computer to reboot. <BR><BR><FONT COLOR="red">Caveat Emptor:
If you did have to recompile your kernel, ensure that if you are using LILO
as your boot-loader that you run: <BR><BR>
<B>lilo</B><BR><BR>
BEFORE you reboot so that it knows about your new kernel-image
:-)</FONT></P>
<!-- ========================== -->
<!-- END: Quota: setting quotas -->
<!-- ========================== -->
<HR WIDTH=25%>
<!-- ============================ -->
<!-- BEGIN: Quota: An Example -->
<!-- ============================ -->
<H2><A NAME="Q-an">An Example</A></H2>
<P>Right. We should now have your machine acknowledging the fact that we
are going to use Quota. What we haven't done yet, is the most important
bit, and that is, who or which groups will be using the quota rule.</P>
<P>What I have decided to do, is to use an example if a user, and show you
how you go about setting up a quota limit for him. We shall call the user
<B>lg</B>.
<P>Assuming <B>lg</B> is already on your system, what we must do is,
depending on which format you are using, edit the appropriate file. For the
purposes of this example, I shall do this on a per-user basis (i.e. I shall
be using the <B>usrquota</B> format, although everything I shall explain
here, is exactly the same for the <B>grpquota</B> option, if you have
decided to do that.</P>
<P>The command that we shall be using is called &quot;edquota&quot; What we
must do is edit a quota for user <B>lg</B> by issuing the command:</P>
<PRE>edquota -u lg</PRE>
<P>What this does, is launches an editor, and opens a new quota. If you
haven't set the environment variable EDITOR="/usr/bin/jed" or some
equivalent editor, then this command will not work. To set up this
variable, add this to your &quot;~/.bash_profile&quot;</P>
<PRE>
EDITOR="/usr/bin/jed"
export EDITOR
</PRE>
<P>Change the program as you see fit, i.e. Vi, jed, joe, emacs, etc. Then
to make the changes active, source the file, by typing:</P>
<PRE>source ~/.bash_profile</PRE>
<P>What you should find, is that for user <B>lg</B> you get something
similar to the following:</P>
<PRE>
Quotas for user lg:
/dev/hdb2: blocks in use 0, limits (soft = 0, hard = 0)
inodes in use: 356, limits (soft = 0, hard = 0)
</PRE>
<P>Now your thinking: &quot;err....&quot :-) Don't worry. It is much more
simpler than it looks.</P>
<P><B>Blocks</B> indicate the total number of blocks that a user has used
on a partition (measured in Kilobytes, KB).</P>
<P><B>Inodes</B> indicate the total number of files that a user has on the
partition. N.B. These values you cannot change.</P>
<P>What we are concerned with, is the bit in brackets, right at the end of
each line. This is the key to setting the entire quota. You'll notice that
there are two options, one for <B>soft</B> and one for <B>hard</B>.
<P><B>Soft limits</B> indicate the maximum amount of space (in Kilobytes)
that <B>lg</B> is allowed to have. It acts as a boundary which when set
along with a <B>grace period</B> informs to user <B>lg</B> that he is
exceeding his limit.</P>
<P>A <B>grace</B> limit is a period of time before the <B>soft</B> limit is
enforced. This can be set from (sec)onds, (min)utes, hour, day, week,
month. This is set by issuing the command:</P>
<PRE>edquota -t</PRE>
<P>You'll see that you should get the following:</P>
<PRE>
Time units may be: days, hours, minutes, or seconds
Grace period before enforcing soft limits for users:
/dev/hdb2: block grace period: 0 days, file grace period: 0 days
</PRE>
<P>Change both values for <B>block</B> and <B>file</B> to whatever you see
fit. I recommend 14 days (2 weeks) for both. But then, I am generous
:-)</P>
<P>A <B>hard</B> limit indicates the maximum amount of space that a user
<I>cannot</I> exceed. This only works when a grace period has been set.</P>
<P>That's all there is to it. Now, you are probably wondering how the hell
you are supposed to assign the same quota to every user on your system.
Well, having just followed the example for <B>lg</B>, what you can do, is
to use user <B>lg</B> as a template, and issue the command:</P>
<PRE>awk -F: '$3 >= 500 {print $1}' /etc/passwd'</PRE>
<P>What this does, is prints a list to the screen of all users who start
with a UID greater than 499 (i.e 500 onwards). If this set of users on the
screen looks OK, then we can use the above, in conjunction with the
<B>edquota</B>, as shown below:</P>
<PRE>edquota -p lg $(awk -F: '$3 > 499 {print $1}' /etc/passwd')</PRE>
<P>This uses the quota we have already enabled for <B>lg</B> as a template
to assign it to the string of users that the awk script produces for
us.</P>
<P>That's all there is to it :-). I have found quota to be an excellent
tool in keeping users at bay. I use it for my non-root account, as it stops
me from going wild in my home directory, and thus forces me to clean it out
once in a while.</P>
<!-- ========================== -->
<!-- END: Quota: An Example -->
<!-- ========================== -->
<HR>
<!-- ======================== -->
<!-- ============================ -->
<!-- BEGIN: Dansguardian -->
<!-- ============================ -->
<H2><A NAME="dansg">A Brief Introduction: DansGuardian</A></H2>
<UL>
<LI><A HREF="#DG-wis">What is DansGuardian?</A></LI>
<LI><A HREF="#DG-ins">Installation</A></LI>
<LI><A HREF="#DG-conf">Configuration</A></LI>
</UL>
<HR WIDTH=25%>
<H2><A NAME="DG-wis">What is DansGuardian?</A></H2>
<P>For those of you who followed my last miniature introduction to the world
of linux proxying for <B>Squid</B> and <B>SquidGuard</B>,
<A HREF="http://www.linuxgazette.com/issue78/adam.html">will remember</A> that
I showed you how you could filter certain webpages that matched a certain
regex. What <B>Dansguardian</B> does. is take the concept of filtering and
stretches it so that you can filter webpages, based on <B>content!!</B>. Also
though, Dansguardian allows you to filter out mime-types and block file
extensions, thus meaning that should your users have the unfortunate punishment
of using an M$-Windows machine, you can block files such as <B>.exe, .com,
.dll, .zip .... etc</B></P>
<!-- ======================================== -->
<HR WIDTH=25%>
<H2><A NAME="DG-ins">Installation</A></H2>
<P>Dansguardian can be obtained from the following:</P>
<A HREF="http://www.dansguardian.org">http://www.dansguardian.org</A>
<P>You can either download an RPM or tar.gz file from his site. If you're a
budding Debian GNU/Linux user, then you can always use the <B>alien</B>
package to convert the RPM file to a DEB file :-). To actually install the
files, follow the <A HREF="#Q-inst">instructions</A> as in the Quota
section.</P>
<P>It is also worth noting, that Dansguardian requires the use of the
<B>nb++</B> library. There is a link to a download site, on the main site
of dansguardian. This library is used to look at the content of webpages,
and is thus essential to the operation of Dansguardian.</P>
<P>On install, dansguardian, main program is installed as
&quot;/usr/sbin/dansguardian&quot. What you must do, is either in
&quot;/etc/init.d/rc.local&quot; OR &quot;/etc/init.d/boot.local&quot;
(depending on which distribution you are using), add:<P>
<PRE>
/usr/sbin/dansguardian
</PRE>
<P>So that Dansguardian is loaded up on init.</P>
<!-- ======================== -->
<HR WIDTH=25%>
<!-- ======================== -->
<!-- BEGIN: DG: Configuration -->
<!-- ======================== -->
<H2><A NAME="DG-conf">Configuration</A></H2>
<P>There really is not <I>too</I> much to configure when it comes to
Dansguardian. What takes all the work, is the various regex expressions
that you may want to build for really accurate content filtering.</P>
<P>It should be pointed out that DansGuardian can be used in conjunction
with <A
HREF="http://www.linuxgazette.com/issue78/adam.html#squidg">SquidGuard</A>
so that you don't have to replace any existing filters that you may already
have in place :-) Good, eh?</P>
<P>So, the first thing we should do, is check where the package has put the
configuration files. Well, it should be no surprise that they have been out
in &quot;/etc/dansguadian&quot;, and it is the files contained in this
directory that we shall concentrate on. We shall begin by looking at the
configuration file <B>/etc/dansguardian/dansguardian.conf</B>.</P>
<P>This is all the settings that Dansguardian will require. Typically, the
only options that I have had to change are listed below:</P>
<PRE>
#DansGuardian config file
[Reporting]
reportinglevel = 1 # 0 = just say 'Access Denied'
# 1 = report why but not what denied phrase
# 2 = report fully
[Network Settings]
filterport = 8080 # the port that DansGuardian listens to
proxyip = 127.0.0.1 # loop back address to access squid locally
proxyport = 3128 # the port DansGuardian connects to squid on
accessdeniedaddress = "http://grangedairy.laptop/cgi-bin/dansguardian.pl"
[Logging] # 0 = none 1 = just denied 2 = all text based 3 = all requests
loglevel = 2
[Content Filtering]
bannedphraselist = "/etc/dansguardian/bannedphraselist"
bannedextensionlist = "/etc/dansguardian/bannedextensionlist"
bannedmimetypelist = "/etc/dansguardian/bannedmimetypelist"
exceptionsitelist = "/etc/dansguardian/exceptionsitelist"
exceptioniplist = "/etc/dansguardian/exceptioniplist"
[Phrase Scanning] # 0 = normal 1 = intelligent
scanningmode = 1
# normal does a phrase check on the raw HTML
# intelligent does a normal check as well as removing HTML tags and
# multiple blank spaces, tabs, etc - then does 2nd check
[ ** Many other options elided ** ]
</PRE>
<P>The only things I changed here, was the <B>filterport</B>, the
<B>proxyport</B> and the <B>accessdeniedaddress</B> tags, to reflect the
configurations I used in <B>&quot;/etc/squid.conf&quot;</B>. Having
changed your options accordingly, you can save the file, and ignore it
:-)</P>
<P>OK, moving on. In the same directory, you should notice files with the
following filenames:</P>
<UL>
<LI>bannedphraselist</LI>
<LI>bannedextensionlist</LI>
<LI>bannedmimetypelist</LI>
<LI>exceptionsitelist</LI>
<LI>exceptioniplist</LI>
</UL>
<P>I shall take each file in turn, and explain what each one does. Where
appropriate, I shall list small portions of the file.</P>
<B>bannedphraselist</B>
<P>This file contains explicit words and as such, I shall not list its
contents here. Suffice to say, this is the file that holds keywords which
are blocked if found anywhere in the HTML page.</P>
<P>As you will see, each word is enclosed within &lt; &gt; signs, as
in:</P>
<PRE>&lt; sex &gt;</PRE>
<P>These angled brackets are important, since without them, the word would
not be blocked.</P>
<P>You will also notice, throughout the file that some words have a space
either side of the angle brackets, and some only have one space, either end
of the bracket. This is important, since it says to dansguardian how to
block the word.<P>
<PRE>&lt; sex &gt;</PRE>
<P>Indicates that the word sex (and only the word sex) should be blocked
when it is found, nothing more.</P>
<PRE>&lt;sex&gt;</PRE>
<P>Indicates that the word sex should be blocked, regardless of where it is
found in a sentence or phrase. I.e. if it is found in
<B>hellosexyhowareyou?</B> then it will be blocked.</P>
<PRE>&lt; sex&gt;</PRE>
<P>Means that anything is blocked, to the left of the word.</P>
<PRE>&lt;sex &gt;</PRE>
<P>Is the converse of the above.</P>
<P>As you look down the file, you'll see a number of different words which
are being blocked. :-) You will also notice that there a number of comments
of example words or hyphenated phrases which are not blocked, because you
have already blocked part of that word. For example:</P>
<PRE>&lt;middlesex&gt;</PRE>
<P>Need not be blocked, since the phrase:</P>
<PRE>&lt;sex&gt;</PRE>
<P>is already blocking any other word that contains the word <B>sex</B>.
That is an important fact to remember of you are going to be adding to the
list at a later date.</P>
<B>bannedextensionlist</B>
<P>Simply contains a list of file extensions that will be blocked by
dansguardian, thus:</P>
<PRE>
#Banned extension list
.gz
.tar
.zip
.mp3
.mpeg
.mpg
.avi
.exe
.sys
.ini
.bat
.doc
.xls
.scr
</PRE>
<P>This is pretty much self explanatory!!</P>
<B>bannedmimetypelist</B>
<PRE>
# banned MIME types
audio/mpeg
audio/x-mpeg
audio/x-pn-realaudio
video/mpeg
video/x-mpeg2
video/acorn-replay
video/quicktime
video/x-msvideo
video/msvideo
application/gzip
application/x-gzip
application/zip
application/compress
application/x-compress
application/java-vm
</PRE>
<P>MIME types are used to identify different multi-media portions of
applications, and as such is particularly useful when sending e-mail,
however MIME has its uses in HTML too :-)</P>
<P>Again, I would add some other options here.</P>
<B>exceptionsitelist</B>
<P>Lists those sites which, are allowed to be viewed, even though it would
ordinarily be blocked by the rules defined in any of the other files,
thus:</P>
<PRE>
#Sites in exception list
#Don't bother with the www. or
#the http://
jadeb.com
</PRE>
<P>You can obviously add more sites as you are going along :-)</P>
<B>exceptioniplist</B>
<PRE>
#IP addresses to ignore and just
#pass straight through.
#
#These would be servers which
#need unfiltered access for
#updates. Also administrator
#workstations which need to
#download programs and check
#out blocked sites should be
#put here.
#
#Only put IP addresses here,
#not host names
192.168.0.1
192.168.0.2
192.168.42.2
#these are examples above
#delete them and put your own
#in if you want
</PRE>
<P>The comments in this, pretty much say all :-). Obviously I would say be
careful as to which machines you allow override access to :-)</P>
<P>And that rather short explanation explains how dansguardian works. You
may well find, as I did, that it is very frustrating at first, since it
really does block what you tell it to, but once you yourself have shoved a
whole load of domain names into the <B>exceptionsitelist</B>, things should
not be too bad at all! :-)</P>
<!-- ===================== -->
<!-- END: DG: ALL SECTIONS -->
<!-- ===================== -->
<HR>
<!-- ========================== -->
<!-- ===================== -->
<!-- BEGIN: Touchrec -->
<!-- ===================== -->
<H2><A NAME="touchrec">Touchrec: Recursively touches files in a
directory</A></H2>
<P>In <A HREF="http://www.linuxgazette.com/issue66/tag/2.html"
TARGET="_blank">issue66</A>, there appeared a thread about how to
recursively touch files in a given directory. Since the GNU
version of touch does not support an option (yet), a few
suggestions were offered using GNU find.</P>
<P>Indeed I was intrigued by this idea. I have often been in a situation
where having a recursive feature to touch all files and/or directories was
a necessity. Such an example is where I had forgotten to add the
&quot;m&quot; flag to the tarball I was un-tarring, and as a result had a
while load of future modification dates on my files (See <A
HREF="../issue79/lg_tips.html#tips/3">
issue79</A>). Deleting the entire directory would have been a pain, since
it took <I>ages</I> to untar. Thus, I decided to write the following
shell-script :-)</P>
<A HREF="misc/adam/touchrec.tar.gz">(tar.gz file)</A>
<P ALIGN="center">-----------------</P>
<PRE>
#!/bin/bash
##########################################################
#touchrec -- Recursively "touches" files in a directory #
#Ackn: Written for TAG (Linux Gazette) :-) #
#Version: Version 1.0 (first draft) #
#Author: Created by Thomas Adam #
#Date: Saturday 15 June 2002, 16:58pm BST #
#Contact: thomas_adam16@yahoo.com #
##########################################################
#Declare Variables
bname=$(basename $0) #Basename of program (path stripped)
curr_dir=$(pwd) #Current dir
dironly=0 #-d off
filesonly=0 #-f off
quiet=0 #-q off
toplevel= #-l off
redir=$(tty) #verbosity redirection tag
version="$bname: Created by Thomas Adam, Saturday 15 June 2002, 16:58pm BST,
Version 1.0"
#Start Procedures
#Help Procedure
help_user()
{
echo "
$bname usage: [-s directory path] [-q] [-d] [-f] [-t] [-h] [-v]
where:
-s (optional starting directory, default is 'pwd')
-q (quiet mode -- suppresses verbosity)
-d (only touch directories)
-f (only touch files)
-t (touches the top-level directory, i.e. '.')
-h (prints this message)
-v (version of program)
Issue command \"man \\1 touchrec\" for full documentation
"
exit 0
}
run_default ()
{
for lists in $(find ${curr_dir} ${toplevel} -depth 2> /dev/null); do
#If it's a directory....
[ -d $lists ] && {
#All directories -- yes
[ $dironly = 0 ] && {
#Just the files? -- continue to the next instance of a loop, if so
[ $filesonly = 1 ] && {
continue
}
echo "touching dir $lists/" >$redir && touch -c $lists
continue
} || [ $dironly = 1 ] && {
#then we are only checking for directories
echo "touching dir $lists/" >$redir && touch -c $lists
}
#This time check for files...
} || [ $dironly = 0 ] && {
[ -f $lists ] && {
[ $filesonly = 1 ] && {
#Only checking for files....
echo "touching files $lists" >$redir && touch -c $lists
continue
} || [ $filesonly = 0 ] && {
#As a result of no flags passed at run-time, this executes :-)
echo "touching files $lists" >$redir && touch -c $lists
}
}
}
done
}
#Main
#Check for presence of command-line switches
if [ "$#" = 0 ]; then
echo "No command-line args given"
curr_dir=$(pwd)
else
while getopts ":hqlfvdts: " opts; do
case $opts in
d )
#Only Check for Directories
dironly=1
;;
q )
#Quiet -- suppresses verbosity to console
quiet=1
redir="/dev/null"
;;
f )
#Only check for files, no directories
filesonly=1
;;
t )
#Only process the top-level directory "."
toplevel="-maxdepth 1"
#echo $toplevel #for debugging purposes
;;
s )
#Get path as specified
#If $optarg is blank, print help_user()
[ $OPTARG = "" ] && {
echo "No Parameter Given"
help_user
} || curr_dir=${OPTARG}
;;
h )
#Print help message
help_user
;;
v )
#Prints the version
echo $version
exit 0
;;
-* | * )
#Any other options -- ignore
help_user
;;
esac
done
fi
#Process optional commands...
shift $(($OPTIND - 1))
#Start main procedure -- once all options processed.
run_default
</PRE>
<P ALIGN="center">-----------------</P>
<P>For those of you who are completely new to BASH programming, please
refer back to Ben Okopnik's excellent tutorial earlier on in the LG series
(<A HREF="http://www.linuxgazette.com/issue52/okopnik2.html"
TARGET="_blank">issue52</A> onwards). For those experienced programmers,
you'll notice that I have used the &quot;[ ..... ] && {} ||&quot;
construct, rather than the more traditional &quot;if..then..else..fi&quot;
method, since the former gives more control with exit status :-), and
I prefer coding like this anyway. Perl also requires this syntax too :-)</P>
<P>The script in itself is quite simple. Basically what happens is that I
initialise all of my variables first. Now, BASH does not require this, but
I find it much easier to know what's going on if I do.</P>
<P>I set up various variables, most of which are just switch identifiers so
that I can tell whether or not any command-line switches (and which ones)
have been issued. I set up another variable <B>bname</B> which returns the
name of the program, with the PATH stripped, which I used in my
<I>help_user()</I> function.</P>
<P>The other variable I defined is the <B>redir</B> variable. This is
initially set to whichever tty you invoke the script from, so that if you
did not specify the &quot;-q&quot; option, you will get messages to your
screen. I think I have been quite clever since, whenever a file/directory
is found, I issue a command thus:</P>
<PRE>echo "touching $lists/" >$redir</PRE>
<P>which, as I say is set to whatever tty you invoked it from.
(/dev/tty1)???. But, if you specified the &quot;-q&quot; flag $redir equals
&quot;/dev/null&quot; so that no messages appear</P>
<P>With regards to command-line switching, I have made good use of the
<B>getopts</B> command. Refer to <B>man 1 touchrec</B> for more information
on that.</P>
<P>I was so taken by this, that I even wrote a manual page :-).
Simply download the tar.gz file, untar it, and run
&quot;install.sh&quot;</P>
<P>For more information about how to use this script, please refer to
&quot;man touchrec&quot;. Hope you get good use out of it :-)</P>
<HR>
<!-- ============= -->
<!-- END: Touchrec -->
<!-- ============= -->
<H2><A NAME="gnufind">GNU Find: Evaluating its effectiveness</A></H2>
<P>How many of you have been guilty of using <B>mc</B> (midnight
commander), hitting the key sequence
&quot;&lt;ALT&gt;&lt;SHIFT&gt;&lt;?&gt;&quot; before, and then filling out
that nice dialog box to find the file that you require?? Don't lie, we've
all done it <B>(Hi Ben :-))</B>. And why? All that dialog box is, is a front
end to the command <B>find(1)</B> anyway. This article will help try and
wean you off pretty command-line dialog boxes. While there is nothing wrong
with using <B>mc's</B> searching feature, it does not give you the full
benefit to do complex searches. GNU <B>find</B> is a very
powerful tool indeed.</P>
<H2>Finding one particular file</H2>
<P>The most common use of find, is knowing where a certain file is. Now,
usually, if it is a binary file, you would most likely either use the
commands <B>which</B> and <B>where</B> to find it :-), but what if you were
looking for that file called <B>etherh.c</B>? You'd issue the command:</P>
<PRE>
cd /
find / -name etherh.c -print 2>/dev/null
</PRE>
<P>Now don't panic :-) The syntax of the find command is thus:</P>
<PRE>find {/path/} [name_of_file/expression] [options...]</PRE>
<P>So, what the command does, is beginning at &quot;/&quot; (the root
directory of the partition), search for the file called <B>etherh.c</B>,
when it finds it, <B>-print</B> it to stdout (and in this case the
<I>2&gt;/dev/null</I> redirects any errors to oblivion. -- used here
because I am not user <B>root</B> I obviously have permission problems
looking at certain files from &quot/&quot; that I don't care to know
about!)</I>.</P>
<P>The <B>-name</B> flag above has more than just one use as shown here. It
is in fact a flag which allows you to pass shell metacharacters to the
filename that you are trying to look for, and we will discuss that in the
next section.</P>
<P>If you have your kernel sources installed, you should find that the
file, is at:</P>
<PRE>/usr/src/linux/drivers/acorn/net/etherh.c</PRE>
<H2>Finding filenames using shell metacharacters</H2>
<P>It is all very well, knowing the exact name of the file that you trying
to search for. That makes life easier. But what if you didn't know the
exact name of the file, what then?</P>
<P>Well, in that situation, you would obviously have to use wildcards, or
more specifically shell metacharacters. These are characters such as:</P>
<PRE>
*
?
[]
{} -- [ although these have their uses as we shall see later on ]
</PRE>
<P>Quite simply then, we can try something like the following:</P>
<PRE>
find /usr/bin -name 'xa*' -print
</PRE>
<P>Which should return:</P>
<PRE>
/usr/bin/xargs
</PRE>
<P>The sharp eyed among you will have noticed that I
<H2>Find involving actions</H2>
<P>You can also tell find to run a program on the file(s) that it finds
too. This is an extremely useful feature, and you will be surprised at just
how often you will have cause to use it.</P>
<P>Suppose you have a bunch of files, say in $HOME, and I wanted to look
for a regular expression in each of them, i.e. "#!/bin/bash". I can do the
following:</P>
<PRE>
find $HOME -name '*' -print -depth -exec egrep -n '#!/bin/bash' {} \;
</PRE>
<P>The syntax of the last part, may seem strange, but what is happening is
that the flag <PRE>-exec</PRE> accepts first the command, and then any
addition options (in this case, a regular expression), followed by two
brackets {} which when run, will be expanded to the current filename which
is returned by the find parameter (be it a regular expression or specific
filename -- in this case all files (*). The backslash (\;) terminates the
command.</P>
<P>Therefore, in short, the syntax is:
<PRE>
find -path -name {pattern/regex} -exec {name_of_program} [options] {} \;
</PRE>
<P>You can then apply this principle to use any command that you can see a
use for :-)</P>
<H2>Finding particular types</H2>
<P>Once again, find makes our life even easier, by allowing us to look for
specific file types. Now, while you might well think that you could use a
combination of <PRE>ls, test, find</PRE> to do the same thing, <B>don't
re-invent the wheel</B> :-). Here are some examples:</P>
<PRE>find / -name '*' -print -depth -type d</PRE>
<P>-- which prints only directories</P>
<PRE>find / -name '*' -print -depth -type f</PRE>
<P>-- which finds only files</P>
<PRE>find / -name '*' -print -depth -type l</PRE>
<P>-- finds symbolic links only</P>
<P>If you only want to search say, on the top-level directory, and not
traverse any lower, then you can use the:</P>
<PRE>-maxdepth {number}</PRE>
<P>switch. For example, if you only wanted to search for directories which
is in your $(pwd) -- (current working directory) you can do:</P>
<PRE>
find / -name '*' -type d -maxdepth 1 -print
</PRE>
<P>Which on my computer (laptop) returns the following:</P>
<PRE>
/
/lost+found
/boot
/proc
/var
/tmp
/etc
/sbin
/bin
/lib
/root
/usr
/cdrom
/floppy
/home
/mnt
/opt
/dev
/chess
/pavement
</PRE>
<P>The number indicates the number of subdirectories that you wish to
descend during your search.</P>
<P>But the fun doesn't stop just with this mini-article. <B>find</B> has a
whole host of other options many of which I cannot ever see the need
for, but that's only because I have a limited use for it.....</P>
<P>Definitely check out the command:</P>
<B>man find</B>
<HR>
<!-- ========================== -->
<A NAME="intjf"><H2>Interview: John M. Fisk</H2></A>
<I>[ Yep! It is the same John Fisk that started off this magazine, and
thie Weekend Mechanic series. I was <B>really</B> pleased when John sent me an
e-mail out of the blue saying he had read my article :-) So, I post a
transcript of our conversation here -- Thomas Adam ]</I>
<BR><BR>
<I><FONT COLOR="blue"><B>[John]</B></FONT></I>: &nbsp; <PRE><B>Dear Thomas,
I want to say thanks for keeping up the "Weekend Mechanic" column in the
LG. I have to admit that I've had little time for pleasure reading (and
much less for writing) these past several years. On a whim, I started
reading the latest LG (after seeing an announcement for it on the lwn.net
site) and noticed the WM column was still there. I'm absolutely delighted
that you're keeping it going and wish you the very best.
Trust your end-of-semester exams go well. Have a great summer 'linuxing.
cheers,
John
p.s., kudos for providing "install from source" instructions for squid. I
suppose that a growing number of users are simply dependent on rpm or deb
binaries (and there are good reasons for using these) but I still tend to
"roll my own" from source and make a package out of it when I'm not feeling
so lazy :-)
</B></PRE>
<I>[Thomas]</I> &nbsp;
<PRE>Hello. I must say that I feel *very* honoured to have
received an e-mail from you -- especially as you
founded the Linux Gazette :-) You have no idea just
how much I valued your efforts way back in 1996. Had
you any idea that the LG would be as popular as it is
now?
</PRE>
<I><B><FONT COLOR="blue">[John]</B></FONT></I>: &nbsp;
<PRE><B>
Absolutely not. I started getting interested in Unix/Linux during the
summer of 1994. I had just switched from being a general surgery resident
at a very busy tertiary care hospital to working as a research assistant in
the lab of one of the hepatobiliary surgeons. I managed to get a dial-up
account on the universities VAX machine (2400 baud :-) and started using
gopher. Somehow, I ran across information on Linux and decided to give it
a try since I was interested in doing a medical informatics fellowship.
It took countless days to download the installation floppy set from TAMU
(Texas A&M Univ.). I had a 2 MB limit on my shell account so I would ftp
an image to the account and then turn around and transfer it to my local
box via kermit. TAMU was the first distribution I ever tried. Almost
immediately, I decided to give Slackware a try -- it was the "new kid on
the block" and was supposed to be so much better than SLS. That was
August, 1994.
After playing with Linux for a year or so I decided that I wanted to learn
how to write HTML and so the Linux Gazette was born out of similar
"itches": learning Linux and learning HTML. I absolutely loved Linux, and
do so to this day, so it was easy to come up with content. I just wrote
about the things I loved and found exciting. I had no earthly notion that
it would be that popular. I had a good deal more time on my hands back
then and so I was able to do almost everything -- write columns, coordinate
inclusions by others, format the entire batch so that the HTML was at least
reasonably "legal", etc.
About a year later (issue 8) I was in over my head and was now back in
school full time working on a computer science degree (actually, I was a
non-degree seeking graduate student, but I took the entire computer science
curriculum and enough math courses for a math minor). Phil Hughes from the
Linux Journal got in touch with me. He was interested in an online
magazine of this type and offered to take over the administrative
work. So, I was terribly relieved to turn the reins over to him and
continue writing.
</B></PRE>
<I>[Thomas]</I>: &nbsp;
<PRE>
I started reviving your article several months ago.
Although I started submitting articles once a
month, they have been more intermittent of late, due
to University work getting in the way :-(
</PRE>
<I><B><FONT COLOR="blue">[John]</B></FONT></I>: &nbsp;
<PRE><B>
Brother, I know that feeling... :-)
</B></PRE>
<I>[Thomas]:</I> &nbsp;
<PRE>
Incidentally, I hope you didn't mind me, re-using your
article name, and images. I had tried to get in
contact with you, to ask your permission, but it seems
that you don't mind :-)
</PRE>
<I><B><FONT COLOR="blue">[John]</B></FONT></I>: &nbsp;
<PRE><B>
Not in the least. I'm absolutely delighted that you've done this and wish
you the very best.
</B></PRE>
<I>[Thomas]:</I> &nbsp;
<PRE>
If time permits, you should start reading the LG. It
would be nice, if you could send an e-mail to the
editor :-) Just to say, hi. I'm sure that'll cause
quite a stir.....especially with Jim Dennis :-)
</PRE>
<I><B><FONT COLOR="blue">[John]</B></FONT></I>: &nbsp;
<PRE><B>
I'll do that.
</B></PRE>
<I>[Thomas]:</I> &nbsp;
<PRE>
What are you doing these days??? Your last ever
article said that you'd finished your degree
(congratulations) and was going to work for a medical
centre?? Is this still the case?? How is your wife??
</PRE>
<I><B><FONT COLOR="blue">[John]</B></FONT></I>: &nbsp;
<PRE><B>
At the moment, I'm within a couple years of finally finishing up my medical
training! I went on to do a brief medical informatics fellowship under
Drs. Randolph Miller and William Stead at the Vanderbilt University Medical
Center and then decided to finish my formal medical training in
Pathology. I matched at Yale (here in New Haven, Connecticut) and have
completed 2 years of Anatomic Pathology training. This year, I was able to
take a year off to do some medical informatics research with Dr. Prakash
Nadkarni. We've just finished writing our first paper (in information
retrieval) and I'm working on two additional projects. I start back "on
the wards" as a Clinical Pathology (AKA, Laboratory Medicine) resident on
July 1.
Life has gotten a rather busy of late. My wife and I adopted a little girl
from China in August, 2000. She's a cutie pie, but definitely takes a good
deal of what little "free time" we had left :-). Any more, I try to keep
up with things in the Linux Community but I've had no time to write.
What distribution are you using?
</B></PRE>
<I>[Thomas]</I>: &nbsp;
<PRE>
I'm using SuSE 7.1, soon to switch back to using <B>Debian</B>
</PRE>
<I><B><FONT COLOR="blue">[John]</B></FONT></I>: &nbsp;
<PRE><B>
I'm still using Slackware :-). You mentioned that you've been using Linux
for around six years. That's long enough that you've probably given a
number of distributions a whirl. I have to say that I really like
Mandrake, and I've run Debian for short time. Eventually, however,
managing the *.deb's and *.rpm's becomes a headache and I start fighting
with the package manager. In time, I just get disgusted and go back to
Slackware. It's stable, Patrick V. does a nice job of keeping current
without pushing too far toward the bleeding edge. And I still compile
nearly everything from scratch.
</B></PRE>
<I>[Thomas]</I>: &nbsp;
<PRE>
Thanks again John :-)
Keep in touch,
</PRE>
<I><B><FONT COLOR="blue">[John]</B></FONT></I>: &nbsp;
<PRE><B>
You too. Best wishes,
John
--
John M. Fisk, M.D.
Postdoctoral Research Associate, The Yale Center for Medical Informatics
Yale University School of Medicine, 333 Cedar Street, PO Box 208009, New
Haven, CT 06520-8009
email: John.Fisk@yale.edu
phone: (203) 764-8132
</B></PRE>
<!-- ========================== -->
<!-- =================== -->
<!-- BEGIN: closing time -->
<!-- =================== -->
<HR>
<H2><A NAME="closet">Closing Time</A></H2>
<P></P>
<P>Oh well, until next month -- take care.</P>
<!-- ==================== -->
<!-- END: closet -->
<!-- ==================== -->
<HR>
<!-- ** Begin table comments, etc. Oh wakey wakey you idiot Thomas ** -->
<TABLE width="60%" align=center border=0>
<TBODY>
<TR>
<TH></TH>
<TH></TH>
<TH></TH>
<TR>
<TD width="10%"><IMG height=64 alt="" src="../gx/adam/mail.png"
width=64 align=left></TD>
<TD align=middle width="80%"><FONT color=red size=5>Send Your
Comments</FONT></TD>
<TD width="10%"><IMG height=64 alt="" src="../gx/adam/mail.png"
width=64 align=left></TD></TR></TBODY></TABLE>
<P align=center><FONT size=3>Any comments, suggestions, ideas, etc can be mailed
to me by clicking the e-mail address link below:</FONT></P>
<P align=center><FONT size=3><A
href="mailto:thomas_adam16@yahoo.com">mailto:thomas_adam16@yahoo.com</A></FONT></P>
<HR>
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Thomas Adam</H4>
<EM>My name is Thomas Adam. I am 18, and am currently studying for A-Levels
(=university entrance exam). I live
on a small farm, in the county of Dorset in England. I am a massive Linux
enthusiast, and help with linux proxy issues while I am at school. I have been
using Linux now for about six years. When not using Linux, I play the piano,
and enjoy walking and cycling.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright &copy; 2002, Thomas Adam.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Introduction to Programming Ada</font></H1>
<H4>By <a href="mailto:thomas_adam16@yahoo.com">Thomas Adam</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<H2>Introduction</H2>
<P>I'm quite old-fashioned when it comes to computers. I am one of these
people whom prefers working at a command-line driven interface rather than
a GUI. So it should not come as a shock to you that many of the
programming languages I have experimented in are also based on <I>textual
</I> input / output. <B>Ada</B>, along with <B>Perl, Bash, Sed, Awk,
C</B>, etc is no such exception.</P>
<P>Over the years, there have been quite a few programming languages
mentioned in the <I>Linux Gazette</I>. Ben Okopnik has done two
<B><I>very</I></B> good tutorials on both <B>Perl</B> and <B>Bash</B>,
and other people have contributed to describing other languages, such as:
<B>Smalltalk, C++, Python</B>. Over the next couple of months, I shall
be writing a series of articles to do with programming in Ada.</P>
<H2>What is Ada?</H2>
<P>Glad you asked :-) Originally <B>Ada</B> was a US governmental (DoD)
developed programming language. The standard was originally known as
Ada83, but this is now obsolete, as it was recently &quot;overhauled&quot;
and re-born as <B>Ada95</B>. This is now the preferred standard and
implementation of the Ada programming language.</P>
<P>In 1983, Ada was standardised by ANSI. Thus, it went through all the
official motions and in that year, that first edition was released. Then
four years later in 1987, ISO released an equivalent standard. At this
time though, the idea of so called OOP (Object-Orientated Programming) was
a concept that had not really been considered.</P>
<P>Ada however, was not designed by a committee. The original design was
implemented by Jean Ichbiah, who won a language design competition. Then
in 1995, Tucker Taft led a small group of developers and Ada95 was born.
Unlike the previous version (Ada83), the implementation of Ada95 (or
Ada9X, as it is sometimes known) underwent a public &quot;benchmark&quot;
test; whereby testers of the language gave their feedback, and suggestions
to make the syntactical and lexicographical layout more efficient.</P>
<P>The name <B>Ada</B> is attributed to a woman called <B>Ada Loveless</B>
(1815-1852) who is considered to be the world's first programmer. Ada
is used in all sorts of situations, and since it is a <B>concurrent</B>
programming language, it is most commonly used in <B>embedded systems</B>.
Ada has been used in some of the following:</P>
<UL>
<LI>Airplanes</LI>
<LI>Air Traffic Control systems</LI>
<LI>Financial Systems</LI>
<LI>Telecommunications Systems</LI>
<LI>Medical Devices</LI>
</UL>
<P>The list however is by no means exhaustive :-)</P>
<H2>Ada Compilers</H2>
<P>Unlike other scripting programming languages (Perl, Bash, Python, tcsh,
etc), Ada like C is compiled rather than interpreted. This means that
the person that is going to run the program does not need the
interpreter installed to use it. Ada programs are therefore standalone
from having any kind of Ada packages installed. <I>[Unless you have used
pragmas to interface with other languages, like C, in which case you might
have libraries, but more on that later -- TA]</I></P>
<P>The Ada compiler that I recommend to you is called <B>GNAT</B>, which
stands for: <B>GNU</B> <B>NYU</B> (New York University) <B>A</B>da
<B>T</B>ranslator. It is free (GNU license :-), and there is a wealth of
information on it. It is based on the <B>gcc</B> compiler, which has had
the Ada syntax bundled in with it.</P>
<P>It is available from the following website, which then has a link to
the GNAT compiler:</P>
<A HREF="http://www.gnuada.org/alt.html"
TARGET="_blank">www.gnuada.org/alt.html</A>
<P>A word of caution here. I recommend that you download a pre-compiled
binary version of GNAT, and use the package <B>alien</B> if need be to
convert to .DEB .RPM .TGZ, etc. The reason I say this, is because you will
need an Ada version of <B>gcc</B> (often called <B>gnatcc</B>) to bootstrap
the compiler. If this is the first time you are installing GNAT then the
compilation from source code will not be possible.</P>
<P>That said, you can then go ahead and install the package once you have
downloaded it. You'll find that with the RPM version of GNAT, that there
should be one single RPM: &quot;GNAT-3.13p-7.rpm&quot; which will contain
everything you need to start programming in this wonderful language
:-).</P>
<H2>Ada IDE's</H2>
<P>Before we start our first program in Ada, I thought it would be good to
make you aware of some of the IDE's (<B>I</B>ntegrated <B>D</B>evelopment
<B>E</B>nvironment). These are programs which help you to program in the
specified language by offering features such as: </P>
<UL>
<LI>Syntax Highlightling</LI>
<LI>Compiler Support</LI>
<LI>Keyword Definitions</LI>
<LI>Pre-defined Templates</LI>
</UL>
<P>The two that I would recommend to you are:-</P>
<P><B>TIA</B> (TIny Ada) -- a console based IDE written in Ada and is built
around the use of GNAT</P>
<P><B>GRASP</B> -- an X11 IDE which supports among other languages,
Ada!</P>
<P>For all you EMACS fans, there is an extension called <B>Glade</B> which
is installed as part of the main GNAT distribution. This is an EMACS
extension which supports the GNAT compiler, syntax highlighting, etc. More
information on that can be found at <A
HREF="http://www.gnuada.org">gnuada</A> website</P>
<P>You do not have to use and IDE at all to be able to use GNAT.
I actually don't bother, and instead use <B>jed</B> if I am at the
console (although this does not yet support Ada syntax highlighting) and
<A
HREF="http://www.linuxgazette.com/issue79/adam.html#prognedit"
TARGET="_blank"><B>Nedit</B></A> if I am in X11. This <I>does</I> support
Ada syntax highlighting :-)</P>
<H2>The Features of Ada</H2>
<P>Ada95 has been greately enhanced over its predecesor Ada83. The biggest
improvement has been <B>object orientation</B>, which many people will
find useful. Some of the features that Ada has are:</P>
<UL>
<LI>Packages (Modules), related types, objects can all be defined</LI>
<LI>Packages and data types can be made generic</LI>
<LI>Data representation gives a means to support systems
programming</LI>
<LI>Object-orientated programming is supported</LI>
<LI>Errors can be caught and delt with explicitly</LI>
<LI>Tasks (multiple paralell threads) can be created and used. This
ability is inherent to Ada95 and is uncommon is most other
langugaes</LI>
<LI>Interfaces to other languages (such as: C, Fortran, COLBOL) can be
included in the language</LI>
<LI>Ada supports hard <B>types</B> of data, both for textual and
mathematical Input/Output. As a result, Ada is well suited to writing
and maintaining complex systems</LI>
</UL>
<P>In addition to the above, there are also:</P>
<UL>
<LI>Packages</LI>
<LI>Functions</LI>
<LI>Procedures</LI>
<LI>Task Units</LI>
<LI>Records</LI>
<LI>Arrays</LI>
</UL>
<P>And many more....</P>
<H2>Hello World!</H2>
<P>Now it's time to write our first ada program. In time-honoured
tradition, we are going to start by writing a <I>Hello World</I>
example. Open up a text editor, and type in the following:</P>
<TABLE BORDER="1">
<TBODY>
<TR COLSPAN="12">
<TD>
<PRE>
<FONT COLOR="red">with</FONT> text_io;
<FONT COLOR="red">use</FONT> text_io;
<FONT COLOR="red">procedure</FONT> hello_world <FONT COLOR="red">is </FONT>
<FONT COLOR="red">begin</FONT>
<FONT COLOR="red"> put</FONT>("Hello World!");
<FONT COLOR="red">end</FONT> hello_world;
</PRE>
</TD>
</TR>
</TBODY>
</TABLE>
<P>Easy, isn't it :-). Before we can run the program, we have to save it.
But it has to be with the correct suffix. GNU/Linux doesn't require any
suffix (file extension) as a rule, but it is <B>essential</B> when
programming in <B>Ada</B> and using the GNAT compiler. A list of valid
extensions are:</P>
<UL>
<LI>.ads - Ada package specification</LI>
<LI>.adb - Ada package body or program</LI>
</UL>
<P>When writing anything other than a package (which we won't be doing for
<I>some</I> time yet -- I can assure you) :-) you should append a
&quot;.adb&quot; extension to your filename. This is so that the compiler
knows that the file it is compiling is a program and not a package
specification!</P>
<P>So, save your file as <B>hello_world.adb</B>
<P>Now we are ready to start to compile / build the program. This has to
be done so that we can run it. You cannot run an Ada program until it has
been compiled and built.</P>
<P>Change to the directory that you have just saved the file, and issue
the command:</P>
<PRE>
gnatmake hello_world.adb
</PRE>
<P>This will compile -> link -> build your Ada code into a compiled
program.</P>
<P>Now if you type in:</P>
<PRE>
./hello_world
</PRE>
<P>the response:</P>
<PRE><B>hello world!</B></PRE>
<P>is output to the screen, and the program exits.</P>
<P>You should also have noticed that as you issued the command, the following
output was produced:</P>
<PRE>
gnatgcc -c hello_world.adb
gnatbind -x hello_world.ali
gnatlink hello_world.ali
</PRE>
<P>You could, if you wish, type each of the above commands in turn to both
<B>compile, bind and link</B> your program (respectively). Luckily
<B>gnatmake</B> provides a nice automation for this :-). If you now look
in your directory, along with the main program, you'll find that GNAT has
created other files too, namely:</P>
<UL>
<LI>hello_world.ali</LI>
<LI>hello_world.o</LI>
</UL>
<P><B>.ali</B> files are GNAT link files that contain information about
debugging and linking for the main program</P>
<P><B>.o</B> files are object files which can be used in conjunction with
the program-debugger: <B>gdb</B>.</P>
<P> In short, unless you plan to debug your program, you can delete these files.</P>
<H2>Explanation: Hello World</H2>
<P>In perl, you can issue a command such as: <B>print("Hello");</B> and
that can be the <B><I>only</I></B> line in your program (excluding the
she-bang line), and it will run.</P>
<P>Ada however, has to be told exactly which packages it is to use before
it can perform even the simplest of commands like echoing statements to
the VDU. A <B>package</B> is a collection of functions and procedures that
perform specific tasks. If you do not declare explicitly these at the
start of the program, GNAT, when it comes to compile your program, will
bomb out immediately.</P>
<P>Therefore, if we wish to read and write I/O (Input/Output) to a screen
terminal, this has to be stated. All I/O functions are found within the
package <B>text_io</B>, and the first two lines within our hello_world
example are crucial....</P>
<PRE>
<FONT COLOR="red">with</FONT> text_io;
<FONT COLOR="red">use</FONT> text_io;
</PRE>
<P>The <FONT COLOR="red">with</FONT> statement in Ada indicates that we
will be requiring the use of the named package, in this case
<B>text_io</B>. If more than one package is required then this can be
added, by separating each package name by a comma (,). When we have
finished, we must append a semi-colon (;) to the end of the line, similiar
to that of Perl. The <FONT COLOR="red">with</FONT> statement is a
mandatory command that must <B>ALWAYS</B> be present at the start of your
program in order for it to work.</P>
<P>The package <B>text_io</B>, as I have already stated allows I/O
functions / procedures. This involves printing messages to the screen,
allowing user input to be entered, etc. It is a package that is used in
virtually every program you will ever write in Ada.</P>
<P>The <FONT COLOR="red">use</FONT> statement MUST be used only after the <FONT
COLOR="red">with</FONT> statement has been made. It allows for unqualified
references to be made to procedures and functions from other packages.
Without the use of this statement, each procedure or function call must
have the name of the package that it belongs to, followed by a period
(full stop) preceeding it. For example, below is what the
<B>hello_world</B> program would look like <B>without</B> the <FONT
COLOR="red">use</FONT> statement.</P>
<TABLE BORDER="1">
<TBODY>
<TR COLSPAN="12">
<TD>
<PRE>
<FONT COLOR="red">with</FONT> text_io;
<FONT COLOR="red">procedure</FONT> hello_world <FONT COLOR="red">is </FONT>
<FONT COLOR="red">begin</FONT>
<FONT COLOR="red"> text_io.put</FONT>("Hello World!");
<FONT COLOR="red">end</FONT> hello_world;
</PRE>
</TD>
</TR>
</TBODY>
</TABLE>
<P>You can see how this has increased the amount of information that we
have to type in, without the use of the <FONT COLOR="red">use</FONT>
statement. When more than one package is used that might have the same
procedure or function names, the compiler can usually tell to which
package you are referring, based on the parameters passed to it.</P>
<P>The third line:</P>
<PRE>
<FONT COLOR="red">procedure</FONT> hello_world <FONT COLOR="red">is </FONT>
</PRE>
<P>declares that we are writing a new procedure with the name
<B>hello_world</B>. The statement word <FONT COLOR="red">is</FONT> tells
us that we are about to start the declarative section of the procedure,
more on that later.</P>
<P>The keyword <BR><BR>
<FONT COLOR="red">begin</FONT><BR><BR> then tells us that we are going to
start the executable part of the procedure -- i.e. where all the
statements will appear and be executed, which in this case is:</P>
<PRE>
<FONT COLOR="red">put</FONT>("Hello World!")</FONT>
</PRE>
<P>Which calls the procedure <FONT COLOR="red">put</FONT> from the package
<B>text_io</B> to print the message <B>Hello World!</B> on the screen.</P>
<P>The last line:</P>
<PRE>
<FONT COLOR="red">end</FONT> hello_world;
</PRE>
<P>simply just ends the named procedure.</P>
<P>In short, the basic structure for an Ada program looks like the
following:</P>
<TABLE BORDER="1">
<TBODY>
<TR COLSPAN="12">
<TD>
<PRE>
<FONT COLOR="red">with</FONT> text_io;
<FONT COLOR="red">use</FONT> text_io;
<FONT COLOR="red">procedure</FONT> program_name <FONT COLOR="red">is </FONT>
[ declaritive part here ]
<FONT COLOR="red">begin</FONT>
[ executable section here ]
<FONT COLOR="red">end</FONT> program_name;
</PRE>
</TD>
</TR>
</TBODY>
</TABLE>
<P>Also within the package <B>text_io</B> are commands such as:</P>
<PRE><FONT COLOR="red">
put
put_line
get
get_line
new_line
</FONT></PRE>
<P>Plus many others...</P>
<P>
<FONT COLOR="red">put</FONT> does what we have already seen.<BR>
<FONT COLOR="red">put_line</FONT> does the same as <FONT
COLOR="red">put</FONT>, except starts on a new line.<BR>
<FONT COLOR="red">new_line</FONT> is a command issued on its own, which
starts a new line. If you use it, make sure that you put a semicolon at the
end of it, like:<BR><BR>
<FONT COLOR="red">new_line;</FONT><BR><BR>
In fact, that statement about the
semicolon (;) goes for each command that you make in Ada.
</P>
<P>Next month, we will be looking at:</P>
<UL>
<LI>text_io (inputting data via the <FONT COLOR="red">get</FONT>
statement)</LI>
<LI>data types</LI>
<LI>simple arithmetic expressions</LI>
<LI>enumeration types</LI>
</UL>
<H2>Exercises</H2>
<P>Well, that is all for this month. I'm sorry if it seems like I'm not
explaining enough things all in one go, but trying to explain anything
more at this point, is I think overload. So, I am going to leave you with
a few exercises for you to try.....</P>
<P>1. Print your name on the screen</P>
<P>2. Print your address on the screen, using only <FONT
COLOR="red">put</FONT> and <FONT COLOR="red">new_line</FONT></P>
<P>3. Repeat exercise 2, this time with <FONT COLOR="red">put_line</FONT>
<P>If you submit them to me, I will print them in my next installment of
this article!</P>
<P>As with all of my articles, if you have any questions, suggestions,
rants or raves (hopefully not complaints :-) drop me a line!!</P>
<HR WIDTH=25%>
<PRE>
with text_io, ada.integer_text_io;
use text_io, ada.integer_text_io;
procedure happy_programming is
loop_number : integer :=0;
begin
while loop_number /= 10 loop
loop_number := loop_number + 1;
put("Happy Programming in Ada");
new_line;
end loop;
end happy_programming;
</PRE>
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Thomas Adam</H4>
<EM>My name is Thomas Adam. I am 18, and am currently studying for A-Levels
(=university entrance exam). I live
on a small farm, in the county of Dorset in England. I am a massive Linux
enthusiast, and help with linux proxy issues while I am at school. I have been
using Linux now for about six years. When not using Linux, I play the piano,
and enjoy walking and cycling.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright &copy; 2002, Thomas Adam.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Office Linux: Ideas for a Desktop Distribution</font></H1>
<H4>By <a href="mailto:marndt@asmsoftware.de">Matthias Arndt</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<h3>Introduction</h3>
<p>
I remember one of the meetings of my LUG a few weeks ago. We argued about Linux and
its readiness for the desktop.
We all had the same opinion that Linux is ready for the desktop, at least where software
is concerned. We discussed other related things but this is the thing that made me think about distributions.
<p>
In this article I want to propose to create a special desktop distribution for end users
especially those who sit and work in an office all day long like secretaries.
<h3>Why another distribution of GNU/Linux?</h3>
<p>
To summarize my thoughts:
<ul>
<li>Most current Linux distributions like <a href="http://www.suse.com/">SuSE</a>,
<a href="http://www.debian.org/">Debian</a> or <a href="http://www.redhat.com/">Red Hat</a> come
with huge amounts of available software. This has many advantages but many new users are confused
with this. They ask: <em>I want to do .... . I installed lots of software from CD but which one
should I use?</em> So why not only install one package that fits well for the required work?
<li>A distribution for offices and end user use should be easy to install and easy to administrate.
The people shall work with the computer not fix bugs and tweak configurations.
<li>A distribution consisting of a few but proven components might be much easier to promote its use.
</ul>
<h3>Office Linux Manifest</h3>
<p>
<em>Office Linux</em> should not be one of the bloated 6 CDs full of programs distributions but
a simple distribution that fits on one CD and that brings all needed applications and tools to
create a productivity environment using GNU/Linux.
<p>
<em>Office Linux</em> should
<ul>
<li>run on standard PC hardware as found in offices
<li>be easy to use
<li>be easy to install
<li>consist only of selected applications and environments
<li>fit on one CD
<li>be easy to upgrade
<li>be designed for a workstation setup - not a single server application should be included
<li>bring along optional development packages to allow users to compile software
<li>have a nice and comfortable standard look'n'feel compatible to M$ Windows &trade; so
that the intended end user audience feels at home
<li>come with all applications and tools needed for office work such as word processors, spreadsheets
file viewers and printing utilities
<li>be easy to network to Linux and M$ servers
<li>be easy to administrate from remote locations
<li>bring standard compliant Internet software such as <a href="http://www.mozilla.org/">Mozilla</a>
<li>allow network install for disk-less workstations
</ul>
<p>
<em>Office Linux</em> could consist only of free software but this is not a requirement.
<h3>The bare system</h3>
<p>
<em>Office Linux</em> should only come with a proven and stable version of the
<a href="http://www.kernel.org/">Linux kernel</a>. The kernel should be compiled to run on standard
hardware out of the box supporting typically office hardware as networking and printing.
Multimedia support would be nice but not required.
<p>
The standard set of <a href="http://www.gnu.org/">GNU tools</a> like Bash, sed, awk and find should
come with <em>Office Linux</em>. However <em>Office Linux</em> should not present the user or admin with
a huge list of tools to be installed. Installing a standard subset should be enough.
<p>
As <em>Office Linux</em> puts emphasize on secretaries and other office personnel it should not come
with much applications for the console. One or two proven editors should be enough.
<h3>Desktop environment</h3>
<p>
<em>Office Linux</em> should be easy to use. Therefor a proven stable and possibly fast desktop environment
is required. <a href="http://www.kde.org/">The K Desktop Environment</a> could fit to meet this. However it
is not the fastest possible solution.
<p>
<table width="100%">
<tr><td>Pro KDE</td><td>Contra KDE</td></tr>
<tr valign="top">
<td>
<!-- Pro KDE -->
<ul>
<li>easy to use
<li>known and well supported in the GNU/Linux community
<li>can be configured to feel like M$ Windows &trade;
<li>Desktop environment with file manager and panel
<li>easy to configure by the end user
<li>comes fully internationalized
</ul>
</td>
<td>
<!-- Contra KDE -->
<ul>
<li>needs a considerable time to launch
<li>huge memory footprint both in RAM and on hard-disk
</ul>
</td>
</tr>
</table>
<p>
Personally I do not like KDE that much but I recommend it for <em>Office Linux</em>.
<h3>Office productivity</h3>
<p>
This is a very important field and <em>Office Linux</em> should concentrate on this
field as its name suggests.
A reliable and commonly accepted office suite like Star Office or OpenOffice should
come with it.
<p>
Compatibility with M$ Office &trade; is required to allow the intended user audience to import and reuse
their old files. This compatibility should be achieved through the office suite and not through
external tools. Not only to provide GUI but to make it more easy to use.
A worst case scenario may invoke a GUI shell for command line tools.
<p>
I do not recommend KOffice for <em>Office Linux</em> just because it will find more
resistance from the intended audience than suites that resemble M$ Office &trade;.
<p>
The distribution should provide reliable PDF readers and converters. Perhaps an installable PDF
printer for <em>Office Linux</em> would be a nice idea. Users could print PDFs from any application
then.
<p>
The printing subsystem should be able to communicate with existing network printers of any kind
including SAMBA printers and standard Unix printers.
The subsystem should be easy to install and use. It should be compatible with Unix convention in resembling
the BSD printing system. CUPS would be a fine solution and I suggest using it in <em>Office Linux</em>
<h3>Internet</h3>
<p>
A standard compliant Internet suite is another main part of <em>Office Linux</em>.
<p>
Although there a many fine programs out there <em>Office Linux</em> should only provide on of them
in a preconfigured and working way. A stable <a href="http://www.mozilla.org/">Mozilla</a> release
in a complete install with all needed plugins such as Macromedia Flash and a Java VM.
<p>
A security tweaked default configuration should be included.
<h3>Help System</h3>
<p>
To be easy to use <em>Office Linux</em> has to include a help system that is easy to use and navigate.
<p>
The help system should provide
<ul>
<li>a general tutorial for new users
<li>tutorial / help system for the desktop environment
<li>access to software documentation
<li>a wizard for application selection depending upon the task the user wants to accomplish
<li>general introductions to Unix concepts
<li>HOWTOs on Internet security
<li>wizards to install default configurations for main applications like the office suite or the
Internet software
</ul>
<p>
Markup in HTML is recommended for the Help System.
<h3>Conclusion</h3>
<p>
I think the creation of a distribution upon these ideas is entirely possible. It will require some work
and patience but it shouldn't be impossible.
<p>
A distribution providing only a few but proven components might be as easy to use as M$ Windows &trade;.
And then GNU/Linux might be ready for the desktop. It is a matter of time, hard work and patience but it
is possible.
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Matthias Arndt</H4>
<EM>I'm a Linux enthusiast from northern Germany.
I like plain old fifties rock'n'roll music, writing
stories and publishing in the Linux Gazette, of course.
Currently I'm studying computer science in conjunction with
economics.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright &copy; 2002, Matthias Arndt.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Playing DVDs on Linux</font></H1>
<H4>By <a href="mailto:oladokun@consultant.com">Tunji Durodola</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<BODY LANG="en-US" TEXT="#000000" LINK="#0000ff" VLINK="#0000ff">
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">Hello
dear readers.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">My
name is Tunji Durodola and I write from Nigeria, West Africa, the
largest collection of black peoples on the face of the planet.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">The
purpose of this article is to give an insight into how to get Linux
to play DVDs using one or more of the now readily available tools on
the web. You should have basic DVD playing in a matter of minutes;
are more detailed section will follow later. </FONT>
</P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Preamble.</B></FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">The
key to watching DVDs lies in the ability of hardware or software to
decode and read encrypted movies. DVDs are encrypted with a special
algorithm called Content Scrambling System or CSS, to prevent illegal
copying of the material contained on the disc. The algorithm is not a
secret, but to get a copy of it to put in your device (hardware or
software), you have to pay a license fee <STRONG>plus</STRONG> sign a mean set of
agreements to prevent you from disclosing the algorithm to anyone.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">Each
DVD has its own key, rather akin to each door having a separate key
to unlock it. The key itself in Windows is kept secret.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">All
commercial Windows DVD players have the algorithm contained in it,
but they have paid, and as such, charge for their software, or the
cost is embedded in the price of the DVD drive your purchase, so in
effect you are paying a fee for the &ldquo;bundled&rdquo; software
player.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">The
whole philosophy of Linux is <STRONG>freedom</STRONG>, which would be defeated if you
have to pay for a Linux DVD player. Some chaps tried to get the
algorithm from the owners, but were told they had to go through the
same process as the Windows people.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">For
those earthlings who haven't got a clue as to what DeCSS is, I'll
give a brief summary.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">A
young lad, a few years ago, desiring to watch <STRONG>his</STRONG>
legally purchased DVDs in Linux, thought to develop a player for
Linux, when none existed at the time, stumbled on a flaw in a now
defunct Windows&rsquo; player called Xing, which had the unfortunate
habit of leaving the key in the program itself. He then used his
knowledge of maths to reverse-engineer the code and generate the
algorithm.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">The
software he wrote to do that job was called DeCSS. He then teamed up
with a few friends collectively called Masters Of Reverse Engineering
(MORE) to develop a DVD ripper on Windows, and a small set of
Linux-based utilities to view the un-encrypted files.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">No
fee was charged, but was posted on the &lsquo;net for anyone with a
similar desire to view their DVDs in Linux. The MPAA found out and
subsequently obtained a court order forbidding any US site from
hosting DeCSS. That of course sparked worldwide interest in
Linux-based DVD players. The case is still in court in the Land of
the Free. For more info please click <A HREF="http://www.eff.org/">here.</A></FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">Today,
there are other software decryptors available for Linux which do not
use the original DeCSS code, but do the same job, and are not subject
to any litigation. We shall focus on these.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma"><B>The
Goods!</B></FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">Just
to get you warm, I'll tell you what system I've got in my crib.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm">&nbsp;</P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Hardware</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>CPU:
Pentium III 750 (old, I know, I'm planning for an Athlon XP 1900+)</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>RAM:
1GB PC 133 SDRAM (hey, ram was cheeeep when I bought)</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>BOARD:
MSI BX Master, 4 IDE Slots (2 on an on-board Promise Controller)</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>Case:
ATX Extended Tower with 9 5.25 Slots</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>Sound:
SoundBlaster Live! 5.1 Platinum (lovely card!)</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>VGA:
NVidia TNT2, 32MB SDRAM</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>HDD:
2x WD400 7200 RPM, 40GB drives, 2MB Cache (I'm showing off here)</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>Speakers:
<B>Front:</B> 80W Kenwood speakers, driven by a Technics 80W Power Amp
connected directly to the card</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT SIZE=2><FONT FACE="Garamond"><B>Rear:
</B>Some mid-budget 20W RMS computer speakers</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT SIZE=2><FONT FACE="Garamond"><B>Center:
</B>As Above</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT SIZE=2><FONT FACE="Garamond"><B>Sub:
</B>A no name 40W Sub in a wooden enclosure</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>Monitor:
18&quot; NEC TFT Flat Panel</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm">&nbsp;</P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Software</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT SIZE=2><FONT FACE="Garamond"><B>OS:</B>
SuSE Linux 8.0 Professional</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT SIZE=2><FONT FACE="Garamond"><B>Sound:</B>
<B>ALSA 0.9.0rc2,</B> running emu10k1 SoundBlaster driver. This is
the only audio driver for Linux capable of using the Surround
capabilities of the SB Live 5.1. Even the Windows drivers and
software don't have half the features of this driver. Linux driver
can handle up to 8 such cards on 1 system, whereas Windows can't
handle two (don't bother, I've tried it). Hats off to the ALSA team!</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT SIZE=2><FONT FACE="Garamond"><B>Video:</B>
</FONT></FONT>
</P>
<P STYLE="margin-left: 6.35cm; margin-bottom: 0cm">1.<FONT SIZE=1><FONT FACE="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;
</FONT></FONT><FONT SIZE=2><FONT FACE="Garamond"><B>Xine 0.9.12
</B>(Complete with its plugin capabilities makes Xine hard to beat)</FONT></FONT></P>
<P STYLE="margin-left: 6.35cm; margin-bottom: 0cm">2.<FONT SIZE=1><FONT FACE="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;
</FONT></FONT><FONT SIZE=2><FONT FACE="Garamond"><B>Ogle 0.8.2 </B>(Fast
and quick DVD-only player that supports DVD menus)</FONT></FONT></P>
<P STYLE="margin-left: 6.35cm; margin-bottom: 0cm">3.<FONT SIZE=1><FONT FACE="Times New Roman">&nbsp;&nbsp;&nbsp;&nbsp;
</FONT></FONT><FONT SIZE=2><FONT FACE="Garamond"><B>Mplayer 0.90</B>
(Mainly Console-based player with an unusual assortment of options.
Mplayer will play almost any type of file format available today
including VOB, VIVO, ASF/WMV, QT/MOV, Xanim, AVI, DiVX, VCD, SVCD,
and of course DVDs It has a GUI option with skins.)</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><FONT SIZE=2>Both
Xine and the Mplayer now offer FULL multi-channel (5.1) surround
audio.</FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><BR>
</P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>To compile
mplayer:</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">Requirements</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">libdvdread 0.8 <B>and</B>
libcss (<U>not</U> libdvdcss)</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>or</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><A HREF="http://www.dtek.chalmers.se/groups/dvd/downloads.shtml">libdvdread
0.9</A> <B>and</B> <A HREF="http://www.videolan.org/">libdvdcss 0.0.3</A>
(not libcss NOR libdvdcss 1.0)</P>
<P STYLE="margin-bottom: 0cm">all may be obtained at
<A HREF="http://www.dtek.chalmers.se/groups/dvd">www.dtek.chalmers.se/groups/dvd</A></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">The libdvdcss is
used to decrypt the DVD and libdvdread to read its contents, and for
chapter support.</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">I recommend you use
<B>ALSA 0.9.0rc2</B>, for audio, if you have a modern sound card, such
as the SoundBlaster Live! 5.1 series. The Audigy range may work, but
alas, I don't have one :-(</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Garamond"><I>Please read
the </I>INSTALL<I> and </I>README<I> files in all packages</I></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Step 1</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">libdvdcss</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">./configure</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">compile install it
with &quot;make &amp;&amp; make install &amp;&amp; ldconfig&quot;</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Step 2</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">libdvdread</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">compile and install
as above</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Step 3</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">mplayer 0.90</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">./configure &ndash;help</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">make &amp;&amp;
make install</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">It should then
install itself in /usr/local/bin as mplayer</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Step 4</B></FONT></P>
<P STYLE="margin-bottom: 0cm">(a) if /dev/hdc is your dvd drive,
make a link <I><FONT FACE="Garamond">ln -s /dev/hdc /dev/dvd</FONT></I></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">(only needs to be
done once)</FONT></P>
<P STYLE="margin-bottom: 0cm">type<I><FONT FACE="Garamond"> mplayer
-dvd 1 -ao oss</FONT></I></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">The
software should give some info such as the encryption key for the
DVD, and then start to play the &quot;encrypted&quot; movie.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm">There are a
gazillion options available, too numerous to dig into here, but
multichannel audio is possible with <I><FONT FACE="Garamond">-channels
x</FONT></I>, where x is 2,4 or 6 speakers. Remember, it is pointless
if you have a basic 2-channel card. These multichannel cards are
affordable these days so spoil yourself and get one!
</P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">Other
useful options:</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><I><FONT FACE="Garamond">-title
x</FONT></I> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&ndash; select DVD title</P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><I><FONT FACE="Garamond">-chapter
y</FONT></I> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&ndash; select chapter in title specified above</P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><I><FONT FACE="Garamond">-ss
hh:mm:ss</FONT></I> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&ndash;jump to specific time point</P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><I><FONT FACE="Garamond">-vcd
x</FONT></I>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
- play vcd chapter</P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm">-channels 4
- play thru 4 discrete channels (front &amp; rear)</P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma">On-screen
display is also available, but not regular DVD subtitles.</FONT></P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm">Mplayer has rapidly
become the most widely downloaded Linux software by a far margin (see
<A HREF="http://freshmeat.net/stats/#popularity">http://freshmeat.net/stats/#popularity</A>
if you don&rsquo;t believe me), but it is not as easy to set up as
Xine, if you don&rsquo;t like compiling apps.0</P>
<P STYLE="margin-top: 0.3cm; margin-bottom: 0cm"><FONT FACE="Tahoma"><FONT SIZE=4 STYLE="font-size: 13pt"><B>To
get Xine up and running in 5 minutes flat.</B></FONT></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Step 1</B></FONT></P>
<P STYLE="margin-bottom: 0cm">download the latest xine releases from
<A HREF="http://xine.sourceforge.net/">xine.sourceforge.net</A></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">You will need the
following RPMs if you do not feel like compiling. x86 refers to your
type of Pentium processor; i686 for Pentium III or higher, i586 for
Pentium and AMD K6</FONT></P>
<UL>
<LI> xine-lib-0.9.12-x86.rpm
<LI> xine-lib-0.9.12-oss-x86.rpm
<LI> xine-lib-0.9.12-oggvorbis-x86.rpm
<LI> xine-lib-0.9.12-xv.rpm
<LI> xine-lib-0.9.12-x86.rpm
<LI> xine-ui-0.9.12-x86.rpm
<LI> xine-lib-dvdnav-0.9.10-x86.rpm
</UL>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><I>There are
others, but these are the bare essentials.</I></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Step 2</B></FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">Copy all the RPMs
into an empty folder and from there, logged in as root, run the
following:</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">rpm -Uvh xine*.rpm</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">If you are averse
to using the console, call up kpackage or gnorpm and install them in
the GUI instead.</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>Step 3</B></FONT></P>
<P STYLE="margin-bottom: 0cm">In GUI, open up a console (purely to
see the output from the player, once you are comfortable with the
settings, you won't need the console), and type the following (mind
the case sensitivity of each letter) <I><FONT FACE="Garamond">xine
-pq -A oss -V xv -u0 dvdnav://</FONT></I></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">It may look cryptic
but it is easy to explain. The purpose of the switches is to set
defaults for audio and video in the config file which is stored in </FONT>
</P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">&ldquo;.xine/config&rdquo;
in your home folder.</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">-pq play
immediately, and quit when done</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">-A oss use oss as
the audio driver</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">-V xv use xv as the
video driver</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">-u0 select the
first subtitle (usually English, u1 refers to French, etc.)</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">dvdnav:// is the
optional plugin that actually plays the DVD. It also has menu
functionality and allows you to jump from chapter to chapter with 9/3
on the numeric keypad.</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">Type &quot;xine
--help&quot; or man xine for full details.</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">As stated earlier,
the skin may be changed in the menu. All settings are also possible
in the menu including multichannel audio.</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">Xine plays a whole
range of media: DVDs, VCDs, CDs, ogg, mp3, wav, DiVX... on and on and
on.</FONT></P>
<P STYLE="margin-bottom: 0cm">&nbsp;</P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma"><B>URLs</B></FONT></P>
<P STYLE="margin-bottom: 0cm">xine: <A HREF="http://xine.sourceforge.net/">xine.sourceforge.net</A></P>
<P STYLE="margin-bottom: 0cm">ogle: <A HREF="http://www.dtek.chalmers.se/groups/dvd">www.dtek.chalmers.se/groups/dvd</A></P>
<P STYLE="margin-bottom: 0cm">mplayer: <A HREF="http://www.mplayerhq.hu/homepage">www.mplayerhq.hu/homepage</A></P>
<P STYLE="margin-bottom: 0cm">ALSA: <A HREF="http://www.alsa-project.org/">www.alsa-project.org</A></P>
<P STYLE="margin-bottom: 0cm">xinedvdnav plugin (to decrypt DVDs,
with DVD menus): <A HREF="http://dvd.sourceforge.net/d">http://dvd.sourceforge.net/</A></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">I hope to keep you
posted with a more detailed paper sometime soon, with tips and
tricks.</FONT></P>
<P STYLE="margin-bottom: 0cm"><FONT FACE="Tahoma">'Later.</FONT></P>
<P STYLE="margin-bottom: 0cm">&nbsp;</P>
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Tunji Durodola</H4>
<EM>Tunji is a Lagos-based computer consultant specialising in Linux solutions.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright &copy; 2002, Tunji Durodola.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Is Your Memory Not What It Used To Be?</font></H1>
<H4>By <a href="http://www.geocities.com/madhumkurup/mailme.html">Madhu M Kurup</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<h2>Intent</h2>
The intent of this article is to provide an understanding of memory
leak detection and profiling tools currently available. It also aims at
providing you with enough information to be able to make a choice between
the different tools for your needs.<br>
<h2>Leaks and Corruption</h2>
We are talking software here, not plumbing. And yes, any fairly large,
non trivial program is bound to have a problem with memory and or leaks.<br>
<h3>Where do problems occur?</h3>
First, leaks and such memory problems do not occur in some languages.
These languages believe that memory management is <i>so important</i> that
it should never be handled by the users of that language. It is better
handled by the <i>language designers</i>. Examples of such languages are
Perl, Java &nbsp;and so on.<br>
&nbsp;&nbsp;&nbsp; However, in some other languages (notably C and
C++) the language designers have felt that memory management is <i>so important</i>
that it can only be taken care of by the <i>users</i> of the language.
A leak is said to occur when you dynamically allocate memory and then forget
to return it. In addition to leaks, other memory problems such as <a
href="http://www.tuxedo.org/%7Eesr/jargon/html/entry/buffer-overflow.html">buffer
overflows</a>,&nbsp;<a
href="http://www.tuxedo.org/%7Eesr/jargon/html/entry/dangling-pointer.html">dangling
pointers</a> &nbsp;also occur when programmers manage memory themselves.
These problems are caused where there is a&nbsp; mismatch between what
the program (and by extension the programmer) believes the state of memory
is, as opposed to what it really is.<br>
<h3>What are the problems?</h3>
In order for programs to be able to deal with data whose size is
not known at compile time, the program may need to request memory from
the runtime environment (operating system). However, having obtained a
chunk of memory, it may be possible that the program does not return to
back to the environment after use. An even more severe condition results
when the address of the block that was obtained is lost, which means that
it is no longer possible to identify that allocated memory. &nbsp;Other
problems include trying to access memory after it has been returned (dangling
pointers). Another common problem is trying to access more memory that was
originally requested and so on (buffer overflow).<br>
<h3>Why should these problems bother me?</h3>
Leaks may not be a problem for short-lived programs that finish their
work quickly. Unfortunately, many programs are designed to function
without termination for a long period. A good example would be the Apache
webserver that is currently providing you this web page. In such a situation,
a malfunctioning leaky program could keep requesting memory from the system
and not return it. Eventually this would lead to the system running out
of memory and all programs running on that machine to suffer. This is obviously
not a &nbsp;good thing. In addition to a program requiring more memory,
leaks can also make a program sluggish. The speed at which the program
is context-switched in and out can decrease if the memory load increases.
While not as severe as causing the machine to crash, an excessive memory
load on a machine could cause it to thrash, swapping data back and forth.<br>
&nbsp;&nbsp;&nbsp; Dangling pointers can result in subtle corruption
and bugs that are extremely unusual, obscure and hard to solve. Buffer overflows
are probably the most dangerous of the three forms of memory problems.
They lead to most of the security exploits that you read about[<a
href="#Secure_Programming_">SEC</a>]. &nbsp;In addition to the problems
described above, it may be possible that the same memory chunk is returned
back to the system multiple times. This obviously indicates a programming
error. A programmer may wish to see how the memory requests are made by
a program over the course of the lifetime of the program in order to find
and fix bugs.<br>
<h3>Combating these problems</h3>
There are some run time mechanisms to combat memory problems. Leaks can
be solved by periodically stopping and restarting the offending program
<cite></cite> [<a href="#OOM_killer">OOM</a>]. Dangling pointers can be
made repeatable by zeroing out all memory returned back to the operating
systems. Buffer overflows have a variety of solutions, some of which are
described in more detail <a
href="http://www.geocities.com/madhumkurup/papers/Buffer.ps">here</a>. <br>
&nbsp;&nbsp;&nbsp; Typically, the overhead of combating these problems at
runtime or late in development cycle is so high that finding them and
fixing them at the program level is often the more optimal solution.<br>
<h2>Open Source </h2>
<h3>GCC-based alternatives</h3>
The <a
href="http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/boehm-gc/">gcc</a> toolset
now includes a garbage collector which facilitates the easy detection
and elimination of many memory problems. Note that while this can be used
to detect leaks, the primary reason for creating this was to implement
a good garbage collector[<a href="#Garbage_Collectors">GC</a>]. This work
is currently being led by Hans-J. Boehm at HP.&nbsp;
<h4>Technology</h4>
The technology used here is <a
href="http://www.hpl.hp.com/personal/Hans_Boehm/gc/gcdescr.html">Boehm-Demers-Weiser</a>
technique for keeping track of allocated memory. Allocation of memory
is done using the algorithm's version of the standard memory allocation
functions. The program is then compiled with these functions and when executed,
the algorithm can analyze the behavior of the program. This algorithm is
fairly well known and well understood. It should not cause any problems
and/or interfere with programs. It can be made thread safe and can even
scale onto a multiprocessor system.<br>
<h4>Performance</h4>
Good performance with reduction in speed in line with expectations.
The code is extremely portable and is also available directly with gcc.
The version shipped with gcc is slightly older, but can be upgraded.<br>
&nbsp;&nbsp;&nbsp; There is no interface - it is difficult to use
and requires much effort for it to be useful. Existing systems may not
have this compiler configuration and may require some additional work to
get it going. In addition, in order for the calls to be trapped, all memory
calls (such as <i>malloc()</i> and <i>free()</i> ) have to be replaced with
equivalents provided by the garbage collector. One could use a macro, but
that is still not very flexible.&nbsp; Also this approach implicitly requires
source code for all pieces that require memory profiling with the ability
to shift from the real functions to those provided.<br>
<h4>Verdict</h4>
If you need a solution across multiple platforms (architectures,
operating systems) where you have control over all relevant source, this
could be it.<br>
<h3>Memprof</h3>
<a href="http://people.redhat.com/otaylor/memprof/">Memprof</a> is
an attractive easy to use package, created by Owen Talyor of Red Hat. This
tool is a nice clean GNOME front-end to the Boehm-Demers-Weiser garbage
collector.<br>
<h4>Technology</h4>
At the heart of the profiling, memprof is no different from the toolset
described above. However, how it implements this functionality is to trap
all memory requests from the program and redirect it at runtime to the
garbage collector. While not as functional as the gcc alternative on threads
and multiprocessors, the program can be asked to follow forks as they happen.<br>
<h4>Performance</h4>
The performance of this tool is pretty good. The GUI was well designed,
responsive and informative. This tools works directly with executables,
and it works without any changes needed to the source. This tool also graphically
displays the memory profile as the program executes which helps in understanding
memory requirements of the program during its lifetime.<br>
&nbsp;&nbsp;&nbsp; This tool is currently available only for the x86
and PPC architecture on Linux. If you need help on other platforms, you
will need to look elsewhere. This tool is not a GTK application, it needs
the full-blown GNOME environment. This may not be feasible everywhere.
Finally, development on this tool appears to be static (version 0.4.1.
for a while). While it is possible that it does what it is required to do
well, it does not seem that this too will do anything more than just leak
detection.<br>
<h4>Verdict</h4>
If you like GUI tools and don't mind GNOME and Linux, this is a
tool for you.<br>
<h3>Valgrind</h3>
<a href="http://developer.kde.org/%7Esewardj/">Valgrind</a> is a
program that attempts to solve a whole slew of memory problems, leaks
being just one of them. This tool is the product of Julian Seward (of
<a href="http://sources.redhat.com/bzip2/index.html">bzip2</a> and <a
href="http://www.cacheprof.org">cacheprof</a> fame). It terms itself "an open source
memory debugger for x86 linux" and it certainly fits that bill. In addition,
it can profile the usage of the CPU cache, something that is fairly unusual.
<h4>Technology</h4>
The technology used in this program is fairly complex and <a
href="http://developer.kde.org/%7Esewardj/docs/techdocs.html">well documented</a>.
Each byte of memory allocated by the program is tracked by nine status
bits, which are then used for housekeeping purposes to identify what is
going on. At the cost of tremendously increasing the memory load of an
executing program, this tool enables a much greater set of checks. As all
the reads and writes are intercepted, cache profiling of the CPU's various
L caches can also be done.<br>
<h4>Performance</h4>
The tool was the slowest of the three detailed here, for obvious
reasons. However, for the reduction in speed, this tool provides a wealth
of information is probably the most detailed of the three. In addition
to the usual suspects, this tool can identify a variety of other memory
and even some POSIX pthread issues. Cache information is probably overkill
for most applications, but it is an interesting way to look at the performance
of an application. The biggest plus for Valgrind is that it is under rapid
development with a pro-active developer and an active community. In fact
the web page of Valgrind proclaims the following from the author - &nbsp;<i>"If
you have problems with Valgrind, don't suffer in silence. Mail me."</i>.<br>
&nbsp;&nbsp;&nbsp; The tool however, is very x86 specific. Portability
is fairly limited and to x86 Linux. The interface is purely command-line
driven and while usable, sometimes the tool gives you too much information
for it to be useful. This tool also directly works with binaries, so while
recompiles are not required, it will require diligence to go through the
output of this tool to find what you are looking for. You can suppress memory
profiling for various system libraries by creating suppression files, but
writing these files is not easy. In addition, threading support is not complete,
although this tool has been used on Mozilla, OpenOffice and such other
large threaded programs. If this tool had a GUI front end, it would
win hands down.<br>
<h4>Verdict</h4>
If you are on x86 and know your code well and do not mind a CLI interface,
this program will take you another level.<br>
<h3>Other Open Source tools</h3>
Before I get sent to the stake for not having mentioned your favorite
memory tool, I must confess that few compare in completeness to these three
in terms of the data that they provide. A more&nbsp; comprehensive list
of leak detection tools is available&nbsp;<a
href="http://www.sslug.dk/emailarkiv/bog/2001_08/msg00030.html">here</a>.
<br>
<h2>Commercial</h2>
These tools are mentioned here only for completeness.
<h3>Purify</h3>
The <a href="http://www.rational.com/products/pqc/pplus_ux.jsp">big
daddy</a> of memory tools, does <i>not work</i> on Linux, so you can stop
asking that question.
<h3>Geodesic</h3>
A latecomer to this arena, <a
href="http://www.geodesic.com/solutions/solutions_linux.html">Geodesic</a>
is known most in the Linux community for their <a
href="http://www.geodesic.com/solutions/products_gc_demo.html">Mozilla</a>
demo, in which they use their tools to help find memory problems in the
Mozilla codebase. How much use this has been to the Mozilla team is yet
to be quantified, but their open-source friendliness can't hurt. Works
for Solaris/Linux with a fully functional trial. Works on Windows as well.<br>
<h3>Insure++</h3>
A C++ specific tool, but still fairly well known, Parasoft's <a
href="http://www.parasoft.com/jsp/products/home.jsp?product=Insure">Insure++</a>
is a fairly complete memory profiling / leak detection tool. In addition,
it can find some C++ specific errors as well, so that can't hurt. This tool
works with a variety of compilers and operating systems, a free trial version
is available too.
<h2>Miscellaneous Notes:</h2>
<h3><a name="Secure_Programming_"></a>Secure Programming </h3>
Secure programming involves many components, but probably the most significant
is the careful use of memory. More details are available&nbsp;<a
href="http://www.theorygroup.com/Theory/FAQ/Secure-Programs-HOWTO-1.html">here</a>.<br>
<h3><a name="OOM_killer"></a>OOM killer</h3>
Some the newer Linux kernels employ an algorithm which is known as the
Out Of Memory (OOM) killer. This code is invoked when the kernel completely
runs out of memory, at which point active programs / processes are chosen
to be executed (as in killed, end_of_the_road, happy hunting grounds, etc).
More details are available&nbsp;<a
href="http://linux-mm.org/docs/oom-killer.shtml">here</a>.<br>
<h3><a name="Garbage_Collectors"></a>Garbage Collectors </h3>
One of the other reasons why garbage collection is not always a preferred
solution is that it is really tough to implement. They have severe problems
with self-referential structures (i.e. structures that link to themselves)
as aptly described <a
href="http://www.tuxedo.org/%7Eesr/jargon/html/Some-AI-Koans.html">here</a>.<br>
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Madhu Kurup</H4>
<EM>I'm a CS engineer from Bangalore, India and formerly of the
<a href="http://www.linux-bangalore.org">ILUG Bangalore</a>. I've
been working and playing with Linux for a while and while programming is
my first love, Linux comes a close second. I work at the Data Mining group
at <a href="http://www.yahoo.com">Yahoo!</a> Inc and work on algorithms,
scalability and APIs there. I moonlight on the Linux messenger client and
dabble in various software projects when (if ever) I can find any free time.
<P> And yes, if you want to know, I use C++, vi, mutt, Windowmaker
and Mandrake; let the flame wars begin :) </EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright &copy; 2002, Madhu M Kurup.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Exploring Perl Modules - Part 1: On-The-Fly Graphics with GD</font></H1>
<H4>By <a href="mailto:p_padala@yahoo.com">Pradeep Padala</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<h3 name="intro"> Welcome To "Exploring Perl Modules" !!!</h3>
<p>
Perl modules are considered to be one of the strongest points for perl's
success. They contain a lot of re-usable code and of course are free.
This is an attempt to trap the treasure trove. There are lot
of tutorials and even books written on popular modules like CGI, DBI etc..
For less popular modules, users are left with documentation which is cryptic
and sometimes incomplete.
<p>
I am starting a series of articles that will attempt to explain some of the less popular but
useful modules.
During the last year, I came across and programmed with
numerous perl modules. I will explain the modules with numerous
useful examples from my experience. We will take one module at a time
and explore its various uses.
<h3 name="whoread"> Who should be reading these</h3>
<p>
Well, you should know perl. We won't be delving much into the basics of perl.
There are plenty of documentation, articles and books on perl.
<a href=http://www.oreilly.com/catalog/lperl3/>Learning Perl</a> is
often recommended for beginners. Once you gain experience, you can try
<a href=http://www.oreilly.com/catalog/pperl3/>Programming Perl</a>.
<p>
If you are an average perl programmer and haven't used lot of modules, this
is the right place. Modules provide a great way to re-use code and write
efficient and compact applications. In each article we will graduate from
simple examples to complex examples ending in a real-world application,
if appropriate.
<h3 name="intromodules"> Introduction to Modules </h3>
Modules provide an effective mechanism to import code and use it. The
following line imports a module and makes its functions accessible.
<pre>
use module;
</pre>
For example if you want to use GD, you would write
<pre>
use GD;
</pre>
<h3> Finding and Installing Modules </h3>
<p>
Before we plunge into the details of programming, here are some instructions
for finding and installing modules. We will be using various modules, and most
of them are not installed by default. Some modules require libraries which
may or may not have been installed. I will mention the things
required whenever appropriate. Here are generic instructions for downloading
and installing modules.
<p>
An easy way to install the module is by using the CPAN module. Run CPAN in
interactive mode as
<pre>
perl -MCPAN -e shell
</pre>
<p>
Then you can do various tasks like downloading, decompressing and installing
modules. For example, for installing GD you can use
<pre>
install GD
</pre>
<p>
If you are like me and and are accustomed to configure, make, make install method,
here are the steps to install a module.
<ul>
<li> Find the module in CPAN's
<a href=http://www.cpan.org/modules/00modlist.long.html>list</a> of all modules.
<li> Download the latest version of the module. For example, the latest GD
module can be downloaded from
<a href=http://www.cpan.org/authors/id/LDS/GD-1.40.tar.gz>http://www.cpan.org/authors/id/LDS/GD-1.40.tar.gz</a>
<li> Unzip the module
<pre>
tar zxvf GD-1.40.tar.gz
</pre>
<li> Build the module
<pre>
perl Makefile.PL
(or)
perl Makefile.PL PREFIX=/my/perl/directory
(if you want to install in /my/perl/directory)
make
make test (optional)
</pre>
<li> Install the module
<pre>
make install
</pre>
</ul>
<h3> Ready to Go ... </h3>
<p>
So you have installed your favourite module and are raring to learn. In this article we
will explore the perl GD module, which provides an interface to <a href="http://www.boutell.com/gd/">GD library</a>. We will also be using the CGI module
for the web interface. You don't need to know a great deal of CGI to understand
this article. I will explain things where necessary.
<h3> Graphics with GD </h3>
<p>
Let's start the wheels with a simple and effective example
<pre>
Text version of the file can be found <a href=misc/padala/simple.pl.txt>here</a>.
<font color="#a020f0">#!/usr/local/bin/perl -w</font>
<font color="#0000ff"># Change above line to path to your perl binary</font>
<font color="#a52a2a"><b>use </b></font>GD;
<font color="#0000ff"># Create a new image</font>
<font color="#008b8b">$im</font> = <font color="#a52a2a"><b>new</b></font> GD::Image(<font color="#ff00ff">100</font>,<font color="#ff00ff">100</font>);
<font color="#0000ff"># Allocate some colors</font>
<font color="#008b8b">$white</font> = <font color="#008b8b">$im</font>-&gt;colorAllocate(<font color="#ff00ff">255</font>,<font color="#ff00ff">255</font>,<font color="#ff00ff">255</font>);
<font color="#008b8b">$black</font> = <font color="#008b8b">$im</font>-&gt;colorAllocate(<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>);
<font color="#008b8b">$red</font> = <font color="#008b8b">$im</font>-&gt;colorAllocate(<font color="#ff00ff">255</font>,<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>);
<font color="#008b8b">$blue</font> = <font color="#008b8b">$im</font>-&gt;colorAllocate(<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>,<font color="#ff00ff">255</font>);
<font color="#0000ff"># Make the background transparent and interlaced</font>
<font color="#008b8b">$im</font>-&gt;transparent(<font color="#008b8b">$white</font>);
<font color="#008b8b">$im</font>-&gt;interlaced(<font color="#ff00ff">'</font><font color="#ff00ff">true</font><font color="#ff00ff">'</font>);
<font color="#0000ff"># Put a black frame around the picture</font>
<font color="#008b8b">$im</font>-&gt;rectangle(<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>,<font color="#ff00ff">99</font>,<font color="#ff00ff">99</font>,<font color="#008b8b">$black</font>);
<font color="#0000ff"># Draw a blue oval</font>
<font color="#008b8b">$im</font>-&gt;arc(<font color="#ff00ff">50</font>,<font color="#ff00ff">50</font>,<font color="#ff00ff">95</font>,<font color="#ff00ff">75</font>,<font color="#ff00ff">0</font>,<font color="#ff00ff">360</font>,<font color="#008b8b">$blue</font>);
<font color="#0000ff"># And fill it with red</font>
<font color="#008b8b">$im</font>-&gt;fill(<font color="#ff00ff">50</font>,<font color="#ff00ff">50</font>,<font color="#008b8b">$red</font>);
<font color="#0000ff"># Open a file for writing </font>
<font color="#a52a2a"><b>open</b></font>(<font color="#008b8b">PICTURE</font>, <font color="#ff00ff">&quot;</font><font color="#ff00ff">&gt;picture.png</font><font color="#ff00ff">&quot;</font>) <font color="#a52a2a"><b>or</b></font> <font color="#a52a2a"><b>die</b></font>(<font color="#ff00ff">&quot;</font><font color="#ff00ff">Cannot open file for writing</font><font color="#ff00ff">&quot;</font>);
<font color="#0000ff"># Make sure we are writing to a binary stream</font>
<font color="#a52a2a"><b>binmode</b></font> <font color="#008b8b">PICTURE</font>;
<font color="#0000ff"># Convert the image to PNG and print it to the file PICTURE</font>
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">PICTURE</font> <font color="#008b8b">$im</font>-&gt;png;
<font color="#a52a2a"><b>close</b></font> <font color="#008b8b">PICTURE</font>;
</pre>
<p>
This is the example given in the
<a href= http://stein.cshl.org/WWW/software/GD/>GD man page</a>
with little modifications. This produces a small rectangle
with a red oval with blue border. Let's dissect the program.
<p>
One of the first things you do with GD library, is create an image handle to
work with. The line
<pre>
$im = new GD::Image($width, $height)
</pre>
<p>
creates and image with the specified width and height. You can also create
an image from an existing image as well. It is useful for manipulating existing
images. We will see an example on this in the later part of the article.
<p>
Next we need to allocate some colors. As you can guess, the RGB intensities
need to be specified for initializing colors. Since we will be using lots of
colors, let's write a small function which will initialize a bunch of colors
for use.
<pre>
Text version of the file can be found <a href=misc/padala/init_colors.pl.txt>here</a>.
<font color="#0000ff"># Save this as init_colors.pl </font>
<font color="#0000ff"># Other scripts call this function</font>
</font>
<font color="#a52a2a"><b>sub</b></font><font color="#008b8b"> </font><font color="#008b8b">InitColors</font><font color="#008b8b"> </font>{
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$im</font>) = <font color="#008b8b">$_</font>[<font color="#ff00ff">0</font>];
<font color="#0000ff"># Allocate colors</font>
<font color="#008b8b">$white</font> = <font color="#008b8b">$im</font>-&gt;colorAllocate(<font color="#ff00ff">255</font>,<font color="#ff00ff">255</font>,<font color="#ff00ff">255</font>);
<font color="#008b8b">$black</font> = <font color="#008b8b">$im</font>-&gt;colorAllocate(<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>);
<font color="#008b8b">$red</font> = <font color="#008b8b">$im</font>-&gt;colorAllocate(<font color="#ff00ff">255</font>,<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>);
<font color="#008b8b">$blue</font> = <font color="#008b8b">$im</font>-&gt;colorAllocate(<font color="#ff00ff">0</font>,<font color="#ff00ff">0</font>,<font color="#ff00ff">255</font>);
<font color="#008b8b">$green</font> = <font color="#008b8b">$im</font>-&gt;colorAllocate(<font color="#ff00ff">0</font>, <font color="#ff00ff">255</font>, <font color="#ff00ff">0</font>);
<font color="#008b8b">$brown</font> = <font color="#008b8b">$im</font>-&gt;colorAllocate(<font color="#ff00ff">255</font>, <font color="#ff00ff">0x99</font>, <font color="#ff00ff">0</font>);
<font color="#008b8b">$violet</font> = <font color="#008b8b">$im</font>-&gt;colorAllocate(<font color="#ff00ff">255</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">255</font>);
<font color="#008b8b">$yellow</font> = <font color="#008b8b">$im</font>-&gt;colorAllocate(<font color="#ff00ff">255</font>, <font color="#ff00ff">255</font>, <font color="#ff00ff">0</font>);
}
</pre>
<p>
I often refer to this <a href=http://www.hypersolutions.org/pages/rgbhex.html>
page</a> for some nice rgb combinations.
<p>
The next few lines are straightforward and pretty much self-explanatory.
The last lines regarding the file creation require special mention.
Since we will be writing an image to a file, we need to put the file handle
in binary mode with
<pre>
binmode MYFILEHANDLE;
</pre>
<p> This actually is a no-op on most UNIX-like systems.
<p>
Then we write to the file with the usual print command. GD can print the image
in various formats. For example if you want to print a jpeg image instead of
png, all you need to do is
<pre>
print MYFILEHANDLE $im-&gt;jpeg;
</pre>
<h3> Simple Drawing </h3>
<p>
GD offers some simple drawing primitives which can be combined to generate complex
graphics. Examine the following script that gives a whirlwind tour of all the
simple primitives.
<pre>
Text version of the file can be found <a href=misc/padala/drawing.pl.txt>here</a>.
<font color="#a020f0">#!/usr/local/bin/perl</font>
<font color="#0000ff"># Change above line to path to your perl binary</font>
<font color="#a52a2a"><b>use </b></font>GD;
<font color="#a52a2a"><b>do</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">init_colors.pl</font><font color="#ff00ff">&quot;</font>;
<font color="#0000ff"># Create a new image</font>
<font color="#008b8b">$im</font> = <font color="#a52a2a"><b>new</b></font> GD::Image(<font color="#ff00ff">640</font>,<font color="#ff00ff">400</font>);
<font color="#0000ff"># Allocate some colors</font>
<font color="#008b8b">&amp;InitColors</font>(<font color="#008b8b">$im</font>);
<font color="#0000ff"># Make the background transparent and interlaced</font>
<font color="#008b8b">$im</font>-&gt;transparent(<font color="#008b8b">$white</font>);
<font color="#008b8b">$im</font>-&gt;interlaced(<font color="#ff00ff">'</font><font color="#ff00ff">true</font><font color="#ff00ff">'</font>);
<font color="#008b8b">$x1</font> = <font color="#ff00ff">10</font>;
<font color="#008b8b">$y1</font> = <font color="#ff00ff">10</font>;
<font color="#008b8b">$x2</font> = <font color="#ff00ff">200</font>;
<font color="#008b8b">$y2</font> = <font color="#ff00ff">200</font>;
<font color="#0000ff"># Draw a border</font>
<font color="#008b8b">$im</font>-&gt;rectangle(<font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">639</font>, <font color="#ff00ff">399</font>, <font color="#008b8b">$black</font>);
<font color="#0000ff"># A line</font>
<font color="#008b8b">$im</font>-&gt;line(<font color="#008b8b">$x1</font>,<font color="#008b8b">$y1</font>,<font color="#008b8b">$x2</font>,<font color="#008b8b">$y2</font>,<font color="#008b8b">$red</font>);
<font color="#0000ff"># A Dashed Line</font>
<font color="#008b8b">$im</font>-&gt;dashedLine(<font color="#008b8b">$x1</font> + <font color="#ff00ff">100</font>, <font color="#008b8b">$y1</font>, <font color="#008b8b">$x2</font>, <font color="#008b8b">$y2</font>, <font color="#008b8b">$blue</font>);
<font color="#0000ff"># Draw a rectangle</font>
<font color="#008b8b">$im</font>-&gt;rectangle(<font color="#008b8b">$x1</font> + <font color="#ff00ff">200</font>, <font color="#008b8b">$y1</font>, <font color="#008b8b">$x2</font> + <font color="#ff00ff">200</font>, <font color="#008b8b">$y2</font>, <font color="#008b8b">$green</font>);
<font color="#0000ff"># A filled rectangle</font>
<font color="#008b8b">$im</font>-&gt;filledRectangle(<font color="#008b8b">$x1</font> + <font color="#ff00ff">400</font>, <font color="#008b8b">$y1</font>, <font color="#008b8b">$x2</font> + <font color="#ff00ff">400</font>, <font color="#008b8b">$y2</font>, <font color="#008b8b">$brown</font>);
<font color="#0000ff"># A circle</font>
<font color="#008b8b">$im</font>-&gt;arc(<font color="#008b8b">$x1</font> + <font color="#ff00ff">100</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">200</font> + <font color="#ff00ff">100</font>, <font color="#ff00ff">50</font>, <font color="#ff00ff">50</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">360</font>, <font color="#008b8b">$violet</font>);
<font color="#0000ff"># A polygon</font>
<font color="#0000ff"># Make the polygon</font>
<font color="#008b8b">$poly</font> = <font color="#a52a2a"><b>new</b></font> GD::Polygon;
<font color="#008b8b">$poly</font>-&gt;addPt(<font color="#008b8b">$x1</font> + <font color="#ff00ff">200</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">200</font>);
<font color="#008b8b">$poly</font>-&gt;addPt(<font color="#008b8b">$x1</font> + <font color="#ff00ff">250</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">230</font>);
<font color="#008b8b">$poly</font>-&gt;addPt(<font color="#008b8b">$x1</font> + <font color="#ff00ff">300</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">310</font>);
<font color="#008b8b">$poly</font>-&gt;addPt(<font color="#008b8b">$x1</font> + <font color="#ff00ff">400</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">300</font>);
<font color="#0000ff"># Draw it</font>
<font color="#008b8b">$im</font>-&gt;polygon(<font color="#008b8b">$poly</font>, <font color="#008b8b">$yellow</font>);
<font color="#0000ff"># Open a file for writing </font>
<font color="#a52a2a"><b>open</b></font>(<font color="#008b8b">PICTURE</font>, <font color="#ff00ff">&quot;</font><font color="#ff00ff">&gt;picture.png</font><font color="#ff00ff">&quot;</font>) <font color="#a52a2a"><b>or</b></font> <font color="#a52a2a"><b>die</b></font>(<font color="#ff00ff">&quot;</font><font color="#ff00ff">Cannot open file for writing</font><font color="#ff00ff">&quot;</font>);
<font color="#0000ff"># Make sure we are writing to a binary stream</font>
<font color="#a52a2a"><b>binmode</b></font> <font color="#008b8b">PICTURE</font>;
<font color="#0000ff"># Convert the image to PNG and print it to the file PICTURE</font>
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">PICTURE</font> <font color="#008b8b">$im</font>-&gt;png;
<font color="#a52a2a"><b>close</b></font> <font color="#008b8b">PICTURE</font>;
</pre>
<p>
The output looks like
<a href="misc/padala/picture1.png">this</a>.
<p>
The above script is self-explanatory. The polygon needs a little bit
of explanation. In order to draw a polygon, you first have to make the polygon and then
draw it. Of course, a polygon must have at least three vertices.
<h3> Drawing Text </h3>
<p>
So what about text? You can draw text in some of the simple fonts
provided by GD or use a True Type font available on your system.
There are two simple functions available to draw text.
<pre>
# Draw the text
$im-&gt;string($font, $x, $y, $string, $color);
# Print text rotated 90 degrees
$im-&gt;stringUp($font, $x, $y, $string, $color);
</pre>
The following script shows various simple fonts provided by GD.
<pre>
Text version of the file can be found <a href=misc/padala/text.pl.txt>here</a>.
<font color="#a020f0">#!/usr/local/bin/perl</font>
<font color="#0000ff"># Change above line to path to your perl binary</font>
<font color="#a52a2a"><b>use </b></font>GD;
<font color="#a52a2a"><b>do</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">init_colors.pl</font><font color="#ff00ff">&quot;</font>;
<font color="#0000ff"># Create a new image</font>
<font color="#008b8b">$im</font> = <font color="#a52a2a"><b>new</b></font> GD::Image(<font color="#ff00ff">200</font>, <font color="#ff00ff">80</font>);
<font color="#0000ff"># Allocate some colors</font>
<font color="#008b8b">&amp;InitColors</font>(<font color="#008b8b">$im</font>);
<font color="#0000ff"># Make the background transparent and interlaced</font>
<font color="#008b8b">$im</font>-&gt;transparent(<font color="#008b8b">$white</font>);
<font color="#008b8b">$im</font>-&gt;interlaced(<font color="#ff00ff">'</font><font color="#ff00ff">true</font><font color="#ff00ff">'</font>);
<font color="#0000ff"># Create a Border around the image</font>
<font color="#008b8b">$im</font>-&gt;rectangle(<font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">199</font>, <font color="#ff00ff">79</font>, <font color="#008b8b">$black</font>);
<font color="#008b8b">$x1</font> = <font color="#ff00ff">2</font>;
<font color="#008b8b">$y1</font> = <font color="#ff00ff">2</font>;
<font color="#0000ff"># Draw text in small font</font>
<font color="#008b8b">$im</font>-&gt;string(gdSmallFont, <font color="#008b8b">$x1</font>, <font color="#008b8b">$y1</font>, <font color="#ff00ff">&quot;</font><font color="#ff00ff">Small font</font><font color="#ff00ff">&quot;</font>, <font color="#008b8b">$blue</font>);
<font color="#008b8b">$im</font>-&gt;string(gdMediumBoldFont, <font color="#008b8b">$x1</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">20</font>, <font color="#ff00ff">&quot;</font><font color="#ff00ff">Medium Bold Font</font><font color="#ff00ff">&quot;</font>, <font color="#008b8b">$green</font>);
<font color="#008b8b">$im</font>-&gt;string(gdLargeFont, <font color="#008b8b">$x1</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">40</font>, <font color="#ff00ff">&quot;</font><font color="#ff00ff">Large font</font><font color="#ff00ff">&quot;</font>, <font color="#008b8b">$red</font>);
<font color="#008b8b">$im</font>-&gt;string(gdGiantFont, <font color="#008b8b">$x1</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">60</font>, <font color="#ff00ff">&quot;</font><font color="#ff00ff">Giant font</font><font color="#ff00ff">&quot;</font>, <font color="#008b8b">$black</font>);
<font color="#0000ff"># Open a file for writing </font>
<font color="#a52a2a"><b>open</b></font>(<font color="#008b8b">PICTURE</font>, <font color="#ff00ff">&quot;</font><font color="#ff00ff">&gt;picture.png</font><font color="#ff00ff">&quot;</font>) <font color="#a52a2a"><b>or</b></font> <font color="#a52a2a"><b>die</b></font>(<font color="#ff00ff">&quot;</font><font color="#ff00ff">Cannot open file for writing</font><font color="#ff00ff">&quot;</font>);
<font color="#0000ff"># Make sure we are writing to a binary stream</font>
<font color="#a52a2a"><b>binmode</b></font> <font color="#008b8b">PICTURE</font>;
<font color="#0000ff"># Convert the image to PNG and print it to the file PICTURE</font>
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">PICTURE</font> <font color="#008b8b">$im</font>-&gt;png;
<font color="#a52a2a"><b>close</b></font> <font color="#008b8b">PICTURE</font>;
</pre>
<p>
The output picture looks like this.<br>
<img alt="Output image of above script" src=misc/padala/picture2.png width=200 height=80>
<p>
As you can see, these fonts are quite limited and not so attractive. The
following section shows the usage of True Type Fonts with GD
<h3> True Type Fonts </h3>
<p>
You can use the true type fonts available on your system to draw some nice
text. The function <code>stringFT</code> is used to draw in TTF font.
<pre>
# $fontname is an absolute or relative path to a TrueType font.
stringFT($fgcolor,$fgcolor,$fontname,$ptsize,$angle,$x,$y,$string);
</pre>
<p>
Here's an example showing the usage
<pre>
Text version of the file can be found <a href=misc/padala/ttf.pl.txt>here</a>.
<font color="#a020f0">#!/usr/local/bin/perl</font>
<font color="#0000ff"># Change above line to path to your perl binary</font>
<font color="#a52a2a"><b>use </b></font>GD;
<font color="#a52a2a"><b>do</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">init_colors.pl</font><font color="#ff00ff">&quot;</font>;
<font color="#0000ff"># Create a new image</font>
<font color="#008b8b">$im</font> = <font color="#a52a2a"><b>new</b></font> GD::Image(<font color="#ff00ff">270</font>, <font color="#ff00ff">80</font>);
<font color="#0000ff"># Allocate some colors</font>
<font color="#008b8b">&amp;InitColors</font>(<font color="#008b8b">$im</font>);
<font color="#0000ff"># Make the background transparent and interlaced</font>
<font color="#008b8b">$im</font>-&gt;transparent(<font color="#008b8b">$white</font>);
<font color="#008b8b">$im</font>-&gt;interlaced(<font color="#ff00ff">'</font><font color="#ff00ff">true</font><font color="#ff00ff">'</font>);
<font color="#008b8b">$im</font>-&gt;rectangle(<font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">269</font>, <font color="#ff00ff">79</font>, <font color="#008b8b">$black</font>);
<font color="#008b8b">$x1</font> = <font color="#ff00ff">10</font>;
<font color="#008b8b">$y1</font> = <font color="#ff00ff">20</font>;
<font color="#0000ff"># Draw text in a TTF font</font>
<font color="#008b8b">$font</font> = <font color="#ff00ff">&quot;</font><font color="#ff00ff">/usr/X11R6/lib/X11/fonts/TTF/luxisri.ttf</font><font color="#ff00ff">&quot;</font>;
<font color="#008b8b">$im</font>-&gt;stringFT(<font color="#008b8b">$red</font>, <font color="#008b8b">$font</font>, <font color="#ff00ff">15</font>, <font color="#ff00ff">0</font>, <font color="#008b8b">$x1</font>, <font color="#008b8b">$y1</font>, <font color="#ff00ff">&quot;</font><font color="#ff00ff">A TTF font</font><font color="#ff00ff">&quot;</font>);
<font color="#008b8b">$anotherfont</font> = <font color="#ff00ff">&quot;</font><font color="#ff00ff">/usr/share/fonts/default/TrueType/starbats.ttf</font><font color="#ff00ff">&quot;</font>;
<font color="#008b8b">$im</font>-&gt;stringFT(<font color="#008b8b">$blue</font>, <font color="#008b8b">$font</font>, <font color="#ff00ff">20</font>, <font color="#ff00ff">0</font>, <font color="#008b8b">$x1</font>, <font color="#008b8b">$y1</font> + <font color="#ff00ff">40</font>, <font color="#ff00ff">&quot;</font><font color="#ff00ff">Another one here !!!</font><font color="#ff00ff">&quot;</font>);
<font color="#0000ff"># Open a file for writing </font>
<font color="#a52a2a"><b>open</b></font>(<font color="#008b8b">PICTURE</font>, <font color="#ff00ff">&quot;</font><font color="#ff00ff">&gt;picture.png</font><font color="#ff00ff">&quot;</font>) <font color="#a52a2a"><b>or</b></font> <font color="#a52a2a"><b>die</b></font>(<font color="#ff00ff">&quot;</font><font color="#ff00ff">Cannot open file for writing</font><font color="#ff00ff">&quot;</font>);
<font color="#0000ff"># Make sure we are writing to a binary stream</font>
<font color="#a52a2a"><b>binmode</b></font> <font color="#008b8b">PICTURE</font>;
<font color="#0000ff"># Convert the image to PNG and print it to the file PICTURE</font>
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">PICTURE</font> <font color="#008b8b">$im</font>-&gt;png;
<font color="#a52a2a"><b>close</b></font> <font color="#008b8b">PICTURE</font>;
</pre>
<p>
The output looks like this.<br>
<img alt="Output image for above script" src=misc/padala/picture3.png width=270 height=80>
<h3> Let's go Online </h3>
<p>
Now that we have seen some basic uses of GD, let's turn our attention to
web graphics. So how do you output an image through CGI? Simple. Add the
following lines to the scripts instead of printing to a file.
<pre>
# To disable buffering of image content.
select(STDOUT);
$| = 1;
undef $/;
print "Content-type: image/jpeg\n\n";
print $im-&gt;jpeg(100);
</pre>
<p>
This is all you need to know about CGI for now. If you already know CGI,
you can enhance your code for handling complex web interaction. Let's write a small program which
reads an image and displays a resized version of it. It might be useful
for showing thumbnails.
<pre>
Text version of the file can be found <a href=misc/padala/resize.cgi.txt>here</a>.
<font color="#a020f0">#!/usr/local/bin/perl -wT</font>
<font color="#0000ff"># Change above line to path to your perl binary</font>
<font color="#a52a2a"><b>use </b></font>CGI <font color="#ff00ff">'</font><font color="#ff00ff">:standard</font><font color="#ff00ff">'</font>;
<font color="#a52a2a"><b>use </b></font>GD;
<font color="#0000ff"># create a new image</font>
<font color="#008b8b">$image_file</font> = <font color="#ff00ff">&quot;</font><font color="#ff00ff">images/surfing.jpg</font><font color="#ff00ff">&quot;</font>;
<font color="#008b8b">$im</font> = GD::Image-&gt;newFromJpeg(<font color="#008b8b">$image_file</font>);
(<font color="#008b8b">$width</font>, <font color="#008b8b">$height</font>) = <font color="#008b8b">$im</font>-&gt;getBounds();
<font color="#008b8b">$newwidth</font> = <font color="#008b8b">$width</font> / <font color="#ff00ff">3</font>;
<font color="#008b8b">$newheight</font> = <font color="#008b8b">$height</font> / <font color="#ff00ff">3</font>;
<font color="#008b8b">$outim</font> = <font color="#a52a2a"><b>new</b></font> GD::Image(<font color="#008b8b">$newwidth</font>, <font color="#008b8b">$newheight</font>);
<font color="#0000ff"># make the background transparent and interlaced</font>
<font color="#008b8b">$outim</font>-&gt;copyResized(<font color="#008b8b">$im</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#008b8b">$newwidth</font>, <font color="#008b8b">$newheight</font>, <font color="#008b8b">$width</font>, <font color="#008b8b">$height</font>);
<font color="#0000ff"># make sure we are writing to a binary stream</font>
<font color="#a52a2a"><b>binmode</b></font> <font color="#008b8b">STDOUT</font>;
<font color="#a52a2a"><b>select</b></font>(STDOUT);
<font color="#008b8b">$|</font> = <font color="#ff00ff">1</font>;
<font color="#a52a2a"><b>undef</b></font> <font color="#008b8b">$/</font>;
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">Content-type: image/jpeg</font><font color="#6a5acd">\n\n</font><font color="#ff00ff">&quot;</font>;
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">$outim</font>-&gt;jpeg();
</pre>
<p>
In this example, the function newFromJpeg() reads a jpeg file. Then we
then calculated the boundaries and resized it accordingly. A demo of the resizing
can be found <a href=http://www.cise.ufl.edu/~ppadala/perl/exploring/cgi-bin/resize.cgi>here</a>
<h3> A Photo Album </h3>
<p>
With this resizing knowledge we can create a small online photo album. In this
we use resizing to show
smaller images and display the original image when the user clicks on the smaller images.
<pre>
Text version of the file can be found <a href=misc/padala/album.cgi.txt>here</a>.
<font color="#a020f0">#!/usr/local/bin/perl -wT</font>
<font color="#0000ff"># Change above line to path to your perl binary</font>
<font color="#a52a2a"><b>use </b></font>CGI <font color="#ff00ff">'</font><font color="#ff00ff">:standard</font><font color="#ff00ff">'</font>;
<font color="#a52a2a"><b>use </b></font>GD;
<font color="#008b8b">$imnum</font> = param(<font color="#ff00ff">'</font><font color="#ff00ff">imnum</font><font color="#ff00ff">'</font>);
<font color="#a52a2a"><b>if</b></font>(!<font color="#a52a2a"><b>defined</b></font>(<font color="#008b8b">$imnum</font>)) {
<font color="#008b8b">$imnum</font> = <font color="#ff00ff">0</font>;
}
<font color="#008b8b">$orig</font> = param(<font color="#ff00ff">'</font><font color="#ff00ff">orig</font><font color="#ff00ff">'</font>);
<font color="#a52a2a"><b>if</b></font>(!<font color="#a52a2a"><b>defined</b></font>(<font color="#008b8b">$imnum</font>)) {
<font color="#008b8b">$orig</font> = <font color="#ff00ff">0</font>;
}
<font color="#a52a2a"><b>select</b></font>(STDOUT);
<font color="#008b8b">$|</font> = <font color="#ff00ff">1</font>;
<font color="#008b8b">@images</font> = (<font color="#ff00ff">&quot;</font><font color="#ff00ff">surfing.jpg</font><font color="#ff00ff">&quot;</font>, <font color="#ff00ff">&quot;</font><font color="#ff00ff">boat.jpg</font><font color="#ff00ff">&quot;</font>, <font color="#ff00ff">&quot;</font><font color="#ff00ff">boston-view.jpg</font><font color="#ff00ff">&quot;</font>, <font color="#ff00ff">&quot;</font><font color="#ff00ff">seashore.jpg</font><font color="#ff00ff">&quot;</font>);
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">Content-type: text/html</font><font color="#6a5acd">\n\n</font><font color="#ff00ff">&quot;</font>;
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">&lt;font color=green&gt;Click on the image to make it bigger or smaller&lt;br&gt;</font>
<font color="#ff00ff">You can browse through the small images using the buttons or by clicking</font>
<font color="#ff00ff">on the numbers &lt;/font&gt;</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>;
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">&lt;table&gt;&lt;tr&gt;</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>;
<font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$imnum</font> &gt; <font color="#ff00ff">0</font> &amp;&amp; <font color="#008b8b">$imnum</font> &lt; <font color="#008b8b">@images</font>) {
<font color="#a52a2a"><b>printf</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">&lt;td&gt;&lt;a href=album.cgi?imnum=</font><font color="#008b8b">%d</font><font color="#ff00ff">&gt;&lt;img src=images/prev.gif border=0&gt;&lt;/a&gt;</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>, <font color="#008b8b">$imnum</font><font color="#ff00ff">-1</font>;
}
<font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$imnum</font> &gt;= <font color="#ff00ff">0</font> &amp;&amp; <font color="#008b8b">$imnum</font> &lt; <font color="#008b8b">@images</font> - <font color="#ff00ff">1</font>) {
<font color="#a52a2a"><b>printf</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">&lt;td&gt;&lt;a href=album.cgi?imnum=</font><font color="#008b8b">%d</font><font color="#ff00ff">&gt;&lt;img src=images/next.gif border=0&gt;&lt;/a&gt;</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>, <font color="#008b8b">$imnum</font><font color="#ff00ff">+1</font>;
}
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">&lt;td&gt;</font><font color="#ff00ff">&quot;</font>;
<font color="#a52a2a"><b>for</b></font>(<font color="#008b8b">$i</font> = <font color="#ff00ff">0</font>; <font color="#008b8b">$i</font> &lt; <font color="#008b8b">@images</font>; ++<font color="#008b8b">$i</font>) {
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">&lt;a href=album.cgi?imnum=</font><font color="#008b8b">$i</font><font color="#ff00ff">&gt;</font><font color="#008b8b">$i</font><font color="#ff00ff">|&lt;/a&gt;</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>;
}
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">&lt;/tr&gt;&lt;/table&gt;</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>;
<font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$imnum</font> &lt; <font color="#ff00ff">0</font> || <font color="#008b8b">$imnum</font> &gt;= <font color="#008b8b">@images</font>) {
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">&lt;b&gt;No such image&lt;/b&gt;</font><font color="#ff00ff">&quot;</font>;
<font color="#a52a2a"><b>exit</b></font>;
}
<font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$orig</font>) {
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">&lt;a href=album.cgi?imnum=</font><font color="#008b8b">$imnum</font><font color="#ff00ff">&gt;&lt;img src=images/</font><font color="#008b8b">$images</font><font color="#ff00ff">[</font><font color="#008b8b">$imnum</font><font color="#ff00ff">] border=0&gt;&lt;/img&gt;&lt;/a&gt;</font><font color="#6a5acd">\n</font><font color="#ff00ff">&quot;</font>;
}
<font color="#a52a2a"><b>else</b></font> {
<font color="#008b8b">$im</font> = GD::Image-&gt;newFromJpeg(<font color="#ff00ff">&quot;</font><font color="#ff00ff">images/</font><font color="#008b8b">$images</font><font color="#ff00ff">[</font><font color="#008b8b">$imnum</font><font color="#ff00ff">]</font><font color="#ff00ff">&quot;</font>);
<font color="#0000ff"># create a new image</font>
(<font color="#008b8b">$width</font>, <font color="#008b8b">$height</font>) = <font color="#008b8b">$im</font>-&gt;getBounds();
<font color="#008b8b">$newwidth</font> = <font color="#ff00ff">200</font>;
<font color="#008b8b">$newheight</font> = <font color="#ff00ff">200</font>;
<font color="#008b8b">$outim</font> = <font color="#a52a2a"><b>new</b></font> GD::Image(<font color="#008b8b">$newwidth</font>, <font color="#008b8b">$newheight</font>);
<font color="#008b8b">$outim</font>-&gt;copyResized(<font color="#008b8b">$im</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#008b8b">$newwidth</font>, <font color="#008b8b">$newheight</font>, <font color="#008b8b">$width</font>, <font color="#008b8b">$height</font>);
<font color="#008b8b">$tmpfile</font> = <font color="#ff00ff">&quot;</font><font color="#ff00ff">images/tmp</font><font color="#008b8b">$imnum</font><font color="#ff00ff">.jpg</font><font color="#ff00ff">&quot;</font>;
<font color="#a52a2a"><b>if</b></font> (<font color="#008b8b">$tmpfile</font> =~<font color="#a52a2a"><b> /</b></font><font color="#ff00ff">^</font><font color="#6a5acd">(</font><font color="#ff00ff">[-</font><font color="#6a5acd">\@\w</font><font color="#6a5acd">.</font><font color="#6a5acd">\/</font><font color="#ff00ff">]</font><font color="#6a5acd">+)</font><font color="#ff00ff">$</font><font color="#a52a2a"><b>/</b></font>) { <font color="#0000ff"># For the tainting stuff</font>
<font color="#008b8b">$tmpfile</font> = <font color="#008b8b">$1</font>;
}
<font color="#a52a2a"><b>else</b></font> {
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">Should never happen</font><font color="#ff00ff">&quot;</font>;
<font color="#a52a2a"><b>exit</b></font>; <font color="#0000ff"># Should never happen</font>
}
<font color="#a52a2a"><b>open</b></font>(<font color="#008b8b">TMP</font>, <font color="#ff00ff">&quot;</font><font color="#ff00ff">&gt;</font><font color="#008b8b">$tmpfile</font><font color="#ff00ff">&quot;</font>) || <font color="#a52a2a"><b>die</b></font>(<font color="#ff00ff">&quot;</font><font color="#ff00ff">Cannot open file</font><font color="#ff00ff">&quot;</font>);
<font color="#a52a2a"><b>binmode</b></font>(TMP);
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">TMP</font> <font color="#008b8b">$outim</font>-&gt;jpeg(<font color="#ff00ff">100</font>);
<font color="#a52a2a"><b>close</b></font>(TMP);
<font color="#a52a2a"><b>chmod</b></font>(<font color="#ff00ff">0644</font>, <font color="#008b8b">$tmpfile</font>);
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">&lt;a href=album.cgi?imnum=</font><font color="#008b8b">$imnum</font><font color="#ff00ff">&amp;orig=1&gt;&lt;img src=</font><font color="#008b8b">$tmpfile</font><font color="#ff00ff"> border=0&gt;&lt;/a&gt;</font><font color="#ff00ff">&quot;</font>;
}
</pre>
<p>
This script uses a few CGI features. The function param returns the parameter
value, if supplied. This value is used to display the proper image. If
the user wants to see an original image, it is displayed. Otherwise a
temporary resized image is created and displayed.
<p>
A <a href=http://www.cise.ufl.edu/~ppadala/perl/exploring/cgi-bin/album.cgi>demo</a>
of the album is
<a href=http://www.cise.ufl.edu/~ppadala/perl/exploring/cgi-bin/album.cgi>here</a>
<h3> A Graphical Hit Counter </h3>
<p>
Now let us turn our attention to another popular web application "A Hit Counter".
There are many counter scripts available on web. Here's our attempt to
write one.
<p>
The counter works like this. Every time a web-page is accessed, the cgi script
records the hit count and creates an image on-the-fly. So why wait? Let's
write it.
<pre>
Text version of the file can be found <a href=misc/padala/counter.cgi.txt>here</a>.
<font color="#a020f0">#!/usr/local/bin/perl -wT</font>
<font color="#a52a2a"><b>use </b></font>CGI <font color="#ff00ff">'</font><font color="#ff00ff">:standard</font><font color="#ff00ff">'</font>;
<font color="#a52a2a"><b>use </b></font>GD;
<font color="#a52a2a"><b>use strict</b></font>;
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$LOCK_SH</font>, <font color="#008b8b">$LOCK_EX</font>, <font color="#008b8b">$LOCK_NB</font>, <font color="#008b8b">$LOCK_UN</font>);
<font color="#008b8b">$LOCK_SH</font> = <font color="#ff00ff">1</font>;
<font color="#008b8b">$LOCK_EX</font> = <font color="#ff00ff">2</font>;
<font color="#008b8b">$LOCK_NB</font> = <font color="#ff00ff">4</font>;
<font color="#008b8b">$LOCK_UN</font> = <font color="#ff00ff">8</font>;
<font color="#a52a2a"><b>select</b></font>(STDOUT);
<font color="#008b8b">$|</font> = <font color="#ff00ff">1</font>;
<font color="#008b8b">&amp;main</font>;
<font color="#a52a2a"><b>sub</b></font><font color="#008b8b"> </font><font color="#008b8b">main</font><font color="#008b8b"> </font>{
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$id</font>, <font color="#008b8b">$iformat</font>, <font color="#008b8b">$show</font>);
<font color="#008b8b">$id</font> = param(<font color="#ff00ff">&quot;</font><font color="#ff00ff">id</font><font color="#ff00ff">&quot;</font>);
<font color="#008b8b">$iformat</font> = param(<font color="#ff00ff">&quot;</font><font color="#ff00ff">iformat</font><font color="#ff00ff">&quot;</font>);
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$counter_value</font>);
<font color="#008b8b">$counter_value</font> = <font color="#008b8b">&amp;update_counter_value</font>(<font color="#008b8b">$id</font>);
<font color="#a52a2a"><b>chomp</b></font>(<font color="#008b8b">$counter_value</font>);
<font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$iformat</font> <font color="#a52a2a"><b>eq</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">jpg</font><font color="#ff00ff">&quot;</font> || <font color="#008b8b">$iformat</font> <font color="#a52a2a"><b>eq</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">png</font><font color="#ff00ff">&quot;</font>) {
<font color="#008b8b">&amp;print_counter</font>(<font color="#008b8b">$iformat</font>, <font color="#008b8b">$counter_value</font>);
}
<font color="#a52a2a"><b>else</b></font> {
<font color="#008b8b">&amp;print_error_image</font>(<font color="#ff00ff">&quot;</font><font color="#ff00ff">Image format </font><font color="#008b8b">$iformat</font><font color="#ff00ff"> not supported</font><font color="#ff00ff">&quot;</font>);
}
}
<font color="#a52a2a"><b>sub</b></font><font color="#008b8b"> </font><font color="#008b8b">print_counter</font><font color="#008b8b"> </font>{
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$iformat</font>, <font color="#008b8b">$counter_value</font>) = <font color="#008b8b">@_</font>;
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$COUNTER_SIZE</font>) = <font color="#ff00ff">4</font>;
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$im</font>) = GD::Image-&gt;<font color="#a52a2a"><b>new</b></font>(<font color="#ff00ff">&quot;</font><font color="#ff00ff">${iformat}s/0.${iformat}</font><font color="#ff00ff">&quot;</font>);
<font color="#a52a2a"><b>if</b></font>(!<font color="#a52a2a"><b>defined</b></font>(<font color="#008b8b">$im</font>)) {
<font color="#008b8b">&amp;print_error_image</font>(<font color="#ff00ff">&quot;</font><font color="#6a5acd">\$</font><font color="#ff00ff">im couldn't be initialized</font><font color="#ff00ff">&quot;</font>);
<font color="#a52a2a"><b>exit</b></font>;
}
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$w</font>, <font color="#008b8b">$h</font>) = <font color="#008b8b">$im</font>-&gt;getBounds();
<font color="#a52a2a"><b>undef</b></font> <font color="#008b8b">$im</font>;
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$printim</font>) = GD::Image-&gt;<font color="#a52a2a"><b>new</b></font>(<font color="#008b8b">$w</font> * <font color="#008b8b">$COUNTER_SIZE</font>, <font color="#008b8b">$h</font>);
<font color="#008b8b">$printim</font>-&gt;colorAllocate(<font color="#ff00ff">255</font>, <font color="#ff00ff">255</font>, <font color="#ff00ff">255</font>);
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$pos</font>, <font color="#008b8b">$l</font>, <font color="#008b8b">$temp</font>, <font color="#008b8b">$digit</font>, <font color="#008b8b">$x</font>, <font color="#008b8b">$srcim</font>);
<font color="#008b8b">$x</font> = <font color="#ff00ff">0</font>;
<font color="#a52a2a"><b>for</b></font>(<font color="#008b8b">$pos</font> = <font color="#008b8b">$COUNTER_SIZE</font> - <font color="#ff00ff">1</font>; <font color="#008b8b">$pos</font> &gt;= <font color="#ff00ff">0</font>; <font color="#008b8b">$pos</font>--) {
<font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$pos</font> &gt; <font color="#a52a2a"><b>length</b></font>(<font color="#008b8b">$counter_value</font>) - <font color="#ff00ff">1</font>) {
<font color="#008b8b">$digit</font> = <font color="#ff00ff">0</font>;
}
<font color="#a52a2a"><b>else</b></font> {
<font color="#008b8b">$l</font> = <font color="#a52a2a"><b>length</b></font>(<font color="#008b8b">$counter_value</font>);
<font color="#008b8b">$temp</font> = <font color="#008b8b">$l</font> - <font color="#008b8b">$pos</font> - <font color="#ff00ff">1</font>;
<font color="#008b8b">$digit</font> = <font color="#a52a2a"><b>substr</b></font>(<font color="#008b8b">$counter_value</font>, <font color="#008b8b">$temp</font>, <font color="#ff00ff">1</font>);
}
<font color="#008b8b">$srcim</font> = GD::Image-&gt;<font color="#a52a2a"><b>new</b></font>(<font color="#ff00ff">&quot;</font><font color="#ff00ff">${iformat}s/${digit}.${iformat}</font><font color="#ff00ff">&quot;</font>);
<font color="#008b8b">$printim</font>-&gt;copy(<font color="#008b8b">$srcim</font>, <font color="#008b8b">$x</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#008b8b">$w</font>, <font color="#008b8b">$h</font>);
<font color="#008b8b">$x</font> += <font color="#008b8b">$w</font>;
<font color="#a52a2a"><b>undef</b></font> <font color="#008b8b">$srcim</font>;
}
<font color="#a52a2a"><b>if</b></font>(<font color="#008b8b">$iformat</font> <font color="#a52a2a"><b>eq</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">jpg</font><font color="#ff00ff">&quot;</font>) {
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">Content-type: image/jpeg</font><font color="#6a5acd">\n\n</font><font color="#ff00ff">&quot;</font>;
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">$printim</font>-&gt;jpeg(<font color="#ff00ff">100</font>);
}
<font color="#a52a2a"><b>else</b></font> {
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">Content-type: image/png</font><font color="#6a5acd">\n\n</font><font color="#ff00ff">&quot;</font>;
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">$printim</font>-&gt;png;
}
}
<font color="#a52a2a"><b>sub</b></font><font color="#008b8b"> </font><font color="#008b8b">print_error_image</font><font color="#008b8b"> </font>{
<font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$error_string</font> = <font color="#008b8b">$_</font>[<font color="#ff00ff">0</font>];
<font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$im</font> = <font color="#a52a2a"><b>new</b></font> GD::Image(
gdMediumBoldFont-&gt;width * <font color="#a52a2a"><b>length</b></font>(<font color="#008b8b">$error_string</font>),
gdMediumBoldFont-&gt;height);
<font color="#008b8b">$im</font>-&gt;colorAllocate(<font color="#ff00ff">255</font>, <font color="#ff00ff">255</font>, <font color="#ff00ff">255</font>);
<font color="#a52a2a"><b>my</b></font> <font color="#008b8b">$red</font> = <font color="#008b8b">$im</font>-&gt;colorAllocate(<font color="#ff00ff">255</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>);
<font color="#008b8b">$im</font>-&gt;string(gdMediumBoldFont, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>, <font color="#008b8b">$error_string</font>, <font color="#008b8b">$red</font>);
<font color="#a52a2a"><b>print</b></font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">Content-type: image/jpeg</font><font color="#6a5acd">\n\n</font><font color="#ff00ff">&quot;</font>;
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">$im</font>-&gt;jpeg(<font color="#ff00ff">100</font>);
<font color="#a52a2a"><b>exit</b></font>;
}
<font color="#a52a2a"><b>sub</b></font><font color="#008b8b"> </font><font color="#008b8b">update_counter_value</font><font color="#008b8b"> </font>{
<font color="#a52a2a"><b>my</b></font>(<font color="#008b8b">$file_name</font>, <font color="#008b8b">$counter_value</font>);
<font color="#008b8b">$file_name</font> = <font color="#ff00ff">&quot;</font><font color="#008b8b">$_</font><font color="#ff00ff">[0].counter</font><font color="#ff00ff">&quot;</font>;
<font color="#a52a2a"><b>if</b></font> (<font color="#008b8b">$file_name</font> =~<font color="#a52a2a"><b> /</b></font><font color="#ff00ff">^</font><font color="#6a5acd">(</font><font color="#ff00ff">[-</font><font color="#6a5acd">\@\w</font><font color="#6a5acd">.</font><font color="#ff00ff">]</font><font color="#6a5acd">+)</font><font color="#ff00ff">$</font><font color="#a52a2a"><b>/</b></font>) { <font color="#0000ff"># For the tainting stuff</font>
<font color="#008b8b">$file_name</font> = <font color="#008b8b">$1</font>;
}
<font color="#a52a2a"><b>else</b></font> {
<font color="#a52a2a"><b>exit</b></font>; <font color="#0000ff"># Should never happen</font>
}
<font color="#a52a2a"><b>if</b></font>(<font color="#a52a2a"><b>open</b></font>(<font color="#008b8b">COUNTERFILE</font>, <font color="#ff00ff">&quot;</font><font color="#ff00ff">+&lt;</font><font color="#008b8b">$file_name</font><font color="#ff00ff">&quot;</font>) == <font color="#ff00ff">0</font>) {
<font color="#0000ff"># Getting accessed for the first time</font>
<font color="#a52a2a"><b>open</b></font>(<font color="#008b8b">COUNTERFILE</font>, <font color="#ff00ff">&quot;</font><font color="#ff00ff">&gt;</font><font color="#008b8b">$file_name</font><font color="#ff00ff">&quot;</font>);
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">COUNTERFILE</font> <font color="#ff00ff">&quot;</font><font color="#ff00ff">1</font><font color="#ff00ff">&quot;</font>;
<font color="#a52a2a"><b>close</b></font>(COUNTERFILE);
<font color="#a52a2a"><b>return</b></font> <font color="#ff00ff">1</font>;
}
<font color="#a52a2a"><b>flock</b></font>(<font color="#008b8b">COUNTERFILE</font>, <font color="#008b8b">$LOCK_EX</font>);
<font color="#008b8b">$counter_value</font> = <font color="#008b8b">&lt;COUNTERFILE&gt;</font>;
<font color="#a52a2a"><b>seek</b></font>(<font color="#008b8b">COUNTERFILE</font>, <font color="#ff00ff">0</font>, <font color="#ff00ff">0</font>);
++<font color="#008b8b">$counter_value</font>;
<font color="#a52a2a"><b>print</b></font> <font color="#008b8b">COUNTERFILE</font> <font color="#008b8b">$counter_value</font>;
<font color="#a52a2a"><b>flock</b></font>(<font color="#008b8b">COUNTERFILE</font>, <font color="#008b8b">$LOCK_UN</font>);
<font color="#a52a2a"><b>close</b></font>(COUNTERFILE);
<font color="#a52a2a"><b>return</b></font>(<font color="#008b8b">$counter_value</font> - <font color="#ff00ff">1</font>);
}
</pre>
<p>
This script can be used by adding a line like this in your web page.
<pre>
&lt;img src=counter.cgi?id=my_html_file.html&amp;iformat=jpg&gt;
</pre>
<p>
The id needs to be unique. A sample counter can be seen on my
<a href=http://www.cise.ufl.edu/~ppadala>home page</a>.
<p>
Now to the innards of the script. The counter script has three important
functions.
<pre>
update_counter_value: This function reads the hit count from a file named
html_file.counter and increments it. It creates the
counter file, if one already doesn't exist. It also
locks the file to avoid conflicts due to multiple
simultaneous accesses.
print_counter: Prints the counter by attaching the counter digits in a new
image. The digits are read from an appropriate directory.
print_error_image: This is a useful function to show error images. You
can use it in your programs, for reporting errors
through GD.
</pre>
<p>
You need to have the digits (0-9) in jpg or png format. Sites like
<a href="http://www.counterart.com/">Counter Art dot Com</a> provide free
counter digits. In my next article, I'll discuss how to generate digits on
the fly.
<p>
I developed a <a href=http://pstats.sourceforge.net>personal website statistics</a>
package woven around this counter concept. It provides much more than a simple
counter. It logs the accesses, shows visitor statistics and much more. Check
it out at <a href=http://pstats.sourceforge.net>pstats</a> page.
<p>
You can also use the <a href=http://search.cpan.org/doc/GAAS/File-CounterFile-0.12/CounterFile.pm>File::CounterFile</a>
module for managing the counter file.
<h3> Coming Up.. </h3>
<p>
I hope you enjoyed reading this article. In the coming months, we will look at
GD::Graph and PerlMagick modules. Send me comments at
<a href="mailto:p_padala@yahoo.com">this address</a>.
<p>
Have Fun !!!</a>
<h3> Acknowledgements </h3>
<p>
My best friend <a href=http://www.ece.arizona.edu/~parimi>ravi</a> has become
the official editor for all my writings. I am indebted to him for looking
through all the gibberish I write and make sense out of it. Thanks ravi :-)
<p>
I thank <a href=mailto:ben-fuzzybear@yahoo.com>Benjamin A. Okopnik</a> for
reviewing the article and pointing out some nice perl hacks.
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Pradeep Padala</H4>
<EM>I am a master's student at University of Florida. I love hacking and
adore Linux. My interests include solving puzzles and playing board
games. I can be reached through
<a href="mailto:p_padala@yahoo.com">p_padala@yahoo.com</a> or <a
href="http://www.cise.ufl.edu/~ppadala">my web site</a>.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright &copy; 2002, Pradeep Padala.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Programming in Ruby, part 1</font></H1>
<H4>By <a href="mailto:hiran_rk@rediffmail.com">Hiran Ramankutty</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<H2><B> Introduction </B></H2>
<p>
<p><TD align=right><TD align=left>
Ruby is an interpreted, pure Object Oriented language designed by
Yukihiro Matsumoto of Japan, where it is reported to be more
popular than Python and Perl! The first part of this series is
meant to be a tutorial introduction, with more advanced stuff
in the pipeline.
</TD></TD>
<p>
Of course, I need not go through the ritual of advocating the
`advantages of Ruby compared to languages X, Y and Z' - most people
realize that each language has a unique flavour and character of
its own - whether you choose Python or Ruby for your next open
source project depends more on the peculiar affinity which you as an
individual feel for one over the other, and the availability of
standard library facilities, rather than on arcane technical
issues. So let's enjoy that unique Ruby flavour!
</p>
<H2><B>Requirements</B></H2>
<p>
I presume that your development environment is Linux and you have Ruby installed on
it. Ruby is free software, and there are no restrictions on it's usage. You can
get it from the <a href="http://www.ruby-lang.org"> Ruby Home Page </a>.
</p>
<H2><B>Hello World</B></H2>
<p>
Let's start with the mandatory `Hello, World'.
<pre>
% cat > hello.rb
print "Hello World\n"
^D
% ruby hello.rb
Hello World
%
</pre>
<H2><B>Variables</B></H2>
<p>
Categorization is done on the basis of the first character of the name of the
identifier:
<pre>
$ global variable
@ instance variable
a-z or '_' local variable
A-Z constant
</pre>
<p>
The two `pseudo-variables' are exceptions to the above stated rule. They are `self'
and `nil'.
<ul>
<li> self refers to the currently executing object
<li> nil meaningless or FALSE or value assigned to uninitialized variables
</ul>
<p>
Both are named as if they are local variables, but they are not! We will see their
real meaning later on.
<H2><B>Global variables</B></H2>
<p>
A global variable has it's name starting with $. As such, it can be
referred to from anywhere in the program. It is to be noted that a global variable
assumes the value 'nil' before initialization. You can test this out:
<pre>
% ruby
print $foo,"\n"
$foo = 5
print $foo,"\n"
^D
%
</pre>
The interpreter responds
<pre>
nil
5
</pre>
It is possible for us to `bind' procedures to global variables,
the procedures being automatically invoked when the variable
is changed. More about this later!
<p>
Some special kinds of global variables formed with a single character following a '$'
sign are, as a collection, interpreted by Ruby as major system variables
(made read-only). Some of them are given below along with their meanings.
<ul>
<li> $! latest error message
<li> $@ location of error
<li> $_ string last read by gets
<li> $. line number last read by interpreter
<li> $& string last matched by regexp
<li> $~ the last regexp match, as an array of subexpressions
<li> $n the nth subexpression in the last match (same as $~[n])
<li> $= case-insensitivity flag
<li> $0 the name of the ruby script file
<li> $* the command line arguments
<li> $$ interpreter's process ID
<li> $? exit status of last executed child process
</ul>
<H2><B>Local variables</B></H2>
<p>
A local variable has it's name starting with a lower case letter or an '_'. Unlike
globals and instance variables, they do not assume the value 'nil', but they
behave as shown below:
<pre>
% ruby
print foo
^D
</pre>
You will get an error message:
<pre>
"undefined local variable or method 'foo' for #(object...)".
</pre>
<p>
The scope of a local variable is confined to one of
<ul>
<li> proc {....}
<li> loop {....}
<li> def .... end
<li> class .... end
<li> module .... end
<li> the entire program (unless one of the above applies)
</ul>
If we initialize a local variable in any block(or a procedure), then it remains
undefined after exiting from the loop. For example:
<pre>
def foo(n)
k = 2 * n
print "\n",k,"\n"
print defined? k,"\n"
end
foo 3
print defined? k,"\n"
^D
</pre>
The output is:
<pre>
6
local-variable
nil
</pre>
<p>
In the above example `defined?' is an operator which checks whether it's argument
is defined or not. The results "local-variable" and "nil" (to indicate false) must make it
clear.
</p>
<H2><B>Constants</B></H2>
<p>
Any name with characters following an uppercase letter is treated as a constant. But
Ruby programmers, to avoid confusion, use names with all uppercase letters. So 'Foo' as well
as 'FOO' are constants. As in case of local variables, a constant is defined by a
substitution and an access to an undefined constant or alteration of a defined constant
causes an error. Check for yourself.
<H2><B> Strings </B></H2>
<p>
Strings in ruby can be single quoted('...') or double quoted("...").
But both are different. Use double quotes if the string contains
backslash-escaped characters. Also results of evaluation are
embedded for contained expressions quoted by #{}. See examples:
</p>
<pre>
print "\n"
print '\n'
print "\001","\n"
print '\001',"\n"
print "abcd #{5*3} efg","\n"
var = " abc "
print "1234#{var}567","\n"
^D
\n
\001
abcd 15 efg
1234abc567
</pre>
<p>
We will learn more about strings in the next section, arrays. This is to
include the features that are similar and are held by both arrays and strings.
</p>
<H2><B>Arrays</B></H2>
<p>
Arrays can be quoted using '[]'. One of the features of Ruby is that arrays
are heterogenous.
<pre>
a = [1,2,"3"]
print a,"\n"
^D
</pre>
<p>
Now, if you write a Ruby program to add all the elements of the array shown in the
above program, you will get an error:
<pre>
Error!!String cannot be coerced into Fixnum
</pre>
The `3' in the array is stored as a string. Now, if it is done like this:
<pre>
a = [1,2,"3"]
b = a[0] + a[1] + a[2].to_i
print b,"\n"
^D
</pre>
The program will be executed without any errors. The attachment to a[2] i.e. '.to_i'
is to convert the content of a[2] to an integer.You can also try '.to_s'.
<p>
Operations like concatenation and repetition can be done on arrays.
<pre>
a = [1,2,"3"]
print a + ["foo","bar"]
print a * 2
^D
</pre>
We get
<pre>
123foobar
123123
</pre>
<p>
It's possible to `slice and dice' arrays. Here are some examples:
<pre>
a = [1,2,"3","foo","bar"]
print a[0],"\n"
print a[0,2],"\n"
print a[0..3],"\n"
print a[-2..2],"\n"
print a[-3..-1],"\n"
</pre>
</p>
<p>
Arrays and strings are inter-convertible. An array can be converted to a string
with 'join', and a string is split up into an array with 'split'.
<pre>
a = [1,2,3]
print a[2],"\n"
a = a.join(":")
print a[2],"\n"
print a,"\n"
a = a.split(":")
print a[2],"\n"
print a,"\n"
^D
</pre>
<p>
The Associative Array is another important data structure - it's also
called a `hash' or a `dictionary'. It's basically a name-value mapping,
as shown below:
<pre>
h = {1 => 2, "2" => "4"}
print hash,"\n"
print hash[1],"\n"
print hash["2"],"\n"
print hash[5],"\n"
^D
</pre>
I hope the results are convincing!
</p>
<H2><B>Control structures</B></H2>
<H3><B>If - else</B></H3>
<p>
Let us write the factorial function.The mathematical
definition is:
<pre>
n! = 1 (when n==0)
n! = n * (n-1)! (otherwise)
</pre>
In ruby this can be written as:
<pre>
def fact(n)
if n == 0
1
else
n * fact(n-1)
end
end
print fact 4,"\n"
</pre>
You get 24.
<p>
Ruby has been called `Algol like' because of the repeated
occurrence of `end'. In this recursive call, you may notice the
lack of the return statement. In fact, use of return is
permissible but unnecessary because a ruby function returns
the last evaluated expression (does this sound a wee bit
Lispish? If you insist, you sure can do Lisp in Ruby!)
</p>
<H3><B>The for loop</B></H3>
<p>
<pre>
for i in 0..4
body-of-for
end
</pre>
<p>
Here i is the variable and 0..4 is the range.In the case of
strings, you can very well write:
<pre>
for i in "abc"
</pre>
<H3><B>The while loop</B></H3>
<p>
Try this out
</p>
<pre>
i=0
while i < 10
print i+=1,"\n"
end
</pre>
<H3><B> Case </B></H3>
<p>
We use the case statement to test a sequence of conditions. Try this out.
</p>
<pre>
i = 7
case i
when 1,2..5
print "i in 2 to 5\n"
when 6..10
print "i in 6 to 10\n"
end
^D
</pre>
<p>
You get
</p>
<pre>
i in 6 to 10
</pre>
<p>
2..5 means the range including 2 and 5. It checks whether i falls
within that range.
</p>
<p>
This can be applied to strings as shown below.
</p>
<pre>
case 'abcdef'
when 'aaa','bbb'
print 'contains aaa or bbb \n"
when /def/
print "contains def \n"
end
^D
contains def
</pre>
<p>
Note the slash used with "def". It is used for quoting a regular expression.
We shall see it later.
</p>
<H3><B> Modifications with control structures </B></H3>
<p>
The case statement mentioned just above actually tests for the range
(i in 2..5) as
</p>
<pre>(2..5) === i </pre>
<p>The relationship operator '===' is used by case to check for several
conditions at a time. '===' is interpreted by ruby suitably for the
object that appears in the when condition.
</p>
<p>
Thereby in the example with strings equality is tested with first when
and an expression is matched with the second when.
</p>
<p>
Now try using the operator '===' with if structure(try implementing
functions like isalnum(),isalpha(),isnum() etc.).
</p>
<p>
Your code can be shortened when we have to use if and while constructs
for individual statements: as shown below
</p>
<pre>
i = 7
print "contained in 5..10\n" if (5..10) === i
print i-=1,"\n" while i > 0
^D
contained in 5..10
6
5
4
3
2
1
0
</pre>
<p>
You may at times want to negate the test conditions. An unless is
a negated if, and an until is a negated while. This is left up to you to
experiment with.
</p>
<p>
There are four ways to interrupt the processing of statements of a loop
from inside. First, as in C, break means, to escape from the loop
entirely. Second, next skips to beginning of the next iteration of the
loop (corresponds to continue statement in C). Third ruby has redo,
which restarts the current iteration. The following is C code
illustrating the meanings of break, next, and redo:
</p>
<pre>
while(condition) {
label_redo:
goto label_next; /* ruby's "next" */
goto label_break; /* ruby's "break"*/
goto label_redo; /* ruby's "redo" */
...
...
label_next:
}
label_break:
...
</pre>
<p>
The return statement is actually the fourth way to get out of a loop
from inside. In fact return causes escape not only from the loop
but also from the method that contains the loop.
</p>
<H2><B> Conclusion </B></H2>
We have examined some elementary language features - enough to get
you started with a bit of `quick-and-dirty' coding. As I learn more
about this `gem' of a language, I shall be sharing my experience
with you through future articles. Good bye!
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Hiran Ramankutty</H4>
<EM>I am a final year student of Computer Science at Government Engineering
College, Trichur. Apart from Linux, I enjoy learning Physics.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright &copy; 2002, Hiran Ramankutty.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Process Tracing Using Ptrace</font></H1>
<H4>By <a href="mailto:sk_nellayi@rediffmail.com">Sandeep S</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<EM><B>The ptrace system call is crucial to the working of debugger programs like gdb - yet its behaviour is not very well documented - unless you believe that the best documentation is kernel source itself! I shall attempt to demonstrate how ptrace can be used to implement some of the functionality available in tools like gdb.</B></EM>
<H2><A NAME="s1">1. Introduction</A></H2>
<P><B>ptrace()</B> is a system call that enables one process to control the execution
of another. It also enables a process to change the core image of
another process. The traced process behaves normally until a signal is caught.
When that occurs the process enters stopped state and informs the
tracing process by a <B>wait()</B> call. Then tracing process decides how the
traced process should respond. The only exception is SIGKILL which surely kills
the process.
<P>The traced process may also enter the stopped state in response to some
specific events during its course of execution. This happens only if the
tracing process has set any event flags in the context of the traced process.
The tracing process can even <B>kill</B> the traced one by setting the exit code
of the traced process. After tracing, the tracer process may kill the traced
one or leave to continue with its execution.
<P>
<P><B>Note:</B> Ptrace() is highly dependent on the architecture of the
underlying hardware. Applications using ptrace are not easily portable across
different architectures and implementations.
<P>
<H2><A NAME="s2">2. More Details </A></H2>
<P>The prototype of ptrace() is as follows.
<BLOCKQUOTE><CODE>
<HR>
<PRE>
#include &lt;sys/ptrace.h&gt;
long int ptrace(enum __ptrace_request request, pid_t pid,
void * addr, void * data)
</PRE>
<HR>
</CODE></BLOCKQUOTE>
<P>
<P>Of the four arguments, the value of <B>request</B> decides what to be
done. <B>Pid</B> is the ID of the process to be traced. <B>Addr</B> is the
offset in the user space of the traced process to where the <B>data</B> is
written when instructed to do so. It is the offset in user space of the traced
process from where a word is read and returned as the result of the call.
<P>
<P>The parent can fork a child process and trace it by calling ptrace with
<B>request</B> as PTRACE_TRACEME. Parent can also trace an existing process using
PTRACE_ATTACH. The different values of <B>request</B> are discussed below.
<P>
<H2>2.1 How does ptrace() work.</H2>
<P>Whenever ptrace is called, what it first does is to lock the kernel. Just
before returning it unlocks the kernel. Let's see its working in between
this for different values of <B>request</B>.
<P>
<H3><B>PTRACE_TRACEME</B>:</H3>
<P>This is called when the child is to be traced by the
parent. As said above, any signals (except SIGKILL), either delivered from
outside or from the <B>exec</B> calls made by the process, causes it to stop and
lets the parent decide how to proceed. Inside ptrace(), the only thing that is checked is
whether the ptrace flag of the current process is set. If not, permission
is granted and the flag is set. All the parameters other than <B>request</B> are
ignored.
<P>
<H3><B>PTRACE_ATTACH</B>:</H3>
<P>Here a process wants to control another. One thing to
remember is that nobody is allowed to trace/control the <B>init</B> process.
A process is not allowed to control itself. The current process (caller) becomes
the parent of the process with process ID <B>pid</B>. But a <B>getpid()</B> by the
child (the one being traced) returns the process ID of the real parent.
<P>
<P>What goes behind the scenes is that when a call is made, the usual permission
checks are made along with whether the process is init or current or it is
already traced. If there is no problem, permission is given and the flag
is set. Now the links of the child process are rearranged; e.g., the child is
removed from the task queue and its parent process field is changed (the
original parent remains the same). It is put to the queue again in such a
position that <B>init</B> comes next to it. Finally a SIGSTOP signal is delivered
to it. Here <B>addr</B> and <B>data</B> are ignored.
<P>
<H3><B>PTRACE_DETACH</B>:</H3>
<P>Stop tracing a process. The tracer may decide whether the child should continue
to live. This undoes all the effects made by PTRACE_ATTACH/PTRACE_TRACEME. The
parent sends the exit code for the child in <B>data</B>. Ptrace flag of the child
is reset. Then the child is moved to its original position in the task queue.
The pid of real parent is written to the parent field. The single-step bit
which might have been set is reset. Finally the child is woken up as nothing
had happened to it; <B>addr</B> is ignored.
<P>
<P>
<H3><B>PTRACE_PEEKTEXT, PTRACE_PEEKDATA, PTRACE_PEEKUSER</B>:</H3>
<P>These options read data from child's memory and user space. PTRACE_PEEKTEXT
and PTRACE_PEEKDATA read data from memory and both these options have the same
effect. PTRACE_PEEKUSER reads from the user space of child. A word is read and
placed into a temporary data structure, and with the help of put_user()
(which copies a string from the kernel's memory segment to the
process' memory segment) the required data is written to <B>data</B> and returns
0 on success.
<P>
<P>In the case of PTRACE_PEEKTEXT/PTRACE_PEEKDATA, <B>addr</B> is the address of
the location to be read from child's memory. In PTRACE_PEEKUSER <B>addr</B> is
the offset of the word in child's user space; <B>data</B> is ignored.
<P>
<H3><B>PTRACE_POKETEXT, PTRACE_POKEDATA, PTRACE_POKEUSER</B>:</H3>
<P>These options are analogous to the three explained above. The difference is
that these are used to write the <B>data</B> to the memory/user space of the
process being traced. In PTRACE_POKETEXT and PTRACE_POKEDATA a word from
location <B>data</B> is copied to the child's memory location <B>addr</B>.
<P>
<P>In PTRACE_POKEUSER we are trying to modify some locations in the
<CODE>task_struct</CODE> of the process. As the integrity of the kernel has to be
maintained, we need to be very careful. After a lot of security checks made
by ptrace, only certain portions of the task_struct is allowed to change. Here
<B>addr</B> is the offset in child's user area.
<P>
<H3><B>PTRACE_SYSCALL, PTRACE_CONT</B>:</H3>
<P>Both these wakes up the stopped process. PTRACE_SYSCALL makes the child to
stop after the next system call. PTRACE_CONT just allows the child to continue.
In both, the exit code of the child process is set by the ptrace() where the
exit code is contained in <B>data</B>. All this happens only if the
signal/exit code is a valid one. Ptrace() resets the single step bit of the
child, sets/resets the syscall trace bit, and wakes up the process; <B>addr</B> is ignored.
<P>
<H3><B>PTRACE_SINGLESTEP</B>;</H3>
<P>Does the same as PTRACE_SYSCALL except that the child is stopped after
every instruction. The single step bit of the child is set. As above <B>data</B>
contains the exit code for the child; <B>addr</B> is ignored.
<P>
<H3><B>PTRACE_KILL</B>:</H3>
<P>When the child is to be terminated, PTRACE_KILL may be used. How the murder
occurs is as follows. Ptrace() checks whether the child is already dead or not.
If alive, the exit code of the child is set to <B>sigkill</B>. The single step bit
of the child is reset. Now the child is woken up and when it starts to work it
gets killed as per the exit code.
<P>
<H2>2.2 More machine-dependent calls</H2>
<P>The values of <B>request</B> discussed above were independent on the
architecture and implementation of the system. The values discussed below are
those that allow the tracing process to get/set (i.e., to read/write) the
registers of child process. These register fetching/setting options are more
directly dependent on the architecture of the system. The set of registers
include general purpose registers, floating point registers and extended
floating point registers. These more machine-dependent options are discussed
below. When these options are given, a direct interaction between the
registers/segments of the system is required.
<P> <H3><B>PTRACE_GETREGS,
PTRACE_GETFPREGS, PTRACE_GETFPXREGS</B>:</H3>
<P>These values give the value of general purpose, floating point, extended
floating point registers of the child process. The registers are
read to the location <B>data</B> in the parent. The usual checks for access on the
registers are made. Then the register values are copied to the location
specified by <B>data</B> with the help of getreg() and __put_user() functions;
<B>addr</B> is ignored.
<P>
<H3><B>PTRACE_SETREGS, PTRACE_SETFPREGS, PTRACE_SETFPXREGS</B>:</H3>
<P>These are values of <B>request</B> that allow the tracing process to set the
general purpose, floating point, extended floating point registers of the child
respectively. There are some restrictions in the case of setting the registers.
Some are not allowed to be changed. The data to be copied to the registers will
be taken from the location <B>data</B> of the parent. Here also <B>addr</B> is
ignored.
<P>
<H2>2.3 Return values of ptrace()</H2>
<P>A successful ptrace() returns zero. Errors make it return -1 and set
<B>errno</B>. Since the return value of a successful PEEKDATA/PEEKTEXT may
be -1, it is better to check the <B>errno</B>. The errors are
<P>
<P>EPERM : The requested process couldn't be traced. Permission denied.
<P>
<P>ESRCH : The requested process doesn't exist or is being traced.
<P>
<P>EIO : The request was invalid or read/write was made from/to invalid area
of memory.
<P>
<P>EFAULT: Read/write was made from/to memory which was not really mapped.
<P>
<P>It is really hard to distinguish between the reasons of EIO and EFAULT.
These are returned for almost identical errors.
<P>
<H2><A NAME="s3">3. A small example.</A></H2>
<P>
If you found the parameter description to be a bit dry, don't
despair. I shall not attempt anything of that sort again. I will
try to write simple programs which illustrate many of the
points discussed above.
<P>
<P>Here is the first one. The parent process counts
the number of instructions executed by the test program run by the child.
<P>Here the test program is listing the entries of the current directory.
<P>
<BLOCKQUOTE><CODE>
<HR>
<PRE>
#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
#include &lt;signal.h&gt;
#include &lt;syscall.h&gt;
#include &lt;sys/ptrace.h&gt;
#include &lt;sys/types.h&gt;
#include &lt;sys/wait.h&gt;
#include &lt;unistd.h&gt;
#include &lt;errno.h&gt;
int main(void)
{
long long counter = 0; /* machine instruction counter */
int wait_val; /* child's return value */
int pid; /* child's process id */
puts("Please wait");
switch (pid = fork()) {
case -1:
perror("fork");
break;
case 0: /* child process starts */
ptrace(PTRACE_TRACEME, 0, 0, 0);
/*
* must be called in order to allow the
* control over the child process
*/
execl("/bin/ls", "ls", NULL);
/*
* executes the program and causes
* the child to stop and send a signal
* to the parent, the parent can now
* switch to PTRACE_SINGLESTEP
*/
break;
/* child process ends */
default:/* parent process starts */
wait(&amp;wait_val);
/*
* parent waits for child to stop at next
* instruction (execl())
*/
while (wait_val == 1407 ) {
counter++;
if (ptrace(PTRACE_SINGLESTEP, pid, 0, 0) != 0)
perror("ptrace");
/*
* switch to singlestep tracing and
* release child
* if unable call error.
*/
wait(&amp;wait_val);
/* wait for next instruction to complete */
}
/*
* continue to stop, wait and release until
* the child is finished; wait_val != 1407
* Low=0177L and High=05 (SIGTRAP)
*/
}
printf("Number of machine instructions : %lld\n", counter);
return 0;
}
</PRE>
<HR>
</CODE></BLOCKQUOTE>
<P>
<P>open your favourite editor and write the program. Then run it by typing
<P><CODE>cc file.c</CODE>
<P><CODE>a.out</CODE>
<P>You can see the number of instructions needed for listing of your current
directory. <CODE>cd</CODE> to some other directory and run the program from there
and see whether there is any difference. (note that it may take some time
for the output to appear, if you are using a slow machine).
<P>
<H2><A NAME="s4">4. Conclusion</A></H2>
<P>
<P>Ptrace() is heavily used for debugging. It is also used for system call
tracing. The debugger forks and the
child process created is traced by the parent. The program which is to
be debugged is exec'd by the child (in the above program it was
"ls") and after each instruction the parent can examine the register
values of the program being run. I shall demonstrate programs which
exploit ptrace's versatility in the next part of this series. Good
bye till then.
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Sandeep S</H4>
<EM>I am a final year student of Government Engineering College in Thrissur,
Kerala, India. My areas of interests include FreeBSD, Networking and also
Theoretical Computer Science.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright &copy; 2002, Sandeep S.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Secure and Robust Computer Systems for Primary and Secondary Schools</font></H1>
<H4>By <a href="mailto:rsevenic@netscape.net">Richard A Sevenich</a> and Michael P Angelo</H4>
</center>
<P> <HR> <P>
<!-- END header -->
<P>A wealthy school district will have the
option of purchasing new software and hardware at some appropriate
interval. It may also have the technical staff to install and
maintain the hardware and software. Even in this idealized school
district, the computer system environment is a harsh one, with its
many student users, some of whom start as relatively computer
illiterate and may not have acquired the discipline to follow
administrative rules intended to ameliorate system virus infections
and other external attacks on the system. The technical staff has the
added burden of attempting to maintain system security in this nearly
impossible environment, characterized by intermittent, unplanned
intense work shifts in response to system security disasters.
Providing the necessary level of technical expertise is quite
expensive and consequently rather rare in our school systems. In
fact, many of the primary and secondary schools in the USA have
computer facilities that are in dire straits. Perhaps the major
problems are these two:</P>
<UL>
<LI><P>The networks are plagued by
viruses etc. and suffer significant down time. Further, loss of
files and of attendant work time is routine.</P>
<LI><P>Often the computers are a hodgepodge of donated and purchased
computers with various versions of Microsoft operating systems and
software.</P>
</UL>
<P>Let's consider each of the two problems
in more detail. Cleaning a network of virus infections is a
time-consuming thankless job. Making a system in a school environment
virus proof in practice is probably not possible currently. Other
hostile system attacks (even internal) are quite likely. A teacher
who depends on such a system to be consistently available will be
routinely disappointed.</P>
<P>If we focus on the second problem,
these are its consequences:</P>
<UL>
<LI><P>The various software versions are
not always compatible with each other, so work cannot be dependably
moved from one computer to another.</P>
<LI><P>The original versions of the
software and the corresponding licenses are sometimes missing.
Microsoft is beginning to seize on this issue, requiring an
expensive solution.</P>
</UL>
<P>In this note we propose a
straightforward solution. The idea came to us when we began playing
with version 3.0 of Demo Linux (<A HREF="http://www.demolinux.org/">http://www.demolinux.org</A>).
It provides the start of a solution. When you boot a machine with
Demo Linux, you end up with a machine running Linux from the CD. The
network will be configured as will X Windows. The old Star Office 5.2
is also included. The hard drive may be mounted. We had remarkable
success booting a variety of machines, including laptops, from the
Demo Linux CD.
</P>
<P>Forgetting about the hard drive for the
moment, a school could have such CDs in all their computers and turn
them on each morning to start with a virus-free environment,
compatible software in all machines, and no licensing problems.
Rather than requiring the constant application of security patches,
the system is reborn each day. The solution is not expensive and is
ultimately robust due to its simplicity. Well, it is almost that
simple and convenient, but not quite. Here are three drawbacks:</P>
<OL>
<LI><P>Some system configuration (e.g.
network parameters) is needed at each boot, requiring that somebody
knowledgeable make the appropriate entries. This is time intensive
when the number of systems is large - assuming that a knowledgeable
person is even available.</P>
<LI><P>The hard drive remains a virus
target.</P>
<LI><P>Applications running from the CD
will run relatively slowly; perhaps unacceptably slowly on some
machines.</P>
</OL>
<P>We next suggest solutions to each of
these problems.</P>
<OL>
<LI><P>Automate system
configuration at boot. To implement this we would add a feature to a
clone of Demo Linux. In particular, on the very first boot have the
system configuration choices made by the appropriate sysadmin or
technician and then have the system automatically hard code those
choices by producing an ISO image to be burned onto a new boot CD,
tailored to that specific machine. The new boot CD would
automatically configure the system as desired. Boot CDs could be
updated on whatever schedule the administration would deem
appropriate (e.g. once a year in August).</P>
<LI><P>We'll assume that
the machines at the school do not have an NFS/NIS file sharing
setup. If that assumption were wrong, we would do things a different
way,
We'll further assume that when
this new system is first installed, the hard drive is ours; i.e. any
files stored on the hard drive have been archived by the owner.
We'll propose a severe solution and insist that machine users
either save their daily work on a floppy or transmit it (e.g. via
scp) to a secure machine serving as a repository. The description of
that secure repository machine is outside the scope of this
discussion. Copying work to a floppy or transmitting it to a secure
repository would be made reasonably convenient and intuitive; e.g.
via some GUI interface. The CD boot process would clean all the
prior day's files from the hard drive. This is the aforementioned
severe solution and more involved and intelligent solutions might be
contrived. However, this solution appears to guarantee a virus free
environment at each new boot and is simple. Note that the hard drive
cleaning is not all that time consuming because it involves only
those files created since the previous boot.</P>
<LI><P>Application speed
can be enhanced by having the boot CD move the appropriate
applications to the hard drive during the boot process, after the
hard drive has been cleaned as described in the prior step.</P>
</OL>
<P>It must be admitted that
this approach is not going to produce a well performing system for
very dated machines with limited resources. Open Office, for example,
would not perform well. A small footprint Linux version and other
resource-conserving software could prove viable. Such are available
in the embedded Linux world and could be adapted to resource-limited
machines. This may be too small a market to pursue, however.</P>
<P>We've explored the
preceding ideas for feasibility, tailoring and burning some boot-up
CDs and the like. However, we have various other commitments and
cannot take the concept to full fruition as a polished, flexible
product in a reasonable time frame, although we will continue to work
on it. We see this as having the potential to:
</P>
<UL>
<LI><P>save school
districts a significant amount of money</P>
<LI><P>obviate the
necessity for occasional audits by Microsoft or other vendors</P>
<LI><P>simplify the system
administration task</P>
<LI><P>make systems much
more secure and robust</P>
<LI><P>remove the need to
respond with unplanned, intense work shifts to repair system
security breaches</P>
</UL>
<P>Pretending that such a
product will actually be created, there is the one remaining hurdle -
the initial deployment. School districts with technical personnel
could easily handle the initial CD boot and the creation of the
second, machine-specific boot CD. The cost of the initial
installation would be amortized very quickly. Alternatively, the CD
provider might supply on site initial installation services at a
reasonable cost. Because of the open nature of Linux, other
consultants would become available. Finally, financially hard-pressed
school districts might get such services free from a nearby Linux
User Group.
</P>
<P>Teachers, already
overburdened, will need to learn enough Linux to function. They will
be resistant, because their time is precious. Those of us who
switched to Linux at some point in the past had to travel a learning
curve. However, Linux has progressed to the point where the learning
curve is no longer significant. There are distributions that are
configured to look and act rather like the Microsoft interface. Old
Microsoft Office files can, in most cases, be imported into something
like Open Office and so on. The direct benefits to the teachers
should outweigh the slight pain of conversion.
</P>
<P>We haven't seen this
concept in this form in print before, although all its elements are
out there. Hence, we wanted to put it before the Linux community. If
the proposal bears up under scrutiny and appears viable, we hope some
entity, such as the Demo Linux folks or a Linux distribution, with
appropriate expertise and resources, adopts it as a project. We have
posed it as a solution to certain difficult problems typically faced
by school districts in the USA. Obviously, it could be applied in
other areas. To some extent, time is of the essence - the need and
opportunity are there now.
</P>
<!-- *** BEGIN bio *** -->
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright &copy; 2002, Richard A Sevenich and Michael P Angelo.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">Creating Reusable Software Libraries</font></H1>
<H4>By <a href="mailto:robt@robtougher.com">Rob Tougher</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<dl>
<dt><a href=#1>1. Introduction</a>
<dt><a href=#2>2. Making It Easy To Use</a>
<dd><a href=#2.1>2.1 Keeping It Simple</a>
<dd><a href=#2.2>2.2 Being Consistent</a>
<dd><a href=#2.3>2.3 Making It Intuitive</a>
<dt><a href=#3>3. Testing Thoroughly</a>
<dt><a href=#4>4. Providing Detailed Error Information</a>
<dt><a href=#5>5. Conclusion</a>
</dl>
<a name=1></a>
<h3>1. Introduction</h3>
<p>
Software libraries provide functionality to
application developers. They consist of reusable code that
developers can utilize in their projects.
Software libraries targeted for Linux are usually available in both
binary and source code form.
</p>
<p>
A well-written software library:
</p>
<ul>
<li>is easy to use
<li>works flawlessly
<li>provides detailed error information
</ul>
<p>
This article describes the above principles of library creation,
and gives examples in C++.
</p>
<table width=80% border=1>
<tr>
<td bgcolor=#EEEEEE>
<font>
<h4>
Is This Article For You?
</h4>
<p>
Create software libraries only when you have to.
Ask yourself
these questions before proceeding:
</p>
<ul>
<li><i>Will anyone (including you) need functionality X in future applications?</i>
<li><i>If so, does a library implementing functionality X already exist?</i>
</ul>
<p>
If no one will need the functionality you are developing,
or a software library implementing it already exists,
don't create a new library.
</p>
</font>
</td>
</tr>
</table>
<a name=2></a>
<h3>2. Making It Easy To Use</h3>
<p>
The first step in creating a software library is designing
its <b>interface</b>.
Interfaces written in procedural languages, like C, contain
functions. Interfaces written in object-oriented languages,
like C++ and Python, can contain both functions and classes.
</p>
<p>
Remember this motto when designing your interface:
</p>
<ul>
<li><i>The easier to use, the better</i>
</ul>
<p>
As a library designer, I am constantly faced with
finding the right balance between functionality and
ease of use. The above motto helps me resist
adding too much functionality into my designs.
</p>
<p>
Stick with the following guidelines, and you'll be fine.
</p>
<a name=2.1></a>
<h4>2.1 Keeping It Simple</h4>
<p>
The more complex a library, the harder it
is to use.
</p>
<ul>
<li><i>Keep It Simple, Stupid</i>
</ul>
<p>
I recently encountered a C++ library that consisted of
one class. This class contained 150 methods.
<i>150 methods!</i>
The designer was most likely a C veteran using C++ - the
class acted like a C module.
Because this class was so complex, it was
<i>very difficult</i> to learn.
</p>
<p>
Avoid complexity in your designs, and your interfaces will
be cleaner and easier to understand.
</p>
<a name=2.2></a>
<h4>2.2 Being Consistent</h4>
<p>
Users learn consistent interfaces more easily. After learning
the rules once, they feel confident in applying those
rules across all classes and methods, even if they
haven't used those classes and methods before.
</p>
<p>
One example I am guilty of involves public accessors
for private variables. I sometimes do the following:
</p>
<pre>
class point
{
public:
int get_x() { return m_x; }
int set_x ( int x ) { m_x = x; }
int y() { return m_y; }
private:
int m_x, m_y;
};
</pre>
<p>
Do you see the problem here? For the m_x member, the public accessor
is "get_x()", but for the m_y member, the public accessor is
"y()". This inconsistency generates more work for the users - they
have to look up the definition of each accessor before using it.
</p>
<p>
Here's another example of an inconsistent interface:
</p>
<pre>
class DataBase
{
public:
recordset get_recordset ( const std::string sql );
void RunSQLQuery ( std::string query, std::string connection );
std::string connectionString() { return m_connection_string; }
long m_sError;
private:
std::string m_connection_string;
};
</pre>
<p>
Can you spot its problems? I can think of at least
these items:
</p>
<ul>
<li>Methods and variables are not named consistently
<li>Two different terms, <i>sql</i> and <i>query</i>, are
used to denote a SQL string
<li><i>m_sError</i> does not have a public accessor
<li><i>get_recordset()</i> does not have a <i>connection</i> in
its argument list
</ul>
<p>
Here is a revised version that solves these problems:
</p>
<pre>
class database
{
public:
recordset get_recordset ( const std::string sql );
void run_sql_query ( std::string sql );
std::string connection_string() { return m_connection_string; }
long error() { return m_error; }
private:
std::string m_connection_string;
long m_error;
};
</pre>
<p>
Keep your interfaces as consistent as possible - your users will
find them much easier to learn.
</p>
<a name=2.3></a>
<h4>2.3 Making It Intuitive</h4>
<p>
Design an interface how you would expect it to
work from a user's point of view - don't design it
with the internal implementation in mind.
</p>
<p>
I find that the easiest way to design an intuitive interface
is to write code that will use the library <i>before</i> actually
writing the library. This forces me to think about the
library from the user's standpoint.
</p>
<p>
Let's look at an example. I was recently considering writing
an encryption library based
on OpenSSL. Before thinking about the library
design, I wrote some code snippets:
</p>
<pre>
crypto::message msg ( "My data" );
crypto::key k ( "my key" );
// blowfish algorithm
msg.encrypt ( k, crypto::blowfish );
msg.decrypt ( k, crypto::blowfish ):
// rijndael algorithm
msg.encrypt ( k, crypto::rijndael );
msg.decrypt ( k, crypto::rijndael ):
</pre>
<p>
This code helped me think about how I should design the interface -
it put me in the user's shoes. If I decide to implement this
library, my design will flow from these initial ideas.
</p>
<a name=3></a>
<h3>3. Testing Thoroughly</h3>
<p>
A software library should work flawlessly. Well not
<i>flawlessly</i>, but as close to flawless as possible.
Users of a library need to know that the library is performing
its tasks correctly.
</p>
<ul>
<li><i>Why use a software library if it doesn't work correctly?</i>
</ul>
<p>
I test my software libraries using automated scripts.
For each library, I create a corresponding
application that exercises all features of the library.
</p>
<p>
For example, say I decided to develop the encryption
library I introduced in the previous section. My test
application would look like the following:
</p>
<pre>
#include "crypto.hpp"
int main ( int argc, int argv[] )
{
//
// 1. Encrypt, decrypt, and check
// message data.
//
crypto::message msg ( "Hello there" );
crypto::key k ( "my key" );
msg.encrypt ( k, crypto::blowfish );
msg.decrypt ( k, crypto::blowfish );
if ( msg.data() != "Hello there" )
{
// Error!
}
//
// 2. Encrypt with one algorithm,
// decrypt with another, and check
// message data.
//
// etc....
}
</pre>
<p>
I would occasionally run this application to make
sure that my software library did not have any major
errors.
</p>
<a name=4></a>
<h3>4. Providing Detailed Error Information</h3>
<p>
Users need to know when a software library cannot perform
its tasks correctly.
</p>
<ul>
<li><i>Alert the user when there is a problem</i>
</ul>
<p>
Software libraries written in C++ use
<b>exceptions</b> to pass information to its
users. Consider the following example:
</p>
<pre>
#include &lt;string&gt;
#include &lt;iostream&gt;
class car
{
public:
void accelerate() { throw error ( "Could not accelerate" ); }
};
class error
{
public:
Error ( std::string text ) : m_text ( text ) {}
std::string text() { return m_text; }
private:
std::string m_text;
};
int main ( int argc, int argv[] )
{
car my_car;
try
{
my_car.accelerate();
}
catch ( error& e )
{
std::cout << e.text() << "\n";
}
}
</pre>
<p>
The <i>car</i> class uses the <b>throw</b> keyword to
alert the caller to an erroneous situation. The caller
catches this exception with the <b>try</b> and
<b>catch</b> keywords, and deals with the problem.
</p>
<p>
</p>
<a name=5></a>
<h3>5. Conclusion</h3>
<p>
In this article I explained the important principles
of well-written software libraries.
Hopefully I've explained everything clearly enough so
that you can incorporate these principles into your
own libraries.
</p>
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Rob Tougher</H4>
<EM>Rob is a C++ software engineer in the New York City area.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright &copy; 2002, Rob Tougher.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <HR> <P>
<!--===================================================================-->
<center>
<H1><font color="maroon">SysRq: The Process-nuke</font></H1>
<H4>By <a href="mailto:vikasgp386@hotmail.com">Vikas G P</a></H4>
</center>
<P> <HR> <P>
<!-- END header -->
<p>
So you thought you could always kill an offending program with <code>kill -9</code> ?
But what if it's your X server that has crashed, or that nifty svgalib program
you wrote ? That's where magic SysRq comes in.
<p>
<h2>What is it</h2>
<p>
Magic SysRq is a key combination directly intercepted by the kernel and
can be used, among other things, to perform an emergency shutdown. It is
described in Documentation/sysrq.txt and implemented in drivers/char/sysrq.c
in the kernel source tree. It exists primarily for kernel hackers, but it can be
useful to people in user-space also. Since it is implemented as a part of the
<a href="http://www.linuxjournal.com/article.php?sid=1080">keyboard driver,</a>
it is guaranteed to work most of the time, unless the
kernel itself is dead.
<p>
A note: In the rest of this article, when I say "SysRq key" I mean the single key
beside the Scroll lock key. But when I say "magic SysRq" I mean the <em>combination
</em>&lt Alt+SysRq &gt.
<p>
<h2>Enabling</h2>
<p>
To do the SysRq magic, your kernel needs to be compiled with CONFIG_MAGIC_SYSRQ.
Most distributions would have enabled it by default. If your's hasn't, you'll
just have to
<A href="http://www.tldp.org/HOWTO/Kernel-HOWTO.html">recompile</a>... :)</p>
<p>
After everything is OK with the kernel, check if SysRq is enabled by default.
</p>
<pre>
$ cat /proc/sys/kernel/sysrq
0
</pre>
If it shows zero, it's not enabled. Writing any non-zero value to
/proc/sys/kernel/sysrq will enable it.
<pre>
$ echo "1" > /proc/sys/kernel/sysrq
</pre>
If you want it to be always enabled, append these lines to one of your initialization
scripts(preferably rc.local).
<pre>
#Enable SysRq
echo -e "Enabling SysRq\n"
echo "1" > /proc/sys/kernel/sysrq
</pre>
<p>
Alternatively, you might look for a file called /etc/sysctl or /etc/sysctl.conf
which some distributions have(mine, RedHat, does). You can add a line like this to
it, and sysrq will be enabled at boot-time.
<pre>
kernel.sysrq = 1
</pre>
<p>
The magic SysRq combination is a unique one. Now, every key on the keyboard sends
a code when pressed or released, called the scan-code. The magic SysRq combination
(Alt+SysRq), however, sends only <em>one</em> scan-code(0x54, decimal 84) even though
two keys have been pressed. Check this out using <code>showkey -s</code>.
<p>
<h2>What can I do with it ?</h2>
<p>
Magic SysRq is invoked as &lt Alt+SysRq &gt + &lt command &gt. The SysRq key is
also labelled as Print Screen. The commands are:
<p>
k: Secure access key - This kills all processes running on the current virtual
console, so that no snoopy program can grab your keystrokes while you type your
password.
<p>
u: Attempts to unmount the root device, and remount it read-only. In addition to an
emergency shutdown, this command also comes in handy if you have only
one partition for Linux and need to do an fsck or low-level filesystem
editing(for example, ext2 undeletion. See
<a href="http://www.tldp.org/HOWTO/mini/Ext2fs-Undeletion.html">
Ext2fs Undeletion Howto</a>
<p>
s: This command syncs the kernel buffers to disk. You should do this
before unmounting.
<p>
b: Does an immediate reboot, pretty much like pressing the reset button. For a
safe shutdown, precede this with a sync and Unmount.
<p>
p: Prints the contents of the CPU registers.
<p>
m: Shows memory information.
<p>
t: Shows information about the tasks currently running.
<p>
0-9: Sets the console log-level to the specified number.
<p>
e: Sends a SIGTERM to all processes, except init.
<p>
i: Sends a SIGKILL(sure kill) to all processes, except init.
<p>
l: Sends a SIGKILL to all processes, including init(you won't be able to anything
after this).
<p>
<h2>Getting out</h2>
<p>
How do you get out of SysRq mode ? There is no definite documentation about this in
sysrq.txt. It talks about having to press the left and right control,alt and
shift keys, but a simpler thing worked for me. Just press Alt+SysRq once again,
and you'll get out of it.
<p>
The way I understand this is:
The kernel remembers the state of the magic SysRq combination: it's either down or
up. When you press the key for the first time, the state is changed to down. And when
you press any other key while SysRq's state is down, the kernel interprets it
as a command. If you press SysRq again, the state is changed to up, and further
keystrokes are handed to whatever program requests it.
<br>
(Actually, it's not that simple. Sometimes, the above mentioned method doesn't work.
I believe it's because the kernel uses a separate translation table when magic SysRq
is down.)
<p>
The SysRq key originally meant, as you can guess, "System Request". It was used by
early IBM terminals to get the attention of a central computer to execute a command.
The key seems to have few uses now, except in the linux kernel.
<p>
<h2> Security</h2>
<p>
Leaving magic SysRq enabled on a production machine can be potentially
dangerous. Anyone with physical access to the machine can bring it
down instantly.<br>
You should also disable SysRq if other people can log in to your system
remotely. A &lt break &gt sent from a remote console will be interpreted
as &lt Alt+SysRq &gt, and the consequences can be disastrous. See the
<a href="http://www.tldp.org/HOWTO/Remote-Serial-Console-HOWTO/index.html">
Remote-Serial-Console-HOWTO
</a> for more details.
<p>
<h2>Conclusion</h2>
<p>
The magic SysRq hack can come in very handy at times. However, it must be used
with care. It can also give you some insights into the inner workings of the kernel.
If you are enterprising, you might even hack the kernel and add new commands !
<!-- *** BEGIN bio *** -->
<SPACER TYPE="vertical" SIZE="30">
<P>
<H4><IMG ALIGN=BOTTOM ALT="" SRC="../gx/note.gif">Vikas G P</H4>
<EM>I'm in the last year of high school and live in Hassan, Karnataka in India,
trying to balance my studies and linuxing.</EM>
<!-- *** END bio *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <!-- P -->
<H5 ALIGN=center>
Copyright &copy; 2002, Vikas G P.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
<H4 ALIGN="center">
"Linux Gazette...<I>making Linux just a little more fun!</I>"
</H4>
<P> <hr> <P>
<H1><font color="maroon">The Back Page</font></H1>
<ul>
<li><a HREF="#reunion">LG Reunion</a>
<li><a HREF="#wacko">Wacko Topic of the Month</a>
</ul>
<a name="reunion"></a>
<P> <hr> <P>
<!--====================================================================-->
<center><H3><font color="maroon">LG Reunion</font></H3></center>
<P> <HR> <P>
<!--======================================================================-->
<P>
<IMG ALT="[picture]" SRC="misc/backpage/chester.jpg" WIDTH="601" HEIGHT="315">
<BR CLEAR="all">
<P> That's me, Didier from Belgium (of The Answer Gang fame) and Mick from
Ireland (of News Bytes fame) in Chester, England during my UK trip in July. We
spent the day in Chester walking on the medieval wall, looking at Roman
columns, and visiting the Roman amphitheater and the Chester Cathedral. More
pictures from my trip are at
<A HREF="http://iron.cx/pix/">http://iron.cx/pix/</A> in the 2002 section.
<a name="wacko"></a>
<P> <hr> <P>
<!--====================================================================-->
<center><H3><font color="maroon">Wacko Topic of the Month</font></H3></center>
<P> <HR> <P>
<!--======================================================================-->
<P>
<P> All this talk about England reminded Ben of a pseudo-<EM>Beowulf</EM>
quote his <CODE>fortune</CODE> program doth said once:
<BLOCKQUOTE><PRE>
Meanehwael, baccat meaddehaele, monstaer lurccen;
Fulle few too many drincce, hie luccen for fyht.
[D]en Hreorfneorht[d]hwr, son of Hrwaerow[p]heororthwl,
AEsccen aewful jeork to steop outsyd.
[P]hud! Bashe! Crasch! Beoom! [D]e bigge gye
Eallum his bon brak, byt his nose offe;
Wicced Godsylla waeld on his asse.
Monstaer moppe fleor wy[p] eallum men in haelle.
Beowulf in bacceroome fonecall bemaccen waes;
Hearen sond of ruccus saed, "Hwaet [d]e helle?"
Graben sheold strang ond swich-blaed scharp
Sond feorth to fyht [d]e grimlic foe.
"Me," Godsylla saed, "mac [d]e minsemete."
Heoro cwyc geten heold wi[p] faemed half-nelson
Ond flyng him lic frisbe bac to fen.
Beowulf belly up to meaddehaele bar,
Saed, "Ne foe beaten mie faersom cung-fu."
Eorderen cocca-colha yce-coeld, [d]e reol [p]yng.
-- Not Chaucer, for certain
</PRE></BLOCKQUOTE>
<P> If that's not wacko enough, see this
<A HREF="http://www.gilchriststudios.com/nancy/images/061802.gif">Nancy cartoon</A>.
<HR> <!-- ************************************************************** -->
<P> Happy Linuxing!
<P> Mike ("Iron") Orr<br>
Editor, <A HREF="http://www.linuxgazette.com/"><i>Linux Gazette</i></A>, <A
HREF="mailto:gazette@ssc.com">gazette@ssc.com</a>
<BR CLEAR="all">
<!-- *** END Not Linux *** -->
<!-- *** BEGIN copyright *** -->
<P> <hr> <P>
<H5 ALIGN=center>
Copyright &copy; 2002, the Editors of <I>Linux Gazette</I>.<BR>
Copying license <A HREF="../copying.html">http://www.linuxgazette.com/copying.html</A><BR>
Published in Issue 81 of <i>Linux Gazette</i>, August 2002</H5>
<!-- *** END copyright *** -->
</BODY></HTML>