#include <rpc/pmap_clnt.h>
#endif
-#define _PATH_INETDCONF "/etc/inetd.conf"
#define _PATH_INETDPID "/var/run/inetd.pid"
static struct servent *sp;
static uid_t uid;
-static const char *CONFIG = _PATH_INETDCONF;
+static const char *config_filename = "/etc/inetd.conf";
static FILE *fconfig;
-static char line[1024];
static char *defhost;
/* xstrdup(NULL) returns NULL, but this one
fseek(fconfig, 0L, SEEK_SET);
return 1;
}
- fconfig = fopen(CONFIG, "r");
+ fconfig = fopen(config_filename, "r");
return (fconfig != NULL);
}
static char *nextline(void)
{
+#define line bb_common_bufsiz1
+
char *cp;
FILE *fd = fconfig;
int c;
c = getc(fconfig);
- (void) ungetc(c, fconfig);
- if (c == ' ' || c == '\t')
- if ((cp = nextline()))
+ ungetc(c, fconfig);
+ if (c == ' ' || c == '\t') {
+ cp = nextline();
+ if (cp)
goto again;
+ }
*cpp = NULL;
/* goto erp; */
return NULL;
char protoname[10];
if (!setconfig()) {
- bb_perror_msg("%s", CONFIG);
+ bb_perror_msg("%s", config_filename);
return;
}
for (sep = servtab; sep; sep = sep->se_next)
uid = getuid();
if (uid != 0)
- CONFIG = NULL;
+ config_filename = NULL;
if (argc > 0)
- CONFIG = argv[0];
- if (CONFIG == NULL)
+ config_filename = argv[0];
+ if (config_filename == NULL)
bb_error_msg_and_die("non-root must specify a config file");
#ifdef BB_NOMMU
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
*/
+# include <sys/times.h>
+# include <setjmp.h>
+
#ifdef STANDALONE
# ifndef _GNU_SOURCE
# define _GNU_SOURCE
# endif
-# include <setjmp.h>
-# include <sys/times.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <sys/wait.h>
return local_buf;
}
#else
-# include <setjmp.h>
-# include <sys/times.h>
# include "busybox.h"
extern char **environ;
#endif
*/
typedef void xint; /* base type of jmp_buf, for not broken compilers */
+
/*
* shell components
*/
-
-#define QUOTE 0200
-
#define NOBLOCK ((struct op *)NULL)
#define NOWORD ((char *)NULL)
#define NOWORDS ((char **)NULL)
static char *null; /* null value for variable */
static int intr; /* interrupt pending */
-static char *trap[_NSIG + 1];
-static char ourtrap[_NSIG + 1];
+/* moved to G: static char *trap[_NSIG + 1]; */
+/* moved to G: static char ourtrap[_NSIG + 1]; */
static int trapset; /* trap pending */
static int heedint; /* heed interrupt signals */
static int yynerrs; /* yacc */
-static char line[LINELIM];
-static char *elinep;
+/* moved to G: static char line[LINELIM]; */
#if ENABLE_FEATURE_EDITING
static char *current_prompt;
static line_input_t *line_input_state;
#endif
-static int areanum; /* current allocation area */
-
/*
* other functions
#define INSUB() (e.iop->task == XGRAVE || e.iop->task == XDOLL)
static struct ioarg temparg = { 0, 0, 0, AFID_NOBUF, 0 }; /* temporary for PUSHIO */
-static struct ioarg ioargstack[NPUSH];
+/* moved to G: static struct ioarg ioargstack[NPUSH]; */
static struct io iostack[NPUSH];
-static struct iobuf sharedbuf = { AFID_NOBUF };
-static struct iobuf mainbuf = { AFID_NOBUF };
+/* moved to G: static struct iobuf sharedbuf = { AFID_NOBUF }; */
+/* moved to G: static struct iobuf mainbuf = { AFID_NOBUF }; */
static unsigned bufid = AFID_ID; /* buffer id counter */
-#define PUSHIO(what,arg,gen) ((temparg.what = (arg)), pushio(&temparg,(gen)))
#define RUN(what,arg,gen) ((temparg.what = (arg)), run(&temparg,(gen)))
-/*
- * parsing & execution environment
- */
-static struct env {
- char *linep;
- struct io *iobase;
- struct io *iop;
- xint *errpt; /* void * */
- int iofd;
- struct env *oenv;
-} e;
-
-
/*
* input generators for IO structure
*/
* IO control
*/
static void pushio(struct ioarg *argp, int (*f) (struct ioarg *));
+#define PUSHIO(what,arg,gen) ((temparg.what = (arg)), pushio(&temparg,(gen)))
static int remap(int fd);
static int openpipe(int *pv);
static void closepipe(int *pv);
static void glob0(char *a0, unsigned a1, int a2,
int (*a3) (char *, char *));
static void readhere(char **name, char *s, int ec);
-static void pushio(struct ioarg *argp, int (*f) (struct ioarg *));
static int xxchar(struct ioarg *ap);
struct here {
static int isbreak;
static struct wdblock *wdlist;
static struct wdblock *iolist;
-static char *trap[_NSIG + 1];
-static char ourtrap[_NSIG + 1];
-static int trapset; /* trap pending */
#ifdef MSHDEBUG
static struct var *mshdbg_var;
static int nlseen;
static int iounit = IODEFAULT;
static YYSTYPE yylval;
-static char *elinep = line + sizeof(line) - 5;
-
+static char *elinep; /* done in main(): = line + sizeof(line) - 5 */
static struct here *inhere; /* list of hear docs while parsing */
static struct here *acthere; /* list of active here documents */
static void *brktop;
static void *brkaddr;
+/*
+ * parsing & execution environment
+ */
+struct env {
+ char *linep;
+ struct io *iobase;
+ struct io *iop;
+ xint *errpt; /* void * */
+ int iofd;
+ struct env *oenv;
+};
+
static struct env e = {
- line, /* linep: char ptr */
+ NULL /* set to line in main() */, /* linep: char ptr */
iostack, /* iobase: struct io ptr */
iostack - 1, /* iop: struct io ptr */
(xint *) NULL, /* errpt: void ptr for errors? */
(struct env *) NULL /* oenv: struct env ptr */
};
+
+struct globals {
+ char ourtrap[_NSIG + 1];
+ char *trap[_NSIG + 1];
+ struct iobuf sharedbuf; /* in main(): set to { AFID_NOBUF } */
+ struct iobuf mainbuf; /* in main(): set to { AFID_NOBUF } */
+ struct ioarg ioargstack[NPUSH];
+ char filechar_cmdbuf[BUFSIZ];
+ char line[LINELIM];
+ char child_cmd[LINELIM];
+};
+
+#define G (*ptr_to_globals)
+#define ourtrap (G.ourtrap )
+#define trap (G.trap )
+#define sharedbuf (G.sharedbuf )
+#define mainbuf (G.mainbuf )
+#define ioargstack (G.ioargstack )
+#define filechar_cmdbuf (G.filechar_cmdbuf)
+#define line (G.line )
+#define child_cmd (G.child_cmd )
+
+
#ifdef MSHDEBUG
void print_t(struct op *t)
{
#define CMASK 0377
#define QUOTE 0200
-#define QMASK (CMASK&~QUOTE)
+#define QMASK (CMASK & ~QUOTE)
#define NOT '!' /* might use ^ */
static const char *cclass(const char *p, int sub)
static int grave(int quoted)
{
+ /* moved to G: static char child_cmd[LINELIM]; */
+
const char *cp;
int i;
int j;
int pf[2];
- static char child_cmd[LINELIM];
const char *src;
char *dest;
int count;
}
#if ENABLE_FEATURE_EDITING
if (interactive && isatty(ap->afile)) {
- static char mycommand[BUFSIZ];
+ /* moved to G: static char filechar_cmdbuf[BUFSIZ]; */
static int position = 0, size = 0;
while (size == 0 || position >= size) {
- read_line_input(current_prompt, mycommand, BUFSIZ, line_input_state);
- size = strlen(mycommand);
+ read_line_input(current_prompt, filechar_cmdbuf, BUFSIZ, line_input_state);
+ size = strlen(filechar_cmdbuf);
position = 0;
}
- c = mycommand[position];
+ c = filechar_cmdbuf[position];
position++;
return c;
}
char *name, **ap;
int (*iof) (struct ioarg *);
+ PTR_TO_GLOBALS = xzalloc(sizeof(G));
+ sharedbuf.id = AFID_NOBUF;
+ mainbuf.id = AFID_NOBUF;
+ e.linep = line;
+ elinep = line + sizeof(line) - 5;
+
#if ENABLE_FEATURE_EDITING
line_input_state = new_line_input_t(FOR_SHELL);
#endif