Sei sulla pagina 1di 13

Coding with Lisp Coding with Lisp

‘A hip, burgeoning free software community is currently pushing Lisp, arguably the oldest case for Lisp than coder and writer Paul Graham (see Hackers and complete theory of computation within Lisp, is a
Painters, LU&D 42), whose own work with Viaweb is good testament rich seam to mine, with demanding papers on
programming language in common use, to the fore as a next generation coding platform. Self- both to the power of Lisp as an expressive language and Lisp’s this subject furnished by the likes of Graham,
relevance within enterprise level, large-scale projects. Graham’s essays Sussman and Guy Steele, another major player in
confessed Lisp newbie, Martin Howse, presents the first part of an accessible guide to the and books provide a singular practical and conceptual resource, the early life of Lisp, and co-inventor of the
elegantly tying real world arguments within a neat conceptual intriguing Connection Machine.
culture of this flexible language, and practical implementations under GNU/Linux’ bundle, which is well wrapped up by his strong theoretical grounding
and knowledge of the language. He speaks from experience, and MORE TO LISP THAN LISTS
those who paraphrase Graham without his depth of understanding Extendibility here means both extending the Lisp
will always sound a bit hollow. Nevertheless, Lisp’s features and language itself in a completely transparent

Lambda The Ultimate


advantages must be outlined, and these can readily be pinned down manner, thus building a domain specific
both to a decent level of abstraction and to highly usable abstractions language for the application, and providing the
themselves, such as closures and macros. It’s worth remembering that facility for others to readily extend and customise
Lisp belongs within the family of functional languages, which implies an application. In the first instance, the field of

The art of Lisp, or coding as philosophy


equivalence between software and data allows
for coding custom languages with powerful
abstractions, and in the latter case, this form of
what Graham calls bottom-up programming
naturally results in extensible software, with GNU
Emacs as prime example here. From this
perspective, Lisp isn’t about writing applications,
it’s about writing languages. And, given the
growing complexity of both hardware and
contemporary software systems, this heavily
modular, high level approach to programming
and systems architecture is seriously compelling.
Indeed, pioneers Sussman and Abelson preface
their essential SICP volume with clear indications
Coder’s dream or of how to control complexity, through
user’s nightmare? establishing conventional interfaces, and
Symbolics Genera establishing new languages.
environment was a And, alongside those who claim that Lisp is
Lisp hacker’s unusable due to an arcane syntax which
paradise, allowing multiplies parentheses, some would still maintain
coders to dig deep that Lisp is slow, and argue thus that the need
into Lisp hardware for speed has lost out in the battle with
complexity. But, given that nearly all modern

good points. To hijack Python guru, Tim Peter’s, words, “Good modularity, an essential requirement for Good languages aren’t random collections of
languages aren’t random collections of interchangeable features: they large-scale, complex projects. Such
have a philosophy and internal coherence that’s never profitably abstractions, and features such as automatic interchangeable features: they have a philosophy

L and internal coherence that’s never profitably


isp has come in from the cold. After years enduring the icy confused with their surface features.” Understanding Lisp is a gradual memory management, courtesy of built-in
Artificial Intelligence (AI) winter, a period in the late eighties process, and involves some degree of immersion in the history, garbage collection, readily enable new ways
when Lisp was dumped by many thanks to associations with philosophy and culture of Lisp as well as a gentle involvement with of programming, and this is Lisp’s great confused with their surface features
over-hyped AI research, and a frosty decade in academic obscurity, coding to further elucidate core concepts such as recursion and advantage.
the open source community has dusted down this unique language, macros. Yet, Lisp, with an array of dialects, libraries and Sure, the semi-interpreted nature of Lisp, with functions able to be implementations compile during interpretation,
and freshened her up with lemon odour. Or rather Lemonodor.com, a implementations is far from the easiest language to get up and tried and tested at the interactive REPL (Read Eval Print Loop) prompt, following a just-in-time model, or allow
high profile Web site which actively promotes and describes Lisp use running with, in contrast to Python, which obviously presents a one or so called top level, assists in rapid development, and, Graham specifically for interactive compilation, speed is
and can readily be considered the Slashdot of the Lisp world, has stop shop. And although a clear conceptual understanding can be proffers amusing examples of improving server software on the fly, rarely an issue. And the speed of prototyping or
performed this service for the community. readily sought in printed works such as The Little Lisper or in Abelson but Lisp’s real advantage remains in its extensibility which can readily coding is a further issue which should also enter
Like a proud mother, Lisp, probably the oldest language still in use and Sussman’s seminal Structure and Interpretation of Computer be seen as stemming from a core feature of the language; the fact the equation. With Lisp, at least one has greater
today, can view her children and remark on how their best features all Programs (SICP), practical advice which would further support this that Lisp programs are expressed as Lisp data structures. Indeed, John options for exploration and prototyping, and, if
stem from her genes or rather memes. Flexibility and speed of knowledge is sorely lacking within the community. As we’ll see, McCarthy, a key figure within AI and inventor and primary needs be, optimisations can be furnished later in
development are her watchwords, and key enabling features of the certain initiatives are under way to resolve these issues, but aside from implementor of Lisp, remarks in an essay on the early history of Lisp, the day. Such notions regarding Lisp as sluggish
language, such as run-time typing and an interactive approach to evangelising Lisp, an effort which is close to achieving its goals, more that “One can even conjecture that Lisp owes its survival specifically belong within an old-fashioned view of Lisp
interpretation or compilation have been adopted by newer languages work does need to be done in this direction, and this short article to the fact that its programs are lists, which everyone, including me, which focuses on syntax and on lists, arguing
such as Python. Yet, Python misses the killer core or inner beauty only aims to provide an overview for the intelligent and necessarily has regarded as a disadvantage.” Hacker, Pascal Constanza, argues that LISP stands for List Processing Language,
which so many celebrate in Lisp. intrigued beginner. that this core feature makes of Lisp much more than just another and which corrals this powerful language within
To approach this core takes more than simply enumerating Lisp’s No-one has been more instrumental in persuasively arguing the Turing complete language, and this notion, which embeds a an academic prison. The new view of Lisp is that,

50 LinuxUser & Developer LinuxUser & Developer 51


Coding with Lisp

given automatic highlighting and indentation, and Sussman’s work. Indeed, in their heyday, these pioneers were
parentheses and other syntactical issues churning out meta-circular evaluators for subsets and dialects of Lisp
disappear. Lisp is a far more flexible language at an alarming rate, and their work forms an important link between
than the acronym would suggest. the more exciting aspects of mathematics, philosophy and computer
science. Another valuable starting point here would be the common
GETTING META assertion that the proof of Godel’s incompleteness theorem, which is
A further consequence of the flattening of essential to an understanding of AI, would have been easier if he had
software and data as quite distinct animals, is invented Lisp first, given Lisp’s predilection for the meta-circular. And
that Lisp really does live in the land of the meta, just before any unthinking C coders chime in, a C compiler written in
and that’s a place where a good few C, which can be used for bootstrapping, does not belong in the realm
sophisticated coders and theorists like to hang of the metacircular which further specifies that precise semantics must
out. Douglas Hofstadter, in his seminal
mathematical and meta-math work, Godel,
Escher, Bach: An Eternal Golden Braid, provides
Another consequence of the much vaunted
many mind stimulating adventures at the meta-
level, and Lisp makes for a very natural fit here.
data/software equivalence, is the unusual
And yet another consequence of the much defining quality that Lisp can be written in itself
not be defined in the evaluator. The
common parallel is with looking up a
word in the dictionary, and finding
that the definition uses the original
word. That is how things work with a
Lisp written in Lisp; eval, which quite
obviously evaluates expressions, is
implemented by calling eval. In
contrast, a C compiler must specify
detailed and precise semantics for
each and every construct, and take
care of boring old parsing. The REPL
defines all that is needed to build a
Lisp interpreter; read an expression,
evaluate it and then print the results. It
has to be admitted that there’s a
certain beauty and simplicity at work
here, and Lisp is certainly unique in
this respect.
A good deal of this simplicity stems
from Lisp’s roots, with the theoretical
work of John McCarthy in the 1950s,
which touches on all the rich
L-Lisp, running with an OpenGL Lisp library, puts some life back into a code heavy subject, thematics wrapped up by Godel’s
with Lindenmayer systems readily simulating plants and fractals work in the sphere of mathematics.
Both McCarthy and Graham write well
on this early history of the language,
and their texts make for essential
vaunted data/software equivalence, is the reading. McCarthy did not set out to design and create a
Lisp lives in
unusual defining quality that Lisp can be written programming language to meet specific programming needs or
in itself. In practice, this can be achieved in very the land of the satisfy a problem domain, rather he was interested in mathematical
few lines of code, and such a resulting beast is meta, and notation and expressing theory. This makes Lisp unique in the field of
the rather frightening metacircular interpreter or that’s a place programming, and quite distinct from the functionality associated
metacircular evaluator. This creature lies at the with C or C++. Lisp is a flexible, theoretical language which is
where a
very heart of an understanding of the history and primarily expressive.
conceptual underpinnings of Lisp, and writing good few Rather than jogging through the history of Lisp, which is well
such an interpreter forms a useful exercise for the sophisticated rehearsed elsewhere by the likes of McCarthy and Steele, Graham’s
novice. Again this is another rich seam well coders and Roots of Lisp paper presents a conceptual walk-through of the birth of
worthy of further investigation, and the intrigued Lisp, with McCarthy’s notation translated into Common Lisp code,
theorists like
could start with Graham’s excellent paper, The and along the way he provides a good description of the primitive
Roots of Lisp, or plough straight into Abelson to hang out Lisp forms, which are function calls or macros, before arriving at the

