Fast Traffic

Fast Traffic

KNOW-HOW D-Bus and HAL Interprocess communication with D-Bus and HAL FAST TRAFFIC It’s the end of the line for CORBA! Gnome now relies on the D-Bus mes- saging system, and KDE is in the process of migrating. BY OLIVER FROMMEL obody likes applications HAL [2], will be the communication sys- that spend all day sitting in tem for future generations of Linux. Nthe corners of the desktop and refusing to talk to anything Talk to Me else. The least you might expect D-Bus is an Inter Process Communica- would be for them to exchange tion (IPC) system; that is, it provides the data with other desktop resi- infrastructure that lets applications talk dents using simple drag & drop to one another and to parts of the oper- techniques. But many users ating system. Although IPC mechanisms expect their programs to were introduced to Unix years ago, they demonstrate more ad- are restricted to signals, pipes, and simi- vanced communication lar things. skills at all levels. Of This may sound familiar to you; after course, users want plug- all, competitive approaches have been gable USB disks no mat- around right from the beginning – just ter what program they think of CORBA, Microsoft’s DCOM, or are using. And VOIP hundreds of other projects. Both KDE softphones should and Gnome have experimented with make friends with their own CORBA implementations from the new hardware the outset. KDE introduced its own when you change DCOP system, and Gnome’s CORBA leg- the headset with- acy is evidenced by the Bonobo compo- out demanding a nent system. Regardless of their personal reboot. opinions of CORBA, most developers To allow this to who just want to code a desktop applica- happen, a Linux tion are overtaxed by the system. And system needs a com- this possibly explains why Bonobo has munication system been vegetating behind the Gnome that lets desktop appli- scenes for so long. cations talk to one an- D-Bus is designed as a simple system other and to the un- with a small footprint. The basic Lib- derlying levels right down through the Oliver spent several kernel to the years as a sysop and programmer at hardware. And if Ars Electronica Cen- the Freedesktop ter in Linz/Austria. developers After finishing his have any say studies in Philoso- in the mat- phy, Linguistics and ter, D-Bus Computer Science, he became an [1], which editor for the Bavarian Broadcasting THEAUTHOR www.photocase. relies on Corporation. Today he is head of the Hardware Editorial Competence Center for Abstrac- Software and Programming at Linux tion Layer New Media AG. com 44 ISSUE 68 JULY 2006 D-Bus and HAL KNOW-HOW dbus library simply provides functions desktop session talk to each other. Of also handle filesystems; it has the ability that allow two applications to communi- course, these applications can be ser- to identify filesystem types, including cate. Application developers don’t typi- vices provided by the desktop environ- LUKS-encrypted partitions [4]. In cally use the library, preferring, instead, ment. In contrast to this, the system bus Gnome, HAL now handles the lion’s the Glib-API-based Libdbus-Glib, which mainly ensures that desktop programs share of the hardware management, par- provides an object-oriented C-API. It is can talk to the underlying layers. For ex- ticularly hot-pluggable devices. The at this level that D-Bus’s capabilities ex- ample, an application can use the system gnome-volume-manager process, which tend to provide a genuine bus system bus to register for a specific hardware runs in the background, makes this hap- living up to its name. The server process, class, such as, say, digital cameras. pen; To configure the process, Gnome dbus-daemon, runs in the background users run the gnome-volume-properties and listens for connection requests from Hardware Management with front-end (Figure 2). applications that register for various HAL There is also a front-end for HAL that event types, such as plugging and un- D-Bus does not provide its own hard- gives users a tree view of the attached plugging specific hardware. When the ware management; instead it relies on devices (Figure 3). Fedora users will find event occurs, the D-Bus daemon sends a the Hardware Abstraction Layer, HAL. the hal-device-manager hidden away in message along the bus, and the applica- Although HAL is independent of D-Bus, the hal-gnome package. tions respond accordingly. the two components work hand in hand: HAL uses D-Bus to provide services, and Using D-Bus System Global or Per D-Bus was mainly programmed for HAL. The D-Bus protocol specification is avail- Session Besides the kernel, modern distribu- able from [1]. The protocol defines four On systems that use D-Bus, each server tions use the Udev subsystem for user- message types that users can send over process implements two buses: the sys- space hardware management. As of ver- the bus. For example, one application tem bus and the session bus. The system sion 0.59, Udev replaces the hotplug sys- can call the methods provided by an- bus launches at boot time and keeps on tem, which has only recently established running even if no users are logged on to itself as a mechanism for supporting Listing 1: 10-camera-ptp.fdi the system. When a user runs the GUI- pluggable hardware by running /sbin/ 01 <deviceinfo version="0.2"> based login manager to launch a desktop hotplug. Besides kernel and Udev infor- session, a server process for the session mation, HAL now has additional details 02 <device> bus is launched. The dbus-daemon bi- on devices stored as FDI files (Device In- 03 <match key="info.bus" nary has command line parameters for formation Files) in an XML format. List- string="usb"> both modes: --system or --session. The ing 1 shows a section from an FDI file 04 <match key="usb. D-Bus package includes the dbus-launch for a digital camera. interface.class" int="0x06"> for starting the daemon and setting the Gnome NetworkManager [3] is a good required environmental variables. Most example of how components cooperate. 05 <match key="usb. distributions launch the session mode It uses the HAL daemon to monitor the interface.subclass" D-Bus daemon along with the X session. network subsystem. When changes int="0x01"> Figure 1 shows the role the two buses occur, such as a user plugging in or un- 06 <match key="usb. play in communications between the op- plugging a wireless USB stick, the dae- interface.protocol" erating system components. The session mon uses D-Bus to notify NetworkMan- int="0x01"> bus lets applications belonging to a ager. Besides genuine devices, HAL can 07 <merge key="info. category" type="string">camera</merge> Application Application 08 <append key="info. capabilities" type="strlist">camera</ System Bus D-Bus Session Bus append> 09 <merge key="camera. HAL Udev access_method" type="string">ptp</merge> 10 </match> Kernel 11 </match> 12 </match> Hardware 13 </match> 14 </device> Figure 1: D-Bus and HAL in the overall context of a Linux system’s components. Applications 15 </deviceinfo> use D-Bus to query HAL about the underlying hardware. WWW.LINUX - MAGAZINE.COM ISSUE 68 JULY 2006 45 KNOW-HOW D-Bus and HAL DBus. Objects pro- advised not to change working systems, vide services that you can use D-Bus to control the BMPx look similar, but are and Banshee audio players. A useful dot-separated: org. thing for network-aware programs is the freedesktop.DBus. current version of the Avahi Zero-Conf The interface package which supports D-Bus. This groups the methods means that applications can be notified and signals for an when servers appear on the network. object; again, a dot- ted notation is used D-Bus Programming in a similar ap- There is good news and bad news for proach to a Java D-Bus programmers. The good news is interface. that bindings are available for a variety of programming languages [6], from the Security Glib-C API, through Python, to Ruby, C#, It would not be a and Java. The bad news is that the API Figure 2: Working with HAL and D-Bus: the Gnome Volume Man- good idea to let has changed so frequently in the past ager, which is user-configurable via gnome-volume-properties. non-privileged that many sample programs on the Inter- (shown above) users access D-Bus. net will not run on the current D-Bus According to the de- versions. There is a general lack of docu- other application. To reflect this, the sec- velopers, security has been a major con- mentation on D-Bus interaction. Your ond type represents a response to a call cern right from the outset. In a simple best bet is to investigate the source code request. The third message type is used case, the UID would be evaluated to con- of working program, such as the Gnome for error handling by the server applica- trol access. If the bus daemon and the tion. The fourth message type provides clients belong to the same user, no re- Listing 4: server.py signals transmitted by applications over strictions are applied. D-Bus also imple- 01 import gobject the bus that do not require a response. ments security policies that define a us- 02 import dbus Programmers can call D-Bus methods er’s privileges to allow more granular synchronously or asynchronously. control (Listing 2). 03 import dbus.glib D-Bus uses a multi-level naming D-Bus can also be used with SE Linux, 04 import dbus.service schema to identify message sources and probably because Red Hat is the main 05 targets.

View Full Text

Details

  • File Type
    pdf
  • Upload Time
    -
  • Content Languages
    English
  • Upload User
    Anonymous/Not logged-in
  • File Pages
    4 Page
  • File Size
    -

Download

Channel Download Status
Express Download Enable

Copyright

We respect the copyrights and intellectual property rights of all users. All uploaded documents are either original works of the uploader or authorized works of the rightful owners.

  • Not to be reproduced or distributed without explicit permission.
  • Not used for commercial purposes outside of approved use cases.
  • Not used to infringe on the rights of the original creators.
  • If you believe any content infringes your copyright, please contact us immediately.

Support

For help with questions, suggestions, or problems, please contact us