aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-10-29 19:17:29 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-10-29 19:17:29 +0000
commita59f435b5f823ee7bdf55ed0e39688a12b7c881e (patch)
tree3370f2912fb6db680af5c77f2aae4e01cd7fa093
parent7ab5e3dfcd74c97d39c4a0effc5a1027c8a0aa7f (diff)
downloadbusybox-w32-a59f435b5f823ee7bdf55ed0e39688a12b7c881e.tar.gz
busybox-w32-a59f435b5f823ee7bdf55ed0e39688a12b7c881e.tar.bz2
busybox-w32-a59f435b5f823ee7bdf55ed0e39688a12b7c881e.zip
ash: if tcgetattr(stdin) fails, don't mess with tcsetattr
ash: size-optimize ulimit's table of limits text data bss dec hex filename 777345 974 9676 787995 c061b busybox_old 777253 974 9676 787903 c05bf busybox_unstripped
-rw-r--r--shell/ash.c110
1 files changed, 75 insertions, 35 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 58527bf9b..bb930f55f 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -11575,26 +11575,31 @@ readcmd(int argc, char **argv)
11575 ifs = defifs; 11575 ifs = defifs;
11576#if ENABLE_ASH_READ_NCHARS 11576#if ENABLE_ASH_READ_NCHARS
11577 if (n_flag || silent) { 11577 if (n_flag || silent) {
11578 tcgetattr(0, &tty); 11578 if (tcgetattr(0, &tty) != 0) {
11579 old_tty = tty; 11579 /* Not a tty */
11580 if (n_flag) { 11580 n_flag = 0;
11581 tty.c_lflag &= ~ICANON; 11581 silent = 0;
11582 tty.c_cc[VMIN] = nchars; 11582 } else {
11583 } 11583 old_tty = tty;
11584 if (silent) { 11584 if (n_flag) {
11585 tty.c_lflag &= ~(ECHO|ECHOK|ECHONL); 11585 tty.c_lflag &= ~ICANON;
11586 tty.c_cc[VMIN] = nchars < 256 ? nchars : 255;
11587 }
11588 if (silent) {
11589 tty.c_lflag &= ~(ECHO | ECHOK | ECHONL);
11590 }
11591 tcsetattr(0, TCSANOW, &tty);
11586 } 11592 }
11587 tcsetattr(0, TCSANOW, &tty);
11588 } 11593 }
11589#endif 11594#endif
11590#if ENABLE_ASH_READ_TIMEOUT 11595#if ENABLE_ASH_READ_TIMEOUT
11591 if (ts.tv_sec || ts.tv_usec) { 11596 if (ts.tv_sec || ts.tv_usec) {
11592// TODO: replace with poll, it is smaller
11593 FD_ZERO(&set); 11597 FD_ZERO(&set);
11594 FD_SET(0, &set); 11598 FD_SET(0, &set);
11595 11599
11596 i = select(FD_SETSIZE, &set, NULL, NULL, &ts); 11600 /* poll-based wait produces bigger code, using select */
11597 if (!i) { 11601 i = select(1, &set, NULL, NULL, &ts);
11602 if (!i) { /* timed out! */
11598#if ENABLE_ASH_READ_NCHARS 11603#if ENABLE_ASH_READ_NCHARS
11599 if (n_flag) 11604 if (n_flag)
11600 tcsetattr(0, TCSANOW, &old_tty); 11605 tcsetattr(0, TCSANOW, &old_tty);
@@ -11742,48 +11747,81 @@ umaskcmd(int argc, char **argv)
11742 */ 11747 */
11743 11748
11744struct limits { 11749struct limits {
11745 const char *name; 11750 uint8_t cmd; /* RLIMIT_xxx fit into it */
11746 int cmd; 11751 uint8_t factor_shift; /* shift by to get rlim_{cur,max} values */
11747 int factor; /* multiply by to get rlim_{cur,max} values */
11748 char option; 11752 char option;
11749}; 11753};
11750 11754
11751static const struct limits limits[] = { 11755static const struct limits limits_tbl[] = {
11752#ifdef RLIMIT_CPU 11756#ifdef RLIMIT_CPU
11753 { "time(seconds)", RLIMIT_CPU, 1, 't' }, 11757 { RLIMIT_CPU, 0, 't' },
11754#endif 11758#endif
11755#ifdef RLIMIT_FSIZE 11759#ifdef RLIMIT_FSIZE
11756 { "file(blocks)", RLIMIT_FSIZE, 512, 'f' }, 11760 { RLIMIT_FSIZE, 9, 'f' },
11757#endif 11761#endif
11758#ifdef RLIMIT_DATA 11762#ifdef RLIMIT_DATA
11759 { "data(kbytes)", RLIMIT_DATA, 1024, 'd' }, 11763 { RLIMIT_DATA, 10, 'd' },
11760#endif 11764#endif
11761#ifdef RLIMIT_STACK 11765#ifdef RLIMIT_STACK
11762 { "stack(kbytes)", RLIMIT_STACK, 1024, 's' }, 11766 { RLIMIT_STACK, 10, 's' },
11763#endif 11767#endif
11764#ifdef RLIMIT_CORE 11768#ifdef RLIMIT_CORE
11765 { "coredump(blocks)", RLIMIT_CORE, 512, 'c' }, 11769 { RLIMIT_CORE, 9, 'c' },
11766#endif 11770#endif
11767#ifdef RLIMIT_RSS 11771#ifdef RLIMIT_RSS
11768 { "memory(kbytes)", RLIMIT_RSS, 1024, 'm' }, 11772 { RLIMIT_RSS, 10, 'm' },
11769#endif 11773#endif
11770#ifdef RLIMIT_MEMLOCK 11774#ifdef RLIMIT_MEMLOCK
11771 { "locked memory(kbytes)", RLIMIT_MEMLOCK, 1024, 'l' }, 11775 { RLIMIT_MEMLOCK, 10, 'l' },
11772#endif 11776#endif
11773#ifdef RLIMIT_NPROC 11777#ifdef RLIMIT_NPROC
11774 { "process", RLIMIT_NPROC, 1, 'p' }, 11778 { RLIMIT_NPROC, 0, 'p' },
11775#endif 11779#endif
11776#ifdef RLIMIT_NOFILE 11780#ifdef RLIMIT_NOFILE
11777 { "nofiles", RLIMIT_NOFILE, 1, 'n' }, 11781 { RLIMIT_NOFILE, 0, 'n' },
11778#endif 11782#endif
11779#ifdef RLIMIT_AS 11783#ifdef RLIMIT_AS
11780 { "vmemory(kbytes)", RLIMIT_AS, 1024, 'v' }, 11784 { RLIMIT_AS, 10, 'v' },
11781#endif 11785#endif
11782#ifdef RLIMIT_LOCKS 11786#ifdef RLIMIT_LOCKS
11783 { "locks", RLIMIT_LOCKS, 1, 'w' }, 11787 { RLIMIT_LOCKS, 0, 'w' },
11784#endif 11788#endif
11785 { NULL, 0, 0, '\0' }
11786}; 11789};
11790static const char limits_name[] =
11791#ifdef RLIMIT_CPU
11792 "time(seconds)" "\0"
11793#endif
11794#ifdef RLIMIT_FSIZE
11795 "file(blocks)" "\0"
11796#endif
11797#ifdef RLIMIT_DATA
11798 "data(kb)" "\0"
11799#endif
11800#ifdef RLIMIT_STACK
11801 "stack(kb)" "\0"
11802#endif
11803#ifdef RLIMIT_CORE
11804 "coredump(blocks)" "\0"
11805#endif
11806#ifdef RLIMIT_RSS
11807 "memory(kb)" "\0"
11808#endif
11809#ifdef RLIMIT_MEMLOCK
11810 "locked memory(kb)" "\0"
11811#endif
11812#ifdef RLIMIT_NPROC
11813 "process" "\0"
11814#endif
11815#ifdef RLIMIT_NOFILE
11816 "nofiles" "\0"
11817#endif
11818#ifdef RLIMIT_AS
11819 "vmemory(kb)" "\0"
11820#endif
11821#ifdef RLIMIT_LOCKS
11822 "locks" "\0"
11823#endif
11824;
11787 11825
11788enum limtype { SOFT = 0x1, HARD = 0x2 }; 11826enum limtype { SOFT = 0x1, HARD = 0x2 };
11789 11827
@@ -11800,7 +11838,7 @@ printlim(enum limtype how, const struct rlimit *limit,
11800 if (val == RLIM_INFINITY) 11838 if (val == RLIM_INFINITY)
11801 out1fmt("unlimited\n"); 11839 out1fmt("unlimited\n");
11802 else { 11840 else {
11803 val /= l->factor; 11841 val >>= l->factor_shift;
11804 out1fmt("%lld\n", (long long) val); 11842 out1fmt("%lld\n", (long long) val);
11805 } 11843 }
11806} 11844}
@@ -11866,8 +11904,8 @@ ulimitcmd(int argc, char **argv)
11866 what = optc; 11904 what = optc;
11867 } 11905 }
11868 11906
11869 for (l = limits; l->option != what; l++) 11907 for (l = limits_tbl; l->option != what; l++)
11870 ; 11908 continue;
11871 11909
11872 set = *argptr ? 1 : 0; 11910 set = *argptr ? 1 : 0;
11873 if (set) { 11911 if (set) {
@@ -11887,13 +11925,15 @@ ulimitcmd(int argc, char **argv)
11887 } 11925 }
11888 if (c) 11926 if (c)
11889 ash_msg_and_raise_error("bad number"); 11927 ash_msg_and_raise_error("bad number");
11890 val *= l->factor; 11928 val <<= l->factor_shift;
11891 } 11929 }
11892 } 11930 }
11893 if (all) { 11931 if (all) {
11894 for (l = limits; l->name; l++) { 11932 const char *lname = limits_name;
11933 for (l = limits_tbl; l != &limits_tbl[ARRAY_SIZE(limits_tbl)]; l++) {
11895 getrlimit(l->cmd, &limit); 11934 getrlimit(l->cmd, &limit);
11896 out1fmt("%-20s ", l->name); 11935 out1fmt("%-20s ", lname);
11936 lname += strlen(lname) + 1;
11897 printlim(how, &limit, l); 11937 printlim(how, &limit, l);
11898 } 11938 }
11899 return 0; 11939 return 0;