1 /* Toybox infrastructure.
3 * Copyright 2006 Rob Landley <rob@landley.net>
6 // Stuff that needs to go before the standard headers
8 #include "generated/config.h"
9 #include "lib/portability.h"
11 // General posix-2008 headers
34 #include <sys/resource.h>
36 #include <sys/statvfs.h>
38 #include <sys/times.h>
39 #include <sys/utsname.h>
49 #include <arpa/inet.h>
52 #include <netinet/in.h>
53 #include <netinet/tcp.h>
55 #include <sys/socket.h>
58 // Internationalization support (also in POSIX and LSB)
67 #include <sys/statfs.h>
68 #include <sys/sysinfo.h>
70 #include <sys/ioctl.h>
74 #include "lib/toyflags.h"
75 #include "toys/e2fs.h"
77 // Get list of function prototypes for all enabled command_main() functions.
79 #define NEWTOY(name, opts, flags) void name##_main(void);
80 #define OLDTOY(name, oldname, flags) void oldname##_main(void);
81 #include "generated/newtoys.h"
82 #include "generated/flags.h"
83 #include "generated/globals.h"
84 #include "generated/tags.h"
86 // These live in main.c
88 struct toy_list *toy_find(char *name);
89 void toy_init(struct toy_list *which, char *argv[]);
90 void toy_exec(char *argv[]);
92 // Array of available commands
94 extern struct toy_list {
96 void (*toy_main)(void);
101 // Global context shared by all commands.
103 extern struct toy_context {
104 struct toy_list *which; // Which entry in toy_list is this one?
105 char **argv; // Original command line arguments
106 char **optargs; // Arguments left over from get_optflags()
107 unsigned long long optflags; // Command line option flags from get_optflags()
108 int exitval; // Value error_exit feeds to exit()
109 int optc; // Count of optargs
110 int old_umask; // Old umask preserved by TOYFLAG_UMASK
111 short toycount; // Total number of commands in this build
112 short signal; // generic_signal() records what signal it saw here
113 int signalfd; // and writes signal to this fd, if set
114 int wasroot; // dropped setuid
116 // This is at the end so toy_init() doesn't zero it.
117 jmp_buf *rebound; // longjmp here instead of exit when do_rebound set
118 struct arg_list *xexit; // atexit() functions for xexit(), set by sigatexit()
119 void *stacktop; // nested toy_exec() call count, or 0 if vforked
122 // Two big temporary buffers: one for use by commands, one for library functions
124 extern char toybuf[4096], libbuf[4096];
126 extern char **environ;
129 #define ARRAY_LEN(array) (sizeof(array)/sizeof(*array))
130 #define TAGGED_ARRAY(X, ...) {__VA_ARGS__}