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 232: FOSDEM 2018

2018-02-07

Direct Download:HD VideoMP3 AudioTorrent> This episode was brought to you by Headlines [FOSDEM Trip report] Your BSDNow hosts were both at FOSDEM in Brussels, Belgium over the weekend. On the friday before FOSDEM, we held a FreeBSD devsummit (3rd consecutive year), sponsored by the FreeBSD Foundation and organized by Benedict (with the help from Kristof...

Episode 231: Unix Architecture Evolution

2018-01-24

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines Unix Architecture Evolution from the 1970 PDP-7 to the 2017 FreeBSD Q: Could you briefly introduce yourself? I’m a professor of software engineering, a programmer at heart, and a technology author. Currently I’m also the editor in chief of the IEEE...

Episode 230: Your questions, Part III

2018-01-24

Direct Download:HD VideoMP3 AudioTorrent> This episode was brought to you by Headlines KPTI patch lands in FreeBSD -current After a heroic effort by Konstantin Belousov kib@FreeBSD.org, the first meltdown patch has landed in FreeBSD This creates separate page tables for the Kernel and userland, and switches between them when executions enters the kernel, and when...

Episode 229: The Meltdown of Spectre

2018-01-17

Direct Download:HD VideoMP3 AudioTorrent> This episode was brought to you by Headlines More Meltdown Much has been happened this week, but before we get into a status update of the various mitigations on the other BSDs, some important updates: Intel has recalled the microcode update they issued on January 8th. It turns out this update...