52 LinuxUser & Developer


Coding with Lisp Coding with Lisp

The Lemonodor effect detailed explication of an of the huge On Lisp volume to macros, which he considers of great than Common Lisp, more elegant and crystalline, as opposed to the can fire up, say, CLISP, a pleasant, simple
The Common Lisp community has certainly eval function written in importance within the paradigm of bottom-up programming, and baroque, full features of Common Lisp. But there are great Common Lisp interpreter, straight from the
gone from strength to strength in the last Lisp. Graham describes macros are certainly an essential, if hard to learn, feature which allows similarities between the languages, and core features of Scheme command line and throw a few Lisp expressions
two years, with blogs and wikis as primary Lisp’s elegant syntax and for writing programs that write programs. Macros are quite simply such as continuations, which freeze the state of a computation for at it, but to get some decent work done you’ll
medium for the sharing of enthusiasm,
notation, and key terms functions which transform expressions and they can themselves call later use, can readily be achieved with macros under Common Lisp. need a more powerful implementation which
inspiration and information. There are blogs
by and for newbies, and blogs from old such as expression, form, other functions and make use of other macros; a heady brew indeed Once again, it seems that languages cannot so readily be boiled integrates well with an editor such as GNU
hands such as Rainer Joswig, and sometime list and atom. Alongside whose power of transformation is unheard of elsewhere. To clear up down to a feature set. Emacs to form an efficient IDE. In part
LU&D contributor, Daniel Barlow. However, six primitive operators, any confusion, macros under Lisp have little to do with their C-based The relative size of two, we’ll pit SBCL against CMUCL, the
the Slashdot of all Lisp weblogs, if such a
thing can be imagined, is surely Lemonodor, the quote operator, namesakes, which perform purely string substitutions. Macros allow Scheme is also an Lushly produced, with two favoured free implementations,
clearly signalling that Lisp is the new rock
and roll with a mix of hardcore news from
which has obvious
parallels with quotation
the language to play with its own readily accessible internals as data,
and a good many Common Lisp functions are implemented as
issue. Given that Lisp
doesn’t really bother
intriguing illustrations often integrate these tightly with GNU Emacs
using a touch of SLIME, throw
the Lisp community, John Wiseman’s artistic
LA lifestyle reports, and a marked emphasis
in the English language,
is well described as
macros themselves. Understanding macros is one thing, and making
use of them perhaps even more complex, but given the definition
about the difference
between built-in
loosely associated with the packaging and packages into the mix
and touch on embedding and
on Lisp within the field of robotics.
Lushly produced, with intriguing functioning to distinguish that macros are simply operators that are implemented by functions and user- topic at hand, Lemonodor is a extending with Lisps such as librep and
illustrations often loosely associated with the
topic at hand, Lemonodor is a legend in the
land of Lisp. And a mention by Wiseman of a
data from code. The
lambda notation for
transformation, and noting a few example expansions which can
readily be tested with the macroexpand-1 function should set the
defined functions, it’s
a tough call to decide
legend in the land of Lisp functionalities such as FFI (Foreign
Function Interface).
site, surely results in record traffic, if not of denoting functions is beginner on the right track.
Slashdotting proportions. Even one of the
best free Common Lisp IDEs, SLIME, makes
mention of achieving Lemonodor fame in the
Scheme can be viewed as a more minimal
startup routines. Inspired by Planet GNOME,
Planet Lisp acts as meta blog, collecting
language than Common Lisp, more elegant and
essential content from a huge number of Lisp-
related weblogs. Despite sometimes straying crystalline, as opposed to the baroque, full
from the Lisp path into territory which indeed
may rival the poor signal-to-noise ratios of features of Common Lisp
Slashdot, Planet Lisp does make for a decent
daily immersion in Lisp culture. clearly elaborated, and SCHEMING
With plentiful RSS feeds, and much cross with great elegance, Though Lisp’s history post-McCarthy does make for interesting
linking the Lisp world is well connected, and
the greatest resource of them all, cliki.net Graham whips out a reading, with colourful anecdotes peppering the story of computer
collects much of these links and blogs and surprise Lisp eval, written science’s most philosophical language and furnishing a classic
provides further essential resources. Cliki.net, using functions built from narrative of riches to rags and back again, there is little here that is
powered by Daniel Barlow’s CLiki engine, a only seven primitives. totally relevant to the contemporary Lisper, aside perhaps from
Common Lisp wiki, is well worth checking out
changelog-wise on a daily basis. The practical Further functions can be intriguing material covering the hardware implemented Lisp
lisp page is a useful starting point for newbies, elaborated and evaluated Machines and their associated development environments such as
if somewhat dated in respect to SLIME use, using this eval, which can Genera, which few contemporary IDEs can even dream of
but cliki.net does provide links or information
readily be transformed competing with. It’s also worth bearing in mind that given Lisp’s Debugging is a fine art under Common Lisp, and along with packaging and macros can
on practically every aspect of Lisp culture and
practice. Parodying or mirroring the towards a contemporary flexibility and extendibility which make it easy to create quite readily confuse the beginner SLIME on GNU Emacs makes for a contemporary IDE which matches up to the power and
evangelicism of a religious Web site, another Lisp, and thence bended radically different dialects of Lisp, Lisp should really be considered as sheer flexibility of Lisp languages
CLiki, the ALU (Association of Lisp Users) wiki, towards implementations a family of languages rather than a language in its own right. And
is packed with so called “Road to Lisp” pages
which can easily furnish until the early to mid 80s the Lisp world was seriously splintered
which demonstrate the fervent admiration
which Lisp provokes. Unfortunately, the ALU
wiki has recently been the subject of
abstractions such as
object-oriented
with competing dialects and implementations proliferating. To
address these issues, hardcore Lisp hackers gathered to standardise a
where the core language ends and library functions begin. Under
ANSI Common Lisp, the piece of string is certainly seen as being a
Key Links
prolonged spam attacks, and its active life programming (OOP). new language, Common Lisp, which is the main Lisp in use today, good deal longer than under Scheme, but to do any useful work *hyper-cliki*
Lemonodor
does appear to be in danger. Other CLikis of lisp.tech.coop/index
Indeed, in his excellent alongside Scheme, an unusual, elegant dialect created by Sussman Schemers may have to take on board some supplementary libraries. www.lemonodor.com
note include the *hyper-cliki*, an annotatable
Common Lisp reference, and the wonderfully ANSI Common Lisp, and Steele in the late 70s. Common Lisp is well specified in It is perhaps more fitting to investigate specific implementations,
SICP ALU wiki
funky TUNES project CLiki which outlines a Graham shows as an Common Lisp the Language, or CLtL for those in the know, with PLT Scheme as a hot favourite on that side of the Lisp fence.
mitpress.mit.edu/sicp alu.cliki.net/index
range of projects and resources towards the exercise how a minimal authored by Guy Steele. ANSI standardisation for Common Lisp Scheme does have a lot of things going for it, and contrary to the
creation of a free reflective computing system,
or Lisp-based OS. Other essential online OOP can be followed a few years later. argument that Scheme’s simplicity and beauty don’t play well with Paul Graham CLiki
resources linked from cliki.net, include the implemented in Thus, one of the first choices facing the novice Lisp coder, before real-world issues, it is totally possible to produce enterprise level www.paulgraham.com www.cliki.net/index
Common Lisp Cookbook, an attempt to create Common Lisp, without even considering free implementations, is whether to ride with apps under Scheme. That said, the free software Common Lisp
a community resource parallelling the Perl John McCarthy TUNES project
using CLOS (Common Common Lisp or Scheme. There can be no easy answer and the community, grouped around hearty resources such as cliki.net and
Cookbook approach and both Successful Lisp www-formal.stanford.edu/jmc tunes.org
and Practical Common Lisp, two essential Lisp Object System) question has probably fed more flame wars in both communities Lemonodor, just seems much more active, though there is a good
online works. features. His preliminary than any other issue. Researching the culture of both dialects can deal of crossover, with seasoned hackers turning their hands to both Guy Steele Successful Lisp
language is implemented throw interesting light on theoretical issues under both languages, dialects. For the sake of simplicity, Scheme will remain outside the library.readscheme.org/page1.html www.psg.com/~dlamkins/sl/contents.html
in just eight lines of code. and it’s relatively easy to grasp the fundamental differences in feel scope of these articles, with the caveat that an understanding of the
PLT Scheme Practical Common Lisp
Under the mini OOP embedded language, when it comes down to and approach. Scheme does have a particularly interesting history, conceptual underpinnings of Scheme and the lazy evaluation which
www.plt-scheme.org www.gigamonkeys.com/book
improving the syntax of message calls to make them read more like and its creation is considered as of seminal importance within the continuations facilitate can prove suitably enriching for any hacker.
Lisp, the rather more complex meta world of macros is encountered. history of computing, resulting as it does from an attempt to Beyond this essential conceptual background, what the newbie Planet Lisp Common Lisp Cookbook
Once again macros come courtesy of the uniform treatment of code understand Actors, Carl Hewitt’s message passing model of sorely needs to know are the specifics of respected implementations planet.lisp.org cl-cookbook.sourceforge.net
and data as forms for manipulation. Graham has devoted the whole computation. Scheme can be viewed as a more minimal language and how to get up and running with these most efficiently. Sure you

