2012-04-09

TLPI third print run now available

I'm happy to announce that the third print run of TLPI is now printed, and should be available for sale shortly. The third print run incorporates these 131 errata shown on the errata page. (If that seems like a lot of errata, take a look at this FAQ.)

2012-03-13

Kernel capability usage statistics

(Update: 2012-07-16: I wrote a related article for this blog post, "CAP_SYS_ADMIN: the new root" that was published on LWN.net on 2012-03-14.)

The idea of capabilities is to break the power of root (user ID 0) into independently assigned pieces governing specific privileged operations. Implicit in that model is that the set of privileged operations governed by each capability should be small (otherwise, why break the power of root into pieces at all?). However, that implication hasn't turned out to be true in practice.

Table 1 shows some statistics on the use of the 36 currently existing capabilities in the C files of the Linux 3.2 kernel source code. The "#uses" column is the number of uses of the capability across all source files; the "#files" column is the number of distinct source files where the capability is used.

Table 1: Breakdown of Linux capability uses in Linux 3.2
Capability#uses#files
CAP_AUDIT_CONTROL22
CAP_AUDIT_WRITE11
CAP_CHOWN42
CAP_DAC_OVERRIDE21
CAP_DAC_READ_SEARCH42
CAP_FOWNER98
CAP_FSETID86
CAP_IPC_LOCK138
CAP_IPC_OWNER11
CAP_KILL22
CAP_LEASE11
CAP_LINUX_IMMUTABLE1313
CAP_MAC_ADMIN255
CAP_MAC_OVERRIDE62
CAP_MKNOD33
CAP_NET_ADMIN395182
CAP_NET_BIND_SERVICE1310
CAP_NET_BROADCAST00
CAP_NET_RAW1811
CAP_SETFCAP32
CAP_SETGID106
CAP_SETPCAP22
CAP_SETUID84
CAP_SYS_ADMIN451229
CAP_SYS_BOOT22
CAP_SYS_CHROOT11
CAP_SYSLOG22
CAP_SYS_MODULE43
CAP_SYS_NICE148
CAP_SYS_PACCT11
CAP_SYS_PTRACE116
CAP_SYS_RAWIO6742
CAP_SYS_RESOURCE3624
CAP_SYS_TIME2213
CAP_SYS_TTY_CONFIG114
CAP_WAKE_ALARM21
Total1167610

What is of course notable is the extremely heavy use of  two capabilities: CAP_SYS_ADMIN and CAP_NET_ADMIN. Together, these two capabilities account for more than 70% of all uses of capabilities! The uses of CAP_NET_ADMIN are limited to the drivers/ (mainly drivers/net/) and net/ directories. On the other hand, the uses of CAP_SYS_ADMIN, which accounts for nearly 39% of all capability uses, are spread widely across the kernel source tree.

One might wonder whether either of these two capabilities is overrepresented because of duplications in the drivers/ or the arch/ trees. (In particular, CAP_SYS_ADMIN is used for similar administrative functions on a lot of device drivers.) However, even if we strip drivers/ and architectures other than x86 from the measurements, the overall picture doesn't change greatly, as shown in Table 2.

Table 2: Breakdown of Linux capability uses in Linux 3.2, excluding drivers and architectures other than x86
Capability#uses#files
CAP_AUDIT_CONTROL22
CAP_AUDIT_WRITE11
CAP_CHOWN42
CAP_DAC_OVERRIDE21
CAP_DAC_READ_SEARCH42
CAP_FOWNER98
CAP_FSETID86
CAP_IPC_LOCK116
CAP_IPC_OWNER11
CAP_KILL11
CAP_LEASE11
CAP_LINUX_IMMUTABLE1313
CAP_MAC_ADMIN255
CAP_MAC_OVERRIDE62
CAP_MKNOD33
CAP_NET_ADMIN16773
CAP_NET_BIND_SERVICE129
CAP_NET_BROADCAST00
CAP_NET_RAW1811
CAP_SETFCAP32
CAP_SETGID95
CAP_SETPCAP22
CAP_SETUID84
CAP_SYS_ADMIN16780
CAP_SYS_BOOT22
CAP_SYS_CHROOT11
CAP_SYSLOG22
CAP_SYS_MODULE43
CAP_SYS_NICE126
CAP_SYS_PACCT11
CAP_SYS_PTRACE105
CAP_SYS_RAWIO109
CAP_SYS_RESOURCE2618
CAP_SYS_TIME42
CAP_SYS_TTY_CONFIG11
CAP_WAKE_ALARM21
Total552291

