annotate toys.h @ 370:c7a26e26ad08

Add TOYBOX_SUID.
author Rob Landley <rob@landley.net>
date Tue, 05 Jan 2010 12:17:05 -0600
parents 86a4054307ab
children 827ad88a3456
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
1 /* vi: set ts=4 :*/
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
2 /* Toybox infrastructure.
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
3 *
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
4 * Copyright 2006 Rob Landley <rob@landley.net>
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
5 *
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
6 * Licensed under GPL version 2, see file LICENSE in this tarball for details.
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
7 */
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
8
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 232
diff changeset
9 #include "generated/config.h"
94
884c03c29f21 Teach build to build only the toys/*.c selected in .config, and teach
Rob Landley <rob@landley.net>
parents: 82
diff changeset
10
63
69efffcacd70 Add fdprintf(). Remove reread() and rewrite() which handle -EINTR, which
Rob Landley <rob@landley.net>
parents: 53
diff changeset
11 #include "lib/portability.h"
69efffcacd70 Add fdprintf(). Remove reread() and rewrite() which handle -EINTR, which
Rob Landley <rob@landley.net>
parents: 53
diff changeset
12
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 4
diff changeset
13 #include <ctype.h>
94
884c03c29f21 Teach build to build only the toys/*.c selected in .config, and teach
Rob Landley <rob@landley.net>
parents: 82
diff changeset
14 #include <dirent.h>
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 4
diff changeset
15 #include <errno.h>
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 4
diff changeset
16 #include <fcntl.h>
114
ce6956dfc0cf Add sync and an incomplete version of mdev.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
17 #include <grp.h>
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 4
diff changeset
18 #include <inttypes.h>
2
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
19 #include <limits.h>
321
dfbfbaeb69c9 Add netcat server mode, -l, -L, and -t.
Rob Landley <rob@landley.net>
parents: 257
diff changeset
20 #include <pty.h>
114
ce6956dfc0cf Add sync and an incomplete version of mdev.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
21 #include <pwd.h>
37
14d27eab3acf Add my old micro-bunzip library. Needs some cleanup...
Rob Landley <rob@landley.net>
parents: 35
diff changeset
22 #include <setjmp.h>
2
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
23 #include <stdarg.h>
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 4
diff changeset
24 #include <stdint.h>
1
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
25 #include <stdio.h>
2
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
26 #include <stdlib.h>
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
27 #include <string.h>
53
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents: 37
diff changeset
28 #include <sys/ioctl.h>
114
ce6956dfc0cf Add sync and an incomplete version of mdev.
Rob Landley <rob@landley.net>
parents: 94
diff changeset
29 #include <sys/mman.h>
75
89ca591a9236 More random progress on mke2fs. Nothing to see yet.
Rob Landley <rob@landley.net>
parents: 63
diff changeset
30 #include <sys/mount.h>
4
732b055e17f7 Add xmsprintf(), xgetcwd(), xgetcwd(), find_in_path().
landley@driftwood
parents: 3
diff changeset
31 #include <sys/stat.h>
7
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 4
diff changeset
32 #include <sys/statvfs.h>
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 4
diff changeset
33 #include <sys/types.h>
fc9c0503d5e2 Implement df. Add -Wall to build and fix up warnings. Add copyright notices.
landley@driftwood
parents: 4
diff changeset
34 #include <sys/wait.h>
218
bc87305c391f Make touch work reliably when file doesn't exist and clean up headers a bit.
Rob Landley <rob@landley.net>
parents: 145
diff changeset
35 #include <unistd.h>
bc87305c391f Make touch work reliably when file doesn't exist and clean up headers a bit.
Rob Landley <rob@landley.net>
parents: 145
diff changeset
36 #include <utime.h>
bc87305c391f Make touch work reliably when file doesn't exist and clean up headers a bit.
Rob Landley <rob@landley.net>
parents: 145
diff changeset
37
359
86a4054307ab Make a warning go away on Fedora 11.
Rob Landley <rob@landley.net>
parents: 345
diff changeset
38 #undef _XOPEN_SOURCE
218
bc87305c391f Make touch work reliably when file doesn't exist and clean up headers a bit.
Rob Landley <rob@landley.net>
parents: 145
diff changeset
39 #define _XOPEN_SOURCE 600
76
e6332139adae More work on mke2fs.
Rob Landley <rob@landley.net>
parents: 75
diff changeset
40 #include <time.h>
1
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
41
2
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
42 #include "lib/lib.h"
82
612c8d6c2829 More work on mke2fs.
Rob Landley <rob@landley.net>
parents: 76
diff changeset
43 #include "toys/e2fs.h"
1
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
44
234
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
45 // Get list of function prototypes for all enabled command_main() functions.
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
46
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
47 #define NEWTOY(name, opts, flags) void name##_main(void);
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
48 #define OLDTOY(name, oldname, opts, flags)
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
49 #include "generated/newtoys.h"
237
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
50 #include "generated/globals.h"
234
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
51
21
6475d6c46066 Add pwd. Consolidate toy list information under toylist.h.
Rob Landley <rob@landley.net>
parents: 20
diff changeset
52 // These live in main.c
2
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
53
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
54 struct toy_list *toy_find(char *name);
3
266a462ed18c Next drop of toysh, plus more infratructure.
landley@driftwood
parents: 2
diff changeset
55 void toy_init(struct toy_list *which, char *argv[]);
266a462ed18c Next drop of toysh, plus more infratructure.
landley@driftwood
parents: 2
diff changeset
56 void toy_exec(char *argv[]);
1
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
57
345
10618c4c8cf2 Comment tweaks.
Rob Landley <rob@landley.net>
parents: 321
diff changeset
58 // Flags describing applet behavior.
237
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
59
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
60 #define TOYFLAG_USR (1<<0)
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
61 #define TOYFLAG_BIN (1<<1)
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
62 #define TOYFLAG_SBIN (1<<2)
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
63 #define TOYMASK_LOCATION ((1<<4)-1)
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
64
345
10618c4c8cf2 Comment tweaks.
Rob Landley <rob@landley.net>
parents: 321
diff changeset
65 // This is a shell built-in function, running in the same process context.
237
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
66 #define TOYFLAG_NOFORK (1<<4)
345
10618c4c8cf2 Comment tweaks.
Rob Landley <rob@landley.net>
parents: 321
diff changeset
67
10618c4c8cf2 Comment tweaks.
Rob Landley <rob@landley.net>
parents: 321
diff changeset
68 // Start applet with a umask of 0 (saves old umask in this.old_umask)
257
951110c37fee Add TOYFLAG_UMASK.
Rob Landley <rob@landley.net>
parents: 255
diff changeset
69 #define TOYFLAG_UMASK (1<<5)
237
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
70
370
c7a26e26ad08 Add TOYBOX_SUID.
Rob Landley <rob@landley.net>
parents: 359
diff changeset
71 // This applet runs as root.
c7a26e26ad08 Add TOYBOX_SUID.
Rob Landley <rob@landley.net>
parents: 359
diff changeset
72 #define TOYFLAG_STAYROOT (1<<6)
c7a26e26ad08 Add TOYBOX_SUID.
Rob Landley <rob@landley.net>
parents: 359
diff changeset
73 #define TOYFLAG_NEEDROOT (1<<7)
c7a26e26ad08 Add TOYBOX_SUID.
Rob Landley <rob@landley.net>
parents: 359
diff changeset
74 #define TOYFLAG_ROOTONLY (TOYFLAG_STAYROOT|TOYFLAG_NEEDROOT)
c7a26e26ad08 Add TOYBOX_SUID.
Rob Landley <rob@landley.net>
parents: 359
diff changeset
75
345
10618c4c8cf2 Comment tweaks.
Rob Landley <rob@landley.net>
parents: 321
diff changeset
76 // Array of available applets
10618c4c8cf2 Comment tweaks.
Rob Landley <rob@landley.net>
parents: 321
diff changeset
77
237
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
78 extern struct toy_list {
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
79 char *name;
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
80 void (*toy_main)(void);
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
81 char *options;
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
82 int flags;
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
83 } toy_list[];
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
84
345
10618c4c8cf2 Comment tweaks.
Rob Landley <rob@landley.net>
parents: 321
diff changeset
85 // Global context shared by all applets.
1
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
86
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
87 extern struct toy_context {
2
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
88 struct toy_list *which; // Which entry in toy_list is this one?
67b517913e56 Infrastructure, first drop of toy shell, and a bit of work on df.
landley@driftwood
parents: 1
diff changeset
89 int exitval; // Value error_exit feeds to exit()
118
93da7cc220e6 Add sleep.
Rob Landley <rob@landley.net>
parents: 114
diff changeset
90 char **argv; // Original command line arguments
25
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents: 21
diff changeset
91 unsigned optflags; // Command line option flags from get_optflags()
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents: 21
diff changeset
92 char **optargs; // Arguments left over from get_optflags()
255
3fe66e630944 Add toys.optc, an argv-style count for toys.optargs.
Rob Landley <rob@landley.net>
parents: 237
diff changeset
93 int optc; // Count of optargs
345
10618c4c8cf2 Comment tweaks.
Rob Landley <rob@landley.net>
parents: 321
diff changeset
94 int exithelp; // Should error_exit print a usage message first?
10618c4c8cf2 Comment tweaks.
Rob Landley <rob@landley.net>
parents: 321
diff changeset
95 int old_umask; // Old umask preserved by TOYFLAG_UMASK
1
59d58fab67c6 Next snapshot. Tries to grab something out of lib in order to build, I have
landley@driftwood
parents:
diff changeset
96 } toys;
25
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents: 21
diff changeset
97
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents: 21
diff changeset
98 // One big temporary buffer, for use by applets (not library functions).
eb46bb5626cb New option parsing infrastructure (doesn't use getopt). Hook it up to
Rob Landley <rob@landley.net>
parents: 21
diff changeset
99
53
41d55b5d49fd Add start of mke2fs/gene2fs, and some other stuff I've been working on.
Rob Landley <rob@landley.net>
parents: 37
diff changeset
100 extern char toybuf[4096];
237
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
101
7cb15eae1664 Zap toylist.h, moving contents of global structures into DEFINE_GLOBALS()
Rob Landley <rob@landley.net>
parents: 234
diff changeset
102 #define DEFINE_GLOBALS(...)