Archive for the ‘software’ Category

Why Do Long Options Start with Two Dashes?

August 2, 2019

Around 1990, Richard Stallman (RMS) and I were writing the GNU C library getopt() and he wanted to extend it to support long (multi-character) option names for user-friendliness. He considered Unix inferior in this regard to other operating systems such as TOPS-20 which supported long options (that could be abbreviated). He wanted GNU to be better than Unix while still compatible. There were a few programs that ran on Unix systems and used long option names starting with either - or no prefix at all, such as find, but those syntaxes were not compatible with Unix getopt() and were parsed by ad-hoc code.

Long options needed a prefix that wouldn’t clash with the Unix conventions, so programs could support both types of options without ambiguity. Richard chose +, since logically if - (for a small number mathematically) is for short options then + would be for long options, and it’s no additional typing. We created an extended interface called getopt_long() to support specifying long options.

But when the IEEE POSIX shell and utilities standard was published in 1992, the + syntax was disallowed. GNU developers discussed what to do over email. We considered -+ as the long options prefix, but that was hard to type, so we settled on --, which wouldn’t violate POSIX or Unix compatibility and wasn’t hard to type.

For a few months, GNU getopt() supported both + and -- to allow time for people to transition their scripts. I’m pretty sure support for + during that transition could be disabled by setting the environment variable POSIX_ME_HARDER (RMS’s exasperation with standards showing there), later changed to the more polite POSIXLY_CORRECT, which also disables recognizing options intermixed with positional arguments.

Because GNU software was popular and the solution was logical, everyone else adopted the -- prefix and implemented variations of it in their own argument parsers. Perl was probably one of the first.

Sharing a Printer from Mavericks to Windows

January 14, 2015

Every few years I have to figure out a new way to share a Mac’s printer with Windows PCs. The printer is connected to a Mac with USB and shared using System Preferences>Sharing>Printer Sharing.

Apple provides Bonjour Print Services for Windows as a free download. It starts a service that discovers printers using the Zeroconf protocol, of which Apple’s implementation is called Bonjour (formerly Rendezvous before they lost a trademark dispute). It works great on Windows XP. But on Windows 7, Apple’s Bonjour service (as of version 2.0.2, which hasn’t been updated in years) is flaky, spewing tons of error messages to the event log and frequently losing the connection to the printer. I had to give up on it (and that’s without a Windows firewall getting involved).

When the Mac with the printer was running Snow Leopard (10.6), I could add the printer on Windows 7 using Control Panel>Hardware and Sound>Devices and Printers>Add a printer>Add a local printer>Create a new port>LPR Port and then entering the hostname or IP address of the Mac and the CUPS printer queue name (which the lpq command in Terminal shows). Snow Leopard shares the printer using the Unix LPD (also called LPR) protocol, among others.

When I upgraded the Mac to Mavericks (10.9), I found that it wasn’t listening on the LPD port. After a lot of research, I discovered that support for LPD printer sharing is included in Mavericks but disabled by default. Here is how to enable it.

Open a Terminal window.

sudo launchctl load -w /System/Library/LaunchDaemons/org.cups.cups-lpd.plist

Type your password. Your Mac should now be listening on the LPD port. If you have its firewall enabled in System Preferences, you might need to open the LPD printer port (TCP port 515) in the firewall. Now printing to it from Windows should work.

The load -w option forces the service to be enabled. If you want to more clearly mark it as enabled, you can:

sudo bash

Edit /System/Library/LaunchDaemons/org.cups.cups-lpd.plist using a text editor like vi or nano.

Under the Disabled key, change the “true” to “false”, then save the file and exit the editor.

All of this probably applies to Yosemite (10.10) too, but I haven’t tested that, or Windows 8 or Vista.

From Novice to Master, and Back Again

January 14, 2013

In 1985, I was a freshman at St. Olaf College in Minnesota. The college had a VAX 11/780 running 4.2BSD and a PDP-11/70 running v7 with some Berkeley and local code hacked in. It was my first experience with multi-user systems other than dialing into an MS-DOS BBS or two.

The college’s Academic Computing Center had printouts of the 4.2BSD manuals, plus some home-grown documentation, available for sale so students could learn how to use UNIX. One week I sat in the Science Center terminal room and started going through the alphabetical list of the commands available on the VAX, trying each one and reading its man page to learn what it did.

Eventually I got to “su”. “Become the super-user”? What’s that? Does it involve wearing a cape? Sounds interesting, so I tried it. To my disappointment, it just asked for a password, and wouldn’t do anything.

Shortly thereafter, someone came running into the room and asked, “Are you David MacKenzie? Did you just run ‘su’?” “Yeah… what does it do?” “Uh, don’t do that.” My failed “su” attempt had been logged on the system console and one of the sysadmins was worried about an attempted breakin.

Within a year, I did have root access on the VAX, as I learned enough to be hired as a student system programmer. I contributed to upgrading the machine to 4.3BSD when that was released.

Recently I was working on a CentOS Linux virtual machine and needed to look up the command-line options to “su”. I had worked for the past several years mostly on Macs where “sudo” is preferred, so my “su” skills were rusty. I ran “man su” and got the information I needed. Then at the bottom of the screen I sheepishly read “Written by David MacKenzie.”

In the 1990s, while filling in gaps in the GNU toolset, I wrote the GNU “su”, and I had forgotten about it. It’s still what Red Hat and other distributions are shipping.

At least I know what it does now.


Design a site like this with WordPress.com
Get started