CAP_SYS_ADMIN still accounts for 167 of 552 uses of capabilities--about 30%, and, by chance, usage of CAP_NET_ADMIN is the same.

It turns out that the overall picture hasn't changed that much since capabilities were first introduced with Linux 2.2 (Jan 1999). Then, there were 27 capabilities, broken down as shown in Table 3.

Table 3: Breakdown of Linux capability uses in Linux 2.2
Capability#uses#files
CAP_CHOWN21
CAP_DAC_OVERRIDE55
CAP_DAC_READ_SEARCH44
CAP_FOWNER75
CAP_FSETID32
CAP_IPC_LOCK42
CAP_IPC_OWNER11
CAP_KILL00
CAP_LINUX_IMMUTABLE22
CAP_NET_ADMIN7532
CAP_NET_BIND_SERVICE33
CAP_NET_BROADCAST00
CAP_NET_RAW86
CAP_SETGID72
CAP_SETPCAP22
CAP_SETUID73
CAP_SYS_ADMIN12769
CAP_SYS_BOOT11
CAP_SYS_CHROOT11
CAP_SYS_MODULE42
CAP_SYS_NICE52
CAP_SYS_PACCT11
CAP_SYS_PTRACE99
CAP_SYS_RAWIO21
CAP_SYS_RESOURCE108
CAP_SYS_TIME74
CAP_SYS_TTY_CONFIG11
Total298169

In Linux 2.2, CAP_SYS_ADMIN accounted for 42% of the uses of capabilities, and CAP_NET_ADMIN accounted for 25%.

Table 4 repeats the earlier exercise of excluding drivers/ and architectures other than i386 (as the Intel arch/ directory was then named) from the Linux 2.2 data. In this case, an interesting difference emerges.

Table 4: Breakdown of Linux capability uses in Linux 2.2, excluding drivers and architectures other than i386
Capability#uses#files
CAP_CHOWN21
CAP_DAC_OVERRIDE55
CAP_DAC_READ_SEARCH44
CAP_FOWNER75
CAP_FSETID32
CAP_IPC_LOCK42
CAP_IPC_OWNER11
CAP_KILL00
CAP_LINUX_IMMUTABLE22
CAP_NET_ADMIN4423
CAP_NET_BIND_SERVICE33
CAP_NET_BROADCAST00
CAP_NET_RAW86
CAP_SETGID72
CAP_SETPCAP22
CAP_SETUID73
CAP_SYS_ADMIN2317
CAP_SYS_BOOT11
CAP_SYS_CHROOT11
CAP_SYS_MODULE42
CAP_SYS_NICE52
CAP_SYS_PACCT11
CAP_SYS_PTRACE22
CAP_SYS_RAWIO21
CAP_SYS_RESOURCE54
CAP_SYS_TIME31
CAP_SYS_TTY_CONFIG11
Total14794

