GB
  
You are currently viewing the United Kingdom version of the site.
Would you like to switch to your local site?
15 MIN READ TIME

L XF SHELL

Revealing the shell behind the shell

In the last iteration of the shell, Ferenc Deák managed to reveal the password for his home computer…

OUR EXPERT

Ferenc Deák sees no way back from the C++ mayhem he brought upon readers with this quick and dirty shell, so you just have to accept it. C++.

QUICK TIP

The code for the shell can still be found at https://github. com/fritzone/lxf-shell.

In the first three parts of our mini series, the basic operational aspect of our shell was I solidly established, showcasing its proficiency in executing programs. Now our focus shifts towards integrating advanced features. We are happy to call in the heavy cavalry to extend the shell’s repertoire by a modular plugin architecture. With these refinements we not only broaden the range of tasks the shell can perform but also contribute to a more versatile and open environment, and provide a framework for anyone willing to enhance its functionality.

To properly implement a flexible and easy-to-use plugin architecture, we need to present another basic component of the Linux ecosystem: shared object files. These files, having the .so extension, are instrumental in constructing plugin architectures, offering a dynamic means to augment the existing software functionality. In a plugin system, these shared libraries serve as modular components, enabling developers to extend a base application without altering its core code.

The .so and the not so

Shared libraries are one of the few basic components of modern operating systems. In Linux (and other Unixlike OSes), they materialise as SO files; under Windows, they are the infamous DLL files. Generally, they are pivotal components of the OS, facilitating dynamic linking, a process where programs access libraries during runtime rather than compile time.

Dynamic linking enables flexibility and resource efficiency, as multiple programs can share (or link with) a common SO file dynamically. This encourages the reuse of code, particularly for system libraries and frequently employed functions. Changes to shared objects automatically apply to all linked programs, streamlining maintenance and reducing redundancy. During program execution, the dynamic linker/ loader, often referred to as ld.so or ld-linux.so, loads the necessary SO files into memory and resolves the required dependencies, thus reducing the memory footprint and startup time of the application.

Part four!

Don’t miss next issue, subscribe on page 16!

Shared object files adhere to a naming convention, typically lib.so.major.minor. Symbolic links, such as lib.so, point to the latest version, aiding in version management and compatibility.

Since CMake is our build system, here’s a snippet on how to build shared object files with it. Instead of add_ application , which was used until now, we simply use add_library , and also optionally specify the version: add_library(mylibrary SHARED source1.cpp source2.cpp) set_target_properties(mylibrary PROPERTIES VERSION 1.2.3 SOVERSION 1)

Here, CMakeLists.txt defines a shared library named mylibrary, and specifies source files to include.

Plugin loaders

One of the main benefits of shared libraries is that they can be dynamically loaded upon request without the need to explicitly link to them via a build system. This step delays the loading of the shared library until the user needs it, with the expense that extra code needs to be written, but it has the advantage that if the user (a client application) does not need the functionality provided by a specific library, it does not load it. This feature stands at the base of our plugin architecture: we will dynamically load the libraries (from now on referred to as plugins) when we start the application, without knowing how many of them we have, and we will create a common interface for these plugins in order to correctly integrate into our shell.

Unlock this article and much more with
You can enjoy:
Enjoy this edition in full
Instant access to 600+ titles
Thousands of back issues
No contract or commitment
Try for 99p
SUBSCRIBE NOW
30 day trial, then just £9.99 / month. Cancel anytime. New subscribers only.


Learn more
Pocketmags Plus
Pocketmags Plus

This article is from...


View Issues
Linux Format
April 2024
VIEW IN STORE

Other Articles in this Issue


LINUX FORMAT
LINUX FORMAT
The #1 open source mag
WELCOME
MEET THE TEAM
LINUX FORMAT
Back to basics
For anyone looking to learn the basics of
REGULARS AT A GLANCE
Newsdesk
New Mozilla CEO to double down on Firefox
Answers
Got a burning question about open source or the kernel? Whatever your level, email it to answers@linuxformat.com
Mailserver
WRITE TO US Do you have a burning
HotPicks
THE BEST NE W OPEN SOURCE SOF T WARE ON THE PL ANET
MICROSOFT INVASION!
When an immovable penguin meets an unstoppable corporation, always bet on the penguin…
REVIEWS
GeForce RTX 4070 Super
Jarred Walton considers what’s so super about mid-cycle updates.
Linux Mint 21.3
Nate Drake keeps things Minty fresh with this incredibly intuitive and powerful Linux distro. Be sure to add some spices.
AV Linux MXE-23.1
Nate Drake puts his ear to the ground to hear the latest version of AV Linux, Enlightenment, rumbling into town.
Solus 4.5 Resilience
Nate Drake’s Irish eyes are smiling at this latest offering from Solus, with improvements to the desktop and under the hood.
SDesk 2024.01.26
Nate Drake discovers the new kid on the block, SDesk, including shiny toys such as Wayland and a brand new browser.
ROUNDUP
Retrogaming distros
WE COMPARE TONS OF STUFF SO YOU DON’ T HAVE TO!
The verdict
Retrogaming distros
Hacker’s toolkit
After an extended break, alleged hacker Jonni Bidwell emerges from the shadows to teach you the noble art and keep you out of trouble.
Pi USER
Raspberry Pi supports T Level students
“What’s a T Level?” we hear you ask. Don’t worry, we didn’t know either…
MX Linux 23.1 Pi
Les Pounder spends all day tinkering with Raspberry Pis and the latest MX Linux has got him in a spin.
NVMe Base Pi 5
Everyone, says Les Pounder, is based, especially regarding Pimoroni!
Scare your enemies with a Pi prank box
Yes, Les Pounder is very scary, but buying OEP3W amplifiers from AliExpress is worse. He wonders what pranks he can pull with them…
Enhance your Pi-vacy
A man who likes to keep himself to himself, Christian Cawley explains how to keep online activity private when using a Raspberry Pi.
IN DEPTH
THE PAW-FECT DISTRO
Nick Peers can hardly ‘container’ himself after taking the Puppy Linux developer’s new distro for a good run off the lead.
TUTORIALS
Parallel compression
Parallel processing, the computing equivalent of juggling, as Shashank Sharma calls it, can be used to perform everyday tasks to save time.
Get more from your virtual machines
VIRTUALBOX
What’s in a filesystem?
EXT4 Credit: https://ext4.wiki.kernel.org
Moving rooms and sharing your game
ADVENTURE GAME STUDIO Credit: www.adventuregamestudio.co.uk
Fix LEDs with some coded CAD models
OPENSCAD Credit: http://openscad.org
Take the Rust-based kernel for a test run
MAESTRO Credit: https://github.com/llenotre
ADMINISTERIA
Disk management
Stuart Burns isn’t boring, he’s essential – just like looking after your disks
The Pi 5 as a mini server
A sysadmin’s perspective on setting up and running a new Raspberry Pi 5 for Docker and beyond.
Yodeck
Jonas P DeMuro dusts off his Raspberry Pi so he can take a quick overview of this digital signage service.
Hostinger
James Capell is just the guy to try out a web host that’s easy enough for your granny to use.
Framework
Three years on, the DIY laptop concept has come of age. 
Framework Laptop 16
Slapping parts together, Dave James takes this modular laptop with upgradable GPU for a spin. 
CODING ACADEMY
Develop games for the CBM-64
David Bolton demonstrates how to develop games in 6502 for the Commodore 64 and run them on the Vice emulator in the 21st century!
Chat
X
Pocketmags Support