From owner-svn-doc-head@FreeBSD.ORG Thu Jul 12 14:12:50 2012 Return-Path: Delivered-To: svn-doc-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 197A91065670; Thu, 12 Jul 2012 14:12:50 +0000 (UTC) (envelope-from issyl0@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 0347B8FC0C; Thu, 12 Jul 2012 14:12:50 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.4/8.14.4) with ESMTP id q6CECnBX011555; Thu, 12 Jul 2012 14:12:49 GMT (envelope-from issyl0@svn.freebsd.org) Received: (from issyl0@localhost) by svn.freebsd.org (8.14.4/8.14.4/Submit) id q6CECngA011553; Thu, 12 Jul 2012 14:12:49 GMT (envelope-from issyl0@svn.freebsd.org) Message-Id: <201207121412.q6CECngA011553@svn.freebsd.org> From: Isabell Long Date: Thu, 12 Jul 2012 14:12:49 +0000 (UTC) To: doc-committers@freebsd.org, svn-doc-all@freebsd.org, svn-doc-head@freebsd.org X-SVN-Group: doc-head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r39189 - head/en_US.ISO8859-1/books/porters-handbook X-BeenThere: svn-doc-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the doc tree for head List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 12 Jul 2012 14:12:50 -0000 Author: issyl0 Date: Thu Jul 12 14:12:49 2012 New Revision: 39189 URL: http://svn.freebsd.org/changeset/doc/39189 Log: Add a section to the Dos and Don'ts section of the porter's handbook about avoiding Linuxisms. Submitted by: issyl0 (as part of Google Code-In 2011) Reviewed by: eadler Approved by: gabor (mentor) Modified: head/en_US.ISO8859-1/books/porters-handbook/book.sgml Modified: head/en_US.ISO8859-1/books/porters-handbook/book.sgml ============================================================================== --- head/en_US.ISO8859-1/books/porters-handbook/book.sgml Thu Jul 12 13:19:23 2012 (r39188) +++ head/en_US.ISO8859-1/books/porters-handbook/book.sgml Thu Jul 12 14:12:49 2012 (r39189) @@ -16059,6 +16059,77 @@ IGNORE= POINTYHAT is not supported and confirm the changes with them. + + Avoiding Linuxisms + + Do not use /proc if there are any + other ways of getting the information, e.g. + setprogname(argv[0]) in + main() and then &man.getprogname.3; if you + want to know your name. + + Do not rely on behaviour that is undocumented by + POSIX. + + Do not record timestamps in the critical path of the + application if it also works without. Getting timestamps may + be slow, depending on the accuracy of timestamps in the + OS. If timestamps are really needed, + determine how precise they have to be and use an + API which is documented to just deliver the + needed precision. + + A number of simple syscalls (for example + &man.gettimeofday.2;, &man.getpid.2;) are much faster on + &linux; than on any other operating system due to caching and + the vsyscall performance optimizations. Do not rely on them + being cheap in performance-critical applications. In general, + try hard to avoid syscalls if possible. + + Do not rely on &linux;-specific socket behaviour. In + particular, default socket buffer sizes are different (call + &man.setsockopt.2; with SO_SNDBUF and + SO_RCVBUF, and while &linux;'s &man.send.2; + blocks when the socket buffer is full, &os;'s will fail and + set ENOBUFS in errno. + + If relying on non-standard behaviour is required, + encapsulate it properly into a generic API, + do a check for the behaviour in the configure stage, and stop + if it is missing. + + Check the man pages to + see if the function used is a POSIX + interface (in the STANDARDS section of the man + page). + + Do not assume that /bin/sh is + bash. Ensure that a command line + passed to &man.system.3; will work with a + POSIX compliant shell. + + A list of common bashisms is + available here. + + Do not #include + <stdint.h> if + inttypes.h is sufficient. This will + ensure that the software builds on older versions of + &os;. + + Check that headers are included in the + POSIX or man page recommended way, e.g. + sys/types.h is often forgotten, which is + not as much of a problem for &linux; as it is for &os;. + + Compile threaded applications with + -pthread, not -lpthread or + variations thereof. + + + Miscellanea