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

We understand that Michael Dexter, Brad Davis, and George Rosamond think 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 275: OpenBSD in stereo

2018-12-05

Direct Download:MP3 AudioVideo Headlines DragonflyBSD 5.4 released DragonFly version 5.4 brings a new system compiler in GCC 8, improved NUMA support, a large of number network and virtual machine driver updates, and updates to video support. This release is 64-bit only, as with previous releases. The details of all commits...

Episode 274: Language: Assembly

2018-11-28

Direct Download:MP3 AudioVideo Headlines Assembly language on OpenBSD amd64+arm64 This is a short introduction to assembly language programming on OpenBSD/amd64+arm64. Because of security features in the kernel, I have had to rethink a series of tutorials covering Aarch64 assembly language on OpenBSD, and therefore this will serve as a placeholder-cum-reminder....

Episode 273: A thoughtful episode

2018-11-21

Direct Download:MP3 AudioVideo Headlines Some thoughts on NetBSD 8.0 NetBSD is a highly portable operating system which can be run on dozens of different hardware architectures. The operating system's clean and minimal design allow it to be run in all sorts of environments, ranging from embedded devices, to servers, to workstations....

Episode 272: Detain the bhyve

2018-11-14

Direct Download:MP3 AudioVideo Headlines The byproducts of reading OpenBSD netcat code When I took part in a training last year, I heard about netcat for the first time. During that class, the tutor showed some hacks and tricks of using netcat which appealed to me and motivated me to learn the...