aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--editors/ed.c12
-rw-r--r--networking/inetd.c24
-rw-r--r--shell/msh.c104
3 files changed, 83 insertions, 57 deletions
diff --git a/editors/ed.c b/editors/ed.c
index 42adca409..1706e4271 100644
--- a/editors/ed.c
+++ b/editors/ed.c
@@ -9,8 +9,12 @@
9 9
10#include "busybox.h" 10#include "busybox.h"
11 11
12#define USERSIZE 1024 /* max line length typed in by user */ 12enum {
13#define INITBUF_SIZE 1024 /* initial buffer size */ 13 USERSIZE = sizeof(bb_common_bufsiz1) > 1024 ? 1024
14 : sizeof(bb_common_bufsiz1) - 1, /* max line length typed in by user */
15 INITBUF_SIZE = 1024, /* initial buffer size */
16};
17
14typedef struct LINE { 18typedef struct LINE {
15 struct LINE *next; 19 struct LINE *next;
16 struct LINE *prev; 20 struct LINE *prev;
@@ -18,9 +22,11 @@ typedef struct LINE {
18 char data[1]; 22 char data[1];
19} LINE; 23} LINE;
20 24
25#define searchString bb_common_bufsiz1
26
21static LINE lines, *curLine; 27static LINE lines, *curLine;
22static int curNum, lastNum, marks[26], dirty; 28static int curNum, lastNum, marks[26], dirty;
23static char *bufBase, *bufPtr, *fileName, searchString[USERSIZE]; 29static char *bufBase, *bufPtr, *fileName;
24static int bufUsed, bufSize; 30static int bufUsed, bufSize;
25 31
26static void doCommands(void); 32static void doCommands(void);
diff --git a/networking/inetd.c b/networking/inetd.c
index 48e23db2e..83123463f 100644
--- a/networking/inetd.c
+++ b/networking/inetd.c
@@ -172,7 +172,6 @@
172#include <rpc/pmap_clnt.h> 172#include <rpc/pmap_clnt.h>
173#endif 173#endif
174 174
175#define _PATH_INETDCONF "/etc/inetd.conf"
176#define _PATH_INETDPID "/var/run/inetd.pid" 175#define _PATH_INETDPID "/var/run/inetd.pid"
177 176
178 177
@@ -327,10 +326,9 @@ static int timingout;
327static struct servent *sp; 326static struct servent *sp;
328static uid_t uid; 327static uid_t uid;
329 328
330static const char *CONFIG = _PATH_INETDCONF; 329static const char *config_filename = "/etc/inetd.conf";
331 330
332static FILE *fconfig; 331static FILE *fconfig;
333static char line[1024];
334static char *defhost; 332static char *defhost;
335 333
336/* xstrdup(NULL) returns NULL, but this one 334/* xstrdup(NULL) returns NULL, but this one
@@ -350,7 +348,7 @@ static int setconfig(void)
350 fseek(fconfig, 0L, SEEK_SET); 348 fseek(fconfig, 0L, SEEK_SET);
351 return 1; 349 return 1;
352 } 350 }
353 fconfig = fopen(CONFIG, "r"); 351 fconfig = fopen(config_filename, "r");
354 return (fconfig != NULL); 352 return (fconfig != NULL);
355} 353}
356 354
@@ -511,6 +509,8 @@ static void setup(servtab_t *sep)
511 509
512static char *nextline(void) 510static char *nextline(void)
513{ 511{
512#define line bb_common_bufsiz1
513
514 char *cp; 514 char *cp;
515 FILE *fd = fconfig; 515 FILE *fd = fconfig;
516 516
@@ -541,10 +541,12 @@ static char *skip(char **cpp) /* int report; */
541 int c; 541 int c;
542 542
543 c = getc(fconfig); 543 c = getc(fconfig);
544 (void) ungetc(c, fconfig); 544 ungetc(c, fconfig);
545 if (c == ' ' || c == '\t') 545 if (c == ' ' || c == '\t') {
546 if ((cp = nextline())) 546 cp = nextline();
547 if (cp)
547 goto again; 548 goto again;
549 }
548 *cpp = NULL; 550 *cpp = NULL;
549 /* goto erp; */ 551 /* goto erp; */
550 return NULL; 552 return NULL;
@@ -924,7 +926,7 @@ static void config(int sig ATTRIBUTE_UNUSED)
924 char protoname[10]; 926 char protoname[10];
925 927
926 if (!setconfig()) { 928 if (!setconfig()) {
927 bb_perror_msg("%s", CONFIG); 929 bb_perror_msg("%s", config_filename);
928 return; 930 return;
929 } 931 }
930 for (sep = servtab; sep; sep = sep->se_next) 932 for (sep = servtab; sep; sep = sep->se_next)
@@ -1281,10 +1283,10 @@ int inetd_main(int argc, char *argv[])
1281 1283
1282 uid = getuid(); 1284 uid = getuid();
1283 if (uid != 0) 1285 if (uid != 0)
1284 CONFIG = NULL; 1286 config_filename = NULL;
1285 if (argc > 0) 1287 if (argc > 0)
1286 CONFIG = argv[0]; 1288 config_filename = argv[0];
1287 if (CONFIG == NULL) 1289 if (config_filename == NULL)
1288 bb_error_msg_and_die("non-root must specify a config file"); 1290 bb_error_msg_and_die("non-root must specify a config file");
1289 1291
1290#ifdef BB_NOMMU 1292#ifdef BB_NOMMU
diff --git a/shell/msh.c b/shell/msh.c
index d9dd3efb2..66b10f346 100644
--- a/shell/msh.c
+++ b/shell/msh.c
@@ -13,12 +13,13 @@
13 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. 13 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
14 */ 14 */
15 15
16# include <sys/times.h>
17# include <setjmp.h>
18
16#ifdef STANDALONE 19#ifdef STANDALONE
17# ifndef _GNU_SOURCE 20# ifndef _GNU_SOURCE
18# define _GNU_SOURCE 21# define _GNU_SOURCE
19# endif 22# endif
20# include <setjmp.h>
21# include <sys/times.h>
22# include <sys/types.h> 23# include <sys/types.h>
23# include <sys/stat.h> 24# include <sys/stat.h>
24# include <sys/wait.h> 25# include <sys/wait.h>
@@ -82,8 +83,6 @@ static char *itoa(int n)
82 return local_buf; 83 return local_buf;
83} 84}
84#else 85#else
85# include <setjmp.h>
86# include <sys/times.h>
87# include "busybox.h" 86# include "busybox.h"
88extern char **environ; 87extern char **environ;
89#endif 88#endif
@@ -162,12 +161,10 @@ int mshdbg_rc = 0;
162 */ 161 */
163typedef void xint; /* base type of jmp_buf, for not broken compilers */ 162typedef void xint; /* base type of jmp_buf, for not broken compilers */
164 163
164
165/* 165/*
166 * shell components 166 * shell components
167 */ 167 */
168
169#define QUOTE 0200
170
171#define NOBLOCK ((struct op *)NULL) 168#define NOBLOCK ((struct op *)NULL)
172#define NOWORD ((char *)NULL) 169#define NOWORD ((char *)NULL)
173#define NOWORDS ((char **)NULL) 170#define NOWORDS ((char **)NULL)
@@ -297,24 +294,21 @@ static char *flag = flags - 'a';
297static char *null; /* null value for variable */ 294static char *null; /* null value for variable */
298static int intr; /* interrupt pending */ 295static int intr; /* interrupt pending */
299 296
300static char *trap[_NSIG + 1]; 297/* moved to G: static char *trap[_NSIG + 1]; */
301static char ourtrap[_NSIG + 1]; 298/* moved to G: static char ourtrap[_NSIG + 1]; */
302static int trapset; /* trap pending */ 299static int trapset; /* trap pending */
303 300
304static int heedint; /* heed interrupt signals */ 301static int heedint; /* heed interrupt signals */
305 302
306static int yynerrs; /* yacc */ 303static int yynerrs; /* yacc */
307 304
308static char line[LINELIM]; 305/* moved to G: static char line[LINELIM]; */
309static char *elinep;
310 306
311#if ENABLE_FEATURE_EDITING 307#if ENABLE_FEATURE_EDITING
312static char *current_prompt; 308static char *current_prompt;
313static line_input_t *line_input_state; 309static line_input_t *line_input_state;
314#endif 310#endif
315 311
316static int areanum; /* current allocation area */
317
318 312
319/* 313/*
320 * other functions 314 * other functions
@@ -483,30 +477,16 @@ struct io {
483#define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL) 477#define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL)
484 478
485static struct ioarg temparg = { 0, 0, 0, AFID_NOBUF, 0 }; /* temporary for PUSHIO */ 479static struct ioarg temparg = { 0, 0, 0, AFID_NOBUF, 0 }; /* temporary for PUSHIO */
486static struct ioarg ioargstack[NPUSH]; 480/* moved to G: static struct ioarg ioargstack[NPUSH]; */
487static struct io iostack[NPUSH]; 481static struct io iostack[NPUSH];
488static struct iobuf sharedbuf = { AFID_NOBUF }; 482/* moved to G: static struct iobuf sharedbuf = { AFID_NOBUF }; */
489static struct iobuf mainbuf = { AFID_NOBUF }; 483/* moved to G: static struct iobuf mainbuf = { AFID_NOBUF }; */
490static unsigned bufid = AFID_ID; /* buffer id counter */ 484static unsigned bufid = AFID_ID; /* buffer id counter */
491 485
492#define PUSHIO(what,arg,gen) ((temparg.what = (arg)), pushio(&temparg,(gen)))
493#define RUN(what,arg,gen) ((temparg.what = (arg)), run(&temparg,(gen))) 486#define RUN(what,arg,gen) ((temparg.what = (arg)), run(&temparg,(gen)))
494 487
495 488
496/* 489/*
497 * parsing & execution environment
498 */
499static struct env {
500 char *linep;
501 struct io *iobase;
502 struct io *iop;
503 xint *errpt; /* void * */
504 int iofd;
505 struct env *oenv;
506} e;
507
508
509/*
510 * input generators for IO structure 490 * input generators for IO structure
511 */ 491 */
512static int nlchar(struct ioarg *ap); 492static int nlchar(struct ioarg *ap);
@@ -537,6 +517,7 @@ static void ioecho(char c);
537 * IO control 517 * IO control
538 */ 518 */
539static void pushio(struct ioarg *argp, int (*f) (struct ioarg *)); 519static void pushio(struct ioarg *argp, int (*f) (struct ioarg *));
520#define PUSHIO(what,arg,gen) ((temparg.what = (arg)), pushio(&temparg,(gen)))
540static int remap(int fd); 521static int remap(int fd);
541static int openpipe(int *pv); 522static int openpipe(int *pv);
542static void closepipe(int *pv); 523static void closepipe(int *pv);
@@ -599,7 +580,6 @@ static int xstrcmp(char *p1, char *p2);
599static void glob0(char *a0, unsigned a1, int a2, 580static void glob0(char *a0, unsigned a1, int a2,
600 int (*a3) (char *, char *)); 581 int (*a3) (char *, char *));
601static void readhere(char **name, char *s, int ec); 582static void readhere(char **name, char *s, int ec);
602static void pushio(struct ioarg *argp, int (*f) (struct ioarg *));
603static int xxchar(struct ioarg *ap); 583static int xxchar(struct ioarg *ap);
604 584
605struct here { 585struct here {
@@ -705,9 +685,6 @@ static struct brkcon *brklist;
705static int isbreak; 685static int isbreak;
706static struct wdblock *wdlist; 686static struct wdblock *wdlist;
707static struct wdblock *iolist; 687static struct wdblock *iolist;
708static char *trap[_NSIG + 1];
709static char ourtrap[_NSIG + 1];
710static int trapset; /* trap pending */
711 688
712#ifdef MSHDEBUG 689#ifdef MSHDEBUG
713static struct var *mshdbg_var; 690static struct var *mshdbg_var;
@@ -731,8 +708,7 @@ static int peeksym;
731static int nlseen; 708static int nlseen;
732static int iounit = IODEFAULT; 709static int iounit = IODEFAULT;
733static YYSTYPE yylval; 710static YYSTYPE yylval;
734static char *elinep = line + sizeof(line) - 5; 711static char *elinep; /* done in main(): = line + sizeof(line) - 5 */
735
736 712
737static struct here *inhere; /* list of hear docs while parsing */ 713static struct here *inhere; /* list of hear docs while parsing */
738static struct here *acthere; /* list of active here documents */ 714static struct here *acthere; /* list of active here documents */
@@ -742,8 +718,20 @@ static struct region *areanxt; /* starting point of scan */
742static void *brktop; 718static void *brktop;
743static void *brkaddr; 719static void *brkaddr;
744 720
721/*
722 * parsing & execution environment
723 */
724struct env {
725 char *linep;
726 struct io *iobase;
727 struct io *iop;
728 xint *errpt; /* void * */
729 int iofd;
730 struct env *oenv;
731};
732
745static struct env e = { 733static struct env e = {
746 line, /* linep: char ptr */ 734 NULL /* set to line in main() */, /* linep: char ptr */
747 iostack, /* iobase: struct io ptr */ 735 iostack, /* iobase: struct io ptr */
748 iostack - 1, /* iop: struct io ptr */ 736 iostack - 1, /* iop: struct io ptr */
749 (xint *) NULL, /* errpt: void ptr for errors? */ 737 (xint *) NULL, /* errpt: void ptr for errors? */
@@ -751,6 +739,29 @@ static struct env e = {
751 (struct env *) NULL /* oenv: struct env ptr */ 739 (struct env *) NULL /* oenv: struct env ptr */
752}; 740};
753 741
742
743struct globals {
744 char ourtrap[_NSIG + 1];
745 char *trap[_NSIG + 1];
746 struct iobuf sharedbuf; /* in main(): set to { AFID_NOBUF } */
747 struct iobuf mainbuf; /* in main(): set to { AFID_NOBUF } */
748 struct ioarg ioargstack[NPUSH];
749 char filechar_cmdbuf[BUFSIZ];
750 char line[LINELIM];
751 char child_cmd[LINELIM];
752};
753
754#define G (*ptr_to_globals)
755#define ourtrap (G.ourtrap )
756#define trap (G.trap )
757#define sharedbuf (G.sharedbuf )
758#define mainbuf (G.mainbuf )
759#define ioargstack (G.ioargstack )
760#define filechar_cmdbuf (G.filechar_cmdbuf)
761#define line (G.line )
762#define child_cmd (G.child_cmd )
763
764
754#ifdef MSHDEBUG 765#ifdef MSHDEBUG
755void print_t(struct op *t) 766void print_t(struct op *t)
756{ 767{
@@ -1517,7 +1528,7 @@ static void onintr(int s) /* ANSI C requires a parameter */
1517 1528
1518#define CMASK 0377 1529#define CMASK 0377
1519#define QUOTE 0200 1530#define QUOTE 0200
1520#define QMASK (CMASK&~QUOTE) 1531#define QMASK (CMASK & ~QUOTE)
1521#define NOT '!' /* might use ^ */ 1532#define NOT '!' /* might use ^ */
1522 1533
1523static const char *cclass(const char *p, int sub) 1534static const char *cclass(const char *p, int sub)
@@ -4011,11 +4022,12 @@ static int dollar(int quoted)
4011 4022
4012static int grave(int quoted) 4023static int grave(int quoted)
4013{ 4024{
4025 /* moved to G: static char child_cmd[LINELIM]; */
4026
4014 const char *cp; 4027 const char *cp;
4015 int i; 4028 int i;
4016 int j; 4029 int j;
4017 int pf[2]; 4030 int pf[2];
4018 static char child_cmd[LINELIM];
4019 const char *src; 4031 const char *src;
4020 char *dest; 4032 char *dest;
4021 int count; 4033 int count;
@@ -4823,15 +4835,15 @@ static int filechar(struct ioarg *ap)
4823 } 4835 }
4824#if ENABLE_FEATURE_EDITING 4836#if ENABLE_FEATURE_EDITING
4825 if (interactive && isatty(ap->afile)) { 4837 if (interactive && isatty(ap->afile)) {
4826 static char mycommand[BUFSIZ]; 4838 /* moved to G: static char filechar_cmdbuf[BUFSIZ]; */
4827 static int position = 0, size = 0; 4839 static int position = 0, size = 0;
4828 4840
4829 while (size == 0 || position >= size) { 4841 while (size == 0 || position >= size) {
4830 read_line_input(current_prompt, mycommand, BUFSIZ, line_input_state); 4842 read_line_input(current_prompt, filechar_cmdbuf, BUFSIZ, line_input_state);
4831 size = strlen(mycommand); 4843 size = strlen(filechar_cmdbuf);
4832 position = 0; 4844 position = 0;
4833 } 4845 }
4834 c = mycommand[position]; 4846 c = filechar_cmdbuf[position];
4835 position++; 4847 position++;
4836 return c; 4848 return c;
4837 } 4849 }
@@ -5176,6 +5188,12 @@ int msh_main(int argc, char **argv)
5176 char *name, **ap; 5188 char *name, **ap;
5177 int (*iof) (struct ioarg *); 5189 int (*iof) (struct ioarg *);
5178 5190
5191 PTR_TO_GLOBALS = xzalloc(sizeof(G));
5192 sharedbuf.id = AFID_NOBUF;
5193 mainbuf.id = AFID_NOBUF;
5194 e.linep = line;
5195 elinep = line + sizeof(line) - 5;
5196
5179#if ENABLE_FEATURE_EDITING 5197#if ENABLE_FEATURE_EDITING
5180 line_input_state = new_line_input_t(FOR_SHELL); 5198 line_input_state = new_line_input_t(FOR_SHELL);
5181#endif 5199#endif