Linux backwards binary compatibility, GLIBC, and __isoc99_sscanf

As a Java developer I occasionally have to mess around with Linux C and C++ code. This post is aimed at helping fellow Java developers overcome some Linux backward compatibility issues and navigate the almighty power of GLIBC.

GLIBC is a library of functions used by many Linux packages. Each new release contains bug fixes and new features. While code compiled with an older GLIBC will work with a new GLIBC the inverse is not true. This is where the trouble starts....

GLIBC cannot be upgraded (or at least its not recommended) and asking customers who receive your code to upgrade GLIBC or the OS is a real hassle. So let's do a dive in to the version numbers...

GLIBC Versions

To check your GLIBC version run one of the following commands. Notice they are from different OS version since 2.5 representes RHEL 5 and 2.12 represents RHEL 6. For a full history of versions click this link.

$ ldd --version
ldd (GNU libc) 2.12
Copyright (C) 2010 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.
Written by Roland McGrath and Ulrich Drepper.
$ /lib/
GNU C Library stable release version 2.5, by Roland McGrath et al.
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
Compiled by GNU CC version 4.1.2 20080704 (Red Hat 4.1.2-50).
Compiled on a Linux 2.6.9 system on 2012-01-19.
Available extensions:
        The C stubs add-on version 2.1.2.
        crypt add-on version 2.1 by Michael Glad
        GNU Libidn by Simon Josefsson
        GNU libio by Per Bothner
        NIS(YP)/NIS+ NSS modules 0.19 by Thorsten Kukuk
        Native POSIX Threads Library by Ulrich Drepper et al
        RT using linux kernel aio
Thread-local storage support included.
For bug reporting instructions, please see:

Viewing your dependencies...

When building a C/C++ application on a RHEL6 box you are automatically binding to the GLIBC 2.12 library. However... this doesn't mean you app will fail to work on RHEL5. It very much depends on the functions you use. If you choose a function that's only in GLIBC 2.12 then you have automatically tied yourself to newer OS versions.

BUT WAIT... What if I didn't use a new function! I just have a plain old C program but it won't run. This is likely due to libraries you may link with that are also compiled on RHEL6.

To view your dependencies run the program nm or objdump. Objdump will show your overall dependencies and nm will show specific function dependencies. Both programs allow you to quickly home in on the function that will not run on older Linux servers (compare the GLIBC version).

Once you find the offending function you can grep -R for it in your libraries and binaries to figure out what third party code polluted your build!

$ objdump -p mybin
mybin:     file format elf64-x86-64
Program Header:
Dynamic Section:

Version References:
  required from
    0x0b792650 0x00 07 GCC_3.0
  required from
    0x09691a75 0x00 06 GLIBC_2.2.5
  required from
    0x0d696913 0x00 05 GLIBC_2.3
    0x09691a75 0x00 04 GLIBC_2.2.5
  required from
    0x08922974 0x00 03 GLIBCXX_3.4
    0x056bafd3 0x00 02 CXXABI_1.3

$ nm mybin
00000000006124f0 V DW.ref._ZTIN6oracle4occi12SQLExceptionE
00000000006124f8 V DW.ref.__gxx_personality_v0
000000000040e575 t I_comp
0000000000612038 d _DYNAMIC
0000000000612290 d _GLOBAL_OFFSET_TABLE_
00000000004032d0 t _GLOBAL__I_occi_db.cpp
0000000000401f90 t _GLOBAL__I_occi_port.cpp
000000000040f280 R _IO_stdin_used
                 w _Jv_RegisterClasses
0000000000405dfd t pvariable
                 U realloc@@GLIBC_2.2.5
0000000000405d95 t release_chain
                 U sscanf@@GLIBC_2.2.5
                 U stderr@@GLIBC_2.2.5
0000000000405bae t strsave
000000000040d135 t to_float
0000000000405d46 t undo_bindings
0000000000612754 b use_fallback.4930
                 U write@@GLIBC_2.2.5

Solution for __isoc99_sscanf

