Skip to main content.

Making your first patch (OpenBSD)

2015-02-18

Live demo in BSD Now Episode 077. Originally written by an anonymous listener, with additions by TJ, for bsdnow.tv | Last updated: 2015/02/18

NOTE: the author/maintainer of the tutorial(s) is no longer with the show, so the information below may be outdated or incorrect.

So you're reading through OpenBSD's man pages or website and, lo' and behold, you stumble upon a typo. Here's the perfect opportunity to learn how to create patches to send and get your first credit in the source tree. OpenBSD uses CVS for version control and the cvs(1) tool to create patches. It can be found in the default install of OpenBSD and NetBSD, and it's also available in FreeBSD ports. The first thing you need to do is identify which tree you need to check out. There are four in total:

  • src - the source code (including man pages and default config files)
  • ports - third party software, as well as the ports infrastructure
  • xenocara - Xorg and associated utilities
  • www - the openbsd.org web pages

To keep things organized, consider making subdirectory for code you're working on.

$ mkdir -p ~/code && cd ~/code

Before checking out what you need, read over the AnonCVS page and use the mirror closest to you. The following example would work for the system source:

$ cvs -qd anoncvs@anoncvs.usa.openbsd.org:/cvs checkout -P src

U src/Makefile
U src/Makefile.cross
U src/bin/Makefile
U src/bin/Makefile.inc
U src/bin/cat/Makefile
U src/bin/cat/cat.1
U src/bin/cat/cat.c
[...]

You don't actually need to check out everything if you only have a quick fix, like a typo. It's possible to check out only what you plan to work on. Let's say, for example, you only want to fix something in the vi(1) editor.

$ cvs -qd anoncvs@anoncvs.usa.openbsd.org:/cvs checkout -P src/usr.bin/vi

Only the files in vi will be checked out by doing it this way. CVS will also remember which server you checked out from, so you don't need to enter it again. At this point you can simply edit it with your favorite editor. It's easiest to cd into the directory containing the file before you do any editing, since it will make the later CVS commands a little easier.

$ cd src/usr.bin/vi/common
$ ls

CVS          exf.c        log.c        msg.c        put.c        seq.h
args.h       exf.h        log.h        msg.h        recover.c    util.c
common.h     gs.h         main.c       options.awk  screen.c     util.h
cut.c        key.c        mark.c       options.c    screen.h
cut.h        key.h        mark.h       options.h    search.c
delete.c     line.c       mem.h        options_f.c  seq.c

Edit the file you're interested in...

$ vi options.h

The next step is to generate a diff against what the server has. In the old days, you had to remember to generate a unified diff. In the last year or so, you'll find a ".cvsrc" file in your home directory (on OpenBSD, at least) that takes care of setting the correct flags for you so you don't have to.

$ cvs diff

cvs server: Diffing .
Index: options.h
===================================================================
RCS file: /cvs/src/usr.bin/vi/common/options.h,v
retrieving revision 1.8
diff -u -p -r1.8 options.h
--- options.h   8 Jan 2006 21:05:39 -0000       1.8
+++ options.h   12 Feb 2015 04:12:45 -0000
@@ -52,8 +52,8 @@

 struct _option {
        union {
-               u_long   val;           / * Value or boolean. */
-               char    *str;           / * String. */
+               u_long   val;           / * I don't actually know any C. */
+               char    *str;           / * But don't tell them that. */
        } o_cur;
 #define        O_CLR(sp, o)            o_set((sp), (o), 0, NULL, 0)
 #define        O_SET(sp, o)            o_set((sp), (o), 0, NULL, 1)

Output your changes to a file:

$ cvs diff > myfirstpatch.diff

Double-check it to make sure everything's all OK, and there you have it! A diff that you can send off. Now the question is.. where should it go?

  • Source code and man page diffs should go to tech@ (inline only).
  • Website diffs can go to tech@ (inline only).
  • Ports diffs go to ports@ (inline or as an attachment).
  • Xorg diffs go to tech@ or x11@ (inline only).

Give it some time and hopefully a developer takes note and commits the diff. You should see your name in the commit message as the person who sent the fix in. Cool, huh? Now you're famous.

Latest News

New announcement

2017-05-25

Hi, Mr. Dexter. Also, we understand that Brad Davis thinks there should be more real news....

Two Year Anniversary

2015-08-08

We're quickly approaching our two-year anniversary, which will be on episode 105. To celebrate, we've created a unique t-shirt design, available for purchase until the end of August. Shirts will be shipped out around September 1st. Most of the proceeds will support the show, and specifically allow us to buy...

New discussion segment

2015-01-17

We're thinking about adding a new segment to the show where we discuss a topic that the listeners suggest. It's meant to be informative like a tutorial, but more of a "free discussion" format. If you have any subjects you want us to explore, or even just a good name...

How did you get into BSD?

2014-11-26

We've got a fun idea for the holidays this year: just like we ask during the interviews, we want to hear how all the viewers and listeners first got into BSD. Email us your story, either written or a video version, and we'll read and play some of them for...


Episode 220: Opening ZFS in 2017

2017-11-15

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines The First PS4 Kernel Exploit: Adieu The First PS4 Kernel Exploit: Adieu Plenty of time has passed since we first demonstrated Linux running on the PS4. Now we will step back a bit and explain how we managed to jump...

Episode 219: We love the ARC

2017-11-08

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines Papers We Love: ARC: A Self-Tuning, Low Overhead Replacement Cache Ever wondered how the ZFS ARC (Adaptive Replacement Cache) works? How about if Bryan Cantrill presented the original paper on its design? Today is that day. Slides It starts by looking back at a fundamental paper...

Episode 218: A KRACK in the WiFi

2017-11-01

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines FreeBSD 10.4-RELEASE Available FreeBSD 10.4-RELEASE is out. The FreeBSD Project dedicates the FreeBSD 10.4-RELEASE to the memory of Andrey A. Chernov. Some of the highlights: 10.4-RELEASE is the first FreeBSD release to feature full support for eMMC storage, including eMMC partitions, TRIM...

Episode 217: Your questions, part II

2017-10-25

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines OpenBSD 6.2 Released OpenBSD continues their six month release cadence with the release of 6.2, the 44th release On a disappointing note, the song for 6.2 will not be released until December Highlights: Improved hardware support on modern platforms including ARM64/ARMv7 and octeon,...