54 LinuxUser & Developer LinuxUser & Developer 55


Sensor networks Sensor networks

G
lobal warming has became the new booming nuclear-powered India in the EARLY WARNING SYSTEMS
ghoul of modern politics. Since the middle, sudden prospects of economic ECONOMICS
cold war, global terrorism, Islam and prosperity and even regional dominance. While global data networks are providing
various dictators have been made timely warnings of tsunamis in the Pacific,
to serve as the new GLOBAL NETWORKS = US the presence of the US, Canada, Japan and
counterpoints of global NETWORKS? New Zealand is a factor not only valid for
political strategy. But The USA developed the global reach, but geographers, but also for budget allocations
the frontiers have none of the global economic and social for respective governments. The Indian
changed. Global presence so essential to experience divergent Ocean contains few zones of cooperation
warming and its political cultures and environmental and and many of conflict: India and Pakistan,
attendant political concerns. Technical and scientific Burma and Thailand, Sri Lanka, Indonesia

Microkernels and TinyOS


consequences have expertise was available to the US political and Malaysia have all eyed each other across
suddenly become a elites, but as recent political events have lengthy borders and through decades of
more important issue borne out, the very thought of global conflict. Asking them to cooperate is often a
For anyone with any knowledge of recent Unix history, the debate as to whether
than the war in Iraq political engagement with other countries on question of political tact as much as global
microkernels or so-called monolithic kernels are to be preferred is fairly old hat.
Embedded systems do sometimes rely on them even though they might not have much or the catastrophic equal terms is anathema to the current US economic realities. Where should the money
more than a rudimentary kernel running only essential services. Sensor systems tend to Indian Ocean tsunami. administration. and the experts come from to finance and
run real-time operating systems, usually without prejudice towards the kernel The nations of the Indian Ocean and The very size of the scientific establishment run an early-warning network that can be
architecture.
Europe have always been slightly more in the US and its rather smaller, but still run by all Indian Ocean countries?
The design decisions for TinyOS are quite interesting in this regard, since
many RTOS companies tend to be quite fond of microkernel architectures. attuned to global environmental concerns. influential counterparts in the European
RTOS developers like to be able to strip down a kernel to its most essential Many reasons can be adduced: Europe’s Union and Japan leads to similar problems. JASON AND THE ARGONAUTS
functions so that they only need to add on services whenever they need. global dominance until the end of the 2nd More than 50 per cent of all scientists There are precedents for global
Very small RTOS systems like VXworks and a number of Linux-based RTOS
flavours can scale down to 32 k quite easily, but they tend to be quite world war and the spectacular implosion of globally are employed inside the US. If one is networks that already provide
unsuitable for sensor nodes. imperial pretensions in the post-war period to add the number of scientists employed by global oceanographic data:
Sensor nodes need to be able to process concurrent data bursts. Since most systems left many Europeans with a clear image of EU countries and organizations, the one of them is called
are still using a process model that is quite complex, and traditional multithreading global political and economic realities, but predominance becomes simply staggering. the Argo project
models need to be able to interrupt threads whenever necessary, it is vital that individual
data processing tasks are always running right through to the end. No interruption of little power to influence either. The nations Japan is turning into a major source of which
data processing tasks is allowed. This does not mean that tasks cannot run concurrently, of the Indian Ocean were mostly subject to scientific expertise, although logistical and consists
but it does mean that time constraints are not quite as important as in other RTOS the political will of others until well after cultural issues are inhibiting process.
applications.
1945. The late 20th century, however,
Sensor nodes also need to wake up and go back to sleep without draining the energy
reserves needed by the node. These are devices in the millimeter range and energy afforded countries from Iran to
density plus energy efficiency are extremely important. Microkernels are designed for
modularity, not for energy efficiency. Although portability is a major concern for TinyOS
Indonesia, with a
There might be few interesting data
- there are large numbers of “mote” architectures out there - modularity is a condition
for the design of TinyOS, not the major design goal. Microkernels come earlier in the one day and the next day, a storm or
evolution of kernel design. TinyOS is far more concerned with running the node while
avoiding energy waste.
Finally, microkernels tend to factor networking out of the kernel and provide separate
an earthquake
services to deal with networking and routing. TinyOS has to provide simple networking
support (“single-hop networking”) inside the kernel, since routing algorithms require
might deluge
more time and resources than the average node can deliver. 2k of RAM and, say, a 5
MHz CPU do not allow for that. observing
scientists with
interesting data
Predicting global warming and natural phenomena, volcanic tremors and shifts in the earth
beneath our feet, may depend on global networks of tiny sensors around the world’s oceans.
The extent to which the fate of this planet is in our hands is overwhelming, but the
complexities of our ecology are still defeating the resources and people researching it.
Frank Pohlmann investigates

Embedding Sensors in Global Politics


56 LinuxUser & Developer LinuxUser & Developer 57
Sensor networks Sensor networks

of more than 1600 robotic sensors resources and people researching it. cope with sudden increases in the data RAM might sound positively excessive. acquisition board combined with a another mote synchronized all data transmissions that were
floating 1 mile below sea level to collect The Argo project is just one example. stream. The configuration of networks Java for mobile platforms is not small motherboard with processor and coming from the motes and a stationary seismic detector a
data about water salinity and water What we are talking about here is a would have to change quickly if the comparable for architectural reasons: it radio running in standby mode 24 few miles away. The sensor nodes ran TinyOS of course and
temperature changes. In a few years, large number of subsurface floats taking need arises. If the sensors are mobile, a is not as heavily componentized as hours a day. data processing was accomplished using Java and Perl
3000 sensors will be stationed in the fairly simple measurements. Imagine greater concentration of sensors in one TinyOS, and neither does it include a Wireless sensor networks usually have routines.
world’s oceans. This is complemented having to take meaningful area might be regarded as necessary. If concurrent programming language: to be self-organizing, but when it This is just an experiment, although many other
by the laser altimeter satellite Jason 1 measurements in biotopes and around some of them were destroyed, the Java includes concurrent libraries comes to networks the size of the Argos applications can be thought of. The technology to collect
and the radar altimeter platform small lakes a few hundred yards across. wider mesh of sensor nodes should not expressed in APIs, not the language network, there is another element to be data all over the world exists and advances in the
TOPEX/Poseidon, which provides Now imagine having to accomplish create problems for data transmission, itself. It would also need an OS running taken into account: since wireless sensor miniaturization of networking and CPU technology have
surface topography data from almost all that very same task in several hundred like increased latency. The operating the Java virtual machine and the code, networks consisting of motes cannot made global environmental monitoring possible.
global oceans. Ocean currents change thousand locations globally. Collecting systems and programs running the conditions which the TinyOS transmit data across long distances,
the surface height and curvature of the and collating the data locally and sensors should be stable and follow soft architecture does not impose. they have to employ precisely the same RELATIONS BETWEEN NODES AND POLITICIANS
sea, which in turn can be measured to reliably and according to accepted real-time standards. TinyOS is written in a C like principles of mesh-networking and ad- There is another problem that the tsunami in December 2004
two-inch accuracy from a height of scientific standards is difficult and has There are a number of projects using language called nesC that provides hoc routing, but enable the same kind threw into sharp relief: even if the data are present and they
1300 km. Combined with temperature hardly begun. precisely such a technology. Wireless both a structured componentized of coverage for environmental have been evaluated, they have to be presented to decision
development model and a monitoring, and a less dense sensor makers in a comprehensible form. The Indian, Sri Lankan and

Oceanography and climatology are concurrency paradigm. Since