The function __isoc99_sscanf caused me a lot of trouble. A library I was linking to was compiled with RHEL6 and GLIBC 2.12. I used objdump and nm (see above) to locate the offending function... __isoc99_sscanf

The GCC/G++ compiler I was using had a change in one of the header files regarding scanf such that any builds now required __isoc99_sscanf and GLIBC 2.12... locking me in to RHEL6 and breaking RHEL5 compatibility.

The solution is simple... define the following #define...

    #define _GNU_SOURCE 1

or adjust your makefile CFLAGS/CPPFLAGS/CXXFLAGS...


This alters the behavior of the sscanf code block stdio.h by setting __USE_GNU to TRUE (an internal macro that is enabled when _GNU_SOURCE is defined). The macro prevents the __isoc99_sscanf redefinition and saves us from compatibility hell! :-)

#if defined __USE_ISOC99 && !defined __USE_GNU \
    && (!defined __LDBL_COMPAT || !defined __REDIRECT) \
    && (defined __STRICT_ANSI__ || defined __USE_XOPEN2K)

    /* For strict ISO C99 or POSIX compliance disallow
       %as, %aS and %a[ GNU extension which conflicts
       with valid %a followed by letter s, S or [.  */
    extern int __isoc99_sscanf (__const char *__restrict __s,
          __const char *__restrict __format, ...) __THROW;

define sscanf __isoc99_sscanf

Home Emergency Power

What happens when the power goes out? This blog post intends to provide a short introduction to some of your options.

Before we get going I need to remind you that working with electrical equipment and fuel sources is inherently dangerous and should only be undertaken by skilled individuals. Further....
This blog and it's author are not responsible for, and expressly disclaims all liability for, damages of any kind arising out of use, reference to, or reliance upon any information contained within the site. While the information contained within the site is periodically updated, no guarantee is given that the information provided in this Web site is correct, complete, and up-to-date.
Let's ask a few questions to get the ball rolling...

Question 1: Are your power outages likely to be short (you have reliable power) or long due to hurricanes, snow, or similar circumstances?

Question 2: What do you need to keep running in the event of an outage? for example:
  • Fridge/freezer
  • Lights
  • Sump pump
  • Electric heater
  • Medical equipment
  • Cell phones, etc.

Question 3: What fuel source do you have available? for example:
  • 20lb BBQ propane - this has a very long shelf life and can run a generator for 10 hours. This produces carbon monoxide exhaust gases.
  • Gasoline - this has a limited shelf life (30-60 days) but it can be extended with fuel stabilizer to a maximum of one year. Equipment using gasoline must be run regularly or stored following the manufacturer's recommended procedures to prevent failure. This produces carbon monoxide exhaust gases.
  • Automobile - you have a self-contained generator, electrical system, and fuel! We'll talk about this a little more below.
  • AGM deep cycle battery - this special type of battery has a long shelf life, allows for deep discharge, and produces zero hydrogen when charged with the correct three or four stage charger (slow-charger or fast-charger). The longevity and safety features of an AGM battery are unmatched by car batteries, "maintenance free" batteries, and regular deep cycle batteries.
  • Solar - there are whole home solar solutions available along with battery backup for use during dark hours.

Question 4: How much power do you need?

So... we have a few choices based on the questions! but since this is a "home emergency power" blog post I will assume you have a fridge/freezer you need to run along with some electronics that need charging or maintenance.

When deciding on your home emergency power solution consider the maximum and running electrical load. A typical fridge/freezer or any device with a motor requires a very large surge of power. This surge is indicated on the electrical information label on your device. For example, a fridge/freezer label may indicate 8.5 amps at 115 volts. The above example represents 8.5A x 115V = 978W. Typically the running watts of a fridge is around 1/5 of that value, e.g. 200W.

So go ahead and check all the devices you wish to run during a power outage. Calculate the maximum watts and approximate the running watts. You can even buy a cheap watt meter to measure running watts for your critical devices - but remember to look at the electrical label for the maximum load details!

