Gettext’s bindtextdomain() ignoring directory

If you use strace on a program using the gettext internationalization library and you see something like the below.

open("/usr/lib/locale/ru/LC_MESSAGES", O_RDONLY|O_CLOEXEC) = -1 ENOENT (No such file or directory)

This means gettext is looking in the default locale directory which is /usr/lib/locale on my ubuntu machine. This was a bug for me because I had used bindtextdomain() to change the directory for the locale’s .mo files.

The cause for gettext ignoring my custom locale directory was that I had set my LANG enviromental variable to just the language code. For example LANG=ja

Instead LANG should be a full xx_CC format, for example:

LANG=ja_JP

You can check what your terminal’s locale environmental variables are set to use `locale`. An example of this is below.

danieru@danieru-x1:~$ locale
LANG=ja_JP.UTF-8
LANGUAGE=ja:en_CA:en
LC_CTYPE="ja_JP.UTF-8"
LC_NUMERIC=en_CA.UTF-8
LC_TIME=en_CA.UTF-8
LC_COLLATE="ja_JP.UTF-8"
LC_MONETARY=en_CA.UTF-8
LC_MESSAGES="ja_JP.UTF-8"
LC_PAPER=en_CA.UTF-8
LC_NAME=en_CA.UTF-8
LC_ADDRESS=en_CA.UTF-8
LC_TELEPHONE=en_CA.UTF-8
LC_MEASUREMENT=en_CA.UTF-8
LC_IDENTIFICATION=en_CA.UTF-8
LC_ALL=

Above was a correct and valid set of locale variables. What caused gettext to not find my translation’s .mo files was the following broken set.

danieru@danieru-x1:~$ locale
locale: Cannot set LC_CTYPE to default locale: No such file or directory
locale: Cannot set LC_MESSAGES to default locale: No such file or directory
locale: Cannot set LC_ALL to default locale: No such file or directory
LANG=ja
LANGUAGE=ja:en_CA:en
LC_CTYPE="ja"
LC_NUMERIC=en_CA.UTF-8
LC_TIME=en_CA.UTF-8
LC_COLLATE="ja"
LC_MONETARY=en_CA.UTF-8
LC_MESSAGES="ja"
LC_PAPER=en_CA.UTF-8
LC_NAME=en_CA.UTF-8
LC_ADDRESS=en_CA.UTF-8
LC_TELEPHONE=en_CA.UTF-8
LC_MEASUREMENT=en_CA.UTF-8
LC_IDENTIFICATION=en_CA.UTF-8
LC_ALL=

Bypassing ShawOpen Wifi’s Captive Portal

Shaw, a local cable monopoly, has started offering businesses a free wifi with free internet connection if they allow the installation of a public wifi access point. If you are a Canadian in the western provinces you might have seen these networks under the name “ShawOpen”. The term open in this case is misleading since only customers with shaw accounts can access the internet. The entire thing is a clever branding of the 2.4GHz frequency and businesses love being able to “offer” wifi with no cash out of their pocket.

 

Meanwhile I’m sitting here in the doctor’s waiting room and I am bit less enthusiastic over the ordeal. If Shaw wasn’t offering this service there is a good chance my doctor would be providing usable internet. Instead all I can do is poke around inspecting things.

 

There is more to inspect than initial impressions give. ShawOpen allows unauthenticated users to browse Shaw’s webportal and other Shaw owned web properties.

 

The easy bypass is through DNS which is unrestricted. While most protocols are blocked for unauthenticated users DNS requests are often not. In general restricted wifi access points do not restrict DNS because it requires setting up a special DNS server and isn’t the easiest solution. Since it is a common work around you can use iodine to proxy your traffic. To my discredit I don’t have a dns2ip proxy setup on my server so this is no use to me.

 

Instead with an unknown period of waiting ahead I set about inspecting those Shaw owned web properties. The best list for our needs is found at the bottom of Shaw Connect Lite. The full version of connect can be found here over the full internet. http://www.shawconnect.ca/ which also contains the list.

 

What you want to use for this task is either Firefox Development Tools or Chrome Development Tools. The panel of interest is the network connections tab. This will show what resources have been requested by the page.

 