continuous data collection is the major
population. Argo nodes send data
directly to satellites, which given the
Indonesian governments were faced with the need to make
quick decisions; Sri Lanka and India had sufficient time to
not yet threatened by patent lawyers, purpose of this operating system, it is coverage and stability of the nodes warn their populations and cut down the number of dead
extremely important that there are makes a lot of sense, but if somewhat substantially. Unfortunately, even the best technology, as
although cloud patterns or whale facilities for a programmer to debug more local information is needed, software available for free under the GPL or as hardware for
his code for race conditions; the nesC requires too much investment. fairly little money are not sufficient to make those countries
songs may become subject to compiler would report them. The kind of coverage and quick data able to respond to national emergencies quickly. In the case
Programming in nesC also includes collection and information evaluation of the Indian Ocean tsunami some data was available, but the
copyright or patent law in the future primitives that allow controlling data necessary to prevent, e.g. earthquakes respective governments had few systems available to respond
collection from sensor nodes. from killing 100s of thousands is not quickly to the emergency in question.
Science and technology, owing to its quite available yet, but first attempts are In undergraduate essays it is considered vital to come up
NETWORK ZOOLOGY
institutional history, is still settled The sensor nodes, also known as
in the works.
TinyOS and various types of motes
with a conclusion that draws on various answers given to the
essay question. Embedded networking and indeed the
around the Atlantic and the Pacific “motes” when just the radio-board were developed largely at UC availability of sensor networks are political issues, not only due
underlying the sensor hardware is Berkeley. A small number of to the importance of the data they collect, but also due to their
referred to, are connected and companies tried to establish a number potential ubiquity. It is one thing to observe that surveillance
gradient data, a fairly accurate picture YES OR NO? IT IS RANDOM, SIR! sensor networks have been developed controlled via an RF network; a network of application areas like biological tools can become almost invisible. It is another to increase our
of the “weather” below the surface of One simple observation with regard to for a number of years and it seems that consisting of TinyOS-run sensor nodes habitat monitoring, building expertise concerning geological and biological systems.
the see can be gleaned. global climate and local ecology is the micro-sensor technologies and some or “motes” would need to be extremely monitoring in case of seismic events Pervasive computing is slowly becoming reality and sensor
Recent events in the Indian Ocean fact that with our methods of related networking products have left efficient in transmitting data. and patient monitoring in long-term networks are probably the most important part of it. It can save
and the brouhaha around global observation we are unlikely to be able the embrace of academia and entered The motes would not be able to store care facilities. By now, other 10s of thousands of lives, but it can also make Orwell’s 1984
warming - the latter being old news to predict the global climate. the industry. In some cases the much information in RAM, given that researchers working with TinyOS have look like political naivitÈ. And we shouldn’t forget that for the
which was common knowledge 25 Randomness and unpredictability are reception of sensor networks has been RAM size ranges from 0.5 k to 8 k are tried to simplify and extend TinyOS moment, many countries still do not have the resources to
years ago - suddenly brought global probably features inherent in large, colored by some very negative political common and secondary storage is and mote networks to apply them to instrument their coastlines and seabeds with sensors and data
early warning systems and the complex systems: there are no hidden perceptions: sensors the size of flies extremely limited. The so-called mica2 new applications. Harvard-based centers. Science and technology, owing to its institutional
evaluation of scientific data collected all variables whose elaboration would (“motes”) have military and civilian motes, reached a size of 7 mm a few researchers succeeded in testing history, is still settled around the Atlantic and the Pacific.
over the world to the forefront. Luckily, make the weather or ocean currents military applications whose potential years ago. Traditional TCP/IP motes for a network that was
oceanography and climatology are not fully transparent. have civil rights campaigners up in networking is not suitable, since wireless monitoring a volcano for seismic
yet threatened by patent lawyers,
although cloud patterns or whale songs
This also means that the collection of
ecological data on any scale has to
arms. The fears are justified and
legislation is going to be needed. But
mesh networks have to be routed ad
hoc and the communication overhead
events and possible eruptions. Key Links
Argo
may become subject to copyright or respond to rapid, seemingly random there are uses to which sensor networks would tax the limited power budget VOLCANO SURVEILLANCE www.argo.ucsd.edu/
patent law in the future. This is changes in the environment. There can be put that might ensure mankind’s motes have to run on. Traditional When volcanoes are about to erupt, www.primidi.com/2004/12/03.html
somewhat less frivolous than it sounds, might be few interesting data one day longevity, rather than stoking the fires addressing modes like Ipv6 would be they emit seismic tremors as well as TinyOS
since, as we all know, songs are being and the next day, a storm or an of global paranoia. suitable, if it wasn’t for the fact that infrasonic pulses. A sensor array tailored www.tinyos.net/
www.xbow.com/General_info/eventdetails.aspx?eid=54&localeid
copyrighted and to our knowledge, earthquake might deluge observing connection establishment and reliability to the work of volcanologists would =3&addressid=54
whale songs are unique to the whales Recent scientists with interesting data. HEY TINY are major issues for IP-based include two sensors detecting infrasonic
Sensor Networks
singing them. TinyOS is a GPLed operating system networking: it means that they energy waves and tremors. In this particular www.intel.com/research/exploratory/heterogeneous.htm
models have
Let there be no doubt that data SENSOR NETWORKS AND running the nodes of embedded expenditure for Ipv6 stacks would be case, the sensor array consisted of lternet.edu/technology/sensors/arrays.htm
relating to the global climate are in the
run for 945 SENSOR POLITICS wireless networks. The networking considered excessive and the need for infrasonic detectors, since other stations Medical Monitoring
public domain. The extent to which the Obviously, the sensors would have to components are not vital to the OS, routing servers imposes networking were able to pick up seismic tremors www.eecs.harvard.edu/~mdw/proj/vitaldust/
fate of this planet is in our hands is days on 2 AA be hardy enough to survive a battering which is built to run extremely small overhead that is impossible to maintain. already. Three mica2 motes collected Volcano Monitoring
overwhelming, but the complexities of by the elements and the networks processors whose ROM might not Recent models have run for 945 days the data, one transmitted the infrasonic www.eecs.harvard.edu/~werner/projects/volcano/
our ecology are still defeating the batteries linking the sensors have to be flexible to exceed 256K and for whom 128K of on 2 AA batteries. Not bad for a data data over a point-to-point link and

58 LinuxUser & Developer LinuxUser & Developer 59


Advertising Feature

UK Office: Telephone: 01295 756102

UK Office Fax: 01295 276133

Email: transtec.uk@transtec.co.uk

http://www.transtec.co.uk/

transtec 2500 Opteron Servers


The ideal entry to 64-bit computing
The transtec AG - THE EUROPEAN IT FACTORY
The right product, for the right price at the right time and the
right place. A simple message. A high demand. A challenge
we fulfil. That is our purpose. Our customers do not want off-
the-rack products. They expect tailor-made. That is why they
need a competent partner. Competence that transtec has
built up within two decades. And we work to strengthen it -
every day.

The newest software, the fastest processors, the largest


memory chips. The technology scouts from transtec track
down the latest inventions in the IT industry. In combination
with proven technology the engineers in Tuebingen develop
faster and more stable IT systems. In this way, the most
innovative technology flows directly into the computer
networks of the transtec customer

Only in their own production facilities transtec can fulfil


