Brace Yourself For Expansion

| No TrackBacks
SVG Icons * Bluesphere Icon Theme

SVG Icons * Bluesphere Icon Theme (Photo credit: Wikipedia)

So I am, once again Scratching That Itch and am playing with Linux From Scratch (more reports to come). But I came across an interesting bash syntax in the online manual and I had to investigate it further.

In the expect build section, they write about creating a backup of the configure script, and they do it thusly:
$ cp -v configure{,.orig}
This is the same thing as:
$ cp -v configure configure.orig
And so I had to look at it a bit. I came across a section in the man page about brace expansion, where you can generate arbitrary strings using a common prefix and/or suffix, so:

$ echo a{d,c,b}e 
ade ace abe
In the above 'cp' command, they are pass two parameters to cp, one without a suffix and one with the suffix of '.orig'. That's pretty cool, although I can't imagine ever remembering to do it! I would usually just use tab completion to do most of the heavy lifting for me:

$ cp -v confi<TAB> confi<TAB>.orig
But the methods could be combined and save a few keystrokes, esp. if there were multiple files that started with "confi".

Bash Reference Manual

Enhanced by Zemanta

Getting The Right Sound

| No TrackBacks
Arch Linux logo

Arch Linux logo (Photo credit: Wikipedia)

FSF artwork of the gnu (GNU mascot) and the pe...

FSF artwork of the gnu (GNU mascot) and the penguin Tux (Linux kernel mascot) representing their viewpoint on "GNU/Linux". The GNU General Public License (GPL), which is used by the Linux kernel as well as by most GNU software, armors both characters. (Photo credit: Wikipedia)

I finally figured out how to change the default output sound device!
I finally figured out how to change the default output sound device!

I've been using Linux as my main OS now for years. But one thing has always eluded me - how to swap which is the default sound device. If I have a USB headphone plugged in at start time, it would randomly pick it as the default output sound device and I just couldn't convince the sound system (ALSA in this case) otherwise. I actually have a pretty nice 5.1 sound setup and when listening to the radio, I'd rather not wear headphones in my home office.

But the only way I could change its mind was to unplug the headphones and reboot, which seemed a little bit of overkill. I had edited the .asoundrc file to try and convince it not to pick the headphones, but there were times when I wanted to use them, so that wasn't an optimal solution.

Some apps, like Audacity and VLC, will let you choose at runtime, but most apps just don't do that and just use the currently selected device. Even when I run KDE, the device selection dialog (KMix) is a mite confusing and it doesn't often work, especially when not in KDE.

But finally today I stumbled across asoundconf, a utility that creates a asoundrc compatible file and mucks about with it then, I guess, restarts ALSA to pick up the changes. It won't affect any currently running programs, so you have to restart them to get the changes, but that's way better than anything else I've run into!

Like I said, I already had a badly edited .asoundrc file, so when I first ran the GUI interface for it, I got a very mysterious error:

$ asoundconf-gtk 
You need to make sure asoundconf is active!
By default, asoundconf's configuration file is ~/.asoundrc.asoundconf
and must be included in ~/.asoundrc. Open this file to make sure it is!

Hmm, how does one go about including .asoundrc.asoundconf in .asoundrc? I guess asoundconf operates by working on its own file and then expects it to be "included" in the ALSA configuration file, but what is the syntax?

I went on a bit of a Google quest to no avail. Even the .asoundrc reference page makes no mention of it. No where I looked told me how to "include" an ALSA rc file into another.

Finally I came across something that mentioned asoundconf would create an .asoundrc file for itself if there wasn't one. So I deleted my .asoundrc file and re-ran asoundconf-gtk. And sure enough, it created a new .asoundrc file with the correct syntax:

# ALSA library configuration file
# Include settings that are under the control of asoundconf(1).
# (To disable these settings, comment out this line.)
</home/jdarnold/.asoundrc.asoundconf>

So it looks like if you have your own .asoundrc, you can just include the .asoundrc.asoundconf file using the <> syntax. Good to know. Don't you hate it when documentation is incomplete?

So how I can run asoundconf-gtk and it gives me a list of the current sound devices (usally just my sound card and a USB headset) and I can choose one of them. It it works like a charm!





Enhanced by Zemanta

Surprising Link

| No TrackBacks
English: Input and output file types of the li...

English: Input and output file types of the linking process. (Photo credit: Wikipedia)

