The setmode() function doesn't always set errno on error. The attached patch pulls rev 1.31 from NetBSD[1] to fix this. Notes: A. OpenBSD[2] and NetBSD have slightly different error returns for octal mode errors. OpenBSD always returns ERANGE, while NetBSD returns EINVAL unless strtol returned ERANGE. The attached patch follows the OpenBSD policy. B. The patch uses a slightly different definition for addcmd from NetBSD: (BITCMD *, char, mode_t, mode_t, mode_t) instead of (BITCMD *, mode_t, mode_t, mode_t, mode_t). It's pretty obvious from the context and use that op is only a char. Also, we change the types of the local vars in addcmd() appropriately to match the function definition. C. Comments from rev 1.15[3] are added since they are more accurate after that change (which was imported to FreeBSD in the past), and reduce any future diffs. However, spelling error was corrected. [1] http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/setmode.c.diff?r1=1.30&r2=1.31&only_with_tag=MAIN [2] http://www.openbsd.org/cgi-bin/cvsweb/src/lib/libc/gen/setmode.c?rev=1.20;content-type=text%2Fplain [3] http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libc/gen/setmode.c.diff?r1=1.14&r2=1.15&only_with_tag=MAIN Fix: See attached patch. Patch attached with submission follows:
Created attachment 153280 [details] Patch based on NetBSD I would prefer to take only the NetBSD approach. We can check later if we should simplify it like OpenBSD did.
Grab PR.
A commit references this bug: Author: pfg Date: Sun Feb 22 20:16:45 UTC 2015 New revision: 279186 URL: https://svnweb.freebsd.org/changeset/base/279186 Log: setmode(3): Make sure that setmode sets errno on failure. Our man page already documented this partially but now we have some consistent behavior. PR: 136669 Obtained from: NetBSD (CVS rev. 1.31, 1.33) Relnotes: yes MFC after: 3 weeks Changes: head/lib/libc/gen/setmode.3 head/lib/libc/gen/setmode.c
A commit references this bug: Author: pfg Date: Mon Mar 23 19:44:20 UTC 2015 New revision: 280392 URL: https://svnweb.freebsd.org/changeset/base/280392 Log: MFC r279186: setmode(3): Make sure that setmode sets errno on failure. Our man page already documented this partially but now we provide more consistent behavior. PR: 136669 Obtained from: NetBSD (CVS rev. 1.31, 1.33) Relnotes: yes Changes: _U stable/10/ stable/10/lib/libc/gen/setmode.3 stable/10/lib/libc/gen/setmode.c
Committed and MFC'd. Thanks!