customers` requests. From thousands of variations and
combination possibilities, companies can select the
technology that suits exactly their needs. transtec builds the
equipment together precisely as ordered in the built-to-order
process. This makes many of transtec´s 45,000 annually
delivered computer systems unique.

The AMD Opteron™ is based on the AMD64 technology, which ● Tower, optional 19“ Rackmount,
makes it possible to have 64-bit technology on an x86 platform. Other ● 4 U One AMD Opteron™ 242 1.6 GHz processor
important innovations in Opteron™ processors include an integrated ● Max. 2x AMD Opteron™ 250 2.4 GHz
storage control module to lower the number bottlenecks in memory ● 1 GB registered ECC DDR-SDRAM (max. 16 GB)
and the HyperTransport technology. Opteron-based systems are ideal ● Onboard Dual 10/100/1000BASE-T
for use in database servers or for complex applications that need ● Hotswap 36 GB Ultra320 SCSI disk
more than 4 GB memory per process. Thanks to the complete 32-bit ● max. 10 Hotswap Ultra320 SCSI disks
compatibility of Opteron™ processors, these servers are also perfect
if an upgrade to 64-bit technology has already been planned, but not £1595.00
all of the applications are available yet in a 64-bit edition.

transtec-solutions in hardware
60 LinuxUser & Developer
regular column
Amazing Offer!
Swing digital

Poles apart
Worth
£64.95 FREE W
elcome to my new column, I’m Jason Kitcat and I’ll be your there are just over 8,400 Linux users

SUSE 9.2
host over the coming months as we explore Free Libre Open in Poland, a country of nearly 40
Source Software (FLOSS), e-government and life in the digital million people. While the project’s
lane. Enjoy the ride. methodology is hard to verify the
Just so you know that I am qualified to take you on this journey, I’ve results still give us an idea of the low
been tooling around with the Internet since around 1996. I’ve run a adoption Linux has had.

Professional
dial-in bulletin board system and started several tech companies. Since Before accepting Microsoft’s
2000 I’ve been building online communities at Swing Digital, a overwhelming dominance I
Brighton-based company I co-founded. We host all our communities wanted to double check the
on custom versions of Linux and Apache. market share figures. After much
So what’s the first stop on our journey? Poland as it happens. I spent digging I found some more
Jason Kitcat
With NEW some time in the south-eastern corner of Poland during the Christmas statistics. Ranking.pl (www.

subscriptions to GNU/
period and was curious to know how Linux is doing in this region.
Poles are bursting with pride in their country, rightfully so, still it has its
ranking.pl) shows that 98.8% of those accessing the Internet in
Poland are on Windows with only 1.1 per cent on all forms of Unix
fair share of challenges. In a country with high unemployment and low including Linux and MacOS X. 64.6 per cent of Polish Internet users
wages relative to the rest of the EU I was expecting FLOSS to play a are on Windows XP. Sadly these figures are probably, if anything,

Or any one of these major part in Polish digital life.


I was very wrong. I didn’t see a single copy of Linux running in any
underestimating the Windows share as Linux and MacOS X users are
far more likely to go online than the average user, especially those

O’Reilly books! of the offices or homes I visited, everyone had Windows. Chatting with
Marek Ogrodnik, an employee at a major technology retailer, I learnt
stuck with Windows 3.1 or 95.
Historically a significant portion of the copies of Windows and
GET THE AWARD WINNING SUSE LINUX
9.2 PROFESSIONAL INCLUDING THE Never miss an issue!
The average man in the street,
COVERDISCS
LINUX KERNEL 2.6.8, KDE 3.3 AND
GNOME 2.6 - AVAILABLE ON 5 CDS AND
2 DVDS PLUS EXTENSIVE
DOCUMENTATION. NEWCOMERS AND
Every LinuxUser & Developer CD is
guaranteed to be packed with hundreds of
or computer shop for that matter,
ADVANCED USERS WILL FIND
PROFESSIONAL ASSISTANCE AND
the latest and greatest Free Software
projects, including many exclusive LinuxUser
is still ignorant of the benefits Linux could offer
INSTRUCTIONS FOR ALL KINDS OF & Developer covermounts

PRIORITY
ISSUES. THE SUSE LINUX 9.2 that he reckoned that Windows has 99% market-share in Poland. associated software have been shared and not purchased legally.
PROFESSIONAL PACKAGE NOW Piled up next to Marek as we chatted were boxes and boxes of However, since a very strict government crackdown on piracy three
INCLUDES THE PORTED 64-BIT Mandrake Linux on DVD for £15. It wasn’t selling, but OEM versions years ago the majority of software is grudgingly purchased. Coming
APPLICATIONS FOR USERS WHO EMPLOY
THE LATEST TECHNOLOGY OF INTEL AND
AMD 64-BIT PROCESSORS AS WELL AS
DELIVERY
Receive your copy direct to your place or
of Windows XP for £65 were. Consider that for those with jobs in
Poland an excellent salary is £300 per month. With Windows XP
Home Upgrade selling for £190, Office going for £360 and the
from a Communist era where scarcity forced ingenuity, Poland is
culturally ripe for the FLOSS approach to digital life. Unfortunately
Windows got there first and it’s going to be very tough overcoming
32-BIT BINARIES. work or home before it reaches the
newsstands! academic license for Office a cheeky £70 I couldn’t understand why Microsoft’s huge installed base.
Linux was more popular. All is not lost though‚ - As in many other countries, the government
Stepping over discarded flyers for Mandrake I asked Marek why can use procurement policies to force competition. The Polish
Please send me the next 12 issues of LinuxUser and Developer and my copy of Suse 9.2 Professional for £59.99 (1 year) or £89.99 (2 years)
Linux wasn’t more popular. His answer was similar to those I often Ministry of Finance is using Linux for some backend functions. This
Please send me the next 12 issues of LinuxUser and Developer (rest of the world subscription offer) hear back in the UK: Linux is very hard to use, he couldn’t get it to move gained considerable publicity and is probably only the first of
even install on the showroom computer - when it does work you many gains for Linux in the Polish government. On the other hand
MR/MRS/MISS FIRST NAME ........................................................................... Send to; can’t play games, watch movies or buy software the way you can government has also been unhelpful, in at least one case commercial
Subscriptions Dept
SURNAME...................................................................................................... with Windows. The network effect is in full force in Poland - Because installations of Debian Linux were regarded by the local tax office as
LinuxUser and Developer
everyone else has Windows, you are better off having Windows. ‘gifts’ so a 30 per cent tax was applied on the assumption that
ADDRESS ...................................................................................................... 5 Broadhey, Romily
Poland has, like most countries, a technical elite who can and do Debian cost as much as Windows. Oops.
Stockport, Cheshire SK6 4NL
ignore Microsoft-shaped bandwagons, and inevitably they are playing While Windows’ dominance in markets such as Poland can be
..................................................................................................................... Or call the subscriptions hotline on;
with Linux. PLD is the Polish Linux Distribution (www.pld.org.pl) depressing, it isn’t the whole picture. The key thing to remember is
..................................................................................................................... 0161 4303423 made by Poles. Another Polish distribution is Aurox (www.aurox.org). that whether we look to Eastern Europe, Central America or India,
There is also a Polish Linux User Group (www.linux.org.pl). It’s a most people don’t have a computer at all. So we don’t need to wean
POSTCODE.......................................TELEPHONE............................................ small group, but they seem to have influence. Poland caused a storm them off Windows, we need to reach out to them and explain why
Or subscribe online at and ingratiated themselves to the FLOSS community by stopping the EU FLOSS can help to make our digital lives more fair and open.
EMAIL ...........................................................................................................
www.linuxuser.co.uk Software Patent Directive in its tracks. This is the sign of a well informed
PLEASE BEGIN MY SUBSCRIPTION WITH ISSUE NUMBER................................. Outside the UK - If you live outside of the UK, technorati but unfortunately the average man in the street, or computer
we regret to say that the free software offer
doesn’t apply. However, you can subscribe for shop for that matter, is still ignorant of the benefits Linux could offer. Jason Kitcat (jason@swingdigital.com) is Managing Director of online
I ENCLOSE A CHEQUE PAYABLE TO LINUXUSER & DEVELOPER FOR.................. £74.99* if you live within Europe and £89.99* if
you live elsewhere, including the US and According to the Linux Counter Project (counter.li.org/bycountry/PL.php) community consultancy, Swing Digital
Australia. Both prices include P&P.
ALTERNATIVELY PLEASE BILL ME FOR............................................................ *Charged at local currency exchange rate.

LinuxUser & Developer 63


Hacking the kernel
Hacking the Kernel Hacking the kernel

complex remote kgdb hacking - we’ll get to that after we have dealt
Jon Masters provides his regular look at Linux Kernel development with the basics and the merits for using debuggers at all.
Kernel debuggers, like all software debuggers, allow us to peek into
the internals of a running system and discern some specific

Taking
information about the way in which it is operating at run time. This
helps us to track down difficult to locate bugs but also provides a
service as a mechanism for understanding the correct normal
operation of a real system. In last month’s column, we devoted a
small section to using UML but the time is right now to explore the
Using gdb could
the reins.
workings of the kernel in more detail using a combination of available
tools. The first of these is the venerable GNU Debugger, gdb. gdb
represents one of the most popular and widely used GNU tools after
the GNU Compiler Collection (gcc) and GNU C Library (glibc). It is
form the subject
certainly one of the most ubiquitous debuggers in widespread use matter of a rather

Tracing
today and is well understood by many programmers.
Using gdb could form the subject matter of a rather large book (it
does), and also deviate us from our chosen topic, so a thorough
large book (it does)
exploration of the available features is left up to the reader. It is
assumed that the reader has a working environment with appropriate kernel, fire up gdb with the appropriate kernel

the source
development tools installed, and that the gdb documentation has image and core file:
been consulted where necessary. gdb is typically used to debug a
standalone program or running process, but it can also utilise a jcm@perihelion:~$ sudo gdb /lib/
memory image contained within a “core dump” - produced as a side modules/2.6.10/build/vmlinux /proc/kcore
effect of eg. a “segmentation fault”, during which this file is dumped GNU gdb 6.1-debian
if the user has not configured a system not so to do. The Linux kernel Copyright 2004 Free Software Foundation,
provides a special procfs entry in /proc/kcore, which is a dynamically Inc.
Debugging the Linux kernel (continued) generated “core” file with a difference. By hooking gdb up to use this GDB is free software, covered by the GNU
file, we can peek at the state of the running system. General Public License, and you are

K
ernel Hacking is a regular feature on the inner workings of ways to make the system crash horribly. Debugging provides a We won’t be able to change anything through this initial interface, Waiting for gdb welcome to change it and/or distribute
the Linux kernel. Each article is split into several sections, mechanism for tracing the execution of a running Linux system and but we can look at certain kernel counters and check on its general to connect to a copies of it under certain conditions.
which vary in both technical detail as well as intended watching as each line of kernel source results in a a series of mental wellbeing to a certain extent. To begin debugging a live remote target Type “show copying” to see the conditions.
audience, although the goal is to provide an accessible alternative to operations which form the cohesive whole. Let’s have some fun with There is absolutely no warranty for GDB.
existing introductory material. In this issue, we continue our gdb, and kgdb through in a little debugging of Linux on Fedora Core Type “show warranty” for details.
investigations with various kernel debugging techniques in 3, within a VMware machine. To follow the instructions in this next
preparation for building a python based GUI kernel memory browser section, readers will benefit from having a kernel image built with Core was generated by `auto BOOT_
debug symbols - see the IMAGE=linux ro root=2103’.
“Kernel Debugging” #0 0x00000000 in ?? ()
Debugging isn’t just a mechanism for fixing bugs in submenu under “Kernel (gdb)
kernel drivers and discovering new and spectacular Hacking”, when building a
kernel from the source. Note the use of sudo to run the gdb
ways to make the system crash horribly command as the root user. Those without sudo
appropriately installed and configured can use a
in the coming issues, investigate some of the more recent changes to USING GDB FOR FUN AND PROFIT root shell instead. Also note that gdb was passed
the kernel and check out the latest news from the various mailing In the last issue, readers were briefly introduced to the concept of the full kernel vmlinux image from the top level
lists. Kernel security is increasingly becoming an issue of interest as kernel debugging using the UML (User Mode Linux) as a mechanism of the kernel source directory. This is the full
numerous new exploits have recently surfaced, we’ll look at what’s for running test kernels within a virtual machine on a regular desktop kernel binary prior to any stripping and with full
being done to tackle these kinds of kinks in the new development PC. This time around, we will look at using the GNU command line debugging symbols already built in. The kernel
process. Your feedback is most welcome, especially any feature debugger, gdb to peak at the running kernel on a regular Linux was booted with the parameters shown in the
suggestions - drop us a line at letters@linuxuser.co.uk. machine and then consider the options for interactive real time kernel last output lines above. It is possible to
Learning about the kernel is almost as important as writing code debugging. None of these options require a second PC since it’s interrogate the state of various kernel variables
itself, sometimes more so. Debugging isn’t just a mechanism for possible to use a virtual machine PC emulator such as VMware (even from this prompt, but it is not possible to change
fixing bugs in kernel drivers and discovering new and spectacular an evaluation version if just for a single test run) for some of the more the kernel state - so calling kernel functions is out

