Module Name: src Committed By: kre Date: Thu May 18 13:56:58 UTC 2017
Modified Files: src/bin/sh: redir.c sh.1 Log Message: Allow abbreviations of option names for the "fdflags -s" command. While documenting that, cleanup markup of the fdflags section of the man page. To generate a diff of this commit: cvs rdiff -u -r1.55 -r1.56 src/bin/sh/redir.c cvs rdiff -u -r1.142 -r1.143 src/bin/sh/sh.1 Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/bin/sh/redir.c diff -u src/bin/sh/redir.c:1.55 src/bin/sh/redir.c:1.56 --- src/bin/sh/redir.c:1.55 Sun May 14 17:27:05 2017 +++ src/bin/sh/redir.c Thu May 18 13:56:58 2017 @@ -1,4 +1,4 @@ -/* $NetBSD: redir.c,v 1.55 2017/05/14 17:27:05 kre Exp $ */ +/* $NetBSD: redir.c,v 1.56 2017/05/18 13:56:58 kre Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -37,7 +37,7 @@ #if 0 static char sccsid[] = "@(#)redir.c 8.2 (Berkeley) 5/4/95"; #else -__RCSID("$NetBSD: redir.c,v 1.55 2017/05/14 17:27:05 kre Exp $"); +__RCSID("$NetBSD: redir.c,v 1.56 2017/05/18 13:56:58 kre Exp $"); #endif #endif /* not lint */ @@ -653,42 +653,43 @@ renumber_sh_fd(struct shell_fds *fp) static const struct flgnames { const char *name; + uint16_t minch; uint32_t value; } nv[] = { #ifdef O_APPEND - { "append", O_APPEND }, + { "append", 2, O_APPEND }, #endif #ifdef O_ASYNC - { "async", O_ASYNC }, + { "async", 2, O_ASYNC }, #endif #ifdef O_SYNC - { "sync", O_SYNC }, + { "sync", 2, O_SYNC }, #endif #ifdef O_NONBLOCK - { "nonblock", O_NONBLOCK }, + { "nonblock", 3, O_NONBLOCK }, #endif #ifdef O_FSYNC - { "fsync", O_FSYNC }, + { "fsync", 2, O_FSYNC }, #endif #ifdef O_DSYNC - { "dsync", O_DSYNC }, + { "dsync", 2, O_DSYNC }, #endif #ifdef O_RSYNC - { "rsync", O_RSYNC }, + { "rsync", 2, O_RSYNC }, #endif #ifdef O_ALTIO - { "altio", O_ALT_IO }, + { "altio", 2, O_ALT_IO }, #endif #ifdef O_DIRECT - { "direct", O_DIRECT }, + { "direct", 2, O_DIRECT }, #endif #ifdef O_NOSIGPIPE - { "nosigpipe", O_NOSIGPIPE }, + { "nosigpipe", 3, O_NOSIGPIPE }, #endif #ifdef O_CLOEXEC - { "cloexec", O_CLOEXEC }, + { "cloexec", 2, O_CLOEXEC }, #endif - { 0, 0 } + { 0, 0, 0 } }; #define ALLFLAGS (O_APPEND|O_ASYNC|O_SYNC|O_NONBLOCK|O_DSYNC|O_RSYNC|\ O_ALT_IO|O_DIRECT|O_NOSIGPIPE|O_CLOEXEC) @@ -752,6 +753,7 @@ parseflags(char *s, int *p, int *n) { int *v, *w; const struct flgnames *fn; + size_t len; *p = 0; *n = 0; @@ -769,8 +771,9 @@ parseflags(char *s, int *p, int *n) error("Missing +/- indicator before flag %s", s-1); } + len = strlen(s); for (fn = nv; fn->name; fn++) - if (strcmp(s, fn->name) == 0) { + if (len >= fn->minch && strncmp(s,fn->name,len) == 0) { *v |= fn->value; *w &=~ fn->value; break; @@ -846,11 +849,6 @@ fdflagscmd(int argc, char *argv[]) if (setflags) goto msg; - /* - * XXX we should only ever operate on user defined fds - * XXX not on sh internal fds that might be open. - * XXX but for that we need to know their range (later) - */ for (i = 0; i <= max_user_fd; i++) printone(i, 0, verbose, 1); return 0; Index: src/bin/sh/sh.1 diff -u src/bin/sh/sh.1:1.142 src/bin/sh/sh.1:1.143 --- src/bin/sh/sh.1:1.142 Thu May 18 13:53:18 2017 +++ src/bin/sh/sh.1 Thu May 18 13:56:58 2017 @@ -1,4 +1,4 @@ -.\" $NetBSD: sh.1,v 1.142 2017/05/18 13:53:18 kre Exp $ +.\" $NetBSD: sh.1,v 1.143 2017/05/18 13:56:58 kre Exp $ .\" Copyright (c) 1991, 1993 .\" The Regents of the University of California. All rights reserved. .\" @@ -1962,14 +1962,28 @@ flag interprets the .Ar flags argument as a comma separated list of file descriptor flags, each preceded with a -.Dq + +.Dq \(pl or a -.Dq - +.Dq \(mi indicating to set or clear the respective flag. Valid flags are: -append,async,sync,nonblock,fsync,dsync,rsync,direct,nosigpipe,cloexec. +.Cm append , +.Cm async , +.Cm sync , +.Cm nonblock , +.Cm fsync , +.Cm dsync , +.Cm rsync , +.Cm direct , +.Cm nosigpipe , +and +.Cm cloexec . +Unique abbreviations of these names, of at least 2 characters, +may be used on input. See .Xr fcntl 2 +and +.Xr open 2 for more information. .It getopts Ar optstring var The