toys.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /* Toybox infrastructure.
  2. *
  3. * Copyright 2006 Rob Landley <rob@landley.net>
  4. */
  5. // Stuff that needs to go before the standard headers
  6. #include "generated/config.h"
  7. #include "lib/portability.h"
  8. // General posix-2008 headers
  9. #include <ctype.h>
  10. #include <dirent.h>
  11. #include <errno.h>
  12. #include <fcntl.h>
  13. #include <fnmatch.h>
  14. #include <grp.h>
  15. #include <inttypes.h>
  16. #include <limits.h>
  17. #include <math.h>
  18. #include <paths.h>
  19. #include <pwd.h>
  20. #include <regex.h>
  21. #include <sched.h>
  22. #include <setjmp.h>
  23. #include <signal.h>
  24. #include <stdarg.h>
  25. #include <stddef.h>
  26. #include <stdint.h>
  27. #include <stdio.h>
  28. #include <stdlib.h>
  29. #include <string.h>
  30. #include <strings.h>
  31. #include <sys/mman.h>
  32. #include <sys/resource.h>
  33. #include <sys/stat.h>
  34. #include <sys/statvfs.h>
  35. #include <sys/time.h>
  36. #include <sys/times.h>
  37. #include <sys/utsname.h>
  38. #include <sys/wait.h>
  39. #include <syslog.h>
  40. #include <termios.h>
  41. #include <time.h>
  42. #include <unistd.h>
  43. #include <utime.h>
  44. // Posix networking
  45. #include <arpa/inet.h>
  46. #include <netdb.h>
  47. #include <net/if.h>
  48. #include <netinet/in.h>
  49. #include <netinet/tcp.h>
  50. #include <poll.h>
  51. #include <sys/socket.h>
  52. #include <sys/un.h>
  53. // Internationalization support (also in POSIX)
  54. #include <langinfo.h>
  55. #include <locale.h>
  56. #include <wchar.h>
  57. #include <wctype.h>
  58. // Non-posix headers
  59. #include <sys/ioctl.h>
  60. #include <sys/syscall.h>
  61. #include "lib/lib.h"
  62. #include "lib/lsm.h"
  63. #include "lib/toyflags.h"
  64. // Get list of function prototypes for all enabled command_main() functions.
  65. #define NEWTOY(name, opts, flags) void name##_main(void);
  66. #define OLDTOY(name, oldname, flags) void oldname##_main(void);
  67. #include "generated/newtoys.h"
  68. #include "generated/flags.h"
  69. #include "generated/globals.h"
  70. #include "generated/tags.h"
  71. // These live in main.c
  72. struct toy_list *toy_find(char *name);
  73. void show_help(FILE *out, int full);
  74. void check_help(char **arg);
  75. void toy_singleinit(struct toy_list *which, char *argv[]);
  76. void toy_init(struct toy_list *which, char *argv[]);
  77. void toy_exec(char *argv[]);
  78. // Array of available commands
  79. extern struct toy_list {
  80. char *name;
  81. void (*toy_main)(void);
  82. char *options;
  83. unsigned flags;
  84. } toy_list[];
  85. // Global context shared by all commands.
  86. extern struct toy_context {
  87. struct toy_list *which; // Which entry in toy_list is this one?
  88. char **argv; // Original command line arguments
  89. char **optargs; // Arguments left over from get_optflags()
  90. unsigned long long optflags; // Command line option flags from get_optflags()
  91. int optc; // Count of optargs
  92. short toycount; // Total number of commands in this build
  93. char exitval; // Value error_exit feeds to exit()
  94. char wasroot; // dropped setuid
  95. // toy_init() should not zero past here.
  96. sigjmp_buf *rebound; // siglongjmp here instead of exit when do_rebound
  97. struct arg_list *xexit; // atexit() functions for xexit(), set by sigatexit()
  98. void *stacktop; // nested toy_exec() call count, or 0 if vforked
  99. int envc; // Count of original environ entries
  100. int old_umask; // Old umask preserved by TOYFLAG_UMASK
  101. short signal; // generic_signal() records what signal it saw here
  102. int signalfd; // and writes signal to this fd, if set
  103. } toys;
  104. // Two big temporary buffers: one for use by commands, one for library functions
  105. extern char **environ, *toybox_version, toybuf[4096], libbuf[4096];
  106. #define FLAG(x) (toys.optflags&FLAG_##x)
  107. #define GLOBALS(...)
  108. #define ARRAY_LEN(array) (sizeof(array)/sizeof(*array))
  109. #define TAGGED_ARRAY(X, ...) {__VA_ARGS__}
  110. #ifndef TOYBOX_VERSION
  111. #ifndef TOYBOX_VENDOR
  112. #define TOYBOX_VENDOR ""
  113. #endif
  114. #define TOYBOX_VERSION "0.8.8"TOYBOX_VENDOR
  115. #endif