64 LinuxUser & Developer LinuxUser & Developer 65


Hacking the kernel
Hacking the Kernel Hacking the kernel

Debugging the kernel init process Kernel Personalities


with the aid of a remote gdb
client. The virtual machine
running within VMware is
completely controlled by a remote Linux wouldn’t be nearly as amounts of wasted code and be an interesting talk on updated for kernels up to
gdb, which can issue commands fun and interesting as it is, resources to achieve a the new development and including 2.6.10. This
to set breakpoints and modify the were it not for the efforts relatively simple task. Inotify process - which, it has to be edition is published by his
behaviour of the target. of a select group of gifted instead uses a new device said, he doesn’t seem all new employer, Novell, and
hackers who busily code node, through which too fond of. now includes additional
away in the wee hours of programs can communicate chapters on “Getting
the morning, powered with the kernel to request As effort is underway to bring Started with the Kernel”,
solely by adrenaline and notifications of events on a out the 2.6.11 kernel, various “Modules”, and also the
unholy amounts of caffeine file - especially through a -rc prereleases have started to Kernel Events layer
- well some of them, at regular poll or select syscall become available. Kernel “kobjects and sysfs” that
least. The LKML (Linux within its main loop. releases can be tracked most Robert has helped work on.
Kernel Mailing List) is a hive effectively by maintaining a All in all, this promises to
of activity on a daily basis. Perhaps one of the most daily update of Linus’ be a very interesting read
Recent discussions have disturbing issues with BitKeeper tree. The graphical and worthy of a place on
included a new “inotify” kernel development at the “revtool” allows one to track the reader’s bookshelf -
mechanism in 2.6.10, a moment is the handling of a tree of changes from one unfortunately this title is
reworking of the internal critical security issues. We release of the kernel to the not yet available in electronic
representations of pipes, have recently seen several next - and to see a complete form and has yet to become
and a treatise on “Getting remotely exploitable changelog history for widely available in European
Started With Kernel defects in the kernel which arbitrary points along the countries (we’ll do a review
Hacking” in which Jonathan could be used by malicious time line. Readers would be just as soon as we can get
for the moment. Print the value of jiffies: allows us to remotely debug a kernel at the source level rather Corbet reminded readers crackers to gain well advised to perform a hold of it!). In the words of
than interrupt a running machine and issue limited diagnostic that the new edition of unauthorised access or to daily pull of Linus’s tree and the books’ author: “You
(gdb) print jiffies commands. Kgdb was the original creation of SGI hackers but is Linux Device Drivers will be launch a Denial of Service watch as new patches are should buy a copy or two
$1 = 51656788 now a sourceforge project in its own right. It comes in the form of out possibly during Boston (DoS) attack. Fortunately, released unto the and carry them with you
various patches which must be applied to the kernel sources in LinuxWorld. fixes for such problems are unsuspecting masses. Consult everywhere you go’”.
The kernel maintains an internal counter, known as the jiffy, which documented order. The kernel boot command line must be altered typically a mere few lines of http://linux.bkbits.net/,
represents the number of timer ticks (timer interrupts) which have (in /boot/grub/menu.lst or /etc/lilo.conf, depending upon your Amongst the various mailing code and quickly make it in Documentation/BK-usage The 2005 FOSDEM (Free and
taken place since the system was booted. It’s what effectively defines platform and bootloader) to include a serial port for kgdb to listen list posts came a replacement to vendor updates - but as directory within the kernel Open Source Developers
the “uptime”. We can use this mechanism to interrogate any global on for a remote gdb. to “dnotify”. Dnotify has development is taking place source itself, and the European Meeting) takes
kernel variables but must be aware of gdb’s internal caching, which In the example case, kernel 2.6.7 has been patched using the historically represented a bit in the mainstream kernel accompanying website to this place on the weekend of
may result in a repeated output of the above value of jiffies if asked kgdb sources and built to run on an AMD Athlon. The author of a hack job solution to the source tree, these patches series for more specific usage February 26 and 27. Your
for the same value immediately afterwards. gdb supports full tab chose to use a VMware virtual machine rather than a real physical problem of tracking changes can be delayed by several information. author will be there to
completion, and in combination with a Linux source code cross PC to prove the point that even a real machine is not required for to directories. Rather than days getting in to the stable witness the Kernel and
reference such as LXR (see resources) allows for limited, but entirely our experimentation purposes. VMware is an example of an Intel having a program source. For example, as of Robert Love released a new Embedded Linux fora, as well
safe, perusal of the kernel state. We’ll build on this example in the Architecture machine emulator which in this case runs Fedora Core continuously poll a directory this writing, there remains edition of “Linux Kernel as the general talks held at
next issue - to create a graphical browser of kernel state information. 3 as if it were standalone. The modifed kernel was placed in /boot/ for changes, it is possible to a critical exploit in the Development”, revised and this event.
vmlinuz-2.6.7 and /boot/grub/menu.lst was modified to register to receive a signal current stable kernel which
KGDB - TAKING THE REINS accommodate the new kernel image. An entry of the following when such events occur. has not yet resulted in a
It’s all very well using gdb to pick at the running kernel on a form was added to the grub boot menu: Unfortunately, dnotify public release of a fixed
desktop machine, but how does that help us in our quest to learn doesn’t adequately solve the stable kernel. At the
more about the innards of Linux? The answer comes in the form of title Kernel Development problem of watching FOSDEM in Brussels at the
patches to the kernel source which add remote debugging root (hd0,0) individual files for changes end of February, Alan Cox
capabilities. Using a second PC (or a VMware virtual machine in kernel /boot/vmlinuz-2.6.7 ro root=/dev/hda1 kgdbwait and can result in large will give what promises to
this case) one can remotely take control of the execution of each kgdb8250=0,115200
line of the kernel source. There are two primary kernel debuggers
used in such cases: kgb and kgdb. We’ll focus on kgdb, since it This instructs kgdb to halt the kernel as early as possible and wait

66 LinuxUser & Developer LinuxUser & Developer 67


Hacking the kernel
LAMP LAMP

for a remote connection from a gdb client via kernel source tree without a radical change of heart on the part of One of the major advantages of a relational database is the ability to
the first serial port (ttyS0). Now, another Linus Torvalds. Linus believes debuggers do more harm than
machine connected to this serial line can take good, altering the characteristic performance of the system under join more than one table when executing queries. In this month’s article David Tansley looks at
remote control thusly: test. He’s right, but us mere mortals exercising appropriate care
and due attention probably benefit more than we lose out. joins, using MySQL with a touch of PHP to show how it can work on a web page
(gdb) target remote /dev/ttyp0 [VMware no longer supports direct access to the virtual
Remote debugging using /dev/ttyp0 machine’s serial port in newer versions. It is now necessary to use a
breakpoint () at kernel/kgdb.c:1212 wrapper (e.g. “vmware-p2s”) in combination with the “named

PHP and Joins


1212 atomic_set(&kgdb_setting_ pipe” option in the VMware configuration to connect VMware to a
breakpoint, 0); spare pseudo terminal (e.g. /dev/ptyp0) on the reader’s
computer. This is quite straightforward - see Resources box.]
It is now possible to control the kernel as if it
were any other program being debugged. For
example, in the following sequence we elect to
insert a few breakpoints in the boot sequence,
stopping execution in init/main.c at “prepare_
Linus believes debuggers do
more harm than good,
W
namespace” (which is near to the end of the hile there are plenty of in-depth resources available elsewhere customers table; this forms the relationship between the two tables
boot sequence) and to then view the console on relational database design, the LAMP developer requires (customer.customer_id to orders.customer_id). This allows us to know
ringbuffer (the buffer to which printk saves its altering the characteristic at least a basic grasp of the subject. A true relational database which customer has ordered what, and the link back to the customers
output before it is sent to the console) and a design provides the minimum of repeated information. If changes are name is the customer_id.
backtrace of functions called along the way.: performance of the system required to table attributes, then the design should allow for the

