Xdm Startup Programs



“XDM is a true marketing partner – it’s like I have a marketing department on the side. They’re with me start to finish, as much a part of the program as my people, and they always go the extra mile. They know the business, they understand my wants and desires, and they produce. Running a qt application at startup. How can I run a qt program at startup so that the user won't see the desktop at all? I am building my program in linux and I want to distribute it to linux users. I want to add that code to my app, because the customers don't have any understanding about linux. I found that QSettings can do that, is it true? I installed xorg-xdm and made.xsession file executable. I then added xdm to the end of daemons list in rc.conf file. However, xdm is not starting at startup. Where could be the error? I have not installed xdm-archlinux or set up any background wallpaper.

Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

  1. Exploring the Startup of the X Window System
< BackPage 2 of 4Next >
From the author of
Special Edition Using Linux, 6th Edition
Special Edition Using Linux, 6th Edition

Exploring the Startup of the X Window System

Each distribution has a slightly different startup sequence, and your startup sequence will also be different if you use another window manager. These sequences also tend to change from version to version of a distribution. Obviously, trying to document all of the possible startup sequences would take us quite a while and make for rather boring reading.

Understanding why all these scripts are run will help you understand the startup sequence for any distribution. Learning a little shell scripting won't hurt, either. Let's go through the startup sequence from an explorer's point of view.

inittab

Startup of the X Window System will almost always start with /etc/inittab, if you've configured a graphical login. inittab is init's configuration file, and init is about the first thing to run during Linux startup. It is process no. 1 and is the ultimate parent of every other process in the system.

One of the few things that has standardized among Linux startup sequences is the definitions of run levels. Run level 5 is a graphical login. So, if you want the X Window System to automatically start on bootup, you need to set your default run level to 5.

Starting at the beginning of our exploration, we should verify the default run level by looking for the following line in /etc/inittab:

This tells us that the default run level is, in fact, 5. The other likely setting is 3, which is full multiuser mode.

Now that we know the starting run level, let's determine what processes init will run (this example happens to be a Red Hat system):

The id line indicates the default run level. The l5 line is what kicks off all the /etc/rc.d/rc5.d scripts. We'll get back to these in a moment. The pr line is for when power is restored after a power failure, so we don't really care about that. All those mingetty lines represent the virtual consoles that you get when pressing Ctrl+Alt+F#, so we're not interested in those, either.

