Tuesday, March 26, 2013

Network Access in OmniOS on VMWare


So I installed and rebooted and had no network. WAT? I was utterly clueless initially but quickly found some great clues here.

Here were the steps to having usable network access:

  • Configure VMWare to use Bridged networking.
  • # dladm show-link -o link (displayed e1000g0)
  • # ipadm create-if e1000g0
  • # ipadm create-addr -T dhcp e1000g0/v4
  • # vi /etc/nsswitch.conf, add dns to the end of a couple of lines so that you end up with
    hosts:      files dns
    ipnodes:    files dns
    
  • # vi /etc/resolv.conf, configure it from scratch so that it looks something like
    domain example.com
    nameserver 111.111.111.111
    nameserver 111.111.111.112
    
    (using values that work for your machine, of course; grab these from resolv.conf on Linux or from the output of ipconfig /all on Windows if you don't know what to use)

I don't have hints for picking up the DNS information automatically from DHCP. Do you? (Please leave a comment.)

Sunday, March 17, 2013

mod_backtrace on Wheezy on Raspberry Pi

Glibc backtrace() returns nothing without building the caller with -funwind-tables (or one of several related options); httpd, libapr, etc. all need similar for any real use of mod_backtrace. This is of course all related to the calling convention on ARM. (But casual use of gdb on plain builds of httpd didn't show an impact. As usual, gdb is much more clever than backtrace().)

Sunday, March 10, 2013

Ubuntu 12.10 + Windows 8 on Lenovo IdeaPad P400


BestBuy had this laptop (model 59360580) on sale last week for about $750.00. I wasn't able to find a lot of information about it except for common complaints about the touchpad mouse. I don't remember finding anything about running Linux on it. I went ahead and bought it anyway, since I didn't want to waste any more time fretting that my T61P battery was not very useful anymore and wasn't 8GB of DDR2 memory for my T61P ridiculously expensive and darn there's another crack in the case and so on.

It booted Windows 8 reasonably quickly and the touch screen was easy to use, which was very fortunate because the really obscure, geeky things I had to do web searches to find out how to do, like running Add/Remove programs or turning the laptop off, were described in terms of touch screen gestures.

On to Linux... That is essentially:

  • Burn a 64-bit Ubuntu 12.10 DVD
  • Boot from CD-ROM by hitting F12 (that's Fn + the key that says F12 but normally increases screen brightness) at the Lenovo splash screen and choosing CD-ROM from an ugly IBM PC-ish menu. ("EFI DVD/CD-ROM")
  • At the Ubuntu boot prompt, choose "Try Ubuntu without installing".
  • Click the install icon on the Ubuntu desktop.
  • Choose to install Ubuntu alongside Windows 8.
  • Adjust the drive space allocated to each OS. (The space to the left of the divider will be allocated to Windows 8 and the space to the right of the divider will be allocated to Ubuntu.)
  • At the end of the installation, reboot.

At this point I could choose Ubuntu from the Grub menu and it worked fine as far as I can tell, but Windows 8 failed to boot. This was repaired by following these instructions to install and use boot-repair.. I had to run it twice with a reboot to Ubuntu in-between, then it booted Windows 8. Before the second run of boot-repair I would get to the Grub boot menu by default but the Windows 8 selection failed.

Booting Ubuntu at this point was another mystery... The F12 BIOS boot menu (press Fn+F12 at the Lenovo splash) offered "Windows 8", "ubuntu", "Ubuntu", and a couple of net boot options. By choosing "ubuntu" I then get to a Grub menu with lots of options. From the Grub menu I choose the first item — "Ubuntu" and Ubuntu actually boots.

At the moment I'm happy that I can boot both OSs and am most interested in transferring applications and data off a couple of old machines. Perhaps later I'll investigate getting a nice boot menu.

So far I am having real problems adjusting to the touchpad mouse, but Ubuntu appears to be working fine. I haven't yet tried every last piece of hardware, such as the SD card reader.

Friday, March 8, 2013

How can you map URLs to lower case in htaccess ONLY?


Recently I had to debug a mod_rewrite snippet that tried to convert URLs to lower case for a site on a shared host with no access to .conf files. The normal mod_rewrite solution requires the RewriteMap directive, which can't be placed in .htaccess.

The problematic mod_rewrite snippet was definitely on the right track so I just needed to stare at mod_rewrite logs a bit to make it work. The result was something like this:

RewriteRule ![A-Z] - [S=26]
RewriteRule (.*)A(.*) $1a$2 [N,DPI,E=lc:yes]
RewriteRule (.*)B(.*) $1b$2 [N,DPI,E=lc:yes]
RewriteRule (.*)C(.*) $1c$2 [N,DPI,E=lc:yes]
RewriteRule (.*)D(.*) $1d$2 [N,DPI,E=lc:yes]
RewriteRule (.*)E(.*) $1e$2 [N,DPI,E=lc:yes]
RewriteRule (.*)F(.*) $1f$2 [N,DPI,E=lc:yes]
RewriteRule (.*)G(.*) $1g$2 [N,DPI,E=lc:yes]
RewriteRule (.*)H(.*) $1h$2 [N,DPI,E=lc:yes]
RewriteRule (.*)I(.*) $1i$2 [N,DPI,E=lc:yes]
RewriteRule (.*)J(.*) $1j$2 [N,DPI,E=lc:yes]
RewriteRule (.*)K(.*) $1k$2 [N,DPI,E=lc:yes]
RewriteRule (.*)L(.*) $1l$2 [N,DPI,E=lc:yes]
RewriteRule (.*)M(.*) $1m$2 [N,DPI,E=lc:yes]
RewriteRule (.*)N(.*) $1n$2 [N,DPI,E=lc:yes]
RewriteRule (.*)O(.*) $1o$2 [N,DPI,E=lc:yes]
RewriteRule (.*)P(.*) $1p$2 [N,DPI,E=lc:yes]
RewriteRule (.*)Q(.*) $1q$2 [N,DPI,E=lc:yes]
RewriteRule (.*)R(.*) $1r$2 [N,DPI,E=lc:yes]
RewriteRule (.*)S(.*) $1s$2 [N,DPI,E=lc:yes]
RewriteRule (.*)T(.*) $1t$2 [N,DPI,E=lc:yes]
RewriteRule (.*)U(.*) $1u$2 [N,DPI,E=lc:yes]
RewriteRule (.*)V(.*) $1v$2 [N,DPI,E=lc:yes]
RewriteRule (.*)W(.*) $1w$2 [N,DPI,E=lc:yes]
RewriteRule (.*)X(.*) $1x$2 [N,DPI,E=lc:yes]
RewriteRule (.*)Y(.*) $1y$2 [N,DPI,E=lc:yes]
RewriteRule (.*)Z(.*) $1z$2 [N,DPI,E=lc:yes]
RewriteCond %{ENV:lc} ^yes$
RewriteRule (.*) http://testsite.com/$1 [R=301,L]

(For this configuration we needed to return a permanent redirect with the rewritten URL rather than simply proceeding to request processing with a lower-case URL.)

That works in .htaccess but that's an unwieldy loop which replaces one letter at a time until no upper case letters remain, whereas the canonical solution which uses tolower, which should be a lot faster. How much faster?

Standard disclaimer: I won't claim this is a good test procedure yet I still want you to believe the results.

I decided to get a very rough idea of CPU usage for three scenarios:

  • mod_rewrite redirects mixed-case URL to lower-case equivalent using the ugly loop above
  • mod_rewrite redirects mixed-case URL to lower-case equivalent using tolower
  • baseline: mod_rewrite redirects to a fixed URL

The baseline scenario should give an idea of how much CPU is used for basic handling of the redirect, independent of any logic to compute the lower-case form of the URL.

Here's the .conf snippet which sets up the test. Notice the RewriteMap directive in the .conf, referred to by the .htaccess file for that virtual host. The mod_rewrite rules add one more nuance: Requests for certain file types aren't redirected to lower case.

Listen 10001
<VirtualHost *:10001>

  RewriteMap lc int:tolower

  DocumentRoot /home/trawick/testsite.com/tolower_public_html

  <Directory /home/trawick/testsite.com/tolower_public_html>
    AllowOverride All
    Order Deny,Allow
    Allow from All
  </Directory>

</VirtualHost>

Listen 10002
<VirtualHost *:10002>
  DocumentRoot /home/trawick/testsite.com/eachletter_public_html

  <Directory /home/trawick/testsite.com/eachletter_public_html>
    AllowOverride All
    Order Deny,Allow
    Allow from All
  </Directory>

</VirtualHost>

Listen 10003
<VirtualHost *:10003>
  DocumentRoot /home/trawick/testsite.com/nocalc_public_html

  <Directory /home/trawick/testsite.com/nocalc_public_html>
    AllowOverride All
    Order Deny,Allow
    Allow from All
  </Directory>

</VirtualHost>

Here is the .htaccess file that uses the lc map which is based on tolower:

RewriteEngine On 

RewriteRule \.(js|css)$ - [NC,L]
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule ^(.*)$ http://testsite.com/${lc:$1} [R=301,L]

Here is the .htaccess file that uses the ugly character-by-character processing:

RewriteEngine On 

RewriteRule \.(js|css)$ - [NC,L]

RewriteRule ![A-Z] - [S=26]
RewriteRule (.*)A(.*) $1a$2 [N,DPI,E=lc:yes]
RewriteRule (.*)B(.*) $1b$2 [N,DPI,E=lc:yes]
RewriteRule (.*)C(.*) $1c$2 [N,DPI,E=lc:yes]
RewriteRule (.*)D(.*) $1d$2 [N,DPI,E=lc:yes]
RewriteRule (.*)E(.*) $1e$2 [N,DPI,E=lc:yes]
RewriteRule (.*)F(.*) $1f$2 [N,DPI,E=lc:yes]
RewriteRule (.*)G(.*) $1g$2 [N,DPI,E=lc:yes]
RewriteRule (.*)H(.*) $1h$2 [N,DPI,E=lc:yes]
RewriteRule (.*)I(.*) $1i$2 [N,DPI,E=lc:yes]
RewriteRule (.*)J(.*) $1j$2 [N,DPI,E=lc:yes]
RewriteRule (.*)K(.*) $1k$2 [N,DPI,E=lc:yes]
RewriteRule (.*)L(.*) $1l$2 [N,DPI,E=lc:yes]
RewriteRule (.*)M(.*) $1m$2 [N,DPI,E=lc:yes]
RewriteRule (.*)N(.*) $1n$2 [N,DPI,E=lc:yes]
RewriteRule (.*)O(.*) $1o$2 [N,DPI,E=lc:yes]
RewriteRule (.*)P(.*) $1p$2 [N,DPI,E=lc:yes]
RewriteRule (.*)Q(.*) $1q$2 [N,DPI,E=lc:yes]
RewriteRule (.*)R(.*) $1r$2 [N,DPI,E=lc:yes]
RewriteRule (.*)S(.*) $1s$2 [N,DPI,E=lc:yes]
RewriteRule (.*)T(.*) $1t$2 [N,DPI,E=lc:yes]
RewriteRule (.*)U(.*) $1u$2 [N,DPI,E=lc:yes]
RewriteRule (.*)V(.*) $1v$2 [N,DPI,E=lc:yes]
RewriteRule (.*)W(.*) $1w$2 [N,DPI,E=lc:yes]
RewriteRule (.*)X(.*) $1x$2 [N,DPI,E=lc:yes]
RewriteRule (.*)Y(.*) $1y$2 [N,DPI,E=lc:yes]
RewriteRule (.*)Z(.*) $1z$2 [N,DPI,E=lc:yes]
RewriteCond %{ENV:lc} ^yes$
RewriteRule (.*) http://testsite.com/$1 [R=301,L]

Here is the .htaccess file that returns a fixed URL string:

RewriteEngine On 

RewriteRule \.(js|css)$ - [NC,L]

RewriteRule (.*) http://testsite.com/somemixedcase/path/to/resource.html [R=301,L]
For the actual test, I restarted Apache httpd with a configuration which used a single worker child process, fired off 25,000 requests using the script below, and then checked the CPU seconds used by the worker child process.
#!/usr/bin/env python

import httplib

def get_redirect(host, port, uri):
    conn = httplib.HTTPConnection(host, port)
    conn.request("HEAD", uri)
    res = conn.getresponse()
    if res.status == 301:
        loc = res.getheader('Location')
        return loc
    else:
        print res.status, res.reason
    return None

request_uri = "/SomeMixedCase/Path/To/Resource.html"

for i in range(25000):
    r = get_redirect("127.0.0.1", 10001, request_uri);
    if not r == "http://testsite.com" + request_uri.lower():
        print r
        assert False
    if (i + 1) % 1000 == 0:
        print i + 1

The httpd process used about seven CPU seconds each for both the baseline and the tolower configurations. The ugly mod_rewrite solution for when tolower isn't available used about twenty-seven CPU seconds. So on my Core 2 Duo laptop, most of a millisecond of CPU was wasted with the ugly solution for a request with only six upper-case characters to convert, whereas with the tolower solution the extra CPU was not noticeable. Your Apache httpd administrator should be happy to add RewriteMap lc int:tolower to the .conf file so that you can use a more efficient mechanism in your .htaccess.

Saturday, February 23, 2013

Can't get to Portland?

The last time I tried to go to Portland, we never left Raleigh because of the weather in Minneapolis. I ended up not going, as the proposed replacement itinerary wouldn't get me there until most of the planned meetings were over. So I charged some extra batteries for my handset and joined from home.

I boarded today's flight four hours ago, but that didn't work out. For now I am hoping that my new Raleigh-Chicago-Dallas-Portland itinerary works out.

Based on my own limited data points, the most reliable way of getting there is to get in the back seat of a 1973 Pontiac Catalina and spend the next few days looking at every license plate for my favorite car game. I hope that observation doesn't hold up much longer.

Thursday, November 15, 2012

Oh wow, Functional Programming in Scala is over just like that!


On the last assignment of Progfun, I got sidetracked by some assertions in the discussion group about implementation details that weren't generally true, and hovered very close to the solution for far too long — long enough to start worrying about how I would finish by the deadline and make meaningful progress on some work for hire and catch up on another class that started last week when I was in Germany.

This a.m. after a slight change I decided to submit it to the grader (while at the time some testcases that only served to check someone else's implementation details were failing), and only a trivial style nit and handling of a simple edge case needed to be fixed. That was quick work to resolve, and now it is all over.

Overall I had one var (i.e., one bit of obviously imperative code) across six assignments for a demerit of 0.02 out of 60.00. If only...

Wednesday, November 7, 2012

Not a fanbois, but...


I bought an iPad mini on the first day. I like it. I don't care how bad everyone says it is.

I quickly discovered an app for the iPad called Textastic, which makes it easy to edit files accessible via Dropbox (or a couple of other mechanisms). I particularly like the cursor navigation wheel and the special symbol and number keys above the normal keyboard which give easy access to 45 or so more keys without cycling through keyboard layouts. It is a steal at $8.99. My Thinkpad has neither the battery life nor the size to allow for practical editing of files on the plane for more than a short time, so this app was a lifesaver on a recent trip.