The overall picture differs in a way that I suspect is significant: just under 16% (23/147) of the uses of capabilities are CAP_SYS_ADMIN. (As we saw in Table 2, by Linux 3.2, this figure had grown to 30% (167/552).) This difference suggests to me that as a series of kernel developers was faced with the question: "What capability should I use to govern my new privileged kernel feature?", the answer was often something like "I don't know; maybe CAP_SYS_ADMIN?". (That certainly fits with a few anecdotal cases I've encountered while discussing things with kernel developers as I wrote man pages for new kernel features.)

The script (count_kernel_cap_uses.sh) used to generate the data for these statistics can be found here. The first and third tables above are based on analysis of the "p2" output files produced by the script. The second and fourth tables are based on analysis of the "p4" output files.

2012-02-22

Look hard, and you can see TLPI

This is fun... I'm fairly certain that the guess by this redditor about what you can see sitting behind the laptop in this photo (taken by John Snyder, and used in the 21 Feb 2012 Wired article, Lord of the Files: How GitHub Tamed Free Software (And More)) is correct. Probably, it's the copy I gave Linus last year. It's nice to know he held on to it, though I'm not so sure there's so much in the book that he doesn't already know.

Updated 2015-07-06: fix a broken URL, and add the title of Wired article. 
Updates 2016-07-25: fix a broken URL (again... Wired.com doesn't seem to embrace the notion of stable URLs).

2012-02-20

Traditional Chinese translation of TLPI

The Taiwanese publisher GOTOP has contracted the rights to do a Traditional Chinese publication of TLPI.

There are now four translations of TLPI in progress. It looks like the first of the translations that will appear will be the Korean translation, sometime around the middle of this year.

2012-02-04

Web site updates

I've rolled out a few updates to the man7.org web site, including a redesigned main page for TLPI, and the addition of several errata to the errata page. Special thanks for a long list of error reports to Junjiro Okajima, who's working on the Japanese translation of TLPI.

2012-01-16

Third print run (and request for bug reports)

Sales of The Linux Programming Interface have continued well enough that the publisher will soon start preparing the third print run. That print run will incorporate all of the outstanding errata.

If you've been reading TLPI and noticed any errors or typos, now would be a good time to report them, so that fixes can be included in the next printing.

2011-12-03

Nice discount on No Starch books

No Starch Press is doing a brief pre-Christmas sale -- 40% off all paper books, and the ebook is included for free. That's cheaper than the normal discount offered for TLPI, and it applies to all No Starch books. But I only found out about this sale a little late: according to http://nostarch.com/newsletters/2011_holiday.htm, the sale finishes at midnight on 3 Dec. I presume that means midnight in California (UTC-8), about 24 hours from now. So, you might want to take a quick look at the full catalog at No Starch.

PS The publisher's costs for international shipping from the US is pretty hefty, but with the free ebooks, and if you're ordering more than one book, the prices might still beat the online bookstores even if you're shipping outside the US.

2011-11-09

Slides from OpenFest presentation

The slides from my OpenFest presentation, Why kernel space sucks, can be found here.

2011-11-04

Speaking tomorrow at OpenFest

The organizers very kindly invited me to speak at OpenFest in Sofia, Bulgaria. My talk tomorrow is entitled Why Kernel Space Sucks.

That title is of course a reference to the highly amusing presentation of a few years ago by kernel hacker Dave Jones entitled Why Userspace Sucks (MagicPoint presentation). (For the PDF of Dave's complete paper presented at Linux Symposium 2006, look here; LWN.net has a nice tl;dr summary.)

Dave's presentation was all about the ways in which various userspace systems and applications kill performance by wasting system resources on pointless tasks. I'm not contradicting anything that Dave says, but it seems at least fair to point out that there are places where kernel space sucks too. My talk is about one of those places with special interest to me--the kernel-userspace programming interface--a place where kernel developers have inflicted a steady stream of small train wrecks (to borrow Dave's term) on userspace.

2011-10-20

LinuxCon Europe

I'll be at LinuxCon Europe, 26-28 October, in Prague, Czech Republic. (In fact, I arrive already on Monday, 24 October.) I'll have a few copies of The Linux Programming Interface with me for sale. If you want to buy a copy (signed even, if you want!), drop me a mail (mtk AT man7.org).

2011-08-14

Linux Plumbers Conference

I'm going to be at Linux Plumbers Conference, 7-9 September, in Santa Rosa, California. I'm looking forward to connect up with folk, and spend a couple of days in the Bay Area. I may have a limited number of copies of The Linux Programming Interface with me for sale. If you want to buy a copy directly from me (signed even, if you want!), please contact me by email by the end of this month (mtk AT man7.org).

2011-05-27

Updated API Changes page

With the release of Linux 2.6.39, and the opening of the merge window for Linux 2.8.0 (or 2.6.40, or 3.0, or whatever) 3.0, I've updated the API changes page to include recent and upcoming userspace API changes in the Linux kernel. (This page covers changes since Linux 2.6.36, which was the next kernel released after the book went to press.)

Updated 2011-05-30: fixed kernel version number

2011-05-18

No Starch Press discount offer further extended

Because TLPI was temporarily out of stock while the second print run was being completed, No Starch Press has further extended their earlier discount offer, allowing you to order the paper version of TLPI from them at a 30% discount (i.e., a total price of US$70 plus shipping), and receive the ebook free (look here for details on the ebook release). The offer is now extended to 30 June 2011.

To obtain the discount (and ebook), you must buy TLPI direct from the publisher's web site, and quote the coupon code Mamaku (what's that?). (No Starch Press is located in San Francisco, so international shipping rates will apply for readers outside North America.)

No Starch Press has the second print run in stock, so they can ship immediately.

2011-05-17

Second print run now available

The second print run of The Linux Programming Interface is now available. Sellers such as Amazon are now restocked.

2011-04-27

Reworked errata page

I've reworked the errata page to use color and fonts to classify the errata into three broad types and two levels of "severity".

One reason that I've done this is because there are by now quite a few errata. Another reason is because I earlier received a couple of inquiries along the lines "Because there are a lot of errata, should I wait for the second printing of the book before I buy a copy?" My response to this was "probably not", for reasons that I give below.

As of today, there are 104 errata posted on the errata page. One reason that there are a lot of errata is because there is a lot of book: 1500 pages. Another reason is that I'm very conscientious about fixing and documenting all errors that I find or that are reported to me (by contrast, a lot of books don't even maintain an errata list).

However, the observation that there are a lot of errata also needs to be tempered with some analysis. The current set of errata can be broken down (see the coding on the errata page) as follows:
  • 5 fixes to significant code problems.
  • 1 significant fix to an explanation in the text.
  • 1 significant fix to a technical detail explained in the text.
  • 10 minor code fixes. The corresponding code problem is minor and its solution is normally obvious to an attentive reader with a good understanding of C. (The most common culprit here was small code snippets that I wrote directly into the text--complete with syntax errors--rather than extracting directly from source files.)
  • 24 minor technical fixes. These are typically obvious fixes to minor technical errors or imprecisions in the text. (In many cases, these issues probably wouldn't have impacted the reader's understanding of the topic.)
  • 25 minor clarifications. These are improvements or fixes to minor details in the text. In many cases, the fix could simply have been omitted (the problem would have been unlikely to trouble most readers), but I took the opportunity anyway to improve the text because it was easily possible to do so.
  • 38 typo fixes. Spelling and grammar corrections and obvious fixes to wording errors.
For most readers, probably only the first three categories of errata will matter--and possibly a few of those in the fourth category. In other words, the number of significant errata fixed between the two print runs is actually quite small, which is why I counseled those wondering whether to wait for the second print run that they probably didn't need to.

PS Meanwhile, we look to still be on target to have the second print run ready and in shops at the start of May.

2011-04-17

Low stock

While we wait for the second print run to complete, it looks like some of the online booksellers (such as Amazon.com) have temporarily run out of stock. The second print run should be completed at the start of next month, and sellers will be restocked within a couple of days after that.

2011-04-16

man7.org down this weekend

Currently, the company where I work and host my website is going through a move of offices. As a result, access to the man7.org website will see some interruptions. Everything should be right by Monday.

Update 2011-04-17: And we're back

2011-04-11

Second print run going to press

Last December, I wrote that we'd be preparing the second print run of the book soon. That time window changed a bit, mainly because it turned out that the lead time with the publisher became much shorter than we expected, so that it was possible to delay preparation of the print run until later. By now however, reserves from the first print run have run low enough that the files for the second print run have already gone to the publisher, and will emerge from the presses in a few weeks time.

The new print run will incorporate all of the errata reported up to the end of March, and I have now reorganized the main errata page so that it breaks the errata down by the print run in which they were applied (as well as a list of errata queued for the next print run).

Updated 2011-04-16 to fix a wording error.

2011-04-08

Using TLPI in a university course? Let me know

I didn't specifically target TLPI at the university market as I wrote it. But, by now I've had emails from a number of university teachers who are using TLPI as a required text or as recommended reading for courses on Linux or UNIX system programming.

If you are a teacher or a student using TLPI in a university course, I'd love to hear about it. In particular, I'm very interested to find out more details about how TLPI is being used as a course book, with the idea in mind of improving a future edition of the book for use in that market. If you're a teacher or a student using TLPI, take a look at the questions here, and drop me a mail.

2011-04-06

Training course details posted on my web site

I've posted the full training course outline for the Linux/UNIX system programming course that I teach on my web site. You can find it here.