summaryrefslogtreecommitdiff
path: root/bin/sh/miscbltin.c
Commit message (Collapse)AuthorAgeFilesLines
* sh: Remove a comment that was obsoleted by r358152Jilles Tjoelker2020-05-221-3/+1
| | | | | | | | | | | Since r358152, the read builtin has used a buffer. Also, remove a space at the end of the line in a comment. No functional change is intended. Notes: svn path=/head/; revision=361384
* [sh] Fix a "may be unused" warning on mips-gccAdrian Chadd2020-04-161-0/+1
| | | | | | | | | | | | mips-gcc for mips32 was complaining that c was potentially used before being set. Setting it to 0 before calling fdgetsc() looks like the right thing to do in this instance; there's an explicit check for c == 0 later on. Tested: mips-gcc mips32 build, running /bin/sh on mips32 Notes: svn path=/head/; revision=360028
* sh: fix read builtin on 32-bit systemsKyle Evans2020-02-221-1/+1
| | | | | | | | | | | | | | | | | | Specifically, any system with a 32-bit size_t; -residue is calculated as a 32-bit *then* promoted to the 64-bit off_t and the result is ultimately wrong. This resulted in what would appear to be truncated output, as only the first line would be read. Correct it by just making residue an off_t to begin with, since this is what lseek will take anyways. Reported by: antoine, dim Triaged by: cem Tested by: kevans X-MFC-With: r358152 Notes: svn path=/head/; revision=358235
* Improve performance of "read" built-in command when using a seekableHiroki Sato2020-02-201-1/+73
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | fd. The read built-in command calls read(2) with a 1-byte buffer because newline characters need to be detected even on a byte stream which comes from a non-seekable file descriptor. Because of this, the following script calls >6,000 read(2) to show a 6KiB file: while read IN; do echo "$IN"; done < /COPYRIGHT When the input byte stream is seekable, it is possible to read a data block and then reposition the file pointer to where a newline character found. This change adds a small buffer to do this and reduces the number of read(2) calls. Theoretically, multiple built-in commands reading the same seekable byte stream in a single pipe chain can share the buffer. However, this change just makes a single invocation of the read built-in allocate a buffer and deallocate it every time for simplicity. Although this causes read(2) to read the same regions multiple times, the performance penalty should be small compared to the reduction of read(2) calls. Reviewed by: jilles MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D23747 Notes: svn path=/head/; revision=358152
* General further adoption of SPDX licensing ID tags.Pedro F. Giffuni2017-11-201-0/+2
| | | | | | | | | | | | | | | | | Mainly focus on files that use BSD 3-Clause license. The Software Package Data Exchange (SPDX) group provides a specification to make it easier for automated tools to detect and summarize well known opensource licenses. We are gradually adopting the specification, noting that the tags are considered only advisory and do not, in any way, superceed or replace the license texts. Special thanks to Wind River for providing access to "The Duke of Highlander" tool: an older (2014) run over FreeBSD tree was useful as a starting point. Notes: svn path=/head/; revision=326025
* sh: Reduce size of limits table.Jilles Tjoelker2017-04-121-1/+1
| | | | Notes: svn path=/head/; revision=316744
* Renumber copyright clause 4Warner Losh2017-02-281-1/+1
| | | | | | | | | | | | Renumber cluase 4 to 3, per what everybody else did when BSD granted them permission to remove clause 3. My insistance on keeping the same numbering for legal reasons is too pedantic, so give up on that point. Submitted by: Jan Schaumann <jschauma@stevens.edu> Pull Request: https://github.com/freebsd/freebsd/pull/96 Notes: svn path=/head/; revision=314436
* sh: Improve descriptions in 'ulimit -a' output.Jilles Tjoelker2016-06-051-2/+2
| | | | | | | | The format limits descriptions to 18 characters and is not changed, so the descriptions do not describe the limits exactly. Notes: svn path=/head/; revision=301452
* sh(1): replace 0 with NULL for pointers.Pedro F. Giffuni2016-04-091-1/+1
| | | | | | | | | Found with devel/coccinelle. Reviewed by: jilles Notes: svn path=/head/; revision=297761
* Fix handling of umtxp resource limit in sh(1)/ulimit(1), limits(1), addKonstantin Belousov2016-03-121-1/+1
| | | | | | | | | | | login.conf(5) support. Reviewed by: jilles Sponsored by: The FreeBSD Foundation Differential revision: https://reviews.freebsd.org/D5610 Notes: svn path=/head/; revision=296723
* Implement process-shared locks support for libthr.so.3, withoutKonstantin Belousov2016-02-281-0/+3
| | | | | | | | | | | | | | | breaking the ABI. Special value is stored in the lock pointer to indicate shared lock, and offline page in the shared memory is allocated to store the actual lock. Reviewed by: vangyzen (previous version) Discussed with: deischen, emaste, jhb, rwatson, Martin Simmons <martin@lispworks.com> Tested by: pho Sponsored by: The FreeBSD Foundation Notes: svn path=/head/; revision=296162
* sh: Fix read with escaped IFS characters at the end.Jilles Tjoelker2015-08-301-12/+17
| | | | | | | | Characters escaped with a backslash must be treated as if they were not in IFS. This includes stripping trailing IFS characters. Notes: svn path=/head/; revision=287308
* sh: Backslash-newline should not affect field splitting in read builtin.Jilles Tjoelker2015-08-161-2/+3
| | | | | | | This was originally broken in r212339 in 2010. Notes: svn path=/head/; revision=286826
* sh: Prefer "" to nullstr where possible.Jilles Tjoelker2015-02-151-1/+1
| | | | Notes: svn path=/head/; revision=278820
* sh: Deduplicate some code in ulimit builtin.Jilles Tjoelker2014-07-191-27/+25
| | | | Notes: svn path=/head/; revision=268873
* sh: Fix overflow checking on 'ulimit' operand.Jilles Tjoelker2014-07-051-10/+14
| | | | Notes: svn path=/head/; revision=268304
* Add a resource limit for the total number of kqueues available to theKonstantin Belousov2013-10-211-1/+4
| | | | | | | | | | | | | | | | | | | | | user. Kqueue now saves the ucred of the allocating thread, to correctly decrement the counter on close. Under some specific and not real-world use scenario for kqueue, it is possible for the kqueues to consume memory proportional to the square of the number of the filedescriptors available to the process. Limit allows administrator to prevent the abuse. This is kernel-mode side of the change, with the user-mode enabling commit following. Reported and tested by: pho Discussed with: jmg Sponsored by: The FreeBSD Foundation MFC after: 2 weeks Notes: svn path=/head/; revision=256850
* sh: Improve error handling in read builtin:Jilles Tjoelker2013-05-031-3/+20
| | | | | | | | | | | | | | | * If read -t times out, return status as if interrupted by SIGALRM (formerly 1). * If a trapped signal interrupts read, return status 128+sig (formerly 1). * If [EINTR] occurs but there is no trap, retry the read (for example because of a SIGWINCH in interactive mode). * If a read error occurs, write an error message and return status 2. As before, a variable assignment error returns 2 and discards the remaining data read. Notes: svn path=/head/; revision=250214
* sh: Prefer our character classification functions to <ctype.h>.Jilles Tjoelker2013-01-311-2/+2
| | | | Notes: svn path=/head/; revision=246167
* sh: Remove an unused header.Jilles Tjoelker2012-05-151-1/+0
| | | | | | | The read builtin no longer does things with termios. Notes: svn path=/head/; revision=235488
* sh: Minor optimization to output from ulimit/export/readonly.Jilles Tjoelker2011-05-151-2/+2
| | | | | | | No functional change is intended. Notes: svn path=/head/; revision=221975
* sh: Code size optimizations to "stack string" memory allocation:Jilles Tjoelker2010-11-231-5/+6
| | | | | | | | | | | * Prefer one CHECKSTRSPACE with multiple USTPUTC to multiple STPUTC. * Add STPUTS macro (based on function) and use it instead of loops that add nul-terminated strings to the stack string. No functional change is intended, but code size is about 1K less on i386. Notes: svn path=/head/; revision=215783
* sh: Fix 'read' if all chars before the first IFS char are backslash-escaped.Jilles Tjoelker2010-09-081-0/+1
| | | | | | | | | Backslash-escaped characters did not set the flag for a non-IFS character. MFC after: 2 weeks Notes: svn path=/head/; revision=212339
* sh: Various warning fixes (from WARNS=6 NO_WERROR=1):Jilles Tjoelker2009-12-271-2/+2
| | | | | | | | | | - const - initializations to silence -Wuninitialized (it was safe anyway) - remove nested extern declarations - rename "index" locals to "idx" Notes: svn path=/head/; revision=201053
* Usermode portion of the support for swap allocation accounting:Konstantin Belousov2009-06-231-1/+1
| | | | | | | | | | | | | | - update for getrlimit(2) manpage; - support for setting RLIMIT_SWAP in login class; - addition to the limits(1) and sh and csh limit-setting builtins; - tuning(7) documentation on the sysctls controlling overcommit. In collaboration with: pho Reviewed by: alc Approved by: re (kensmith) Notes: svn path=/head/; revision=194767
* sh: Make read's timeout (-t) apply to the entire line, not only the firstJilles Tjoelker2009-05-311-17/+0
| | | | | | | | | | | | | | | | | | | character. This avoids using non-standard behaviour of the old (upto FreeBSD 7) TTY layer: it reprocesses the input queue when switching to canonical mode. The new TTY layer does not provide this functionality and so read -t worked very poorly (first character is not echoed, cannot be backspaced but is still read). This also agrees with what most other shells with read -t do. PR: bin/129566 Reviewed by: stefanf Approved by: ed (mentor) Notes: svn path=/head/; revision=193185
* Fix the behaviour of the read built-in when IFS is unset.Stefan Farfeleder2009-03-221-1/+1
| | | | | | | Obtained from: NetBSD Notes: svn path=/head/; revision=190298
* Improve the IFS handling of the read built-in.Stefan Farfeleder2009-03-221-10/+68
| | | | | | | | Obtained from: NetBSD Submitted by: Jilles Tjoelker Notes: svn path=/head/; revision=190295
* Don't disable CR-to-NL translation when waiting for data to arrive.Ed Schouten2009-03-081-0/+1
| | | | | | | | | | | | | | | | | | | A difference between the old and the new TTY layer is that the new implementation does not perform any post-processing before returning data back to userspace when calling read(). sh(1)'s read turns the TTY into a raw mode before calling select(). This means that the first character will not receive any ICRNL processing. Inherit this flag from the original terminal attributes. Even though this issue is not present on RELENG_*, I'm MFCing it to make sh(1) in jails behave better. PR: bin/129566 MFC after: 2 weeks Notes: svn path=/head/; revision=189542
* Integrate the new MPSAFE TTY layer to the FreeBSD operating system.Ed Schouten2008-08-201-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | The last half year I've been working on a replacement TTY layer for the FreeBSD kernel. The new TTY layer was designed to improve the following: - Improved driver model: The old TTY layer has a driver model that is not abstract enough to make it friendly to use. A good example is the output path, where the device drivers directly access the output buffers. This means that an in-kernel PPP implementation must always convert network buffers into TTY buffers. If a PPP implementation would be built on top of the new TTY layer (still needs a hooks layer, though), it would allow the PPP implementation to directly hand the data to the TTY driver. - Improved hotplugging: With the old TTY layer, it isn't entirely safe to destroy TTY's from the system. This implementation has a two-step destructing design, where the driver first abandons the TTY. After all threads have left the TTY, the TTY layer calls a routine in the driver, which can be used to free resources (unit numbers, etc). The pts(4) driver also implements this feature, which means posix_openpt() will now return PTY's that are created on the fly. - Improved performance: One of the major improvements is the per-TTY mutex, which is expected to improve scalability when compared to the old Giant locking. Another change is the unbuffered copying to userspace, which is both used on TTY device nodes and PTY masters. Upgrading should be quite straightforward. Unlike previous versions, existing kernel configuration files do not need to be changed, except when they reference device drivers that are listed in UPDATING. Obtained from: //depot/projects/mpsafetty/... Approved by: philip (ex-mentor) Discussed: on the lists, at BSDCan, at the DevSummit Sponsored by: Snow B.V., the Netherlands dcons(4) fixed by: kan Notes: svn path=/head/; revision=181905
* Remove some white space at EOL.Jens Schweikhardt2006-02-041-1/+1
| | | | Notes: svn path=/head/; revision=155301
* Protect malloc, realloc and free calls with INT{ON,OFF} directly in chkalloc,Stefan Farfeleder2005-10-281-0/+2
| | | | | | | | | | | | | | | | | ckrealloc and ckfree (added), respectively. sh jumps out of the signal handler using longjmp which is obviously a bad idea during malloc calls. Note: I think there is still a small race here because volatile sig_atomic_t only guarantees atomic reads and writes while we're doing increments and decrements. Protect a setmode call with INT{ON,OFF} as it calls malloc internally. PR: 45478 Patch from: Nate Eldredge Notes: svn path=/head/; revision=151795
* Fix the error message if the mask that is passed to umask -S containsStefan Farfeleder2005-09-091-1/+1
| | | | | | | non-digits. Notes: svn path=/head/; revision=149918
* Various small code cleanups resulting from a code reviewingRalf S. Engelschall2005-09-061-7/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | and linting procedure: 1. Remove useless sub-expression: - if (*start || (!ifsspc && start > string && (nulonly || 1))) { + if (*start || (!ifsspc && start > string)) { The sub-expression "(nulonly || 1)" always evaluates to true and according to CVS logs seems to be just a left-over from some debugging and introduced by accident. Removing the sub-expression doesn't change semantics and a code inspection showed that the variable "nulonly" is also not necessary here in any way (and the expression would require fixing instead of removing). 2. Remove dead code: - if (backslash && c == '\\') { - if (read(STDIN_FILENO, &c, 1) != 1) { - status = 1; - break; - } - STPUTC(c, p); - } else if (ap[1] != NULL && strchr(ifs, c) != NULL) { + if (ap[1] != NULL && strchr(ifs, c) != NULL) { Inspection of the control and data flow showed that variable "backslash" is always false (0) when the "if"-expression is evaluated, hence the whole block is effectively dead code. Additionally, the skipping of characters after a backslash is already performed correctly a few lines above, so this code is also not needed at all. According to the CVS logs and the ASH 0.2 sources, this code existed in this way already since its early days. 3. Cleanup Style: - ! trap[signo][0] == '\0' && + ! (trap[signo][0] == '\0') && The expression wants to ensure the trap is not assigned the empty string. But the "!" operator has higher precedence than "==", so the comparison should be put into parenthesis to form the intended way of expression. Nevertheless the code was effectively not really broken as both particular NUL comparisons are semantically equal, of course. But the parenthesized version is a lot more intuitive. 4. Remove shadowing variable declaration: - char *q; The declaration of symbol "q" hides another identical declaration of "q" in the same context. As the other "q" is already reused multiple times and also can be reused again without negative side-effects, just remove the shadowing declaration. 5. Just small cosmetics: - if (ifsset() != 0) + if (ifsset()) The ifsset() macro is already coded by returning the boolean result of a comparison operator, so no need to compare this boolean result again against a numerical value. This also aligns the macros usage to the remaining existing code. Reviewed by: stefanf@ Notes: svn path=/head/; revision=149825
* First declare the functions to pacify -Wmissing-prototypes.Stefan Farfeleder2005-08-131-0/+4
| | | | Notes: svn path=/head/; revision=149018
* Remove clause 3 from the UCB licenses.Mark Murray2004-04-061-4/+0
| | | | | | | OK'ed by: imp, core Notes: svn path=/head/; revision=127958
* - Don't use quad_t when we really mean rlim_t.Maxime Henrion2002-10-011-5/+6
| | | | | | | | | | | - Cast rlim_t to intmax_t when printing it. This should fix the last format errors in sh(1). Tested on: i386, sparc64 Notes: svn path=/head/; revision=104282
* Callers of error() don't need to supply a program name prefix in theTim J. Robbins2002-09-301-6/+6
| | | | | | | error message. Stops ulimit giving error messages like "ulimit: ulimit: xyz". Notes: svn path=/head/; revision=104208
* Consistently use FBSDIDDavid E. O'Brien2002-06-301-2/+2
| | | | Notes: svn path=/head/; revision=99110
* Add support for RLIMIT_VMEM. The #ifdef's were already there but getopt()Matthew Dillon2002-06-261-1/+1
| | | | | | | needed to be adjusted. Notes: svn path=/head/; revision=98834
* o __P has been reovedWarner Losh2002-02-021-9/+3
| | | | | | | | | | | | | | | | | | | | | o Old-style K&R declarations have been converted to new C89 style o register has been removed o prototype for main() has been removed (gcc3 makes it an error) o int main(int argc, char *argv[]) is the preferred main definition. o Attempt to not break style(9) conformance for declarations more than they already are. o Change int foo() { ... to int foo(void) { ... Notes: svn path=/head/; revision=90111
* Use STD{ERR,IN,OUT}_FILENO instead of their numeric values. TheSheldon Hearn2001-07-261-2/+2
| | | | | | | | | | definitions are more readable, and it's possible that they're more portable to pathalogical platforms. Submitted by: David Hill <david@phobia.ms> Notes: svn path=/head/; revision=80381
* Fix warnings, some of them serious because sh violated nameMartin Cracauer2000-04-201-6/+3
| | | | | | | | | | | spaces reserved by the header files it includes. mkinit.c still produces C code with redundant declarations, although they are more harmless since they automatically derived from the right places. Notes: svn path=/head/; revision=59436
* Implement ulimit -b for RLIMIT_SBSIZE.Brian Feldman1999-10-091-1/+4
| | | | Notes: svn path=/head/; revision=52072
* $Id$ -> $FreeBSD$Peter Wemm1999-08-271-1/+1
| | | | Notes: svn path=/head/; revision=50471
* Make the behaviour of `read -e', ie. treating backslashes as special,Thomas Gellekum1999-08-261-8/+10
| | | | | | | | | | the default. Add -r option for the read builtin to reverse this. PR: 13274 Reviewed by: cpiazza, hoek, sheldonh Notes: svn path=/head/; revision=50394
* Various spelling/formatting changes.Kris Kennaway1999-05-081-2/+2
| | | | | | | Submitted by: Philippe Charnier <charnier@xp11.frmug.org> Notes: svn path=/head/; revision=46684
* Free memory from setmode.Warner Losh1998-12-161-2/+3
| | | | | | | Obtained from: OpenBSD Notes: svn path=/head/; revision=41844
* Improve bookkeeping of in_waitcmd and style fixes.Martin Cracauer1998-08-251-2/+2
| | | | | | | Submitted by: Bruce Evans Notes: svn path=/head/; revision=38536
* Do not exit on SIGINT in non-interactive shells, fixes PR 1206,Martin Cracauer1998-08-241-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | i.e. this makes emacs usable from system(3). Programs called from shellscripts are now required to exit with proper signal status. That means, they have to kill themself. Exiting with faked numerical exit code is not sufficient. Exit with proper signal status if script exits on signal. Make the wait builtin interruptable, both with and without traps set. Use volatile sig_atomic_t where (and only where) appropriate. (Almost) fix printing of newlines on SIGINT. Make traps setable from trap handlers. This is needed for shellscripts that catch SIGINT for cleanup work but intend to exit on it, hance have to kill themself from a trap handler. I.e. mkdep. While I'm at it, make it -Wall clean. -Wall is not enabled in Makefile, since vararg warnx() macro calls in usr.bin/printf/printf.c are not -Wall-able. PR: 1206 Obtained from: Basic SIGINT fix from Bruce Evans Notes: svn path=/head/; revision=38521