What we want to find is a request which contains another url in the get parameters. These requests may be going to a proxy which is allowed to access the real interenet. You will find some false starts and will want to ignore anything going to Twitter or Facebook as these requests are for the social media buttons.

 

What you want is something like this: http://www.globaltv.com/images/blank.gif?size=100×70&src=http://media.globaltv.com/uploadedimages/content/shows/remedy/remedy_castdillon_400x500.jpg

Notice how it includes a full url to another domain. This is what you want to look for and there are a few of them on different accessible websites. This exact image proxy requires us to specify a size value in the get request but will accept 0x0 to skip resizing.

 

Thus allowing us to request: http://www.globaltv.com/images/blank.gif?size=0x0&src=http://www2.warnerbros.com/spacejam/movie/img/p-jamlogo.gif

In theory you could tunnel IP through these image proxies to your own proxy similar to how iodine functions. Of course it is more fun to find these loop-holes than use them so you may just want to do that.

How to gain root on HTM H10

The two cheap phones I ordered for porting Firefox OS have arrived. For far my favourite is the H10. This quick guide should also work for the HTM M1 with slight alterations.

This guide will show you how to install SuperSU and gain root. The entire process was easier than I anticipated.

Step 1: Download the latest version of Framaroot

Step 2: Copy the Framaroot apk to your phone

Step 3: Use your phone’s File Manager app to open the Framaroot apk you copied in step 2.

Screenshot_2014-01-22-09-59-56

Figure for Step 3.

Step 4: Android will have you verify the permissions Framaroot has requested. For our usage because Framaroot will exploit a permission escalation vulnerability it has access to all permissions despite only requesting photos. For this reason you must only ever install apks from sources you trust.

Screenshot_2014-01-22-10-00-11

Figure for step 4.

Step 5: My HTM H10 came with Android 4.2.2 which has an option to check apks against Google’s blacklist of apks. This blacklist should include Framaroot so you must select Disagree from the dialogue. In general this blacklist exists to protect us from malicious apps which might use the same exploit we need.

Screenshot_2014-01-22-10-00-25

Figure for step 5. If you see this remember to select Disagree.

Step 6: Framaroot is now installed but has not performed the exploit. Press Open to run Framaroot.

Screenshot_2014-01-22-10-00-45

Figure for step 6.

Step 7: As of writing the latest version of Framaroot is 1.8.1.apk. The only exploit version 1.8.1 knows which the H10 is still vulnerable against is the Boromir exploit. In the future Boromir should get fixed but new exploits should appear. Should must tap on the Boromir text to perform the exploit.

Screenshot_2014-01-22-10-00-49

Figure for step 7.

Step 8: Congradulations! The exploit should have worked but you must reboot your phone for it to take effect.

Screenshot_2014-01-22-10-00-54

Figure for step 8.

Let’s become Mozillians!

Mozilla is special. No organization that I know of is so effective, open, or stubborn.

Stubburn because when the world embraced patent encumbered H.264 & MP3 Mozilla turned around and said: “Okay, then we’ll just make an encoding better in every dimension.”.

And that’s the story behind Daala & Opus.

Mozilla is not the organization we deserve. We deserve no better than MPEGLA, Apple, Microsoft, SAP, Oracle, or Intellectual Ventures.

Mozilla is the organization we need.

When someone says “The web is not ready” we need people who are working to make it ready. We are not going to see the real web on mobile until we stick it there. We need a stubborn organization which will keep fighting for our freedom even after we’ve all locked our bootloaders with someone else’s key.

We need an organization which goes into the mobile fight not looking to monopolize yet another app ecosystem. We need someone to unlock apps so when regular people ask “Does it have X app?” the answer is: “Yes, because it supports webapps“. Only then can operating systems compete as equals without user’s sacrifice.

So that rant should give an accurate portrait of my motivation for contributing. If it also describes you then please do consider contributing as well. In either case please enjoy my story.

Our journey starts mid-July 2013, I have just gotten back from Microsoft after another day of my internship. The weather is warm, the sun is shining, and it hasn’t rained in at least five minutes. First order of business is to select my project preferences for the coming semester’s UCOSP.

