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 267: Absolute FreeBSD

2018-10-10

Direct Download:MP3 AudioVideo Headlines Interview - Michael W. Lucas - mwlucas@michaelwlucas.com / @mwlauthor BR: [Welcome Back] AJ: What have you been doing since last we talked to you [ed, ssh, and af3e] BR: Tell us more about AF3e AJ: How did the first Absolute FreeBSD come about? BR: Do you have anything special planned for MeetBSD? AJ: What...

Episode 266: File type history

2018-10-03

Direct Download:MP3 AudioVideo Headlines OpenBSD/NetBSD on FreeBSD using grub2-bhyve When I was writing a blog post about the process title, I needed a couple of virtual machines with OpenBSD, NetBSD, and Ubuntu. Before that day I mainly used FreeBSD and Windows with bhyve. I spent some time trying to set up...

Episode 265: Software Disenchantment

2018-09-26

Direct Download:MP3 AudioVideo Headlines [FreeBSD DevSummit & EuroBSDcon 2018 in Romania] Your hosts are back from EuroBSDcon 2018 held in Bucharest, Romania this year. The first two days of the conference are used for tutorials and devsummits (FreeBSD and NetBSD), while the last two are for talks. Although Benedict organized the devsummit in large...

Episode 264: Optimized-out

2018-09-19

Direct Download:MP3 AudioVideo This episode was brought to you by Headlines FreeBSD & DragonFlyBSD Put Up A Strong Fight On AMD's Threadripper 2990WX, Benchmarks Against Linux The past two weeks I have been delivering a great deal of AMD Threadripper 2990WX benchmarks on Linux as well as some against Windows and Windows...