For this example let's assume you have a fridge/freezer that requires 978W surge load and 200W running load. You also have a 60W LED TV and 60W light bulb for a total 320W running load and 1100W surge load.

Question 5: How much are you willing to spend?

Now we can choose a power source! You have a few options at different price points but I'm going to narrow it to three of the most common:
  • Portable generators - cheap, plenty of energy, pure sine wave, very loud (lawn mower volume), and uses gasoline/propane. Buy this if you need cheap reliable power and don't mind the noise.
  • Inverter generators - expensive, limited capacity, relatively quiet, and uses gasoline/propane. This is very common for tailgating and camping where low noise is very imporant.
  • Inverter - inexpensive to moderately expensive but requires a separate power source (automobile or AGM battery) and correctly sized cables (4 gauge for anything longer than 12 inches but less than 48 inches).
Inverters come in two flavors: pure sine wave and modified sine wave. Pure sine wave inverters are preferred due to their similarity with utility provided power. Medical equipment, compact fluorescent lights, and other sensitive equipment require a pure sine wave inverter.

Purchasing a self-contained generator is certainly the easiest solution but comes at a high initial cost and requires maintenance and care. You must use fuel stabilizer to protect your gasoline and run your generator regularly to keep the fuel lines and carburetor functioning. Please follow manufacturer's guidelines to prepare the generator engine for long term storage.

Question 6: Would you like maintenance free power?

If you're still reading... then you're looking for an affordable solution for infrequent power outages and you'd like to avoid the hassle of maintaining a small gas engine. So let's look at inverters, automobiles, and AGM batteries!

Inverters, depending on your needs, can be purchased for as little as $80 for a modified sine wave and $180 for a pure sine wave. Here are three products to consider from reputable manufacturer's:
The modified sine wave inverters are suitable for a fridge/freezer applications but realize a modified sine wave causes your compressor to run warmer than a pure sine wave inverter. For $100-$200 extra you can protect your equipment and have clean power for sensitive electronics.

Carefully check the surge rating of both products against your electrical needs. If you are close to the limit then consider a higher capacity product.