Just when I thought the g++ compiler and linker couldn't surprise me, it sneaks around and breaks my mind. This time it has to do with linking against shared libraries and what it does with global objects found therein.

Here are the source files:

Here's a zip file containing all the source files for the project: tsproj.zip

Pretty straight forward, really. There is a set of functions in trace.cpp that push, print and pop strings from a globally defined 'history' std::deque and it is put into a static (.a) library file. ts1 and ts2 merely add another layer on the interface and are shared libraries (DLLs) that statically link in the trace library. tso.cpp uses ts1, ts2 and, if trace.h is included, trace to push a few strings on and print them out via dynamically linking against ts1 and ts2 and statically linking the trace.cpp library. tsd.cpp using dlopen and dlsym to load ts1 and ts2 at run time, rather than link time. It also can optionally link directly against the trace library.

Here's what I would expect both tsd and tso to print out:

 $ LD_LIBRARY_PATH=. ./tsd
print history1:
 This is shared 1 history
 This is local from the shared 1 library

print history2
 This is shared 2 history
 This is local from the shared 2 library

print local trace history:
 this is line 1
 this is line 2
 this is line 3
 this is line 4
 this is line 5
 this is line 6
 this is line 7
 this is line 8
 this is line 9
 this is line 10
 this is line 11
I would think that each standalone entity - the app and the 2 different shared libraries - would get their own copy of the history deque defined at the global level in trace.cpp and thus you would get the above output

But instead, it all depends on the order the .so files are linked in, whether the app uses trace.cpp and on the mysterious -Bsymbolic flag, with many of the options crashing on exit! The only time it works like the above is if you use trace.cpp, load the .so files at run time, and use -Bsymbolic.

If you don't use -Bsymbolic:

$ LD_LIBRARY_PATH=. ./tsd
print history1:
 this is line 6
 this is line 7
 this is line 8
 this is line 9
 This is shared 1 history
 This is shared 2 history
 this is line 10
 This is local from the shared 1 library
 This is local from the shared 2 library
 this is line 11

print history2
 this is line 6
 this is line 7
 this is line 8
 this is line 9
 This is shared 1 history
 This is shared 2 history
 this is line 10
 This is local from the shared 1 library
 This is local from the shared 2 library
 this is line 11

print local trace history:
 this is line 6
 this is line 7
 this is line 8
 this is line 9
 This is shared 1 history
 This is shared 2 history
 this is line 10
 This is local from the shared 1 library
 This is local from the shared 2 library
 this is line 11

*** Error in `./tsd': free(): invalid pointer: 0x00007f4f80cd8660 ***
======= Backtrace: =========
...
Aborted (core dumped)
As you can see, this is really weird. First off, loading the second library seems to reset the history deque. And they all share the global history deque. And then it crashes on exit, because the deque's constructor is called multiple times. Irregardless of how you feel about sharing the global variable between the calling program and the shared libraries, it certainly shouldn't crash it on the way out as it tries to call the destructor two or three times.

The -Bsymbolic flag is, according to the ld man page:

       -Bsymbolic
           When creating a shared library, bind references to global
           symbols to the definition within the shared library, if
           any. Normally, it is possible for a program linked against
           a shared library to override the definition within the
           shared library. This option is only meaningful on ELF
           platforms which support shared libraries.
I have no idea why it is called 'symbolic' but basically if you use it when you build your .so file, it says to always use its own local copy and to never use the copy of the program linked against it, which seems to be the default (I won't call it a normal) case.

And here is the output if you run the tso program, which links against the .so, instead of dynamically loading them, like tsd does:

 $ LD_LIBRARY_PATH=. ./tso
print history1:
 This is line 1
 This is shared 1 history
 This is line 2
 This is local from the shared 1 library
 This is line 3
 This is shared 2 history
 This is line 4
 This is local from the shared 2 library
 This is line 5

print history2:
 This is line 1
 This is shared 1 history
 This is line 2
 This is local from the shared 1 library
 This is line 3
 This is shared 2 history
 This is line 4
 This is local from the shared 2 library
 This is line 5

print local trace history:
 This is line 1
 This is shared 1 history
 This is line 2
 This is local from the shared 1 library
 This is line 3
 This is shared 2 history
 This is line 4
 This is local from the shared 2 library
 This is line 5

*** Error in `./tso': free(): invalid pointer: 0x00007f2d043e3660 ***
======= Backtrace: =========
/usr/lib/libc.so.6(+0x72ecf)[0x7f2d040b0ecf]
....
Aborted (core dumped)
So you can see where, without the -Wl,-Bsymbolic passed to the link line of the two shared libraries, they and the calling program all share a single global instance of the history std::deque and it still crashes on exit. Ouch.

