- mention strtod code-duplication as TODO for cleanup
[platform/upstream/busybox.git] / TODO
1 Busybox TODO
2
3 Stuff that needs to be done.  This is organized by who plans to get around to
4 doing it eventually, but that doesn't mean they "own" the item.  If you want to
5 do one of these bounce an email off the person it's listed under to see if they
6 have any suggestions how they plan to go about it, and to minimize conflicts
7 between your work and theirs.  But otherwise, all of these are fair game.
8
9 Rob Landley <rob@landley.net>:
10   Add BB_NOMMU to platform.h and migrate __uClinux__ tests to that.
11     #if defined __UCLIBC__ && !defined __ARCH_USE_MMU__
12   Add a libbb/platform.c
13     Implement fdprintf() for platforms that haven't got one.
14     Implement bb_realpath() that can handle NULL on non-glibc.
15     Cleanup bb_asprintf()
16
17   Migrate calloc() and bb_calloc() occurrences to bb_xzalloc().
18   Remove obsolete _() wrapper crud for internationalization we don't do.
19   Figure out where we need utf8 support, and add it.
20
21   sh
22     The command shell situation is a big mess.  We have three or four different
23     shells that don't really share any code, and the "standalone shell" doesn't
24     work all that well (especially not in a chroot environment), due to apps not
25     being reentrant.
26     lash is phased out. hush can be configured down to be nearly as small,
27     but less buggy :)
28   init
29     General cleanup (should use ENABLE_FEATURE_INIT_SYSLOG and ENABLE_FEATURE_INIT_DEBUG).
30   depmod
31     busybox lacks a way to update module deps when running from firmware without the
32     use of the depmod.pl (perl is to bloated for most embedded setups) and or orig
33     modutils. The orig depmod is rather pointless to have to add to a firmware image
34     in when we already have a insmod/rmmod and friends.
35   Do a SUSv3 audit
36     Look at the full Single Unix Specification version 3 (available online at
37     "http://www.opengroup.org/onlinepubs/009695399/nfindex.html") and
38     figure out which of our apps are compliant, and what we're missing that
39     we might actually care about.
40
41     Even better would be some kind of automated compliance test harness that
42     exercises each command line option and the various corner cases.
43   Internationalization
44     How much internationalization should we do?
45
46     The low hanging fruit is UTF-8 character set support.  We should do this.
47     (Vodz pointed out the shell's cmdedit as needing work here.  What else?)
48
49     We also have lots of hardwired english text messages.  Consolidating this
50     into some kind of message table not only makes translation easier, but
51     also allows us to consolidate redundant (or close) strings.
52
53     We probably don't want to be bloated with locale support.  (Not unless we
54     can cleanly export it from our underlying C library without having to
55     concern ourselves with it directly.  Perhaps a few specific things like a
56     config option for "date" are low hanging fruit here?)
57
58     What level should things happen at?  How much do we care about
59     internationalizing the text console when X11 and xterms are so much better
60     at it?  (There's some infrastructure here we don't implement: The
61     "unicode_start" and "unicode_stop" shell scripts need "vt-is-UTF8" and a
62     --unicode option to loadkeys.  That implies a real loadkeys/dumpkeys
63     implementation to replace loadkmap/dumpkmap.  Plus messing with console font
64     loading.  Is it worth it, or do we just say "use X"?)
65
66   Individual compilation of applets.
67     It would be nice if busybox had the option to compile to individual applets,
68     for people who want an alternate implementation less bloated than the gnu
69     utils (or simply with less political baggage), but without it being one big
70     executable.
71
72     Turning libbb into a real dll is another possibility, especially if libbb
73     could export some of the other library interfaces we've already more or less
74     got the code for (like zlib).
75   buildroot - Make a "dogfood" option
76     Busybox 1.1 will be capable of replacing most gnu packages for real world
77     use, such as developing software or in a live CD.  It needs wider testing.
78
79     Busybox should now be able to replace bzip2, coreutils, e2fsprogs, file,
80     findutils, gawk, grep, inetutils, less, modutils, net-tools, patch, procps,
81     sed, shadow, sysklogd, sysvinit, tar, util-linux, and vim.  The resulting
82     system should be self-hosting (I.E. able to rebuild itself from source
83     code).  This means it would need (at least) binutils, gcc, and make, or
84     equivalents.
85
86     It would be a good "eating our own dogfood" test if buildroot had the option
87     of using a "make allyesconfig" busybox instead of the all of the above
88     packages.  Anything that's wrong with the resulting system, we can fix.  (It
89     would be nice to be able to upgrade busybox to be able to replace bash and
90     diffutils as well, but we're not there yet.)
91
92     One example of an existing system that does this already is Firmware Linux:
93       http://www.landley.net/code/firmware
94   initramfs
95     Busybox should have a sample initramfs build script.  This depends on
96     bbsh, mdev, and switch_root.
97   mkdep
98     Write a mkdep that doesn't segfault if there's a directory it doesn't
99     have permission to read, isn't based on manually editing the output of
100     lexx and yacc, doesn't make such a mess under include/config, etc.
101   Group globals into unions of structures.
102     Go through and turn all the global and static variables into structures,
103     and have all those structures be in a big union shared between processes,
104     so busybox uses less bss.  (This is a big win on nommu machines.)  See
105     sed.c and mdev.c for examples.
106   Go through bugs.busybox.net and close out all of that somehow.
107     This one's open to everybody, but I'll wind up doing it...
108
109
110 Bernhard Fischer <busybox@busybox.net> suggests to look at these:
111   New debug options:
112     -Wlarger-than-127
113     Cleanup any big users
114     -Wunused-parameter
115     Facilitate applet PROTOTYPES to provide means for having applets that
116     do a) not take any arguments b) need only one of argc or argv c) need
117     both argc and argv. All of these three options should go for the most
118     feature complete denominator.
119   Collate BUFSIZ IOBUF_SIZE MY_BUF_SIZE PIPE_PROGRESS_SIZE BUFSIZE PIPESIZE
120     make bb_common_bufsiz1 configurable, size wise.
121     make pipesize configurable, size wise.
122     Use bb_common_bufsiz1 throughout applets!
123
124 As yet unclaimed:
125
126 ----
127 find
128   doesn't understand (), lots of susv3 stuff.
129 ----
130 diff
131   Make sure we handle empty files properly:
132     From the patch man page:
133
134     you can remove a file by sending out a context diff that compares
135     the file to be deleted with an empty file dated the Epoch.  The
136     file will be removed unless patch is conforming to POSIX and the
137     -E or --remove-empty-files option is not given.
138 ---
139 patch
140   Should have simple fuzz factor support to apply patches at an offset which
141   shouldn't take up too much space.
142
143   And while we're at it, a new patch filename quoting format is apparently
144   coming soon:  http://marc.theaimsgroup.com/?l=git&m=112927316408690&w=2
145 ---
146 ps / top
147   Add support for both RSS and VSIZE rather than just one or the other.
148   Or make it a build option.
149 ---
150 man
151   It would be nice to have a man command.  Not one that handles troff or
152   anything, just one that can handle preformatted ascii man pages, possibly
153   compressed.  This could probably be a script in the extras directory that
154   calls cat/zcat/bzcat | less
155
156   (How doclifter might work into this is anybody's guess.)
157 ---
158 ar
159   Write support?
160 ---
161 stty / catv
162   stty's visible() function and catv's guts are identical. Merge them into
163   an appropriate libbb function.
164 ---
165 struct suffix_mult
166   Several duplicate users of: grep -r "1024\*1024" * -B2 -A1
167   Merge to a single size_suffixes[] in libbb.
168   Users: head tail od_bloaty hexdump and (partially as it wouldn't hurt) svlogd
169 ---
170 tail
171   ./busybox tail -f foo.c~ TODO
172   should not print fmt=header_fmt for subsequent date >> TODO; i.e. only
173   fmt+ if another (not the current) file did change
174
175 Architectural issues:
176
177 bb_close() with fsync()
178   We should have a bb_close() in place of normal close, with a CONFIG_ option
179   to not just check the return value of close() for an error, but fsync().
180   Close can't reliably report anything useful because if write() accepted the
181   data then it either went out to the network or it's in cache or a pipe
182   buffer.  Either way, there's no guarantee it'll make it to its final
183   destination before close() gets called, so there's no guarantee that any
184   error will be reported.
185
186   You need to call fsync() if you care about errors that occur after write(),
187   but that can have a big performance impact.  So make it a config option.
188 ---
189 Unify archivers
190   Lots of archivers have the same general infrastructure.  The directory
191   traversal code should be factored out, and the guts of each archiver could
192   be some setup code and a series of callbacks for "add this file",
193   "add this directory", "add this symlink" and so on.
194
195   This could clean up tar and zip, and make it cheaper to add cpio and ar
196   write support, and possibly even cheaply add things like mkisofs or
197   mksquashfs someday, if they become relevant.
198 ---
199 Text buffer support.
200   Several existing applets (sort, vi, less...) read
201   a whole file into memory and act on it.  There might be an opportunity
202   for shared code in there that could be moved into libbb...
203 ---
204 Memory Allocation
205   We have a CONFIG_BUFFER mechanism that lets us select whether to do memory
206   allocation on the stack or the heap.  Unfortunately, we're not using it much.
207   We need to audit our memory allocations and turn a lot of malloc/free calls
208   into RESERVE_CONFIG_BUFFER/RELEASE_CONFIG_BUFFER.
209   For a start, see e.g. make EXTRA_CFLAGS=-Wlarger-than-64
210
211   And while we're at it, many of the CONFIG_FEATURE_CLEAN_UP #ifdefs will be
212   optimized out by the compiler in the stack allocation case (since there's no
213   free for an alloca()), and this means that various cleanup loops that just
214   call free might also be optimized out by the compiler if written right, so
215   we can yank those #ifdefs too, and generally clean up the code.
216 ---
217 Switch CONFIG_SYMBOLS to ENABLE_SYMBOLS
218
219   In busybox 1.0 and earlier, configuration was done by CONFIG_SYMBOLS
220   that were either defined or undefined to indicate whether the symbol was
221   selected in the .config file.  They were used with #ifdefs, ala:
222
223     #ifdef CONFIG_SYMBOL
224       if (other_test) {
225         do_code();
226       }
227     #endif
228
229   In 1.1, we have new ENABLE_SYMBOLS which are always defined (as 0 or 1),
230   meaning you can still use them for preprocessor tests by replacing
231   "#ifdef CONFIG_SYMBOL" with "#if ENABLE_SYMBOL".  But more importantly, we
232   can use them as a true or false test in normal C code:
233
234     if (ENABLE_SYMBOL && other_test) {
235       do_code();
236     }
237
238   (Optimizing away if() statements that resolve to a constant value
239   is known as "dead code elimination", an optimization so old and simple that
240   Turbo Pascal for DOS did it twenty years ago.  Even modern mini-compilers
241   like the Tiny C Compiler (tcc) and the Small Device C Compiler (SDCC)
242   perform dead code elimination.)
243
244   Right now, busybox.h is #including both "config.h" (defining the
245   CONFIG_SYMBOLS) and "bb_config.h" (defining the ENABLE_SYMBOLS).  At some
246   point in the future, it would be nice to wean ourselves off of the
247   CONFIG versions.  (Among other things, some defective build environments
248   leak the Linux kernel's CONFIG_SYMBOLS into the system's standard #include
249   files.  We've experienced collisions before.)
250 ---
251 FEATURE_CLEAN_UP
252   This is more an unresolved issue than a to-do item.  More thought is needed.
253
254   Normally we rely on exit() to free memory, close files, and unmap segments
255   for us.  This makes most calls to free(), close(), and unmap() optional in
256   busybox applets that don't intend to run for very long, and optional stuff
257   can be omitted to save size.
258
259   The idea was raised that we could simulate fork/exit with setjmp/longjmp
260   for _really_ brainless embedded systems, or speed up the standalone shell
261   by not forking.  Doing so would require a reliable FEATURE_CLEAN_UP.
262   Unfortunately, this isn't as easy as it sounds.
263
264   The problem is, lots of things exit(), sometimes unexpectedly (xmalloc())
265   and sometimes reliably (bb_perror_msg_and_die() or show_usage()).  This
266   jumps out of the normal flow control and bypasses any cleanup code we
267   put at the end of our applets.
268
269   It's possible to add hooks to libbb functions like xmalloc() and xopen()
270   to add their entries to a linked list, which could be traversed and
271   freed/closed automatically.  (This would need to be able to free just the
272   entries after a checkpoint to be usable for a forkless standalone shell.
273   You don't want to free the shell's own resources.)
274
275   Right now, FEATURE_CLEAN_UP is more or less a debugging aid, to make things
276   like valgrind happy.  It's also documentation of _what_ we're trusting
277   exit() to clean up for us.  But new infrastructure to auto-free stuff would
278   render the existing FEATURE_CLEAN_UP code redundant.
279
280   For right now, exit() handles it just fine.
281
282
283
284 Minor stuff:
285   watchdog.c could autodetect the timer duration via:
286     if(!ioctl (fd, WDIOC_GETTIMEOUT, &tmo)) timer_duration = 1 + (tmo / 2);
287   Unfortunately, that needs linux/watchdog.h and that contains unfiltered
288   kernel types on some distros, which breaks the build.
289 ---
290   use bb_error_msg where appropriate: See
291   egrep "(printf.*\([[:space:]]*(stderr|2)|[^_]write.*\([[:space:]]*(stderr|2))"
292 ---
293   use bb_perror_msg where appropriate: See
294   egrep "[^_]perror"
295 ---
296   Remove superfluous fmt occurances: e.g.
297   fprintf(stderr, "%s: %s not found\n", "unalias", *argptr);
298   -> fprintf(stderr, "unalias: %s not found\n", *argptr);
299 ---
300   possible code duplication ingroup() and is_a_group_member()
301 ---
302   Move __get_hz() to a better place and (re)use it in route.c, ash.c, msh.c
303 ---
304   See grep -r strtod
305   Alot of duplication that wants cleanup.
306 ---
307
308
309 Code cleanup:
310
311 Replace deprecated functions.
312
313 bzero() -> memset()
314 ---
315 sigblock(), siggetmask(), sigsetmask(), sigmask() -> sigprocmask et al
316 ---
317 vdprintf() -> similar sized functionality
318 ---