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...

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 210: Your questions, part I

2017-09-06

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines A Reimplementation Of Netbsd Using a Microkernel Minix author Andy Tanenbaum writes in Part 1 of a-reimplementation-of-netbsd-using-a-microkernel Based on the MINIX 3 microkernel, we have constructed a system that to the user looks a great deal like NetBSD. It uses pkgsrc,...

Episode 209: Signals: gotta catch ‘em all

2017-08-30

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines Trip Report: FreeBSD in China at COPU and LinuxCon This trip report is from Deb Goodkin, the Executive Director of the FreeBSD Foundation. She travelled to China in May 2017 to promote FreeBSD, meet with companies, and participate in discussions around Open...

Episode 208: Faces of Open Source

2017-08-23

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines LLVM, Clang and compiler-rt support enhancements In the last month I started with upstream of the code for sanitizers: the common layer and ubsan. I worked also on the elimination of unexpected failures in LLVM and Clang. I've managed to...

Episode 207: Bridge over the river Cam

2017-08-16

Direct Download:HD VideoMP3 AudioTorrent This episode was brought to you by Headlines BSDCam recap The 2017 Cambridge DevSummit took place from 2-4 August 2017. The event took place over three days including a formal dinner at St John's College, and was attended by 55 registered developers and guests. Prior to the start of...