2 /* Toybox infrastructure.
4 * Copyright 2006 Rob Landley <rob@landley.net>
7 #include "generated/config.h"
9 #include "lib/portability.h"
29 #include <sys/ioctl.h>
31 #include <sys/mount.h>
32 #include <sys/resource.h>
34 #include <sys/statvfs.h>
35 #include <sys/sysinfo.h>
37 #include <sys/types.h>
38 #include <sys/utsname.h>
45 #define _XOPEN_SOURCE 600
49 #include "toys/e2fs.h"
51 // Get list of function prototypes for all enabled command_main() functions.
53 #define NEWTOY(name, opts, flags) void name##_main(void);
54 #define OLDTOY(name, oldname, opts, flags)
55 #include "generated/newtoys.h"
56 #include "generated/globals.h"
58 // These live in main.c
60 struct toy_list *toy_find(char *name);
61 void toy_init(struct toy_list *which, char *argv[]);
62 void toy_exec(char *argv[]);
64 // Flags describing command behavior.
66 #define TOYFLAG_USR (1<<0)
67 #define TOYFLAG_BIN (1<<1)
68 #define TOYFLAG_SBIN (1<<2)
69 #define TOYMASK_LOCATION ((1<<4)-1)
71 // This is a shell built-in function, running in the same process context.
72 #define TOYFLAG_NOFORK (1<<4)
74 // Start command with a umask of 0 (saves old umask in this.old_umask)
75 #define TOYFLAG_UMASK (1<<5)
77 // This command runs as root.
78 #define TOYFLAG_STAYROOT (1<<6)
79 #define TOYFLAG_NEEDROOT (1<<7)
80 #define TOYFLAG_ROOTONLY (TOYFLAG_STAYROOT|TOYFLAG_NEEDROOT)
82 // Array of available applets
84 extern struct toy_list {
86 void (*toy_main)(void);
91 // Global context shared by all commands.
93 extern struct toy_context {
94 struct toy_list *which; // Which entry in toy_list is this one?
95 int exitval; // Value error_exit feeds to exit()
96 char **argv; // Original command line arguments
97 unsigned optflags; // Command line option flags from get_optflags()
98 char **optargs; // Arguments left over from get_optflags()
99 int optc; // Count of optargs
100 int exithelp; // Should error_exit print a usage message first?
101 int old_umask; // Old umask preserved by TOYFLAG_UMASK
104 // One big temporary buffer, for use by commands (not library functions).
106 extern char toybuf[4096];
108 #define DEFINE_GLOBALS(...)