Okay, now we have our inverter we must consider the 12V power source that will drive it. A word of caution:
12V is low voltage but to supply the required power (watts) for residential appliances the amps are VERY HIGH. For example a 200W load requires 20A at 12V. A rule of thumb is to divide the wattage required by ten for the number of DC amps necessary to drive your appliances.
Which leads to another warning:
Car batteries and AGM batteries can supply hundreds of amps very rapidly. This can and will cause a fire, death, and property damage if handled incorrectly. Keep all cables and equipment out of the reach of children.
For automotive power source you must consider your car's alternator capacity. Typically it is 80A maximum for a small sedan and 130A for a luxury sedan or heavy duty truck. Here are a few important tips:
  • The vehicle engine must be running with all electrical and electronic accessories switched off.
  • The vehicle should be a minimum of 15 feet from a house to prevent carbon monoxide poisoning.
  • The inverter should be kept out of direct sunlight and kept dry.
  • The cable connections to the car must be of a suitable gauge to prevent overheating (see manufacturer's guidelines).
  • Use no more than 50% of your alternator capacity to prevent overheating and failure of the alternator. e.g. 80A alternator translates to 400W sustained running load.
  • Car batteries produce hydrogen so be extremely careful when connecting the inverter to your car battery terminals. Make sure there's ample ventilation and wait a few minutes after starting the car to avoid sparks igniting hydrogen gas.
  • Do not connect your inverter to the car cigarette lighter, it is only suitable for 100W inverter applications.
  • Do not short the battery terminals; death and property damage will occur.

For non-automotive power you can use a battery... I recommend an AGM battery as it produces no carbon monoxide, it's completely silent, and can be used inside an apartment or other enclosed space. They are not cheap however, costing $200 for a 80AH capacity... here are some important tips:
  • Store the AGM battery fully charged with nothing connected to it. It should be fine for six weeks between charges (unlike a car battery).
  • You can refresh charge after six weeks without discharging first. Schedule an occasional discharge to 50% to exercise the battery. Be sure to measure the voltage to ensure your battery is still healthy when you do exercise it.
  • You can check the charge of an AGM battery using a cheap digital volt meter. Measure the voltage when there is NO LOAD on the battery (turn the inverter/load off). The voltage must NOT drop below 12.0 volts and is fully charged at 13.0 volts or higher. It is normal to see a lower voltage when the battery is under load.
  • AGM batteries typically do not produce hydrogen unless they are overcharged! so get a quality three or four stage charger (slow-charger or fast-charger) which correctly maintains AGM batteries. Do not cut corners on your charger to save a few dollars!
  • The cable connections to the battery must be of a suitable gauge to prevent overheating and fire (see manufacturer's guidelines). Use no less than six gauge and preferably four gauge, they are sold at Walmart.
  • Use no more than 80% of the battery's rated capacity. For example a 80AH AGM battery can safely discharge 64AH before shortening it's service life. That means an 80AH AGM battery can provide 640W of power for one hour, or 320W for two hours, and 160W for four hours continuously. A volt meter will read 12.0 volts when the battery is at 20% capacity remaining (measure with no load on the battery).
  • Do not short the battery terminals; death and property damage will occur.
Please remember that working with power sources is dangerous. Follow all manufacturer instructions to the letter.

Jawbone Jambox Silent Mode

This is a great little device but I tend to leave the volume on full and control actual volume from my iPhone. So when I click on the talk/connect button in the morning the voice notification is very loud! Here's the answer to make your Jambox work in silent mode (with the latest software) but without using Mytalk to change the feature.

  1. Power OFF your Jambox
  2. Hold the TALK and MINUS buttons at the same time as powering ON your Jambox
  1. Power OFF your Jambox
  2. Hold the TALK and PLUS buttons at the same time as powering ON your Jambox
Enjoy silent and convenient use of your Jambox!

Central Texas Yard Maintenance

As anyone who lives in Austin TX knows... our summers are hot and water is in short supply. To make the most of your yard I have compiled a list of tips that will keep your grass healthy, happy, and more drought tolerant; leading to a vibrant spring when the next season arrives.

  • March 15th - cut + bag clipping, put down anti-fungal,
    and one of...
  • April 1st - cut + bag clippings
  • April 15th - begin cutting each week, do not bag, use side shoot to redistribute clippings
  • Aug/Sep - lift mower height by 1" and cut on a two week schedule to reducing "cut" stress.
  • Nov - drop mower 1" and stop cutting when the grass stops growing.
NOTE: Cut grass when dry only and with a sharp blade, never wet. If the grass blade is torn (not cut) then Chinch bugs and fungus attack, plus it takes longer to heal in high temperatures.

NOTE: Fungus (brown patch) will be your biggest problem... First sign of brown patch use anti-fungal granules. Remember anything that feeds the grass will feed fungus (manure & fertilizer)

NOTE: Always water as late in the morning as your schedule allows... Damp cold grass is vulnerable to fungus.

NOTE: Sharping your mower blade - get a standard metal file, rough on one side, smoother on the other.... Tip mower with air filter in the air (otherwise gas will flood your air filter - $15)... Unplug the spark plug (don't want it starting on you - $priceless). File the blade with rough then smooth... rotate and repeat. Put back on wheels, add spark plug, let sit for 10 mins before starting.

That's all there is to it! :-)

Please post tips and suggestions to the comments section.

Updated 4/27/2013 - Compost cow manure behaves differently to regular cow manure, I have updated the blog post accordingly. It appears my local stores have stopped selling regular cow manure!

Formula 1 Austin

I've had the chance to go to three Formula 1 race weekends and a MotoGP weekend. I hope you enjoy the pictures!

SSD and Windows 7

Context: My experience with a Dell E6410 migration from the old spin HDD to a new Intel SSD.

Results: Boot times are reduced significantly and launching "cold" a YouTube video takes 1-2 seconds instead of 20-25 seconds.

Note: I will provide updates to this post as I explore options and settings.

1) I am using a Intel 520 180GB SSD disc (Best Buy) and a SIIG SuperSpeed USB 3.0 to SATA 2.5" enclosure (Fry's).

2) "Clone" your hard drive using Acronis True Image... If your USB enclosure is not recognized - use "backup to a file" and "restore from a file".

3) Install the new SSD in your laptop and boot.