It is still confusing in the tso (which, remember, links against the .so libraries) when we use -Bsymbolic:

$ LD_LIBRARY_PATH=. ./tso
print history1:
 This is line 1
 This is shared 1 history
 This is line 2
 This is local from the shared 1 library
 This is line 3
 This is line 4
 This is line 5

print history2:
 This is shared 2 history
 This is local from the shared 2 library

print local trace history:
 This is line 1
 This is shared 1 history
 This is line 2
 This is local from the shared 1 library
 This is line 3
 This is line 4
 This is line 5
At least it doesn't crash! But in this case, the calling program and the first shared library that is linked against, share an instance of the history deque, while the second one gets its own copy. Which seems to be another bug, I'm pretty sure.

If I don't include the trace interface in the calling programs, things behave more or less as expected when using the -Bsymbolic:

$ LD_LIBRARY_PATH=. ./tso
No trace.cpp included

print history1:
 This is shared 1 history
 This is local from the shared 1 library

print history2:
 This is shared 2 history
 This is local from the shared 2 library
But if I build the .so files without -Bsymbolic, things get weird again in the static linked version:
$ LD_LIBRARY_PATH=. ./tso
No trace.cpp included

print history1:
 This is shared 1 history
 This is local from the shared 1 library
 This is shared 2 history
 This is local from the shared 2 library

print history2:
 This is shared 1 history
 This is local from the shared 1 library
 This is shared 2 history
 This is local from the shared 2 library

