6

lrwxrwxrwx 1 root root 14 Apr 19 14:36 /etc/alternatives/x-terminal-emulator -> /usr/bin/xterm

Running it using these 2 calls:

  • /usr/bin/xterm
  • /etc/alternatives/x-terminal-emulator

First starts with black background and other starts with white. What are possible reasons that is it not the same configuration? How to debug it?

  • Can you try to open x-terminal-emulator with text editor just to check that it is not bash executable or something like that? – phoops Apr 19 '14 at 17:22
4

An X resource name consists of a list of components separated by periods. Each component can be either an instance name or a class name. Instances identify a specific component (e.g. the third button on the top row) while classes identify a type of components (e.g. all buttons in the main window). By convention, class names begin with an uppercase letter and instance names begin with a lowercase letter. See Doubts about creating a .Xresources file. or the read the X documentation for more details.

The first component of a resource name is the application. At this level, the class name some application name chosen by the author of the application; for Xterm, that's XTerm (by convention, for applications called X Foo, the second letter is also capitalized). The instance name is, by default, the name of the executable file used to launch the application. Conventional X applications support command line options -name and -class to override these default values.

When you start Xterm through a symbolic link, this changes the name of the executable file (it's the name you use that matters, or more precisely the name that the calling processes passes in argument 0). Thus the instance name (used, among other less visible things, for resource lookup) changes. If you want your settings to apply regardless of the name used to invoke Xterm, define your resources (in ~/.Xresources or whatever file you chose to put them) through the class, e.g.

XTerm.VT100.background:        Black

instead of through the instance (xterm.VT100.background).

2

I don't know why it would behave differently but often times executables are "overloaded" to behave differently when called with different names.

There's typically a structure inside the program called a case/switch statement that determines the name the executable was called with and then will call the appropriate functionality for that executable name. That name is usually the first argument the program receives. For example, in C when you write:

int main(int argc, char** argv)

argv[0] contains the name of the called executable. At least, this is the standard behaviour for all shells, and all executables that use arguments should be aware of it.

Example in Perl

Here's a contrived example I put together in Perl which shows the technique as well.

Here's the actual script, call it mycmd.pl:

#!/usr/bin/perl

use feature ':5.10';

(my $arg = $0) =~ s#./##;

my $msg = "I was called as: ";

given ($arg) {
  $msg .= $arg  when 'ls';
  $msg .= $arg  when 'find';
  $msg .= $arg  when 'pwd';
  default { $msg = "Error: I don't know who I am 8-)"; }
}

say $msg;
exit 0;

Here's the file system setup:

$ ls -l
total 4
lrwxrwxrwx 1 saml saml   8 May 24 20:49 find -> mycmd.pl
lrwxrwxrwx 1 saml saml   8 May 24 20:34 ls -> mycmd.pl
-rwxrwxr-x 1 saml saml 275 May 24 20:49 mycmd.pl
lrwxrwxrwx 1 saml saml   8 May 24 20:49 pwd -> mycmd.pl

Now when I run my commands:

$ ./find 
I was called as: find

$ ./ls
I was called as: ls

$ ./pwd
I was called as: pwd

$ ./mycmd.pl 
Error: I don't know who I am 8-)

How to debug?

I would make use of strace to figure out what configuration files are being used when the "application" is called with the various names.

$ strace -s 2000 -o xterm.log /usr/bin/xterm
... after its launched ...
$ exit

Then run it again like this:

$ strace -s 2000 -o emulator.log /etc/alternatives/x-terminal-emulator
... after its launched ...
$ exit

You'll want to take a look at the various open(...) lines in the output to narrow focus to the files it's calling on.

~/.Xresources file?

As @chepner suggested in the comments perhaps the issue is being caused by a errant configuration definition in your ~/.Xresources file. This file allows you to set various things such as the font used by xterm

You likely have a line such as this:

XTerm*background: black
XTerm*foreground: gray
XTerm*title: terminal
XTerm*saveLines: 1024

These rules would get picked up by applications whose name is XTerm but not by any other apps such as x-terminal-emulator. It's also entirely possible that the rule looks like this instead:

xterm*reverseVideo: on

NOTE: You can force changes in this file to be reloaded like so:

$ xrdb -merge ~/.Xresources

References

  • This is useful, but in this particular case it seems trickier than that. diff <(grep open xterm.log) <(grep open emulator.log) shows 0 results. Also, both have string xterm*ReverseVideo=on (and no other similar matches). – Rumca Apr 19 '14 at 14:25
  • 2
    It's been a while since I've dealt with X resources, but I think xterm*ReverseVideo=on only applies to programs whose names start with xterm. x-term-emulator has x-term, not xterm, as a prefix, so it doesn't use that resource. – chepner Apr 19 '14 at 14:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.