0% found this document useful (0 votes)
44 views

Hack BSD

The document discusses several lightweight GUI utilities that are included in the core X distribution, including xconsole for viewing console messages, xclipboard for managing the clipboard, xmessage for sending popup messages, and xwd/xwud for creating and viewing screenshots. It also covers how X authorization works using magic cookies and how the root user can leverage this to send messages to other users' displays.

Uploaded by

vinod kapate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
44 views

Hack BSD

The document discusses several lightweight GUI utilities that are included in the core X distribution, including xconsole for viewing console messages, xclipboard for managing the clipboard, xmessage for sending popup messages, and xwd/xwud for creating and viewing screenshots. It also covers how X authorization works using magic cookies and how the root user can leverage this to send messages to other users' displays.

Uploaded by

vinod kapate
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 3

Fun with X

Use the utilities that come with the core X distribution.

There are so many GUI utilities, available either as part of your favorite Window Manager or as a
separate installation, that you can forget that the core X distribution also provides several useful and
lightweight programs. Do you need to monitor console messages, manage your clipboard, send pop-
up messages, or create and view screenshots? Before you hit the ports collection, give the built-in
utilities a try.

Seeing Console Messages


In [Hack #42], we saw how to redirect console messages. If you're using an X session, the
xconsole utility fulfills this purpose. To start this utility, simply type its name into an xterm or
use the Run command provided by your window manager.

By default, only the superuser can start xconsole. A regular user will instead receive a Couldn't
open console message. This is a safety precaution on multiuser systems, preventing regular
users from viewing system messages. If you're the only user who uses your system, remove the
comment (#) from this line in /etc/fbtab:

#/dev/ttyv0 0600 /dev/console

If you spend a lot of your time at an X session, consider adding xconsole to your ~/.xinitrc file so
it will start automatically (see [Hack #9]).

Managing Your Clipboard


If you do a lot of copying and pasting, xclipboard is another excellent candidate for automatic
startup. This utility stores each of your clipboard selections as a separate entity, allowing you to
scroll through them one at a time in a simple GUI window. In addition to the Next and Prev buttons,
a Delete button lets you remove unwanted items and a Save button allows you to save all of your
items as a file.

Sending Pop-up Messages


Do you find yourself starting a command that takes a while to execute, continuing your work in an
X session, then returning periodically to the original terminal or xterm to see how that command is
perking along? Wouldn't it be easier to send yourself a pop-up message once the command
completes?

For example, suppose I want to know when the script from [Hack #80] finishes. I could execute that
script as follows:

#~/bin/mycustomupgrade.sh && xmessage -nearmouse cvsup is


complete.

When the upgrade completes, a pop-up message with the text cvsup is complete. will appear
in my X session near my mouse. That message will disappear once I click on the Okay button.
If you're in the habit of using su -l to provide a new login when you become the superuser, you'll
find that the preceding command will fail to send you a pop-up menu. (I'm assuming you're logged
in as a regular user when you start your X session. You should be!) Instead, you'll receive this error
message:

Xlib: connection to ":0.0" refused by server


Xlib: No protocol specified
Error: Can't open display: :0.0

This has to do with the X authorization process. If I start my X session as the user dru and use su to
execute a command, I'm still logged in as dru, so I'm allowed to send a message to my display.
However, if I use su -l to execute the command, I'm no longer logged in as dru but as root. The
X server refuses to let another user interfere with my display, which is a good thing.

A quick workaround is to not use su -l when sending pop-up messages to your regular user
account. An alternative is to understand the X authorization process. You can then use this
knowledge to enable the superuser to send a message to any user on any display.

Understanding X authorization

Your X server uses a token known as an MIT magic cookie to provide authorization. When you start
your X session, the server creates and stores this unique cookie in ~/.Xauthority. You can view it at
any time using this command:

% xauth list
genisis/unix:0 MIT-MAGIC-COOKIE-1
7e7bc20f9413469a7376e2e5c91aa6f1

Take note that you're the only user with access to this file:

% ls -l ~/.Xauthority
-rw------- 1 dru wheel 101 Feb 18 13:28 .Xauthority

Always keep in the back of your mind, though, that file ownership does not matter to the superuser.
For example, if I need to send an important message to the user dru, I can ssh into the system she's
working on and become the superuser. Then:

# cp ~dru/.Xauthority .

I now have a copy of dru's magic cookie. However, before I can use it, I'll first have to change my
display. Since I sshed into a terminal, I currently don't have one:

# echo $DISPLAY
DISPLAY: Undefined variable.

I don't want just any display, I want the display dru is currently using. I can find the name of her
display by reading her magic cookie:

# xauth list
genisis/unix:0 MIT-MAGIC-COOKIE-1
7e7bc20f9413469a7376e2e5c91aa6f1

The name of her display is genisis/unix:0, where genisis represents the hostname of the
system. I'll now attach to that display and send my message:

# setenv DISPLAY genisis/unix:0


# xmessage -nearmouse Time to go home, Dru...
(prompt hangs until dru responds by pressing the "Okay"
button)

This cheat works on any system to which you have superuser access. Technically, you can execute
any command X understands in a user's X session once you have his cookie and display. Do
remember to use your superuser powers for good, though.

Taking Screenshots
Have you ever needed to send a user a screenshot? There are ports available for this purpose, but the
built-in X command xwd will suffice. Creating a screenshot is a simple matter of:

% xwd -out screenshot.xwd

The command will appear to hang as it waits for you to click your mouse on the portion of the
screen you'd like to capture. Use the -root switch to capture the entire screen and save yourself a
click.

You can view and manipulate the resulting file with most third-party image editors, including xv
and gimp. For quick viewing, though, nothing beats the built-in xwud:

% xwud -in screenshot.xwd

Your results won't seem that impressive if you use xwud immediately, as your screen still probably
looks like your screenshot. When you're finished viewing the screenshot, press Ctrl-c.

See also:
 man xconsole
 man xclipboard
 man xauth
 man xwd
 man xwud

You might also like