4) Disable the service named SuperFetch (Services)
  • Services program via Control Panel > Computer Management > Services.
  • Double click "SuperFetch".
  • Change the startup type to "disabled".
  • Click "stop".
  • Click "OK".
5) Set EnablePrefetcher and EnableSuperfetch to 0 at the following registry key:
  • HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Session Manager\Memory Management\PrefetchParameters
6) Disabled any scheduled disk defrag (right click on a drive > properties > tools > defrag now > turn on scheduled)

7) Disable ReadyBoot (ReadyBoost should already be disabled) as it causes unnecessary writes to the SSD.
  • Open the "Reliability and Performance Monitor" program via Control Panel > Computer Management > Performance.
  • Click "Performance > Data Collector Sets > Startup Event Trace Sessions"
  • Double click "ReadyBoot"
  • Select tab "Trace Session"
  • Uncheck "Enabled"
  • Click "OK"
8) Disable "System Restore" if you feel comfortable doing so - or have a hard drive image backup (like Acronis True Image) that you can roll back to in the event of system corruption.
  • Right click on My Computer and select Properties
  • Select System Protection
  • Select Configure
  • Select Turn Off System Restore
9) Firefox users:

10) Disable hard drive shutdown.
  • Go to Control Panel
  • Select System and Security
  • Select Power Options and Click the drop down for Show Additional Plans
  • Click Change "Advanced Power Settings"
  • Click the hard disk drop down option
  • Change Turn off hard disk after to 0 minutes (never)
  • Select OK and Save Settings
11) Disable hibernate to save hard drive write and you'll find boot times virtually identical:

  • Click Start, and then type cmd in the Start Search box.
  • In the search results list, right-click Command Prompt, and then click Run as Administrator.
  • When you are prompted by User Account Control, click Continue.
  • At the command prompt, type powercfg.exe /hibernate off, and then press ENTER.
  • Type exit and then press ENTER to close the Command Prompt window.
12) Windows Search Indexing does NOT need to be disabled. To enable/disable follow these steps:
  • Services program via Control Panel > Computer Management > Services.
  • Double click "Windows Search".
  • Change the startup type to "automatic" or "disabled".
  • Click "start" or "stop".
  • Click "OK".
13) Reboot your PC to experience better SDD write wearing compared to the native Windows behaviors.

14) Verify TRIM is working. Launch a command prompt (Start > Run > cmd.exe) and then:
  • Click Start, and then type cmd in the Start Search box.
  • In the search results list, right-click Command Prompt, and then click Run as Administrator.
  • When you are prompted by User Account Control, click Continue.
  • At the command prompt, type fsutil behavior query DisableDeleteNotify, and then press ENTER.
  • when DisableDeleteNotify is 0 TRIM is working
  • when DisableDeleteNotify is 1 TRIM is disabled

Faster Firefox Disk Performance (HD/SSD)

To improve your hard drive performance (spinning) and wear (SSD) consider increasing the auto-save interval for crash recovery and using a memory only cache instead of disk cache. As usual select the following about:config settings and make the highlighted changes.

Backyard Wildlife

Spring and summer in Central Texas brings a lot of yard friendly wildlife. Here are some pictures I've taken over the last month. I particularly like the rare Painted Bunting (male and female below) and our abundance of Humming Birds. Click to view the full album.


I've toyed with the idea of writing a sprite compiler when I stumbled across this neat bookmarklet called SpriteMe. This program analyzes a web page and builds the sprite and CSS semi-automatically. I may still write the compiler but for now I'm going to play with this.