Finally, that x line is exactly what we're looking for. Don't assume that the x itself means anything. Remember that in OpenLinux, this line was labeled gu. The first field is just a name that the distribution gave to this rule. What we're looking for generally is something that kicks off a display manager (xdm, gdm, kdm). This version of Red Hat uses /etc/X11/prefdm. We'll investigate prefdm in a moment, but for now, notice that this rule is fired when we enter run level 5 and that, if prefdm ever dies, init will restart it (that's what respawn means). The -nodaemon parameter indicates that prefdm should not put itself into the background. This is how programs run by init should work because init handles backgrounding them.

Xdm

Sometimes it's not as easy as looking for 'dm' in the name. OpenLinux runs a script called rc.gui, which then runs kdm. Generally, the line we're interested in is near the bottom, though, and should be fairly obvious (once you know what you're looking for).

You might discover that nothing in inittab seems to start a display manager. In this case, you should look at the rc scripts, which are usually stored in /etc/rc.d/rc#.d or /etc/rc#.d, where # is the run level. In the case of Debian, you'll find an rc script called xdm. This is the script that starts the display manager. A quick look inside this script will show us this line:

This is the display manager that Debian will start.

The Display Manager

init's ultimate goal with run level 5 is to get a display manager started. Whether it does it directly (by calling xdm, for instance) or through a script (such as rc.gui), eventually a display manager should be started.

In the previous example, we saw that Red Hat uses prefdm. In older version of Red Hat, this was a symbolic link to the desired display manager. In newer versions of Red Hat, this is a script (similar to OpenLinux's rc.gui).

There are three common display managers: xdm, kdm, and gdm.

xdm

xdm is the oldest display manager. Most distributions store the xdm configuration files in /etc/X11/xdm. If the configuration files aren't here, try this:

As an explorer, our next point is xdm-config (if we've determined that this system uses xdm). There is a lot of interesting information in this file, but here are the most important lines:

The first line, errorLogFile, determines where xdm will output error messages. This is very important when trying to troubleshoot problems with xdm. Most distributions seem to be standardizing on /var/log/xdm-error.log.

The second line, _0.setup, determines what script xdm will run before providing a login prompt. This script generally does things like provide an attractive background and perhaps a console window. The _0 indicates that this configuration entry is for the primary display. On machines with multiple displays, you might have a _1.setup line as well, but this is very rare. Unless you are debugging problems with xdm itself, it is unlikely that you will need to investigate this script.

The third line, session, is probably the most important. This is the script that is run once a user logs in. This is also where different distributions start to diverge the most. We'll investigate Xsession more later.

Xdm Startup Programs Free

kdm

As we've mentioned already, kdm is the KDE Display Manager and is almost identical to xdm in configuration. In fact, kdm is based directly on xdm's source code. kdm provides some nice features, such as 'faces' (which show available user IDs on the system as small pictures), multilingual support, and a more configurable appearance. All of these advanced configuration options are managed by the Control Center under System, Login Manager.

Because kdm uses xdm's configuration files, it also calls /etc/X11/xdm/Xsession when a user logs in.

gdm

gdm is the GNOME display manager and is a complete rewrite of xdm, although it generally implements the same functions (as well as the added features of kdm).

The primary gdm configuration file is /etc/X11/gdm/gdm.conf. This location is fairly standard, but if you cannot find gdm.conf here, try this:

gdm configuration is actually somewhat complicated, but the following lines from gdm.conf should point you in the right direction to understand the startup sequence:

Notice that most of the variables end with 'Dir' and point to directories rather than files. This is because gdm allows extremely configurable session types. A session is the sequence of events between when a user logs in and when that user logs out. Each session type has a name and is selected with the Session menu on the login screen of gdm. If no session type is selected, then Default is used (this is also what is used if no special rules exist for a particular session type). So, for example, if you have chosen the GNOME session, gdm will first look for the script /etc/X11/gdm/PreSession/GNOME and then look for /etc/X11/gdm/PreSession/Default.

The LogDir variable indicates the directory where gdm stores all of its logs. This is very important if you are debugging a problem with gdm.

The DisplayInitDir variable indicates where to look for scripts to run before presenting the user a login prompt. This is the same function as the Xsetup_0 file for xdm. In fact, /etc/X11/gdm/Init/Default is often symbolically linked to /etc/X11/xdm/Xsetup_0. Although gdm is incredibly flexible in what it allows to be done, you will find that most distributions just have it point back to what xdm does.

The PreSessionScriptDir variable indicates where to look for scripts to run after the user has logged in but while the system is still running as root. This generally points back to /etc/X11/xdm/GiveConsole, where the user is given ownership of the console.

The SessionDir variable indicates where to look for scripts to run as the user. This generally points back to /etc/X11/xdm/Xsession. Almost all display manager configurations eventually get back to Xsession, which we'll cover next.

The PostSessionScriptDir variable indicates where to look for scripts to run after the user has logged out and once gdm is running as root again. This generally points back to /etc/X11/xdm/TakeConsole, which gives the console back to root.

Xsession

After the user has logged in, most distributions will run /etc/X11/xdm/Xsession. Although most distributions call this file the same thing, they tend to differ wildly about what it does. The only way to know is to actually read it.

In general, Xsession is going to do the following things:

  • Redirect output to ${HOME}/.xsession-errors—Most distributions agree on this location, and it is an important source of information for debugging all kinds of problems. This file will catch the output of any application that doesn't have a controlling terminal, so it is a good place to look for output from applications that you launch via KDE or GNOME's panel or in other ways that don't use a terminal.

  • Load resources—Many older applications in the X Window System are configured with resources. Resources are configuration options stored in memory by the X Window System and are queried by various applications. Xsession generally includes a mechanism for loading user-specific resources from a file such as ${HOME}/.Xresources. Another common name is ${HOME}/.Xdefaults. To verify the actual name, look for parts of Xsession that call xrdb.

  • Run user-defined script—Generally, the user is allowed to create her own startup scripts. Some distributions will run ${HOME}/.xsession, if it is found. If not, they may try ${HOME}/.Xclients or even ${HOME}/.xinitrc. Which user-defined scripts Xsession will honor is somewhat distribution-specific, and you should check Xsession itself to be sure. Some distributions will also skip this step if the user requested a specific session via kdm or gdm. In that case, Xsession may just run the desktop or window manager directly.

  • Run Xclients—The final fallback is almost always /etc/X11/xinit/Xclients. This script generally figures out what desktop or window manager the user wants (sometimes by querying distribution-specific configuration files) and starts it.

Desktop or Window Manager Startup

The last startup step is generally an 'exec' command that starts a desktop (KDE or GNOME, for example) or a window manager (fvwm2 or Blackbox, for example). The 'exec' instructs the script to remove itself from memory before launching the desired environment. This not only saves memory, but it also ensures that the rest of the script won't be accidentally executed when the user logs out.

KDE starts with a script called startkde. This script launches the various servers that KDE needs for interprocess communication. It also starts the window manager, the KDE panel, and other useful applications.

GNOME starts with a script called gnome-session. This script does essentially the same things as startkde.

Window managers are generally started by simply running the window manager's executable.

Related Resources

  • Book $39.99
  • Book $31.99

Xdm Startup Programs 2020

  • Book $35.99

Home > Articles > Operating Systems, Server > Linux/UNIX/Open Source

  1. Exploring the Startup of the X Window System
< BackPage 2 of 4Next >
From the author of
Special Edition Using Linux, 6th Edition
Special Edition Using Linux, 6th Edition

Exploring the Startup of the X Window System

Each distribution has a slightly different startup sequence, and your startup sequence will also be different if you use another window manager. These sequences also tend to change from version to version of a distribution. Obviously, trying to document all of the possible startup sequences would take us quite a while and make for rather boring reading.

Understanding why all these scripts are run will help you understand the startup sequence for any distribution. Learning a little shell scripting won't hurt, either. Let's go through the startup sequence from an explorer's point of view.

inittab

Startup of the X Window System will almost always start with /etc/inittab, if you've configured a graphical login. inittab is init's configuration file, and init is about the first thing to run during Linux startup. It is process no. 1 and is the ultimate parent of every other process in the system.

One of the few things that has standardized among Linux startup sequences is the definitions of run levels. Run level 5 is a graphical login. So, if you want the X Window System to automatically start on bootup, you need to set your default run level to 5.

Starting at the beginning of our exploration, we should verify the default run level by looking for the following line in /etc/inittab:

Xdm Startup ProgramsStartup

This tells us that the default run level is, in fact, 5. The other likely setting is 3, which is full multiuser mode.

Now that we know the starting run level, let's determine what processes init will run (this example happens to be a Red Hat system):

The id line indicates the default run level. The l5 line is what kicks off all the /etc/rc.d/rc5.d scripts. We'll get back to these in a moment. The pr line is for when power is restored after a power failure, so we don't really care about that. All those mingetty lines represent the virtual consoles that you get when pressing Ctrl+Alt+F#, so we're not interested in those, either.

Finally, that x line is exactly what we're looking for. Don't assume that the x itself means anything. Remember that in OpenLinux, this line was labeled gu. The first field is just a name that the distribution gave to this rule. What we're looking for generally is something that kicks off a display manager (xdm, gdm, kdm). This version of Red Hat uses /etc/X11/prefdm. We'll investigate prefdm in a moment, but for now, notice that this rule is fired when we enter run level 5 and that, if prefdm ever dies, init will restart it (that's what respawn means). The -nodaemon parameter indicates that prefdm should not put itself into the background. This is how programs run by init should work because init handles backgrounding them.

Sometimes it's not as easy as looking for 'dm' in the name. OpenLinux runs a script called rc.gui, which then runs kdm. Generally, the line we're interested in is near the bottom, though, and should be fairly obvious (once you know what you're looking for).

You might discover that nothing in inittab seems to start a display manager. In this case, you should look at the rc scripts, which are usually stored in /etc/rc.d/rc#.d or /etc/rc#.d, where # is the run level. In the case of Debian, you'll find an rc script called xdm. This is the script that starts the display manager. A quick look inside this script will show us this line:

This is the display manager that Debian will start.

The Display Manager

init's ultimate goal with run level 5 is to get a display manager started. Whether it does it directly (by calling xdm, for instance) or through a script (such as rc.gui), eventually a display manager should be started.

In the previous example, we saw that Red Hat uses prefdm. In older version of Red Hat, this was a symbolic link to the desired display manager. In newer versions of Red Hat, this is a script (similar to OpenLinux's rc.gui).

There are three common display managers: xdm, kdm, and gdm.

xdm

xdm is the oldest display manager. Most distributions store the xdm configuration files in /etc/X11/xdm. If the configuration files aren't here, try this:

As an explorer, our next point is xdm-config (if we've determined that this system uses xdm). There is a lot of interesting information in this file, but here are the most important lines:

The first line, errorLogFile, determines where xdm will output error messages. This is very important when trying to troubleshoot problems with xdm. Most distributions seem to be standardizing on /var/log/xdm-error.log.

The second line, _0.setup, determines what script xdm will run before providing a login prompt. This script generally does things like provide an attractive background and perhaps a console window. The _0 indicates that this configuration entry is for the primary display. On machines with multiple displays, you might have a _1.setup line as well, but this is very rare. Unless you are debugging problems with xdm itself, it is unlikely that you will need to investigate this script.

The third line, session, is probably the most important. This is the script that is run once a user logs in. This is also where different distributions start to diverge the most. We'll investigate Xsession more later.

kdm

As we've mentioned already, kdm is the KDE Display Manager and is almost identical to xdm in configuration. In fact, kdm is based directly on xdm's source code. kdm provides some nice features, such as 'faces' (which show available user IDs on the system as small pictures), multilingual support, and a more configurable appearance. All of these advanced configuration options are managed by the Control Center under System, Login Manager.

Because kdm uses xdm's configuration files, it also calls /etc/X11/xdm/Xsession when a user logs in.

gdm

gdm is the GNOME display manager and is a complete rewrite of xdm, although it generally implements the same functions (as well as the added features of kdm).

The primary gdm configuration file is /etc/X11/gdm/gdm.conf. This location is fairly standard, but if you cannot find gdm.conf here, try this:

gdm configuration is actually somewhat complicated, but the following lines from gdm.conf should point you in the right direction to understand the startup sequence:

Notice that most of the variables end with 'Dir' and point to directories rather than files. This is because gdm allows extremely configurable session types. A session is the sequence of events between when a user logs in and when that user logs out. Each session type has a name and is selected with the Session menu on the login screen of gdm. If no session type is selected, then Default is used (this is also what is used if no special rules exist for a particular session type). So, for example, if you have chosen the GNOME session, gdm will first look for the script /etc/X11/gdm/PreSession/GNOME and then look for /etc/X11/gdm/PreSession/Default.

Xdm

The LogDir variable indicates the directory where gdm stores all of its logs. This is very important if you are debugging a problem with gdm.

The DisplayInitDir variable indicates where to look for scripts to run before presenting the user a login prompt. This is the same function as the Xsetup_0 file for xdm. In fact, /etc/X11/gdm/Init/Default is often symbolically linked to /etc/X11/xdm/Xsetup_0. Although gdm is incredibly flexible in what it allows to be done, you will find that most distributions just have it point back to what xdm does.

The PreSessionScriptDir variable indicates where to look for scripts to run after the user has logged in but while the system is still running as root. This generally points back to /etc/X11/xdm/GiveConsole, where the user is given ownership of the console.

The SessionDir variable indicates where to look for scripts to run as the user. This generally points back to /etc/X11/xdm/Xsession. Almost all display manager configurations eventually get back to Xsession, which we'll cover next.

The PostSessionScriptDir variable indicates where to look for scripts to run after the user has logged out and once gdm is running as root again. This generally points back to /etc/X11/xdm/TakeConsole, which gives the console back to root.

Xsession

Startup

After the user has logged in, most distributions will run /etc/X11/xdm/Xsession. Although most distributions call this file the same thing, they tend to differ wildly about what it does. The only way to know is to actually read it.

In general, Xsession is going to do the following things:

  • Redirect output to ${HOME}/.xsession-errors—Most distributions agree on this location, and it is an important source of information for debugging all kinds of problems. This file will catch the output of any application that doesn't have a controlling terminal, so it is a good place to look for output from applications that you launch via KDE or GNOME's panel or in other ways that don't use a terminal.

  • Load resources—Many older applications in the X Window System are configured with resources. Resources are configuration options stored in memory by the X Window System and are queried by various applications. Xsession generally includes a mechanism for loading user-specific resources from a file such as ${HOME}/.Xresources. Another common name is ${HOME}/.Xdefaults. To verify the actual name, look for parts of Xsession that call xrdb.

  • Run user-defined script—Generally, the user is allowed to create her own startup scripts. Some distributions will run ${HOME}/.xsession, if it is found. If not, they may try ${HOME}/.Xclients or even ${HOME}/.xinitrc. Which user-defined scripts Xsession will honor is somewhat distribution-specific, and you should check Xsession itself to be sure. Some distributions will also skip this step if the user requested a specific session via kdm or gdm. In that case, Xsession may just run the desktop or window manager directly.

  • Run Xclients—The final fallback is almost always /etc/X11/xinit/Xclients. This script generally figures out what desktop or window manager the user wants (sometimes by querying distribution-specific configuration files) and starts it.

Desktop or Window Manager Startup

The last startup step is generally an 'exec' command that starts a desktop (KDE or GNOME, for example) or a window manager (fvwm2 or Blackbox, for example). The 'exec' instructs the script to remove itself from memory before launching the desired environment. This not only saves memory, but it also ensures that the rest of the script won't be accidentally executed when the user logs out.

KDE starts with a script called startkde. This script launches the various servers that KDE needs for interprocess communication. It also starts the window manager, the KDE panel, and other useful applications.

GNOME starts with a script called gnome-session. This script does essentially the same things as startkde.

Window managers are generally started by simply running the window manager's executable.

Related Resources

  • Book $39.99
  • Book $31.99
  • Book $35.99