2 /* Toybox infrastructure.
4 * Copyright 2006 Rob Landley <rob@landley.net>
7 #include "generated/config.h"
9 #include "lib/portability.h"
31 #include <sys/ioctl.h>
33 #include <sys/mount.h>
34 #include <sys/resource.h>
36 #include <sys/statvfs.h>
37 #include <sys/sysinfo.h>
39 #include <sys/times.h>
40 #include <sys/types.h>
41 #include <sys/utsname.h>
50 #include "toys/e2fs.h"
52 // Get list of function prototypes for all enabled command_main() functions.
54 #define NEWTOY(name, opts, flags) void name##_main(void);
55 #define OLDTOY(name, oldname, opts, flags)
56 #include "generated/newtoys.h"
57 #include "generated/globals.h"
59 // These live in main.c
61 struct toy_list *toy_find(char *name);
62 void toy_init(struct toy_list *which, char *argv[]);
63 void toy_exec(char *argv[]);
65 // Flags describing command behavior.
67 #define TOYFLAG_USR (1<<0)
68 #define TOYFLAG_BIN (1<<1)
69 #define TOYFLAG_SBIN (1<<2)
70 #define TOYMASK_LOCATION ((1<<4)-1)
72 // This is a shell built-in function, running in the same process context.
73 #define TOYFLAG_NOFORK (1<<4)
75 // Start command with a umask of 0 (saves old umask in this.old_umask)
76 #define TOYFLAG_UMASK (1<<5)
78 // This command runs as root.
79 #define TOYFLAG_STAYROOT (1<<6)
80 #define TOYFLAG_NEEDROOT (1<<7)
81 #define TOYFLAG_ROOTONLY (TOYFLAG_STAYROOT|TOYFLAG_NEEDROOT)
83 // Array of available applets
85 extern struct toy_list {
87 void (*toy_main)(void);
92 // Global context shared by all commands.
94 extern struct toy_context {
95 struct toy_list *which; // Which entry in toy_list is this one?
96 int exitval; // Value error_exit feeds to exit()
97 char **argv; // Original command line arguments
98 unsigned optflags; // Command line option flags from get_optflags()
99 char **optargs; // Arguments left over from get_optflags()
100 int optc; // Count of optargs
101 int exithelp; // Should error_exit print a usage message first?
102 int old_umask; // Old umask preserved by TOYFLAG_UMASK
105 // One big temporary buffer, for use by commands (not library functions).
107 extern char toybuf[4096];
109 #define DEFINE_GLOBALS(...)