*** Error in `./tso': free(): invalid pointer: 0x00007f9caecc5660 ***
======= Backtrace: =========
/usr/lib/libc.so.6(+0x72ecf)[0x7f9cae992ecf]
/usr/lib/libc.so.6(+0x7869e)[0x7f9cae99869e]
[...]
Aborted (core dumped)
As you can see, even though the calling program no longer pulls in its own copy of trace, the .so files still share a copy of the global and it still crashes. The dynamically loading version works just fine, even without the -Bsymbolic, as long as it doesn't use trace itself.

So after all this, there is only one recommendation I have - always build your .so files with -Wl,-Bsymbolic. To me, it only makes sense that programs and shared libraries have their own copies of globals. Of course, if you don't want this to be true, you are currently screwed, as they all crash. And even despite that recommendation, it doesn't work correctly in some cases anyway. Ugh.

For the record:

$ g++ --version
g++ (GCC) 4.8.1 20130725 (prerelease)
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

The Use of -Bsymbolic (Linker and Libraries Guide)

Enhanced by Zemanta

Drop The X

| No TrackBacks
English: A vector hand cursor and cursor.

English: A vector hand cursor and cursor. (Photo credit: Wikipedia)

Most DEs (Desktop Environments) like KDE or GNOME, handle setting the mouse cursor themselves. But some of the lighter WMs (Window Managers) don't, and you end up with a default cursor that is a large black X, which is ugly and it is hard to find the hotspot.

The xsetroot command sets the default cursor, so you can make it be the more normal arrow
cursor pointing to the top left. Other fun options, depending on your cursor theme, are 'boat', 'trek', 'shuttle' and 'hand1'. This all depends on the Xcursor "theme" you have selected, of course. You can put this command in your ~/.xinitrc file so it always runs when you
begin your X session.

...
xsetroot -cursor_name left_ptr
...
xsetroot(1) - Linux man page

Enhanced by Zemanta

Dancing Back

| No TrackBacks
Arch Linux logo
So I'm going to try and be back in the saddle again here at Daemon Dancing World Headquarters. It's been a long dry spell (almost a year!), as I was distracted for a bit with the Linux Love tumblr (for random Linux quickies), my ArChatter blog (for more Arch specific posts) or even, gasp, my "regular" blog, Trifle One-Sided. But I got on a roll the other day and I have a bunch of posts ready to go - all I need is some time to format them correctly!

Just to give a run down of where I am at, computer wise. Here at home I have an i5-2500 Intel with 16gb of ram running Arch Linux. I recently swapped over from KDE to an obscure but fun window manager called xoat ("An obstinate, asymmetric, tiling, window manager for X"). Not usually a fan of tiling WMs, but this has been working out well. I'll have a longer post on my WM searching soon. Tiling WMs seem to make sense if you have dual 1920x1080 displays like I do - plenty of screen real estate.

The server this blog is running on is an older rack server, with a 2.2ghz Xeon, 4gb of RAM and a 22gb RAID drive. It too is running Arch. Which reminds me - I really should update it! As it just runs a few servers, like this Movable Type server, Teamspeak and a couple others, it really doesn't need a whole bunch of horsepower, although sometimes MT can drag it down.

I have been playing with a virtual box over at Digital Ocean via the recommendation of a co-worker. I got 2 months free, and it runs an Arch "droplet", so why not? It is really speedy, although the initial install is a drag because it is before the big "/usr/bin move" (you just need to do step 5, so it isn't a huge deal). I haven't quite figured out what I'm going to do with it, if anything. Maybe I'll move my physical server over to it, although even at $5 / month, it is still more expensive than the free co-location at my friend's place of business.

So, with only a modicum of luck and perserverence, I should have plenty of posts here at Daemon Dancing, as I head to my tenth(!) anniversary of the blog.

Enhanced by Zemanta

7 Ways To More Info

| No TrackBacks

tylko jogina brak // where the yogi is?
There are a bunch of cool little commands beginning with 'ls' that can tell you a lot about your system. Most of the information you get from the commands can be ferreted out in the /proc filesystem, but these are easier to remember and focused on the problem at hand. Commands like:

lsblk

Quick listing of mounted drives. There are lots of informational options you can give it. I'm partial to this version had have made an alias for it:

$ lsblk -o name,fstype,mountpoint
NAME   FSTYPE MOUNTPOINT
sda           
├─sda1 ext3   /backup
├─sda2 ext3   
└─sda3 ntfs   /mediax
sdb           
├─sdb1 ntfs   
├─sdb2 ext4   /
└─sdb3 ext4   /home
sdc           
├─sdc1 vfat   
├─sdc2 swap   [SWAP]
├─sdc3 ext4   
└─sdc4 ext4   /oldsys
sr0           

lscpu

For a quick listing of cpu information, turn to lscpu:

$ lscpu
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                4
On-line CPU(s) list:   0-3
Thread(s) per core:    1
Core(s) per socket:    4
Socket(s):             1
NUMA node(s):          1
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 42
Model name:            Intel(R) Core(TM) i5-2500K CPU @ 3.30GHz
Stepping:              7
CPU MHz:               1782.000
BogoMIPS:              6587.00
Virtualization:        VT-x
L1d cache:             32K
L1i cache:             32K
L2 cache:              256K
L3 cache:              6144K
NUMA node0 CPU(s):     0-3

lslocks

Lists filesystem locks currently in place. If you're having a problem deleting a file because it is locked, you can use this command to figure out which program has it locked, so you can kill it and try again.

$ lslocks 
COMMAND           PID  TYPE   SIZE MODE  M      START                 END PATH
chrome           2208 POSIX   6.3M WRITE 0 1073741824          1073742335 /home/
steam            1834 POSIX   216B WRITE 0          0                   0 /home/
steam            1834 POSIX   2.3K WRITE 0          0                   0 /home/
chrome           2208 POSIX    30K WRITE 0 1073741824          1073742335 /home/
firefox          2004 POSIX     0B WRITE 0          0                   0 /home/
firefox          2004 POSIX   512K READ  0 1073741826          1073742335 /home/
[...]

lsmod

Simply and quickly shows you the kernel modules loaded:

$ lsmod
Module                  Size  Used by
arc4                    2000  0 
ecb                     2073  0 
md4                     3497  0 
md5                     2313  3 
hmac                    2921  3 
nls_utf8                1320  3 
cifs                  340742  6 
fscache                46067  1 cifs
w83627ehf              32907  0 
hwmon_vid               3260  1 w83627ehf
fuse                   74541  3 
x86_pkg_temp_thermal     6959  0 
intel_powerclamp        8802  0 
coretemp                6326  0 
kvm_intel             129393  0 
kvm                   379223  1 kvm_intel
crc32_pclmul            3019  0 
[...]

lsof

Really useful and dense report of all files currently open on your system. This comes in really handy as a developer, as it shows you all the various network sockets your program is using, what files it has opened, and lots more.

$ lsof
COMMAND    PID  TID     USER   FD      TYPE             DEVICE SIZE/OFF       NODE NAME
dropbox    380      jdarnold  cwd       DIR               8,18     4096          2 /
dropbox    380      jdarnold  rtd       DIR               8,18     4096          2 /
dropbox    380      jdarnold  txt       REG               8,18 18072842     800462 /opt/dropbox/dropbox
dropbox    380      jdarnold  mem       REG               8,18    22960     133891 /usr/lib/libnss_dns-2.18.so
dropbox    380      jdarnold  mem       REG               8,18   274440     799402 /opt/dropbox/wx._combo.so
dropbox    380      jdarnold  mem       REG               8,18    51808     133881 /usr/lib/libnss_files-2.18.so
dropbox    380      jdarnold  mem       REG               8,18    31992     799467 /opt/dropbox/libpopt.so.0
[...]

lspci

In-depth listing of all the cards on your system's PCI bus. Easy way to figure out what your graphics card is, for instance:

$ lspci|grep -i nv
01:00.0 VGA compatible controller: NVIDIA Corporation GF114 [GeForce GTX 560 Ti] (rev a1)

lsusb

Much like lspci, only it shows you the various USB devices that are plugged in. This comes in handy when you plug a USB device in and you're wondering if the system noticed it.

$ lsusb
Bus 006 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 006 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 003: ID 047f:d955 Plantronics, Inc. 
Bus 001 Device 002: ID 05e3:0608 Genesys Logic, Inc. USB-2.0 4-Port HUB
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 005 Device 004: ID 12cf:0186  
Bus 005 Device 003: ID 045e:00db Microsoft Corp. Natural Ergonomic Keyboard 4000 V1.0
Bus 005 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Bus 005 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Enhanced by Zemanta

chvt magic

| No TrackBacks
Arch Linux logo

Arch Linux logo (Photo credit: Wikipedia)

Found out about a nice new command - chvt. I am using Synergy these days instead of my KVM (something that will be the subject of another, much longer post), which doesn't send Ctrl-Alt-Fn to the client machines. Which normally isn't a problem, because it only works if you are running X, so it wouldn't work anyway from a virtual terminal.

But in this case, it is a virtual machine running Arch Linux (the Synergy client machine is running Windows 7), so changing virtual terminals would be fine. So I needed to find a way to change virtual terminals besides using the Ctrl-Alt-Fn keystrokes.

Enter the 'chvt' command. It needs to be run as the superuser, so issuing this command swaps the virtual terminal to terminal 2:

$ sudo chvt 2

So now I can swap virtual terminals in virtual machines even if I can't get the fancy keystrokes to go through to them.

chvt(1): change foreground virtual terminal - Linux man page

Enhanced by Zemanta

September 2014

Sun Mon Tue Wed Thu Fri Sat
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30        

Recent Comments

  • latedreamer1: Iotop seems to be not updating since it still look read more
  • gabrielle03.myopenid.com: Cool desktop theme, it reminds me of the blue screen read more
  • gabrielle03.myopenid.com: I haven't seen x-Window environment, its good you've shared about read more
  • bootstrap12gm: I love the music, its not distracting like others does. read more
  • naveennishad: To enable login as root in KDE open /etc/kde4/kdm/kdmrc and read more
  • Saviq: It's best to use './bootstrap' instead of autoconf itself. read more
  • Jonathan: I'd rather depend on a Linux module like ntfs-3g working read more
  • gormux: sorry but i think you did wrong : first never read more
  • Jonathan: Not sure why it would say it won't work, as read more
  • Jens Andreasen: Hi, I have exactly this problem, and have been trying read more

A Few Random Entries

bash is a 4 letter word
(Oct 3, 2006)
How to copy files
(Apr 13, 2004)
FreeBSD 6.1 out
(May 10, 2006)
BSDCan 2006 coming up
(May 8, 2006)
Cheat Sheets
(Feb 2, 2006)

Recent Assets

  • Eisenbahn Lust
  • prospect512.jpg
  • dosboxmenu2.png
  • dosboxmenu1.png
  • Screenshot Blue Busy.png
  • Screenshot Blue.png