Our product selection is pretty broad: a programming language, conferencing webapp, code review webapp, and a few more webapps I do not remember. All fine projects but I only had eyes for two: RIght-to-left language support in Android Firefox, and Plugins for BB10 Cordova.

During my internship at Microsoft I came to the descision upon two things: I want to work for a smaller organization, and I’d go crazy if I could not talk about my work in the open. Those realizations and my preference for open source mobile operating systems close to the top of my list.

Back to the selection: As a way to make connections the Android Firefox project sounded perfect. Thus it was my first choice. BB10 took second but only for its merits as a project matching my exact interests.

As it happened, the UCOSP organizers saw through my ploy and assigned me to BB10. Yet despite the organizer’s clear attempts at thwarting me, they forgot one thing: our hackathon was being hosted at Mozilla!

In fact it appeared as if the Undergraduate Capstone Open Source Project organizers had not shared with Mozilla their plan of keeping me away from Mozilla. You see at the hackathon Greg Wilson gave everyone a tour of the new Toronto office: a modern and wonderful work environment on full display! Everyone was envious, including myself. Greg was even kind enough to give me his email!

With email in hand I went home to Calgary and worked. I worked so hard I mis-placed the email. That’s my story and I’m sticking to it!

With no email I took a long shot and asked the UCOSP organizers. They must have thought I was someone else because they give me Greg’s email without a fight. Now with email in hand for real I could email Greg asking how to apply.

And then I mis-placed the email again…

Just joking. Greg was encouraging and cc’d Mike Hoye, also of Mozilla, who gave fantastic general career advice plus good Mozilla specific advice. The advice is so good we should take a moment to read it together:

Don’t let anyone pressure you with what’s called an “exploding offer” – anyone who’s telling you that their offer is off the table after a certain date is just trying to fill chairs, and trying to scare you into accepting a job where you’ll be deeply undervalued. People who actually want to hire you _for you_ will, within reason, wait for you to make up your mind.

Finish UCOSP. Ship. Blog about shipping. Spin up a Mozilla build environment, go to http://www.whatcanidoformozilla.org/ and wander through it until you find a bug you want to fix, and then work your way through the process for fixing it. Ship that, and blog about that.

Then come and talk to us; let me know when you’re applying, and let the people you’ve collaborated with on that bug know you’re applying.

Unrelated to Mozilla, a colleague of mine ran this talk for Seneca last year: https://senema.senecac.on.ca/videos/1958/fsoss-2012-open-soucre-careers

It’s called “Open Source Careers”, typo in the URL aside, and you should watch it.

Thanks,

– mhoye

Just to make sure you understood please repeat after me: You should goto http://www.whatcanidoformozilla.org/ and find a cool project. Right now. I’ll wait for you. I’ll be right here when you get back.

Back?

I suspect you’re lying, instead just kept reading right? This is serious you should goto http://www.whatcanidoformozilla.org/, select a project and head over to BugsAhoy for a selection of mentored new contributor friendly bugs.

Promise me you’ll at least open the links and press 2 buttons. Just 2, not 3, only 2. Please? I’ll stay here and drink some tea.

IMG_20140110_213327

I promise you green tea which is the color green: is good green tea. The cookies are also pretty good.

Back for real? Okay I’ll trust you.

Now I should caution that the pain I encountered with the development environment I encountered is not something an app developer will encounter. With the disclaimer complete I must admit I’ve bricked one (1) phone. You see developing apps for FxOS is fast and easy but compiling an entire operating system is a bit more complex.

Before I could do anything I needed a phone so I ordered the recommended and cheap ZTE Open from ebay. While waiting for the phone’s arrival I experimented with FxOS’s QEMU based virtual machine, which I did not succeed at.

When I did receive the phone I set out at once to blog about it. Looking back I’m a bit ashamed, almost all of the issues I identified had already been reported. I should have searched for reports ahead of time so I could point out how things had been fixed. Instead at least one reader got the impression I hated FxOS.

On that note, my attempts at compiling for the ZTE Open have bricked it. The issue is well reported on the mailing list but I’m happy to report that ZTE is working on it.