(gdb) break prepare_namespace under test, but us mere database to scale gracefully with the additional data load. Breaking
data into many tables allows for more manageable storage of the
Listing 2. Orders Table
product_id order_id customer_id
Breakpoint 6 at 0xc05511f6: file init/do_
mounts.c, line 391.
mortals probably benefit information within the database.
To be able to select related data from these tables, we must be able
1000
1012
Karate GI 1
Brown Belt 3
(gdb) c
Continuing.
more than we lose out to select from more than one table in a single SQL statement. In other
words, we must be able to join these tables in order to extract the
1014
1016
Mouth Guard
Mitts
3
5
Breakpoint 6, prepare_namespace () at init/ data and turn it into useful information. The actual join of the tables
do_mounts.c:391 goes on behind the scenes, but to inform MySQL that we wish to TABLE CREATION
391 if (saved_root_name[0]) { extract from more than one table a particular SQL syntax is required. To create the database and the customer table, the following sql is used:
(gdb) p log_buf
$3 = 0xc0588aa0 “<4>Linux version 2.6.7 CREATING THE TABLES [dxtans@bumper dxtans]$ mysql -u root
(jcm@perihelion) (gcc version 3.3.5 (Debian To demonstrate how joins can be accomplished we first need to mysql> CREATE DATABASE customer_ord;
1:3.3.5-5)) #1 Tue Jan 1 00:00:00 GMT create two tables, where the first table has a relationship to the mysql> USE customer_ord;

Resources
1970\n<6>BIOS-provided physical RAM second table. In my very simplified example tables we have a mysql> CREATE TABLE customer (
map:\n<4> BIOS-e820: “, ‘0’ <repeats 16 customers table and an orders table. The customer table (see Listing -> full_name varchar(45) NOT NULL default ‘’,
times>, “ - “, ‘0’ <repeats 11 times>, “9f800 1) contains a unique number for each customer (customer_id) which -> customer_id int(10) unsigned NOT NULL auto_increment,
kgdb
(usa”... kgdb.sourceforge.net is the primary key for that table. It also contains the customer’s full -> PRIMARY KEY (customer_id));
(gdb) bt name.
The website accompanying this series
#0 prepare_namespace () at init/do_ www.jonmasters.org/kernel To create the orders table the following sql is provided:
mounts.c:391 Listing 1. Customer Table
Kernel newbies
#1 0xc01006fd in init (unused=0x0) at init/ www.kernelnewbies.org customer_id full_name mysql> CREATE TABLE orders (
main.c:638 wiki.kernelnewbies.org 1 Peter Jones -> product_id int(10) unsigned NOT NULL default ‘0’,
#kernelnewbies IRC discussion channel
#2 0xc01032b1 in kernel_thread_helper () 2 Lucy Bling -> order_id varchar(45) NOT NULL default ‘’,
at arch/i386/kernel/process.c:229 Tracking the Linux kernel mailing lists 3 David Grass -> customer_id int(10) unsigned NOT NULL default ‘0’,
www.kerneltraffic.org
(gdb) 4 Pauline Neave -> PRIMARY KEY (product_id));
Archives of the lkml 5 Louise Christine
www.lkml.org
This SGI tool is both extremely powerful and The next task is to insert some values into the tables. For the customer
available for several architectures at this point. Linux Weekly News features Kernel Page The orders table (see Listing 2), contains a product_id, and this is the table I have taken the long route and inserted them one at a time like so:
www.lwn.net
While it is technically impressive and certainly primary key for the table. A product name is also provided as well as
of wide use, it is unlikely that tools such as Linux Kernel Cross Reference the customer_id. You may have noticed that the customer_id in the mysql> insert into customer (full_name,customer_id) values (‘Peter
www.lxr.linux.no
kgdb will be integrated in to the mainline orders table contains some of the values from the customer_id in the Jones’,’’);

68 LinuxUser & Developer LinuxUser & Developer 69


LAMP
LAMP LAMP

By the time I got to the orders table I was bored with entering data In the SQL used here each table name is comma separated. This mysql> select customer.full_name, orders.order_id customer records have been read in from the customers table to
manually, and created a file (orders_in.txt) to import the orders rows. informs MySQL that we will be extracting from two tables, and this is -> from customer populate the pull down menu. See Listing 4. cust_select.php.
The file was a <tab> separated field for each row, like so: therefore a join query. Notice that there are 20 rows returned; though -> inner join orders
this is a join, it does not provide any really useful information. Using a -> on customer.customer_id=orders.customer_id; LISTING 3. CUST_INC.PHP
1000 Karate GI 1 WHERE clause we can gather better information in our decision making
1012 Brown Belt 3 environment. Let’s extract all customers that have ordered a product: Notice that ‘inner join’ is now used to indicate we are performing an <?php
1014 Mouth Guard 3 inner join in the query and the WHERE is replaced by the ON word. # cust_inc.php
1016 Mitts 5 mysql> select customer.full_name, orders.order_id Two other joins are the left and right join; The left join will extract
-> from customer, orders all rows from the customer table, even if there are rows in ‘customer’ $SERVER=”localhost”;
Then after making sure we are back at the database prompt, run the -> where customer.customer_id=orders.customer_id; that do not have a match in the orders table. All will become clear $DB=”customer_ord”;
following command: with a query example. Notice in the following query we use a ‘left $USER=”root”;

+------------------+-------------+ In the above SQL, join’, and more rows are returned this time because we have $CUST_TABLE=”customer”;
mysql> load data local infile “orders_in.txt” into table orders; | full_name | order_id | notice that I have customers ‘Lucy Bling’ and ‘Pauline Neave’ who have not ordered any
Query OK, 4 rows affected (0.00 sec) +------------------+-------------+ specified the columns items. This is a non-match between the two tables, but because we # holds initial connection and changing to working database
| Peter Jones | Karate GI |
Records: 4 Deleted: 0 Skipped: 0 Warnings: 0 I want extracted by are using a left join these results will get printed with a NULL value: $connection=mysql_connect($SERVER,$USER);
| David Grass | Brown Belt |
| David Grass | Mouth Guard | using their tablename.
Both tables should now be loaded up and ready to go. Look at the | Louise Christine | Mitts | column_name. First mysql> select customer.full_name, orders.order_id if (!$connection) {
tables with these commands: +------------------+-------------+ we select the ‘full_ -> from customer echo “Could not connect to MySQL server!”;
name’ from the -> left join orders exit;
mysql> select * from customer; customer table as well as the ‘order_id’ from the orders table. We -> on customer.customer_id=orders.customer_id; }
mysql> select * from orders; then filter it through a WHERE condition, which equates to “if the
‘customer_id’ from the customers table matches the ‘customer_id’ +------------------+-------------+ The right join behaves $db=mysql_select_db($DB,$connection);
JOINING from the orders table, then print the results.” | full_name | order_id | similarly to the left if (!$db) {
+------------------+-------------+
A join will create a virtual table, multiplying the tables together. We could also see who has ordered a pair of mitts from our orders join except that we echo “Could not change into the database $DB”;
| Peter Jones | Karate GI |
Then a WHERE clause containing a condition is used to filter out the database, by appending AND to the query. This means “only print | Lucy Bling | NULL | compare from the exit;
unwanted rows for the query. Please note that we have five rows in results if both sides of the condition are true.” As we only want to | David Grass | Brown Belt | second table (orders) }
the customer table and four rows in the orders table. The most basic print the name (full_name) of the customer this time, we only need | David Grass | Mouth Guard | first. ?>
| Pauline Neave | NULL |
join is the cross join, which is fairly useless in its most basic form: to select customer.full_name from the customers table: Practically any
| Louise Christine | Mitts |
+------------------+-------------+ query made by a user LISTING 4. CUST_SELECT.PHP
mysql> select * from customer, orders; mysql> select customer.full_name can be extracted
-> from customer, orders using joins. However, I <HTML>
-> where customer.customer_id=orders.customer_id have just covered the most basic joins and queries; there is a lot more <BODY>
+-------------+------------------+------------+-------------+-------------+ -> and orders.order_id=”Mitts”; to it. Extracting data from tables into a client application is not much <CENTER><B> Select A Customer To View Their Order(s)</B></CENTER>
| customer_id | full_name | product_id | order_id | customer_id | fun. Since this is a LAMP tutorial it would be better to web enable our
+-------------+------------------+------------+-------------+-------------+
| 1 | Peter Jones | 1000 | Karate GI | 1 |
database, and what better tool to do this with than PHP? <?php
| 2 | Lucy Bling | 1000 | Karate GI | 1 | +------------------+ So far we have only # cust_select.php
| 3 | David Grass | 1000 | Karate GI | 1 | | full_name | used the WHERE QUERYING WITH PHP # include file
| 4 | Pauline Neave | 1000 | Karate GI | 1 | +------------------+ join method; this Creating a rudimentary reporting interface is fairly straightforward. I include (“cust_inc.php”);
| 5 | Louise Christine | 1000 | Karate GI | 1 | | Louise Christine |
| 1 | Peter Jones | 1012 | Brown Belt | 3 | +------------------+
method was will present a drop down menu form that contains the customer
| 2 | Lucy Bling | 1012 | Brown Belt | 3 | pushed more names. These customer names will be pulled from the customer table, $sql=”SELECT full_name,customer_id FROM $CUST_TABLE”;
| 3 | David Grass | 1012 | Brown Belt | 3 | heavily in the early and the user will then select a name for the report to be generated.
| 4 | Pauline Neave | 1012 | Brown Belt | 3 |
MySQL documentation. Now the documentation Of course in our example it will only contain one or two names, but $mysql_result=mysql_query($sql,$connection);
| 5 | Louise Christine | 1012 | Brown Belt | 3 |
| 1 | Peter Jones | 1014 | Mouth Guard | 3 | actually uses the word ‘join’, and it is sometimes the concept will be the same no matter how many rows the query $num_rows=mysql_num_rows($mysql_result);
| 2 | Lucy Bling | 1014 | Mouth Guard | 3 | called the ‘join on’ method. One common type of join returns. Running a query against the orders table will then generate
| 3 | David Grass | 1014 | Mouth Guard | 3 | is the inner join, or equi-join. Like our earlier example, the report. The report will display orders for that given customer. if ( $num_rows == 0 ) {
| 4 | Pauline Neave | 1014 | Mouth Guard | 3 |
this join is based on extracting data based on PHP for common MySQL tasks, like connecting to the database and echo “Sorry there is no information”;
| 5 | Louise Christine | 1014 | Mouth Guard | 3 |
| 1 | Peter Jones | 1016 | Mitts | 5 | common or equivalent matching columns. If there is a checking for connection errors, is reusable code so it is put into an } else {
| 2 | Lucy Bling | 1016 | Mitts | 5 | match then results are printed; it will not print any include file which can be called from other PHP scripts. Listing 3. # we have records
| 3 | David Grass | 1016 | Mitts | 5 | results from a non-match. cust_inc.php contains that code. One thing we will need to give to echo “<FORM METHOD=GET ACTION=\”cust_view.php\”>”;
| 4 | Pauline Neave | 1016 | Mitts | 5 |
So to print all customers that have ordered a the user is the choice of whether they want to select an individual echo “Please select a Customer<BR>”;
| 5 | Louise Christine | 1016 | Mitts | 5 |
+-------------+------------------+------------+-------------+-------------+ product, as we did earlier, we could use: customer or see all orders for all customers. This is easily echo “<SELECT NAME=\”customer_id\”>”;
accomplished by adding another OPTION VALUE called ‘all’, after the while ($row=mysql_fetch_array($mysql_result))

70 LinuxUser & Developer LinuxUser & Developer 71


LAMP
regular column
Strange anomalies of copyright law (Part 2)
Freestyle

Clare’s enclosure
T
he poet John Clare died in the Northampton General Lunatic July, 2000, Whitaker made a
{ { Asylum in 1864. During his lifetime he was known as ‘the “provisional bargain”,
$full_name=$row[“full_name”]; $mysql_result=mysql_query($sql_all,$connection); peasant poet’, though he was not, strictly speaking, a peasant, presumably verbal, with the
$customer_id=$row[“customer_id”]; $num_rows=mysql_num_rows($mysql_result); and lived in an era of social upheaval, enclosures and landless labour, dying John Taylor in May 1864,
# display results } else { when a landless labourer had even less rights than a peasant. to pay Clare’s widow, who
echo “<OPTION VALUE=\”$customer_id\”>$full_name”; $mysql_result=mysql_query($sql_single,$connection); Clare was from a rural labouring family, and had little education, could neither read nor write,
} $num_rows=mysql_num_rows($mysql_result); but is now recognised as the greatest English poet of nature, as £10 a year for Clare’s
echo “<OPTION VALUE=\”all\”>All Customers”; } important as his contemporaries, Keats, Byron and Shelley, of whom manuscripts and publication
echo “</SELECT>”; everybody has heard. As the critic Geoffrey Grigson wrote as long ago rights. Later the same year he
} # end else # apologise if there’s nothing to show as 1949, “Clare has gradually been transformed from ‘peasant poet’ signed an agreement with
Richard Hillesley
echo “<BR><BR>”; if ( $num_rows == 0 ) { into poet, from cottage rushlight into what indeed he is, a star of Clare’s widow and her children
echo “<INPUT TYPE=\”SUBMIT\” VALUE=\”See Order\”>”; echo “Sorry there is no information”; considerable and most unique coruscation.” for the transfer of their rights to
echo “<BR><BR><INPUT TYPE=\”RESET\” VALUE=\”Clear selection\”>”; } else { Clare ignored the rules of punctuation and spelling, probably as a Clare’s copyrights. This agreement, discovered in the archive of the
mysql_close($connection); # we have results consequence of the slightness of his education, and wrote: “I am Whitaker publishing house in 1932, was destroyed with the rest of the
?> echo “<TABLE ALIGN=\”CENTER\” BORDER=\”8\” WIDTH=\”40%\”>”; gennerally understood tho I do not use that awkward squad of archive during the London blitz eight years later. Whitaker’s edition of
echo “<TR><TH>Full Name</TH><TH> Item(s) Ordered</TH></TR>”; pointings called commas colons semicolons etc and for the very Clare never appeared, and he transferred the bulk of the surviving
Once the user has selected their customer to view, or ‘all’ to see reason that altho they are drilled hourly daily and weekly by every manuscripts (and, some presumed, the copyright) to the care of the
all customers orders, the submit button will send them onto while ($row=mysql_fetch_array($mysql_result)) boarding school Miss who pretends to gossip in correspondence they Peterborough Museum Society before his death in 1895. No edition of
cust_view.php, see Listing 5. A check is initially carried out to { do not know their proper exercise for they even set grammarians at Clare published between Whitaker’s death and Robinson’s purchase of
determine if the user has loaded this page directly without first $full_name=$row[“full_name”]; loggerheads and no one can assign them their proper places for give “all rights whatsoever possessed by the company in the published and
going to cust_select.php - if this is the case, then a hyperlink $order_id=$row[“order_id”]; each a sentence to point and both shall point it differently.” The unpublished works of John Clare” in 1965, acknowledged any
points them back. This check is carried out by determining if the
parsed variable from the cust_select.php form, customer_id has a # display results The purgatorial hell and French bastile of English liberty,
where harmless people are trapped
value. If not then we know no selection has taken place. Figure 1. echo “<TR><TD><CENTER>$full_name</CENTER></
customer_select, shows the initial web page, where the menu is TD><TD><CENTER>$order_id</CENTER></TD></TR>”;
populated with the customer details. The screen shot below }
shows the result of a query. }
and tortured until they die
LISTING 5. CUST_VIEW.PHP # end the script fashion for removing punctuation from modern poetry began with copyright holder.
mysql_close($connection); the French poets, Apollinaire and Cendrars, in the early decades of Under the 1842 Copyright Act, an author, or after his death his
<HTML> ?> the twentieth century, but Clare had his own untutored, and personal representative, retained perpetual control over his work as
<BODY> strangely modern, take on the rhythms and nuances of poetry and long as it remained unpublished. This clause remained in force until it
<?php </TABLE> punctuation. Clare’s punctuation, and his feelings about it, are at the was finally replaced in the 1988 Act with a finite, 50-year term of
# cust_view.php <BR><A HREF=”cust_select.php”>Back</A> heart of the academic disputes that surround his work. protection (made potentially extendable by a further 25 years in a
# did the user load this page directly ? </BODY> Clare’s first book sold well by the standards of his time, and outsold 1996 Act).
if (empty( $_GET[‘customer_id’] )) { </HTML> Keats by some margin, but his relative commercial success was short- Although Robinson has contributed much to Clare scholarship over
echo “You need to make a selection first”; lived, and he depended for his income on patrons, who sometimes the last half-century, his claims to the ownership of Clare’s legacy has
echo “<A HREF=\”cust_select.php\”> Customer Menu</A>”; over-edited and censored his material. Much of his better poetry was caused much controversy. According to Goodridge: Robinson “has
exit; written during the 23 years he spent in the lunatic asylum - “the enforced this claim, demanding acknowledgement and often
} purgatorial hell and French bastile of English liberty, where harmless payment from anyone who wishes to publish Clare material. In the
people are trapped and tortured until they die”. Most of his work, view of Tim Chilcott, the effect has been ‘the impoverishment of
# include file some 2700 poems, remained unpublished during his lifetime, and at editorial debate compared with other Romantic writers, the absence
include (“cust_inc.php”); the time of his death he was all but forgotten, despite the best efforts of challenging alternative views, the deadening hand of the
of his publisher, John Taylor. authorised definitive version.’”
# this query is used if user selects a customer name But due to a quirk in English copyright law, 140 years after Clare’s A core concern of Clare’s poetry was the disruption to the
$sql_single=”select customer.full_name, orders.order_id from customer death, the ownership of the copyright to Clare’s unpublished writings traditional patterns of life caused by the enclosures of the English
inner join orders on customer.customer_id=orders.customer_id AND is still claimed as the sole property of one individual, Professor Eric commons. Like Gerard Winstanley, Clare believed the earth to be a
customer.customer_id=’{$_GET[‘customer_id’]}’”; Robinson, who purchased the “rights” for £1 in July, 1965. This has “common treasury for all”. It seems unlikely that Clare would approve
# this query is used is user selects all customers been a point of contention among Clare scholars and publishers for of a situation where the rights to his work were enclosed and claimed
$sql_all=”select customer.full_name, orders.order_id from customer Using joins and PHP provides a powerful means to generate business the last 40 years. as the property of one individual 140 years after his death.
inner join orders on customer.customer_id=orders.customer_id”; intelligent information in a user friendly manner. Being web enabled At the time of Clare’s death the ownership of Clare’s unpublished “And me they turned me inside out
is the ultimate user interface; since no installation of client work was passed to James Whitaker, best known as the creator of For sand and grit and stones
# determine which query to use applications is required, reports can be made available to anyone with Whitaker’s Almanac, with the intention of producing a posthumous And turned my old green hills about
if ( $_GET[‘customer_id’] == ‘all’ ) a browser. collection. According to John Goodridge, writing in the Guardian in And pickt my very bones.”

72 LinuxUser & Developer LinuxUser & Developer 73


Regular features

Otherwords
“The absolute transformation of everything
that we ever thought about music will take
place within 10 years, and nothing is going to
be able to stop it. I see absolutely no point in
pretending that it’s not going to happen. I’m
fully confident that copyright, for instance, will
no longer exist in 10 years, and authorship and
intellectual property is in for such a bashing”

David Bowie

LinuxUser & Developer 75

Potrebbero piacerti anche