1 /* Toybox infrastructure.
3 * Copyright 2006 Rob Landley <rob@landley.net>
6 #include "generated/config.h"
8 #include "lib/portability.h"
32 #include <sys/ioctl.h>
34 #include <sys/mount.h>
35 #include <sys/resource.h>
37 #include <sys/statfs.h>
38 #include <sys/statvfs.h>
39 #include <sys/sysinfo.h>
42 #include <sys/times.h>
43 #include <sys/types.h>
44 #include <sys/utsname.h>
52 // Internationalization support
60 #include <arpa/inet.h>
63 #include <netinet/in.h>
64 #include <netinet/tcp.h>
66 #include <sys/socket.h>
70 #include "toys/e2fs.h"
72 // Get list of function prototypes for all enabled command_main() functions.
74 #define NEWTOY(name, opts, flags) void name##_main(void);
75 #define OLDTOY(name, oldname, opts, flags)
76 #include "generated/newtoys.h"
77 #include "generated/oldtoys.h"
78 #include "generated/flags.h"
79 #include "generated/globals.h"
81 // These live in main.c
83 struct toy_list *toy_find(char *name);
84 void toy_init(struct toy_list *which, char *argv[]);
85 void toy_exec(char *argv[]);
87 // Flags describing command behavior.
89 #define TOYFLAG_USR (1<<0)
90 #define TOYFLAG_BIN (1<<1)
91 #define TOYFLAG_SBIN (1<<2)
92 #define TOYMASK_LOCATION ((1<<4)-1)
94 // This is a shell built-in function, running in the same process context.
95 #define TOYFLAG_NOFORK (1<<4)
97 // Start command with a umask of 0 (saves old umask in this.old_umask)
98 #define TOYFLAG_UMASK (1<<5)
100 // This command runs as root.
101 #define TOYFLAG_STAYROOT (1<<6)
102 #define TOYFLAG_NEEDROOT (1<<7)
103 #define TOYFLAG_ROOTONLY (TOYFLAG_STAYROOT|TOYFLAG_NEEDROOT)
105 // Array of available commands
107 extern struct toy_list {
109 void (*toy_main)(void);
114 // Global context shared by all commands.
116 extern struct toy_context {
117 struct toy_list *which; // Which entry in toy_list is this one?
118 char **argv; // Original command line arguments
119 char **optargs; // Arguments left over from get_optflags()
120 jmp_buf *rebound; // longjmp here instead of exit when do_rebound set
121 unsigned optflags; // Command line option flags from get_optflags()
122 int exitval; // Value error_exit feeds to exit()
123 int optc; // Count of optargs
124 int exithelp; // Should error_exit print a usage message first?
125 int old_umask; // Old umask preserved by TOYFLAG_UMASK
126 int toycount; // Total number of commands in this build
129 // Two big temporary buffers: one for use by commands, one for library functions
131 extern char toybuf[4096], libbuf[4096];
133 extern char **environ;
137 #define ARRAY_LEN(array) (sizeof(array)/sizeof(*array))