Instead I’ve been developing on an old Nexus S. The odd thing is my build images have been using ZTE Open’s system backup. By no rights should my Nexus S be anything but bricked. Since the environment is working, I’ve avoided “fixing” this oversight.

With a working build environment I did what you just did: found a cool mentored bug from BugsAhoy. Right at the top of BugsAhoy’s list for firefox os mentored bugs was Bug #939372. This bug stood out as being perfect: low-level, C++, and self-contained.

The exact issue with bug #939372 was that Firefox OS logged all kernel out-of-memory messages via a shell script running as root. Dave Hylands’s suggested solution was to write a new program which could open the kernel log as root but then drop all root permissions unrelated to reading the kernel log.

So I wrote a first attempt at such a program. Perhaps the biggest pain was the permissions dropping. Being a stand-alone program I wanted to avoid bringing in a library dependency. This meant writing against linux’s system call interface. You might have noticed that this is Very Bad Thing™ to do. In this specific case, it was acceptable because the program was to go into FxOS’s hardware abstraction layer. Still, for any kids reading at home please do not attempt this, double so for Windows™®©☘ specific code.

At this point I started hanging out on the Mozilla IRC channels. Now I’m going to show you some links but please do not open them. Please, this is serious and not reverse physiology. –Begin Dangerous Links– Mozilla funny quote database and Mozilla memes. –End Dangerous Links– How dangerous you might wonder? I just wasted 10 minutes reading jokes I’ve read before!

The real IRC conversations are less exciting than the highlights. You may see more Qdot… flavour. For the most part, you’ll overhear people debugging and assisting others. Altogether Mozilla appears to be use IRC to be productive and less about in-jokes.

A bit prior to joining IRC, I did subscribe to the Mozilla mailing lists. These lists are pretty easy to follow and much lower flow than the Linux Kernel Mailing list. The two lists I’ve subscribed to, b2g & gaia, give a good feel for FxOS’s direction. I’ve also noticed that Mozillians are nice to a fault and will respond at face value to even “worthless” email. I’m not sure it’s even possible to write something inane enough to get called out upon. That’s an impressive community wide commitment to being a friendly community!

Back to bug #939372 Dave Hylands has now reviewed my attempt at the stand-alone logger. Along with my patch I asked a few questions. After some discussion, Dave brought in Michael Wu for an opinion. Michael suggested we move logging into the main b2g process. Since this would save me the permissions dropping mess, I had few protests.

Here’s where Dave’s mentoring saved the day: he pointed me to the exact line where to add the logging. It may sound like a small help but FxOS is huge and without his guidance I would have been stuck.

Then Dave gave me eight high quality code reviews, one after the other. Each time he identified real issues with my code. I got the impression he cared about the patch just as much as I did. He even found an issue with the Unagi’s kernel logging which I could not have found: the unagi’s kernel had been patched to format message timestamps in human readable time and not seconds since boot.

At the end of this process I can say with a smile and confidence that I’ve never before participated in a more thorough code review. It is nice to have another programmer dedicate their time to helping you. Dave went out of his way to make Firefox less intimidating and I do not want to imagine how lost I would have been without his help.

This entire process occurred out in the open, you can read it all here on the bug report itself: https://bugzilla.mozilla.org/show_bug.cgi?id=939372 In fact in the beginning I had emailed Dave in private. In the spirit of being open Dave encouraged me to bring the full conversation to the bug report.

It’s small things like encouraging public communication, which make me think open by default is not just a saying at Mozilla. The entire organization lives open by default, you can even attend one of the weekly team meetings. Even if you do not have anything to say you might enjoy just listening. I once attended the B2G meeting and was greeted with an in-depth and geeky discussion of quadcopter kits and microcontrollers.

Now I hope this story has sparked some envy in you. Contributing to FxOS is fun and less work than you’re expecting. Remember that website I harassed you into visiting: http://www.whatcanidoformozilla.org/ ? This would be a perfect time to find yourself an approachable mentored bug and take your first step to becoming a Mozillian.

If nothing else it is now safe to checkout the meme and quotes databases.

 

Exciting Systems Software & Trends as of January 2014

This semester my high level goal is to get a junior position as a systems programmer. In fact right now I should be writing a different post related to this search. Instead my mind has wandered towards why systems software excites me.

In a way this post is a late response to something a co-workers asked over the summer at my Microsoft internship. He wanted to know why I wanted to work in such a “solved domain” as operating systems. You see at Microsoft maintaince is handled by a seperate sub-division from new feature development. Thus within our sub-division the work centred around fixing crashes and patching vulnerabilities.

This to be a dig at Windows and I hope he will not regret expressing his question. Instead the question was something I could not answer to my satisfaction at the time. If anything I must admit that Windows does not excite me but this could just be a factor of how there are no interesting blog posts documenting Window’s development.

From the beginning what has excited me about operating systems is the software.

This list is an attempt to summarize some of those interesting software projects or trends.

BTRFS

Long in development BTRFS has been promised to replace EXT4 as Linux’s default file system. If or when that switch does occur the transition should be smooth. You see BTRFS supports transparent migration from EXT4. Even better this migration is reversible. BTRFS keeps the original EXT4 on disk layout and will write new files in the old free space. At any time you can make the transition permanent by releasing the old EXT4 data structures to BTRFS.

F2FS

A modern file system is built on a castle of lies. The hard disk pretends to have N sectors of M blocks of W bytes. The disk will even lie to the OS about writing data to the platter when the data is only in cache. In simple terms: None of what the HDD tells the OS is true. With the advent of solid state disks these lies drop all pretences of reality. To this end Samsung has developed Flash-Friendly File System which exposes deep configuration knobs. With this configuration F2FS can match its behaviour to  that of the flash chip’s and microcontroller’s. The net result is a file system which shows promise. With proper tuning it appears F2FS can fly as seen on the Moto G.

ASM.js

To call ASM.js systems software I must confess my bias towards the web as a application platform. ASM.js is not a new VM or a new language. Instead I consider it a promise. A promise from javascript enginer developers that your ASM.js code will be fast. Already javascript is supposed to be fast but there are always edgecases. Without knowing you can make a hard to optimize javascript program. Before ASM.js why and how you’ve killed performance was opaque. Now with ASM.js we can give warnings and point you towards wiki pages. You can now optimize your inner loop without guessing or reading JS engine source code.

Sandboxing

Every major operating system is making moves towards sandboxing their ecosystem: Windows has Metro, Mac OS X has Mac Store. Meanwhile the mobile operating systems have all been sandboxed since birth. Sandoxing is even getting popular on linux with Docker. In effect sandboxing is the big red button for security. It brings the benefits of SELinux or AppArmor without the configuration. It assumes the applications are malicious and distrusts them. This distrust will frustrate developers used to being trusted. For this reason I am thankful the web has always been sandboxed: no one ever complains their webapp cannot write to the user’s home directory.

Internet Printing Protocol Everywhere

If anything in computing has a bad reputation it is printing. This reputation is well deserved. Now thanks to the mobile computing revolution the printer vendors have come together with the Apple, Linux, and Windows printing guys to create IPP Everywhere. This new standard reuses existing software and existing protocols to bring the holy grain of printing protocols: configuration-less printing. You might have also heard this goal under the name of driver-less printing. This second term is less accurate since we still have drivers but now all the drivers are generic. IPP Everywhere defines a basic raster format all compatible printers and operating systems must support. From there it also requires PDF and JPEG for capable printers.

Of course before you can print your computer must know about the printer. For discovery IPP Everywhere provides both Apple’s Bonjour (used by linux with Ahavi) and Window’s WS-Discovery. The amazing thing is the printer vendors are the ones volunteering to implement both protocols. We on the operating system side can continue using our existing stack!

Now while IPP Everywhere lays our foundation you might be wondering if it can reach wide adoption. You might recognize this situation from  XKCD #927. For now we only have hope to bet on. In private I’ve been told some encouraging news but you’ll have to wait another few months to hear it.

Disclaimer

Listed above is what I find interesting. My interests might differ from yours. You may even hate systems software and that’s fine. System software just happens to be where I’ve focused and I appreciate those working at different levels of the stack.