From 14ac0f3a54432f3fd0844a6561fe7755ae7bf056 Mon Sep 17 00:00:00 2001 From: onefang Date: Sat, 12 Mar 2005 13:06:30 +0000 Subject: Initial import --- urunlevel/archival/gzip.c | 2558 +++++++++++++++++++++++++ urunlevel/include/applets.h | 752 ++++++++ urunlevel/include/usage.h | 3077 ++++++++++++++++++++++++++++++ urunlevel/my_linux/Config.in | 32 + urunlevel/my_linux/Makefile | 32 + urunlevel/my_linux/Makefile.in | 40 + urunlevel/my_linux/Trinux/README | 346 ++++ urunlevel/my_linux/Trinux/chkfixed | 99 + urunlevel/my_linux/Trinux/fmount | 2 + urunlevel/my_linux/Trinux/fumount | 3 + urunlevel/my_linux/Trinux/gethome | 61 + urunlevel/my_linux/Trinux/getkpkg | 9 + urunlevel/my_linux/Trinux/getpkg | 171 ++ urunlevel/my_linux/Trinux/hwinfo | 23 + urunlevel/my_linux/Trinux/killmod | 8 + urunlevel/my_linux/Trinux/linuxrc | 1261 ++++++++++++ urunlevel/my_linux/Trinux/loadmodules | 30 + urunlevel/my_linux/Trinux/net-config | 18 + urunlevel/my_linux/Trinux/net-start | 141 ++ urunlevel/my_linux/Trinux/net-stop | 11 + urunlevel/my_linux/Trinux/pkgadd | 62 + urunlevel/my_linux/Trinux/pkglist | 12 + urunlevel/my_linux/Trinux/quit | 10 + urunlevel/my_linux/Trinux/rmpkg | 24 + urunlevel/my_linux/Trinux/save-config | 38 + urunlevel/my_linux/Trinux/savecfg | 38 + urunlevel/my_linux/Trinux/savehome | 79 + urunlevel/my_linux/Trinux/update | 62 + urunlevel/my_linux/bootrc | 0 urunlevel/my_linux/getpkg.c | 240 +++ urunlevel/my_linux/inittab | 17 + urunlevel/my_linux/lib_init_d.h | 183 ++ urunlevel/my_linux/linuxrc.c | 829 ++++++++ urunlevel/my_linux/man.c | 41 + urunlevel/my_linux/mkrootfs.c | 104 + urunlevel/my_linux/my_linux.h | 27 + urunlevel/my_linux/rcS | 2 + urunlevel/my_linux/rcS.c | 47 + urunlevel/my_linux/shownet | 8 + urunlevel/my_linux/vt_manager | 22 + urunlevel/networking/udhcp/dhcpc.h | 38 + urunlevel/networking/udhcp/libbb_udhcp.h | 55 + urunlevel/runlevel/Config.in | 110 ++ urunlevel/runlevel/Makefile | 32 + urunlevel/runlevel/Makefile.in | 75 + urunlevel/runlevel/README | 3 + urunlevel/runlevel/TODO | 55 + urunlevel/runlevel/boot_named.c | 57 + urunlevel/runlevel/boot_portmap.c | 78 + urunlevel/runlevel/boot_syslog.c | 79 + urunlevel/runlevel/boot_time.c | 88 + urunlevel/runlevel/default.script | 2 + urunlevel/runlevel/init-functions | 30 + urunlevel/runlevel/inittab | 12 + urunlevel/runlevel/install_initd.c | 48 + urunlevel/runlevel/killproc.c | 162 ++ urunlevel/runlevel/lib_init_d.c | 425 +++++ urunlevel/runlevel/lib_init_d.h | 202 ++ urunlevel/runlevel/local_fs.c | 199 ++ urunlevel/runlevel/log_failure_msg.c | 54 + urunlevel/runlevel/log_success_msg.c | 54 + urunlevel/runlevel/log_warning_msg.c | 54 + urunlevel/runlevel/network.c | 146 ++ urunlevel/runlevel/pidofproc.c | 192 ++ urunlevel/runlevel/rc.c | 1271 ++++++++++++ urunlevel/runlevel/remote_fs.c | 83 + urunlevel/runlevel/remove_initd.c | 38 + urunlevel/runlevel/skeleton | 282 +++ urunlevel/runlevel/start_daemon.c | 153 ++ urunlevel/runlevel/udhcpc_script.c | 191 ++ urunlevel/sysdeps/linux/Config.in | 296 +++ 71 files changed, 15083 insertions(+) create mode 100644 urunlevel/archival/gzip.c create mode 100644 urunlevel/include/applets.h create mode 100644 urunlevel/include/usage.h create mode 100644 urunlevel/my_linux/Config.in create mode 100644 urunlevel/my_linux/Makefile create mode 100644 urunlevel/my_linux/Makefile.in create mode 100644 urunlevel/my_linux/Trinux/README create mode 100755 urunlevel/my_linux/Trinux/chkfixed create mode 100755 urunlevel/my_linux/Trinux/fmount create mode 100755 urunlevel/my_linux/Trinux/fumount create mode 100755 urunlevel/my_linux/Trinux/gethome create mode 100755 urunlevel/my_linux/Trinux/getkpkg create mode 100755 urunlevel/my_linux/Trinux/getpkg create mode 100755 urunlevel/my_linux/Trinux/hwinfo create mode 100755 urunlevel/my_linux/Trinux/killmod create mode 100755 urunlevel/my_linux/Trinux/linuxrc create mode 100755 urunlevel/my_linux/Trinux/loadmodules create mode 100755 urunlevel/my_linux/Trinux/net-config create mode 100755 urunlevel/my_linux/Trinux/net-start create mode 100755 urunlevel/my_linux/Trinux/net-stop create mode 100755 urunlevel/my_linux/Trinux/pkgadd create mode 100755 urunlevel/my_linux/Trinux/pkglist create mode 100755 urunlevel/my_linux/Trinux/quit create mode 100755 urunlevel/my_linux/Trinux/rmpkg create mode 100755 urunlevel/my_linux/Trinux/save-config create mode 100755 urunlevel/my_linux/Trinux/savecfg create mode 100755 urunlevel/my_linux/Trinux/savehome create mode 100755 urunlevel/my_linux/Trinux/update create mode 100644 urunlevel/my_linux/bootrc create mode 100644 urunlevel/my_linux/getpkg.c create mode 100644 urunlevel/my_linux/inittab create mode 100644 urunlevel/my_linux/lib_init_d.h create mode 100644 urunlevel/my_linux/linuxrc.c create mode 100644 urunlevel/my_linux/man.c create mode 100644 urunlevel/my_linux/mkrootfs.c create mode 100644 urunlevel/my_linux/my_linux.h create mode 100755 urunlevel/my_linux/rcS create mode 100644 urunlevel/my_linux/rcS.c create mode 100755 urunlevel/my_linux/shownet create mode 100755 urunlevel/my_linux/vt_manager create mode 100644 urunlevel/networking/udhcp/dhcpc.h create mode 100644 urunlevel/networking/udhcp/libbb_udhcp.h create mode 100644 urunlevel/runlevel/Config.in create mode 100644 urunlevel/runlevel/Makefile create mode 100644 urunlevel/runlevel/Makefile.in create mode 100644 urunlevel/runlevel/README create mode 100644 urunlevel/runlevel/TODO create mode 100644 urunlevel/runlevel/boot_named.c create mode 100644 urunlevel/runlevel/boot_portmap.c create mode 100644 urunlevel/runlevel/boot_syslog.c create mode 100644 urunlevel/runlevel/boot_time.c create mode 100755 urunlevel/runlevel/default.script create mode 100644 urunlevel/runlevel/init-functions create mode 100644 urunlevel/runlevel/inittab create mode 100644 urunlevel/runlevel/install_initd.c create mode 100644 urunlevel/runlevel/killproc.c create mode 100644 urunlevel/runlevel/lib_init_d.c create mode 100644 urunlevel/runlevel/lib_init_d.h create mode 100644 urunlevel/runlevel/local_fs.c create mode 100644 urunlevel/runlevel/log_failure_msg.c create mode 100644 urunlevel/runlevel/log_success_msg.c create mode 100644 urunlevel/runlevel/log_warning_msg.c create mode 100644 urunlevel/runlevel/network.c create mode 100644 urunlevel/runlevel/pidofproc.c create mode 100644 urunlevel/runlevel/rc.c create mode 100644 urunlevel/runlevel/remote_fs.c create mode 100644 urunlevel/runlevel/remove_initd.c create mode 100755 urunlevel/runlevel/skeleton create mode 100644 urunlevel/runlevel/start_daemon.c create mode 100644 urunlevel/runlevel/udhcpc_script.c create mode 100644 urunlevel/sysdeps/linux/Config.in diff --git a/urunlevel/archival/gzip.c b/urunlevel/archival/gzip.c new file mode 100644 index 0000000..1092480 --- /dev/null +++ b/urunlevel/archival/gzip.c @@ -0,0 +1,2558 @@ +/* vi: set sw=4 ts=4: */ +/* + * Gzip implementation for busybox + * + * Based on GNU gzip Copyright (C) 1992-1993 Jean-loup Gailly. + * + * Originally adjusted for busybox by Charles P. Wright + * "this is a stripped down version of gzip I put into busybox, it does + * only standard in to standard out with -9 compression. It also requires + * the zcat module for some important functions." + * + * Adjusted further by Erik Andersen to support + * files as well as stdin/stdout, and to generally behave itself wrt + * command line handling. + * + * Adjusted further by David Seikel to support + * just storing the file. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + */ + +/* These defines are very important for BusyBox. Without these, + * huge chunks of ram are pre-allocated making the BusyBox bss + * size Freaking Huge(tm), which is a bad thing.*/ +#define SMALL_MEM +#define DYN_ALLOC + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "busybox.h" + +#define memzero(s, n) memset ((void *)(s), 0, (n)) + +#ifndef RETSIGTYPE +# define RETSIGTYPE void +#endif + +typedef unsigned char uch; +typedef unsigned short ush; +typedef unsigned long ulg; + +/* Return codes from gzip */ +#define OK 0 +#define ERROR 1 +#define WARNING 2 + +/* Compression methods (see algorithm.doc) */ +/* Only STORED and DEFLATED are supported by this BusyBox module */ +#define STORED 0 +/* methods 4 to 7 reserved */ +#define DEFLATED 8 + +int just_store = 0; + +/* To save memory for 16 bit systems, some arrays are overlaid between + * the various modules: + * deflate: prev+head window d_buf l_buf outbuf + * unlzw: tab_prefix tab_suffix stack inbuf outbuf + * For compression, input is done in window[]. For decompression, output + * is done in window except for unlzw. + */ + +#ifndef INBUFSIZ +# ifdef SMALL_MEM +# define INBUFSIZ 0x2000 /* input buffer size */ +# else +# define INBUFSIZ 0x8000 /* input buffer size */ +# endif +#endif +#define INBUF_EXTRA 64 /* required by unlzw() */ + +#ifndef OUTBUFSIZ +# ifdef SMALL_MEM +# define OUTBUFSIZ 8192 /* output buffer size */ +# else +# define OUTBUFSIZ 16384 /* output buffer size */ +# endif +#endif +#define OUTBUF_EXTRA 2048 /* required by unlzw() */ + +#ifndef DIST_BUFSIZE +# ifdef SMALL_MEM +# define DIST_BUFSIZE 0x2000 /* buffer for distances, see trees.c */ +# else +# define DIST_BUFSIZE 0x8000 /* buffer for distances, see trees.c */ +# endif +#endif + +#ifdef DYN_ALLOC +# define DECLARE(type, array, size) static type * array +# define ALLOC(type, array, size) { \ + array = (type*)xcalloc((size_t)(((size)+1L)/2), 2*sizeof(type)); \ + } +# define FREE(array) {free(array), array=NULL;} +#else +# define DECLARE(type, array, size) static type array[size] +# define ALLOC(type, array, size) +# define FREE(array) +#endif + +#define tab_suffix window +#define tab_prefix prev /* hash link (see deflate.c) */ +#define head (prev+WSIZE) /* hash head (see deflate.c) */ + +static long bytes_in; /* number of input bytes */ + +#define isize bytes_in +/* for compatibility with old zip sources (to be cleaned) */ + +typedef int file_t; /* Do not use stdio */ + +#define NO_FILE (-1) /* in memory compression */ + + +#define PACK_MAGIC "\037\036" /* Magic header for packed files */ +#define GZIP_MAGIC "\037\213" /* Magic header for gzip files, 1F 8B */ +#define OLD_GZIP_MAGIC "\037\236" /* Magic header for gzip 0.5 = freeze 1.x */ +#define LZH_MAGIC "\037\240" /* Magic header for SCO LZH Compress files */ +#define PKZIP_MAGIC "\120\113\003\004" /* Magic header for pkzip files */ + +/* gzip flag byte */ +#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */ +#define CONTINUATION 0x02 /* bit 1 set: continuation of multi-part gzip file */ +#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */ +#define ORIG_NAME 0x08 /* bit 3 set: original file name present */ +#define COMMENT 0x10 /* bit 4 set: file comment present */ +#define RESERVED 0xC0 /* bit 6,7: reserved */ + +/* internal file attribute */ +#define UNKNOWN 0xffff +#define BINARY 0 +#define ASCII 1 + +#ifndef WSIZE +# define WSIZE 0x8000 /* window size--must be a power of two, and */ +#endif /* at least 32K for zip's deflate method */ + +#define MIN_MATCH 3 +#define MAX_MATCH 258 +/* The minimum and maximum match lengths */ + +#define MIN_LOOKAHEAD (MAX_MATCH+MIN_MATCH+1) +/* Minimum amount of lookahead, except at the end of the input file. + * See deflate.c for comments about the MIN_MATCH+1. + */ + +#define MAX_DIST (WSIZE-MIN_LOOKAHEAD) +/* In order to simplify the code, particularly on 16 bit machines, match + * distances are limited to MAX_DIST instead of WSIZE. + */ + +/* put_byte is used for the compressed output */ +#define put_byte(c) {outbuf[outcnt++]=(uch)(c); if (outcnt==OUTBUFSIZ)\ + flush_outbuf();} + + +/* Output a 32 bit value to the bit stream, lsb first */ +#if 0 +#define put_long(n) { \ + put_short((n) & 0xffff); \ + put_short(((ulg)(n)) >> 16); \ +} +#endif + +#define seekable() 0 /* force sequential output */ +#define translate_eol 0 /* no option -a yet */ + +/* Diagnostic functions */ +#ifdef DEBUG +# define Assert(cond,msg) {if(!(cond)) bb_error_msg(msg);} +# define Trace(x) fprintf x +# define Tracev(x) {if (verbose) fprintf x ;} +# define Tracevv(x) {if (verbose>1) fprintf x ;} +# define Tracec(c,x) {if (verbose && (c)) fprintf x ;} +# define Tracecv(c,x) {if (verbose>1 && (c)) fprintf x ;} +#else +# define Assert(cond,msg) +# define Trace(x) +# define Tracev(x) +# define Tracevv(x) +# define Tracec(c,x) +# define Tracecv(c,x) +#endif + +#define WARN(msg) {if (!quiet) fprintf msg ; \ + if (exit_code == OK) exit_code = WARNING;} + +#ifndef MAX_PATH_LEN +# define MAX_PATH_LEN 1024 /* max pathname length */ +#endif + + + /* from zip.c: */ +static int zip(int in, int out); +static int file_read(char *buf, unsigned size); + + /* from gzip.c */ +static RETSIGTYPE abort_gzip(void); + + /* from deflate.c */ +static void lm_init(ush * flags); +static ulg deflate(void); + + /* from trees.c */ +static void ct_init(ush * attr, int *methodp); +static int ct_tally(int dist, int lc); +static ulg flush_block(char *buf, ulg stored_len, int eof); + + /* from bits.c */ +static void bi_init(file_t zipfile); +static void send_bits(int value, int length); +static unsigned bi_reverse(unsigned value, int length); +static void bi_windup(void); +static void copy_block(char *buf, unsigned len, int header); +static int (*read_buf) (char *buf, unsigned size); + + /* from util.c: */ +static void flush_outbuf(void); + +/* lzw.h -- define the lzw functions. + * Copyright (C) 1992-1993 Jean-loup Gailly. + * This is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License, see the file COPYING. + */ + +#if !defined(OF) && defined(lint) +# include "gzip.h" +#endif + +#ifndef BITS +# define BITS 16 +#endif +#define INIT_BITS 9 /* Initial number of bits per code */ + +#define BIT_MASK 0x1f /* Mask for 'number of compression bits' */ +/* Mask 0x20 is reserved to mean a fourth header byte, and 0x40 is free. + * It's a pity that old uncompress does not check bit 0x20. That makes + * extension of the format actually undesirable because old compress + * would just crash on the new format instead of giving a meaningful + * error message. It does check the number of bits, but it's more + * helpful to say "unsupported format, get a new version" than + * "can only handle 16 bits". + */ + +/* tailor.h -- target dependent definitions + * Copyright (C) 1992-1993 Jean-loup Gailly. + * This is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License, see the file COPYING. + */ + +/* The target dependent definitions should be defined here only. + * The target dependent functions should be defined in tailor.c. + */ + + + /* Common defaults */ + +#ifndef OS_CODE +# define OS_CODE 0x03 /* assume Unix */ +#endif + +#ifndef PATH_SEP +# define PATH_SEP '/' +#endif + +#ifndef OPTIONS_VAR +# define OPTIONS_VAR "GZIP" +#endif + +#ifndef Z_SUFFIX +# define Z_SUFFIX ".gz" +#endif + +#ifdef MAX_EXT_CHARS +# define MAX_SUFFIX MAX_EXT_CHARS +#else +# define MAX_SUFFIX 30 +#endif + + /* global buffers */ + +DECLARE(uch, inbuf, INBUFSIZ + INBUF_EXTRA); +DECLARE(uch, outbuf, OUTBUFSIZ + OUTBUF_EXTRA); +DECLARE(ush, d_buf, DIST_BUFSIZE); +DECLARE(uch, window, 2L * WSIZE); +DECLARE(ush, tab_prefix, 1L << BITS); + +static int foreground; /* set if program run in foreground */ +static int method = DEFLATED; /* compression method */ +static int exit_code = OK; /* program exit code */ +static int part_nb; /* number of parts in .gz file */ +static long time_stamp; /* original time stamp (modification time) */ +static long ifile_size; /* input file size, -1 for devices (debug only) */ +static char z_suffix[MAX_SUFFIX + 1]; /* default suffix (can be set with --suffix) */ +static int z_len; /* strlen(z_suffix) */ + +static int ifd; /* input file descriptor */ +static int ofd; /* output file descriptor */ +static unsigned insize; /* valid bytes in inbuf */ +static unsigned outcnt; /* bytes in output buffer */ + + +/* Output a 16 bit value, lsb first */ +static void put_short(ush w) +{ + if (outcnt < OUTBUFSIZ - 2) { + outbuf[outcnt++] = (uch) ((w) & 0xff); + outbuf[outcnt++] = (uch) ((ush) (w) >> 8); + } else { + put_byte((uch) ((w) & 0xff)); + put_byte((uch) ((ush) (w) >> 8)); + } +} + +/* ======================================================================== + * Signal and error handler. + */ +static void abort_gzip() +{ + exit(ERROR); +} + +/* =========================================================================== + * Clear input and output buffers + */ +static void clear_bufs(void) +{ + outcnt = 0; + insize = 0; + bytes_in = 0L; +} + +static void write_bb_error_msg(void) +{ + fputc('\n', stderr); + bb_perror_nomsg(); + abort_gzip(); +} + +/* =========================================================================== + * Does the same as write(), but also handles partial pipe writes and checks + * for error return. + */ +static void write_buf(int fd, void *buf, unsigned cnt) +{ + unsigned n; + + while ((n = write(fd, buf, cnt)) != cnt) { + if (n == (unsigned) (-1)) { + write_bb_error_msg(); + } + cnt -= n; + buf = (void *) ((char *) buf + n); + } +} + +/* =========================================================================== + * Run a set of bytes through the crc shift register. If s is a NULL + * pointer, then initialize the crc shift register contents instead. + * Return the current crc in either case. + */ +static ulg updcrc(uch * s, unsigned n) +{ + static ulg crc = (ulg) 0xffffffffL; /* shift register contents */ + register ulg c; /* temporary variable */ + static unsigned long crc_32_tab[256]; + + if (crc_32_tab[1] == 0x00000000L) { + unsigned long csr; /* crc shift register */ + const unsigned long e = 0xedb88320L; /* polynomial exclusive-or pattern */ + int i; /* counter for all possible eight bit values */ + int k; /* byte being shifted into crc apparatus */ + + /* Compute table of CRC's. */ + for (i = 1; i < 256; i++) { + csr = i; + /* The idea to initialize the register with the byte instead of + * zero was stolen from Haruhiko Okumura's ar002 + */ + for (k = 8; k; k--) + csr = csr & 1 ? (csr >> 1) ^ e : csr >> 1; + crc_32_tab[i] = csr; + } + } + + if (s == NULL) { + c = 0xffffffffL; + } else { + c = crc; + if (n) + do { + c = crc_32_tab[((int) c ^ (*s++)) & 0xff] ^ (c >> 8); + } while (--n); + } + crc = c; + return c ^ 0xffffffffL; /* (instead of ~c for 64-bit machines) */ +} + +/* bits.c -- output variable-length bit strings + * Copyright (C) 1992-1993 Jean-loup Gailly + * This is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License, see the file COPYING. + */ + + +/* + * PURPOSE + * + * Output variable-length bit strings. Compression can be done + * to a file or to memory. (The latter is not supported in this version.) + * + * DISCUSSION + * + * The PKZIP "deflate" file format interprets compressed file data + * as a sequence of bits. Multi-bit strings in the file may cross + * byte boundaries without restriction. + * + * The first bit of each byte is the low-order bit. + * + * The routines in this file allow a variable-length bit value to + * be output right-to-left (useful for literal values). For + * left-to-right output (useful for code strings from the tree routines), + * the bits must have been reversed first with bi_reverse(). + * + * For in-memory compression, the compressed bit stream goes directly + * into the requested output buffer. The input data is read in blocks + * by the mem_read() function. The buffer is limited to 64K on 16 bit + * machines. + * + * INTERFACE + * + * void bi_init (FILE *zipfile) + * Initialize the bit string routines. + * + * void send_bits (int value, int length) + * Write out a bit string, taking the source bits right to + * left. + * + * int bi_reverse (int value, int length) + * Reverse the bits of a bit string, taking the source bits left to + * right and emitting them right to left. + * + * void bi_windup (void) + * Write out any remaining bits in an incomplete byte. + * + * void copy_block(char *buf, unsigned len, int header) + * Copy a stored block to the zip file, storing first the length and + * its one's complement if requested. + * + */ + +/* =========================================================================== + * Local data used by the "bit string" routines. + */ + +static file_t zfile; /* output gzip file */ + +static unsigned short bi_buf; + +/* Output buffer. bits are inserted starting at the bottom (least significant + * bits). + */ + +#define Buf_size (8 * 2*sizeof(char)) +/* Number of bits used within bi_buf. (bi_buf might be implemented on + * more than 16 bits on some systems.) + */ + +static int bi_valid; + +/* Current input function. Set to mem_read for in-memory compression */ + +#ifdef DEBUG +ulg bits_sent; /* bit length of the compressed data */ +#endif + +/* =========================================================================== + * Initialize the bit string routines. + */ +static void bi_init(file_t zipfile) +{ + zfile = zipfile; + bi_buf = 0; + bi_valid = 0; +#ifdef DEBUG + bits_sent = 0L; +#endif + + /* Set the defaults for file compression. They are set by memcompress + * for in-memory compression. + */ + if (zfile != NO_FILE) { + read_buf = file_read; + } +} + +/* =========================================================================== + * Send a value on a given number of bits. + * IN assertion: length <= 16 and value fits in length bits. + */ +static void send_bits(int value, int length) +{ +#ifdef DEBUG + Tracev((stderr, " l %2d v %4x ", length, value)); + Assert(length > 0 && length <= 15, "invalid length"); + bits_sent += (ulg) length; +#endif + /* If not enough room in bi_buf, use (valid) bits from bi_buf and + * (16 - bi_valid) bits from value, leaving (width - (16-bi_valid)) + * unused bits in value. + */ + if (bi_valid > (int) Buf_size - length) { + bi_buf |= (value << bi_valid); + put_short(bi_buf); + bi_buf = (ush) value >> (Buf_size - bi_valid); + bi_valid += length - Buf_size; + } else { + bi_buf |= value << bi_valid; + bi_valid += length; + } +} + +/* =========================================================================== + * Reverse the first len bits of a code, using straightforward code (a faster + * method would use a table) + * IN assertion: 1 <= len <= 15 + */ +static unsigned bi_reverse(unsigned code, int len) +{ + register unsigned res = 0; + + do { + res |= code & 1; + code >>= 1, res <<= 1; + } while (--len > 0); + return res >> 1; +} + +/* =========================================================================== + * Write out any remaining bits in an incomplete byte. + */ +static void bi_windup() +{ + if (bi_valid > 8) { + put_short(bi_buf); + } else if (bi_valid > 0) { + put_byte(bi_buf); + } + bi_buf = 0; + bi_valid = 0; +#ifdef DEBUG + bits_sent = (bits_sent + 7) & ~7; +#endif +} + +/* =========================================================================== + * Copy a stored block to the zip file, storing first the length and its + * one's complement if requested. + */ +static void copy_block(char *buf, unsigned len, int header) +{ + bi_windup(); /* align on byte boundary */ + + if (header) { + put_short((ush) len); + put_short((ush) ~ len); +#ifdef DEBUG + bits_sent += 2 * 16; +#endif + } +#ifdef DEBUG + bits_sent += (ulg) len << 3; +#endif + while (len--) { + put_byte(*buf++); + } +} + +/* deflate.c -- compress data using the deflation algorithm + * Copyright (C) 1992-1993 Jean-loup Gailly + * This is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License, see the file COPYING. + */ + +/* + * PURPOSE + * + * Identify new text as repetitions of old text within a fixed- + * length sliding window trailing behind the new text. + * + * DISCUSSION + * + * The "deflation" process depends on being able to identify portions + * of the input text which are identical to earlier input (within a + * sliding window trailing behind the input currently being processed). + * + * The most straightforward technique turns out to be the fastest for + * most input files: try all possible matches and select the longest. + * The key feature of this algorithm is that insertions into the string + * dictionary are very simple and thus fast, and deletions are avoided + * completely. Insertions are performed at each input character, whereas + * string matches are performed only when the previous match ends. So it + * is preferable to spend more time in matches to allow very fast string + * insertions and avoid deletions. The matching algorithm for small + * strings is inspired from that of Rabin & Karp. A brute force approach + * is used to find longer strings when a small match has been found. + * A similar algorithm is used in comic (by Jan-Mark Wams) and freeze + * (by Leonid Broukhis). + * A previous version of this file used a more sophisticated algorithm + * (by Fiala and Greene) which is guaranteed to run in linear amortized + * time, but has a larger average cost, uses more memory and is patented. + * However the F&G algorithm may be faster for some highly redundant + * files if the parameter max_chain_length (described below) is too large. + * + * ACKNOWLEDGMENTS + * + * The idea of lazy evaluation of matches is due to Jan-Mark Wams, and + * I found it in 'freeze' written by Leonid Broukhis. + * Thanks to many info-zippers for bug reports and testing. + * + * REFERENCES + * + * APPNOTE.TXT documentation file in PKZIP 1.93a distribution. + * + * A description of the Rabin and Karp algorithm is given in the book + * "Algorithms" by R. Sedgewick, Addison-Wesley, p252. + * + * Fiala,E.R., and Greene,D.H. + * Data Compression with Finite Windows, Comm.ACM, 32,4 (1989) 490-595 + * + * INTERFACE + * + * void lm_init (int pack_level, ush *flags) + * Initialize the "longest match" routines for a new file + * + * ulg deflate (void) + * Processes a new input file and return its compressed length. Sets + * the compressed length, crc, deflate flags and internal file + * attributes. + */ + + +/* =========================================================================== + * Configuration parameters + */ + +/* Compile with MEDIUM_MEM to reduce the memory requirements or + * with SMALL_MEM to use as little memory as possible. Use BIG_MEM if the + * entire input file can be held in memory (not possible on 16 bit systems). + * Warning: defining these symbols affects HASH_BITS (see below) and thus + * affects the compression ratio. The compressed output + * is still correct, and might even be smaller in some cases. + */ + +#ifdef SMALL_MEM +# define HASH_BITS 13 /* Number of bits used to hash strings */ +#endif +#ifdef MEDIUM_MEM +# define HASH_BITS 14 +#endif +#ifndef HASH_BITS +# define HASH_BITS 15 + /* For portability to 16 bit machines, do not use values above 15. */ +#endif + +/* To save space (see unlzw.c), we overlay prev+head with tab_prefix and + * window with tab_suffix. Check that we can do this: + */ +#if (WSIZE<<1) > (1< BITS-1 +# error cannot overlay head with tab_prefix1 +#endif +#define HASH_SIZE (unsigned)(1<= HASH_BITS + */ + +static unsigned int prev_length; + +/* Length of the best match at previous step. Matches not greater than this + * are discarded. This is used in the lazy match evaluation. + */ + +static unsigned strstart; /* start of string to insert */ +static unsigned match_start; /* start of matching string */ +static int eofile; /* flag set at end of input file */ +static unsigned lookahead; /* number of valid bytes ahead in window */ + +static const unsigned max_chain_length = 4096; + +/* To speed up deflation, hash chains are never searched beyond this length. + * A higher limit improves compression ratio but degrades the speed. + */ + +static const unsigned int max_lazy_match = 258; + +/* Attempt to find a better match only when the current match is strictly + * smaller than this value. This mechanism is used only for compression + * levels >= 4. + */ +#define max_insert_length max_lazy_match +/* Insert new strings in the hash table only if the match length + * is not greater than this length. This saves time but degrades compression. + * max_insert_length is used only for compression levels <= 3. + */ + +static const unsigned good_match = 32; + +/* Use a faster search when the previous match is longer than this */ + + +/* Values for max_lazy_match, good_match and max_chain_length, depending on + * the desired pack level (0..9). The values given below have been tuned to + * exclude worst case performance for pathological files. Better values may be + * found for specific files. + */ + +static const int nice_match = 258; /* Stop searching when current match exceeds this */ + +/* Note: the deflate() code requires max_lazy >= MIN_MATCH and max_chain >= 4 + * For deflate_fast() (levels <= 3) good is ignored and lazy has a different + * meaning. + */ + +#define EQUAL 0 +/* result of memcmp for equal strings */ + +/* =========================================================================== + * Prototypes for local functions. + */ +static void fill_window(void); + +static int longest_match(IPos cur_match); + +#ifdef DEBUG +static void check_match(IPos start, IPos match, int length); +#endif + +/* =========================================================================== + * Update a hash value with the given input byte + * IN assertion: all calls to to UPDATE_HASH are made with consecutive + * input characters, so that a running hash key can be computed from the + * previous key instead of complete recalculation each time. + */ +#define UPDATE_HASH(h,c) (h = (((h)<= 1 + */ + +/* For MSDOS, OS/2 and 386 Unix, an optimized version is in match.asm or + * match.s. The code is functionally equivalent, so you can use the C version + * if desired. + */ +static int longest_match(IPos cur_match) +{ + unsigned chain_length = max_chain_length; /* max hash chain length */ + register uch *scan = window + strstart; /* current string */ + register uch *match; /* matched string */ + register int len; /* length of current match */ + int best_len = prev_length; /* best match length so far */ + IPos limit = + strstart > (IPos) MAX_DIST ? strstart - (IPos) MAX_DIST : NIL; + /* Stop when cur_match becomes <= limit. To simplify the code, + * we prevent matches with the string of window index 0. + */ + +/* The code is optimized for HASH_BITS >= 8 and MAX_MATCH-2 multiple of 16. + * It is easy to get rid of this optimization if necessary. + */ +#if HASH_BITS < 8 || MAX_MATCH != 258 +# error Code too clever +#endif + register uch *strend = window + strstart + MAX_MATCH; + register uch scan_end1 = scan[best_len - 1]; + register uch scan_end = scan[best_len]; + + /* Do not waste too much time if we already have a good match: */ + if (prev_length >= good_match) { + chain_length >>= 2; + } + Assert(strstart <= window_size - MIN_LOOKAHEAD, "insufficient lookahead"); + + do { + Assert(cur_match < strstart, "no future"); + match = window + cur_match; + + /* Skip to next match if the match length cannot increase + * or if the match length is less than 2: + */ + if (match[best_len] != scan_end || + match[best_len - 1] != scan_end1 || + *match != *scan || *++match != scan[1]) + continue; + + /* The check at best_len-1 can be removed because it will be made + * again later. (This heuristic is not always a win.) + * It is not necessary to compare scan[2] and match[2] since they + * are always equal when the other bytes match, given that + * the hash keys are equal and that HASH_BITS >= 8. + */ + scan += 2, match++; + + /* We check for insufficient lookahead only every 8th comparison; + * the 256th check will be made at strstart+258. + */ + do { + } while (*++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && + *++scan == *++match && *++scan == *++match && scan < strend); + + len = MAX_MATCH - (int) (strend - scan); + scan = strend - MAX_MATCH; + + if (len > best_len) { + match_start = cur_match; + best_len = len; + if (len >= nice_match) + break; + scan_end1 = scan[best_len - 1]; + scan_end = scan[best_len]; + } + } while ((cur_match = prev[cur_match & WMASK]) > limit + && --chain_length != 0); + + return best_len; +} + +#ifdef DEBUG +/* =========================================================================== + * Check that the match at match_start is indeed a match. + */ +static void check_match(IPos start, IPos match, int length) +{ + /* check that the match is indeed a match */ + if (memcmp((char *) window + match, + (char *) window + start, length) != EQUAL) { + bb_error_msg(" start %d, match %d, length %d", start, match, length); + bb_error_msg("invalid match"); + } + if (verbose > 1) { + bb_error_msg("\\[%d,%d]", start - match, length); + do { + putc(window[start++], stderr); + } while (--length != 0); + } +} +#else +# define check_match(start, match, length) +#endif + +/* =========================================================================== + * Fill the window when the lookahead becomes insufficient. + * Updates strstart and lookahead, and sets eofile if end of input file. + * IN assertion: lookahead < MIN_LOOKAHEAD && strstart + lookahead > 0 + * OUT assertions: at least one byte has been read, or eofile is set; + * file reads are performed for at least two bytes (required for the + * translate_eol option). + */ +static void fill_window() +{ + register unsigned n, m; + unsigned more = + (unsigned) (window_size - (ulg) lookahead - (ulg) strstart); + /* Amount of free space at the end of the window. */ + + /* If the window is almost full and there is insufficient lookahead, + * move the upper half to the lower one to make room in the upper half. + */ + if (more == (unsigned) EOF) { + /* Very unlikely, but possible on 16 bit machine if strstart == 0 + * and lookahead == 1 (input done one byte at time) + */ + more--; + } else if (strstart >= WSIZE + MAX_DIST) { + /* By the IN assertion, the window is not empty so we can't confuse + * more == 0 with more == 64K on a 16 bit machine. + */ + Assert(window_size == (ulg) 2 * WSIZE, "no sliding with BIG_MEM"); + + memcpy((char *) window, (char *) window + WSIZE, (unsigned) WSIZE); + match_start -= WSIZE; + strstart -= WSIZE; /* we now have strstart >= MAX_DIST: */ + + block_start -= (long) WSIZE; + + for (n = 0; n < HASH_SIZE; n++) { + m = head[n]; + head[n] = (Pos) (m >= WSIZE ? m - WSIZE : NIL); + } + for (n = 0; n < WSIZE; n++) { + m = prev[n]; + prev[n] = (Pos) (m >= WSIZE ? m - WSIZE : NIL); + /* If n is not on any hash chain, prev[n] is garbage but + * its value will never be used. + */ + } + more += WSIZE; + } + /* At this point, more >= 2 */ + if (!eofile) { + n = read_buf((char *) window + strstart + lookahead, more); + if (n == 0 || n == (unsigned) EOF) { + eofile = 1; + } else { + lookahead += n; + } + } +} + +/* =========================================================================== + * Flush the current block, with given end-of-file flag. + * IN assertion: strstart is set to the end of the current match. + */ +#define FLUSH_BLOCK(eof) \ + flush_block(block_start >= 0L ? (char*)&window[(unsigned)block_start] : \ + (char*)NULL, (long)strstart - block_start, (eof)) + +/* =========================================================================== + * Same as above, but achieves better compression. We use a lazy + * evaluation for matches: a match is finally adopted only if there is + * no better match at the next window position. + */ +static ulg deflate() +{ + IPos hash_head; /* head of hash chain */ + IPos prev_match; /* previous match */ + int flush; /* set if current block must be flushed */ + int match_available = 0; /* set if previous match exists */ + register unsigned match_length = MIN_MATCH - 1; /* length of best match */ + + /* Process the input block. */ + while (lookahead != 0) { + /* Insert the string window[strstart .. strstart+2] in the + * dictionary, and set hash_head to the head of the hash chain: + */ + INSERT_STRING(strstart, hash_head); + + /* Find the longest match, discarding those <= prev_length. + */ + prev_length = match_length, prev_match = match_start; + match_length = MIN_MATCH - 1; + + if (hash_head != NIL && prev_length < max_lazy_match && + strstart - hash_head <= MAX_DIST) { + /* To simplify the code, we prevent matches with the string + * of window index 0 (in particular we have to avoid a match + * of the string with itself at the start of the input file). + */ + match_length = longest_match(hash_head); + /* longest_match() sets match_start */ + if (match_length > lookahead) + match_length = lookahead; + + /* Ignore a length 3 match if it is too distant: */ + if (match_length == MIN_MATCH && strstart - match_start > TOO_FAR) { + /* If prev_match is also MIN_MATCH, match_start is garbage + * but we will ignore the current match anyway. + */ + match_length--; + } + } + /* If there was a match at the previous step and the current + * match is not better, output the previous match: + */ + if (prev_length >= MIN_MATCH && match_length <= prev_length) { + + check_match(strstart - 1, prev_match, prev_length); + + flush = + ct_tally(strstart - 1 - prev_match, prev_length - MIN_MATCH); + + /* Insert in hash table all strings up to the end of the match. + * strstart-1 and strstart are already inserted. + */ + lookahead -= prev_length - 1; + prev_length -= 2; + do { + strstart++; + INSERT_STRING(strstart, hash_head); + /* strstart never exceeds WSIZE-MAX_MATCH, so there are + * always MIN_MATCH bytes ahead. If lookahead < MIN_MATCH + * these bytes are garbage, but it does not matter since the + * next lookahead bytes will always be emitted as literals. + */ + } while (--prev_length != 0); + match_available = 0; + match_length = MIN_MATCH - 1; + strstart++; + if (flush) + FLUSH_BLOCK(0), block_start = strstart; + + } else if (match_available) { + /* If there was no match at the previous position, output a + * single literal. If there was a match but the current match + * is longer, truncate the previous match to a single literal. + */ + Tracevv((stderr, "%c", window[strstart - 1])); + if (ct_tally(0, window[strstart - 1])) { + FLUSH_BLOCK(0), block_start = strstart; + } + strstart++; + lookahead--; + } else { + /* There is no previous match to compare with, wait for + * the next step to decide. + */ + match_available = 1; + strstart++; + lookahead--; + } + Assert(strstart <= isize && lookahead <= isize, "a bit too far"); + + /* Make sure that we always have enough lookahead, except + * at the end of the input file. We need MAX_MATCH bytes + * for the next match, plus MIN_MATCH bytes to insert the + * string following the next match. + */ + while (lookahead < MIN_LOOKAHEAD && !eofile) + fill_window(); + } + if (match_available) + ct_tally(0, window[strstart - 1]); + + return FLUSH_BLOCK(1); /* eof */ +} + +/* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface + * Copyright (C) 1992-1993 Jean-loup Gailly + * The unzip code was written and put in the public domain by Mark Adler. + * Portions of the lzw code are derived from the public domain 'compress' + * written by Spencer Thomas, Joe Orost, James Woods, Jim McKie, Steve Davies, + * Ken Turkowski, Dave Mack and Peter Jannesen. + * + * See the license_msg below and the file COPYING for the software license. + * See the file algorithm.doc for the compression algorithms and file formats. + */ + +/* Compress files with zip algorithm and 'compress' interface. + * See usage() and help() functions below for all options. + * Outputs: + * file.gz: compressed file with same mode, owner, and utimes + * or stdout with -c option or if stdin used as input. + * If the output file name had to be truncated, the original name is kept + * in the compressed file. + */ + + /* configuration */ + +typedef struct dirent dir_type; + +typedef RETSIGTYPE(*sig_type) (int); + +/* ======================================================================== */ +int gzip_main(int argc, char **argv) +{ + int result; + int inFileNum; + int outFileNum; + struct stat statBuf; + char *delFileName; + int tostdout = 0; + int force = 0; + int opt; + + while ((opt = getopt(argc, argv, "cf0123456789dq")) != -1) { + switch (opt) { + case 'c': + tostdout = 1; + break; + case 'f': + force = 1; + break; + + case '0': + just_store = 1; + break; + + /* Ignore 1-9 (compression level) options */ + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + break; + case 'q': + break; +#ifdef CONFIG_GUNZIP + case 'd': + optind = 1; + return gunzip_main(argc, argv); +#endif + default: + bb_show_usage(); + } + } + + foreground = signal(SIGINT, SIG_IGN) != SIG_IGN; + if (foreground) { + (void) signal(SIGINT, (sig_type) abort_gzip); + } +#ifdef SIGTERM + if (signal(SIGTERM, SIG_IGN) != SIG_IGN) { + (void) signal(SIGTERM, (sig_type) abort_gzip); + } +#endif +#ifdef SIGHUP + if (signal(SIGHUP, SIG_IGN) != SIG_IGN) { + (void) signal(SIGHUP, (sig_type) abort_gzip); + } +#endif + + strncpy(z_suffix, Z_SUFFIX, sizeof(z_suffix) - 1); + z_len = strlen(z_suffix); + + /* Allocate all global buffers (for DYN_ALLOC option) */ + ALLOC(uch, inbuf, INBUFSIZ + INBUF_EXTRA); + ALLOC(uch, outbuf, OUTBUFSIZ + OUTBUF_EXTRA); + ALLOC(ush, d_buf, DIST_BUFSIZE); + ALLOC(uch, window, 2L * WSIZE); + ALLOC(ush, tab_prefix, 1L << BITS); + + clear_bufs(); + part_nb = 0; + + if (optind == argc) { + time_stamp = 0; + ifile_size = -1L; + zip(STDIN_FILENO, STDOUT_FILENO); + } else { + int i; + + for (i = optind; i < argc; i++) { + char *path = NULL; + + if (strcmp(argv[i], "-") == 0) { + time_stamp = 0; + ifile_size = -1L; + inFileNum = STDIN_FILENO; + outFileNum = STDOUT_FILENO; + } else { + inFileNum = open(argv[i], O_RDONLY); + if (inFileNum < 0 || fstat(inFileNum, &statBuf) < 0) + bb_perror_msg_and_die("%s", argv[i]); + time_stamp = statBuf.st_ctime; + ifile_size = statBuf.st_size; + + if (!tostdout) { + path = xmalloc(strlen(argv[i]) + 4); + strcpy(path, argv[i]); + strcat(path, ".gz"); + + /* Open output file */ +#if (__GLIBC__ >= 2) && (__GLIBC_MINOR__ >= 1) + outFileNum = + open(path, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW); +#else + outFileNum = open(path, O_RDWR | O_CREAT | O_EXCL); +#endif + if (outFileNum < 0) { + bb_perror_msg("%s", path); + free(path); + continue; + } + + /* Set permissions on the file */ + fchmod(outFileNum, statBuf.st_mode); + } else + outFileNum = STDOUT_FILENO; + } + + if (path == NULL && isatty(outFileNum) && force == 0) { + bb_error_msg + ("compressed data not written to a terminal. Use -f to force compression."); + free(path); + continue; + } + + result = zip(inFileNum, outFileNum); + + if (path != NULL) { + close(inFileNum); + close(outFileNum); + + /* Delete the original file */ + if (result == OK) + delFileName = argv[i]; + else + delFileName = path; + + if (unlink(delFileName) < 0) + bb_perror_msg("%s", delFileName); + } + + free(path); + } + } + + return (exit_code); +} + +/* trees.c -- output deflated data using Huffman coding + * Copyright (C) 1992-1993 Jean-loup Gailly + * This is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License, see the file COPYING. + */ + +/* + * PURPOSE + * + * Encode various sets of source values using variable-length + * binary code trees. + * + * DISCUSSION + * + * The PKZIP "deflation" process uses several Huffman trees. The more + * common source values are represented by shorter bit sequences. + * + * Each code tree is stored in the ZIP file in a compressed form + * which is itself a Huffman encoding of the lengths of + * all the code strings (in ascending order by source values). + * The actual code strings are reconstructed from the lengths in + * the UNZIP process, as described in the "application note" + * (APPNOTE.TXT) distributed as part of PKWARE's PKZIP program. + * + * REFERENCES + * + * Lynch, Thomas J. + * Data Compression: Techniques and Applications, pp. 53-55. + * Lifetime Learning Publications, 1985. ISBN 0-534-03418-7. + * + * Storer, James A. + * Data Compression: Methods and Theory, pp. 49-50. + * Computer Science Press, 1988. ISBN 0-7167-8156-5. + * + * Sedgewick, R. + * Algorithms, p290. + * Addison-Wesley, 1983. ISBN 0-201-06672-6. + * + * INTERFACE + * + * void ct_init (ush *attr, int *methodp) + * Allocate the match buffer, initialize the various tables and save + * the location of the internal file attribute (ascii/binary) and + * method (DEFLATE/STORE) + * + * void ct_tally (int dist, int lc); + * Save the match info and tally the frequency counts. + * + * long flush_block (char *buf, ulg stored_len, int eof) + * Determine the best encoding for the current block: dynamic trees, + * static trees or store, and output the encoded block to the zip + * file. Returns the total compressed length for the file so far. + * + */ + +/* =========================================================================== + * Constants + */ + +#define MAX_BITS 15 +/* All codes must not exceed MAX_BITS bits */ + +#define MAX_BL_BITS 7 +/* Bit length codes must not exceed MAX_BL_BITS bits */ + +#define LENGTH_CODES 29 +/* number of length codes, not counting the special END_BLOCK code */ + +#define LITERALS 256 +/* number of literal bytes 0..255 */ + +#define END_BLOCK 256 +/* end of block literal code */ + +#define L_CODES (LITERALS+1+LENGTH_CODES) +/* number of Literal or Length codes, including the END_BLOCK code */ + +#define D_CODES 30 +/* number of distance codes */ + +#define BL_CODES 19 +/* number of codes used to transfer the bit lengths */ + +typedef uch extra_bits_t; + +/* extra bits for each length code */ +static const extra_bits_t extra_lbits[LENGTH_CODES] + = { 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 2, 2, 2, 2, 3, 3, 3, 3, 4, 4, + 4, 4, 5, 5, 5, 5, 0 +}; + +/* extra bits for each distance code */ +static const extra_bits_t extra_dbits[D_CODES] + = { 0, 0, 0, 0, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, + 10, 10, 11, 11, 12, 12, 13, 13 +}; + +/* extra bits for each bit length code */ +static const extra_bits_t extra_blbits[BL_CODES] += { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 3, 7 }; + +#define STORED_BLOCK 0 +#define STATIC_TREES 1 +#define DYN_TREES 2 +/* The three kinds of block type */ + +#ifndef LIT_BUFSIZE +# ifdef SMALL_MEM +# define LIT_BUFSIZE 0x2000 +# else +# ifdef MEDIUM_MEM +# define LIT_BUFSIZE 0x4000 +# else +# define LIT_BUFSIZE 0x8000 +# endif +# endif +#endif +#ifndef DIST_BUFSIZE +# define DIST_BUFSIZE LIT_BUFSIZE +#endif +/* Sizes of match buffers for literals/lengths and distances. There are + * 4 reasons for limiting LIT_BUFSIZE to 64K: + * - frequencies can be kept in 16 bit counters + * - if compression is not successful for the first block, all input data is + * still in the window so we can still emit a stored block even when input + * comes from standard input. (This can also be done for all blocks if + * LIT_BUFSIZE is not greater than 32K.) + * - if compression is not successful for a file smaller than 64K, we can + * even emit a stored file instead of a stored block (saving 5 bytes). + * - creating new Huffman trees less frequently may not provide fast + * adaptation to changes in the input data statistics. (Take for + * example a binary file with poorly compressible code followed by + * a highly compressible string table.) Smaller buffer sizes give + * fast adaptation but have of course the overhead of transmitting trees + * more frequently. + * - I can't count above 4 + * The current code is general and allows DIST_BUFSIZE < LIT_BUFSIZE (to save + * memory at the expense of compression). Some optimizations would be possible + * if we rely on DIST_BUFSIZE == LIT_BUFSIZE. + */ +#if LIT_BUFSIZE > INBUFSIZ +#error cannot overlay l_buf and inbuf +#endif +#define REP_3_6 16 +/* repeat previous bit length 3-6 times (2 bits of repeat count) */ +#define REPZ_3_10 17 +/* repeat a zero length 3-10 times (3 bits of repeat count) */ +#define REPZ_11_138 18 +/* repeat a zero length 11-138 times (7 bits of repeat count) */ + +/* =========================================================================== + * Local data + */ + +/* Data structure describing a single value and its code string. */ +typedef struct ct_data { + union { + ush freq; /* frequency count */ + ush code; /* bit string */ + } fc; + union { + ush dad; /* father node in Huffman tree */ + ush len; /* length of bit string */ + } dl; +} ct_data; + +#define Freq fc.freq +#define Code fc.code +#define Dad dl.dad +#define Len dl.len + +#define HEAP_SIZE (2*L_CODES+1) +/* maximum heap size */ + +static ct_data dyn_ltree[HEAP_SIZE]; /* literal and length tree */ +static ct_data dyn_dtree[2 * D_CODES + 1]; /* distance tree */ + +static ct_data static_ltree[L_CODES + 2]; + +/* The static literal tree. Since the bit lengths are imposed, there is no + * need for the L_CODES extra codes used during heap construction. However + * The codes 286 and 287 are needed to build a canonical tree (see ct_init + * below). + */ + +static ct_data static_dtree[D_CODES]; + +/* The static distance tree. (Actually a trivial tree since all codes use + * 5 bits.) + */ + +static ct_data bl_tree[2 * BL_CODES + 1]; + +/* Huffman tree for the bit lengths */ + +typedef struct tree_desc { + ct_data *dyn_tree; /* the dynamic tree */ + ct_data *static_tree; /* corresponding static tree or NULL */ + const extra_bits_t *extra_bits; /* extra bits for each code or NULL */ + int extra_base; /* base index for extra_bits */ + int elems; /* max number of elements in the tree */ + int max_length; /* max bit length for the codes */ + int max_code; /* largest code with non zero frequency */ +} tree_desc; + +static tree_desc l_desc = + { dyn_ltree, static_ltree, extra_lbits, LITERALS + 1, L_CODES, + MAX_BITS, 0 +}; + +static tree_desc d_desc = + { dyn_dtree, static_dtree, extra_dbits, 0, D_CODES, MAX_BITS, 0 }; + +static tree_desc bl_desc = + { bl_tree, (ct_data *) 0, extra_blbits, 0, BL_CODES, MAX_BL_BITS, + 0 +}; + + +static ush bl_count[MAX_BITS + 1]; + +/* number of codes at each bit length for an optimal tree */ + +static const uch bl_order[BL_CODES] += { 16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15 }; + +/* The lengths of the bit length codes are sent in order of decreasing + * probability, to avoid transmitting the lengths for unused bit length codes. + */ + +static int heap[2 * L_CODES + 1]; /* heap used to build the Huffman trees */ +static int heap_len; /* number of elements in the heap */ +static int heap_max; /* element of largest frequency */ + +/* The sons of heap[n] are heap[2*n] and heap[2*n+1]. heap[0] is not used. + * The same heap array is used to build all trees. + */ + +static uch depth[2 * L_CODES + 1]; + +/* Depth of each subtree used as tie breaker for trees of equal frequency */ + +static uch length_code[MAX_MATCH - MIN_MATCH + 1]; + +/* length code for each normalized match length (0 == MIN_MATCH) */ + +static uch dist_code[512]; + +/* distance codes. The first 256 values correspond to the distances + * 3 .. 258, the last 256 values correspond to the top 8 bits of + * the 15 bit distances. + */ + +static int base_length[LENGTH_CODES]; + +/* First normalized length for each code (0 = MIN_MATCH) */ + +static int base_dist[D_CODES]; + +/* First normalized distance for each code (0 = distance of 1) */ + +#define l_buf inbuf +/* DECLARE(uch, l_buf, LIT_BUFSIZE); buffer for literals or lengths */ + +/* DECLARE(ush, d_buf, DIST_BUFSIZE); buffer for distances */ + +static uch flag_buf[(LIT_BUFSIZE / 8)]; + +/* flag_buf is a bit array distinguishing literals from lengths in + * l_buf, thus indicating the presence or absence of a distance. + */ + +static unsigned last_lit; /* running index in l_buf */ +static unsigned last_dist; /* running index in d_buf */ +static unsigned last_flags; /* running index in flag_buf */ +static uch flags; /* current flags not yet saved in flag_buf */ +static uch flag_bit; /* current bit used in flags */ + +/* bits are filled in flags starting at bit 0 (least significant). + * Note: these flags are overkill in the current code since we don't + * take advantage of DIST_BUFSIZE == LIT_BUFSIZE. + */ + +static ulg opt_len; /* bit length of current block with optimal trees */ +static ulg static_len; /* bit length of current block with static trees */ + +static ulg compressed_len; /* total bit length of compressed file */ + + +static ush *file_type; /* pointer to UNKNOWN, BINARY or ASCII */ +static int *file_method; /* pointer to DEFLATE or STORE */ + +/* =========================================================================== + * Local (static) routines in this file. + */ + +static void init_block(void); +static void pqdownheap(ct_data * tree, int k); +static void gen_bitlen(tree_desc * desc); +static void gen_codes(ct_data * tree, int max_code); +static void build_tree(tree_desc * desc); +static void scan_tree(ct_data * tree, int max_code); +static void send_tree(ct_data * tree, int max_code); +static int build_bl_tree(void); +static void send_all_trees(int lcodes, int dcodes, int blcodes); +static void compress_block(ct_data * ltree, ct_data * dtree); +static void set_file_type(void); + + +#ifndef DEBUG +# define send_code(c, tree) send_bits(tree[c].Code, tree[c].Len) + /* Send a code of the given tree. c and tree must not have side effects */ + +#else /* DEBUG */ +# define send_code(c, tree) \ + { if (verbose>1) bb_error_msg("\ncd %3d ",(c)); \ + send_bits(tree[c].Code, tree[c].Len); } +#endif + +#define d_code(dist) \ + ((dist) < 256 ? dist_code[dist] : dist_code[256+((dist)>>7)]) +/* Mapping from a distance to a distance code. dist is the distance - 1 and + * must not have side effects. dist_code[256] and dist_code[257] are never + * used. + */ + +/* the arguments must not have side effects */ + +/* =========================================================================== + * Allocate the match buffer, initialize the various tables and save the + * location of the internal file attribute (ascii/binary) and method + * (DEFLATE/STORE). + */ +static void ct_init(ush * attr, int *methodp) +{ + int n; /* iterates over tree elements */ + int bits; /* bit counter */ + int length; /* length value */ + int code; /* code value */ + int dist; /* distance index */ + + file_type = attr; + file_method = methodp; + compressed_len = 0L; + + if (static_dtree[0].Len != 0) + return; /* ct_init already called */ + + /* Initialize the mapping length (0..255) -> length code (0..28) */ + length = 0; + for (code = 0; code < LENGTH_CODES - 1; code++) { + base_length[code] = length; + for (n = 0; n < (1 << extra_lbits[code]); n++) { + length_code[length++] = (uch) code; + } + } + Assert(length == 256, "ct_init: length != 256"); + /* Note that the length 255 (match length 258) can be represented + * in two different ways: code 284 + 5 bits or code 285, so we + * overwrite length_code[255] to use the best encoding: + */ + length_code[length - 1] = (uch) code; + + /* Initialize the mapping dist (0..32K) -> dist code (0..29) */ + dist = 0; + for (code = 0; code < 16; code++) { + base_dist[code] = dist; + for (n = 0; n < (1 << extra_dbits[code]); n++) { + dist_code[dist++] = (uch) code; + } + } + Assert(dist == 256, "ct_init: dist != 256"); + dist >>= 7; /* from now on, all distances are divided by 128 */ + for (; code < D_CODES; code++) { + base_dist[code] = dist << 7; + for (n = 0; n < (1 << (extra_dbits[code] - 7)); n++) { + dist_code[256 + dist++] = (uch) code; + } + } + Assert(dist == 256, "ct_init: 256+dist != 512"); + + /* Construct the codes of the static literal tree */ + for (bits = 0; bits <= MAX_BITS; bits++) + bl_count[bits] = 0; + n = 0; + while (n <= 143) + static_ltree[n++].Len = 8, bl_count[8]++; + while (n <= 255) + static_ltree[n++].Len = 9, bl_count[9]++; + while (n <= 279) + static_ltree[n++].Len = 7, bl_count[7]++; + while (n <= 287) + static_ltree[n++].Len = 8, bl_count[8]++; + /* Codes 286 and 287 do not exist, but we must include them in the + * tree construction to get a canonical Huffman tree (longest code + * all ones) + */ + gen_codes((ct_data *) static_ltree, L_CODES + 1); + + /* The static distance tree is trivial: */ + for (n = 0; n < D_CODES; n++) { + static_dtree[n].Len = 5; + static_dtree[n].Code = bi_reverse(n, 5); + } + + /* Initialize the first block of the first file: */ + init_block(); +} + +/* =========================================================================== + * Initialize a new block. + */ +static void init_block() +{ + int n; /* iterates over tree elements */ + + /* Initialize the trees. */ + for (n = 0; n < L_CODES; n++) + dyn_ltree[n].Freq = 0; + for (n = 0; n < D_CODES; n++) + dyn_dtree[n].Freq = 0; + for (n = 0; n < BL_CODES; n++) + bl_tree[n].Freq = 0; + + dyn_ltree[END_BLOCK].Freq = 1; + opt_len = static_len = 0L; + last_lit = last_dist = last_flags = 0; + flags = 0; + flag_bit = 1; +} + +#define SMALLEST 1 +/* Index within the heap array of least frequent node in the Huffman tree */ + + +/* =========================================================================== + * Remove the smallest element from the heap and recreate the heap with + * one less element. Updates heap and heap_len. + */ +#define pqremove(tree, top) \ +{\ + top = heap[SMALLEST]; \ + heap[SMALLEST] = heap[heap_len--]; \ + pqdownheap(tree, SMALLEST); \ +} + +/* =========================================================================== + * Compares to subtrees, using the tree depth as tie breaker when + * the subtrees have equal frequency. This minimizes the worst case length. + */ +#define smaller(tree, n, m) \ + (tree[n].Freq < tree[m].Freq || \ + (tree[n].Freq == tree[m].Freq && depth[n] <= depth[m])) + +/* =========================================================================== + * Restore the heap property by moving down the tree starting at node k, + * exchanging a node with the smallest of its two sons if necessary, stopping + * when the heap property is re-established (each father smaller than its + * two sons). + */ +static void pqdownheap(ct_data * tree, int k) +{ + int v = heap[k]; + int j = k << 1; /* left son of k */ + + while (j <= heap_len) { + /* Set j to the smallest of the two sons: */ + if (j < heap_len && smaller(tree, heap[j + 1], heap[j])) + j++; + + /* Exit if v is smaller than both sons */ + if (smaller(tree, v, heap[j])) + break; + + /* Exchange v with the smallest son */ + heap[k] = heap[j]; + k = j; + + /* And continue down the tree, setting j to the left son of k */ + j <<= 1; + } + heap[k] = v; +} + +/* =========================================================================== + * Compute the optimal bit lengths for a tree and update the total bit length + * for the current block. + * IN assertion: the fields freq and dad are set, heap[heap_max] and + * above are the tree nodes sorted by increasing frequency. + * OUT assertions: the field len is set to the optimal bit length, the + * array bl_count contains the frequencies for each bit length. + * The length opt_len is updated; static_len is also updated if stree is + * not null. + */ +static void gen_bitlen(tree_desc * desc) +{ + ct_data *tree = desc->dyn_tree; + const extra_bits_t *extra = desc->extra_bits; + int base = desc->extra_base; + int max_code = desc->max_code; + int max_length = desc->max_length; + ct_data *stree = desc->static_tree; + int h; /* heap index */ + int n, m; /* iterate over the tree elements */ + int bits; /* bit length */ + int xbits; /* extra bits */ + ush f; /* frequency */ + int overflow = 0; /* number of elements with bit length too large */ + + for (bits = 0; bits <= MAX_BITS; bits++) + bl_count[bits] = 0; + + /* In a first pass, compute the optimal bit lengths (which may + * overflow in the case of the bit length tree). + */ + tree[heap[heap_max]].Len = 0; /* root of the heap */ + + for (h = heap_max + 1; h < HEAP_SIZE; h++) { + n = heap[h]; + bits = tree[tree[n].Dad].Len + 1; + if (bits > max_length) + bits = max_length, overflow++; + tree[n].Len = (ush) bits; + /* We overwrite tree[n].Dad which is no longer needed */ + + if (n > max_code) + continue; /* not a leaf node */ + + bl_count[bits]++; + xbits = 0; + if (n >= base) + xbits = extra[n - base]; + f = tree[n].Freq; + opt_len += (ulg) f *(bits + xbits); + + if (stree) + static_len += (ulg) f *(stree[n].Len + xbits); + } + if (overflow == 0) + return; + + Trace((stderr, "\nbit length overflow\n")); + /* This happens for example on obj2 and pic of the Calgary corpus */ + + /* Find the first bit length which could increase: */ + do { + bits = max_length - 1; + while (bl_count[bits] == 0) + bits--; + bl_count[bits]--; /* move one leaf down the tree */ + bl_count[bits + 1] += 2; /* move one overflow item as its brother */ + bl_count[max_length]--; + /* The brother of the overflow item also moves one step up, + * but this does not affect bl_count[max_length] + */ + overflow -= 2; + } while (overflow > 0); + + /* Now recompute all bit lengths, scanning in increasing frequency. + * h is still equal to HEAP_SIZE. (It is simpler to reconstruct all + * lengths instead of fixing only the wrong ones. This idea is taken + * from 'ar' written by Haruhiko Okumura.) + */ + for (bits = max_length; bits != 0; bits--) { + n = bl_count[bits]; + while (n != 0) { + m = heap[--h]; + if (m > max_code) + continue; + if (tree[m].Len != (unsigned) bits) { + Trace((stderr, "code %d bits %d->%d\n", m, tree[m].Len, + bits)); + opt_len += + ((long) bits - (long) tree[m].Len) * (long) tree[m].Freq; + tree[m].Len = (ush) bits; + } + n--; + } + } +} + +/* =========================================================================== + * Generate the codes for a given tree and bit counts (which need not be + * optimal). + * IN assertion: the array bl_count contains the bit length statistics for + * the given tree and the field len is set for all tree elements. + * OUT assertion: the field code is set for all tree elements of non + * zero code length. + */ +static void gen_codes(ct_data * tree, int max_code) +{ + ush next_code[MAX_BITS + 1]; /* next code value for each bit length */ + ush code = 0; /* running code value */ + int bits; /* bit index */ + int n; /* code index */ + + /* The distribution counts are first used to generate the code values + * without bit reversal. + */ + for (bits = 1; bits <= MAX_BITS; bits++) { + next_code[bits] = code = (code + bl_count[bits - 1]) << 1; + } + /* Check that the bit counts in bl_count are consistent. The last code + * must be all ones. + */ + Assert(code + bl_count[MAX_BITS] - 1 == (1 << MAX_BITS) - 1, + "inconsistent bit counts"); + Tracev((stderr, "\ngen_codes: max_code %d ", max_code)); + + for (n = 0; n <= max_code; n++) { + int len = tree[n].Len; + + if (len == 0) + continue; + /* Now reverse the bits */ + tree[n].Code = bi_reverse(next_code[len]++, len); + + Tracec(tree != static_ltree, + (stderr, "\nn %3d %c l %2d c %4x (%x) ", n, + (isgraph(n) ? n : ' '), len, tree[n].Code, + next_code[len] - 1)); + } +} + +/* =========================================================================== + * Construct one Huffman tree and assigns the code bit strings and lengths. + * Update the total bit length for the current block. + * IN assertion: the field freq is set for all tree elements. + * OUT assertions: the fields len and code are set to the optimal bit length + * and corresponding code. The length opt_len is updated; static_len is + * also updated if stree is not null. The field max_code is set. + */ +static void build_tree(tree_desc * desc) +{ + ct_data *tree = desc->dyn_tree; + ct_data *stree = desc->static_tree; + int elems = desc->elems; + int n, m; /* iterate over heap elements */ + int max_code = -1; /* largest code with non zero frequency */ + int node = elems; /* next internal node of the tree */ + + /* Construct the initial heap, with least frequent element in + * heap[SMALLEST]. The sons of heap[n] are heap[2*n] and heap[2*n+1]. + * heap[0] is not used. + */ + heap_len = 0, heap_max = HEAP_SIZE; + + for (n = 0; n < elems; n++) { + if (tree[n].Freq != 0) { + heap[++heap_len] = max_code = n; + depth[n] = 0; + } else { + tree[n].Len = 0; + } + } + + /* The pkzip format requires that at least one distance code exists, + * and that at least one bit should be sent even if there is only one + * possible code. So to avoid special checks later on we force at least + * two codes of non zero frequency. + */ + while (heap_len < 2) { + int new = heap[++heap_len] = (max_code < 2 ? ++max_code : 0); + + tree[new].Freq = 1; + depth[new] = 0; + opt_len--; + if (stree) + static_len -= stree[new].Len; + /* new is 0 or 1 so it does not have extra bits */ + } + desc->max_code = max_code; + + /* The elements heap[heap_len/2+1 .. heap_len] are leaves of the tree, + * establish sub-heaps of increasing lengths: + */ + for (n = heap_len / 2; n >= 1; n--) + pqdownheap(tree, n); + + /* Construct the Huffman tree by repeatedly combining the least two + * frequent nodes. + */ + do { + pqremove(tree, n); /* n = node of least frequency */ + m = heap[SMALLEST]; /* m = node of next least frequency */ + + heap[--heap_max] = n; /* keep the nodes sorted by frequency */ + heap[--heap_max] = m; + + /* Create a new node father of n and m */ + tree[node].Freq = tree[n].Freq + tree[m].Freq; + depth[node] = (uch) (MAX(depth[n], depth[m]) + 1); + tree[n].Dad = tree[m].Dad = (ush) node; +#ifdef DUMP_BL_TREE + if (tree == bl_tree) { + bb_error_msg("\nnode %d(%d), sons %d(%d) %d(%d)", + node, tree[node].Freq, n, tree[n].Freq, m, tree[m].Freq); + } +#endif + /* and insert the new node in the heap */ + heap[SMALLEST] = node++; + pqdownheap(tree, SMALLEST); + + } while (heap_len >= 2); + + heap[--heap_max] = heap[SMALLEST]; + + /* At this point, the fields freq and dad are set. We can now + * generate the bit lengths. + */ + gen_bitlen((tree_desc *) desc); + + /* The field len is now set, we can generate the bit codes */ + gen_codes((ct_data *) tree, max_code); +} + +/* =========================================================================== + * Scan a literal or distance tree to determine the frequencies of the codes + * in the bit length tree. Updates opt_len to take into account the repeat + * counts. (The contribution of the bit length codes will be added later + * during the construction of bl_tree.) + */ +static void scan_tree(ct_data * tree, int max_code) +{ + int n; /* iterates over all tree elements */ + int prevlen = -1; /* last emitted length */ + int curlen; /* length of current code */ + int nextlen = tree[0].Len; /* length of next code */ + int count = 0; /* repeat count of the current code */ + int max_count = 7; /* max repeat count */ + int min_count = 4; /* min repeat count */ + + if (nextlen == 0) + max_count = 138, min_count = 3; + tree[max_code + 1].Len = (ush) 0xffff; /* guard */ + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; + nextlen = tree[n + 1].Len; + if (++count < max_count && curlen == nextlen) { + continue; + } else if (count < min_count) { + bl_tree[curlen].Freq += count; + } else if (curlen != 0) { + if (curlen != prevlen) + bl_tree[curlen].Freq++; + bl_tree[REP_3_6].Freq++; + } else if (count <= 10) { + bl_tree[REPZ_3_10].Freq++; + } else { + bl_tree[REPZ_11_138].Freq++; + } + count = 0; + prevlen = curlen; + if (nextlen == 0) { + max_count = 138, min_count = 3; + } else if (curlen == nextlen) { + max_count = 6, min_count = 3; + } else { + max_count = 7, min_count = 4; + } + } +} + +/* =========================================================================== + * Send a literal or distance tree in compressed form, using the codes in + * bl_tree. + */ +static void send_tree(ct_data * tree, int max_code) +{ + int n; /* iterates over all tree elements */ + int prevlen = -1; /* last emitted length */ + int curlen; /* length of current code */ + int nextlen = tree[0].Len; /* length of next code */ + int count = 0; /* repeat count of the current code */ + int max_count = 7; /* max repeat count */ + int min_count = 4; /* min repeat count */ + +/* tree[max_code+1].Len = -1; *//* guard already set */ + if (nextlen == 0) + max_count = 138, min_count = 3; + + for (n = 0; n <= max_code; n++) { + curlen = nextlen; + nextlen = tree[n + 1].Len; + if (++count < max_count && curlen == nextlen) { + continue; + } else if (count < min_count) { + do { + send_code(curlen, bl_tree); + } while (--count != 0); + + } else if (curlen != 0) { + if (curlen != prevlen) { + send_code(curlen, bl_tree); + count--; + } + Assert(count >= 3 && count <= 6, " 3_6?"); + send_code(REP_3_6, bl_tree); + send_bits(count - 3, 2); + + } else if (count <= 10) { + send_code(REPZ_3_10, bl_tree); + send_bits(count - 3, 3); + + } else { + send_code(REPZ_11_138, bl_tree); + send_bits(count - 11, 7); + } + count = 0; + prevlen = curlen; + if (nextlen == 0) { + max_count = 138, min_count = 3; + } else if (curlen == nextlen) { + max_count = 6, min_count = 3; + } else { + max_count = 7, min_count = 4; + } + } +} + +/* =========================================================================== + * Construct the Huffman tree for the bit lengths and return the index in + * bl_order of the last bit length code to send. + */ +static const int build_bl_tree() +{ + int max_blindex; /* index of last bit length code of non zero freq */ + + /* Determine the bit length frequencies for literal and distance trees */ + scan_tree((ct_data *) dyn_ltree, l_desc.max_code); + scan_tree((ct_data *) dyn_dtree, d_desc.max_code); + + /* Build the bit length tree: */ + build_tree((tree_desc *) (&bl_desc)); + /* opt_len now includes the length of the tree representations, except + * the lengths of the bit lengths codes and the 5+5+4 bits for the counts. + */ + + /* Determine the number of bit length codes to send. The pkzip format + * requires that at least 4 bit length codes be sent. (appnote.txt says + * 3 but the actual value used is 4.) + */ + for (max_blindex = BL_CODES - 1; max_blindex >= 3; max_blindex--) { + if (bl_tree[bl_order[max_blindex]].Len != 0) + break; + } + /* Update opt_len to include the bit length tree and counts */ + opt_len += 3 * (max_blindex + 1) + 5 + 5 + 4; + Tracev((stderr, "\ndyn trees: dyn %ld, stat %ld", opt_len, static_len)); + + return max_blindex; +} + +/* =========================================================================== + * Send the header for a block using dynamic Huffman trees: the counts, the + * lengths of the bit length codes, the literal tree and the distance tree. + * IN assertion: lcodes >= 257, dcodes >= 1, blcodes >= 4. + */ +static void send_all_trees(int lcodes, int dcodes, int blcodes) +{ + int rank; /* index in bl_order */ + + Assert(lcodes >= 257 && dcodes >= 1 && blcodes >= 4, "not enough codes"); + Assert(lcodes <= L_CODES && dcodes <= D_CODES + && blcodes <= BL_CODES, "too many codes"); + Tracev((stderr, "\nbl counts: ")); + send_bits(lcodes - 257, 5); /* not +255 as stated in appnote.txt */ + send_bits(dcodes - 1, 5); + send_bits(blcodes - 4, 4); /* not -3 as stated in appnote.txt */ + for (rank = 0; rank < blcodes; rank++) { + Tracev((stderr, "\nbl code %2d ", bl_order[rank])); + send_bits(bl_tree[bl_order[rank]].Len, 3); + } + Tracev((stderr, "\nbl tree: sent %ld", bits_sent)); + + send_tree((ct_data *) dyn_ltree, lcodes - 1); /* send the literal tree */ + Tracev((stderr, "\nlit tree: sent %ld", bits_sent)); + + send_tree((ct_data *) dyn_dtree, dcodes - 1); /* send the distance tree */ + Tracev((stderr, "\ndist tree: sent %ld", bits_sent)); +} + +/* =========================================================================== + * Determine the best encoding for the current block: dynamic trees, static + * trees or store, and output the encoded block to the zip file. This function + * returns the total compressed length for the file so far. + */ +static ulg flush_block(char *buf, ulg stored_len, int eof) +{ + ulg opt_lenb, static_lenb; /* opt_len and static_len in bytes */ + int max_blindex; /* index of last bit length code of non zero freq */ + + flag_buf[last_flags] = flags; /* Save the flags for the last 8 items */ + + /* Check if the file is ascii or binary */ + if (*file_type == (ush) UNKNOWN) + set_file_type(); + + /* Construct the literal and distance trees */ + build_tree((tree_desc *) (&l_desc)); + Tracev((stderr, "\nlit data: dyn %ld, stat %ld", opt_len, static_len)); + + build_tree((tree_desc *) (&d_desc)); + Tracev((stderr, "\ndist data: dyn %ld, stat %ld", opt_len, static_len)); + /* At this point, opt_len and static_len are the total bit lengths of + * the compressed block data, excluding the tree representations. + */ + + /* Build the bit length tree for the above two trees, and get the index + * in bl_order of the last bit length code to send. + */ + max_blindex = build_bl_tree(); + + /* Determine the best encoding. Compute first the block length in bytes */ + opt_lenb = (opt_len + 3 + 7) >> 3; + static_lenb = (static_len + 3 + 7) >> 3; + + Trace((stderr, + "\nopt %lu(%lu) stat %lu(%lu) stored %lu lit %u dist %u ", + opt_lenb, opt_len, static_lenb, static_len, stored_len, + last_lit, last_dist)); + + if (static_lenb <= opt_lenb) + opt_lenb = static_lenb; + + /* If compression failed and this is the first and last block, + * and if the zip file can be seeked (to rewrite the local header), + * the whole file is transformed into a stored file: + */ + if ((just_store || (stored_len <= opt_lenb)) && eof && compressed_len == 0L && seekable()) { + /* Since LIT_BUFSIZE <= 2*WSIZE, the input data must be there: */ + if (buf == (char *) 0) + bb_error_msg("block vanished"); + + copy_block(buf, (unsigned) stored_len, 0); /* without header */ + compressed_len = stored_len << 3; + *file_method = STORED; + + } else if ((just_store || (stored_len + 4 <= opt_lenb)) && buf != (char *) 0) { + /* 4: two words for the lengths */ + /* The test buf != NULL is only necessary if LIT_BUFSIZE > WSIZE. + * Otherwise we can't have processed more than WSIZE input bytes since + * the last block flush, because compression would have been + * successful. If LIT_BUFSIZE <= WSIZE, it is never too late to + * transform a block into a stored block. + */ + send_bits((STORED_BLOCK << 1) + eof, 3); /* send block type */ + compressed_len = (compressed_len + 3 + 7) & ~7L; + compressed_len += (stored_len + 4) << 3; + + copy_block(buf, (unsigned) stored_len, 1); /* with header */ + + } else if (static_lenb == opt_lenb) { + send_bits((STATIC_TREES << 1) + eof, 3); + compress_block((ct_data *) static_ltree, (ct_data *) static_dtree); + compressed_len += 3 + static_len; + } else { + send_bits((DYN_TREES << 1) + eof, 3); + send_all_trees(l_desc.max_code + 1, d_desc.max_code + 1, + max_blindex + 1); + compress_block((ct_data *) dyn_ltree, (ct_data *) dyn_dtree); + compressed_len += 3 + opt_len; + } + Assert(compressed_len == bits_sent, "bad compressed size"); + init_block(); + + if (eof) { + bi_windup(); + compressed_len += 7; /* align on byte boundary */ + } + Tracev((stderr, "\ncomprlen %lu(%lu) ", compressed_len >> 3, + compressed_len - 7 * eof)); + + return compressed_len >> 3; +} + +/* =========================================================================== + * Save the match info and tally the frequency counts. Return true if + * the current block must be flushed. + */ +static int ct_tally(int dist, int lc) +{ + l_buf[last_lit++] = (uch) lc; + if (dist == 0) { + /* lc is the unmatched char */ + dyn_ltree[lc].Freq++; + } else { + /* Here, lc is the match length - MIN_MATCH */ + dist--; /* dist = match distance - 1 */ + Assert((ush) dist < (ush) MAX_DIST && + (ush) lc <= (ush) (MAX_MATCH - MIN_MATCH) && + (ush) d_code(dist) < (ush) D_CODES, "ct_tally: bad match"); + + dyn_ltree[length_code[lc] + LITERALS + 1].Freq++; + dyn_dtree[d_code(dist)].Freq++; + + d_buf[last_dist++] = (ush) dist; + flags |= flag_bit; + } + flag_bit <<= 1; + + /* Output the flags if they fill a byte: */ + if ((last_lit & 7) == 0) { + flag_buf[last_flags++] = flags; + flags = 0, flag_bit = 1; + } + /* Try to guess if it is profitable to stop the current block here */ + if ((last_lit & 0xfff) == 0) { + /* Compute an upper bound for the compressed length */ + ulg out_length = (ulg) last_lit * 8L; + ulg in_length = (ulg) strstart - block_start; + int dcode; + + for (dcode = 0; dcode < D_CODES; dcode++) { + out_length += + (ulg) dyn_dtree[dcode].Freq * (5L + extra_dbits[dcode]); + } + out_length >>= 3; + Trace((stderr, + "\nlast_lit %u, last_dist %u, in %ld, out ~%ld(%ld%%) ", + last_lit, last_dist, in_length, out_length, + 100L - out_length * 100L / in_length)); + if (last_dist < last_lit / 2 && out_length < in_length / 2) + return 1; + } + return (last_lit == LIT_BUFSIZE - 1 || last_dist == DIST_BUFSIZE); + /* We avoid equality with LIT_BUFSIZE because of wraparound at 64K + * on 16 bit machines and because stored blocks are restricted to + * 64K-1 bytes. + */ +} + +/* =========================================================================== + * Send the block data compressed using the given Huffman trees + */ +static void compress_block(ct_data * ltree, ct_data * dtree) +{ + unsigned dist; /* distance of matched string */ + int lc; /* match length or unmatched char (if dist == 0) */ + unsigned lx = 0; /* running index in l_buf */ + unsigned dx = 0; /* running index in d_buf */ + unsigned fx = 0; /* running index in flag_buf */ + uch flag = 0; /* current flags */ + unsigned code; /* the code to send */ + int extra; /* number of extra bits to send */ + + if (last_lit != 0) + do { + if ((lx & 7) == 0) + flag = flag_buf[fx++]; + lc = l_buf[lx++]; + if ((flag & 1) == 0) { + send_code(lc, ltree); /* send a literal byte */ + Tracecv(isgraph(lc), (stderr, " '%c' ", lc)); + } else { + /* Here, lc is the match length - MIN_MATCH */ + code = length_code[lc]; + send_code(code + LITERALS + 1, ltree); /* send the length code */ + extra = extra_lbits[code]; + if (extra != 0) { + lc -= base_length[code]; + send_bits(lc, extra); /* send the extra length bits */ + } + dist = d_buf[dx++]; + /* Here, dist is the match distance - 1 */ + code = d_code(dist); + Assert(code < D_CODES, "bad d_code"); + + send_code(code, dtree); /* send the distance code */ + extra = extra_dbits[code]; + if (extra != 0) { + dist -= base_dist[code]; + send_bits(dist, extra); /* send the extra distance bits */ + } + } /* literal or match pair ? */ + flag >>= 1; + } while (lx < last_lit); + + send_code(END_BLOCK, ltree); +} + +/* =========================================================================== + * Set the file type to ASCII or BINARY, using a crude approximation: + * binary if more than 20% of the bytes are <= 6 or >= 128, ascii otherwise. + * IN assertion: the fields freq of dyn_ltree are set and the total of all + * frequencies does not exceed 64K (to fit in an int on 16 bit machines). + */ +static void set_file_type() +{ + int n = 0; + unsigned ascii_freq = 0; + unsigned bin_freq = 0; + + while (n < 7) + bin_freq += dyn_ltree[n++].Freq; + while (n < 128) + ascii_freq += dyn_ltree[n++].Freq; + while (n < LITERALS) + bin_freq += dyn_ltree[n++].Freq; + *file_type = bin_freq > (ascii_freq >> 2) ? BINARY : ASCII; + if (*file_type == BINARY && translate_eol) { + bb_error_msg("-l used on binary file"); + } +} + +/* zip.c -- compress files to the gzip or pkzip format + * Copyright (C) 1992-1993 Jean-loup Gailly + * This is free software; you can redistribute it and/or modify it under the + * terms of the GNU General Public License, see the file COPYING. + */ + + +static ulg crc; /* crc on uncompressed file data */ +static long header_bytes; /* number of bytes in gzip header */ + +static void put_long(ulg n) +{ + put_short((n) & 0xffff); + put_short(((ulg) (n)) >> 16); +} + +/* put_header_byte is used for the compressed output + * - for the initial 4 bytes that can't overflow the buffer. + */ +#define put_header_byte(c) {outbuf[outcnt++]=(uch)(c);} + +/* =========================================================================== + * Deflate in to out. + * IN assertions: the input and output buffers are cleared. + * The variables time_stamp and save_orig_name are initialized. + */ +static int zip(int in, int out) +{ + uch my_flags = 0; /* general purpose bit flags */ + ush attr = 0; /* ascii/binary flag */ + ush deflate_flags = 0; /* pkzip -es, -en or -ex equivalent */ + + ifd = in; + ofd = out; + outcnt = 0; + + /* Write the header to the gzip file. See algorithm.doc for the format */ + + + method = DEFLATED; + put_header_byte(GZIP_MAGIC[0]); /* magic header */ + put_header_byte(GZIP_MAGIC[1]); + put_header_byte(DEFLATED); /* compression method */ + + put_header_byte(my_flags); /* general flags */ + put_long(time_stamp); + + /* Write deflated file to zip file */ + crc = updcrc(0, 0); + + bi_init(out); + ct_init(&attr, &method); + lm_init(&deflate_flags); + + put_byte((uch) deflate_flags); /* extra flags */ + put_byte(OS_CODE); /* OS identifier */ + + header_bytes = (long) outcnt; + + (void) deflate(); + + /* Write the crc and uncompressed size */ + put_long(crc); + put_long(isize); + header_bytes += 2 * sizeof(long); + + flush_outbuf(); + return OK; +} + + +/* =========================================================================== + * Read a new buffer from the current input file, perform end-of-line + * translation, and update the crc and input file size. + * IN assertion: size >= 2 (for end-of-line translation) + */ +static int file_read(char *buf, unsigned size) +{ + unsigned len; + + Assert(insize == 0, "inbuf not empty"); + + len = read(ifd, buf, size); + if (len == (unsigned) (-1) || len == 0) + return (int) len; + + crc = updcrc((uch *) buf, len); + isize += (ulg) len; + return (int) len; +} + +/* =========================================================================== + * Write the output buffer outbuf[0..outcnt-1] and update bytes_out. + * (used for the compressed data only) + */ +static void flush_outbuf() +{ + if (outcnt == 0) + return; + + write_buf(ofd, (char *) outbuf, outcnt); + outcnt = 0; +} diff --git a/urunlevel/include/applets.h b/urunlevel/include/applets.h new file mode 100644 index 0000000..27fe124 --- /dev/null +++ b/urunlevel/include/applets.h @@ -0,0 +1,752 @@ +/* + * applets.h - a listing of all busybox applets. + * + * If you write a new applet, you need to add an entry to this list to make + * busybox aware of it. + * + * It is CRUCIAL that this listing be kept in ascii order, otherwise the binary + * search lookup contributed by Gaute B Strokkenes stops working. If you value + * your kneecaps, you'll be sure to *make sure* that any changes made to this + * file result in the listing remaining in ascii order. You have been warned. + */ + +#undef APPLET +#undef APPLET_ODDNAME +#undef APPLET_NOUSAGE + + +#if defined(PROTOTYPES) + #define APPLET(a,b,c,d) extern int b(int argc, char **argv); + #define APPLET_NOUSAGE(a,b,c,d) extern int b(int argc, char **argv); + #define APPLET_ODDNAME(a,b,c,d,e) extern int b(int argc, char **argv); + extern const char usage_messages[]; +#elif defined(MAKE_USAGE) + #ifdef CONFIG_FEATURE_VERBOSE_USAGE + #define APPLET(a,b,c,d) a##_trivial_usage "\n\n" a##_full_usage "\0" + #define APPLET_NOUSAGE(a,b,c,d) "\b\0" + #define APPLET_ODDNAME(a,b,c,d,e) e##_trivial_usage "\n\n" e##_full_usage "\0" + #else + #define APPLET(a,b,c,d) a##_trivial_usage "\0" + #define APPLET_NOUSAGE(a,b,c,d) "\b\0" + #define APPLET_ODDNAME(a,b,c,d,e) e##_trivial_usage "\0" + #endif +#elif defined(MAKE_LINKS) +# define APPLET(a,b,c,d) LINK c a +# define APPLET_NOUSAGE(a,b,c,d) LINK c a +# define APPLET_ODDNAME(a,b,c,d,e) LINK c a +#else + const struct BB_applet applets[] = { + #define APPLET(a,b,c,d) {#a,b,c,d}, + #define APPLET_NOUSAGE(a,b,c,d) {a,b,c,d}, + #define APPLET_ODDNAME(a,b,c,d,e) {a,b,c,d}, +#endif + +#ifdef CONFIG_INSTALL_NO_USR +#define _BB_DIR_USR_BIN _BB_DIR_BIN +#define _BB_DIR_USR_SBIN _BB_DIR_SBIN +#endif + + + +#ifdef CONFIG_TEST + APPLET_NOUSAGE("[", test_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_ADDGROUP + APPLET(addgroup, addgroup_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_ADDUSER + APPLET(adduser, adduser_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_ADJTIMEX + APPLET(adjtimex, adjtimex_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_AR + APPLET(ar, ar_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_ARPING + APPLET(arping, arping_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_ASH + APPLET_NOUSAGE("ash", ash_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_AWK + APPLET(awk, awk_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_BASENAME + APPLET(basename, basename_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_BOOT_NAMED + APPLET(boot_named, boot_named_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_BOOT_PORTMAP + APPLET(boot_portmap, boot_portmap_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_BOOT_SYSLOG + APPLET(boot_syslog, boot_syslog_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_BOOT_TIME + APPLET(boot_time, boot_time_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_BUNZIP2 + APPLET(bunzip2, bunzip2_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif + APPLET_NOUSAGE("busybox", busybox_main, _BB_DIR_BIN, _BB_SUID_MAYBE) +#ifdef CONFIG_BUNZIP2 + APPLET(bzcat, bunzip2_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_CAL + APPLET(cal, cal_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_CAT + APPLET(cat, cat_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_CHGRP + APPLET(chgrp, chgrp_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_CHMOD + APPLET(chmod, chmod_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_CHOWN + APPLET(chown, chown_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_CHROOT + APPLET(chroot, chroot_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_CHVT + APPLET(chvt, chvt_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_CLEAR + APPLET(clear, clear_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_CMP + APPLET(cmp, cmp_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_CP + APPLET(cp, cp_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_CPIO + APPLET(cpio, cpio_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_CROND + APPLET(crond, crond_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_CRONTAB + APPLET(crontab, crontab_main, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS) +#endif +#ifdef CONFIG_CUT + APPLET(cut, cut_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_DATE + APPLET(date, date_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_DC + APPLET(dc, dc_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_DD + APPLET(dd, dd_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_DEALLOCVT + APPLET(deallocvt, deallocvt_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_DELGROUP + APPLET(delgroup, delgroup_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_DELUSER + APPLET(deluser, deluser_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_DEVFSD + APPLET(devfsd, devfsd_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_DF + APPLET(df, df_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_DIRNAME + APPLET(dirname, dirname_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_DMESG + APPLET(dmesg, dmesg_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_DOS2UNIX + APPLET(dos2unix, dos2unix_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_DPKG + APPLET(dpkg, dpkg_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_DPKG_DEB + APPLET_ODDNAME("dpkg-deb", dpkg_deb_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER, dpkg_deb) +#endif +#ifdef CONFIG_DU + APPLET(du, du_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_DUMPKMAP + APPLET(dumpkmap, dumpkmap_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_DUMPLEASES + APPLET(dumpleases, dumpleases_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_ECHO + APPLET(echo, echo_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#if defined(CONFIG_FEATURE_GREP_EGREP_ALIAS) + APPLET_NOUSAGE("egrep", grep_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_ENV + APPLET(env, env_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_EXPR + APPLET(expr, expr_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_FALSE + APPLET(false, false_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_FBSET + APPLET(fbset, fbset_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_FDFLUSH + APPLET(fdflush, fdflush_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_FDFORMAT + APPLET(fdformat, fdformat_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_FDISK + APPLET(fdisk, fdisk_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#if defined(CONFIG_FEATURE_GREP_FGREP_ALIAS) + APPLET_NOUSAGE("fgrep", grep_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_FIND + APPLET(find, find_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_FOLD + APPLET(fold, fold_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_FREE + APPLET(free, free_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_FREERAMDISK + APPLET(freeramdisk, freeramdisk_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_FSCK_MINIX + APPLET_ODDNAME("fsck.minix", fsck_minix_main, _BB_DIR_SBIN, _BB_SUID_NEVER, fsck_minix) +#endif +#ifdef CONFIG_FTPGET + APPLET(ftpget, ftpgetput_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_FTPPUT + APPLET(ftpput, ftpgetput_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_GETOPT + APPLET(getopt, getopt_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_GETPKG + APPLET(getpkg, getpkg_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_GETTY + APPLET(getty, getty_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_GREP + APPLET(grep, grep_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_GUNZIP + APPLET(gunzip, gunzip_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_GZIP + APPLET(gzip, gzip_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_HALT + APPLET(halt, halt_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_HDPARM + APPLET(hdparm, hdparm_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_HEAD + APPLET(head, head_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_HEXDUMP + APPLET(hexdump, hexdump_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_HOSTID + APPLET(hostid, hostid_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_HOSTNAME + APPLET(hostname, hostname_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_HTTPD + APPLET(httpd, httpd_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_HUSH + APPLET_NOUSAGE("hush", hush_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_HWCLOCK + APPLET(hwclock, hwclock_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_ID + APPLET(id, id_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_IFCONFIG + APPLET(ifconfig, ifconfig_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_IFUPDOWN + APPLET(ifdown, ifupdown_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_IFUPDOWN + APPLET(ifup, ifupdown_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_INETD + APPLET(inetd, inetd_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_INIT + APPLET(init, init_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_INSMOD + APPLET(insmod, insmod_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_INSTALL + APPLET(install, install_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_INSTALL_INITD + APPLET(install_initd, install_initd_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_IP + APPLET(ip, ip_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_IPADDR + APPLET(ipaddr, ipaddr_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_IPCALC + APPLET(ipcalc, ipcalc_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_IPLINK + APPLET(iplink, iplink_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_IPROUTE + APPLET(iproute, iproute_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_IPTUNNEL + APPLET(iptunnel, iptunnel_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_KILL + APPLET(kill, kill_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_KILLALL + APPLET(killall, kill_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_KILLPROC + APPLET(killproc, killproc_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_KLOGD + APPLET(klogd, klogd_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_LASH + APPLET(lash, lash_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_LAST + APPLET(last, last_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_LENGTH + APPLET(length, length_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_FEATURE_INITRD + APPLET_NOUSAGE("linuxrc", init_main, _BB_DIR_ROOT, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_LINUXRC + APPLET(linuxrc, linuxrc_main, _BB_DIR_ROOT, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_LN + APPLET(ln, ln_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_LOADFONT + APPLET(loadfont, loadfont_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_LOADKMAP + APPLET(loadkmap, loadkmap_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_LOCAL_FS + APPLET(local_fs, local_fs_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_LOG_FAILURE_MSG + APPLET(log_failure_msg, log_failure_msg_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_LOG_SUCCESS_MSG + APPLET(log_success_msg, log_success_msg_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_LOG_WARNING_MSG + APPLET(log_warning_msg, log_warning_msg_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_LOGGER + APPLET(logger, logger_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_LOGIN + APPLET(login, login_main, _BB_DIR_BIN, _BB_SUID_ALWAYS) +#endif +#ifdef CONFIG_LOGNAME + APPLET(logname, logname_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_LOGREAD + APPLET(logread, logread_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_LOSETUP + APPLET(losetup, losetup_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_LS + APPLET(ls, ls_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_LSMOD + APPLET(lsmod, lsmod_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_MAKEDEVS + APPLET(makedevs, makedevs_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_MAN + APPLET(man, man_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_MD5SUM + APPLET(md5sum, md5sum_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_MESG + APPLET(mesg, mesg_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_MKDIR + APPLET(mkdir, mkdir_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_MKFIFO + APPLET(mkfifo, mkfifo_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_MKFS_MINIX + APPLET_ODDNAME("mkfs.minix", mkfs_minix_main, _BB_DIR_SBIN, _BB_SUID_NEVER, mkfs_minix) +#endif +#ifdef CONFIG_MKNOD + APPLET(mknod, mknod_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_MKSWAP + APPLET(mkswap, mkswap_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_MKTEMP + APPLET(mktemp, mktemp_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_MODPROBE + APPLET(modprobe, modprobe_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_MORE + APPLET(more, more_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_MOUNT + APPLET(mount, mount_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_MSH + APPLET_NOUSAGE("msh", msh_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_MT + APPLET(mt, mt_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_MV + APPLET(mv, mv_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_NAMEIF + APPLET(nameif, nameif_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_NC + APPLET(nc, nc_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_NETSTAT + APPLET(netstat, netstat_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_NETWORK + APPLET(network, network_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_NSLOOKUP + APPLET(nslookup, nslookup_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_OD + APPLET(od, od_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_OPENVT + APPLET(openvt, openvt_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_PASSWD + APPLET(passwd, passwd_main, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS) +#endif +#ifdef CONFIG_PATCH + APPLET(patch, patch_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_PIDOF + APPLET(pidof, pidof_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_PIDOFPROC + APPLET(pidofproc, pidofproc_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_PING + APPLET(ping, ping_main, _BB_DIR_BIN, _BB_SUID_MAYBE) +#endif +#ifdef CONFIG_PING6 + APPLET(ping6, ping6_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_PIPE_PROGRESS + APPLET_NOUSAGE("pipe_progress", pipe_progress_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_PIVOT_ROOT + APPLET(pivot_root, pivot_root_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_POWEROFF + APPLET(poweroff, poweroff_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_PRINTF + APPLET(printf, printf_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_PS + APPLET(ps, ps_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_PWD + APPLET(pwd, pwd_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_RC + APPLET(rc, rc_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_RCS + APPLET(rcS, rcS_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_RDATE + APPLET(rdate, rdate_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_READLINK + APPLET(readlink, readlink_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_REALPATH + APPLET(realpath, realpath_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_REBOOT + APPLET(reboot, reboot_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_REMOTE_FS + APPLET(remote_fs, remote_fs_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_REMOVE_INITD + APPLET(remove_initd, remove_initd_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_RENICE + APPLET(renice, renice_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_RESET + APPLET(reset, reset_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_RM + APPLET(rm, rm_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_RMDIR + APPLET(rmdir, rmdir_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_RMMOD + APPLET(rmmod, rmmod_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_ROUTE + APPLET(route, route_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_RPM + APPLET(rpm, rpm_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_RPM2CPIO + APPLET(rpm2cpio, rpm2cpio_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_RUN_PARTS + APPLET_ODDNAME("run-parts", run_parts_main, _BB_DIR_BIN, _BB_SUID_NEVER, run_parts) +#endif +#ifdef CONFIG_RX + APPLET(rx, rx_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_SED + APPLET(sed, sed_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_SEQ + APPLET(seq, seq_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_SETKEYCODES + APPLET(setkeycodes, setkeycodes_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#if defined(CONFIG_FEATURE_SH_IS_ASH) && defined(CONFIG_ASH) + APPLET_NOUSAGE("sh", ash_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#elif defined(CONFIG_FEATURE_SH_IS_HUSH) && defined(CONFIG_HUSH) + APPLET_NOUSAGE("sh", hush_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#elif defined(CONFIG_FEATURE_SH_IS_LASH) && defined(CONFIG_LASH) + APPLET_NOUSAGE("sh", lash_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#elif defined(CONFIG_FEATURE_SH_IS_MSH) && defined(CONFIG_MSH) + APPLET_NOUSAGE("sh", msh_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_SHA1SUM + APPLET(sha1sum, sha1sum_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_SLEEP + APPLET(sleep, sleep_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_SORT + APPLET(sort, sort_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_START_STOP_DAEMON + APPLET_ODDNAME("start-stop-daemon", start_stop_daemon_main, _BB_DIR_SBIN, _BB_SUID_NEVER, start_stop_daemon) +#endif +#ifdef CONFIG_START_DAEMON + APPLET(start_daemon, start_daemon_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_STRINGS + APPLET(strings, strings_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_STTY + APPLET(stty, stty_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_SU + APPLET(su, su_main, _BB_DIR_BIN, _BB_SUID_ALWAYS) +#endif +#ifdef CONFIG_SULOGIN + APPLET(sulogin, sulogin_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_SWAPONOFF + APPLET(swapoff, swap_on_off_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_SWAPONOFF + APPLET(swapon, swap_on_off_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_SYNC + APPLET(sync, sync_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_SYSCTL + APPLET(sysctl, sysctl_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_SYSLOGD + APPLET(syslogd, syslogd_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_TAIL + APPLET(tail, tail_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_TAR + APPLET(tar, tar_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_TEE + APPLET(tee, tee_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_TELNET + APPLET(telnet, telnet_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_TELNETD + APPLET(telnetd, telnetd_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_TEST + APPLET(test, test_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_TFTP + APPLET(tftp, tftp_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_TIME + APPLET(time, time_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_TOP + APPLET(top, top_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_TOUCH + APPLET(touch, touch_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_TR + APPLET(tr, tr_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_TRACEROUTE + APPLET(traceroute, traceroute_main, _BB_DIR_USR_BIN, _BB_SUID_MAYBE) +#endif +#ifdef CONFIG_TRUE + APPLET(true, true_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_TTY + APPLET(tty, tty_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_UDHCPC + APPLET(udhcpc, udhcpc_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_UDHCPC_SCRIPT + APPLET(udhcpc_script, udhcpc_script_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_UDHCPD + APPLET(udhcpd, udhcpd_main, _BB_DIR_USR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_UMOUNT + APPLET(umount, umount_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_UNAME + APPLET(uname, uname_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_UNCOMPRESS + APPLET(uncompress, uncompress_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_UNIQ + APPLET(uniq, uniq_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_UNIX2DOS + APPLET(unix2dos, dos2unix_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_UNZIP + APPLET(unzip, unzip_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_UPTIME + APPLET(uptime, uptime_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_USLEEP + APPLET(usleep, usleep_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_UUDECODE + APPLET(uudecode, uudecode_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_UUENCODE + APPLET(uuencode, uuencode_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_VCONFIG + APPLET(vconfig, vconfig_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_VI + APPLET(vi, vi_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_VLOCK + APPLET(vlock, vlock_main, _BB_DIR_USR_BIN, _BB_SUID_ALWAYS) +#endif +#ifdef CONFIG_WATCH + APPLET(watch, watch_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_WATCHDOG + APPLET(watchdog, watchdog_main, _BB_DIR_SBIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_WC + APPLET(wc, wc_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_WGET + APPLET(wget, wget_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_WHICH + APPLET(which, which_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_WHO + APPLET(who, who_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_WHOAMI + APPLET(whoami, whoami_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_XARGS + APPLET(xargs, xargs_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_YES + APPLET(yes, yes_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER) +#endif +#ifdef CONFIG_GUNZIP + APPLET(zcat, gunzip_main, _BB_DIR_BIN, _BB_SUID_NEVER) +#endif + +#if !defined(PROTOTYPES) && !defined(MAKE_USAGE) + { 0,NULL,0 } +}; + +#endif + + + + + + + + + + + diff --git a/urunlevel/include/usage.h b/urunlevel/include/usage.h new file mode 100644 index 0000000..c18bb20 --- /dev/null +++ b/urunlevel/include/usage.h @@ -0,0 +1,3077 @@ +#ifndef __BB_USAGE_H__ +#define __BB_USAGE_H__ + +#define addgroup_trivial_usage \ + "[-g GID] group_name [user_name]" +#define addgroup_full_usage \ + "Adds a group to the system\n\n" \ + "Options:\n" \ + "\t-g GID\t\tspecify gid" + +#define adduser_trivial_usage \ + "[OPTIONS] user_name" +#define adduser_full_usage \ + "Adds a user to the system\n\n" \ + "Options:\n" \ + "\t-h DIR\t\tAssign home directory DIR\n" \ + "\t-g GECOS\tAssign gecos field GECOS\n" \ + "\t-s SHELL\tAssign login shell SHELL\n" \ + "\t-G\t\tAdd the user to existing group GROUP\n" \ + "\t-S\t\tcreate a system user (ignored)\n" \ + "\t-D\t\tDo not assign a password (logins still possible via ssh)\n" \ + "\t-H\t\tDo not create the home directory" + +#define adjtimex_trivial_usage \ + "[-q] [-o offset] [-f frequency] [-p timeconstant] [-t tick]" +#define adjtimex_full_usage \ + "Reads and optionally sets system timebase parameters.\n" \ + "See adjtimex(2).\n\n" \ + "Options:\n" \ + "\t-q\t\tquiet mode - do not print\n" \ + "\t-o offset\ttime offset, microseconds\n" \ + "\t-f frequency\tfrequency adjust, integer kernel units (65536 is 1ppm)\n" \ + "\t\t\t(positive values make the system clock run fast)\n" \ + "\t-t tick\t\tmicroseconds per tick, usually 10000\n" \ + "\t-p timeconstant" + +#define ar_trivial_usage \ + "[-o] [-v] [-p] [-t] [-x] ARCHIVE FILES" +#define ar_full_usage \ + "Extract or list FILES from an ar archive.\n\n" \ + "Options:\n" \ + "\t-o\t\tpreserve original dates\n" \ + "\t-p\t\textract to stdout\n" \ + "\t-t\t\tlist\n" \ + "\t-x\t\textract\n" \ + "\t-v\t\tverbosely list files processed" + +#define arping_trivial_usage \ + "[-fqbDUA] [-c count] [-w timeout] [-I device] [-s sender] target\n" +#define arping_full_usage \ + "Ping hosts by ARP requests/replies.\n\n" \ + "Options:\n" \ + "\t-f\t\tQuit on first ARP reply\n" \ + "\t-q\t\tBe quiet\n" \ + "\t-b\t\tKeep broadcasting, don't go unicast\n" \ + "\t-D\t\tDuplicated address detection mode\n" \ + "\t-U\t\tUnsolicited ARP mode, update your neighbours\n" \ + "\t-A\t\tARP answer mode, update your neighbours\n" \ + "\t-c count\tStop after sending count ARP request packets\n" \ + "\t-w timeout\tTime to wait for ARP reply, in seconds\n" \ + "\t-I device\tOutgoing interface name, default is eth0\n" \ + "\t-s sender\tSet specific sender IP address\n" \ + "\ttarget\t\tTarget IP address of ARP request" + +#define ash_trivial_usage \ + "[FILE]...\n" \ + "or: ash -c command [args]...\n" +#define ash_full_usage \ + "The ash shell (command interpreter)" + +#define awk_trivial_usage \ + "[OPTION]... [program-text] [FILE ...]" +#define awk_full_usage \ + "Options:\n" \ + "\t-v var=val\t\tassign value 'val' to variable 'var'\n" \ + "\t-F sep\t\tuse 'sep' as field separator\n" \ + "\t-f progname\t\tread program source from file 'progname'" + +#define basename_trivial_usage \ + "FILE [SUFFIX]" +#define basename_full_usage \ + "Strips directory path and suffixes from FILE.\n" \ + "If specified, also removes any trailing SUFFIX." +#define basename_example_usage \ + "$ basename /usr/local/bin/foo\n" \ + "foo\n" \ + "$ basename /usr/local/bin/\n" \ + "bin\n" \ + "$ basename /foo/bar.txt .txt\n" \ + "bar" + + +#define boot_named_trivial_usage \ + "" +#define boot_named_full_usage \ + "LSB boot_named init system." +#define boot_named_example_usage \ + "$ boot_named start\n" + + +#define boot_portmap_trivial_usage \ + "" +#define boot_portmap_full_usage \ + "LSB boot_portmap init system." +#define boot_portmap_example_usage \ + "$ boot_portmap start\n" + + +#define boot_syslog_trivial_usage \ + "" +#define boot_syslog_full_usage \ + "LSB boot_syslog init system." +#define boot_syslog_example_usage \ + "$ boot_syslog start\n" + + +#define boot_time_trivial_usage \ + "" +#define boot_time_full_usage \ + "LSB boot_time init system." +#define boot_time_example_usage \ + "$ boot_time start\n" + + +#define bunzip2_trivial_usage \ + "[OPTION]... [FILE]" +#define bunzip2_full_usage \ + "Uncompress FILE (or standard input if FILE is '-' or omitted).\n\n" \ + "Options:\n" \ + "\t-c\tWrite output to standard output\n" \ + "\t-f\tForce" + +#define bzcat_trivial_usage \ + "FILE" +#define bzcat_full_usage \ + "Uncompress to stdout." + +#define cal_trivial_usage \ + "[-jy] [[month] year]" +#define cal_full_usage \ + "Display a calendar.\n" \ + "\nOptions:\n" \ + "\t-j\tUse julian dates.\n" \ + "\t-y\tDisplay the entire year." + +#define cat_trivial_usage \ + "[-u] [FILE]..." +#define cat_full_usage \ + "Concatenates FILE(s) and prints them to stdout.\n\n" \ + "Options:\n" \ + "\t-u\tignored since unbuffered i/o is always used" +#define cat_example_usage \ + "$ cat /proc/uptime\n" \ + "110716.72 17.67" + +#define chgrp_trivial_usage \ + "[OPTION]... GROUP FILE..." +#define chgrp_full_usage \ + "Change the group membership of each FILE to GROUP.\n" \ + "\nOptions:\n" \ + "\t-R\tChanges files and directories recursively." +#define chgrp_example_usage \ + "$ ls -l /tmp/foo\n" \ + "-r--r--r-- 1 andersen andersen 0 Apr 12 18:25 /tmp/foo\n" \ + "$ chgrp root /tmp/foo\n" \ + "$ ls -l /tmp/foo\n" \ + "-r--r--r-- 1 andersen root 0 Apr 12 18:25 /tmp/foo\n" + +#define chmod_trivial_usage \ + "[-R] MODE[,MODE]... FILE..." +#define chmod_full_usage \ + "Each MODE is one or more of the letters ugoa, one of the\n" \ + "symbols +-= and one or more of the letters rwxst.\n\n" \ + "Options:\n" \ + "\t-R\tChanges files and directories recursively." +#define chmod_example_usage \ + "$ ls -l /tmp/foo\n" \ + "-rw-rw-r-- 1 root root 0 Apr 12 18:25 /tmp/foo\n" \ + "$ chmod u+x /tmp/foo\n" \ + "$ ls -l /tmp/foo\n" \ + "-rwxrw-r-- 1 root root 0 Apr 12 18:25 /tmp/foo*\n" \ + "$ chmod 444 /tmp/foo\n" \ + "$ ls -l /tmp/foo\n" \ + "-r--r--r-- 1 root root 0 Apr 12 18:25 /tmp/foo\n" + +#define chown_trivial_usage \ + "[ -Rh ]... OWNER[<.|:>[GROUP]] FILE..." +#define chown_full_usage \ + "Change the owner and/or group of each FILE to OWNER and/or GROUP.\n" \ + "\nOptions:\n" \ + "\t-R\tChanges files and directories recursively.\n" \ + "\t-h\tDo not dereference symbolic links." +#define chown_example_usage \ + "$ ls -l /tmp/foo\n" \ + "-r--r--r-- 1 andersen andersen 0 Apr 12 18:25 /tmp/foo\n" \ + "$ chown root /tmp/foo\n" \ + "$ ls -l /tmp/foo\n" \ + "-r--r--r-- 1 root andersen 0 Apr 12 18:25 /tmp/foo\n" \ + "$ chown root.root /tmp/foo\n" \ + "ls -l /tmp/foo\n" \ + "-r--r--r-- 1 root root 0 Apr 12 18:25 /tmp/foo\n" + +#define chroot_trivial_usage \ + "NEWROOT [COMMAND...]" +#define chroot_full_usage \ + "Run COMMAND with root directory set to NEWROOT." +#define chroot_example_usage \ + "$ ls -l /bin/ls\n" \ + "lrwxrwxrwx 1 root root 12 Apr 13 00:46 /bin/ls -> /BusyBox\n" \ + "# mount /dev/hdc1 /mnt -t minix\n" \ + "# chroot /mnt\n" \ + "# ls -l /bin/ls\n" \ + "-rwxr-xr-x 1 root root 40816 Feb 5 07:45 /bin/ls*\n" + +#define chvt_trivial_usage \ + "N" +#define chvt_full_usage \ + "Changes the foreground virtual terminal to /dev/ttyN" + +#define clear_trivial_usage \ + "" +#define clear_full_usage \ + "Clear screen." + +#define cmp_trivial_usage \ + "[-l] [-s] FILE1 [FILE2]" +#define cmp_full_usage \ + "Compare files. Compares FILE1 vs stdin if FILE2 is not specified.\n\n" \ + "Options:\n" \ + "\t-l\tWrite the byte numbers (decimal) and values (octal)\n" \ + "\t\t for all differing bytes.\n" \ + "\t-s\tquiet mode - do not print" + +#define cp_trivial_usage \ + "[OPTION]... SOURCE DEST" +#define cp_full_usage \ + "Copies SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n" \ + "\n" \ + "\t-a\tSame as -dpR\n" \ + "\t-d\tPreserves links\n" \ + "\t-p\tPreserves file attributes if possible\n" \ + "\t-f\tforce (implied; ignored) - always set\n" \ + "\t-i\tinteractive, prompt before overwrite\n" \ + "\t-R,-r\tCopies directories recursively" + +#define cpio_trivial_usage \ + "-[dimtuv][F cpiofile]" +#define cpio_full_usage \ + "Extract or list files from a cpio archive\n" \ + "Main operation mode:\n" \ + "\td\t\tmake leading directories\n" \ + "\ti\t\textract\n" \ + "\tm\t\tpreserve mtime\n" \ + "\tt\t\tlist\n" \ + "\tv\t\tverbose\n" \ + "\tu\t\tunconditional overwrite\n" \ + "\tF\t\tinput from file" + +#define crond_trivial_usage \ + "-d[#] -c -f -b" +#define crond_full_usage \ + "\t-d [#] -l [#] -S -L logfile -f -b -c dir\n" \ + "\t-d num\tdebug level\n" \ + "\t-l num\tlog level (8 - default)\n" \ + "\t-S\tlog to syslogd (default)\n" \ + "\t-L file\tlog to file\n" \ + "\t-f\trun in fordeground\n" \ + "\t-b\trun in background (default)\n" \ + "\t-c dir\tworking dir" + +#define crontab_trivial_usage \ + "[-c dir] {file|-}|[-u|-l|-e|-d user]" +#define crontab_full_usage \ + "\tfile replace crontab from file\n" \ + "\t- replace crontab from stdin\n" \ + "\t-u user specify user\n" \ + "\t-l [user] list crontab for user\n" \ + "\t-e [user] edit crontab for user\n" \ + "\t-d [user] delete crontab for user\n" \ + "\t-c dir specify crontab directory" + + +#define cut_trivial_usage \ + "[OPTION]... [FILE]..." +#define cut_full_usage \ + "Prints selected fields from each input FILE to standard output.\n\n" \ + "Options:\n" \ + "\t-b LIST\t\tOutput only bytes from LIST\n" \ + "\t-c LIST\t\tOutput only characters from LIST\n" \ + "\t-d CHAR\t\tUse CHAR instead of tab as the field delimiter\n" \ + "\t-s\t\tOutput only the lines containing delimiter\n" \ + "\t-f N\t\tPrint only these fields\n" \ + "\t-n\t\tIgnored" +#define cut_example_usage \ + "$ echo "Hello world" | cut -f 1 -d ' '\n" \ + "Hello\n" \ + "$ echo "Hello world" | cut -f 2 -d ' '\n" \ + "world\n" + +#ifdef CONFIG_FEATURE_DATE_ISOFMT +#define USAGE_DATE_ISOFMT(a) a +#else +#define USAGE_DATE_ISOFMT(a) +#endif + +#define date_trivial_usage \ + "[OPTION]... [MMDDhhmm[[CC]YY][.ss]] [+FORMAT]" +#define date_full_usage \ + "Displays the current time in the given FORMAT, or sets the system date.\n" \ + "\nOptions:\n" \ + "\t-R\t\tOutputs RFC-822 compliant date string\n" \ + "\t-d STRING\tDisplays time described by STRING, not `now'\n" \ + USAGE_DATE_ISOFMT("\t-I[TIMESPEC]\tOutputs an ISO-8601 compliant date/time string.\n" \ + "\t\t\tTIMESPEC=`date' (or missing) for date only,\n" \ + "\t\t\t`hours', `minutes', or `seconds' for date and,\n" \ + "\t\t\ttime to the indicated precision.\n") \ + "\t-s\t\tSets time described by STRING\n" \ + "\t-r FILE\t\tDisplays the last modification time of FILE\n" \ + "\t-u\t\tPrints or sets Coordinated Universal Time" +#define date_example_usage \ + "$ date\n" \ + "Wed Apr 12 18:52:41 MDT 2000\n" + +#define dc_trivial_usage \ + "expression ..." +#define dc_full_usage \ + "This is a Tiny RPN calculator that understands the\n" \ + "following operations: +, add, -, sub, *, mul, /, div, %, mod, "\ + "**, exp, and, or, not, eor.\n" \ + "For example: 'dc 2 2 add' -> 4, and 'dc 8 8 \\* 2 2 + /' -> 16.\n" \ + "\nOptions:\n" \ + "p - Prints the value on the top of the stack, without altering the stack.\n" \ + "f - Prints the entire contents of the stack without altering anything.\n" \ + "o - Pops the value off the top of the stack and uses it to set the output radix.\n" \ + " Only 10 and 16 are supported." +#define dc_example_usage \ + "$ dc 2 2 + p\n" \ + "4\n" \ + "$ dc 8 8 \\* 2 2 + / p\n" \ + "16\n" \ + "$ dc 0 1 and p\n" \ + "0\n" \ + "$ dc 0 1 or p\n" \ + "1\n" \ + "$ echo 72 9 div 8 mul p | dc\n" \ + "64\n" + +#define dd_trivial_usage \ + "[if=FILE] [of=FILE] [bs=N] [count=N] [skip=N]\n" \ + "\t [seek=N] [conv=notrunc|noerror|sync]" +#define dd_full_usage \ + "Copy a file, converting and formatting according to options\n\n" \ + "\tif=FILE\t\tread from FILE instead of stdin\n" \ + "\tof=FILE\t\twrite to FILE instead of stdout\n" \ + "\tbs=N\t\tread and write N bytes at a time\n" \ + "\tcount=N\t\tcopy only N input blocks\n" \ + "\tskip=N\t\tskip N input blocks\n" \ + "\tseek=N\t\tskip N output blocks\n" \ + "\tconv=notrunc\tdon't truncate output file\n" \ + "\tconv=noerror\tcontinue after read errors\n" \ + "\tconv=sync\tpad blocks with zeros\n" \ + "\n" \ + "Numbers may be suffixed by c (x1), w (x2), b (x512), kD (x1000), k (x1024),\n" \ + "MD (x1000000), M (x1048576), GD (x1000000000) or G (x1073741824)." +#define dd_example_usage \ + "$ dd if=/dev/zero of=/dev/ram1 bs=1M count=4\n" \ + "4+0 records in\n" \ + "4+0 records out\n" + +#define deallocvt_trivial_usage \ + "[N]" +#define deallocvt_full_usage \ + "Deallocate unused virtual terminal /dev/ttyN" + +#define delgroup_trivial_usage \ + "GROUP" +#define delgroup_full_usage \ + "Deletes group GROUP from the system" + +#define deluser_trivial_usage \ + "USER" +#define deluser_full_usage \ + "Deletes user USER from the system" + +#ifdef CONFIG_DEVFSD_FG_NP + #define USAGE_DEVFSD_FG_NP(a) a +#else + #define USAGE_DEVFSD_FG_NP(a) +#endif + +#define devfsd_trivial_usage \ + "mntpnt [-v]"\ + USAGE_DEVFSD_FG_NP("[-fg][-np]" ) +#define devfsd_full_usage \ + "Optional daemon for managing devfs permissions and old device name symlinks.\n" \ + "\nOptions:\n" \ + "\tmntpnt\tThe mount point where devfs is mounted.\n\n" \ + "\t-v\tPrint the protocol version numbers for devfsd\n" \ + "\t\tand the kernel-side protocol version and exits." \ + USAGE_DEVFSD_FG_NP( "\n\n\t-fg\tRun the daemon in the foreground.\n\n" \ + "\t-np\tExit after parsing the configuration file\n" \ + "\t\tand processing synthetic REGISTER events.\n" \ + "\t\tDo not poll for events.") + +#ifdef CONFIG_FEATURE_HUMAN_READABLE + #define USAGE_HUMAN_READABLE(a) a + #define USAGE_NOT_HUMAN_READABLE(a) +#else + #define USAGE_HUMAN_READABLE(a) + #define USAGE_NOT_HUMAN_READABLE(a) a +#endif +#define df_trivial_usage \ + "[-" USAGE_HUMAN_READABLE("hm") USAGE_NOT_HUMAN_READABLE("") "k] [FILESYSTEM ...]" +#define df_full_usage \ + "Print the filesystem space used and space available.\n\n" \ + "Options:\n" \ + USAGE_HUMAN_READABLE( \ + "\n\t-h\tprint sizes in human readable format (e.g., 1K 243M 2G )\n" \ + "\t-m\tprint sizes in megabytes\n" \ + "\t-k\tprint sizes in kilobytes(default)") USAGE_NOT_HUMAN_READABLE( \ + "\n\t-k\tprint sizes in kilobytes(compatibility)") +#define df_example_usage \ + "$ df\n" \ + "Filesystem 1k-blocks Used Available Use% Mounted on\n" \ + "/dev/sda3 8690864 8553540 137324 98% /\n" \ + "/dev/sda1 64216 36364 27852 57% /boot\n" \ + "$ df /dev/sda3\n" \ + "Filesystem 1k-blocks Used Available Use% Mounted on\n" \ + "/dev/sda3 8690864 8553540 137324 98% /\n" + +#define dirname_trivial_usage \ + "FILENAME" +#define dirname_full_usage \ + "Strips non-directory suffix from FILENAME" +#define dirname_example_usage \ + "$ dirname /tmp/foo\n" \ + "/tmp\n" \ + "$ dirname /tmp/foo/\n" \ + "/tmp\n" + +#define dmesg_trivial_usage \ + "[-c] [-n LEVEL] [-s SIZE]" +#define dmesg_full_usage \ + "Prints or controls the kernel ring buffer\n\n" \ + "Options:\n" \ + "\t-c\t\tClears the ring buffer's contents after printing\n" \ + "\t-n LEVEL\tSets console logging level\n" \ + "\t-s SIZE\t\tUse a buffer of size SIZE" + +#define dos2unix_trivial_usage \ + "[option] [FILE]" +#define dos2unix_full_usage \ + "Converts FILE from dos format to unix format. When no option\n" \ + "is given, the input is converted to the opposite output format.\n" \ + "When no file is given, uses stdin for input and stdout for output.\n\n" \ + "Options:\n" \ + "\t-u\toutput will be in UNIX format\n" \ + "\t-d\toutput will be in DOS format" + +#define dpkg_trivial_usage \ + "[-ilCPru] [-F option] package_name" +#define dpkg_full_usage \ + "dpkg is a utility to install, remove and manage Debian packages.\n\n" \ + "Options:\n" \ + "\t-i\t\tInstall the package\n" \ + "\t-l\t\tList of installed packages\n" \ + "\t-C\t\tConfigure an unpackaged package\n" \ + "\t-F depends\tIgnore depency problems\n" \ + "\t-P\t\tPurge all files of a package\n" \ + "\t-r\t\tRemove all but the configuration files for a package\n" \ + "\t-u\t\tUnpack a package, but don't configure it" + +#define dpkg_deb_trivial_usage \ + "[-cefxX] FILE [argument]" +#define dpkg_deb_full_usage \ + "Perform actions on Debian packages (.debs)\n\n" \ + "Options:\n" \ + "\t-c\tList contents of filesystem tree\n" \ + "\t-e\tExtract control files to [argument] directory\n" \ + "\t-f\tDisplay control field name starting with [argument]\n" \ + "\t-x\tExtract packages filesystem tree to directory\n" \ + "\t-X\tVerbose extract" +#define dpkg_deb_example_usage \ + "$ dpkg-deb -X ./busybox_0.48-1_i386.deb /tmp\n" + +#ifdef CONFIG_FEATURE_DU_DEFALT_BLOCKSIZE_1K +#define USAGE_DU_DEFALT_BLOCKSIZE_1k(a) a +#define USAGE_NOT_DU_DEFALT_BLOCKSIZE_1k(a) +#else +#define USAGE_DU_DEFALT_BLOCKSIZE_1k(a) +#define USAGE_NOT_DU_DEFALT_BLOCKSIZE_1k(a) a +#endif + +#define du_trivial_usage \ + "[-aHLdclsx" USAGE_HUMAN_READABLE("hm") "k] [FILE]..." +#define du_full_usage \ + "Summarizes disk space used for each FILE and/or directory.\n" \ + "Disk space is printed in units of " \ + USAGE_DU_DEFALT_BLOCKSIZE_1k("1024") USAGE_NOT_DU_DEFALT_BLOCKSIZE_1k("512") \ + " bytes.\n\n" \ + "Options:\n" \ + "\t-a\tshow sizes of files in addition to directories\n" \ + "\t-H\tfollow symbolic links that are FILE command line args\n" \ + "\t-L\tfollow all symbolic links encountered\n" \ + "\t-d N\tlimit output to directories (and files with -a) of depth < N\n" \ + "\t-c\toutput a grand total\n" \ + "\t-l\tcount sizes many times if hard linked\n" \ + "\t-s\tdisplay only a total for each argument\n" \ + "\t-x\tskip directories on different filesystems\n" \ + USAGE_HUMAN_READABLE( \ + "\t-h\tprint sizes in human readable format (e.g., 1K 243M 2G )\n" \ + "\t-m\tprint sizes in megabytes\n" ) \ + "\t-k\tprint sizes in kilobytes" USAGE_DU_DEFALT_BLOCKSIZE_1k("(default)") +#define du_example_usage \ + "$ du\n" \ + "16 ./CVS\n" \ + "12 ./kernel-patches/CVS\n" \ + "80 ./kernel-patches\n" \ + "12 ./tests/CVS\n" \ + "36 ./tests\n" \ + "12 ./scripts/CVS\n" \ + "16 ./scripts\n" \ + "12 ./docs/CVS\n" \ + "104 ./docs\n" \ + "2417 .\n" + +#define dumpkmap_trivial_usage \ + "> keymap" +#define dumpkmap_full_usage \ + "Prints out a binary keyboard translation table to standard output." +#define dumpkmap_example_usage \ + "$ dumpkmap > keymap\n" + +#define dumpleases_trivial_usage \ + "[-r|-a] [-f LEASEFILE]" +#define dumpleases_full_usage \ + "Displays the DHCP leases granted by udhcpd.\n\n" \ + "Options:\n" \ + "\t-f,\t--file=FILENAME\tLeases file to load\n" \ + "\t-r,\t--remaining\tInterpret lease times as time remaing\n" \ + "\t-a,\t--absolute\tInterpret lease times as expire time" + +#ifdef CONFIG_FEATURE_FANCY_ECHO + #define USAGE_FANCY_ECHO(a) a +#else + #define USAGE_FANCY_ECHO(a) +#endif + +#define echo_trivial_usage \ + USAGE_FANCY_ECHO("[-neE] ") "[ARG ...]" +#define echo_full_usage \ + "Prints the specified ARGs to stdout\n\n" \ + USAGE_FANCY_ECHO("Options:\n" \ + "\t-n\tsuppress trailing newline\n" \ + "\t-e\tinterpret backslash-escaped characters (i.e., \\t=tab)\n" \ + "\t-E\tdisable interpretation of backslash-escaped characters") +#define echo_example_usage \ + "$ echo "Erik is cool"\n" \ + "Erik is cool\n" \ + USAGE_FANCY_ECHO("$ echo -e "Erik\\nis\\ncool"\n" \ + "Erik\n" \ + "is\n" \ + "cool\n" \ + "$ echo "Erik\\nis\\ncool"\n" \ + "Erik\\nis\\ncool\n") + +#define env_trivial_usage \ + "[-iu] [-] [name=value]... [command]" +#define env_full_usage \ + "Prints the current environment or runs a program after setting\n" \ + "up the specified environment.\n\n" \ + "Options:\n" \ + "\t-, -i\tstart with an empty environment\n" \ + "\t-u\tremove variable from the environment" + +#define expr_trivial_usage \ + "EXPRESSION" +#define expr_full_usage \ + "Prints the value of EXPRESSION to standard output.\n\n" \ + "EXPRESSION may be:\n" \ + "\tARG1 | ARG2 ARG1 if it is neither null nor 0, otherwise ARG2\n" \ + "\tARG1 & ARG2 ARG1 if neither argument is null or 0, otherwise 0\n" \ + "\tARG1 < ARG2 ARG1 is less than ARG2\n" \ + "\tARG1 <= ARG2 ARG1 is less than or equal to ARG2\n" \ + "\tARG1 = ARG2 ARG1 is equal to ARG2\n" \ + "\tARG1 != ARG2 ARG1 is unequal to ARG2\n" \ + "\tARG1 >= ARG2 ARG1 is greater than or equal to ARG2\n" \ + "\tARG1 > ARG2 ARG1 is greater than ARG2\n" \ + "\tARG1 + ARG2 arithmetic sum of ARG1 and ARG2\n" \ + "\tARG1 - ARG2 arithmetic difference of ARG1 and ARG2\n" \ + "\tARG1 * ARG2 arithmetic product of ARG1 and ARG2\n" \ + "\tARG1 / ARG2 arithmetic quotient of ARG1 divided by ARG2\n" \ + "\tARG1 % ARG2 arithmetic remainder of ARG1 divided by ARG2\n" \ + "\tSTRING : REGEXP anchored pattern match of REGEXP in STRING\n" \ + "\tmatch STRING REGEXP same as STRING : REGEXP\n" \ + "\tsubstr STRING POS LENGTH substring of STRING, POS counted from 1\n" \ + "\tindex STRING CHARS index in STRING where any CHARS is found,\n" \ + "\t or 0\n" \ + "\tlength STRING length of STRING\n" \ + "\tquote TOKEN interpret TOKEN as a string, even if\n" \ + "\t it is a keyword like `match' or an\n" \ + "\t operator like `/'\n" \ + "\t( EXPRESSION ) value of EXPRESSION\n\n" \ + "Beware that many operators need to be escaped or quoted for shells.\n" \ + "Comparisons are arithmetic if both ARGs are numbers, else\n" \ + "lexicographical. Pattern matches return the string matched between \n" \ + "\\( and \\) or null; if \\( and \\) are not used, they return the number \n" \ + "of characters matched or 0." + +#define false_trivial_usage \ + "" +#define false_full_usage \ + "Return an exit code of FALSE (1)." +#define false_example_usage \ + "$ false\n" \ + "$ echo $?\n" \ + "1\n" + +#define fbset_trivial_usage \ + "[options] [mode]" +#define fbset_full_usage \ + "Show and modify frame buffer settings" +#define fbset_example_usage \ + "$ fbset\n" \ + "mode "1024x768-76"\n" \ + "\t# D: 78.653 MHz, H: 59.949 kHz, V: 75.694 Hz\n" \ + "\tgeometry 1024 768 1024 768 16\n" \ + "\ttimings 12714 128 32 16 4 128 4\n" \ + "\taccel false\n" \ + "\trgba 5/11,6/5,5/0,0/0\n" \ + "endmode\n" + +#define fdflush_trivial_usage \ + "DEVICE" +#define fdflush_full_usage \ + "Forces floppy disk drive to detect disk change" + +#define fdformat_trivial_usage \ + "[-n] DEVICE" +#define fdformat_full_usage \ + "Low-level formats a floppy disk\n\n" \ + "Options:\n" \ + "\t-n\tDon't verify after format" + +#define fdisk_trivial_usage \ + "[-luv] [-C CYLINDERS] [-H HEADS] [-S SECTORS] [-b SSZ] DISK" +#define fdisk_full_usage \ + "Change partition table\n" \ + "Options:\n" \ + "\t-l List partition table(s)\n" \ + "\t-u Give Start and End in sector (instead of cylinder) units\n" \ + "\t-s PARTITION Give partition size(s) in blocks\n" \ + "\t-b 2048: (for certain MO disks) use 2048-byte sectors\n" \ + "\t-C CYLINDERS Set the number of cylinders\n" \ + "\t-H HEADS Set the number of heads\n" \ + "\t-S SECTORS Set the number of sectors\n" \ + "\t-v Give fdisk version" + +#ifdef CONFIG_FEATURE_FIND_TYPE + #define USAGE_FIND_TYPE(a) a +#else + #define USAGE_FIND_TYPE(a) +#endif +#ifdef CONFIG_FEATURE_FIND_PERM + #define USAGE_FIND_PERM(a) a +#else + #define USAGE_FIND_PERM(a) +#endif +#ifdef CONFIG_FEATURE_FIND_MTIME + #define USAGE_FIND_MTIME(a) a +#else + #define USAGE_FIND_MTIME(a) +#endif +#ifdef CONFIG_FEATURE_FIND_NEWER + #define USAGE_FIND_NEWER(a) a +#else + #define USAGE_FIND_NEWER(a) +#endif +#ifdef CONFIG_FEATURE_FIND_INUM + #define USAGE_FIND_INUM(a) a +#else + #define USAGE_FIND_INUM(a) +#endif + +#define find_trivial_usage \ + "[PATH...] [EXPRESSION]" +#define find_full_usage \ + "Search for files in a directory hierarchy. The default PATH is\n" \ + "the current directory; default EXPRESSION is '-print'\n" \ + "\nEXPRESSION may consist of:\n" \ + "\t-follow\t\tDereference symbolic links.\n" \ + "\t-name PATTERN\tFile name (leading directories removed) matches PATTERN.\n" \ + "\t-print\t\tPrint (default and assumed).\n" \ + USAGE_FIND_TYPE( \ + "\n\t-type X\t\tFiletype matches X (where X is one of: f,d,l,b,c,...)" \ +) USAGE_FIND_PERM( \ + "\n\t-perm PERMS\tPermissions match any of (+NNN); all of (-NNN);\n\t\t\tor exactly (NNN)" \ +) USAGE_FIND_MTIME( \ + "\n\t-mtime TIME\tModified time is greater than (+N); less than (-N);\n\t\t\tor exactly (N) days" \ +) USAGE_FIND_NEWER( \ + "\n\t-newer FILE\tModified time is more recent than FILE's" \ +) USAGE_FIND_INUM( \ + "\n\t-inum N\t\tFile has inode number N") +#define find_example_usage \ + "$ find / -name passwd\n" \ + "/etc/passwd\n" + +#define fold_trivial_usage \ + "[-bsw] [FILE]" +#define fold_full_usage \ + "Wrap input lines in each FILE (standard input by default), writing to\n" \ + "standard output.\n\n" \ + "Options:\n" \ + "\t-b\tcount bytes rather than columns\n" \ + "\t-s\tbreak at spaces\n" \ + "\t-w\tuse WIDTH columns instead of 80" + +#define free_trivial_usage \ + "" +#define free_full_usage \ + "Displays the amount of free and used system memory" +#define free_example_usage \ + "$ free\n" \ + " total used free shared buffers\n" \ + " Mem: 257628 248724 8904 59644 93124\n" \ + " Swap: 128516 8404 120112\n" \ + "Total: 386144 257128 129016\n" \ + +#define freeramdisk_trivial_usage \ + "DEVICE" +#define freeramdisk_full_usage \ + "Frees all memory used by the specified ramdisk." +#define freeramdisk_example_usage \ + "$ freeramdisk /dev/ram2\n" + +#define fsck_minix_trivial_usage \ + "[-larvsmf] /dev/name" +#define fsck_minix_full_usage \ + "Performs a consistency check for MINIX filesystems.\n\n" \ + "Options:\n" \ + "\t-l\tLists all filenames\n" \ + "\t-r\tPerform interactive repairs\n" \ + "\t-a\tPerform automatic repairs\n" \ + "\t-v\tverbose\n" \ + "\t-s\tOutputs super-block information\n" \ + "\t-m\tActivates MINIX-like \"mode not cleared\" warnings\n" \ + "\t-f\tForce file system check." + +#define ftpget_trivial_usage \ + "[options] remote-host local-file remote-file" +#define ftpget_full_usage \ + "Retrieve a remote file via FTP.\n\n" \ + "Options:\n" \ + "\t-c, --continue Continue a previous transfer\n" \ + "\t-v, --verbose Verbose\n" \ + "\t-u, --username Username to be used\n" \ + "\t-p, --password Password to be used\n" \ + "\t-P, --port Port number to be used" + +#define ftpput_trivial_usage \ + "[options] remote-host remote-file local-file" +#define ftpput_full_usage \ + "Store a local file on a remote machine via FTP.\n\n" \ + "Options:\n" \ + "\t-v, --verbose Verbose\n" \ + "\t-u, --username Username to be used\n" \ + "\t-p, --password Password to be used\n" \ + "\t-P, --port Port number to be used" + +#define getopt_trivial_usage \ + "[OPTIONS]..." +#define getopt_full_usage \ + "Parse command options\n" \ + "\t-a, --alternative Allow long options starting with single -\n" \ + "\t-l, --longoptions=longopts Long options to be recognized\n" \ + "\t-n, --name=progname The name under which errors are reported\n" \ + "\t-o, --options=optstring Short options to be recognized\n" \ + "\t-q, --quiet Disable error reporting by getopt(3)\n" \ + "\t-Q, --quiet-output No normal output\n" \ + "\t-s, --shell=shell Set shell quoting conventions\n" \ + "\t-T, --test Test for getopt(1) version\n" \ + "\t-u, --unquoted Do not quote the output" +#define getopt_example_usage \ + "$ cat getopt.test\n" \ + "#!/bin/sh\n" \ + "GETOPT=`getopt -o ab:c:: --long a-long,b-long:,c-long:: \\\n" \ + " -n 'example.busybox' -- "$@"`\n" \ + "if [ $? != 0 ] ; then exit 1 ; fi\n" \ + "eval set -- "$GETOPT"\n" \ + "while true ; do\n" \ + " case $1 in\n" \ + " -a|--a-long) echo \"Option a\" ; shift ;;\n" \ + " -b|--b-long) echo \"Option b, argument `$2'\" ; shift 2 ;;\n" \ + " -c|--c-long)\n" \ + " case "$2" in\n" \ + " \"\") echo \"Option c, no argument\"; shift 2 ;;\n" \ + " *) echo \"Option c, argument `$2'\" ; shift 2 ;;\n" \ + " esac ;;\n" \ + " --) shift ; break ;;\n" \ + " *) echo \"Internal error!\" ; exit 1 ;;\n" \ + " esac\n" \ + "done\n" + + +#define getpkg_trivial_usage \ + "[-afk] [PACKAGE] {[URL] | [DIR]}" +#define getpkg_full_usage \ + "Install a Trinux PACKAGE from a FILE or an URL ." \ + "\t-a,\t\tget all packages\n" \ + "\t-f,\t\tpackage file, no need to download\n" \ + "\t-k,\t\tkernel package" +#define getpkg_example_usage \ + "$ getpkg\n" \ + "$ getpkg -a\n" \ + "$ getpkg -f name\n" \ + "$ getpkg -fk name /media/cdrom/trinux/pkg\n" \ + "$ getpkg -k name\n" \ + "$ getpkg name http://www.trinux.org/pkg/\n" + + +#define getty_trivial_usage \ + "[OPTIONS]... baud_rate,... line [termtype]" +#define getty_full_usage \ + "Opens a tty, prompts for a login name, then invokes /bin/login\n\n" \ + "Options:\n" \ + "\t-h\t\tEnable hardware (RTS/CTS) flow control.\n" \ + "\t-i\t\tDo not display /etc/issue before running login.\n" \ + "\t-L\t\tLocal line, so do not do carrier detect.\n" \ + "\t-m\t\tGet baud rate from modem's CONNECT status message.\n" \ + "\t-w\t\tWait for a CR or LF before sending /etc/issue.\n" \ + "\t-n\t\tDo not prompt the user for a login name.\n" \ + "\t-f issue_file\tDisplay issue_file instead of /etc/issue.\n" \ + "\t-l login_app\tInvoke login_app instead of /bin/login.\n" \ + "\t-t timeout\tTerminate after timeout if no username is read.\n" \ + "\t-I initstring\tSets the init string to send before anything else.\n" \ + "\t-H login_host\tLog login_host into the utmp file as the hostname." + + +#define grep_trivial_usage \ + "[-ihHnqvs] PATTERN [FILEs...]" +#define grep_full_usage \ + "Search for PATTERN in each FILE or standard input.\n\n" \ + "Options:\n" \ + "\t-H\tprefix output lines with filename where match was found\n" \ + "\t-h\tsuppress the prefixing filename on output\n" \ + "\t-i\tignore case distinctions\n" \ + "\t-l\tlist names of files that match\n" \ + "\t-n\tprint line number with output lines\n" \ + "\t-q\tbe quiet. Returns 0 if result was found, 1 otherwise\n" \ + "\t-v\tselect non-matching lines\n" \ + "\t-s\tsuppress file open/read error messages" +#define grep_example_usage \ + "$ grep root /etc/passwd\n" \ + "root:x:0:0:root:/root:/bin/bash\n" \ + "$ grep ^[rR]oo. /etc/passwd\n" \ + "root:x:0:0:root:/root:/bin/bash\n" + +#define gunzip_trivial_usage \ + "[OPTION]... FILE" +#define gunzip_full_usage \ + "Uncompress FILE (or standard input if FILE is '-').\n\n" \ + "Options:\n" \ + "\t-c\tWrite output to standard output\n" \ + "\t-f\tForce read when source is a terminal\n" \ + "\t-t\tTest compressed file integrity" +#define gunzip_example_usage \ + "$ ls -la /tmp/BusyBox*\n" \ + "-rw-rw-r-- 1 andersen andersen 557009 Apr 11 10:55 /tmp/BusyBox-0.43.tar.gz\n" \ + "$ gunzip /tmp/BusyBox-0.43.tar.gz\n" \ + "$ ls -la /tmp/BusyBox*\n" \ + "-rw-rw-r-- 1 andersen andersen 1761280 Apr 14 17:47 /tmp/BusyBox-0.43.tar\n" + +#define gzip_trivial_usage \ + "[OPTION]... [FILE]..." +#define gzip_full_usage \ + "Compress FILE(s) with maximum compression.\n" \ + "When FILE is '-' or unspecified, reads standard input. Implies -c.\n\n" \ + "Options:\n" \ + "\t-c\tWrite output to standard output instead of FILE.gz\n" \ + "\t-d\tDecompress\n" \ + "\t-f\tForce write when destination is a terminal" +#define gzip_example_usage \ + "$ ls -la /tmp/busybox*\n" \ + "-rw-rw-r-- 1 andersen andersen 1761280 Apr 14 17:47 /tmp/busybox.tar\n" \ + "$ gzip /tmp/busybox.tar\n" \ + "$ ls -la /tmp/busybox*\n" \ + "-rw-rw-r-- 1 andersen andersen 554058 Apr 14 17:49 /tmp/busybox.tar.gz\n" + +#define halt_trivial_usage \ + "[-d]" +#define halt_full_usage \ + "Halt the system.\n" \ + "Options:\n" \ + "\t-d\t\tdelay interval for halting." + +#ifdef CONFIG_FEATURE_HDPARM_GET_IDENTITY +#define USAGE_HDPARM_IDENT(a) a +#else +#define USAGE_HDPARM_IDENT(a) +#endif + +#ifdef CONFIG_FEATURE_HDPARM_HDIO_SCAN_HWIF +#define USAGE_SCAN_HWIF(a) a +#else +#define USAGE_SCAN_HWIF(a) +#endif + +#ifdef CONFIG_FEATURE_HDPARM_HDIO_UNREGISTER_HWIF +#define USAGE_UNREGISTER_HWIF(a) a +#else +#define USAGE_UNREGISTER_HWIF(a) +#endif + +#ifdef CONFIG_FEATURE_HDPARM_HDIO_DRIVE_RESET +#define USAGE_DRIVE_RESET(a) a +#else +#define USAGE_DRIVE_RESET(a) +#endif + +#ifdef CONFIG_FEATURE_HDPARM_HDIO_TRISTATE_HWIF +#define USAGE_TRISTATE_HWIF(a) a +#else +#define USAGE_TRISTATE_HWIF(a) +#endif + +#ifdef CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA +#define USAGE_GETSET_DMA(a) a +#else +#define USAGE_GETSET_DMA(a) +#endif + +#define hdparm_trivial_usage \ + "[options] [device] .." +#define hdparm_full_usage \ + "Options:" \ + "\t-a get/set fs readahead\n" \ + "\t-A set drive read-lookahead flag (0/1)\n" \ + "\t-b get/set bus state (0 == off, 1 == on, 2 == tristate)\n" \ + "\t-B set Advanced Power Management setting (1-255)\n" \ + "\t-c get/set IDE 32-bit IO setting\n" \ + "\t-C check IDE power mode status\n" \ + USAGE_GETSET_DMA("\t-d get/set using_dma flag\n") \ + "\t-D enable/disable drive defect-mgmt\n" \ + "\t-f flush buffer cache for device on exit\n" \ + "\t-g display drive geometry\n" \ + "\t-h display terse usage information\n" \ + "\t-i display drive identification\n" \ + USAGE_HDPARM_IDENT("\t-I detailed/current information directly from drive\n") \ + USAGE_HDPARM_IDENT("\t-Istdin similar to -I, but wants /proc/ide/" "*" "/hd?/identify as input\n") \ + "\t-k get/set keep_settings_over_reset flag (0/1)\n" \ + "\t-K set drive keep_features_over_reset flag (0/1)\n" \ + "\t-L set drive doorlock (0/1) (removable harddisks only)\n" \ + "\t-m get/set multiple sector count\n" \ + "\t-n get/set ignore-write-errors flag (0/1)\n" \ + "\t-p set PIO mode on IDE interface chipset (0,1,2,3,4,...)\n" \ + "\t-P set drive prefetch count\n" \ + "\t-q change next setting quietly\n" \ + "\t-Q get/set DMA tagged-queuing depth (if supported)\n" \ + "\t-r get/set readonly flag (DANGEROUS to set)\n" \ + USAGE_SCAN_HWIF("\t-R register an IDE interface (DANGEROUS)\n") \ + "\t-S set standby (spindown) timeout\n" \ + "\t-t perform device read timings\n" \ + "\t-T perform cache read timings\n" \ + "\t-u get/set unmaskirq flag (0/1)\n" \ + USAGE_UNREGISTER_HWIF("\t-U un-register an IDE interface (DANGEROUS)\n") \ + "\t-v defaults; same as -mcudkrag for IDE drives\n" \ + "\t-V display program version and exit immediately\n" \ + USAGE_DRIVE_RESET("\t-w perform device reset (DANGEROUS)\n") \ + "\t-W set drive write-caching flag (0/1) (DANGEROUS)\n" \ + USAGE_TRISTATE_HWIF("\t-x tristate device for hotswap (0/1) (DANGEROUS)\n") \ + "\t-X set IDE xfer mode (DANGEROUS)\n" \ + "\t-y put IDE drive in standby mode\n" \ + "\t-Y put IDE drive to sleep\n" \ + "\t-Z disable Seagate auto-powersaving mode\n" \ + "\t-z re-read partition table" + +#ifdef CONFIG_FEATURE_FANCY_HEAD +#define USAGE_FANCY_HEAD(a) a +#else +#define USAGE_FANCY_HEAD(a) +#endif + +#define head_trivial_usage \ + "[OPTION]... [FILE]..." +#define head_full_usage \ + "Print first 10 lines of each FILE to standard output.\n" \ + "With more than one FILE, precede each with a header giving the\n" \ + "file name. With no FILE, or when FILE is -, read standard input.\n\n" \ + "Options:\n" \ + "\t-n NUM\t\tPrint first NUM lines instead of first 10" \ + USAGE_FANCY_HEAD( \ + "\n\t-c NUM\t\toutput the first NUM bytes\n" \ + "\t-q\t\tnever output headers giving file names\n" \ + "\t-v\t\talways output headers giving file names" ) +#define head_example_usage \ + "$ head -n 2 /etc/passwd\n" \ + "root:x:0:0:root:/root:/bin/bash\n" \ + "daemon:x:1:1:daemon:/usr/sbin:/bin/sh\n" + +#define hexdump_trivial_usage \ + "[-[bcdefnosvx]] [OPTION] FILE" +#define hexdump_full_usage \ + "The hexdump utility is a filter which displays the specified files,\n" \ + "or the standard input, if no files are specified, in a user specified\n"\ + "format\n" \ + "\t-b\t\tOne-byte octal display\n" \ + "\t-c\t\tOne-byte character display\n" \ + "\t-d\t\tTwo-byte decimal display\n" \ + "\t-e FORMAT STRING\n" \ + "\t-f FORMAT FILE\n" \ + "\t-n LENGTH\tInterpret only length bytes of input\n" \ + "\t-o\t\tTwo-byte octal display\n" \ + "\t-s OFFSET\tSkip offset byte\n" \ + "\t-v\t\tdisplay all input data\n" \ + "\t-x\t\tTwo-byte hexadecimal display" + +#define hostid_trivial_usage \ + "" +#define hostid_full_usage \ + "Print out a unique 32-bit identifier for the machine." + +#define hostname_trivial_usage \ + "[OPTION] {hostname | -F FILE}" +#define hostname_full_usage \ + "Get or set the hostname or DNS domain name. If a hostname is given\n" \ + "(or FILE with the -F parameter), the host name will be set.\n\n" \ + "Options:\n" \ + "\t-s\tShort\n" \ + "\t-i\tAddresses for the hostname\n" \ + "\t-d\tDNS domain name\n" \ + "\t-f\tFully qualified domain name\n" \ + "\t-F FILE\tUse the contents of FILE to specify the hostname" +#define hostname_example_usage \ + "$ hostname\n" \ + "sage\n" + +#ifdef CONFIG_FEATURE_HTTPD_BASIC_AUTH + #define USAGE_HTTPD_BASIC_AUTH(a) a + #ifdef CONFIG_FEATURE_HTTPD_AUTH_MD5 + #define USAGE_HTTPD_AUTH_MD5(a) a + #else + #define USAGE_HTTPD_AUTH_MD5(a) + #endif +#else + #define USAGE_HTTPD_BASIC_AUTH(a) + #define USAGE_HTTPD_AUTH_MD5(a) +#endif +#ifdef CONFIG_FEATURE_HTTPD_USAGE_FROM_INETD_ONLY + #define USAGE_HTTPD_STANDALONE(a) + #define USAGE_HTTPD_SETUID(a) +#else + #define USAGE_HTTPD_STANDALONE(a) a + #ifdef CONFIG_FEATURE_HTTPD_SETUID + #define USAGE_HTTPD_SETUID(a) a + #else + #define USAGE_HTTPD_SETUID(a) + #endif +#endif +#define httpd_trivial_usage \ + "[-c ]" \ + USAGE_HTTPD_STANDALONE(" [-p ]") \ + USAGE_HTTPD_SETUID(" [-u user]") \ + USAGE_HTTPD_BASIC_AUTH(" [-r ]") \ + USAGE_HTTPD_AUTH_MD5(" [-m pass]") \ + " [-h home]" \ + " [-d/-e ]" +#define httpd_full_usage \ + "Listens for incoming http server requests.\n\n"\ + "Options:\n" \ + "\t-c FILE\t\tSpecifies configuration file. (default httpd.conf)\n" \ + USAGE_HTTPD_STANDALONE("\t-p PORT\tServer port (default 80)\n") \ + USAGE_HTTPD_SETUID("\t-u USER\tSet uid to USER after listening privileges port\n") \ + USAGE_HTTPD_BASIC_AUTH("\t-r REALM\tAuthentication Realm for Basic Authentication\n") \ + USAGE_HTTPD_AUTH_MD5("\t-m PASS\t\tCrypt PASS with md5 algorithm\n") \ + "\t-h HOME \tSpecifies http HOME directory (default ./)\n" \ + "\t-e STRING\tHtml encode STRING\n" \ + "\t-d STRING\tURL decode STRING" + +#define hwclock_trivial_usage \ + "[-r|--show] [-s|--hctosys] [-w|--systohc] [-l|--localtime] [-u|--utc]" +#define hwclock_full_usage \ + "Query and set the hardware clock (RTC)\n\n" \ + "Options:\n" \ + "\t-r\tread hardware clock and print result\n" \ + "\t-s\tset the system time from the hardware clock\n" \ + "\t-w\tset the hardware clock to the current system time\n" \ + "\t-u\tthe hardware clock is kept in coordinated universal time\n" \ + "\t-l\tthe hardware clock is kept in local time" + +#ifdef CONFIG_SELINUX + #define USAGE_SELINUX(a) a +#else + #define USAGE_SELINUX(a) +#endif + +#define id_trivial_usage \ + "[OPTIONS]... [USERNAME]" +#define id_full_usage \ + "Print information for USERNAME or the current user\n\n" \ + "Options:\n" \ + USAGE_SELINUX("\t-c\tprints only the security context\n") \ + "\t-g\tprints only the group ID\n" \ + "\t-u\tprints only the user ID\n" \ + "\t-n\tprint a name instead of a number\n" \ + "\t-r\tprints the real user ID instead of the effective ID" +#define id_example_usage \ + "$ id\n" \ + "uid=1000(andersen) gid=1000(andersen)\n" + +#ifdef CONFIG_FEATURE_IFCONFIG_SLIP + #define USAGE_SIOCSKEEPALIVE(a) a +#else + #define USAGE_SIOCSKEEPALIVE(a) +#endif +#ifdef CONFIG_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ + #define USAGE_IFCONFIG_MII(a) a +#else + #define USAGE_IFCONFIG_MII(a) +#endif +#ifdef CONFIG_FEATURE_IFCONFIG_HW + #define USAGE_IFCONFIG_HW(a) a +#else + #define USAGE_IFCONFIG_HW(a) +#endif +#ifdef CONFIG_FEATURE_IFCONFIG_STATUS + #define USAGE_IFCONFIG_OPT_A(a) a +#else + #define USAGE_IFCONFIG_OPT_A(a) +#endif +#ifdef CONFIG_FEATURE_IPV6 + #define USAGE_IPV6(a) a +#else + #define USAGE_IPV6(a) +#endif + +#define ifconfig_trivial_usage \ + USAGE_IFCONFIG_OPT_A("[-a]") " [
]" +#define ifconfig_full_usage \ + "configure a network interface\n\n" \ + "Options:\n" \ + USAGE_IPV6("[add
[/]]\n") \ + USAGE_IPV6("[del
[/]]\n") \ + "\t[[-]broadcast [
]] [[-]pointopoint [
]]\n" \ + "\t[netmask
] [dstaddr
]\n" \ + USAGE_SIOCSKEEPALIVE("\t[outfill ] [keepalive ]\n") \ + "\t" USAGE_IFCONFIG_HW("[hw ether
] ") \ + "[metric ] [mtu ]\n" \ + "\t[[-]trailers] [[-]arp] [[-]allmulti]\n" \ + "\t[multicast] [[-]promisc] [txqueuelen ] [[-]dynamic]\n" \ + USAGE_IFCONFIG_MII("\t[mem_start ] [io_addr ] [irq ]\n") \ + "\t[up|down] ..." + +#define ifup_trivial_usage \ + "<-ahinv> " +#define ifup_full_usage \ + "ifup \n\n" \ + "Options:\n" \ + "\t-h\tthis help\n" \ + "\t-a\tde/configure all interfaces automatically\n" \ + "\t-i FILE\tuse FILE for interface definitions\n" \ + "\t-n\tprint out what would happen, but don't do it\n" \ + "\t\t\t(note that this option doesn't disable mappings)\n" \ + "\t-v\tprint out what would happen before doing it\n" \ + "\t-m\tdon't run any mappings\n" \ + "\t-f\tforce de/configuration" + +#define ifdown_trivial_usage \ + "<-ahinv> " +#define ifdown_full_usage \ + "ifdown \n\n" \ + "Options:\n" \ + "\t-h\tthis help\n" \ + "\t-a\tde/configure all interfaces automatically\n" \ + "\t-i FILE\tuse FILE for interface definitions\n" \ + "\t-n\tprint out what would happen, but don't do it\n" \ + "\t\t(note that this option doesn't disable mappings)\n" \ + "\t-v\tprint out what would happen before doing it\n" \ + "\t-m\tdon't run any mappings\n" \ + "\t-f\tforce de/configuration" + +#define inetd_trivial_usage \ + "[-q len] [conf]" +#define inetd_full_usage \ + "Listens for network connections and launches programs\n\n" \ + "Option:\n" \ + "\t-q\tSets the size of the socket listen queue to\n" \ + "\t\tthe specified value. Default is 128." + +#define init_trivial_usage \ + "" +#define init_full_usage \ + "Init is the parent of all processes." +#define init_notes_usage \ +"This version of init is designed to be run only by the kernel.\n" \ +"\n" \ +"BusyBox init doesn't support multiple runlevels. The runlevels field of\n" \ +"the /etc/inittab file is completely ignored by BusyBox init. If you want \n" \ +"runlevels, use sysvinit.\n" \ +"\n" \ +"BusyBox init works just fine without an inittab. If no inittab is found, \n" \ +"it has the following default behavior:\n" \ +"\n" \ +" ::sysinit:/etc/init.d/rcS\n" \ +" ::askfirst:/bin/sh\n" \ +" ::ctrlaltdel:/sbin/reboot\n" \ +" ::shutdown:/sbin/swapoff -a\n" \ +" ::shutdown:/bin/umount -a -r\n" \ +" ::restart:/sbin/init\n" \ +"\n" \ +"if it detects that /dev/console is _not_ a serial console, it will also run:\n" \ +"\n" \ +" tty2::askfirst:/bin/sh\n" \ +" tty3::askfirst:/bin/sh\n" \ +" tty4::askfirst:/bin/sh\n" \ +"\n" \ +"If you choose to use an /etc/inittab file, the inittab entry format is as follows:\n" \ +"\n" \ +" :::\n" \ +"\n" \ +" :\n" \ +"\n" \ +" WARNING: This field has a non-traditional meaning for BusyBox init!\n" \ +" The id field is used by BusyBox init to specify the controlling tty for\n" \ +" the specified process to run on. The contents of this field are\n" \ +" appended to "/dev/" and used as-is. There is no need for this field to\n" \ +" be unique, although if it isn't you may have strange results. If this\n" \ +" field is left blank, the controlling tty is set to the console. Also\n" \ +" note that if BusyBox detects that a serial console is in use, then only\n" \ +" entries whose controlling tty is either the serial console or /dev/null\n" \ +" will be run. BusyBox init does nothing with utmp. We don't need no\n" \ +" stinkin' utmp.\n" \ +"\n" \ +" :\n" \ +"\n" \ +" The runlevels field is completely ignored.\n" \ +"\n" \ +" :\n" \ +"\n" \ +" Valid actions include: sysinit, respawn, askfirst, wait,\n" \ +" once, restart, ctrlaltdel, and shutdown.\n" \ +"\n" \ +" The available actions can be classified into two groups: actions\n" \ +" that are run only once, and actions that are re-run when the specified\n" \ +" process exits.\n" \ +"\n" \ +" Run only-once actions:\n" \ +"\n" \ +" 'sysinit' is the first item run on boot. init waits until all\n" \ +" sysinit actions are completed before continuing. Following the\n" \ +" completion of all sysinit actions, all 'wait' actions are run.\n" \ +" 'wait' actions, like 'sysinit' actions, cause init to wait until\n" \ +" the specified task completes. 'once' actions are asynchronous,\n" \ +" therefore, init does not wait for them to complete. 'restart' is\n" \ +" the action taken to restart the init process. By default this should\n" \ +" simply run /sbin/init, but can be a script which runs pivot_root or it\n" \ +" can do all sorts of other interesting things. The 'ctrlaltdel' init\n" \ +" actions are run when the system detects that someone on the system\n" \ +" console has pressed the CTRL-ALT-DEL key combination. Typically one\n" \ +" wants to run 'reboot' at this point to cause the system to reboot.\n" \ +" Finally the 'shutdown' action specifies the actions to taken when\n" \ +" init is told to reboot. Unmounting filesystems and disabling swap\n" \ +" is a very good here\n" \ +"\n" \ +" Run repeatedly actions:\n" \ +"\n" \ +" 'respawn' actions are run after the 'once' actions. When a process\n" \ +" started with a 'respawn' action exits, init automatically restarts\n" \ +" it. Unlike sysvinit, BusyBox init does not stop processes from\n" \ +" respawning out of control. The 'askfirst' actions acts just like\n" \ +" respawn, except that before running the specified process it\n" \ +" displays the line "Please press Enter to activate this console."\n" \ +" and then waits for the user to press enter before starting the\n" \ +" specified process.\n" \ +"\n" \ +" Unrecognized actions (like initdefault) will cause init to emit an\n" \ +" error message, and then go along with its business. All actions are\n" \ +" run in the order they appear in /etc/inittab.\n" \ +"\n" \ +" :\n" \ +"\n" \ +" Specifies the process to be executed and its command line.\n" \ +"\n" \ +"Example /etc/inittab file:\n" \ +"\n" \ +" # This is run first except when booting in single-user mode.\n" \ +" #\n" \ +" ::sysinit:/etc/init.d/rcS\n" \ +" \n" \ +" # /bin/sh invocations on selected ttys\n" \ +" #\n" \ +" # Start an "askfirst" shell on the console (whatever that may be)\n" \ +" ::askfirst:-/bin/sh\n" \ +" # Start an "askfirst" shell on /dev/tty2-4\n" \ +" tty2::askfirst:-/bin/sh\n" \ +" tty3::askfirst:-/bin/sh\n" \ +" tty4::askfirst:-/bin/sh\n" \ +" \n" \ +" # /sbin/getty invocations for selected ttys\n" \ +" #\n" \ +" tty4::respawn:/sbin/getty 38400 tty4\n" \ +" tty5::respawn:/sbin/getty 38400 tty5\n" \ +" \n" \ +" \n" \ +" # Example of how to put a getty on a serial line (for a terminal)\n" \ +" #\n" \ +" #::respawn:/sbin/getty -L ttyS0 9600 vt100\n" \ +" #::respawn:/sbin/getty -L ttyS1 9600 vt100\n" \ +" #\n" \ +" # Example how to put a getty on a modem line.\n" \ +" #::respawn:/sbin/getty 57600 ttyS2\n" \ +" \n" \ +" # Stuff to do when restarting the init process\n" \ +" ::restart:/sbin/init\n" \ +" \n" \ +" # Stuff to do before rebooting\n" \ +" ::ctrlaltdel:/sbin/reboot\n" \ +" ::shutdown:/bin/umount -a -r\n" \ +" ::shutdown:/sbin/swapoff -a\n" + +#ifdef CONFIG_FEATURE_INSMOD_LOAD_MAP + #define USAGE_INSMOD_MAP(a) a +#else + #define USAGE_INSMOD_MAP(a) +#endif +#define insmod_trivial_usage \ + "[OPTION]... MODULE [symbol=value]..." +#define insmod_full_usage \ + "Loads the specified kernel modules into the kernel.\n\n" \ + "Options:\n" \ + "\t-f\tForce module to load into the wrong kernel version.\n" \ + "\t-k\tMake module autoclean-able.\n" \ + "\t-v\tverbose output\n" \ + "\t-q\tquiet output\n" \ + "\t-L\tLock to prevent simultaneous loads of a module\n" \ + USAGE_INSMOD_MAP("\t-m\tOutput load map to stdout\n") \ + "\t-o NAME\tSet internal module name to NAME\n" \ + "\t-x\tdo not export externs" + +#define install_trivial_usage \ + "[-cgmops] [sources] " +#define install_full_usage \ + "Copies files and set attributes\n\n" \ + "Options:\n" \ + "\t-c\tcopy the file, default\n" \ + "\t-d\tcreate directories\n" \ + "\t-g\tset group ownership\n" \ + "\t-m\tset permission modes\n" \ + "\t-o\tset ownership\n" \ + "\t-p\tpreserve date\n" \ + "\t-s\tstrip symbol tables" + + +#define install_initd_trivial_usage \ + "" +#define install_initd_full_usage \ + "LSB install_initd init system." +#define install_initd_example_usage \ + "$ install_initd start\n" + + +#define ip_trivial_usage \ + "[ OPTIONS ] { address | link | route | tunnel } { COMMAND | help }" +#define ip_full_usage \ + "ip [ OPTIONS ] OBJECT { COMMAND | help }\n" \ + "where OBJECT := { link | addr | route | tunnel }\n" \ + "OPTIONS := { -f[amily] { inet | inet6 | link } | -o[neline] }" + +#define ipaddr_trivial_usage \ + "{ {add|del} IFADDR dev STRING | {show|flush}\n" \ + "\t\t[ dev STRING ] [ to PREFIX ] }" +#define ipaddr_full_usage \ + "ipaddr {add|del} IFADDR dev STRING\n" \ + "ipaddr {show|flush} [ dev STRING ] [ scope SCOPE-ID ]\n" \ + "\t\t\t[ to PREFIX ] [ label PATTERN ]\n" \ + "\t\t\tIFADDR := PREFIX | ADDR peer PREFIX\n" \ + "\t\t\t[ broadcast ADDR ] [ anycast ADDR ]\n" \ + "\t\t\t[ label STRING ] [ scope SCOPE-ID ]\n" \ + "\t\t\tSCOPE-ID := [ host | link | global | NUMBER ]" + +#ifdef CONFIG_FEATURE_IPCALC_FANCY + #define XUSAGE_IPCALC_FANCY(a) a +#else + #define XUSAGE_IPCALC_FANCY(a) +#endif +#define ipcalc_trivial_usage \ + "[OPTION]...
[[/]] [NETMASK]" +#define ipcalc_full_usage \ + "Calculate IP network settings from a IP address\n\n" \ + "Options:\n" \ + "\t-b\t--broadcast\tDisplay calculated broadcast address.\n" \ + "\t-n\t--network\tDisplay calculated network address.\n" \ + "\t-m\t--netmask\tDisplay default netmask for IP." \ + XUSAGE_IPCALC_FANCY(\ + "\n\t-p\t--prefix\tDisplay the prefix for IP/NETMASK." \ + "\t-h\t--hostname\tDisplay first resolved host name.\n" \ + "\t-s\t--silent\tDon't ever display error messages.") + +#define iplink_trivial_usage \ + "{ set DEVICE { up | down | arp { on | off } | show [ DEVICE ] }" +#define iplink_full_usage \ + "iplink set DEVICE { up | down | arp { on | off } |\n" \ + "\t\t\tdynamic { on | off } |\n" \ + "\t\t\tmtu MTU }\n" \ + "\tiplink show [ DEVICE ]" + +#define iproute_trivial_usage \ + "{ list | flush | { add | del | change | append |\n" \ + "\t\treplace | monitor } ROUTE }" +#define iproute_full_usage \ + "iproute { list | flush } SELECTOR\n" \ + "iproute get ADDRESS [ from ADDRESS iif STRING ]\n" \ + "\t\t\t[ oif STRING ] [ tos TOS ]\n" \ + "\tiproute { add | del | change | append | replace | monitor } ROUTE\n" \ + "\t\t\tSELECTOR := [ root PREFIX ] [ match PREFIX ] [ proto RTPROTO ]\n" \ + "\t\t\tROUTE := [ TYPE ] PREFIX [ tos TOS ] [ proto RTPROTO ]" + +#define iptunnel_trivial_usage \ + "{ add | change | del | show } [ NAME ]\n" \ + "\t\t[ mode { ipip | gre | sit } ]\n" \ + "\t\t[ remote ADDR ] [ local ADDR ] [ ttl TTL ]" +#define iptunnel_full_usage \ + "iptunnel { add | change | del | show } [ NAME ]\n" \ + "\t\t\t[ mode { ipip | gre | sit } ] [ remote ADDR ] [ local ADDR ]\n" \ + "\t\t\t[ [i|o]seq ] [ [i|o]key KEY ] [ [i|o]csum ]\n" \ + "\t\t\t[ ttl TTL ] [ tos TOS ] [ [no]pmtudisc ] [ dev PHYS_DEV ]" + +#define kill_trivial_usage \ + "[-signal] process-id [process-id ...]" +#define kill_full_usage \ + "Send a signal (default is SIGTERM) to the specified process(es).\n\n"\ + "Options:\n" \ + "\t-l\tList all signal names and numbers." +#define kill_example_usage \ + "$ ps | grep apache\n" \ + "252 root root S [apache]\n" \ + "263 www-data www-data S [apache]\n" \ + "264 www-data www-data S [apache]\n" \ + "265 www-data www-data S [apache]\n" \ + "266 www-data www-data S [apache]\n" \ + "267 www-data www-data S [apache]\n" \ + "$ kill 252\n" + +#define killall_trivial_usage \ + "[-q] [-signal] process-name [process-name ...]" +#define killall_full_usage \ + "Send a signal (default is SIGTERM) to the specified process(es).\n\n"\ + "Options:\n" \ + "\t-l\tList all signal names and numbers.\n"\ + "\t-q\tDo not complain if no processes were killed." +#define killall_example_usage \ + "$ killall apache\n" + +#define killproc_trivial_usage \ + "" +#define killproc_full_usage \ + "LSB killproc." +#define killproc_example_usage \ + "$ killproc 5\n" + + +#define klogd_trivial_usage \ + "[-c n] [-n]" +#define klogd_full_usage \ + "Kernel logger.\n"\ + "Options:\n"\ + "\t-c n\tSets the default log level of console messages to n.\n"\ + "\t-n\tRun as a foreground process." + +#define length_trivial_usage \ + "STRING" +#define length_full_usage \ + "Prints out the length of the specified STRING." +#define length_example_usage \ + "$ length Hello\n" \ + "5\n" + +#define linuxrc_trivial_usage \ + "" +#define linuxrc_full_usage \ + "linuxrc pre boot." +#define linuxrc_example_usage \ + "$ linuxrc\n" + + +#define ln_trivial_usage \ + "[OPTION] TARGET... LINK_NAME|DIRECTORY" +#define ln_full_usage \ + "Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n"\ + "\nYou may use '--' to indicate that all following arguments are non-options.\n\n" \ + "Options:\n" \ + "\t-s\tmake symbolic links instead of hard links\n" \ + "\t-f\tremove existing destination files\n" \ + "\t-n\tno dereference symlinks - treat like normal file" +#define ln_example_usage \ + "$ ln -s BusyBox /tmp/ls\n" \ + "$ ls -l /tmp/ls\n" \ + "lrwxrwxrwx 1 root root 7 Apr 12 18:39 ls -> BusyBox*\n" + +#define loadfont_trivial_usage \ + "< font" +#define loadfont_full_usage \ + "Loads a console font from standard input." +#define loadfont_example_usage \ + "$ loadfont < /etc/i18n/fontname\n" + +#define loadkmap_trivial_usage \ + "< keymap" +#define loadkmap_full_usage \ + "Loads a binary keyboard translation table from standard input." +#define loadkmap_example_usage \ + "$ loadkmap < /etc/i18n/lang-keymap\n" + +#define local_fs_trivial_usage \ + "" +#define local_fs_full_usage \ + "LSB local_fs init system." +#define local_fs_example_usage \ + "$ local_fs start\n" + + +#define log_failure_msg_trivial_usage \ + "" +#define log_failure_msg_full_usage \ + "LSB log_failure_msg." +#define log_failure_msg_example_usage \ + "$ log_failure_msg ""\n" + + +#define log_success_msg_trivial_usage \ + "" +#define log_success_msg_full_usage \ + "LSB log_success_msg." +#define log_success_msg_example_usage \ + "$ log_success_msg ""\n" + + +#define log_warning_msg_trivial_usage \ + "" +#define log_warning_msg_full_usage \ + "LSB log_warning_msg." +#define log_warning_msg_example_usage \ + "$ log_warning_msg ""\n" + + +#define logger_trivial_usage \ + "[OPTION]... [MESSAGE]" +#define logger_full_usage \ + "Write MESSAGE to the system log. If MESSAGE is omitted, log stdin.\n\n" \ + "Options:\n" \ + "\t-s\tLog to stderr as well as the system log.\n" \ + "\t-t TAG\tLog using the specified tag (defaults to user name).\n" \ + "\t-p PRIORITY\tEnter the message with the specified priority.\n" \ + "\t\tThis may be numerical or a ``facility.level'' pair." +#define logger_example_usage \ + "$ logger "hello"\n" + +#define login_trivial_usage \ + "[OPTION]... [username] [ENV=VAR ...]" +#define login_full_usage \ + "Begin a new session on the system\n\n" \ + "Options:\n" \ + "\t-f\tDo not authenticate (user already authenticated)\n" \ + "\t-h\tName of the remote host for this login.\n" \ + "\t-p\tPreserve environment." + +#define logname_trivial_usage \ + "" +#define logname_full_usage \ + "Print the name of the current user." +#define logname_example_usage \ + "$ logname\n" \ + "root\n" + +#define logread_trivial_usage \ + "[OPTION]..." +#define logread_full_usage \ + "Shows the messages from syslogd (using circular buffer).\n\n" \ + "Options:\n" \ + "\t-f\t\toutput data as the log grows" + +#define losetup_trivial_usage \ + "[OPTION]... LOOPDEVICE FILE\n" \ + "or: losetup [OPTION]... -d LOOPDEVICE" +#define losetup_full_usage \ + "Associate LOOPDEVICE with FILE.\n\n" \ + "Options:\n" \ + "\t-d\t\tDisassociate LOOPDEVICE.\n" \ + "\t-o OFFSET\tStart OFFSET bytes into FILE." + +#ifdef CONFIG_FEATURE_LS_TIMESTAMPS + #define USAGE_LS_TIMESTAMPS(a) a +#else + #define USAGE_LS_TIMESTAMPS(a) +#endif +#ifdef CONFIG_FEATURE_LS_FILETYPES + #define USAGE_LS_FILETYPES(a) a +#else + #define USAGE_LS_FILETYPES(a) +#endif +#ifdef CONFIG_FEATURE_LS_FOLLOWLINKS + #define USAGE_LS_FOLLOWLINKS(a) a +#else + #define USAGE_LS_FOLLOWLINKS(a) +#endif +#ifdef CONFIG_FEATURE_LS_RECURSIVE + #define USAGE_LS_RECURSIVE(a) a +#else + #define USAGE_LS_RECURSIVE(a) +#endif +#ifdef CONFIG_FEATURE_LS_SORTFILES + #define USAGE_LS_SORTFILES(a) a +#else + #define USAGE_LS_SORTFILES(a) +#endif +#ifdef CONFIG_FEATURE_AUTOWIDTH + #define USAGE_AUTOWIDTH(a) a +#else + #define USAGE_AUTOWIDTH(a) +#endif + +#define ls_trivial_usage \ + "[-1Aa" USAGE_LS_TIMESTAMPS("c") "Cd" USAGE_LS_TIMESTAMPS("e") USAGE_LS_FILETYPES("F") "iln" USAGE_LS_FILETYPES("p") USAGE_LS_FOLLOWLINKS("L") USAGE_LS_RECURSIVE("R") USAGE_LS_SORTFILES("rS") "s" USAGE_AUTOWIDTH("T") USAGE_LS_TIMESTAMPS("tu") USAGE_LS_SORTFILES("v") USAGE_AUTOWIDTH("w") "x" USAGE_LS_SORTFILES("X") USAGE_HUMAN_READABLE("h") USAGE_NOT_HUMAN_READABLE("") "k" USAGE_SELINUX("K") "] [filenames...]" +#define ls_full_usage \ + "List directory contents\n\n" \ + "Options:\n" \ + "\t-1\tlist files in a single column\n" \ + "\t-A\tdo not list implied . and ..\n" \ + "\t-a\tdo not hide entries starting with .\n" \ + "\t-C\tlist entries by columns\n" \ + USAGE_LS_TIMESTAMPS("\t-c\twith -l: show ctime\n") \ + "\t-d\tlist directory entries instead of contents\n" \ + USAGE_LS_TIMESTAMPS("\t-e\tlist both full date and full time\n") \ + USAGE_LS_FILETYPES("\t-F\tappend indicator (one of */=@|) to entries\n") \ + "\t-i\tlist the i-node for each file\n" \ + "\t-l\tuse a long listing format\n" \ + "\t-n\tlist numeric UIDs and GIDs instead of names\n" \ + USAGE_LS_FILETYPES("\t-p\tappend indicator (one of /=@|) to entries\n") \ + USAGE_LS_FOLLOWLINKS("\t-L\tlist entries pointed to by symbolic links\n") \ + USAGE_LS_RECURSIVE("\t-R\tlist subdirectories recursively\n") \ + USAGE_LS_SORTFILES("\t-r\tsort the listing in reverse order\n") \ + USAGE_LS_SORTFILES("\t-S\tsort the listing by file size\n") \ + "\t-s\tlist the size of each file, in blocks\n" \ + USAGE_AUTOWIDTH("\t-T NUM\tassume Tabstop every NUM columns\n") \ + USAGE_LS_TIMESTAMPS("\t-t\twith -l: show modification time\n") \ + USAGE_LS_TIMESTAMPS("\t-u\twith -l: show access time\n") \ + USAGE_LS_SORTFILES("\t-v\tsort the listing by version\n") \ + USAGE_AUTOWIDTH("\t-w NUM\tassume the terminal is NUM columns wide\n") \ + "\t-x\tlist entries by lines instead of by columns\n" \ + USAGE_LS_SORTFILES("\t-X\tsort the listing by extension\n") \ + USAGE_HUMAN_READABLE( \ + "\t-h\tprint sizes in human readable format (e.g., 1K 243M 2G )\n") \ + USAGE_SELINUX("\t-k\tprint security context\n") \ + USAGE_SELINUX("\t-K\tprint security context in long format\n") + +#define lsmod_trivial_usage \ + "" +#define lsmod_full_usage \ + "List the currently loaded kernel modules." + +#define makedevs_trivial_usage \ + "NAME TYPE MAJOR MINOR FIRST LAST [s]" +#define makedevs_full_usage \ + "Creates a range of block or character special files\n\n" \ + "TYPEs include:\n" \ + "\tb:\tMake a block (buffered) device.\n" \ + "\tc or u:\tMake a character (un-buffered) device.\n" \ + "\tp:\tMake a named pipe. MAJOR and MINOR are ignored for named pipes.\n\n" \ + "FIRST specifies the number appended to NAME to create the first device.\n" \ + "LAST specifies the number of the last item that should be created.\n" \ + "If 's' is the last argument, the base device is created as well.\n\n" \ + "For example:\n" \ + "\tmakedevs /dev/ttyS c 4 66 2 63 -> ttyS2-ttyS63\n" \ + "\tmakedevs /dev/hda b 3 0 0 8 s -> hda,hda1-hda8" +#define makedevs_example_usage \ + "# makedevs /dev/ttyS c 4 66 2 63\n" \ + "[creates ttyS2-ttyS63]\n" \ + "# makedevs /dev/hda b 3 0 0 8 s\n" \ + "[creates hda,hda1-hda8]\n" + +#define man_trivial_usage \ + "[NAME]" +#define man_full_usage \ + "Show documentation for Trinux software." +#define man_example_usage \ + "$ man basics\n" + + +#ifdef CONFIG_FEATURE_MD5_SHA1_SUM_CHECK +#define USAGE_MD5_SHA1_SUM_CHECK(a) a +#else +#define USAGE_MD5_SHA1_SUM_CHECK(a) +#endif + +#define md5sum_trivial_usage \ + "[OPTION] [FILEs...]" \ + USAGE_MD5_SHA1_SUM_CHECK("\n or: md5sum [OPTION] -c [FILE]") +#define md5sum_full_usage \ + "Print" USAGE_MD5_SHA1_SUM_CHECK(" or check") " MD5 checksums.\n\n" \ + "Options:\n" \ + "With no FILE, or when FILE is -, read standard input." \ + USAGE_MD5_SHA1_SUM_CHECK("\n\n" \ + "\t-c\tcheck MD5 sums against given list\n" \ + "\nThe following two options are useful only when verifying checksums:\n" \ + "\t-s\tdon't output anything, status code shows success\n" \ + "\t-w\twarn about improperly formated MD5 checksum lines") +#define md5sum_example_usage \ + "$ md5sum < busybox\n" \ + "6fd11e98b98a58f64ff3398d7b324003\n" \ + "$ md5sum busybox\n" \ + "6fd11e98b98a58f64ff3398d7b324003 busybox\n" \ + "$ md5sum -c -\n" \ + "6fd11e98b98a58f64ff3398d7b324003 busybox\n" \ + "busybox: OK\n" \ + "^D\n" + +#define mesg_trivial_usage \ + "[y|n]" +#define mesg_full_usage \ + "mesg controls write access to your terminal\n" \ + "\ty\tAllow write access to your terminal.\n" \ + "\tn\tDisallow write access to your terminal.\n" + +#define mkdir_trivial_usage \ + "[OPTION] DIRECTORY..." +#define mkdir_full_usage \ + "Create the DIRECTORY(ies) if they do not already exist\n\n" \ + "Options:\n" \ + "\t-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n" \ + "\t-p\tno error if existing, make parent directories as needed" +#define mkdir_example_usage \ + "$ mkdir /tmp/foo\n" \ + "$ mkdir /tmp/foo\n" \ + "/tmp/foo: File exists\n" \ + "$ mkdir /tmp/foo/bar/baz\n" \ + "/tmp/foo/bar/baz: No such file or directory\n" \ + "$ mkdir -p /tmp/foo/bar/baz\n" + +#define mkfifo_trivial_usage \ + "[OPTIONS] name" +#define mkfifo_full_usage \ + "Creates a named pipe (identical to 'mknod name p')\n\n" \ + "Options:\n" \ + "\t-m\tcreate the pipe using the specified mode (default a=rw)" + +#define mkfs_minix_trivial_usage \ + "[-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]" +#define mkfs_minix_full_usage \ + "Make a MINIX filesystem.\n\n" \ + "Options:\n" \ + "\t-c\t\tCheck the device for bad blocks\n" \ + "\t-n [14|30]\tSpecify the maximum length of filenames\n" \ + "\t-i INODES\tSpecify the number of inodes for the filesystem\n" \ + "\t-l FILENAME\tRead the bad blocks list from FILENAME\n" \ + "\t-v\t\tMake a Minix version 2 filesystem" + +#define mknod_trivial_usage \ + "[OPTIONS] NAME TYPE MAJOR MINOR" +#define mknod_full_usage \ + "Create a special file (block, character, or pipe).\n\n" \ + "Options:\n" \ + "\t-m\tcreate the special file using the specified mode (default a=rw)\n\n" \ + "TYPEs include:\n" \ + "\tb:\tMake a block (buffered) device.\n" \ + "\tc or u:\tMake a character (un-buffered) device.\n" \ + "\tp:\tMake a named pipe. MAJOR and MINOR are ignored for named pipes." +#define mknod_example_usage \ + "$ mknod /dev/fd0 b 2 0\n" \ + "$ mknod -m 644 /tmp/pipe p\n" + +#define mkswap_trivial_usage \ + "[-c] [-v0|-v1] device [block-count]" +#define mkswap_full_usage \ + "Prepare a disk partition to be used as a swap partition.\n\n" \ + "Options:\n" \ + "\t-c\t\tCheck for read-ability.\n" \ + "\t-v0\t\tMake version 0 swap [max 128 Megs].\n" \ + "\t-v1\t\tMake version 1 swap [big!] (default for kernels >\n\t\t\t2.1.117).\n" \ + "\tblock-count\tNumber of block to use (default is entire partition)." + +#define mktemp_trivial_usage \ + "[-dq] TEMPLATE" +#define mktemp_full_usage \ + "Creates a temporary file with its name based on TEMPLATE.\n" \ + "TEMPLATE is any name with six `Xs' (i.e., /tmp/temp.XXXXXX).\n\n" \ + "Options:\n" \ + "\t-d\t\tMake a directory instead of a file\n" \ + "\t-q\t\tFail silently if an error occurs" +#define mktemp_example_usage \ + "$ mktemp /tmp/temp.XXXXXX\n" \ + "/tmp/temp.mWiLjM\n" \ + "$ ls -la /tmp/temp.mWiLjM\n" \ + "-rw------- 1 andersen andersen 0 Apr 25 17:10 /tmp/temp.mWiLjM\n" + +#define modprobe_trivial_usage \ + "[-knqrsv] [MODULE ...]" +#define modprobe_full_usage \ + "Used for high level module loading and unloading.\n\n" \ + "Options:\n" \ + "\t-k\tMake module autoclean-able.\n" \ + "\t-n\tJust show what would be done.\n" \ + "\t-q\tQuiet output.\n" \ + "\t-r\tRemove module (stacks) or do autoclean.\n" \ + "\t-s\tReport via syslog instead of stderr.\n" \ + "\t-v\tVerbose output." +#define modprobe_example_usage \ + "$ modprobe cdrom\n" + +#define more_trivial_usage \ + "[FILE ...]" +#define more_full_usage \ + "More is a filter for viewing FILE one screenful at a time." +#define more_example_usage \ + "$ dmesg | more\n" + +#ifdef CONFIG_FEATURE_MOUNT_LOOP + #define USAGE_MOUNT_LOOP(a) a +#else + #define USAGE_MOUNT_LOOP(a) +#endif +#ifdef CONFIG_FEATURE_MTAB_SUPPORT + #define USAGE_MTAB(a) a +#else + #define USAGE_MTAB(a) +#endif +#define mount_trivial_usage \ + "[flags] DEVICE NODE [-o options,more-options]" +#define mount_full_usage \ + "Mount a filesystem. Autodetection of filesystem type requires the\n" \ + "/proc filesystem be already mounted.\n\n" \ + "Flags:\n" \ + "\t-a:\t\tMount all filesystems in fstab.\n" \ + USAGE_MTAB( \ + "\t-f:\t\t\"Fake\" Add entry to mount table but don't mount it.\n" \ + "\t-n:\t\tDon't write a mount table entry.\n" \ + ) \ + "\t-o option:\tOne of many filesystem options, listed below.\n" \ + "\t-r:\t\tMount the filesystem read-only.\n" \ + "\t-t fs-type:\tSpecify the filesystem type.\n" \ + "\t-w:\t\tMount for reading and writing (default).\n" \ + "\n" \ + "Options for use with the \"-o\" flag:\n" \ + "\tasync/sync:\tWrites are asynchronous / synchronous.\n" \ + "\tatime/noatime:\tEnable / disable updates to inode access times.\n" \ + "\tdev/nodev:\tAllow use of special device files / disallow them.\n" \ + "\texec/noexec:\tAllow use of executable files / disallow them.\n" \ + USAGE_MOUNT_LOOP( \ + "\tloop:\t\tMounts a file via loop device.\n" \ + ) \ + "\tsuid/nosuid:\tAllow set-user-id-root programs / disallow them.\n" \ + "\tremount:\tRe-mount a mounted filesystem, changing its flags.\n" \ + "\tro/rw:\t\tMount for read-only / read-write.\n" \ + "\tbind:\t\tUse the linux 2.4.x \"bind\" feature.\n" \ + "\nThere are EVEN MORE flags that are specific to each filesystem.\n" \ + "You'll have to see the written documentation for those filesystems." +#define mount_example_usage \ + "$ mount\n" \ + "/dev/hda3 on / type minix (rw)\n" \ + "proc on /proc type proc (rw)\n" \ + "devpts on /dev/pts type devpts (rw)\n" \ + "$ mount /dev/fd0 /mnt -t msdos -o ro\n" \ + "$ mount /tmp/diskimage /opt -t ext2 -o loop\n" + +#define mt_trivial_usage \ + "[-f device] opcode value" +#define mt_full_usage \ + "Control magnetic tape drive operation\n" \ + "\nAvailable Opcodes:\n\n" \ + "bsf bsfm bsr bss datacompression drvbuffer eof eom erase\n" \ + "fsf fsfm fsr fss load lock mkpart nop offline ras1 ras2\n" \ + "ras3 reset retension rewind rewoffline seek setblk setdensity\n" \ + "setpart tell unload unlock weof wset" + +#define mv_trivial_usage \ + "[OPTION]... SOURCE DEST\n" \ + "or: mv [OPTION]... SOURCE... DIRECTORY" +#define mv_full_usage \ + "Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n\n" \ + "Options:\n" \ + "\t-f\tdon't prompt before overwriting\n" \ + "\t-i\tinteractive, prompt before overwrite" +#define mv_example_usage \ + "$ mv /tmp/foo /bin/bar\n" + +#define nameif_trivial_usage \ + "[-s] [-c FILE] [{IFNAME MACADDR}]" +#define nameif_full_usage \ + "Nameif renaming network interface while it in the down state.\n\n" \ + "Options:\n" \ + "\t-c FILE\t\tUse configuration file (default is /etc/mactab)\n" \ + "\t-s\t\tUse syslog (LOCAL0 facility).\n" \ + "\tIFNAME MACADDR\tnew_interface_name interface_mac_address" +#define nameif_example_usage \ + "$ nameif -s dmz0 00:A0:C9:8C:F6:3F\n" \ + " or\n" \ + "$ nameif -c /etc/my_mactab_file\n" \ + +#define nc_trivial_usage \ + "[OPTIONS] [IP] [port]" +#define nc_full_usage \ + "Netcat opens a pipe to IP:port\n\n" \ + "Options:\n" \ + "\t-l\t\tlisten mode, for inbound connects\n" \ + "\t-p PORT\t\tlocal port number\n" \ + "\t-i SECS\t\tdelay interval for lines sent\n" \ + "\t-e PROG\t\tprogram to exec after connect (dangerous!)" +#define nc_example_usage \ + "$ nc foobar.somedomain.com 25\n" \ + "220 foobar ESMTP Exim 3.12 #1 Sat, 15 Apr 2000 00:03:02 -0600\n" \ + "help\n" \ + "214-Commands supported:\n" \ + "214- HELO EHLO MAIL RCPT DATA AUTH\n" \ + "214 NOOP QUIT RSET HELP\n" \ + "quit\n" \ + "221 foobar closing connection\n" + +#define netstat_trivial_usage \ + "[-laenrtuwx]" +#define netstat_full_usage \ + "Netstat displays Linux networking information.\n\n" \ + "Options:\n" \ + "\t-l display listening server sockets\n" \ + "\t-a display all sockets (default: connected)\n" \ + "\t-e display other/more information\n" \ + "\t-n don't resolve names\n" \ + "\t-r display routing table\n" \ + "\t-t tcp sockets\n" \ + "\t-u udp sockets\n" \ + "\t-w raw sockets\n" \ + "\t-x unix sockets" + + +#define network_trivial_usage \ + "" +#define network_full_usage \ + "LSB network init system." +#define network_example_usage \ + "$ network start\n" + + +#define nslookup_trivial_usage \ + "[HOST] [SERVER]" +#define nslookup_full_usage \ + "Queries the nameserver for the IP address of the given HOST\n" \ + "optionally using a specified DNS server" +#define nslookup_example_usage \ + "$ nslookup localhost\n" \ + "Server: default\n" \ + "Address: default\n" \ + "\n" \ + "Name: debian\n" \ + "Address: 127.0.0.1\n" + +#define od_trivial_usage \ + "[-aBbcDdeFfHhIiLlOovXx] [FILE]" +#define od_full_usage \ + "Write an unambiguous representation, octal bytes by default, of FILE\n"\ + "to standard output. With no FILE, or when FILE is -, read standard input." + +#define openvt_trivial_usage \ + " [ARGS...]" +#define openvt_full_usage \ + "Start a command on a new virtual terminal" +#define openvt_example_usage \ + "openvt 2 /bin/ash\n" + +#ifdef CONFIG_FEATURE_SHA1_PASSWORDS + #define PASSWORD_ALG_TYPES(a) a +#else + #define PASSWORD_ALG_TYPES(a) +#endif +#define passwd_trivial_usage \ + "[OPTION] [name]" +#define passwd_full_usage \ + "Change a user password. If no name is specified,\n" \ + "changes the password for the current user.\n" \ + "Options:\n" \ + "\t-a\tDefine which algorithm shall be used for the password.\n" \ + "\t\t\t(Choices: des, md5" \ + PASSWORD_ALG_TYPES(", sha1") \ + ")\n\t-d\tDelete the password for the specified user account.\n" \ + "\t-l\tLocks (disables) the specified user account.\n" \ + "\t-u\tUnlocks (re-enables) the specified user account." + +#define patch_trivial_usage \ + "[-p]" +#define patch_full_usage \ + "[-p]" +#define patch_example_usage \ + "$ patch -p1 ]" +#define poweroff_full_usage \ + "Halt the system and request that the kernel shut off the power.\n" \ + "Options:\n" \ + "\t-d\t\tdelay interval for shutting off." + +#define printf_trivial_usage \ + "FORMAT [ARGUMENT...]" +#define printf_full_usage \ + "Formats and prints ARGUMENT(s) according to FORMAT,\n" \ + "Where FORMAT controls the output exactly as in C printf." +#define printf_example_usage \ + "$ printf "Val=%d\\n" 5\n" \ + "Val=5\n" + +#ifdef CONFIG_SELINUX +#define USAGE_NONSELINUX(a) +#else +#define USAGE_NONSELINUX(a) a +#endif + +#define ps_trivial_usage \ + "" +#define ps_full_usage \ + "Report process status\n" \ + USAGE_NONSELINUX("\n\tThis version of ps accepts no options.") \ + USAGE_SELINUX("\nOptions:\n\t-c\tshow SE Linux context") + +#define ps_example_usage \ + "$ ps\n" \ + " PID Uid Gid State Command\n" \ + " 1 root root S init\n" \ + " 2 root root S [kflushd]\n" \ + " 3 root root S [kupdate]\n" \ + " 4 root root S [kpiod]\n" \ + " 5 root root S [kswapd]\n" \ + " 742 andersen andersen S [bash]\n" \ + " 743 andersen andersen S -bash\n" \ + " 745 root root S [getty]\n" \ + " 2990 andersen andersen R ps\n" + +#define pwd_trivial_usage \ + "" +#define pwd_full_usage \ + "Print the full filename of the current working directory." +#define pwd_example_usage \ + "$ pwd\n" \ + "/root\n" + +#define rc_trivial_usage \ + "" +#define rc_full_usage \ + "LSB rc init system." +#define rc_example_usage \ + "$ rc 5\n" + + +#define rcS_trivial_usage \ + "" +#define rcS_full_usage \ + "sysinit for inittab." +#define rcS_example_usage \ + "$ rcS\n" + + +#define rdate_trivial_usage \ + "[-sp] HOST" +#define rdate_full_usage \ + "Get and possibly set the system date and time from a remote HOST.\n\n" \ + "Options:\n" \ + "\t-s\tSet the system date and time (default).\n" \ + "\t-p\tPrint the date and time." + +#define readlink_trivial_usage \ + "" +#define readlink_full_usage \ + "Displays the value of a symbolic link." + +#define realpath_trivial_usage \ + "pathname ..." +#define realpath_full_usage \ + "Returns the absolute pathnames of given argument." + +#define reboot_trivial_usage \ + "[-d]" +#define reboot_full_usage \ + "Reboot the system.\n" \ + "Options:\n" \ + "\t-d\t\tdelay interval for rebooting." + +#define remote_fs_trivial_usage \ + "" +#define remote_fs_full_usage \ + "LSB remote_fs init system." +#define remote_fs_example_usage \ + "$ remote_fs start\n" + + +#define remove_initd_trivial_usage \ + "" +#define remove_initd_full_usage \ + "LSB remove_initd init system." +#define remove_initd_example_usage \ + "$ remove_initd start\n" + + +#define renice_trivial_usage \ + "priority pid [pid ...]" +#define renice_full_usage \ + "Changes priority of running processes. Allowed priorities range\n" \ + "from 20 (the process runs only when nothing else is running) to 0\n" \ + "(default priority) to -20 (almost nothing else ever gets to run)." + +#define reset_trivial_usage \ + "" +#define reset_full_usage \ + "Resets the screen." + +#define rm_trivial_usage \ + "[OPTION]... FILE..." +#define rm_full_usage \ + "Remove (unlink) the FILE(s). You may use '--' to\n" \ + "indicate that all following arguments are non-options.\n\n" \ + "Options:\n" \ + "\t-i\t\talways prompt before removing each destination\n" \ + "\t-f\t\tremove existing destinations, never prompt\n" \ + "\t-r or -R\tremove the contents of directories recursively" +#define rm_example_usage \ + "$ rm -rf /tmp/foo\n" + +#define rmdir_trivial_usage \ + "[OPTION]... DIRECTORY..." +#define rmdir_full_usage \ + "Remove the DIRECTORY(ies), if they are empty." +#define rmdir_example_usage \ + "# rmdir /tmp/foo\n" + +#define rmmod_trivial_usage \ + "[OPTION]... [MODULE]..." +#define rmmod_full_usage \ + "Unloads the specified kernel modules from the kernel.\n\n" \ + "Options:\n" \ + "\t-a\tRemove all unused modules (recursively)" +#define rmmod_example_usage \ + "$ rmmod tulip\n" + +#ifdef CONFIG_FEATURE_IPV6 + #define USAGE_ROUTE_IPV6(a) a +#else + #define USAGE_ROUTE_IPV6(a) "\t" +#endif + + +#define route_trivial_usage \ + "[{add|del|delete}]" +#define route_full_usage \ + "Edit the kernel's routing tables.\n\n" \ + "Options:\n" \ + "\t-n\t\tDont resolve names.\n" \ + "\t-e\t\tDisplay other/more information.\n" \ + "\t-A inet" USAGE_ROUTE_IPV6("{6}") "\tSelect address family." + +#define rpm_trivial_usage \ + "-i -q[ildc]p package.rpm" +#define rpm_full_usage \ + "Manipulates RPM packages" \ + "\n\nOptions:" \ + "\n\t-i Install package" \ + "\n\t-q Query package" \ + "\n\t-p Query uninstalled package" \ + "\n\t-i Show information" \ + "\n\t-l List contents" \ + "\n\t-d List documents" \ + "\n\t-c List config files" + +#define rpm2cpio_trivial_usage \ + "package.rpm" +#define rpm2cpio_full_usage \ + "Outputs a cpio archive of the rpm file." + +#define run_parts_trivial_usage \ + "[-t] [-a ARG] [-u MASK] DIRECTORY" +#define run_parts_full_usage \ + "Run a bunch of scripts in a directory.\n\n" \ + "Options:\n" \ + "\t-t\tPrints what would be run, but does not actually run anything.\n" \ + "\t-a ARG\tPass ARG as an argument for every program invoked.\n" \ + "\t-u MASK\tSet the umask to MASK before executing every program." + +#define rx_trivial_usage \ + "FILE" +#define rx_full_usage \ + "Receive a file using the xmodem protocol." +#define rx_example_usage \ + "$ rx /tmp/foo\n" + +#define sed_trivial_usage \ + "[-efinr] pattern [files...]" +#define sed_full_usage \ + "Options:\n" \ + "\t-e script\tadd the script to the commands to be executed\n" \ + "\t-f scriptfile\tadd script-file contents to the\n" \ + "\t\t\tcommands to be executed\n" \ + "\t-i\t\tedit files in-place\n" \ + "\t-n\t\tsuppress automatic printing of pattern space\n" \ + "\t-r\t\tuse extended regular expression syntax\n" \ + "\n" \ + "If no -e or -f is given, the first non-option argument is taken as the sed\n"\ + "script to interpret. All remaining arguments are names of input files; if no\n"\ + "input files are specified, then the standard input is read. Source files\n" \ + "will not be modified unless -i option is given." + +#define sed_example_usage \ + "$ echo "foo" | sed -e 's/f[a-zA-Z]o/bar/g'\n" \ + "bar\n" + +#define seq_trivial_usage \ + "[first [increment]] last" +#define seq_full_usage \ + "Print numbers from FIRST to LAST, in steps of INCREMENT.\n" \ + "FIRST, INCREMENT default to 1\n" \ + "Arguments:\n" \ + "\tLAST\n" \ + "\tFIRST\tLAST\n" \ + "\tFIRST\tINCREMENT\tLAST" + +#define setkeycodes_trivial_usage \ + "SCANCODE KEYCODE ..." +#define setkeycodes_full_usage \ + "Set entries into the kernel's scancode-to-keycode map,\n" \ + "allowing unusual keyboards to generate usable keycodes.\n\n" \ + "SCANCODE may be either xx or e0xx (hexadecimal),\n" \ + "and KEYCODE is given in decimal" +#define setkeycodes_example_usage \ + "$ setkeycodes e030 127\n" + +#define lash_trivial_usage \ + "[FILE]...\n" \ + "or: sh -c command [args]..." +#define lash_full_usage \ + "The BusyBox LAme SHell (command interpreter)" +#define lash_notes_usage \ + "This command does not yet have proper documentation.\n\n" \ + "Use lash just as you would use any other shell. It properly handles pipes,\n" \ + "redirects, job control, can be used as the shell for scripts, and has a\n" \ + "sufficient set of builtins to do what is needed. It does not (yet) support\n" \ + "Bourne Shell syntax. If you need things like "if-then-else", "while", and such\n" \ + "use ash or bash. If you just need a very simple and extremely small shell,\n" \ + "this will do the job." + +#define last_trivial_usage \ + "" +#define last_full_usage \ + "Shows listing of the last users that logged into the system" + +#define sha1sum_trivial_usage \ + "[OPTION] [FILEs...]" \ + USAGE_MD5_SHA1_SUM_CHECK("\n or: sha1sum [OPTION] -c [FILE]") +#define sha1sum_full_usage \ + "Print" USAGE_MD5_SHA1_SUM_CHECK(" or check") " SHA1 checksums.\n\n" \ + "Options:\n" \ + "With no FILE, or when FILE is -, read standard input." \ + USAGE_MD5_SHA1_SUM_CHECK("\n\n" \ + "\t-c\tcheck SHA1 sums against given list\n" \ + "\nThe following two options are useful only when verifying checksums:\n" \ + "\t-s\tdon't output anything, status code shows success\n" \ + "\t-w\twarn about improperly formated SHA1 checksum lines") + +#ifdef CONFIG_FEATURE_FANCY_SLEEP + #define USAGE_FANCY_SLEEP(a) a + #define USAGE_NOT_FANCY_SLEEP(a) +#else + #define USAGE_FANCY_SLEEP(a) + #define USAGE_NOT_FANCY_SLEEP(a) a +#endif + +#define sleep_trivial_usage \ + USAGE_FANCY_SLEEP("[") "N" USAGE_FANCY_SLEEP("]...") +#define sleep_full_usage \ + USAGE_NOT_FANCY_SLEEP("Pause for N seconds.") \ + USAGE_FANCY_SLEEP( \ + "Pause for a time equal to the total of the args given, where each arg can\n" \ + "\t\thave an optional suffix of (s)econds, (m)inutes, (h)ours, or (d)ays.") +#define sleep_example_usage \ + "$ sleep 2\n" \ + "[2 second delay results]\n" \ + USAGE_FANCY_SLEEP("$ sleep 1d 3h 22m 8s\n" \ + "[98528 second delay results]\n") + +#ifdef CONFIG_FEATURE_SORT_UNIQUE + #define USAGE_SORT_UNIQUE(a) a +#else + #define USAGE_SORT_UNIQUE(a) +#endif +#ifdef CONFIG_FEATURE_SORT_REVERSE + #define USAGE_SORT_REVERSE(a) a +#else + #define USAGE_SORT_REVERSE(a) +#endif +#define sort_trivial_usage \ + "[-n" USAGE_SORT_REVERSE("r") USAGE_SORT_UNIQUE("u") "] [FILE]..." +#define sort_full_usage \ + "Sorts lines of text in the specified files\n\n"\ + "Options:\n" \ + USAGE_SORT_UNIQUE("\t-u\tsuppress duplicate lines\n") \ + USAGE_SORT_REVERSE("\t-r\tsort in reverse order\n") \ + "\t-n\tsort numerics" +#define sort_example_usage \ + "$ echo -e \"e\\nf\\nb\\nd\\nc\\na\" | sort\n" \ + "a\n" \ + "b\n" \ + "c\n" \ + "d\n" \ + "e\n" \ + "f\n" + +#define start_daemon_trivial_usage \ + "" +#define start_daemon_full_usage \ + "LSB start_daemon." +#define start_daemon_example_usage \ + "$ start_daemon 5\n" + + +#define start_stop_daemon_trivial_usage \ + "[OPTIONS] [--start|--stop] ... [-- arguments...]\n" +#define start_stop_daemon_full_usage \ + "Program to start and stop services."\ + "\n\nOptions:"\ + "\n\t-S|--start\t\t\tstart"\ + "\n\t-K|--stop\t\t\tstop"\ + "\n\t-a|--startas \t\tstarts process specified by pathname"\ + "\n\t-b|--background\t\t\tforce process into background"\ + "\n\t-u|--user |\tstop this user's processes"\ + "\n\t-x|--exec \t\tprogram to either start or check"\ + "\n\t-m|--make-pidfile \tcreate the -p file and enter pid in it"\ + "\n\t-n|--name \tstop processes with this name"\ + "\n\t-p|--pidfile \t\tsave or load pid using a pid-file"\ + "\n\t-q|--quiet\t\t\tbe quiet" \ + "\n\t-s|--signal \t\tsignal to send (default TERM)" + +#define strings_trivial_usage \ + "[-afo] [-n length] [file ... ]" +#define strings_full_usage \ + "Display printable strings in a binary file." \ + "\n\nOptions:" \ + "\n\t-a\tScan the whole files (this is the default)."\ + "\n\t-f\tPrecede each string with the name of the file where it was found." \ + "\n\t-n N\tSpecifies that at least N characters forms a sequence (default 4)" \ + "\n\t-o\tEach string is preceded by its decimal offset in the file." + +#define stty_trivial_usage \ + "[-a|g] [-F DEVICE] [SETTING]..." +#define stty_full_usage \ + "Without arguments, prints baud rate, line discipline," \ + "\nand deviations from stty sane." \ + "\n\nOptions:" \ + "\n\t-F DEVICE\topen device instead of stdin" \ + "\n\t-a\t\tprint all current settings in human-readable form" \ + "\n\t-g\t\tprint in stty-readable form" \ + "\n\t[SETTING]\tsee manpage" + +#define su_trivial_usage \ + "[OPTION]... [-] [username]" +#define su_full_usage \ + "Change user id or become root.\n" \ + "Options:\n" \ + "\t-p\tPreserve environment" + +#define sulogin_trivial_usage \ + "[OPTION]... [tty-device]" +#define sulogin_full_usage \ + "Single user login\n" \ + "Options:\n" \ + "\t-f\tDo not authenticate (user already authenticated)\n" \ + "\t-h\tName of the remote host for this login.\n" \ + "\t-p\tPreserve environment." + +#define swapoff_trivial_usage \ + "[OPTION] [DEVICE]" +#define swapoff_full_usage \ + "Stop swapping virtual memory pages on DEVICE.\n\n" \ + "Options:\n" \ + "\t-a\tStop swapping on all swap devices" + +#define swapon_trivial_usage \ + "[OPTION] [DEVICE]" +#define swapon_full_usage \ + "Start swapping virtual memory pages on DEVICE.\n\n" \ + "Options:\n" \ + "\t-a\tStart swapping on all swap devices" + +#define sync_trivial_usage \ + "" +#define sync_full_usage \ + "Write all buffered filesystem blocks to disk." + + +#ifdef CONFIG_FEATURE_ROTATE_LOGFILE + #define USAGE_ROTATE_LOGFILE(a) a +#else + #define USAGE_ROTATE_LOGFILE(a) +#endif +#ifdef CONFIG_FEATURE_REMOTE_LOG + #define USAGE_REMOTE_LOG(a) a +#else + #define USAGE_REMOTE_LOG(a) +#endif +#ifdef CONFIG_FEATURE_IPC_SYSLOG + #define USAGE_IPC_LOG(a) a +#else + #define USAGE_IPC_LOG(a) +#endif + +#ifdef CONFIG_SYSCTL +#define sysctl_trivial_usage \ + "[OPTIONS]... [VALUE]...\n" +#define sysctl_full_usage + "sysctl - configure kernel parameters at runtime\n\n" \ + "Options:\n" \ + "\t-n\tUse this option to disable printing of the key name when printing values.\n" \ + "\t-w\tUse this option when you want to change a sysctl setting.\n" \ + "\t-p\tLoad in sysctl settings from the file specified or /etc/sysctl.conf if none given.\n" \ + "\t-a\tDisplay all values currently available.\n" \ + "\t-A\tDisplay all values currently available in table form." +#define sysctl_example_usage + "sysctl [-n] variable ...\n" \ + "sysctl [-n] -w variable=value ...\n" \ + "sysctl [-n] -a\n" \ + "sysctl [-n] -p \t(default /etc/sysctl.conf)\n" \ + "sysctl [-n] -A\n" +#endif + +#define syslogd_trivial_usage \ + "[OPTION]..." +#define syslogd_full_usage \ + "Linux system and kernel logging utility.\n" \ + "Note that this version of syslogd ignores /etc/syslog.conf.\n\n" \ + "Options:\n" \ + "\t-m MIN\t\tMinutes between MARK lines (default=20, 0=off)\n" \ + "\t-n\t\tRun as a foreground process\n" \ + "\t-O FILE\t\tUse an alternate log file (default=/var/log/messages)\n" \ + "\t-S\t\tMake logging output smaller." \ + USAGE_ROTATE_LOGFILE( \ + "\n\t-s SIZE\t\tMax size (KB) before rotate (default=200KB, 0=off)\n" \ + "\t-b NUM\t\tNumber of rotated logs to keep (default=1, max=99, 0=purge)") \ + USAGE_REMOTE_LOG( \ + "\n\t-R HOST[:PORT]\tLog to IP or hostname on PORT (default PORT=514/UDP)\n" \ + "\t-L\t\tLog locally and via network logging (default is network only)") \ + USAGE_IPC_LOG( \ + "\n\t-C [size(KiB)]\tLog to a circular buffer (read the buffer using logread)") +#define syslogd_example_usage \ + "$ syslogd -R masterlog:514\n" \ + "$ syslogd -R 192.168.1.1:601\n" + + +#ifndef CONFIG_FEATURE_FANCY_TAIL + #define USAGE_UNSIMPLE_TAIL(a) +#else + #define USAGE_UNSIMPLE_TAIL(a) a +#endif +#define tail_trivial_usage \ + "[OPTION]... [FILE]..." +#define tail_full_usage \ + "Print last 10 lines of each FILE to standard output.\n" \ + "With more than one FILE, precede each with a header giving the\n" \ + "file name. With no FILE, or when FILE is -, read standard input.\n\n" \ + "Options:\n" \ + USAGE_UNSIMPLE_TAIL("\t-c N[kbm]\toutput the last N bytes\n") \ + "\t-n N[kbm]\tprint last N lines instead of last 10\n" \ + "\t-f\t\toutput data as the file grows" \ + USAGE_UNSIMPLE_TAIL( "\n\t-q\t\tnever output headers giving file names\n" \ + "\t-s SEC\t\twait SEC seconds between reads with -f\n" \ + "\t-v\t\talways output headers giving file names\n\n" \ + "If the first character of N (bytes or lines) is a '+', output begins with \n" \ + "the Nth item from the start of each file, otherwise, print the last N items\n" \ + "in the file. N bytes may be suffixed by k (x1024), b (x512), or m (1024^2)." ) +#define tail_example_usage \ + "$ tail -n 1 /etc/resolv.conf\n" \ + "nameserver 10.0.0.1\n" + +#ifdef CONFIG_FEATURE_TAR_CREATE + #define USAGE_TAR_CREATE(a) a +#else + #define USAGE_TAR_CREATE(a) +#endif +#ifdef CONFIG_FEATURE_TAR_EXCLUDE + #define USAGE_TAR_EXCLUDE(a) a +#else + #define USAGE_TAR_EXCLUDE(a) +#endif +#ifdef CONFIG_FEATURE_TAR_GZIP + #define USAGE_TAR_GZIP(a) a +#else + #define USAGE_TAR_GZIP(a) +#endif +#ifdef CONFIG_FEATURE_TAR_BZIP2 + #define USAGE_TAR_BZIP2(a) a +#else + #define USAGE_TAR_BZIP2(a) +#endif +#ifdef CONFIG_FEATURE_TAR_COMPRESS + #define USAGE_TAR_COMPRESS(a) a +#else + #define USAGE_TAR_COMPRESS(a) +#endif + +#define tar_trivial_usage \ + "-[" USAGE_TAR_CREATE("c") USAGE_TAR_GZIP("z") USAGE_TAR_BZIP2("j") USAGE_TAR_COMPRESS("Z") "xtvO] " \ + USAGE_TAR_EXCLUDE("[-X FILE]") \ + "[-f TARFILE] [-C DIR] [FILE(s)] ..." +#define tar_full_usage \ + "Create, extract, or list files from a tar file.\n\n" \ + "Options:\n" \ + USAGE_TAR_CREATE("\tc\t\tcreate\n") \ + "\tx\t\textract\n" \ + "\tt\t\tlist\n" \ + "\nArchive format selection:\n" \ + USAGE_TAR_GZIP("\tz\t\tFilter the archive through gzip\n") \ + USAGE_TAR_BZIP2("\tj\t\tFilter the archive through bzip2\n") \ + USAGE_TAR_COMPRESS("\tZ\t\tFilter the archive through compress\n") \ + "\nFile selection:\n" \ + "\tf\t\tname of TARFILE or \"-\" for stdin\n" \ + "\tO\t\textract to stdout\n" \ + USAGE_TAR_EXCLUDE( \ + "\texclude\t\tfile to exclude\n" \ + "\tX\t\tfile with names to exclude\n" \ + ) \ + "\tC\t\tchange to directory DIR before operation\n" \ + "\tv\t\tverbosely list files processed" +#define tar_example_usage \ + "$ zcat /tmp/tarball.tar.gz | tar -xf -\n" \ + "$ tar -cf /tmp/tarball.tar /usr/local\n" + +#define tee_trivial_usage \ + "[OPTION]... [FILE]..." +#define tee_full_usage \ + "Copy standard input to each FILE, and also to standard output.\n\n" \ + "Options:\n" \ + "\t-a\tappend to the given FILEs, do not overwrite\n" \ + "\t-i\tignore interrupt signals (SIGINT)" +#define tee_example_usage \ + "$ echo "Hello" | tee /tmp/foo\n" \ + "$ cat /tmp/foo\n" \ + "Hello\n" + +#ifdef CONFIG_FEATURE_TELNET_AUTOLOGIN +#define telnet_trivial_usage \ + "[-a] [-l USER] HOST [PORT]" +#define telnet_full_usage \ + "Telnet is used to establish interactive communication with another\n" \ + "computer over a network using the TELNET protocol.\n\n" \ + "Options:\n" \ + "\t-a\t\tAttempt an automatic login with the USER variable.\n" \ + "\t-l USER\t\tAttempt an automatic login with the USER argument.\n" \ + "\tHOST\t\tThe official name, alias or the IP address of the\n" \ + "\t\t\tremote host.\n" \ + "\tPORT\t\tThe remote port number to connect to. If it is not\n" \ + "\t\t\tspecified, the default telnet (23) port is used." +#else +#define telnet_trivial_usage \ + "HOST [PORT]" +#define telnet_full_usage \ + "Telnet is used to establish interactive communication with another\n"\ + "computer over a network using the TELNET protocol." +#endif + +#ifdef CONFIG_FEATURE_TELNETD_INETD +#define telnetd_trivial_usage \ + "(inetd mode) [OPTION]" +#define telnetd_full_usage \ + "Telnetd uses incoming TELNET connections via inetd.\n"\ + "Options:\n" \ + "\t-l LOGIN\texec LOGIN on connect (default /bin/sh)\n" \ + "\t-f issue_file\tDisplay issue_file instead of /etc/issue." +#else +#define telnetd_trivial_usage \ + "[OPTION]" +#define telnetd_full_usage \ + "Telnetd listens for incoming TELNET connections on PORT.\n"\ + "Options:\n" \ + "\t-p PORT\tlisten for connections on PORT (default 23)\n"\ + "\t-l LOGIN\texec LOGIN on connect (default /bin/sh)\n"\ + "\t-f issue_file\tDisplay issue_file instead of /etc/issue." +#endif + +#define test_trivial_usage \ + "EXPRESSION\n or [ EXPRESSION ]" +#define test_full_usage \ + "Checks file types and compares values returning an exit\n" \ + "code determined by the value of EXPRESSION." +#define test_example_usage \ + "$ test 1 -eq 2\n" \ + "$ echo $?\n" \ + "1\n" \ + "$ test 1 -eq 1\n" \ + "$ echo $?\n" \ + "0\n" \ + "$ [ -d /etc ]\n" \ + "$ echo $?\n" \ + "0\n" \ + "$ [ -d /junk ]\n" \ + "$ echo $?\n" \ + "1\n" + +#ifdef CONFIG_FEATURE_TFTP_GET + #define USAGE_TFTP_GET(a) a +#else + #define USAGE_TFTP_GET(a) +#endif +#ifdef CONFIG_FEATURE_TFTP_PUT + #define USAGE_TFTP_PUT(a) a +#else + #define USAGE_TFTP_PUT(a) +#endif +#ifdef CONFIG_FEATURE_TFTP_BLOCKSIZE + #define USAGE_TFTP_BS(a) a +#else + #define USAGE_TFTP_BS(a) +#endif + +#define tftp_trivial_usage \ + "[OPTION]... HOST [PORT]" +#define tftp_full_usage \ + "Transfers a file from/to a tftp server using \"octet\" mode.\n\n" \ + "Options:\n" \ + "\t-l FILE\tLocal FILE.\n" \ + "\t-r FILE\tRemote FILE." \ + USAGE_TFTP_GET( \ + "\n\t-g\tGet file." \ + ) \ + USAGE_TFTP_PUT( \ + "\n\t-p\tPut file." \ + ) \ + USAGE_TFTP_BS( \ + "\n\t-b SIZE\tTransfer blocks of SIZE octets." \ + ) +#define time_trivial_usage \ + "[OPTION]... COMMAND [ARGS...]" +#define time_full_usage \ + "Runs the program COMMAND with arguments ARGS. When COMMAND finishes,\n" \ + "COMMAND's resource usage information is displayed\n\n" \ + "Options:\n" \ + "\t-v\tDisplays verbose resource usage information." + +#define top_trivial_usage \ + "[-d ]" +#define top_full_usage \ + "top provides an view of processor activity in real time.\n" \ + "This utility reads the status for all processes in /proc each \n" \ + "and shows the status for however many processes will fit on the screen.\n" \ + "This utility will not show processes that are started after program startup,\n" \ + "but it will show the EXIT status for and PIDs that exit while it is running." + +#define touch_trivial_usage \ + "[-c] FILE [FILE ...]" +#define touch_full_usage \ + "Update the last-modified date on the given FILE[s].\n\n" \ + "Options:\n" \ + "\t-c\tDo not create any files" +#define touch_example_usage \ + "$ ls -l /tmp/foo\n" \ + "/bin/ls: /tmp/foo: No such file or directory\n" \ + "$ touch /tmp/foo\n" \ + "$ ls -l /tmp/foo\n" \ + "-rw-rw-r-- 1 andersen andersen 0 Apr 15 01:11 /tmp/foo\n" + +#define tr_trivial_usage \ + "[-cds] STRING1 [STRING2]" +#define tr_full_usage \ + "Translate, squeeze, and/or delete characters from\n" \ + "standard input, writing to standard output.\n\n" \ + "Options:\n" \ + "\t-c\ttake complement of STRING1\n" \ + "\t-d\tdelete input characters coded STRING1\n" \ + "\t-s\tsqueeze multiple output characters of STRING2 into one character" +#define tr_example_usage \ + "$ echo "gdkkn vnqkc" | tr [a-y] [b-z]\n" \ + "hello world\n" + +#define traceroute_trivial_usage \ + "[-dnrv] [-m max_ttl] [-p port#] [-q nqueries]\n"\ + "\t[-s src_addr] [-t tos] [-w wait] host [data size]" +#define traceroute_full_usage \ + "trace the route ip packets follow going to \"host\"\n" \ + "Options:\n" \ + "\t-d\tset SO_DEBUG options to socket\n" \ + "\t-n\tPrint hop addresses numerically rather than symbolically\n" \ + "\t-r\tBypass the normal routing tables and send directly to a host\n" \ + "\t-v\tVerbose output\n" \ + "\t-m max_ttl\tSet the max time-to-live (max number of hops)\n" \ + "\t-p port#\tSet the base UDP port number used in probes\n" \ + "\t\t(default is 33434)\n" \ + "\t-q nqueries\tSet the number of probes per ``ttl'' to nqueries\n" \ + "\t\t(default is 3)\n" \ + "\t-s src_addr\tUse the following IP address as the source address\n" \ + "\t-t tos\tSet the type-of-service in probe packets to the following value\n" \ + "\t\t(default 0)\n" \ + "\t-w wait\tSet the time (in seconds) to wait for a response to a probe\n" \ + "\t\t(default 3 sec.)." + + +#define true_trivial_usage \ + "" +#define true_full_usage \ + "Return an exit code of TRUE (0)." +#define true_example_usage \ + "$ true\n" \ + "$ echo $?\n" \ + "0\n" + +#define tty_trivial_usage \ + "" +#define tty_full_usage \ + "Print the file name of the terminal connected to standard input.\n\n"\ + "Options:\n" \ + "\t-s\tprint nothing, only return an exit status" +#define tty_example_usage \ + "$ tty\n" \ + "/dev/tty2\n" + +#define udhcpc_trivial_usage \ + "[-fbnqv] [-c CLIENTID] [-H HOSTNAME] [-i INTERFACE]\n[-p pidfile] [-r IP] [-s script]" +#define udhcpc_full_usage \ + "\t-c,\t--clientid=CLIENTID\tClient identifier\n" \ + "\t-H,\t--hostname=HOSTNAME\tClient hostname\n" \ + "\t-h,\t \tAlias for -H\n" \ + "\t-f,\t--foreground\tDo not fork after getting lease\n" \ + "\t-b,\t--background\tFork to background if lease cannot be immediately negotiated.\n" \ + "\t-i,\t--interface=INTERFACE\tInterface to use (default: eth0)\n" \ + "\t-n,\t--now\tExit with failure if lease cannot be immediately negotiated.\n" \ + "\t-p,\t--pidfile=file\tStore process ID of daemon in file\n" \ + "\t-q,\t--quit\tQuit after obtaining lease\n" \ + "\t-r,\t--request=IP\tIP address to request (default: none)\n" \ + "\t-s,\t--script=file\tRun file at dhcp events (default: /usr/share/udhcpc/default.script)\n" \ + "\t-v,\t--version\tDisplay version" + +#define udhcpc_script_trivial_usage \ + "[ACTION]" +#define udhcpc_script_full_usage \ + "Should only be called by udhcpc." + +#define udhcpd_trivial_usage \ + "[configfile]\n" \ + +#define udhcpd_full_usage \ + "" + +#ifdef CONFIG_FEATURE_MOUNT_FORCE + #define USAGE_MOUNT_FORCE(a) a +#else + #define USAGE_MOUNT_FORCE(a) +#endif +#define umount_trivial_usage \ + "[flags] FILESYSTEM|DIRECTORY" +#define umount_full_usage \ + "Unmount file systems\n" \ + "\nFlags:\n" "\t-a\tUnmount all file systems" \ + USAGE_MTAB(" in /etc/mtab\n\t-n\tDon't erase /etc/mtab entries") \ + "\n\t-r\tTry to remount devices as read-only if mount is busy" \ + USAGE_MOUNT_FORCE("\n\t-f\tForce umount (i.e., unreachable NFS server)") \ + USAGE_MOUNT_LOOP("\n\t-l\tDo not free loop device (if a loop device has been used)") +#define umount_example_usage \ + "$ umount /dev/hdc1 \n" + +#define uname_trivial_usage \ + "[OPTION]..." +#define uname_full_usage \ + "Print certain system information. With no OPTION, same as -s.\n\n" \ + "Options:\n" \ + "\t-a\tprint all information\n" \ + "\t-m\tthe machine (hardware) type\n" \ + "\t-n\tprint the machine's network node hostname\n" \ + "\t-r\tprint the operating system release\n" \ + "\t-s\tprint the operating system name\n" \ + "\t-p\tprint the host processor type\n" \ + "\t-v\tprint the operating system version" +#define uname_example_usage \ + "$ uname -a\n" \ + "Linux debian 2.4.23 #2 Tue Dec 23 17:09:10 MST 2003 i686 GNU/Linux\n" + +#define uncompress_trivial_usage \ + "[-c] [-f] [ name ... ]" +#define uncompress_full_usage \ + "Uncompress .Z file[s]\n" \ + "Options:\n" \ + "\t-c\textract to stdout\n" \ + "\t-f\tforce overwrite an existing file" + +#define uniq_trivial_usage \ + "[OPTION]... [INPUT [OUTPUT]]" +#define uniq_full_usage \ + "Discard all but one of successive identical lines from INPUT\n" \ + "(or standard input), writing to OUTPUT (or standard output).\n\n" \ + "Options:\n" \ + "\t-c\tprefix lines by the number of occurrences\n" \ + "\t-d\tonly print duplicate lines\n" \ + "\t-u\tonly print unique lines\n" \ + "\t-f N\tskip the first N fields\n" \ + "\t-s N\tskip the first N chars (after any skipped fields)" +#define uniq_example_usage \ + "$ echo -e \"a\\na\\nb\\nc\\nc\\na\" | sort | uniq\n" \ + "a\n" \ + "b\n" \ + "c\n" + +#define unix2dos_trivial_usage \ + "[option] [FILE]" +#define unix2dos_full_usage \ + "Converts FILE from unix format to dos format. When no option\n" \ + "is given, the input is converted to the opposite output format.\n" \ + "When no file is given, uses stdin for input and stdout for output.\n" \ + "Options:\n" \ + "\t-u\toutput will be in UNIX format\n" \ + "\t-d\toutput will be in DOS format" + +#define unzip_trivial_usage \ + "[-opts[modifiers]] file[.zip] [list] [-x xlist] [-d exdir]" +#define unzip_full_usage \ + "Extracts files from ZIP archives.\n\n" \ + "Options:\n" \ + "\t-l\tlist archive contents (short form)\n" \ + "\t-n\tnever overwrite existing files (default)\n" \ + "\t-o\toverwrite files without prompting\n" \ + "\t-p\tsend output to stdout\n" \ + "\t-q\tbe quiet\n" \ + "\t-x\texclude these files\n" \ + "\t-d\textract files into this directory" + +#define uptime_trivial_usage \ + "" +#define uptime_full_usage \ + "Display the time since the last boot." +#define uptime_example_usage \ + "$ uptime\n" \ + " 1:55pm up 2:30, load average: 0.09, 0.04, 0.00\n" + +#define usleep_trivial_usage \ + "N" +#define usleep_full_usage \ + "Pause for N microseconds." +#define usleep_example_usage \ + "$ usleep 1000000\n" \ + "[pauses for 1 second]\n" + +#define uudecode_trivial_usage \ + "[FILE]..." +#define uudecode_full_usage \ + "Uudecode a file that is uuencoded.\n\n" \ + "Options:\n" \ + "\t-o FILE\tdirect output to FILE" +#define uudecode_example_usage \ + "$ uudecode -o busybox busybox.uu\n" \ + "$ ls -l busybox\n" \ + "-rwxr-xr-x 1 ams ams 245264 Jun 7 21:35 busybox\n" + +#define uuencode_trivial_usage \ + "[OPTION] [INFILE] REMOTEFILE" +#define uuencode_full_usage \ + "Uuencode a file.\n\n" \ + "Options:\n" \ + "\t-m\tuse base64 encoding per RFC1521" +#define uuencode_example_usage \ + "$ uuencode busybox busybox\n" \ + "begin 755 busybox\n" \ + "\n" \ + "$ uudecode busybox busybox > busybox.uu\n" \ + "$\n" + +#define vconfig_trivial_usage \ + "COMMAND [OPTIONS] ..." +#define vconfig_full_usage \ + "vconfig lets you create and remove virtual ethernet devices.\n\n" \ + "Options:\n" \ + "\tadd [interface-name] [vlan_id]\n" \ + "\trem [vlan-name]\n" \ + "\tset_flag [interface-name] [flag-num] [0 | 1]\n" \ + "\tset_egress_map [vlan-name] [skb_priority] [vlan_qos]\n" \ + "\tset_ingress_map [vlan-name] [skb_priority] [vlan_qos]\n" \ + "\tset_name_type [name-type]" + +#define vi_trivial_usage \ + "[OPTION] [FILE]..." +#define vi_full_usage \ + "edit FILE.\n\n" \ + "Options:\n" \ + "\t-R\tRead-only- do not write to the file." + +#define vlock_trivial_usage \ + "[OPTIONS]" +#define vlock_full_usage \ + "Lock a virtual terminal. A password is required to unlock\n" \ + "Options:\n" \ + "\t-a\tLock all VTs" + +#define watch_trivial_usage \ + "[-n ] COMMAND..." +#define watch_full_usage \ + "Executes a program periodically.\n" \ + "Options:\n" \ + "\t-n\tLoop period in seconds - default is 2." +#define watch_example_usage \ + "$ watch date\n" \ + "Mon Dec 17 10:31:40 GMT 2000\n" \ + "Mon Dec 17 10:31:42 GMT 2000\n" \ + "Mon Dec 17 10:31:44 GMT 2000" + +#define watchdog_trivial_usage \ + "[-t ] DEV" +#define watchdog_full_usage \ + "Periodically write to watchdog device DEV.\n" \ + "Options:\n" \ + "\t-t\tTimer period in seconds - default is 30." + +#define wc_trivial_usage \ + "[OPTION]... [FILE]..." +#define wc_full_usage \ + "Print line, word, and byte counts for each FILE, and a total line if\n" \ + "more than one FILE is specified. With no FILE, read standard input.\n\n" \ + "Options:\n" \ + "\t-c\tprint the byte counts\n" \ + "\t-l\tprint the newline counts\n" \ + "\t-L\tprint the length of the longest line\n" \ + "\t-w\tprint the word counts" +#define wc_example_usage \ + "$ wc /etc/passwd\n" \ + " 31 46 1365 /etc/passwd\n" + +#define wget_trivial_usage \ + "[-c|--continue] [-q|--quiet] [-O|--output-document file]\n" \ + "\t\t[--header 'header: value'] [-Y|--proxy on/off] [-P DIR] url" +#define wget_full_usage \ + "wget retrieves files via HTTP or FTP\n\n" \ + "Options:\n" \ + "\t-c\tcontinue retrieval of aborted transfers\n" \ + "\t-q\tquiet mode - do not print\n" \ + "\t-P\tSet directory prefix to DIR\n" \ + "\t-O\tsave to filename ('-' for stdout)\n" \ + "\t-Y\tuse proxy ('on' or 'off')" + +#define which_trivial_usage \ + "[COMMAND ...]" +#define which_full_usage \ + "Locates a COMMAND." +#define which_example_usage \ + "$ which login\n" \ + "/bin/login\n" + +#define who_trivial_usage \ + " " +#define who_full_usage \ + "Prints the current user names and related information" + +#define whoami_trivial_usage \ + "" +#define whoami_full_usage \ + "Prints the user name associated with the current effective user id." + +#ifdef CONFIG_FEATURE_XARGS_SUPPORT_CONFIRMATION +#define USAGE_XARGS_CONFIRMATION(a) a +#else +#define USAGE_XARGS_CONFIRMATION(a) +#endif +#ifdef CONFIG_FEATURE_XARGS_SUPPORT_TERMOPT +#define USAGE_XARGS_TERMOPT(a) a +#else +#define USAGE_XARGS_TERMOPT(a) +#endif +#ifdef CONFIG_FEATURE_XARGS_SUPPORT_ZERO_TERM +#define USAGE_XARGS_ZERO_TERM(a) a +#else +#define USAGE_XARGS_ZERO_TERM(a) +#endif + + +#define xargs_trivial_usage \ + "[COMMAND] [OPTIONS] [ARGS...]" +#define xargs_full_usage \ + "Executes COMMAND on every item given by standard input.\n\n" \ + "Options:\n" \ + USAGE_XARGS_CONFIRMATION("\t-p\tPrompt the user about whether to run each command\n") \ + "\t-r\tDo not run command for empty readed lines\n" \ + USAGE_XARGS_TERMOPT("\t-x\tExit if the size is exceeded\n") \ + USAGE_XARGS_ZERO_TERM("\t-0\tInput filenames are terminated by a null character\n") \ + "\t-t\tPrint the command line on stderr before executing it." +#define xargs_example_usage \ + "$ ls | xargs gzip\n" \ + "$ find . -name '*.c' -print | xargs rm\n" + +#define yes_trivial_usage \ + "[OPTION]... [STRING]..." +#define yes_full_usage \ + "Repeatedly outputs a line with all specified STRING(s), or 'y'." + +#define zcat_trivial_usage \ + "FILE" +#define zcat_full_usage \ + "Uncompress to stdout." + +#endif /* __BB_USAGE_H__ */ + + + + + + + + + + + + + + + diff --git a/urunlevel/my_linux/Config.in b/urunlevel/my_linux/Config.in new file mode 100644 index 0000000..89f3c24 --- /dev/null +++ b/urunlevel/my_linux/Config.in @@ -0,0 +1,32 @@ +# +# For a description of the syntax of this configuration file, +# see scripts/kbuild/config-language.txt. +# + +menu "My Linux Utilities" + +config CONFIG_GETPKG + bool "getpkg" + default y + help + An implementation of the My Linux getpkg script. + +config CONFIG_LINUXRC + bool "linuxrc" + default y + help + An implementation of the linuxrc boot script. + +config CONFIG_MAN + bool "man" + default y + help + An implementation of the My Linux man script. + +config CONFIG_RCS + bool "rcS" + default y + help + An implementation of rcS. + +endmenu diff --git a/urunlevel/my_linux/Makefile b/urunlevel/my_linux/Makefile new file mode 100644 index 0000000..5160a99 --- /dev/null +++ b/urunlevel/my_linux/Makefile @@ -0,0 +1,32 @@ +# Makefile for busybox +# +# Copyright (C) 1999-2004 by Erik Andersen +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +top_srcdir=.. +top_builddir=.. +srcdir=$(top_srcdir)/my_linux +MY_LINUX_DIR:=./ +include $(top_builddir)/Rules.mak +include $(top_builddir)/.config +include $(srcdir)/Makefile.in +all: $(libraries-y) +-include $(top_builddir)/.depend + +clean: + rm -f *.o *.a $(AR_TARGET) + diff --git a/urunlevel/my_linux/Makefile.in b/urunlevel/my_linux/Makefile.in new file mode 100644 index 0000000..db30a61 --- /dev/null +++ b/urunlevel/my_linux/Makefile.in @@ -0,0 +1,40 @@ +# Makefile for busybox +# +# Copyright (C) 1999-2004 by Erik Andersen +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +MY_LINUX_AR:=my_linux.a +ifndef $(MY_LINUX_DIR) +MY_LINUX_DIR:=$(top_builddir)/my_linux/ +endif +srcdir=$(top_srcdir)/my_linux + +MY_LINUX-y:= +MY_LINUX-$(CONFIG_GETPKG) += getpkg.o +MY_LINUX-$(CONFIG_LINUXRC) += linuxrc.o +MY_LINUX-$(CONFIG_MAN) += man.o +MY_LINUX-$(CONFIG_MAN) += mkrootfs.o +MY_LINUX-$(CONFIG_RCS) += rcS.o + +libraries-y+=$(MY_LINUX_DIR)$(MY_LINUX_AR) + +$(MY_LINUX_DIR)$(MY_LINUX_AR): $(patsubst %,$(MY_LINUX_DIR)%, $(MY_LINUX-y)) + $(AR) -ro $@ $(patsubst %,$(MY_LINUX_DIR)%, $(MY_LINUX-y)) + +$(MY_LINUX_DIR)%.o: $(srcdir)/%.c + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< + diff --git a/urunlevel/my_linux/Trinux/README b/urunlevel/my_linux/Trinux/README new file mode 100644 index 0000000..b07fa7f --- /dev/null +++ b/urunlevel/my_linux/Trinux/README @@ -0,0 +1,346 @@ +Trinux Documentation Matthew Franz +http://trinux.sf.net/docs.txt 21 August 2003 + +0. Introduction + + 0.1 What is Trinux? + + Trinux is a ramdisk-based Linux distribution that was first + released in April of 1998 and has been maintained on and off + since then. Like other Linux distributions it consists of a + Linux kernel, base utilities, and a variety of packages. Like + many embedded distributions, Trinux uses Busybox, which contains + small versions of common utilities. See http://www.busybox.net. + + 0.2 Where can I get the source? + + Many of the standard utilities came from Slackware 7.1 or + when components needed to be upgraded, I pulled the source + from the Debian stable. The "original code" would be in the + /linuxrc script that is executed within + + 0.3 Installation + + Trinux is released in either 1.4 meg floppy images or small ISO + images. For the floppy images use dd on unix boxes or rawrite + on Windows. Search the web for info. + + 0.4 If in doubt look at the /linuxrc script! + +1. Boot Media + + 1.1 Common Format + + * bzImage - compressed linux kernel + * tux - trinux configuration directory (like /etc on Unix) that + gets copied to /etc/tux when trinux boots + * bootpkg - packages that need to be loaded early + * kpkg - modular kernel packages + * initrd.gz - compressed initial ramdisk + * modules - raw (*.o) modules will be automatically loaded + + 1.2 Floppy Disks + + Trinux uses MS-DOS (vfat actually) formatted disks and syslinux + as the bootloader. The files/directories described in 1.1 are + directly off the root of the drive. + + * syslinux.cfg - bootloader configuration file + * ldlinux.sys - SYSLINUX bootloader (http://syslinux.zytor.com/) + + 1.3 CD-ROM + + Bootable CD's are ISO9660 filesytem contain 2 directories: + * isolinux - bzImage, initrd.gz, isolinux.bin, isolinux.cfg + * trinux - bootpkg, kpkg, modules, tux + + 1.4 Fixed Partition (IDE Drive) + + Trinux can also be booted from a Windows 95/98, MS-DOS, or + FreeDOS partition using loadlin.exe. This is an option for older + hardware that might not have a CD-ROM (or a bootable one) or + if you want to load packages from a compact Flash drive using an + IDE Compact-Flash Adapter. + + 1.4.1 Prepping the Drive + + Use a Windows 95/98 or MS-DOS boot disk or the Trinux FreeDOS + Utility Disk (available on the downloads page) to create a FAT + partition. This involves running FDISK, FORMAT, and SYS. You + should copy loadlin.exe to the drive and it is also useful to have + a text editor (FreeDOS has TE) to edit batch files. You will + need to create trinux directory. My C:\ drive (mounted from + within Trinux as a vfat) looks like this: + + trinux> ls -al + root root 16384 Jul 24 23:28 . + root root 832 Sep 3 2002 .. + root root 2048 Jul 20 18:51 .links + root root 50 Jul 20 17:35 autoexec.bat + root root 618999 Jul 20 18:11 bzimage + root root 86561 Aug 15 2001 command.com + root root 45836 Jul 20 17:35 fdisk.exe + root root 13741 Jul 20 17:35 format.exe + root root 600357 Jul 21 01:01 initrd.gz + root root 75663 Sep 3 2001 kernel.sys + root root 32177 Jul 20 17:35 loadlin.exe + root root 32719 Jul 20 17:35 loadlin.txt + root root 2048 Jul 20 18:33 old + root root 8634 Jul 20 17:36 sys.com + root root 44706 Jul 20 17:35 te.exe + root root 2048 Jul 21 12:31 trinux + + TRINUX.BAT on the FreeDOS boot floppy contains the following + which I renamed to AUTOEXEC.BAT once I new it was stable. + + loadlin bzimage initrd=initrd.gz root=/dev/ram0 rw + + I have had mixed results with FreeDOS, so it might be best + to find a Windows 95/98/SE boot disk with fdisk and format. + I found a DOS 6.22 boot disk with the right tools from + http://www.bootdisk.com. + + Copy a kernel that has IDE support (all the kernels on the + boot floppies after Trinux 0.890 should have the or a kernel + from the CD-ROM will work to) and an initrd.gz to the c:\ + drive. You can do this from DOS or from Linux. + + 1.4.2 Copying necessary files to the DOS partition + + Boot with a Trinux floppy (or CD-ROM) that has IDE support + and then mount the MS-DOS partition with the following + command + + # mount -t vfat /dev/hda1 /mnt + + This assumes the first IDE drive and should work for most + cases. Now create (or cd) the trinux directory on that + partition and create the subdirectories for packages + + # cd /mnt/trinux + # mkdir bootpkg kpkg pkg modules + # mkdir -p tux/config + # mkdir tux/ + + Now you need to get a minimum set of packages into the bootpkg + directory. If you have network access you can download them with + links (getpkg links) or you can copy them to floppies. I have + the following in mine: + + root root 245776 Jul 20 19:17 baselib.tgz + root root 15932 Jul 20 18:17 dhcpcd.tgz + root root 90312 Jul 20 18:17 dnslibs.tgz + root root 163951 Jul 21 12:28 iptables.tgz + root root 131200 Jul 21 12:28 netfilter.tgz + root root 77834 Jul 20 19:22 pthread.tgz + root root 378444 Jul 20 19:22 term.tgz + + These will always get loaded. You can also put packages in the + pkg directory and these may/may not load depending on your + configuration. + + Remember, after you are through modifying the partition, it + needs to be unmounted with: + + #umount /dev/hda1 + or + #umount /mnt + + 1.4.3 Configuarition + + +2. Networking + + 2.1 Hardware Detection + + In order for you to use networking your interface(s) must be + detected by the kernel. In order for this to occur you must either + have support for your NIC compiled into the kernel or use a kernel + module. Older versions of Trinux had support for the most common + NiCs built in, but that is no longer the case. + + If your hardware was succuessfully found + + # dmesg | grep eth0 + eth0: OEM i82557/i82558 10/100 Ethernet, 00:03:47:B9:12:08, IRQ 11 + + 2.2 Module Selection + +3. Kernel Modules + + Raw (non-packaged kernel modules are available at: + http://trinux.sf.net/kernel/ + + Packaged kernel modules are available at http://trinux.sf.net/pkg/2.4.x/ + and may be installed with the "getkpkg " + + Trinux puts all packages in /lib/modules or /usr/lib/modules instead + of the standard linux convention of /lib/modules/2.4.x/... + +4. Packages + + 4.1 Package Format + + Packages are simply tarballs with an initialization script that + will be executed from within /etc/init.d/package_name or + /etc/init.m/kernel_package_name + + 4.2 Scripts + + * pkgadd - loads a package from a local filesystem + * getpkg - loads the package from the network + * getkpkg - loads a kernel package from the network + * pkglist - lists available packages + * rmpkg - deletes package + * mypkg - shows packages currently installed + + 4.3 Building your own + + All the Trinux packages are compiled with glibc 2.1.3 using + Slackware 7.1. I upgraded the compiler to gcc 2.95 and have upgraded + libraries as necessary. + + 4.4 Adding packages after bootup + + You can either use the getpkg/getkpkg commands to load a package + from the network. If /etc/tux/config/localpkg is set + (added 0.891) + + 4.5 Configuration + + Add list of package (in order) to /etc/tux/config/pkglist and these + will be loaded at boot + + 4.6 Miscellaneous + +5. Filesystems + + 5.1 Supported Filesytems + + Trinux may only have support for a few filesystems such as minix + vfat (Windows) and ISO9660 (for CDROMs). To see which filesystems + are currently supported in the kernel: + + # cat /proc/filesystems | grep -v nodev + minix + vfat + iso9660 + reiserfs + + In this case I installed the reiserfs module: + + # lsmod + reiserfs 165600 1 + 3c59x 24560 1 + 8139too 13396 1 + mii 2092 0 [8139too] + + + To mount a device you use the following command: + + mount -t hda4 + hde: LEXAR ATA FLASH, ATA DISK drive + hde: 96384 sectors (49 MB) w/1KiB Cache, CHS=753/4/32 + hde: hde1 + + So assuming hde1 were a vfat partition, you would use: + + # mount -t vfat /dev/hde1 /mnt + # mount + /dev/hda2 on / type ext3 (rw,errors=remount-ro) + proc on /proc type proc (rw) + devpts on /dev/pts type devpts (rw,gid=5,mode=620) + /dev/hda4 on /alt type reiserfs (rw) + /trinux/boot/trinux.img on /loop type vfat (rw,loop=/dev/loop0) + /dev/hde1 on /mnt type vfat (rw) + + This was from my laptop. Within Trinux, the following is more + typical: + + # mount + /dev/ram0 on / type minix (rw) + /proc on /proc type proc (rw) + /dev/null on /usr type tmpfs (rw) + /dev/null on /home type tmpfs (rw) + /dev/null on /var type tmpfs (rw) + /dev/hda2 on /hda2 type reiserfs (rw) + + + 5.3 Swap + + Usually, you probably have enough memory (otherwise you wouldn't + be running ramdisks) but if you want to set up a swap file or swap + filesystem, put the name of the file (within an existing filesytem) + the name of the partition (/dev/hda3) in /etc/tux/config/swap and + the linuxrc will automatically run mkswap and swapon. You may + want to make sure the swaputils.tgz package is included, + although it will be loaded automatically if /sbin/makeswap + isn't found. + + 5.4 Tmpfs + + A neat feature that came out in 2.4 was the ability to use the + temporary or shared memory filesystem instead of ramdisks. The key + advantage is that ramdisks are completed allocated when the are + created, but tmpfs partitions only use RAM as they are filled. + + + Trinux only has support for a minimal set of filesystems + +6. Management and Monitoring + + Although it is probably not the most common option, Trinux can be + used in a headless server capacity + + 6.1 Serial Console + + 6.2 SSH Remote Logins + + 6.3 Enabling Cisco Discovery Protocol (CDP) + + 6.4 Building a Local Package Server + +7. Miscellaneous + + 6.1 Troubleshooting + + Recent versions of trinux have a /sbin/hwinfo script that gathers + hardware information about the system and saves it to the file + /tmp/hwinfo. It basically saves the output of the dmesg command + and copies the values of some /proc files that can be used to help + troubleshoot hardware problems. The following commands allow you to + save this file to the boot floppy (assuming you have enough room) + + # fmount + # cp /tmp/hwinfo /floppy + # fumount + + You can then post some or all of this file to the trinux-talk mailing + list when you have a problem. + + 6.2 Where to get help + + You should subscribe to the trinux-talk mailing list + + 6.3 Floppy Errors + + If you do not have a floppy drive or you floppy drive takes very + long to time out, append "nofloppy" to the kernel boot arguments. + CD-ROM booting automatically disables this checking. I had to do + this on an old Compaq 486-66 because it was taking several minutes + to complete the bootup: + + loadlin bzimage initrd=initrd.gz root=/dev/ram0 rw nofloppy + diff --git a/urunlevel/my_linux/Trinux/chkfixed b/urunlevel/my_linux/Trinux/chkfixed new file mode 100755 index 0000000..4cbb45b --- /dev/null +++ b/urunlevel/my_linux/Trinux/chkfixed @@ -0,0 +1,99 @@ +#!/bin/sh +# +# chkfixed - look for legitimate parititions and build mount points +# and populate /etc/proc +# + +rm /tmp/partitions 2> /dev/null + + +[ -d /etc/proc ] || mkdir /etc/proc + +if [ -f /etc/tux/config/fstab ] +then + echo "fstab found, exiting..." + exit 1 +fi + +for i in `grep -v nodev /proc/filesystems` +do + echo "$i" +done > /etc/proc/availfs + +echo "The following filesystems are supported:" +cat /etc/proc/availfs +echo + +cdpart=`dmesg | grep D-ROM | grep hd | cut -d: -f1` + +if [ "$cdpart" ] +then + echo "A CD-ROM was found at $cdpart" + echo "$cdpart" > /tmp/partitions +fi + +partitions=`dmesg | grep ' hd[abcdef]' | cut -d':' -f2` +scsiparts=`dmesg | grep "^ sd[abcdef][12345]"` + +echo IDE Partitions: $partitions +echo SCSI Partitions: $scsiparts + +for i in $partitions +do + + if echo "$partitions" | grep unknown > /dev/null + then + echo "Unkown partition" + else + echo $i >> /tmp/partitions + fi +done + +for i in $partitions +do + + if echo "$partitions" | grep unknown > /dev/null + then + echo "Unkown partition" + else + echo $i >> /tmp/partitions + fi +done + + +for i in $scsiparts +do + echo $i >> /tmp/partitions +done + +if [ ! -f /tmp/partitions ] +then + echo "No fixed partitions found!" + exit +fi + +sort /tmp/partitions | uniq | grep "hd" > /etc/proc/partitions +sort /tmp/partitions | uniq | grep "sd" >> /etc/proc/partitions + +echo "The following partitions were found: " +cat /etc/proc/partitions +echo + +##echo "The following filesystems were found: " +for i in `cat /etc/proc/partitions` +do + mkdir /$i 2> /dev/null + + for j in `cat /etc/proc/availfs` + do + echo -n Checking $i: + if mount -o ro -t $j /dev/$i /$i 2> /dev/null > /dev/null + then + echo " found $j" + echo "$i:$j" >> /etc/tux/config/fstab + umount /dev/$i 2> /dev/null > /dev/null + else + echo + fi + done +done diff --git a/urunlevel/my_linux/Trinux/fmount b/urunlevel/my_linux/Trinux/fmount new file mode 100755 index 0000000..db8595b --- /dev/null +++ b/urunlevel/my_linux/Trinux/fmount @@ -0,0 +1,2 @@ +#!/bin/sh +mount -t vfat /dev/fd0 /floppy diff --git a/urunlevel/my_linux/Trinux/fumount b/urunlevel/my_linux/Trinux/fumount new file mode 100755 index 0000000..003ce14 --- /dev/null +++ b/urunlevel/my_linux/Trinux/fumount @@ -0,0 +1,3 @@ +#!/bin/sh +cd / +umount /dev/fd0 diff --git a/urunlevel/my_linux/Trinux/gethome b/urunlevel/my_linux/Trinux/gethome new file mode 100755 index 0000000..c47c238 --- /dev/null +++ b/urunlevel/my_linux/Trinux/gethome @@ -0,0 +1,61 @@ +#!/bin/sh + +if [ "$1" ] +then + home=$1 +else + home="home" +fi + +homeline=`cat /etc/tux/config/home` + +if [ "$homeline" ] +then + PROTO=`cut -d':' -f1 /etc/tux/config/home` + HOST=`cut -d':' -f2 /etc/tux/config/home` + USER=`cut -d':' -f3 /etc/tux/config/home` +else + echo -n "ftp or ssh: " + read PROTO + echo -n "Host: " + read HOST + echo -n "User: " + read USER + echo $PROTO:$HOST:$USER > /etc/tux/config/home +fi + + +echo "Retrieving home directory from $USER@$HOST via $PROTO" + +if [ $PROTO = "ssh" ] +then + scp $USER@$HOST:~/$home.tgz / +fi + +if [ $PROTO = "ftp" ] +then + echo "Using FTP to transfor $home.tgz -- your passwords are sniffable" + + if [ -x /usr/bin/curl ] + then + curl -u $USER ftp://$HOST/$home.tgz > /$home.tgz + + else + echo "Curl is not installed. You will have to login with your" + echo "username and upload $home.tgz manually" + + ftp $HOST + + fi +fi + +cd / +echo +echo "Uncompressing archive..." +gunzip -c $home.tgz | tar xvf - +rm /$home.tgz 2> /dev/null + + + + + diff --git a/urunlevel/my_linux/Trinux/getkpkg b/urunlevel/my_linux/Trinux/getkpkg new file mode 100755 index 0000000..ceab0ce --- /dev/null +++ b/urunlevel/my_linux/Trinux/getkpkg @@ -0,0 +1,9 @@ +#!/bin/sh + +if [ "$1" ] +then + KERNEL=`uname -r` + getpkg $KERNEL/$1 +else + echo "No package specified!" +fi diff --git a/urunlevel/my_linux/Trinux/getpkg b/urunlevel/my_linux/Trinux/getpkg new file mode 100755 index 0000000..adeab02 --- /dev/null +++ b/urunlevel/my_linux/Trinux/getpkg @@ -0,0 +1,171 @@ +#!/bin/sh +# +# getpkg - retrieves a single package from package server +# +# Author: Matthew D. Franz +# +# $1 - name of package +# $2 - URL of server +# +############################################################################ + +[ -d /var/pkg/contents ] || mkdir -p /var/pkg/contents + +# if in current directory, call pkgadd + +if [ -f "$1" ] +then + pkgadd $i +else + if [ -f /etc/tux/config/localpkg ] + then + print "Using local package repository" + if [ -f /etc/proc/fixed ] + then + print "Found /etc/proc/fixed" + fi + fi +fi + + +if [ -f /etc/tux/config/proxy ] +then + SNARF_PROXY=`cat /etc/tux/config/proxy` + export SNARF_PROXY +fi + +mkdir /etc/init.d/running 2> /dev/null + +if [ "$1" = "list" ] +then + pkglist + exit +fi + +if [ "$1" = "all" ] + then + echo "Downloading all packages..." + + if [ ! -f /etc/tux/config/eth0 ] + then + echo "Network was not configured" + if dmesg | grep eth0 > /dev/null + then + echo -n "Attempting DHCP on eth0: " + if dhcpcd > /dev/null 2> /dev/null + then + echo "Successful" + else + echo "Failed" + exit + fi + else + echo "No ethernet interfaces were found" + exit + fi + fi + + if [ -f /etc/tux/config/pkglist ] + then + pkglist=`cat /etc/tux/config/pkglist` + for i in $pkglist + do + getpkg $i + done + else + echo "No package list found, retrieving a minimal set" + getpkg baselib + getpkg term + getpkg vi + getpkg tcpdump + fi + + exit +fi + +if [ "$1" = "" ] +then + echo; echo "You did not specify a package or server!"; echo + echo "getpkg all will load all the packages from /etc/tux/config/pkglist" + getpkg all +else + if [ "$2" = "" ] + then + if [ "$URL" = "" ] + then + if [ -f /etc/tux/config/server ] + then + blah=1 + else + echo -n "Enter URL for package retrieval: " + read URL + if [ "$URL" != "" ] + then + echo "Using $URL as your package server from now on..." + echo "$URL" > /etc/tux/config/server + fi + fi + fi + else + URL=$2 + fi + + if echo $1 | grep tgz > /dev/null + then + FILE=$1 + else + FILE=$1.tgz + fi + + cd / + + PREFIX=`basename $FILE ".tgz"` + + #echo $PREFIX + + MODPKGNAME=`echo ${1} | cut -d'/' -f2` + + + if echo $MODPKGNAME | grep tgz > /dev/null + then + MODPKGNAME=`basename $MODPKGNAME ".tgz"` + fi + + # Loop through servers listed in + + for URL in `cat /etc/tux/config/server` + do + if snarf $URL - > /dev/null 2> /dev/null + then + echo "Retrieving ${URL}${FILE}" + output=`snarf ${URL}/${FILE} - | gunzip -c | tar xvf -` + fi + + echo $output > /var/pkg/contents/$PREFIX + + if [ -f /etc/init.d/${PREFIX} ] + then + chmod a+x /etc/init.d/${PREFIX} 2> /dev/null + echo; echo "Initializing ${PREFIX}" + /etc/init.d/${PREFIX} 2> /dev/null + fi + + + if [ "$MODPKGNAME" ] + then + chmod a+x /etc/init.m/${MODPKGNAME} 2> /dev/null + if [ -x /etc/init.m/$MODPKGNAME ] + then + /etc/init.m/$MODPKGNAME + echo "Initializing $1 modules" + fi + fi + + + break + done + + [ $? -eq 0 ] || exit 1 + +fi + diff --git a/urunlevel/my_linux/Trinux/hwinfo b/urunlevel/my_linux/Trinux/hwinfo new file mode 100755 index 0000000..5e32126 --- /dev/null +++ b/urunlevel/my_linux/Trinux/hwinfo @@ -0,0 +1,23 @@ +#!/bin/sh + +echo "Gathering hardware information, saving to /tmp/hwinfo" + +echo "[--- dmesg ---]" > /tmp/hwinfo +dmesg >> /tmp/hwinfo +echo "[--- /proc/devices ---]" >> /tmp/hwinfo +cat /proc/devices >> /tmp/hwinfo +echo "[--- /proc/iomem ---]" >> /tmp/hwinfo +cat /proc/iomem >> /tmp/hwinfo +echo "[--- /proc/ioports ---]" >> /tmp/hwinfo +cat /proc/ioports >> /tmp/hwinfo +echo "[--- /proc/interrupts ---]" >> /tmp/hwinfo +cat /proc/interrupts >> /tmp/hwinfo +echo "[--- /proc/pci ---]" >> /tmp/hwinfo +cat /proc/pci >> /tmp/hwinfo +echo "[--- /proc/meminfo ---]" >> /tmp/hwinfo +cat /proc/meminfo >> /tmp/hwinfo +echo "[--- /proc/partitions ---]" >> /tmp/hwinfo +cat /proc/partitions >> /tmp/hwinfo +echo "[--- /proc/modules ---]" >> /tmp/hwinfo +cat /proc/modules >> /tmp/hwinfo + diff --git a/urunlevel/my_linux/Trinux/killmod b/urunlevel/my_linux/Trinux/killmod new file mode 100755 index 0000000..7dc80b6 --- /dev/null +++ b/urunlevel/my_linux/Trinux/killmod @@ -0,0 +1,8 @@ +#!/bin/sh + +echo "Unloading all kernel modules" +for i in `lsmod` +do + mod=`echo $i | cut -d' ' -f1` + rmmod $mod 2> /dev/null +done diff --git a/urunlevel/my_linux/Trinux/linuxrc b/urunlevel/my_linux/Trinux/linuxrc new file mode 100755 index 0000000..4597234 --- /dev/null +++ b/urunlevel/my_linux/Trinux/linuxrc @@ -0,0 +1,1261 @@ +#!/bin/sh +# +# linuxrc - main trinux initialization script +# +# Author: Matthew Franz +# Bill Burdick for the User-Mode-Linux fixes +######################################################################## +# +# Attempts to do the following: +# +# - Determine where trinux booted from [ Floppy/CD-ROM/IDE/UML ] +# - Mount boot device and copy configuration files to /etc/tux +# - Initialize and create ramdisks/tmpfs or mount filesystems +# - Determine where packages are located and to be loaded from +# - Initialize kernel modules and detect hardware +# - Configure and enable networking +# - Load and initialize packages +# - Initialize system daemons +# +######################################################################## +## Define stuff that is probably rejected by busybox +######################################################################## + +UMLROOT="/trinux-uml" +PATH="/usr/bin:/usr/sbin:/bin:/sbin:/usr/local/bin:/usr/local/sbin" +TERM=linux +PS1="trinux> " +PS2='>' + +export PATH TERM PS1 PS2 VERSION PKGSRC BOOT PKGSRC BOOTFS FLCFG FXCFG PKGLIST FIXED +umask 022 +[ -d /etc/proc ] || mkdir -p /etc/proc +mount -t proc proc /proc +mkdir -p /lib/modules +mkdir -p /etc/tux/config +ln -sf /proc/self/fd/0 /dev/stdin +ln -sf /proc/self/fd/2 /dev/stderr +ln -sf /proc/self/fd/1 /dev/stdout + +chmod a+w /tmp +chmod a+w /dev/null + +##################################################################### +## Gather information about system +##################################################################### + +MEMORY=`grep MemTotal /proc/meminfo | cut -d':' -f2 | cut -d'k' -f1` +KERNEL=`cat /proc/version | cut -d' ' -f3` +CDEV=`dmesg | grep D-ROM | grep hd | cut -d: -f1 | sort | uniq` # CD-ROM devices +FDEV=`dmesg | grep -v LDM | grep -v "ldm_val" | grep "^ [sh]d[a-f]" | cut -d':' -f2 | sort | uniq` # FIXED + +echo "Checking for fixed disks" +/sbin/chkfixed + + + +echo "FDEV: $FDEV" +echo "CDEV: $CDEV" +sleep 1 + +echo "$FDEV" > /tmp/fixed + + +for i in `cat /tmp/fixed` +do + echo $i +done > /etc/proc/fixed + + +[ "$CDEV" ] && echo "$CDEV" >> /etc/proc/fixed + + +#check initial filesytem support + +for i in `grep -v nodev /proc/filesystems` +do + echo $i +done > /etc/proc/filesystems + + +###################################################################### +### Special Probing stuff +###################################################################### + +## Did we boot from UML? +#if dmesg | grep 'User-mode Linux' > /dev/null + +if grep ' ubd' /proc/devices > /dev/null +then + echo "Trinux booted via User Mode Linux (UML)" + sleep 3 + UML="true" + BOOT="UML" +fi + +## Did we boot from ms-dos loadlin + +echo "Checking all vfat partitions for loadlin.exe" + +for i in `cat /etc/proc/fixed 2> /dev/null` +do +# [ -d /${i} ] || mkdir /${i} +# echo "Checking $i" + + if mount -o ro -t vfat /dev/${i} /mnt 2> /dev/null + then + echo -n "VFAT found on $i" + if ls /mnt/loadlin.exe 2> /dev/null + then + echo -n " found loadlin.exe" + if [ -d /mnt/trinux ] + then + echo " found trinux" + BOOT="/dev/${i}" + BOOTFS="vfat" + echo "BOOT=$BOOT" + echo "$i" > /etc/proc/fixedpkg + LOADLIN="true" + cd / + umount /mnt 2> /dev/null + break + fi + fi + + fi + umount /mnt 2> /dev/null +done + +# Check to see if checking for floppy drive should be disabled + +if grep nofloppy /proc/cmdline > /dev/null +then + NOFLOPPY="true" + echo "Disabling checks for floppy drive" +fi + +######################################################################## +# Determine where Trinux booted from in order of likelihood +# +# /dev/fd0 - floppy (this is normally the case) +# /dev/hd[alpha] - IDE CD-ROM (usually /dev/hdc) +# /dev/hd[numeric] - IDE Hard Disk (including flash disk) +# +# We assume that if a floppy is present and no-› +# +######################################################################## +# +# first check if CD-ROM is present + +if [ "$CDEV" ] +then + echo -n "Attempting to mount CD-ROM at $CDEV:" + + if mount -t iso9660 /dev/${CDEV} /mnt 2> /dev/null > /dev/null + then + echo "successful" + if [ -d /mnt/trinux ] + then + echo "/trinux found on $CDEV" + PKGSRC=$CDEV # we assume packages will be loaded from it + + # Now check and see if we booted from CD-ROM + + if [ -d /mnt/isolinux ] + then + BOOT=/dev/${CDEV} + BOOTFS="iso9660" + NOFLOPPY="true" + echo $CDEV > /etc/proc/fixedpkg + fi + cd / + umount /mnt 2> /dev/null + fi + else + echo "failed" + [ "$UML" ] || BOOT="/dev/fd0" + fi +fi + +if [ ! "$NOFLOPPY" ] +then + echo "Checking for floppy in /dev/fd0" + sleep 1 + + if mount -t vfat /dev/fd0 /boot 2> /dev/null + then + [ -d /boot/bootpkg ] && BOOT="/dev/fd0" + [ -d /boot/tux ] && FLCFG="true" + [ -f /boot/tux/options/floppy ] && PKGSRC="/dev/fd0" + umount /boot 2> /dev/null + + [ "$BOOT" = "/dev/fd0" ] && echo "Trinux booted from a floppy." + [ "$PKGSRC" = "/dev/fd0" ] && echo "Trinux will load packages from one or more floppies." + else + echo "Unable to mount boot floppy" + fi +else + echo "Floppy checking is disabled" +fi + +echo $BOOT > /etc/proc/boot +echo $BOOTFS > /etc/proc/bootfs + +echo +echo "========================" +echo "BOOT: $BOOT" +echo "KERNEL: $KERNEL" +echo -n "CDEV: " + +if [ $CDEV ] +then + echo "$CDEV" +else + echo "none" +fi + +echo -n "FDEV: " + +if [ "$FDEV" ] +then + echo $FDEV +else + echo "none" +fi + + +## Determine boot filesystem type + +if [ "$BOOT" = "/dev/fd0" ] +then + BOOTFS="vfat" +elif [ "$UML" ] +then + BOOTFS="ext2" +elif [ "$BOOT" = "$CDEV" ] +then + BOOTFS="iso9660" +fi + +echo "BOOTFS: $BOOTFS" +echo "========================" +sleep 2 + +#################################################################### +# Determine where packages should be loaded from. By default, Trinux +# will look at /etc/tux/config/pkgsrc otherwise it will look at +# parameters passed from syslinux.cfg (i.e. pkgsrc=/dev/hda1). +# Otherwise Trinux will assume network package loading unlesss +# the network is unable to be configured +#################################################################### + +if grep 'pkg=floppy' /proc/cmdline > /dev/null +then + PKGSRC="/dev/fd0" +fi + +PKGSRC="network" ## Assume network package loading unless... + +##################################################################### +## Mount the boot filesystem +## 1) copy config from tux over +## 2) install kernel module pkgs from kpkg +##################################################################### + +if [ "$UML" ] +then + echo + # mount the host ext2 filesystem RO so initial packages can be installed + mount none /boot -t hostfs -o $UMLROOT,ro +else + mount -o ro -t $BOOTFS $BOOT /boot + VERSION=`cat /boot/version 2> /dev/null` + PS1="Trinux $VERSION> " +fi + +[ "$BOOT" != "/dev/fd0" ] && PREFIX="trinux/" + +cd /boot + +#pwd +#ls -al + +echo "Copying /tux from boot filesystem..." +cp -a ${PREFIX}tux /etc + + +echo "Copying modules from boot filesystem..." + +# support either within /trinux/modules or /trinux/*.o + +cp ${PREFIX}*.o /lib/modules 2> /dev/null +cp ${PREFIX}modules/*.o /lib/modules 2> /dev/null +cp ${PREFIX}modules/*.gz /lib/modules 2> /dev/null + +cd /lib/modules + +for i in `ls *.gz` +do + FNAME=`basename $i .gz` + echo "Uncompressing $i" + gunzip $i + mv $FNAME $FNAME.o +done + +if [ -f /etc/tux/version ] +then + VERSION=`cat /etc/tux/version 2> /dev/null` +else + VERSION="unknown" +fi + +cd /boot +if cd ${PREFIX}kpkg 2> /dev/null +then + echo "Installing kernel module packages from boot device" + for i in `ls` + do + pkgadd $i + echo $i >> /etc/proc/kpkg.installed + done +fi + +######## Store temporary scripts in scripts directory ########### + +if [ -d ${PREFIX}scripts ] +then + echo "Copying local scripts to /bin:" + cd ${PREFIX}scripts + for i in `ls` + do + cp $i /bin/ + chmod u+x /bin/$i + done +fi + +cd / +umount /boot + +echo "Unmounting boot filesystem" + +# load in kernel modules + +#cd /lib/modules + +if [ -f /etc/tux/config/modules ] +then + while read i + do + echo "Installing $i" + insmod /lib/modules/$i 2> /dev/null > /dev/null + done < /etc/tux/config/modules +fi + + +echo "Waiting for modules to settle..." + +sleep 3 + +#### Since modules have already been loaded now is a good +#### time to scour the partitions, checking for devices + +echo "Checking for fixed disks" + +/sbin/chkfixed + +#### Check for a saved fixedpkg to avoid checking all found partitions + +if [ -f /etc/tux/config/fixedpkg ] +then + echo -n "Found previously saved fixed package source: " + FIXEDPKG=`cat /etc/tux/config/fixedpkg` + if [ "$FIXEDPKG" = "cdrom" -o "$FIXEDPKG" = "cd-rom" ] + then + FIXEDPKG=$CDEV + fi + + echo $FIXEDPKG + echo $FIXEDPKG > /etc/proc/fixed +fi + +for i in `cat /etc/proc/fixed` # loop through fixed devices +do + [ -d /${i} ] || mkdir /${i} # create mount point + + for j in `cat /etc/proc/filesystems` # loop through supported fstype + do + #echo -n "Checking $i:" + if mount -o ro -t $j /dev/$i /$i 2> /dev/null > /dev/null + then + #echo " found $j" + echo "$i:$j" >> /etc/tux/config/fstab + umount /dev/$i 2> /dev/null > /dev/null 2> /dev/null + else + echo + fi + done +done + +if [ -f /etc/tux/config/fstab ] +then + echo "The following partitions/filesytems were found:" + cat /etc/tux/config/fstab + cat /etc/tux/config/fstab | sort | uniq > /tmp/fstab + cat /tmp/fstab > /etc/tux/config/fstab +fi + +######### +# Search filesystems for /trinux directories + +if [ -f /etc/proc/fixedpkg ] +then + fixedpkg=`cat /etc/proc/fixedpkg` + echo "/trinux already found on $fixedpkg, aborting search" + mount +else + if [ -f /etc/tux/config/fstab ] + then + for i in `cat /etc/tux/config/fstab` + do + part=`cut -d: -f1 /etc/tux/config/fstab` + fstype=`cut -d: -f2 /etc/tux/config/fstab` + + if mount -t $fstype /dev/${part} /mnt 2> /dev/null + then + echo -n "Checking $part for trinux directory: " + + if [ -d /mnt/trinux/ ] + then + echo " found" + umount /mnt 2> /dev/null + echo $part > /etc/proc/fixedpkg + break + else + echo " not found" + fi + + cd /; umount /mnt 2> /dev/null + else + echo -n "Failed to mount $part" + fi + done + fi +fi + +chmod a+x /etc/tux/init/first 2> /dev/null +if [ -x /etc/tux/init/first ] +then + . /etc/tux/init/first +fi + +################################################################# +################### Ramdisk building stuff ###################### +################################################################# + +if grep ' 2.4' /proc/version 2> /dev/null +then + echo "Found 2.4.x kernel: tmpfs capable" + if [ -f /etc/tux/config/tmpfs ] + then + echo "Using tmpfs" + TMPFS="true" + fi +else + TMPFS="false" +fi + +#### If /etc/tux/config/corefs is present we use that for +#### partitions *other* than root. If fstab is blank then +#### everything is mounted as root. Trinux will attempt to mount +#### to filesystem and will *not* reformat +#### +#### An additional file (/etc/tux/config/suppfs) will be mounted +#### later so that nfs/smbfs can be mounted +#### +#### corefs format +#### partition:mount point:size in Kb:filesystem:options +#### +#### /dev/sda1:/var:512:minix:keep,ro +#### +#### +#### possible filesystems +#### vfat, minix, tmpfs, ram (actually minix) +#### +#### plus anything compiled in your kernel + +if [ -f /etc/tux/config/corefs ] +then + for i in `cat /etc/tux/config/corefs` + do + DEV=`echo $i | cut -d: -f1` + MOUNT=`echo $i | cut -d: -f2` + SIZE=`echo $i | cut -d: -f3` + FSTYPE=`echo $i | cut -d: -f4` + OPTIONS=`echo $i | cut -d: -f5` + + echo "[DEV: $DEV]" + echo "MOUNT: $MOUNT" + echo "SIZE: $SIZE" + echo "FSTYPE: $FSTYPE" + echo "OPTIONS: $OPTIONS" + + if [ ! "$DEV" ] + then + # if no device is specified, assume tmpfs + mount -n -t tmpfs -o size=${SIZE}000 /dev/null $MOUNT + else + mkdir $MOUNT 2> /dev/null + + if grep "$FSTYPE" /proc/filesystems > /dev/null + then + if [ ! "$SIZE" ] + then + + # assume entire partition should formatted + if [ "$FSTYPE" = "minix" ] + then + mkfs.minix $DEV + mount -t minix $DEV $MOUNT + else + echo "Currently only minix is supported: skipping $$DEV" + fi + + fi # not $SIZE + else + # if no FSTYPE is specified, assume minix + mkfs.minix $DEV # 2> /dev/null > /dev/null + mount -t minix $DEV $MOUNT + fi + + fi # no $DEV + done # loop through each line of corefs +else + # + # Autosize ramdisks based on amount of RAM discovered + # + + LIB="" + VAR="" + USR="" + USRLOC="" + HOMEP="" + + echo "RAM: $MEMORY MB" + echo -n "RAM is " + + if [ $MEMORY -lt 16000 ] + then + echo "< 16MB, you may run into problems" + USR="2048" + HOMEP="128" + VAR="512" + PKGMEM="min" + # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP" + elif [ $MEMORY -lt 24000 ] + then + echo "> 16MB" + USR="4096" + HOMEP="256" + VAR="512" + PKGMEM="16" + # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP" + elif [ $MEMORY -lt 32000 ] + then + echo "> 24MB" + USR="8192" + HOMEP="512" + VAR="1024" + PKGMEM="24" + # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP" + elif [ $MEMORY -lt 48000 ] + then + echo "> 32MB" + USR="16384" + HOMEP="1024" + VAR="1024" + LIB="4896" + PKGMEM="32" + + # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP" + elif [ $MEMORY -lt 64000 ] + then + echo "> 48MB" + USR="16384" + LIB="8192" + USRLOC="8192" + HOMEP="2048" + VAR="2048" + PKGMEM="48" + # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP" + elif [ $MEMORY -lt 96000 ] + then + echo "> 64MB" + + LIB="8192" + USR="16384" + USRLOC="16384" + HOMEP="4096" + VAR="2048" + PKGMEM="64" + # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP" + elif [ $MEMORY -lt 128000 ] + then + echo "> 96MB" + LIB="16384" + USR="16384" + USRLOC="32768" + HOMEP="8192" + VAR="4192" + PKGMEM="96" + # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP" + else + echo "> 128MB" + USR="16384" + USRLOC="16384" + HOMEP="16384" + VAR="4192" + PKGMEM="128" + # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP" + fi + + #if [ "$LIB" != "" ] + #then + # echo "Creating /lib" + # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP" + + # if [ "$TMPFS" = "true" ] + # then + # mount -n -t tmpfs -o size=${LIB}000 /dev/null /lib + # else + # mkdir /usr 2> /dev/null + # mkfs.minix /dev/ram3 $LIB 2> /dev/null > /dev/null + # mount -t minix /dev/ram7 /lib + # fi + #fi + + if [ "$USR" != "" ] + then + echo "Creating /usr" + # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP" + + if [ "$TMPFS" = "true" ] + then + mount -n -t tmpfs -o size=${USR}000 /dev/null /usr + else + mkdir /usr 2> /dev/null + mkfs.minix /dev/ram3 $USR 2> /dev/null > /dev/null + mount -t minix /dev/ram3 /usr + fi + fi + + if [ "$USRLOC" -gt 0 ] + then + + echo "Creating /usr/local" + # echo "USR: $USR USRLOC: $USRLOC HOME: $HOMEP" + mkdir /usr/local 2> /dev/null + + if [ "$TMPFS" = "true" ] + then + mount -n -t tmpfs -o size=${USRLOC}000 /dev/null /usr/local + else + mkfs.minix /dev/ram4 $USRLOC 2> /dev/null > /dev/null + mount -t minix /dev/ram4 /usr/local + fi + fi + + if [ "$HOME" != "" ] + then + echo "Creating /home" + mkdir /home 2> /dev/null + if [ "$TMPFS" = "true" ] + then + mount -n -t tmpfs -o size=${HOMEP}000 /dev/null /home + else + mkfs.minix /dev/ram5 $HOMEP 2> /dev/null > /dev/null + mount -t minix /dev/ram5 /home + fi + fi + + # + # Need to add a check for "physical" var + # + + if [ "$VAR" != "" ] + then + echo "Creating /var" + mkdir /var 2> /dev/null + if [ "$TMPFS" = "true" ] + then + mount -n -t tmpfs -o size=${VAR}000 /dev/null /var + else + mkfs.minix /dev/ram5 $VAR 2> /dev/null > /dev/null + mount -t minix /dev/ram6 /var + fi + fi + +fi + +############################################################################ +# +# handle /etc/tux/config/permfs +# +# mount "permanent filesystems" -- for now these should be umounted +# manually to avoid corruption +# +# partition:mount point:filesystem:options +# +############################################################################ + + + + +if [ -f /etc/tux/config/permfs ] +then + echo "Mounting permanent (non-ramdisk) filesystems based on /etc/tux/config/permfs" + + for i in `/etc/tux/config/permfs` + do + DEV=`cat /etc/tux/config/permfs | cut -d":" -f1` + MOUNT=`cat /etc/tux/config/permfs | cut -d":" -f2` + FSTYPE=`cat /etc/tux/config/permfs | cut -d":" -f3` + + if mount -t $FSTYPE $DEV $MOUNT + then + echo "-- $DEV ($FSTYPE) was mounted at $MOUNT" + else + echo "-- $DEV ($FSTYPE) failed to mount at $MOUNT!" + fi + done + + echo "Remember, these must be manually umounted prior to reboot" +fi + +echo "--------------------- FILESYSTEM CONFIGURATION ------------------------" +df +sleep 1 +echo "-----------------------------------------------------------------------" +echo + +################################################################# +# +# Kludgy stuff to do after the filesystems have been created +# +################################################################ + +echo "Creating misc links and directories..." + +mkdir -p /lib/modules/`uname -r` +touch /lib/modules/`uname -r`/modules.dep +mkdir /usr/lib/ 2> /dev/null +ln -sf /lib/terminfo /usr/lib/terminfo +mkdir /usr/home +cd /var +mkdir pkg log spool run 2> /dev/null +cd log +cp /dev/null mtp +cd / +echo + +if [ -f /etc/proc/fixedpkg -o "$UML" ] +then + if [ -f /etc/proc/fixedpkg ] + then + part=`cat /etc/proc/fixedpkg 2> /dev/null` + echo "Trinux packages were found on $part" + PKGSRC=$part + + cat /etc/tux/config/fstab | grep $part | cut -d: -f2 2> /dev/null + + fstype=`cat /etc/tux/config/fstab | grep $part | cut -d: -f2 2> /dev/null` + fi + + ##echo "[PKGSRC] = $PKGSRC" + ##echo "[fstype] = $fstype" + + if [ "$fstype" ] + then + if mount -t $fstype /dev/${part} /mnt 2> /dev/null + then + mounted="true" + fi + fi + + + + if [ "$UML" ] + then + echo -n "Attempting to mount UML host filesystem: " + if mount none /mnt -t hostfs -o $UMLROOT,ro + then + mounted="true" + echo "ok" + else + echo "failed" + fi + fi + + echo "[mounted] = $mounted" + + if [ "$mounted" ] + then + echo "Preparing to load base packages from $part" + if cd /mnt/trinux/bootpkg 2> /dev/null + then + for i in `ls *.tgz 2> /dev/null` + do + pkgadd $i + done + else + "No base packages found, hmmm..." + fi + + echo "Preparing to load kernel packages from $part" + if cd /mnt/trinux/kpkg 2> /dev/null + then + if [ -f /etc/tux/conf/kpkglist ] + then + for i in `cat /etc/tux/conf/pkglist` + do + pkgadd $i + done + else + echo "No kpkglist found, loading everything" + for i in `ls *.tgz 2> /dev/null` + do + if grep $i /etc/proc/kpkg.installed > /dev/null + then + echo "$i is already installed." + else + pkgadd $i + fi + done + + fi + else + echo "Kernel package directory not found on $part!" + fi + + echo "Preparing to load packages from $part" + + if cd /mnt/trinux/pkg 2> /dev/null + then + if [ -f /etc/tux/conf/pkglist ] + then + for i in `cat /etc/tux/conf/pkglist` + do + pkgadd $i + done + + # NOTE: now the desired behavior is to put whatever + # you want to load into bootpkg + # + #else + # echo "No pkglist found, loading everything" + # for i in `ls *.tgz 2> /dev/null` + # do + # pkgadd $i + # done + + fi + else + echo "Package directory not found on $part!" + fi + + cd / + umount /mnt + else + echo -n "Failed to mount $part" + fi +else + ### This should only go for a floppy + ### Load required packages from boot device + ### echo "For some reason we made it here" + + sleep 1 + + if mount -t $BOOTFS $BOOT /boot 2> /dev/null + then + if [ "$PKGSRC" != "$CDEV" ] + then + if cd /boot/bootpkg + then + echo "Installing base packages from boot device" + for i in `ls` + do + pkgadd $i + done + echo + fi + fi + cd / + umount /boot + else + echo "Unable to mount $BOOT on $BOOTFS" + fi + cd / + umount /boot 2> /dev/null +fi + + +[ -x /etc/init.d/pcmcia ] && . /etc/init.d/pcmcia + +sleep 1 + + + + +############### Syslog Configuration ################### + +LOGHOST=`cat /etc/tux/options/loghost 2> /dev/null` +if [ "$LOGHOST" ] +then + if [ "$LOGHOST" = "prompt" ] + then + echo -n "Enter syslog server: " + read $LOGHOST + fi + $REMOTELOG="-R $LOGHOST" +fi + +echo "Starting syslogd" +[ -x /sbin/syslogd ] && syslogd $REMOTELOG + +# +# At this point we have loaded all the packages if a CD-ROM +# boot or package load from fixed partition +# otherwise base packages have been loaded from the +# floppy. We also have any saved config data. Now we attempt +# to configure the network, then load packages from an HTTP/FTP server +# + +chmod a+x /etc/tux/init/prenet 2> /dev/null +if [ -x /etc/tux/init/prenet ] +then + . /etc/tux/init/prenet +fi + + +##### Attempt to initialize networking ####################### + + +ifconfig lo 127.0.0.1 up + + + +# [ "$IPADDR" ] && echo "Network configured successfully" + + +if [ -f /etc/tux/config/eth0 ] +then + /sbin/net-start + IPADDR=`cat /etc/proc/ipaddr 2> /dev/null` +else + echo 'No network configuration found. Type "net-config"' +fi + +if [ -f /etc/tux/config/proxy ] +then + SNARF_PROXY=`cat /etc/tux/config/proxy` + export SNARF_PROXY + echo "Found proxy: $SNARF_PROXY" + echo +fi + +if [ "$PKGSRC" = "network" ] +then + + if [ "$IPADDR" != "" ] + then + echo "The network was succesfully configured" + + [ -f /etc/tux/config/pkglist ] && PKGLIST=`cat /etc/tux/config/pkglist` + + # attempt to connect to servers in /etc/tux/config/server + + #snarf $server | grep tgz | cut -d">" -f3 | cut -d"<" -f1 > /tmp/packages + + #echo "3" > /proc/sys/net/ipv4/tcp_syn_retries + #echo "3" > /proc/sys/net/ipv4/tcp_retries1 + #echo "3" > /proc/sys/net/ipv4/tcp_retries2 + + if [ -f /etc/tux/config/server ] + then + + for SERVER in `cat /etc/tux/config/server` + do + echo "Contacting $SERVER..." + if snarf $SERVER > /dev/null 2> /dev/null + then + getpkg all + # echo; echo "Retrieving base packages from $SERVER" + # for i in $PKGLIST + # do + # getpkg $i $SERVER + # done + + if [ -f /etc/tux/config/kpkglist ] + then + KPKGLIST=`cat /etc/tux/config/kpkglist` + echo "Retrieving Linux $KERNEL packages from $SERVER" + for i in $KPKGLIST + do + getpkg $KERNEL/${i} $SERVER + done + fi + + break + fi + done + fi + else + PKGSRC="/dev/fd0" + fi +fi + +if [ "$PKGSRC" = "/dev/fd0" ] +then + echo -n "Do you have a package disk? " + read response + + until [ "$response" != "y" ] + do + if mount -t vfat -r /dev/fd0 /floppy 2> /dev/null + then + cd /floppy + + if ls *.o > /dev/null 2> /dev/null + then + echo "Copying modules from package disk" + cp *.o /lib/modules 2> /dev/null + cp modules/*.o /lib/modules 2> /dev/null + fi + + for i in *.tgz + do + cd /floppy + pkgadd $i + done + fi + + cd /; umount /floppy + echo -n "Do you have another floppy? " + read response + done + + + #if ifconfig | grep eth0 /dev/null 2> /dev/null + #then + # echo "Network was sucessfully initialized" + #else + #net-start + # fi +else + if echo $PKGSRC | grep "/dev/[sh]d" > /dev/null + then + echo "Packages will be loaded from fixed disk: $PKGSRC" + fi +fi + + +if [ -x /etc/tux/init/postnet ] +then + chmod a+x /etc/tux/init/postnet 2> /dev/null + . /etc/tux/init/postnet +fi + +# Install modules that end up in /lib/modules +# this will include any on the boot disk +# +# Consult /etc/tux/config/modules for any parameters +# (i.e. irq's io's for NIC modules +# + +# This should be moved to /etc/init.d/system + +echo "Enabling port scan (scanlogd)" +[ -x /sbin/scanlogd ] && scanlogd + + +### Fix the linker/library stuff +if [ -x /usr/sbin/ldconfig ] +then + echo "Rebuilding ld.so.cache one last time" + ldconfig -v 2> /dev/null > /dev/null +else + echo "Unable to rebuild run-time link bindings" +fi + + +chmod a+x /etc/tux/init/prepkg 2> /dev/null +if [ -x /etc/tux/init/prepkg ] +then + . /etc/tux/init/prepkg +fi + +[ -x /usr/bin/bash ] && ln -sf /usr/bin/bash /bin/sh + + + +## This needs to be fixed *bad* + +##/sbin/loadmodules # load any last minute kernel modules + +chmod a+x /etc/tux/init/last 2> /dev/null +if [ -x /etc/tux/init/last ] +then + . /etc/tux/init/last +fi + +# Increasing syn_retries to something more reasonable +echo "7" > /proc/sys/net/ipv4/tcp_syn_retries + +###################################################################### +# Set up swap space +###################################################################### + +SWAPCONF=`cat /etc/tux/config/swap 2> /dev/null` + +if [ "$SWAPCONF" ] +then + echo "Configuring swap space" + + [ -x /sbin/mkswap ] || getpkg swaputil + + SWAPFILE=`echo $SWAPCONF | cut -d: -f1` + SWAPSIZE=`echo $SWAPCONF | cut -d: -f2` + + [ "$SWAPSIZE" ] || SWAPSIZE=8192 # default to 8MB swap + + if echo "$SWAPFILE" | grep "dev" > /dev/null + then + # user specified a partition + echo "Attempting to use $SWAPFILE for swap partition" + else + echo "Using $SWAPFILE as your swap file" + dd if=/dev/zero of=$SWAPFILE bs=512 count=$SWAPSIZE + fi + + mkswap $SWAPFILE + swapon $SWAPFILE + free +fi + + +#### + +if [ -f /etc/tux/config/ipfwd ] +then + echo "Enabling IP forwarding" + echo "1" > /proc/sys/net/ipv4/ip_forward +fi + +if [ -f /etc/tux/config/noping ] +then + echo "1" > /proc/sys/net/ipv4/icmp_echo_ignore_all +fi + + + +#### This stuff should all get moved to the system direcotry ###### +### +#### Notify any emails addr in /etc/tux/options/mailmon that you're up + +if [ -f /etc/tux/config/monitor/smtp ] +then + for ADDR in `cat /etc/tux/config/emaildst` + do + echo | mail $ADDR UP + done +fi + +if [ -f /etc/tux/config/monitor/http ] +then + webmon + # add to crontab + echo '0,10,20,30,40,50 * * * * /usr/sbin/webmon' >> /etc/tux/config/crontab +fi + +if [ -f /etc/tux/config/monitor/cdp ] +then + echo "Starting CDP (Cisco Discovery Protocol)" + echo '* * * * * /usr/sbin/cdpdump' >> /etc/tux/config/crontab +fi + + +if [ -f /etc/tux/config/crontab ] +then + if /usr/sbin/crond 2> /dev/null + then + echo "Starting crond" + sort /etc/tux/config/crontab | uniq > /tmp/crontab 2> /dev/null + cat /tmp/crontab > /etc/tux/config/crontab 2> /dev/null + /usr/sbin/crontab /etc/tux/config/crontab 2> /dev/null + crontab -l + echo + else + echo "Unable to start crond" + fi +else + echo "No crontab config found, not starting" +fi + +### Erase /floppy/tux/options/console to disable console access +### +##if [ -f /etc/tux/options/console ] +##then +## [ -f /etc/tux/config/home ] && gethome +##else +## grep -v askfirst /etc/inittab > /etc/inittab.new +## rm /etc/inittab +## mv /etc/inittab.new /etc/inittab +##fi + +### Add a hack for dropbear with fixed partition + + +# check for custom /etc/inittab + +if [ -f /etc/tux/config/inittab ] +then + echo "Found custom inittab" + cp /etc/tux/config/inittab /etc/inittab +else + echo "Using default inittab" +fi + +if [ -x /etc/init.d/dropbear ] +then + killall dropbear >2 + echo "Restarting dropbear" + /etc/init.d/dropbear +fi + +### This shouldn't be necessary, but just in case + +if [ -x /usr/local/sbin/sshd ] +then + if ps | grep -v sshd > /dev/null + then + echo "SSH server failed to start, trying again" + /etc/init.d/opensshd + fi +fi + +cat /README | tr '\t' ' ' > /usr/doc/trinux + +################################################################# + +sleep 1 +clear +echo -n "Welcome to Trinux: A Linux Security Toolkit" +if [ "$VERSION" ] +then + echo -n " (version " + echo -n $VERSION + echo ")" +fi +echo +echo "Type 'man' for a list of help topics or 'man trinux' for docs." +echo "ALT- allows you to view other virtual terminals. " +echo diff --git a/urunlevel/my_linux/Trinux/loadmodules b/urunlevel/my_linux/Trinux/loadmodules new file mode 100755 index 0000000..69c28ad --- /dev/null +++ b/urunlevel/my_linux/Trinux/loadmodules @@ -0,0 +1,30 @@ +#!/bin/sh + +ls /lib/modules/*.o > /tmp/modules.in 2> /dev/null +ls /usr/local/lib/modules/*.o >> /tmp/modules.in 2> /dev/null + +sort /tmp/modules.in | uniq > /tmp/modules + +for module in `cat /tmp/modules` +do + base=`basename $module` + naked=`basename $base .o` + + + #echo "base: $base" + #echo "naked: $naked" + + + if grep $naked /etc/tux/config/modules 2> /dev/null + then + param=`grep $naked /etc/tux/config/modules | cut -d' ' -f2- 2> /dev/null` + echo "Loading $module $param" + if insmod $module $param 2> /dev/null + then + echo $module >> /etc/proc/modules.in + else + echo $module >> /etc/proc/modules.out + fi + fi +done + diff --git a/urunlevel/my_linux/Trinux/net-config b/urunlevel/my_linux/Trinux/net-config new file mode 100755 index 0000000..2b85baa --- /dev/null +++ b/urunlevel/my_linux/Trinux/net-config @@ -0,0 +1,18 @@ +#!/bin/sh + +echo "By default Trinux configures eth0 via DHCP" +found_faces=`dmesg | grep eth[0-9]: | cut -d: -f1` + + +# Check for pcmcia +if lsmod | grep pcmcia_core > /dev/null 2> /dev/null +then + echo "PCMCIA modules running" + if ifconfig $face | grep UP > /dev/null 2> /dev/null + then + echo "PCMCIA interface already configured: exiting..." + exit + else + echo "PCMCIA interface was not configured: trying again" + fi +fi diff --git a/urunlevel/my_linux/Trinux/net-start b/urunlevel/my_linux/Trinux/net-start new file mode 100755 index 0000000..a090d85 --- /dev/null +++ b/urunlevel/my_linux/Trinux/net-start @@ -0,0 +1,141 @@ +#!/bin/sh +# net-start +# +# can also be run via "start net" or "start network" +# + + +# find which dhcp client + + +if [ -x /usr/sbin/dhcpcd ] +then + DHCPCLIENT="/usr/sbin/dhcpcd" +elif [ -x /sbin/udhcpc ] +then + DHCPCLIENT="/sbin/udhcpc" +else + echo "No DHCP client found!" +fi + +/sbin/net-stop # bring down any interfaces and kill dhcp clients + +[ -d /etc/proc ] || mkdir /etc/proc + +probed=`dmesg | grep eth[0-9]: | cut -d: -f1` + +cd /etc/tux/config/ +found_faces=`ls eth*` + +echo "Found configs for: $found_faces" + +# first bring up interfaces + +for i in $found_faces +do + echo -n "Configuring $i:" + + if grep dhcp /etc/tux/config/$i > /dev/null 2> /dev/null + then + DHCP="true" + # things are really easy we just do dhcp + echo " using DHCP" + killall dhcpcd 2> /dev/null + sleep 1 + if [ $DHCPCLIENT = "/usr/sbin/dhcpcd" ] + then + $DHCPCLIENT $i 2> /dev/null + else + $DHCPCLIENT -i $i 2> /dev/null + fi + + else # static IP + + if [ -f /etc/tux/config/$i ] + then + echo "settings found" + IP=`cut -d" " -f1 /etc/tux/config/$i` + MASK=`cut -d" " -f2 /etc/tux/config/$i` + + if [ "$IP" ] + then + ifconfig $i $IP netmask $MASK up + fi + + else + echo "no settings found, skipping..." + fi + fi + + + if [ "$i" = "eth0" ] + then + ifconfig $face | grep inet | cut -d":" -f2 | cut -d" " -f1 | grep -v 127.0.0.1 > /etc/proc/ipaddr + ln -sf /etc/proc/ipaddr /etc/proc/$i + nslookup `cat /etc/proc/ipaddr` | grep -v default | grep Name | cut -d":" -f2 | tr -d ' ' | tail -n 1 > /etc/proc/hostname + fi + +done + +if [ "$DHCP" ] +then + echo "Skipping DNS and gateway config" +else + echo -n "Adding default route: " + + GW=`cat /etc/tux/config/gateway` + + echo "$GW" + if [ "$GW" ] + then + route add default gw $GW + echo "done" + else + echo "failed" + fi + + echo -n "Builing /etc/resolv.conf (DNS): " + # need to fix this for multiple DNS servers + + DNS=`cat /etc/tux/config/dns 2>/dev/null` + + if [ "$DNS" ] + then + echo "nameserver $DNS" > /etc/resolv.conf + else + echo "failed" + fi +fi + + +# update /etc/hosts and set HOSTNAME + +IPADDR=`cat /etc/proc/ipaddr` + +if [ -f /etc/tux/config/hostname ] +then + HOSTNAME=`cat /etc/tux/config/hostname` +else + HOSTNAME=`cat /etc/proc/hostname` + hlen=`length "$HOSTNAME"` + + if [ "$hlen" -lt 1 ] + then + HOSTNAME='trinux' + fi +fi + +echo "Setting hostname: $HOSTNAME" +hostname $HOSTNAME + +echo "Building /etc/hosts" +if [ -f /etc/tux/config/hosts ] +then + cp /etc/tux/config/hosts /etc/hosts +fi + +echo "127.0.0.1 localhost" >> /etc/hosts +echo "$IPADDR $HOSTNAME" >> /etc/hosts + +sleep 3 + diff --git a/urunlevel/my_linux/Trinux/net-stop b/urunlevel/my_linux/Trinux/net-stop new file mode 100755 index 0000000..4b60457 --- /dev/null +++ b/urunlevel/my_linux/Trinux/net-stop @@ -0,0 +1,11 @@ +#!/bin/sh + +killall udhcpcd 2> /dev/null +killall dhcpcd 2> /dev/null +killall pump 2> /dev/mull + +for i in `grep eth /proc/net/dev | cut -d: -f1` +do + echo "Bringing down $i" + ifconfig $i down 2> /dev/null +done diff --git a/urunlevel/my_linux/Trinux/pkgadd b/urunlevel/my_linux/Trinux/pkgadd new file mode 100755 index 0000000..f04834b --- /dev/null +++ b/urunlevel/my_linux/Trinux/pkgadd @@ -0,0 +1,62 @@ +#!/bin/sh +# +# pkgadd - adds trinux packages (c) 1999 OpenSEC under GPL +# +# Author: Matthew Franz +# +# $1 = name of package +# +########################################################################## + +if [ $# -ne 0 ] +then + rm /*.tgz 2> /dev/null; rm /*.md5 2> /dev/null + + # accepting package name with/without tarball extension + + if echo $1 | grep -v tgz > /dev/null + then + FILE="$1.tgz" + else + FILE=$1 + fi + + PREFIX=`echo $FILE | cut -d"." -f1` + + if [ -f $FILE ] + then + echo "Adding $FILE" + PF=`pwd` + #cp $FILE /; cd / + cd / + gunzip -c $PF/${FILE} | tar xf - + + if [ -f /etc/init.d/${PREFIX} ] + then + chmod a+x /etc/init.d/${PREFIX} 2> /dev/null + echo; echo "Initializing package: $PREFIX" + /etc/init.d/${PREFIX} 2> /dev/null + elif [ -f /etc/init.m/${PREFIX} ] + then + chmod a+x /etc/init.m/${PREFIX} 2> /dev/null + echo; echo "Initializing module: $PREFIX" + /etc/init.m/${PREFIX} 2> /dev/null + fi + +# base=`echo $FILE | cut -d"." -f1` +# tar xf $base.tar + + #rm $FILE + + [ -x /etc/pkg/$PREFIX ] && ./etc/pkg/$PREFIX + else + echo "$FILE not found" + fi + +else # no parameters !! + echo "Usage: " + echo ' pkgadd filename[.tgz] ' + echo +fi + + diff --git a/urunlevel/my_linux/Trinux/pkglist b/urunlevel/my_linux/Trinux/pkglist new file mode 100755 index 0000000..0fc82b0 --- /dev/null +++ b/urunlevel/my_linux/Trinux/pkglist @@ -0,0 +1,12 @@ +#!/bin/sh + +if [ -f /etc/tux/config/server ] +then + SERVER=`cat /etc/tux/config/server` +else + SERVER="http://trinux.sf.net/pkg" +fi + +snarf $SERVER - | cut -d'"' -f6 | grep "tgz" | sort | more + + diff --git a/urunlevel/my_linux/Trinux/quit b/urunlevel/my_linux/Trinux/quit new file mode 100755 index 0000000..555644b --- /dev/null +++ b/urunlevel/my_linux/Trinux/quit @@ -0,0 +1,10 @@ +#!/bin/sh + +echo "Preparing for reboot..." + +savehome +savecfg +sync +sync +sync +reboot diff --git a/urunlevel/my_linux/Trinux/rmpkg b/urunlevel/my_linux/Trinux/rmpkg new file mode 100755 index 0000000..28e105a --- /dev/null +++ b/urunlevel/my_linux/Trinux/rmpkg @@ -0,0 +1,24 @@ +#!/bin/sh + +if [ ! "$1" ] +then + echo "No package specified"; exit +fi + +if [ -f /var/pkg/contents/$1 ] +then + + echo "Deleting $1:" + + for i in `cat /var/pkg/contents/$1` + do + if echo $i | grep -v "\/$" 2> /dev/null + then + rm /${i} 2> /dev/null + fi + done + + rm /var/pkg/contents/$1 2> /dev/null +else + echo "/var/pkg/contents/$1 does not exist!" +fi diff --git a/urunlevel/my_linux/Trinux/save-config b/urunlevel/my_linux/Trinux/save-config new file mode 100755 index 0000000..587728b --- /dev/null +++ b/urunlevel/my_linux/Trinux/save-config @@ -0,0 +1,38 @@ +#!/bin/sh + +echo +echo "Trinux will save configuration information to the /tux directory" +echo "on a DOS formatted floppy or to C:\trinux\tux\ if you booted " +echo "from a fixed disk using loadlin" + +if [ -f /etc/proc/boot ] +then + BOOT=`cat /etc/proc/boot` +else + BOOT="/dev/fd0" +fi + +echo +echo "Boot device: $BOOT" + +if [ "$BOOT" = "/dev/fd0" ] +then + echo -n "Please enter your boot/config floppy, then hit return: " + read blah +else + PREFIX="/trinux" +fi + +if mount -t vfat $BOOT /boot +then + echo "Backing up old configuration" + cd /boot${PREFIX} + rm -r tux.bak 2> /dev/null + mv tux tux.bak + cp -a /etc/tux . + + echo "Unmounting $BOOT" + cd /; umount /boot +else + echo "Unable to mount boot device!" +fi diff --git a/urunlevel/my_linux/Trinux/savecfg b/urunlevel/my_linux/Trinux/savecfg new file mode 100755 index 0000000..587728b --- /dev/null +++ b/urunlevel/my_linux/Trinux/savecfg @@ -0,0 +1,38 @@ +#!/bin/sh + +echo +echo "Trinux will save configuration information to the /tux directory" +echo "on a DOS formatted floppy or to C:\trinux\tux\ if you booted " +echo "from a fixed disk using loadlin" + +if [ -f /etc/proc/boot ] +then + BOOT=`cat /etc/proc/boot` +else + BOOT="/dev/fd0" +fi + +echo +echo "Boot device: $BOOT" + +if [ "$BOOT" = "/dev/fd0" ] +then + echo -n "Please enter your boot/config floppy, then hit return: " + read blah +else + PREFIX="/trinux" +fi + +if mount -t vfat $BOOT /boot +then + echo "Backing up old configuration" + cd /boot${PREFIX} + rm -r tux.bak 2> /dev/null + mv tux tux.bak + cp -a /etc/tux . + + echo "Unmounting $BOOT" + cd /; umount /boot +else + echo "Unable to mount boot device!" +fi diff --git a/urunlevel/my_linux/Trinux/savehome b/urunlevel/my_linux/Trinux/savehome new file mode 100755 index 0000000..837c639 --- /dev/null +++ b/urunlevel/my_linux/Trinux/savehome @@ -0,0 +1,79 @@ +#!/bin/sh + +# savehome - saves home directory to + +if [ "$1" ] +then + home=$1 +else + home="home" +fi + + + +if [ -f /etc/tux/config/home ] +then + PROTO=`cut -d':' -f1 /etc/tux/config/home` + HOST=`cut -d':' -f2 /etc/tux/config/home` + USER=`cut -d':' -f3 /etc/tux/config/home` +else + echo -n "ftp or ssh: " + read PROTO + echo -n "Host: " + read HOST + echo -n "User: " + read USER + echo $PROTO:$HOST:$USER > /etc/tux/config/home +fi + +[ -d /usr/local/tmp ] || mkdir -p /usr/local/tmp + +cd / +tar cf - home | gzip -f > /usr/local/tmp/$home.tgz +echo "Saving home directory to $USER@$HOST via $PROTO" + +cd /usr/local/tmp + +if [ "$PROTO" = "ssh" ] +then + scp $home.tgz $USER@$HOST:~ +fi + +if [ "$PROTO" = "ftp" ] +then + echo "Using FTP to transfor $home.tgz -- your passwords are sniffable" + if [ -x /usr/bin/curl ] + then + curl -u $USER -T $home.tgz ftp://$HOST + + else + echo "Curl is not installed. You will have to login with your" + echo "username and upload $home.tgz manually" + + ftp $HOST + + fi +fi + +if [ "$PROTO" = "fixed" ] +then + if mount -t $PROTO $HOST /mnt + then + [ "$USER" ] && cd /mnt/$USER + cp /usr/local/tmp/$home.tgz . + cd / + umount /mnt + fi +fi + +if [ "$PROTO" = "floppy" ] +then + if mount -t vfat /dev/fd0 /mnt + then + cp /usr/local/tmp/$home.tgz /mnt + cd / + umount /mnt + else + echo "Unable to mount floppy" + fi +fi diff --git a/urunlevel/my_linux/Trinux/update b/urunlevel/my_linux/Trinux/update new file mode 100755 index 0000000..ebeff6b --- /dev/null +++ b/urunlevel/my_linux/Trinux/update @@ -0,0 +1,62 @@ +#!/bin/sh + +if [ ! "$*" ] +then + echo + echo "Usage: " + echo " update [kernel|initrd|pkglist]" + exit +fi + + +if [ -f /etc/proc/boot ] +then + BOOT=`cat /etc/proc/boot` +else + BOOT="/dev/fd0" +fi + +echo +echo "Boot device: $BOOT" + +if [ "$BOOT" = "/dev/fd0" ] +then + echo -n "Please enter your boot/config floppy, then hit return: " + read blah +else + PREFIX="/trinux" +fi + +if mount -t vfat $BOOT /boot +then + if echo $* | grep "initrd" + then + INITRD=`cat /etc/tux/config/src/initrd` + if [ "$INITRD" ] + then + echo "Updating initrd from $INITRD" + cd /tmp + if snarf $INITRD + then + echo -n "Are you sure? " + read quest + if [ "$quest" != "n" ] + then + echo "Deleting existing initrd.gz" + cd /boot/$PREFIX + ls -al + rm initrd.gz + mv /tmp/initrd.gz . + fi + fi + else + echo "No initrd found" + fi + fi + + sync + echo "Unmounting $BOOT" + cd /; umount /boot +else + echo "Unable to mount boot device!" +fi diff --git a/urunlevel/my_linux/bootrc b/urunlevel/my_linux/bootrc new file mode 100644 index 0000000..e69de29 diff --git a/urunlevel/my_linux/getpkg.c b/urunlevel/my_linux/getpkg.c new file mode 100644 index 0000000..9127c45 --- /dev/null +++ b/urunlevel/my_linux/getpkg.c @@ -0,0 +1,240 @@ +/* + * Mini getpkg implementation for busybox. + * + * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include +#include +#include +#include /* for uname(2) */ + +#include "busybox.h" +#include "lib_init_d.h" +#include "my_linux.h" + + +#define GETPKG_OPT_ALL 1 +#define GETPKG_OPT_FILE 2 +#define GETPKG_OPT_KERNEL 4 + + +void init_package(char *temp) +{ + if (stat(temp, &path_stat) == 0) + { + doit(0, "chmod a+x %s 2> /dev/null", temp); + bb_printf("Initializing %s\n", temp); + doit(0, "%s 2> /dev/null", temp); + } +} + + +static char *DEFAULT_PACKAGES = +"LIB\n" +"system\n" +"baselib\n" +"term\n" +"modutil\n" +"swaputil\n" +"bash2\n" +"pthread\n" +"mc\n" +"ext2tools\n" +"sysutil\n" +"fileutil\n" +"diskutil\n" +"modutils\n" +"portmap\n" +"openssh\n" +"links"; + +static char *DEFAULT_SERVERS = +"ftp://0.0.0.0/distros/Linux-on-net/Trinux/pkg/\n" +"ftp://192.168.146.25/distros/Linux-on-net/Trinux/pkg/\n" +"http://0.0.0.0/ftp/distros/Linux-on-net/Trinux/pkg/\n" +"http://www.trinux.org/pkg/\n" +"http://www.io.com/~mdfranz/trinux/pkg/"; + +static char *DEFAULT_PATHS = +"/trinux/pkg\n" +"/trinux/bootpkg\n" +"/trinux/kpkg\n" +"/trinux\n" +"/pkg"; + +static llist_t *package_head = NULL; /* growable list of packages */ +static llist_t *source_head = NULL; /* growable list of sources */ + + +int get_package(int opt, char *source, char *package, const char *KERNEL) +{ + int result = 0; + int incomplete = 0; + char *PACKAGE = 0; + char *PRE = 0; + char *temp = ""; + + if (strcmp(&package[bb_strlen(package) - 4], ".tgz") != 0) + temp = ".tgz"; + + bb_xasprintf(&PACKAGE, "%s%s%s", KERNEL, package, temp); + bb_xasprintf(&PRE, "%s%s", KERNEL, package); + + if (opt & GETPKG_OPT_FILE) + { + temp = concat_path_file(source, PACKAGE); + free(PACKAGE); + PACKAGE = temp; + bb_printf("Installing %s\n", PACKAGE); + } + else + { + char *URL; + + temp = concat_path_file("/tmp", PACKAGE); + bb_xasprintf(&URL, "%s%s", source, PACKAGE); + free(PACKAGE); + PACKAGE = temp; + +//bb_printf("Retrieving %s\n", URL); + doit(0, "wget -O %s %s", PACKAGE, URL); + if (errno) + incomplete = 1; + + free(URL); + } + + temp = ""; + if ((incomplete == 0) && (stat(PACKAGE, &path_stat) == 0)) + { + bb_xasprintf(&temp, doit(0, "gunzip -c %s | tar xvf -", PACKAGE)); + result = 1; + if (!(opt & GETPKG_OPT_FILE)) + remove_file(PACKAGE, FILEUTILS_FORCE); + } + doit(0, "echo \"%s\" > /var/lib/my_linux/contents/%s", temp, PRE); + + if (result) + { + free(temp); + bb_xasprintf(&temp, "/etc/init.d/%s", PRE); + init_package(temp); + temp[10] = 'm'; + init_package(temp); + free(temp); + bb_xasprintf(&temp, "/etc/pkg/%s", PRE); + init_package(temp); + } + + free(temp); + free(PACKAGE); + return result; +} + + +int getpkg_main(int argc, char **argv) +{ + int i; + unsigned long opt; + char *PACKAGE = 0; + char *KERNEL = ""; + char *SRC = 0; + char *token; + char *strtok_temp; + + opt = bb_getopt_ulflags(argc, argv, "afk"); + + if (argv[optind]) + PACKAGE = argv[optind++]; + if (argv[optind]) + SRC = argv[optind++]; + if (PACKAGE == 0) + opt |= GETPKG_OPT_ALL; + if (opt & GETPKG_OPT_KERNEL) + { + struct utsname name; + + if (uname(&name) == -1) + bb_perror_msg_and_die("cannot get system information"); + bb_xasprintf(&KERNEL, "%s/", name.release); + } + + if (opt & GETPKG_OPT_ALL) + { + if (PACKAGE != 0) + { + SRC = PACKAGE; + PACKAGE = 0; + } + PACKAGE = quick_read("/var/lib/my_linux/config/pkglist"); + if ((PACKAGE == 0) || (PACKAGE[0] == '\0')) + { + PACKAGE = (char *) xmalloc (sizeof (char) * bb_strlen(DEFAULT_PACKAGES) + 1); + strcpy(PACKAGE, DEFAULT_PACKAGES); + } + } + + if (SRC == 0) + { + SRC = quick_read("/var/lib/my_linux/config/server"); + if ((SRC == 0) || (SRC[0] == '\0')) + { + if (opt & GETPKG_OPT_FILE) + token = DEFAULT_PATHS; + else + token = DEFAULT_SERVERS; + SRC = (char *) xmalloc (sizeof (char) * bb_strlen(token) + 1); + strcpy(SRC, token); + } + } + + token = strtok_r(PACKAGE, " \r\n", &strtok_temp); + for (i = 0; token != NULL; i++) + { + package_head = llist_add_to_end(package_head, token); + token = strtok_r(NULL, " \r\n", &strtok_temp); + } + + token = strtok_r(SRC, " \r\n", &strtok_temp); + for (i = 0; token != NULL; i++) + { + source_head = llist_add_to_end(source_head, token); + token = strtok_r(NULL, " \r\n", &strtok_temp); + } + + + llist_t *package_current = package_head; + while (package_current) + { + int found = 0; + llist_t *source_current = source_head; + + while (source_current) + { + if ((found = get_package(opt, source_current->data, package_current->data, KERNEL))) + break; + source_current = source_current->link; + } + + package_current = package_current->link; + } + + return EXIT_SUCCESS; +} diff --git a/urunlevel/my_linux/inittab b/urunlevel/my_linux/inittab new file mode 100644 index 0000000..2f90616 --- /dev/null +++ b/urunlevel/my_linux/inittab @@ -0,0 +1,17 @@ +::sysinit:/sbin/rcS +#tty1::respawn:/sbin/getty 38400 tty1 +#tty2::respawn:/sbin/getty 38400 tty2 +tty1::respawn:/sbin/getty -inl /usr/sbin/tw1 38400 tty1 +tty2::respawn:/sbin/getty -inl /usr/sbin/tw2 38400 tty2 +tty3::respawn:/sbin/getty -inl /usr/sbin/tw3 38400 tty3 +tty4::respawn:/sbin/getty -inl /usr/sbin/tw4 38400 tty4 +#tty5::respawn:/usr/X11R6/bin/X +tty9::once:/sbin/rc +tty10::respawn:/bin/tail -f /var/log/messages +tty11::once:/bin/dmesg +tty11::respawn:/sbin/klogd -n +::ctrlaltdel:/sbin/reboot +::shutdown:/sbin/rc 0 +::shutdown:/sbin/swapoff -a +::shutdown:/bin/umount -a -r +::restart:/sbin/init diff --git a/urunlevel/my_linux/lib_init_d.h b/urunlevel/my_linux/lib_init_d.h new file mode 100644 index 0000000..13253e9 --- /dev/null +++ b/urunlevel/my_linux/lib_init_d.h @@ -0,0 +1,183 @@ +/* + * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#ifndef _INIT_D_H +#define _INIT_D_H + + +/* + * init script defines + */ + +#define INIT_D_COMMENT "\n#// " +#define INIT_D_BEGIN "\n### BEGIN INIT INFO " +#define INIT_D_PROV "\n# Provides: " +#define INIT_D_RSTART "\n# Required-Start: " +#define INIT_D_RSTOP "\n# Required-Stop: " +#define INIT_D_SSTART "\n# Should-Start: " +#define INIT_D_SSTOP "\n# Should-Stop: " +#define INIT_D_DSTART "\n# Default-Start: " +#define INIT_D_DSTOP "\n# Default-Stop: " +#define INIT_D_SDESC "\n# Short-Description: " +#define INIT_D_DESC "\n# Description: " +#define INIT_D_CONT "\n#\t" +#define INIT_D_CONT2 "\n# " +#define INIT_D_END "\n### END INIT INFO\n" +#define INIT_D_CUSTOM "\n# X-" + + +/* + * init info + */ + +typedef struct init_d_info_s { + char **provides; + char **reqstart; + char **reqstop; + char **shouldstart; + char **shouldstop; + int *defstart; + int *defstop; + char *shortdesc; + char *desc; + char *comment; + int sizes[11]; + char *path; + llist_t *start; +} init_d_info_t; + + +/* + * init commands + */ + +typedef struct init_d_handle_s { + int (*start)(struct init_d_handle_s *); + int (*stop)(struct init_d_handle_s *); + int (*restart)(struct init_d_handle_s *); + int (*try_restart)(struct init_d_handle_s *); + int (*reload)(struct init_d_handle_s *); + int (*force_reload)(struct init_d_handle_s *); + int (*status)(struct init_d_handle_s *, int); + int (*show_info)(struct init_d_handle_s *); + char *basename; + char *pathname; + char *args; + char *pidfile; + char *info; +} init_d_handle_t; + + +int do_init_from_main(int argc, char **argv, struct init_d_handle_s *init_d); +int do_init(struct init_d_handle_s *init_d, const char *command); + +int default_start(struct init_d_handle_s *); +int default_stop(struct init_d_handle_s *); +int default_restart(struct init_d_handle_s *); +int default_try_restart(struct init_d_handle_s *); +int default_reload(struct init_d_handle_s *); +int default_force_reload(struct init_d_handle_s *); +int default_status(struct init_d_handle_s *, int); +int default_show_info(struct init_d_handle_s *); + +int no_stop(struct init_d_handle_s *); +int no_reload(struct init_d_handle_s *); +int no_status(struct init_d_handle_s *, int); + +/* + * error codes + */ + +#define INIT_D_OK 0 +#define INIT_D_ERROR_GENERIC 1 +#define INIT_D_ERROR_ARGS 2 +#define INIT_D_ERROR_NOT_IMPLEMENTED 3 +#define INIT_D_ERROR_SECURITY 4 +#define INIT_D_ERROR_NOT_INSTALLED 5 +#define INIT_D_ERROR_NOT_CONFIGURED 6 +#define INIT_D_ERROR_NOT_RUNNING 7 + + +/* + * status codes + */ + +#define INIT_D_STATUS_OK 0 +#define INIT_D_STATUS_DEAD_PID 1 +#define INIT_D_STATUS_DEAD_LOCK 2 +#define INIT_D_STATUS_NOT_RUNNING 3 +#define INIT_D_STATUS_UNKNOWN 4 + + +/* + * /lib/lsb/init-functions + */ +int start_daemon(int force, int nice_level, char *pidfile, char *pathname, char *args); +int killproc(char *pidfile, char *pathname, int my_signal); +int checkpid(char *pid); +int pidofproc(char *pidfile, char *pathname, char **pids); +void log_success_msg(char *message); +void log_failure_msg(char *message); +void log_warning_msg(char *message); + + +#define REDIR 1 +#define QUIET 2 +#define ERRONLY 4 +#define FORK 8 +#define NOFORK 16 +#define DAEMON 32 + +extern struct stat path_stat; + +typedef struct nodes_s +{ + const char *name; + mode_t mode; + int major; + int minor; + int count; +} nodes_t; + + +char *argv_cat(int argc, char **argv); +char *big_chomp(char *s); +int checkpid(char *pid); +char *doit(int mode, char *command, ...); + +#ifndef CONFIG_IFUPDOWN +#define RUNLEVEL_LIST 1 +#endif +#ifdef RUNLEVEL_LIST +// From ifupdown, so it should probably be in libbb. +llist_t *llist_add_to_end(llist_t *list_head, char *data); +#else +extern llist_t *llist_add_to_end(llist_t *list_head, char *data); +#endif + +llist_t *llist_delete(llist_t **unsorted, llist_t *previous, llist_t *current); +void make_disk(char *token, const nodes_t *nodes); +void make_ram_disk(int size, int number, char *place, int TMPFS); +void quick_mount(char *type, char *device, char *path, char *data, ...); +char *quick_read(char *filename); +void quick_write(const char *filename, const char *data, ...); + + +#endif diff --git a/urunlevel/my_linux/linuxrc.c b/urunlevel/my_linux/linuxrc.c new file mode 100644 index 0000000..15fba1a --- /dev/null +++ b/urunlevel/my_linux/linuxrc.c @@ -0,0 +1,829 @@ +/* + * Mini linuxrc implementation for busybox. + * An implementation of the linuxrc boot script. + * + * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include /* for uname(2) */ + +#include "busybox.h" +#include "lib_init_d.h" +#include "my_linux.h" + + +const static char *directories[] = +{ + "boot", + "dev/pts", + "dev/input", + "lib", + "media/ROOT", + "media/cdrom", + "media/floppy", + "mnt", + "opt", + "proc", + "sbin", + "sys", + "udev", + "usr/bin", + "usr/etc/init.d", + "usr/lib", + "usr/sbin", + "var/cache", + "var/etc/network/if-down.d", + "var/etc/network/if-post-down.d", + "var/etc/network/if-pre-up.d", + "var/etc/network/if-up.d", + "var/etc/sysconfig", + "var/home/root", + "var/lib/misc", + "var/lib/network", + "var/lib/my_linux/init.m/done", + "var/lib/my_linux/pkg", + "var/lib/my_linux/config", + "var/lib/my_linux/contents", + "var/log", + "var/spool/cron/crontabs", + "var/temp", + "var/tmp", +#ifdef CONFIG_FEATURE_FULL_LSB + "boot/grub", + "bin", + "dev/net", + "etc/X11", + "etc/cron.d", + "etc/cron.daily", + "etc/cron.fortnightly", + "etc/cron.hourly", + "etc/cron.monthly", + "etc/cron.weekly", + "etc/cups", + "etc/opt", + "etc/sgml", + "etc/udev", + "lib/lsb", + "lib/modules/2.6.9/kernel", + "opt/bin", + "opt/doc", + "opt/include", + "opt/info", + "opt/lib", + "opt/man", + "usr/X11R6", + "usr/X11R6/bin", + "usr/X11R6/include/X11", + "usr/X11R6/lib/X11", + "usr/X11R6/man/en/man8", + "usr/doc", + "usr/games", + "usr/i386-linux-uclibc/include", + "usr/i386-linux-uclibc/lib", + "usr/i386-linux-uclibc/games", + "usr/i386-linux-uclibc/lsb", + "usr/include/bsd", + "usr/local/bin", + "usr/local/games", + "usr/local/i386-linux-uclibc/include", + "usr/local/i386-linux-uclibc/lib", + "usr/local/include", + "usr/local/lib", + "usr/local/man/en/man8", + "usr/local/sbin", + "usr/local/share", + "usr/local/src", + "usr/share/dict", + "usr/share/doc", + "usr/share/games", + "usr/share/ghostscript", + "usr/share/groff", + "usr/share/info", + "usr/share/kbd", + "usr/share/locale", + "usr/share/man/en/man8", + "usr/share/misc/getopt", + "usr/share/nls", + "usr/share/perl", + "usr/share/sgml/docbook", + "usr/share/sgml/html/dtd", + "usr/share/sgml/tei", + "usr/share/terminfo", + "usr/share/texmf", + "usr/share/zoneinfo", + "usr/src/linux-2.6.9/include", + "usr/src/packages/BUILD", + "usr/src/packages/RPMS/athlon", + "usr/src/packages/RPMS/i386", + "usr/src/packages/RPMS/i486", + "usr/src/packages/RPMS/i586", + "usr/src/packages/RPMS/i686", + "usr/src/packages/RPMS/noarch", + "usr/src/packages/SOURCES", + "usr/src/packages/SPECS", + "usr/src/packages/SRPMS", + "var/account", + "var/backups", + "var/cache/fonts", + "var/cache/man/en/man8", + "var/cache/www", + "var/cron", + "var/games", + "var/lib/hwclock", + "var/lib/xdm", + "var/local", + "var/msgs", + "var/nis", + "var/opt", + "var/preserve", + "var/spool/lpd", + "var/spool/mail", + "var/spool/mqueue", + "var/spool/news", + "var/spool/rwho", + "var/spool/uucp", + "var/yp", +#endif + NULL +}; + + +const static nodes_t nodes[] = +{ + {"initctl", S_IFIFO, 0, 0, 0}, + {"log", S_IFIFO, 0, 0, 0}, + {"mem", S_IFCHR, 1, 1, 0}, + {"kmem", S_IFCHR, 1, 2, 0}, + {"port", S_IFCHR, 1, 4, 0}, + {"zero", S_IFCHR, 1, 5, 0}, + {"full", S_IFCHR, 1, 7, 0}, + {"random", S_IFCHR, 1, 8, 0}, + {"urandom", S_IFCHR, 1, 9, 0}, + {"tty", S_IFCHR, 5, 0, 0}, + {"psaux", S_IFCHR, 10, 1, 0}, + {"hda", S_IFBLK, 3, 0, 0}, + {"hdb", S_IFBLK, 3, 64, 0}, + {"hdc", S_IFBLK, 22, 0, 0}, + {"hdd", S_IFBLK, 22, 64, 0}, + {"ram", S_IFBLK, 1, 0, 9}, + {"fd", S_IFBLK, 2, 0, 1}, + {"tty", S_IFCHR, 4, 0,12}, + {"ttyS", S_IFCHR, 4, 64,47}, + {"loop", S_IFBLK, 7, 0,63}, + {"cloop", S_IFBLK, 240, 0, 7}, + {"vcs", S_IFBLK, 7, 0, 9}, + {"vcsa", S_IFBLK, 7, 0, 9}, + {"input/keyboard", S_IFCHR, 10,150, 0}, + {"input/js", S_IFCHR, 13, 0, 31}, + {"input/mouse", S_IFCHR, 13, 32, 30}, + {"input/mice", S_IFCHR, 13, 63, 0}, + {"input/event", S_IFCHR, 13, 64, 63}, +#ifdef CONFIG_FEATURE_FULL_LSB + {"net/tun", S_IFCHR, 10,200, 0}, + {"fb0", S_IFCHR, 29, 0, 0}, + {"fb1", S_IFCHR, 29, 32, 0}, + {"fb2", S_IFCHR, 29, 64, 0}, + {"fb3", S_IFCHR, 29, 96, 0}, +#endif + {0, 0, 0, 0, 0} +}; + + +const static char *files[][2] = +{ + {"/var/etc/crontab", ""}, +// {"/var/etc/fstab", "none\t/dev/shm\tshm\tdefaults\t0 0\n/\t/dev/ram0\tminix\tdefaults\t0 0\n"}, + {"/var/etc/fstab", ""}, + {"/var/etc/group", "root:x:0:\ndaemon:x:2:\nshadow:x:42:\nusers:x:100:\nnogroup:x:65534:\n"}, + {"/var/etc/host.conf", "order hosts,bind\nmulti on\n"}, + {"/var/etc/hosts", "127.0.0.1 localhost\n"}, + {"/var/etc/inittab", "::sysinit:/sbin/rcS\ntty1::respawn:/bin/ash\ntty9::once:/sbin/rc 1\ntty11::once:/bin/dmesg\n::ctrlaltdel:/sbin/reboot\n::shutdown:/sbin/rc 0\n::shutdown:/sbin/swapoff -a\n::shutdown:/bin/umount -a -r\n::restart:/sbin/init\n"}, + {"/var/etc/ld.so.conf", ""}, + {"/var/etc/network/interfaces", "auto lo eth0\niface lo inet loopback\niface eth0 inet dhcp\n"}, + {"/var/etc/passwd", "root::0:0:My Linux Root:/root:/bin/sh\nftp:x:40:2:ftp:/tmp:/bin/sh\nsshd:x:41:2:sshd:/tmp:/bin/sh\nnobody:x:65534:65534:nobody:/tmp:/bin/sh\n"}, + {"/var/etc/resolv.conf", "search cluster.meeting.humbug.org.au\nnameserver 192.168.254.254\n"}, + {"/var/etc/securetty", "tty1\n"}, + {"/var/etc/shells", "/bin/ash\n/bin/hush\n/bin/lash\n/bin/msh\n/bin/sh\n"}, +#ifdef CONFIG_FEATURE_FULL_LSB + {"/boot/grub/device.map", "(hd0)\t/dev/hda\n(hd1)\t/dev/hdb\n(hd2)\t/dev/hdc\n(hd3)\t/dev/hdd\n(fd0)\t/dev/fd0\n"}, +#endif + {NULL, NULL} +}; + + +const static char *scripts[][2] = +{ + {"/sbin/shownet", "#!/bin/sh\necho \"\"\nifconfig\nroute\nip addr list\nip link list\nip route list\necho \"\"\n"}, + {"/var/etc/profile", "#!/bin/sh\nPATH=/usr/bin:/usr/sbin:/bin:/sbin\nexport PATH\n"}, +#ifdef CONFIG_FEATURE_FULL_LSB +#endif + {NULL, NULL} +}; + + +const static char *links[][2] = +{ + {"/proc/kcore", "/dev/core"}, + {"/dev/ram1", "/dev/ram"}, + {"/dev/vcs0", "/dev/vcs"}, + {"/dev/vcsa0", "/dev/vcsa"}, + {"/var/home", "/home"}, + {"/home/root", "/root"}, + {"/bin/busybox", "/sbin/init"}, + {"/bin/busybox", "/sbin/local_fs"}, + {"/bin/busybox", "/sbin/network"}, + {"/var/temp", "/tmp"}, + {"/sbin/local_fs", "/usr/etc/init.d/local_fs" }, + {"/sbin/boot_named", "/usr/etc/init.d/boot_named"}, + {"/sbin/network", "/usr/etc/init.d/network"}, + {"/sbin/boot_portmap", "/usr/etc/init.d/boot_portmap"}, + {"/sbin/remote_fs", "/usr/etc/init.d/remote_fs" }, + {"/sbin/boot_syslog", "/usr/etc/init.d/boot_syslog"}, + {"/sbin/boot_time", "/usr/etc/init.d/boot_time"}, + {"/usr/sbin/install_initd", "/usr/lib/lsb/install_initd" }, + {"/usr/sbin/remove_initd", "/usr/lib/lsb/remove_initd" }, + {"/usr/etc/init.d", "/var/etc/init.d"}, + {"/usr/etc/protocols", "/var/etc/protocols"}, + {"/usr/etc/rpc", "/var/etc/rpc"}, + {"/usr/etc/services", "/var/etc/services"}, + {"/var/lib/my_linux", "/var/etc/tux"}, + {"/.mc", "/var/home/root/.mc"}, + {"/tmp", "/var/lock"}, + {"/tmp", "/var/run"}, +#ifdef CONFIG_FEATURE_FULL_LSB +#endif + {NULL, NULL} +}; + + +const static char *modules[] = +{ +// "af_packet", +// Should try all NICS instead. +// "mii", +// "ne2k-pci", +// "nfs", + NULL +}; + + +llist_t *floppies_list = NULL; +llist_t *cdroms_list = NULL; +llist_t *hard_disks_list = NULL; +static void find_all_drives(void) +{ + int count; + struct dirent **dir; + + if ((floppies_list == NULL) && (cdroms_list == NULL) && (hard_disks_list == NULL)) + { +// This is hard coded for now. +floppies_list = llist_add_to(floppies_list, "fd0"); + if ((count = scandir("/proc/ide", &dir, 0, alphasort))) + { + int n; + + for (n = 0; n < count; n++) + { + struct dirent *script = dir[n]; + struct stat script_stat; + char *info_text = NULL; + + bb_xasprintf(&info_text, "/proc/ide/%s", script->d_name); + if (stat(info_text, &script_stat) == 0) + { + if (strncmp(info_text, "/proc/ide/hd", 12) == 0) + { + char *text = NULL; + char *name = NULL; + + bb_xasprintf(&text, "%s", doit(REDIR, "cat %s/media", info_text)); + bb_xasprintf(&name, "%s", script->d_name); + if (strcmp(text, "disk") == 0) + { +// Should add partitions instead. + hard_disks_list = llist_add_to(hard_disks_list, name); + } + else + cdroms_list = llist_add_to(cdroms_list, name); + } + free(info_text); + } + free(dir[n]); + } + free(dir); + } + } +} + + +static int is_boot_device(char *device, char *image, char **type); +static int find_boot_device_in_list(llist_t *disks, char *image, char **device, char **type) +{ + int result = 0; + char *original = *device; + llist_t *current = disks; + + while (current) + { + char *disc = current->data; + +bb_printf("Checking %s for %s\n", disc, image); + bb_xasprintf(device, "/dev/%s", disc); + if (is_boot_device(*device, image, type)) + { + result = 1; + free(*device); + bb_xasprintf(device, "/dev/%s", disc); + *device = concat_path_file(*device, image); + break; + } + current = current->link; + free(*device); + *device = original; + } + return result; +} + + +static int is_boot_device(char *device, char *image, char **type) +{ + int result = 0; + + if (*type == NULL) + { +// Should try to detect it. +*type = "auto"; + } + quick_mount(*type, device, "/boot", "-o ro"); + if (errno == 0) + { + char *dest = concat_path_file("/boot", image); + + if (stat(dest, &path_stat) == 0) + { + if (stat("/boot/bootrc", &path_stat) == 0) + result = 1; + } + if (result == 0) + doit(QUIET, "umount /boot"); + free(dest); + } + + return result; +} + + +static void pivot_dir(char *place, const char *root) +{ + char *dest = concat_path_file(root, place); + + remove_file(place, FILEUTILS_FORCE | FILEUTILS_RECUR); + symlink(dest, place); + free(dest); +} + + +static int rebuild_fs(char *root) +{ + int result = 0; + char *check = concat_path_file(root, "var/lib/distro"); + + if (stat(check, &path_stat) == 0) + { + free(check); + bb_printf("Rebuilding root fs from %s.\n", root); + check = concat_path_file(root, "bootrc"); + copy_file(check, "/bootrc", FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS); + free(check); + pivot_dir("/boot", root); + pivot_dir("/etc", root); + remove_file("/var/etc", FILEUTILS_FORCE | FILEUTILS_RECUR); + pivot_dir("/opt", root); + pivot_dir("/sbin", root); + pivot_dir("/usr", root); +// Should pivot dev and var if root is writable. + check = concat_path_file(root, "dev"); + copy_file(check, "/dev", FILEUTILS_FORCE | FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS); + free(check); + check = concat_path_file(root, "var"); + copy_file(check, "/var", FILEUTILS_FORCE | FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS); +// doit(QUIET, "ln -sf %s/lib/* /lib", root); + pivot_dir("/lib", root); + doit(0, "/sbin/ldconfig"); + pivot_dir("/bin", root); + result = 1; + } + + free(check); + return result; +} + + +void set_boot_env(char *token); +void read_bootrc(void) +{ + if (stat("/bootrc", &path_stat) == 0) + { + char *line; + FILE *contents; + + contents = fopen("/bootrc", "r"); + if (contents != NULL) + { + char *buffer = (char *) xmalloc(sizeof (char) * 256); + + bb_printf("Parsing configuration.\n"); + do + { + line = fgets(buffer, 255, contents); + if (line != NULL) + set_boot_env(buffer); + } while (line != NULL); + } + } +} + + +void set_boot_env(char *token) +{ + int i; + char *eq = NULL; + char *ha = NULL; + +//bb_printf("$$ %s\n", token); + for(i = 0; token[i] != '\0'; i++) + { + switch (token[i]) + { + case '=' : if (eq == NULL) eq = &token[i]; break; + case '#' : if (ha == NULL) ha = &token[i]; break; + } + } + + if ((eq != token) && (ha != token)) + { + char *name = (char *) xmalloc(sizeof (char) * (i + 5)); + + if (eq != NULL) + *eq = '\0'; + if (ha != NULL) + *ha = '\0'; + sprintf(name, "%s", token); + trim(name); + if (name[0] != '\0') + { + if (eq != NULL) + { + setenv(name, &eq[1], 1); +//bb_printf(" SET %s=%s\n", name, &eq[1]); + } + else + { + setenv(name, "", 1); +//bb_printf(" SET %s=\n", name); + } + } + free(name); + if (eq != NULL) + *eq = '='; + if (ha != NULL) + *ha = '#'; + } +} + + +int linuxrc_main(int argc, char **argv) +{ + int i; + int root_write = 0; + long MEMORY = 0; + char *CMDLINE = 0; + char *BOOT = 0; + char *ROOT = 0; + char *ROOT_TYPE = "auto"; + char *BOOTFS = 0; + char *ROOT_MOUNT = "/media/ROOT"; +// char *PKGSRC = "network"; + int TMPFS = 0; + int USR = 0; + int VAR = 0; + char *NFSADDR = 0; + char temp[32]; + char *token; + char *strtok_temp; + struct sysinfo info; + struct utsname name; + + mkrootfs(directories, nodes, files, scripts, links); + + for (i = 0; modules[i] != 0; i++) + { +//bb_printf("\n\n modprobe %s\n\n\n", modules[i]); + doit(0, "modprobe %s", modules[i]); + } +// quick_mount("usbfs", "usbfs", "/proc/bus/usb", ""); + + + doit(0, "dmesg >/var/log/dmesg.txt"); + + sysinfo(&info); + /* Kernels prior to 2.4.x will return info.mem_unit==0, so cope... */ + if (info.mem_unit==0) { + info.mem_unit=1; + } + if ( info.mem_unit == 1 ) { + info.mem_unit=1024; + + /* TODO: Make all this stuff not overflow when mem >= 4 Gib */ + info.totalram/=info.mem_unit; + } else { + info.mem_unit/=1024; + /* TODO: Make all this stuff not overflow when mem >= 4 Gib */ + info.totalram*=info.mem_unit; + } + MEMORY = info.totalram; + USR = MEMORY / 2.5; + VAR = MEMORY / 16; + + if (uname(&name) == -1) + bb_perror_msg_and_die("cannot get system information"); + if (atof(name.release) > 2.4) + TMPFS = 1; + + make_ram_disk(VAR, 2, "/var", TMPFS); + + bb_xasprintf(&CMDLINE, "%s", doit(REDIR, "cat /proc/cmdline")); +//bb_printf("%s\n", CMDLINE); + for (token = strtok_r(CMDLINE, " \t\n\r", &strtok_temp); token != NULL; token = strtok_r(NULL, " \t\n\r", &strtok_temp)) + { + if (strcmp(token, "RW") == 0) + { + root_write = 1; + sprintf(temp, "ROOT_MODE=RW"); + set_boot_env(temp); + } + else if (strcmp(token, "RO") == 0) + { + root_write = 0; + sprintf(temp, "ROOT_MODE=RO"); + set_boot_env(temp); + } + } + + BOOT = getenv("BOOT_IMAGE"); + if (BOOT != NULL) + { +#define CDROM 1 +#define FLOPPY 2 +#define HD 3 +#define NETWORK 4 + int type = 0; + int disk = -1; + int part = -1; + char *image = BOOT; + char device[16]; + +/* + * BOOT_IMAGE=(hd0,4)/boot/bzImage + * BOOT_IMAGE=(hd3)/boot/bzImage + * BOOT_IMAGE=(hdx,y)/boot/bzImage + * translate to /dev/hd(x+1)(y+1) + * BOOT_IMAGE=(cd)/boot/bzImage + * scan cd drives + * BOOT_IMAGE=/boot/bzImage + * try to avoid this, but scan all disks + * BOOT_IMAGE=bzImage + * probably syslinux, assume floppy boot (see next) + * BOOT_IMAGE=(fd0)/bzImage + * try to find bootrc on first floppy + * BOOT_IMAGE=(nd)/tftpboot/vmlinux + * try to tftp bootrc from network + */ + if ((BOOT[0] == '(') && (BOOT[2] == 'd') ) /* This is a grub boot, based on my BOOT_IMAGE patch for grub1. */ + { + while (image[0] != '\0') + { + if (image[0] == ')') + { + image++; + break; + } + image++; + } + switch (BOOT[1]) + { + case 'c' : type = CDROM; break; + case 'f' : type = FLOPPY; break; + case 'h' : type = HD; break; + case 'n' : type = NETWORK; break; + } + if (BOOT[3] != ')') + { + disk = atoi(&BOOT[3]) + 1; + if (BOOT[4] == ',') + part = atoi(&BOOT[5]) + 1; + } + } + + device[0] = '\0'; + switch (type) + { + case FLOPPY : + sprintf(device, "/dev/fd%d", disk - 1); + break; + + case HD : + sprintf(device, "/dev/hd%c%d", 'a' + disk, part); + break; + + case NETWORK : + sprintf(device, "tftp:/"); + break; + } + + if (device[0] == '\0') + { + find_all_drives(); + if (type == CDROM) + { + BOOTFS="iso9660"; + bb_printf("Scanning all CD and DVD drives for %s.\n", image); + if (find_boot_device_in_list(cdroms_list, image, &BOOT, &BOOTFS) == 0) + BOOTFS=NULL; + } + else + { + BOOTFS="vfat"; + bb_printf("Scanning all drives for %s.\n", image); + if (find_boot_device_in_list(floppies_list, image, &BOOT, &BOOTFS) == 0) + { + BOOTFS="iso9660"; + if (find_boot_device_in_list(cdroms_list, image, &BOOT, &BOOTFS) == 0) + { + BOOTFS=NULL; + if (find_boot_device_in_list(hard_disks_list, image, &BOOT, &BOOTFS) == 0) + BOOTFS=NULL; + } + } + } + } + else + { + if (type == NETWORK) + { + bb_xasprintf(&BOOT, "%s%s", device, image); + BOOTFS="Network"; + bb_printf("Kicking network into life.\n"); + doit(0, "rc network start"); + if (stat("/var/lib/network/tftpaddr", &path_stat) == 0) + { + bb_printf("\nDownloading configuration from network.\n"); + doit(QUIET, "tftp -gr /tftpboot/bootrc -l /bootrc %s", quick_read("/var/lib/network/tftpaddr")); + } + else if (stat("/var/lib/network/nfsaddr", &path_stat) == 0) + { + bb_printf("\nDownloading configuration from network.\n"); + doit(QUIET, "tftp -gr /tftpboot/bootrc -l /bootrc %s", quick_read("/var/lib/network/nfsaddr")); + } + } + else + { + bb_xasprintf(&BOOT, "%s%s", device, image); + if (is_boot_device(device, image, &BOOTFS)) + BOOT=device; + } + } + + if (BOOTFS == NULL) + BOOTFS = "Unknown"; + + if (stat("/boot/bootrc", &path_stat) == 0) + { + bb_printf("Copying configuration from boot filesystem.\n"); + copy_file("/boot/bootrc", "/bootrc", FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS); + doit(QUIET, "umount /boot"); + } + } + else + { + BOOT = ""; + BOOTFS = ""; + } + + read_bootrc(); + + ROOT = getenv("ROOT"); + if (ROOT == 0) + { + if (strncmp(BOOT, "/dev/", 5) == 0) + { + bb_xasprintf(&ROOT, "%s", BOOT); + for (i = 5; ROOT[i] != '\0'; i++) + { + if (ROOT[i] == '/') + { + ROOT[i] = '\0'; + ROOT_TYPE = BOOTFS; + break; + } + } + } + } + +/* +#VERSION=`cat /boot/version 2> /dev/null` +#PS1="My Linux $VERSION> " +*/ + + bb_printf("================================\n"); + bb_printf("Kernel: %s %s\n", name.release, TMPFS ? "- tmpfs capable" : ""); + bb_printf("RAM: %li MB %s\n", MEMORY / 1024, (MEMORY < (16 * 1024)) ? "< 16 MB, you may run into problems" : "" ); + bb_printf("Boot: %s - %s\n", BOOT, BOOTFS); + bb_printf("Root: %s - %s\n", ROOT, root_write ? "read/write" : "read only"); + bb_printf("================================\n"); + +/* +ROOT=/dev/hda6 +ROOT=nfs://REAL/MDS/TEST +*/ + if (ROOT == 0) + { + ; + } + else + { + if (strncmp(ROOT, "/dev/", 5) == 0) + { +// PKGSRC=BOOT; +// Should fsck this partition first. + bb_printf("Mounting %s \n on %s as type %s\n", ROOT, ROOT_MOUNT, ROOT_TYPE); + make_disk(&ROOT[5], nodes); + quick_mount(ROOT_TYPE, ROOT, ROOT_MOUNT, root_write ? "-o rw" : "-o ro"); + } + else if (strncmp(ROOT, "nfs://", 5) == 0) + { + doit(0, "rc network start"); + if (stat("/var/lib/network/ipaddr", &path_stat) == 0) + NFSADDR = quick_read("/var/lib/network/nfsaddr"); + if ((NFSADDR != 0) && (NFSADDR[0] != '\0')) + { + char *NFSMOUNT = 0; + + ROOT_TYPE = "nfs"; + if (NFSMOUNT == 0) + bb_xasprintf(&NFSMOUNT, "%s:%s", NFSADDR, &ROOT[5]); + bb_printf("Mounting %s \n on %s as type %s\n", NFSMOUNT, ROOT_MOUNT, ROOT_TYPE); + quick_mount(ROOT_TYPE, NFSMOUNT, ROOT_MOUNT, root_write ? "-o nolock,rw" : "-o nolock,ro"); + + free(NFSMOUNT); + } + free(NFSADDR); + } + } + +if (root_write) + copy_file("/bin/busybox", "/media/ROOT/bin/busybox", FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS); + + if (!rebuild_fs(ROOT_MOUNT)) + { +// make_ram_disk(USR, 3, "/usr", TMPFS); +// doit(0, "getpkg"); + } + else + { + read_bootrc(); + } + + doit(0, "/sbin/ldconfig"); + + free(CMDLINE); + + execl("/sbin/init", "/sbin/init"); + return EXIT_FAILURE; +} + diff --git a/urunlevel/my_linux/man.c b/urunlevel/my_linux/man.c new file mode 100644 index 0000000..162cac8 --- /dev/null +++ b/urunlevel/my_linux/man.c @@ -0,0 +1,41 @@ +/* + * Mini man implementation for busybox. + * + * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include + +#include "busybox.h" +#include "lib_init_d.h" +#include "my_linux.h" + + +int man_main(int argc, char **argv) +{ + argv += optind; + if (!*argv) + { + bb_printf("\nThe following manual topics are available:\n"); + doit(NOFORK, "ls -m /usr/doc"); + } + else + doit(NOFORK, "less /usr/doc/%s", *argv); + return EXIT_SUCCESS; +} diff --git a/urunlevel/my_linux/mkrootfs.c b/urunlevel/my_linux/mkrootfs.c new file mode 100644 index 0000000..9098be6 --- /dev/null +++ b/urunlevel/my_linux/mkrootfs.c @@ -0,0 +1,104 @@ +/* + * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include /* for uname(2) */ + +#include "busybox.h" +#include "lib_init_d.h" + + +void mkrootfs(const char *directories[], const nodes_t *nodes, const char *files[][2], const char *scripts[][2], const char *links[][2]) +{ + int i; + char temp[64]; + + umask(022); + sprintf(temp, "/dev"); + bb_make_directory(temp, -1l, FILEUTILS_RECUR); + mknod("/dev/console", S_IFCHR, makedev(4, 0)); + chmod("/dev/console", S_IRUSR | S_IWUSR); + mknod("/dev/null", S_IFCHR, makedev(1, 3)); + chmod("/dev/null", S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH); + mknod("/dev/ptmx", S_IFCHR, makedev(5, 2)); + chmod("/dev/ptmx", S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); + sprintf(temp, "/bin"); + bb_make_directory(temp, -1l, FILEUTILS_RECUR); + symlink("/bin/busybox", "/bin/sh"); + + bb_printf("\n\nCreating directories, devices, files, and links.\n"); + for (i = 0; directories[i] != 0; i++) + { + /* Can't use it directly, coz bb_make_directory segfaults. */ + sprintf(temp, "/%s", directories[i]); + bb_make_directory(temp, -1l, FILEUTILS_RECUR); + } + + symlink("/var/etc", "/etc"); + symlink("/proc/mounts", "/var/etc/mtab"); + quick_mount("proc", "proc", "/proc", ""); + quick_mount("sysfs", "sysfs", "/sys", ""); + for (i = 0; nodes[i].name != 0; i++) + { + if (nodes[i].count) + { + int j; + for (j = 0; j <= nodes[i].count; j++) + { + sprintf(temp, "/dev/%s%i", nodes[i].name, j); + mknod(temp, nodes[i].mode, makedev(nodes[i].major, nodes[i].minor + j)); + } + } + else + { + sprintf(temp, "/dev/%s", nodes[i].name); + mknod(temp, nodes[i].mode, makedev(nodes[i].major, nodes[i].minor)); + } + } + + for (i = 0; files[i][0] != NULL; i++) + quick_write(files[i][0], files[i][1]); + + for (i = 0; scripts[i][0] != NULL; i++) + { + quick_write(scripts[i][0], scripts[i][1]); + chmod(scripts[i][0], S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH); + } + + for (i = 0; links[i][0] != NULL; i++) + symlink(links[i][0], links[i][1]); + + quick_mount("devpts", "devpts", "/dev/pts", ""); + doit(0, "busybox --install"); + + /* This must be last, as it currently defines a valid install. */ + /* Can't use it directly, coz bb_make_directory segfaults. */ + sprintf(temp, "/var/lib/distro"); + bb_make_directory(temp, -1l, FILEUTILS_RECUR); + + bb_printf("Created.\n"); +} diff --git a/urunlevel/my_linux/my_linux.h b/urunlevel/my_linux/my_linux.h new file mode 100644 index 0000000..7be8fe4 --- /dev/null +++ b/urunlevel/my_linux/my_linux.h @@ -0,0 +1,27 @@ +/* vi: set sw=4 ts=4: */ +/* + * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#ifndef _MY_LINUX_H +#define _MY_LINUX_H + +void mkrootfs(const char *directories[], const nodes_t *nodes, const char *files[][2], const char *scripts[][2], const char *links[][2]); + +#endif diff --git a/urunlevel/my_linux/rcS b/urunlevel/my_linux/rcS new file mode 100755 index 0000000..5d3785e --- /dev/null +++ b/urunlevel/my_linux/rcS @@ -0,0 +1,2 @@ +#!/bin/sh +/bin/busybox rcS diff --git a/urunlevel/my_linux/rcS.c b/urunlevel/my_linux/rcS.c new file mode 100644 index 0000000..6d1f64f --- /dev/null +++ b/urunlevel/my_linux/rcS.c @@ -0,0 +1,47 @@ +/* + * Mini rcS implementation for busybox. + * + * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include + +#include "busybox.h" +#include "lib_init_d.h" +#include "my_linux.h" + + +int rcS_main(int argc, char **argv) +{ + doit(FORK | QUIET, "gpm -m /dev/input/mice -t exps2 -M -m /dev/ttyS0 -t ms"); + +// doit(FORK | QUIET, "/usr/sbin/crond"); +// if (errno == 0) +// { +// bb_printf("Starting cron.\n"); +// doit(0, "sort /etc/crontab | uniq > /tmp/crontab 2> /dev/null"); +// copy_file("/tmp/crontab", "/etc/crontab", FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS); +// doit(0, "/usr/sbin/crontab /etc/crontab 2> /dev/null"); +// doit(0, "crontab -l"); +// } + + bb_printf("\n\nALT- allows you to view other virtual terminals.\n"); + + return EXIT_SUCCESS; +} diff --git a/urunlevel/my_linux/shownet b/urunlevel/my_linux/shownet new file mode 100755 index 0000000..94f1172 --- /dev/null +++ b/urunlevel/my_linux/shownet @@ -0,0 +1,8 @@ +#!/bin/sh +echo "" +ifconfig +route +ip addr list +ip link list +ip route list +echo "" diff --git a/urunlevel/my_linux/vt_manager b/urunlevel/my_linux/vt_manager new file mode 100755 index 0000000..978f2ec --- /dev/null +++ b/urunlevel/my_linux/vt_manager @@ -0,0 +1,22 @@ +#!/bin/sh + +runlevel=`cat /etc/runlevel` + +if [ -f /var/lib/misc/runlevel ] +then + runlevel=`/var/lib/misc/runlevel` +fi + +if [ "$runlevel" = "3" ] +then + /sbin/getty 38400 tty$1 +elif [ "$runlevel" = "4" ] +then + sleep 1 + /usr/bin/openvt $1 twdm --quiet --hw=tty@/dev/tty$1,stdout,TERM=linux + sleep 1d +elif [ "$runlevel" = "5" ] +then + /usr/bin/openvt $1 /usr/X11R6/bin/X + sleep 1d +fi diff --git a/urunlevel/networking/udhcp/dhcpc.h b/urunlevel/networking/udhcp/dhcpc.h new file mode 100644 index 0000000..25252af --- /dev/null +++ b/urunlevel/networking/udhcp/dhcpc.h @@ -0,0 +1,38 @@ +/* dhcpc.h */ +#ifndef _DHCPC_H +#define _DHCPC_H + +//#define DEFAULT_SCRIPT "/usr/share/udhcpc/default.script" +#define DEFAULT_SCRIPT "/sbin/udhcpc_script" + +/* allow libbb_udhcp.h to redefine DEFAULT_SCRIPT */ +#include "libbb_udhcp.h" + +#define INIT_SELECTING 0 +#define REQUESTING 1 +#define BOUND 2 +#define RENEWING 3 +#define REBINDING 4 +#define INIT_REBOOT 5 +#define RENEW_REQUESTED 6 +#define RELEASED 7 + + +struct client_config_t { + char foreground; /* Do not fork */ + char quit_after_lease; /* Quit after obtaining lease */ + char abort_if_no_lease; /* Abort if no lease */ + char background_if_no_lease; /* Fork to background if no lease */ + char *interface; /* The name of the interface to use */ + char *pidfile; /* Optionally store the process ID */ + char *script; /* User script to run at dhcp events */ + uint8_t *clientid; /* Optional client id to use */ + uint8_t *hostname; /* Optional hostname to use */ + int ifindex; /* Index number of the interface to use */ + uint8_t arp[6]; /* Our arp address */ +}; + +extern struct client_config_t client_config; + + +#endif diff --git a/urunlevel/networking/udhcp/libbb_udhcp.h b/urunlevel/networking/udhcp/libbb_udhcp.h new file mode 100644 index 0000000..3204be0 --- /dev/null +++ b/urunlevel/networking/udhcp/libbb_udhcp.h @@ -0,0 +1,55 @@ +/* libbb_udhcp.h - busybox compatability wrapper */ + +/* bit of a hack, do this no matter what the order of the includes. + * (for busybox) */ + +#ifdef CONFIG_INSTALL_NO_USR +#undef DEFAULT_SCRIPT +//#define DEFAULT_SCRIPT "/share/udhcpc/default.script" +#define DEFAULT_SCRIPT "/sbin/udhcpc_script" +#endif + +#ifndef _LIBBB_UDHCP_H +#define _LIBBB_UDHCP_H + +#ifdef IN_BUSYBOX +#include "busybox.h" + +#ifdef CONFIG_FEATURE_UDHCP_SYSLOG +#define UDHCP_SYSLOG +#endif + +#ifdef CONFIG_FEATURE_UDHCP_DEBUG +#define UDHCP_DEBUG +#endif + +#define COMBINED_BINARY +#include "version.h" + +#define xfopen bb_xfopen + +#else /* ! BB_VER */ + +#include +#include +#include + +#define TRUE 1 +#define FALSE 0 + +#define xmalloc malloc +#define xcalloc calloc + +static inline FILE *xfopen(const char *file, const char *mode) +{ + FILE *fp; + if (!(fp = fopen(file, mode))) { + perror("could not open input file"); + exit(0); + } + return fp; +} + +#endif /* BB_VER */ + +#endif /* _LIBBB_UDHCP_H */ diff --git a/urunlevel/runlevel/Config.in b/urunlevel/runlevel/Config.in new file mode 100644 index 0000000..36be84b --- /dev/null +++ b/urunlevel/runlevel/Config.in @@ -0,0 +1,110 @@ +# +# For a description of the syntax of this configuration file, +# see scripts/kbuild/config-language.txt. +# + +menu "Runlevel Utilities" + +config CONFIG_BOOT_NAMED + bool "boot_named" + default y + help + An implementation of LSB $named. + +config CONFIG_BOOT_PORTMAP + bool "boot_portmap" + default y + help + An implementation of LSB $. + +config CONFIG_BOOT_SYSLOG + bool "boot_syslog" + default y + help + An implementation of LSB $syslog. + +config CONFIG_BOOT_TIME + bool "boot_time" + default y + help + An implementation of LSB $time. + +config CONFIG_INSTALL_INITD + bool "install_initd" + default y + help + An implementation of install_initd. + +config CONFIG_KILLPROC + bool "killproc" + default y + help + An implementation of killproc. + +config CONFIG_LOCAL_FS + bool "local_fs" + default y + help + A $local_fs boot script. + +config CONFIG_LOG_FAILURE_MSG + bool "log_failure_msg" + default y + help + An implementation of log_failure_msg. + +config CONFIG_LOG_SUCCESS_MSG + bool "log_success_msg" + default y + help + An implementation of log_success_msg. + +config CONFIG_LOG_WARNING_MSG + bool "log_warning_msg" + default y + help + An implementation of log_warning_msg. + +config CONFIG_NETWORK + bool "network" + default y + help + A $network boot script. + +config CONFIG_PIDOFPROC + bool "pidofproc" + default y + help + An implementation of pidofproc. + +config CONFIG_RC + bool "rc" + default y + help + An implementation of rc. + +config CONFIG_REMOTE_FS + bool "remote_fs" + default y + help + A $remote_fs boot script. + +config CONFIG_REMOVE_INITD + bool "remove_initd" + default y + help + An implementation of remove_initd. + +config CONFIG_START_DAEMON + bool "start_daemon" + default y + help + An implementation of start_daemon. + +config CONFIG_UDHCPC_SCRIPT + bool "udhcpc_script" + default y + help + An implementation of udhcpc.script. + +endmenu diff --git a/urunlevel/runlevel/Makefile b/urunlevel/runlevel/Makefile new file mode 100644 index 0000000..e7e9466 --- /dev/null +++ b/urunlevel/runlevel/Makefile @@ -0,0 +1,32 @@ +# Makefile for busybox +# +# Copyright (C) 1999-2004 by Erik Andersen +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +top_srcdir=.. +top_builddir=.. +srcdir=$(top_srcdir)/runlevel +RUNLEVEL_DIR:=./ +include $(top_builddir)/Rules.mak +include $(top_builddir)/.config +include $(srcdir)/Makefile.in +all: $(libraries-y) +-include $(top_builddir)/.depend + +clean: + rm -f *.o *.a $(AR_TARGET) + diff --git a/urunlevel/runlevel/Makefile.in b/urunlevel/runlevel/Makefile.in new file mode 100644 index 0000000..787dd18 --- /dev/null +++ b/urunlevel/runlevel/Makefile.in @@ -0,0 +1,75 @@ +# Makefile for busybox +# +# Copyright (C) 1999-2004 by Erik Andersen +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# + +RUNLEVEL_AR:=runlevel.a +ifndef $(RUNLEVEL_DIR) +RUNLEVEL_DIR:=$(top_builddir)/runlevel/ +endif +srcdir=$(top_srcdir)/runlevel + +RUNLEVEL-y:= +RUNLEVEL-$(CONFIG_BOOT_NAMED) += boot_named.o +RUNLEVEL-$(CONFIG_BOOT_PORTMAP) += boot_portmap.o +RUNLEVEL-$(CONFIG_BOOT_SYSLOG) += boot_syslog.o +RUNLEVEL-$(CONFIG_BOOT_TIME) += boot_time.o +RUNLEVEL-$(CONFIG_INSTALL_INITD) += install_initd.o +RUNLEVEL-$(CONFIG_KILLPROC) += killproc.o +RUNLEVEL-$(CONFIG_LOCAL_FS) += local_fs.o +RUNLEVEL-$(CONFIG_LOG_FAILURE_MSG) += log_failure_msg.o +RUNLEVEL-$(CONFIG_LOG_SUCCESS_MSG) += log_success_msg.o +RUNLEVEL-$(CONFIG_LOG_WARNING_MSG) += log_warning_msg.o +RUNLEVEL-$(CONFIG_NETWORK) += network.o +RUNLEVEL-$(CONFIG_PIDOFPROC) += pidofproc.o +RUNLEVEL-$(CONFIG_RC) += rc.o +RUNLEVEL-$(CONFIG_REMOTE_FS) += remote_fs.o +RUNLEVEL-$(CONFIG_REMOVE_INITD) += remove_initd.o +RUNLEVEL-$(CONFIG_START_DAEMON) += start_daemon.o +RUNLEVEL-$(CONFIG_UDHCPC_SCRIPT) += udhcpc_script.o + + +#ifeq ($(CONFIG_HALT), y) +CONFIG_RUNLEVEL_SHARED=y +#else +#ifeq ($(CONFIG_INIT), y) +#CONFIG_RUNLEVEL_SHARED=y +#else +#ifeq ($(CONFIG_POWEROFF), y) +#CONFIG_RUNLEVEL_SHARED=y +#else +#ifeq ($(CONFIG_REBOOT), y) +#CONFIG_RUNLEVEL_SHARED=y +#else +#CONFIG_RUNLEVEL_SHARED=n +#endif +#endif +#endif +#endif + +ifeq ($(CONFIG_RUNLEVEL_SHARED), y) +RUNLEVEL-$(CONFIG_RUNLEVEL_SHARED) += lib_init_d.o +endif + +libraries-y+=$(RUNLEVEL_DIR)$(RUNLEVEL_AR) + +$(RUNLEVEL_DIR)$(RUNLEVEL_AR): $(patsubst %,$(RUNLEVEL_DIR)%, $(RUNLEVEL-y)) + $(AR) -ro $@ $(patsubst %,$(RUNLEVEL_DIR)%, $(RUNLEVEL-y)) + +$(RUNLEVEL_DIR)%.o: $(srcdir)/%.c + $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c -o $@ $< + diff --git a/urunlevel/runlevel/README b/urunlevel/runlevel/README new file mode 100644 index 0000000..7c3e2ce --- /dev/null +++ b/urunlevel/runlevel/README @@ -0,0 +1,3 @@ +Busybox does not include named and portmap applets, so boot_named.c and +boot_portmap.c should be considered as examples. Skeleton is also an example. + diff --git a/urunlevel/runlevel/TODO b/urunlevel/runlevel/TODO new file mode 100644 index 0000000..d522d93 --- /dev/null +++ b/urunlevel/runlevel/TODO @@ -0,0 +1,55 @@ ++ LSB niceness +* LSB compliance +! fix bug +$ store config info in - + kernel command line + boot://bootrc + /etc/sysconfig/* syslog network/config network/routes + + if (stat("/var/lib/my_linux/config/ipfwd", &path_stat) == 0) + if (stat("/var/lib/my_linux/config/noping", &path_stat) == 0) + /var/lib/my_linux/config/hostname - hostname + /var/lib/my_linux/config/loghost - syslogd remote host + + + review init.d script dependencies + local_fs - + time ? network? + syslog ? (local_fs? or network) and time + network - syslog + remote_fs - network + portmap - network + named - network and syslog + +$ write a proper network & friends + add fsck support to local_fs and linuxrc + local_fs should only umount things it mounted +! try to detect ext3 before mount whinges +! redirect console to some other VT + +* do something with info->shouldstart's in rc ++ rc foo start - start dependencies of foo first ++ rc foo stop - stop things dependent on foo first +* add a database of runlevels per script +* add database editing and reporting commands to rc + +* finish install_initd & remove_initd +$ finish boot_syslog +$ finish boot_time +! double check status functions + ++ write init_d_from_script ++ rewrite skeleton to use initd_from_script + +! pidofproc needs to check the name of the proc as well as the pid in /proc/$pid + remove start_daemon's reliance on start-stop-daemon +! remove need for sleep(1) in start_daemon +! fix forking, daemon begat's daemon, and daemonic hell breaks loose. + My doit() is probably to blame. + + on boot - hard link /linuxrc to /bin/busybox + turn makefs into a full blown applet + CONFIG_FEATURE_FULL_LSB + permissions for files + move cron out of rcS + diff --git a/urunlevel/runlevel/boot_named.c b/urunlevel/runlevel/boot_named.c new file mode 100644 index 0000000..fba83c7 --- /dev/null +++ b/urunlevel/runlevel/boot_named.c @@ -0,0 +1,57 @@ +/* + * Mini named boot implementation for busybox. + * + * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include + +#include "busybox.h" +#include "lib_init_d.h" + + +static init_d_handle_t my_commands = +{ + NULL, + NULL, + NULL, + NULL, + &sighup_reload, + NULL, + NULL, + NULL, + "boot_named", + "named", + NULL, + NULL, + INIT_D_BEGIN \ + INIT_D_PROV "$named" \ + INIT_D_RSTART "$network $syslog" \ + INIT_D_DSTART "3 4 5" \ + INIT_D_DSTOP "0 1 2 6" \ + INIT_D_SDESC "Hostname resolution service." \ + INIT_D_DESC "Hostname resolution service." \ + INIT_D_END +}; + + +int boot_named_main(int argc, char **argv) +{ + return do_init_from_main(argc, argv, &my_commands); +} diff --git a/urunlevel/runlevel/boot_portmap.c b/urunlevel/runlevel/boot_portmap.c new file mode 100644 index 0000000..d354b3b --- /dev/null +++ b/urunlevel/runlevel/boot_portmap.c @@ -0,0 +1,78 @@ +/* + * Mini portmap boot implementation for busybox. + * + * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include + +#include "busybox.h" +#include "lib_init_d.h" + +static int restart(struct init_d_handle_s *init_d, int just_checking); + + +static init_d_handle_t my_commands = +{ + NULL, + NULL, + &restart, + NULL, + NULL, + NULL, + NULL, + NULL, + "boot_portmap", + "/sbin/portmap", + NULL, + NULL, + INIT_D_BEGIN \ + INIT_D_PROV "$portmap" \ + INIT_D_RSTART "$network" \ + INIT_D_DSTART "3 4 5" \ + INIT_D_DSTOP "0 1 2 6" \ + INIT_D_SDESC "RPC port mapper." \ + INIT_D_DESC "The RPC port mapper provides SunPRC/ONCRPC portmapping" \ + INIT_D_CONT "services." \ + INIT_D_END +}; + + +int boot_portmap_main(int argc, char **argv) +{ + return do_init_from_main(argc, argv, &my_commands); +} + + +static const char *state = "/var/run/portmap.state"; +static int restart(struct init_d_handle_s *init_d, int just_checking) +{ + int status = (init_d->status)(init_d, 0); + + if (status == INIT_D_STATUS_OK) + { + doit(0, "pmap_dump > %s", state); + status = default_restart(init_d, 0); + doit(0, "pmap_set < %s", state); + remove_file(state, FILEUTILS_FORCE); + } + else + status = default_restart(init_d, 0); + return status; +} diff --git a/urunlevel/runlevel/boot_syslog.c b/urunlevel/runlevel/boot_syslog.c new file mode 100644 index 0000000..dc7548a --- /dev/null +++ b/urunlevel/runlevel/boot_syslog.c @@ -0,0 +1,79 @@ +/* + * Mini syslog boot implementation for busybox. + * + * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include + +#include "busybox.h" +#include "lib_init_d.h" + + +static int start(struct init_d_handle_s *, int); + + +static init_d_handle_t my_commands = +{ + &start, + NULL, + NULL, + NULL, + &no_reload, + NULL, + NULL, + NULL, + "boot_syslogd", + "/sbin/syslogd", + "-n", + NULL, + INIT_D_BEGIN \ + INIT_D_PROV "$syslog" \ + INIT_D_RSTART "$local_fs $time" \ + INIT_D_SSTART "$network" \ + INIT_D_DSTART "1 2 3 4 5" \ + INIT_D_DSTOP "0 6" \ + INIT_D_SDESC "System logger." \ + INIT_D_DESC "System logger." \ + INIT_D_END +}; + + +int boot_syslog_main(int argc, char **argv) +{ + return do_init_from_main(argc, argv, &my_commands); +} + + +static int start(struct init_d_handle_s *init_d, int just_checking) +{ +/* +#LOGHOST=`cat /var/lib/my_linux/config/loghost 2> /dev/null` +#if [ "$LOGHOST" ] +#then +# if [ "$LOGHOST" = "prompt" ] +# then +# echo -n "Enter syslog server: " +# read $LOGHOST +# fi +# $REMOTELOG = "-R $LOGHOST" +#fi +*/ + return default_start(init_d, 0); +} diff --git a/urunlevel/runlevel/boot_time.c b/urunlevel/runlevel/boot_time.c new file mode 100644 index 0000000..aa1fde7 --- /dev/null +++ b/urunlevel/runlevel/boot_time.c @@ -0,0 +1,88 @@ +/* + * Mini time boot implementation for busybox. + * + * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include + +#include "busybox.h" +#include "lib_init_d.h" + + +static int start(struct init_d_handle_s *, int); +static int status(struct init_d_handle_s *, int); +static int stop(struct init_d_handle_s *, int); + + +static init_d_handle_t my_commands = +{ + &start, + &stop, + NULL, + NULL, + &no_reload, + NULL, + &status, + NULL, + "boot_time", + NULL, + NULL, + NULL, + INIT_D_BEGIN \ + INIT_D_PROV "$time" \ + INIT_D_DSTART "1 2 3 4 5" \ + INIT_D_DSTOP "0 6" \ + INIT_D_SDESC "Set the system time." \ + INIT_D_DESC "Set the system time, maybe from the hardware clock," \ + INIT_D_CONT "maybe from the network via NTP or DATE." \ + INIT_D_END +}; +// INIT_D_SSTART "$network" \ + + +int boot_time_main(int argc, char **argv) +{ + return do_init_from_main(argc, argv, &my_commands); +} + + +static int start(struct init_d_handle_s *init_d, int just_checking) +{ +// Should check if we need to NTP or whatever +// Should check for -l/-u + doit(0, "/sbin/hwclock -su"); +// Should check errno and convert into INIT_D_ERROR_? + return INIT_D_OK; +} + + +static int status(struct init_d_handle_s *init_d, int quiet) +{ + return print_status(init_d, quiet, INIT_D_STATUS_OK); +} + + +static int stop(struct init_d_handle_s *init_d, int just_checking) +{ +// Should check for -l/-u + doit(0, "/sbin/hwclock -wu"); +// Should check errno and convert into INIT_D_ERROR_? + return INIT_D_OK; +} diff --git a/urunlevel/runlevel/default.script b/urunlevel/runlevel/default.script new file mode 100755 index 0000000..9b11c8a --- /dev/null +++ b/urunlevel/runlevel/default.script @@ -0,0 +1,2 @@ +#!/bin/bash +/bin/busybox udhcpc_script \ No newline at end of file diff --git a/urunlevel/runlevel/init-functions b/urunlevel/runlevel/init-functions new file mode 100644 index 0000000..8b2200c --- /dev/null +++ b/urunlevel/runlevel/init-functions @@ -0,0 +1,30 @@ +function start_daemon () +{ + /bin/busybox start_daemon ${1+"$@"} +} + +function killproc () +{ + /bin/busybox killproc ${1+"$@"} +} + +function pidofproc () +{ + /bin/busybox pidofproc ${1+"$@"} +} + +function log_success_msg () +{ + /bin/busybox log_success_msg ${1+"$@"} +} + +function log_failure_msg () +{ + /bin/busybox log_failure_msg ${1+"$@"} +} + +function log_warning_msg () +{ + /bin/busybox log_warning_msg ${1+"$@"} +} + diff --git a/urunlevel/runlevel/inittab b/urunlevel/runlevel/inittab new file mode 100644 index 0000000..f1e6c11 --- /dev/null +++ b/urunlevel/runlevel/inittab @@ -0,0 +1,12 @@ +::sysinit:/sbin/rcS +tty1::respawn:/sbin/getty 38400 tty1 +tty2::respawn:/sbin/getty 38400 tty2 +tty9::once:/sbin/rc +tty10::respawn:/bin/tail -f /var/log/messages +tty11::once:/bin/dmesg +tty11::respawn:/sbin/klogd -n +::ctrlaltdel:/sbin/reboot +::shutdown:/sbin/rc 0 +::shutdown:/sbin/swapoff -a +::shutdown:/bin/umount -a -r +::restart:/sbin/init diff --git a/urunlevel/runlevel/install_initd.c b/urunlevel/runlevel/install_initd.c new file mode 100644 index 0000000..4b9ab88 --- /dev/null +++ b/urunlevel/runlevel/install_initd.c @@ -0,0 +1,48 @@ +/* + * Mini install_initd implementation for busybox. + * + * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include + +#include "busybox.h" +#include "lib_init_d.h" + + +int install_initd_main(int argc, char **argv) +{ + llist_t *sorted = NULL; + llist_t *unsorted = get_scripts(); +// char *info_text = NULL; +// char *pathname = NULL; +// init_d_info_t *info = NULL; + +// bb_xasprintf(&pathname, "/etc/init.d/%s", script->d_name); +// info_text = get_init_info(pathname); +// info = parse_init_info(info_text, script->d_name); +// if (info) +// result = llist_add_to(result, (char *) info); + + sorted = sort_scripts(unsorted); +// Should return 1 if this script is in unsorted. + +// free(info_text); + return EXIT_SUCCESS; +} diff --git a/urunlevel/runlevel/killproc.c b/urunlevel/runlevel/killproc.c new file mode 100644 index 0000000..fd91c10 --- /dev/null +++ b/urunlevel/runlevel/killproc.c @@ -0,0 +1,162 @@ +/* + * Mini killproc implementation for busybox. + * + * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include +#include +#include +#include + +#include "busybox.h" +#include "lib_init_d.h" + + +int killproc(char *pidfile, char *pathname, int my_signal) +{ + char *pids = NULL; + int status = pidofproc(pidfile, pathname, &pids); + + if (status == INIT_D_STATUS_OK) + { + int i; + char *pid; + char *strtok_temp; + + pid = strtok_r(pids, " ", &strtok_temp); + for (i = 0; pid != NULL; i++) + { + int pid_num; + + if (!isdigit(*pid)) + bb_error_msg( "Bad PID '%s'", pid); + pid_num = strtol(pid, NULL, 0); + if (my_signal != 0) + { + if (kill(pid_num, my_signal) != 0) + bb_perror_msg( "Could not kill pid '%d'", pid_num); + } + else + { + if (kill(pid_num, SIGTERM) != 0) + bb_perror_msg( "Could not kill pid '%d'", pid_num); + sleep(1); + status = pidofproc(pidfile, pathname, &pids); + if (status == INIT_D_STATUS_OK) + { + sleep(5); + status = pidofproc(pidfile, pathname, &pids); + if (status == INIT_D_STATUS_OK) + { + if (kill(pid_num, SIGKILL) != 0) + bb_perror_msg( "Could not kill pid '%d'", pid_num); + } + } + } + + pid = strtok_r(NULL, " ", &strtok_temp); + } + + status = pidofproc(pidfile, pathname, &pids); + if (status == INIT_D_STATUS_DEAD_PID) + { + if (pidfile != NULL) + remove_file(pidfile, FILEUTILS_FORCE); + status = INIT_D_STATUS_NOT_RUNNING; + } + if ((my_signal == 0) && (status == INIT_D_STATUS_NOT_RUNNING)) + status = INIT_D_STATUS_OK; + } + + return status; +} + + +/* +killproc [-p pidfile] pathname [signal] + This stops the specified program. The program is + found using the algorithm given above. If a + signal is specified, using the + -signal_name or -signal_number syntaxes + as specified by the kill command, + the program is sent that signal. + Otherwise, a SIGTERM followed by a SIGKILL + after some number of seconds shall be sent. + If a program has been terminated, the pidfile should be removed if the + terminated process has not already done so. + Compliant applications may use the basename instead of the + pathname. + + killproc should return the LSB defined exit status codes. If called + without a signal, it shall return 0 if the program has been stopped or + is not running and not 0 otherwise. If a signal is given, it shall return 0 + only if the program is running. +*/ + + +int killproc_main(int argc, char **argv) +{ + int i; + int my_signal = 0; + char *pidfile = NULL; + char *pathname = NULL; + char *signame = NULL; + + for (i = 1; i < argc; i++) + { + char *p = argv[i]; + + if (*p == '-') + { + p++; + if (*p == 'p') + { + if ((i + 1) < argc) + pidfile = argv[++i]; + else + bb_show_usage(); + } + else + signame = &argv[i][1]; + } + else if (pathname == NULL) + pathname = p; + else if (signame == NULL) + signame = p; + else + bb_show_usage(); + } + + if (pathname == NULL) + bb_show_usage(); + + if (signame != NULL) + { + u_signal_names(signame, &my_signal, 1); + if (my_signal == 0) + { + log_failure_msg("unknown signal."); + bb_show_usage(); + } + } + +//bb_printf("ARGS - %s %s %d = %s\n", pidfile, pathname, my_signal, u_signal_names(NULL, &signal, 1)); + return killproc(pidfile, pathname, my_signal); +} diff --git a/urunlevel/runlevel/lib_init_d.c b/urunlevel/runlevel/lib_init_d.c new file mode 100644 index 0000000..866888c --- /dev/null +++ b/urunlevel/runlevel/lib_init_d.c @@ -0,0 +1,425 @@ +/* + * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include /* for uname(2) */ + +#include "busybox.h" +#include "lib_init_d.h" + + +static char *shell = 0; +struct stat path_stat; + + +char *argv_cat(int argc, char **argv) +{ + int i; + int length = 1; + char *message = NULL; + + for (i = 0; i < argc; i++) + length += strlen(argv[i]); + message = (char *) xmalloc(sizeof (char) * length); + + if (message != NULL) + { + message[0] = '\0'; + for (i = 1; i < argc; i++) + { + strcat(message, argv[i]); + if (i < (argc - 1)) + strcat(message, " "); + } + } + return message; +} + + +char *big_chomp(char *s) +{ + char *lc = index(s, '\n'); + + if(lc) + *lc = '\0'; + return s; +} + + +char *doit(int mode, char *command, ...) +{ + int buffsize = 63; + char *buffer = NULL; + int dataPipe[2] = { -1, -1 }; + int statusPipe[2] = { -1, -1 }; + int n; + pid_t pid = 0; + volatile int vfork_exec_errno = 0; + char **args; + char *commandBuffer; + + if (mode & DAEMON) + mode |= FORK | QUIET; + + va_list p; + int r; + + va_start(p, command); + r = vasprintf(&commandBuffer, command, p); + va_end(p); + + if (r < 0) + bb_perror_msg_and_die("doit"); + + if (shell == 0) + { + shell = getenv("SHELL"); + if (shell == 0) + shell = "/bin/sh"; + } + + args = (char **) xmalloc (sizeof (char *) * 4); + n = 0; + args[n++] = shell; + args[n++] = "-c"; + if (mode & QUIET) + bb_xasprintf(&(args[n++]), "%s 2>/dev/null", commandBuffer); + else + args[n++] = commandBuffer; + args[n++] = 0; + + if (!(mode & NOFORK)) + { + if (!(mode & DAEMON)) + { + if (pipe(dataPipe) < 0 || pipe(statusPipe) < 0) + bb_perror_msg("Failed to create pipe"); + signal(SIGPIPE, SIG_IGN); /* we only want EPIPE on errors */ + } +// pid = vfork(); + pid = fork(); + } + if (pid == 0) /* child */ + { + if ((!(mode & NOFORK)) && (!(mode & NOFORK))) + { + close(STDIN_FILENO); + dup2(dataPipe[1], STDOUT_FILENO); + dup2(dataPipe[1], STDERR_FILENO); + close(dataPipe[0]); + close(statusPipe[0]); + fcntl(statusPipe[1], F_SETFD, FD_CLOEXEC); /* close on exec shows sucess */ + } + + if ((mode & DAEMON)) + { + if (!(mode & NOFORK)) + { + close(dataPipe[1]); + close(statusPipe[1]); + close(STDOUT_FILENO); + close(STDERR_FILENO); + } + daemon(1, 0); + } + errno = 0; + execvp(shell, (char **) args ); + + vfork_exec_errno = errno; + if (!(mode & NOFORK)) + close(statusPipe[1]); + _exit(-1); + } + else if (pid > 0) /* parent */ + { + close(dataPipe[1]); + close(statusPipe[1]); + + while (1) + { + char buf; + + n = read(statusPipe[0], &buf, 1); + + if ((n < 0) && ((errno == EAGAIN) || (errno == EINTR)) && !(mode & FORK)) + continue; /* try it again */ + else if (n == 0 && vfork_exec_errno != 0) + { + errno = vfork_exec_errno; + bb_perror_msg("Could not exec process"); + } + break; + } + close(statusPipe[0]); + + if (buffer == NULL) + buffer = (char *) xcalloc(buffsize + 1, sizeof (char)); + + if ((mode & FORK) == 0) + { + ssize_t cc; + struct pollfd poller[1]; + + poller[0].fd = dataPipe[0]; + poller[0].events = POLLIN | POLLPRI; + poller[0].revents = 0; + + n = 0; + while (1) + { + if ((buffsize - n) <= 0) + { + int i; + + buffsize += buffsize; + buffer = xrealloc(buffer, sizeof(char) * (buffsize + 1)); + for (i = n; i <= buffsize; i++) + buffer[i] = '\0'; + } + + errno = 0; + cc = poll(poller, 1, 1010); /* network sleeps for 1000 between '.' outputs */ + if (cc > 0) + cc = read(dataPipe[0], &buffer[n], buffsize - n); + + if (cc < 0) + { + if (errno == EINTR) + continue; + if (errno == EAGAIN) + continue; + break; + } + else if (cc == 0) + break; + + if ((mode & (QUIET | REDIR)) == 0) + bb_printf(&buffer[n]); + n += cc; + } + } + + if (mode & REDIR) + chomp(buffer); + } + else + { + bb_perror_msg("Failed to fork process"); + } + + n = 0; + if (pid) + { + close(dataPipe[0]); + + if ((mode & FORK) == 0) + { + if (waitpid(pid, &n, 0) == -1) + bb_printf("Couldn't wait?"); + } + if (WIFEXITED(n)) + n = WEXITSTATUS(n); + else + n = -1; + } + + free(args); + free(commandBuffer); + errno = n; + return buffer; +} + + +#ifdef RUNLEVEL_LIST +// From ifupdown, so it should probably be in libbb. +llist_t *llist_add_to_end(llist_t *list_head, char *data) +{ + llist_t *new_item, *tmp, *prev; + + new_item = xmalloc(sizeof(llist_t)); + new_item->data = data; + new_item->link = NULL; + + prev = NULL; + tmp = list_head; + while(tmp) + { + prev = tmp; + tmp = tmp->link; + } + if (prev) + prev->link = new_item; + else + list_head = new_item; + + return(list_head); +} +#endif + + +llist_t *llist_delete(llist_t **head, llist_t *previous, llist_t *current) +{ + if (previous == NULL) + { + *head = current->link; + free(current); + current = *head; + } + else + { + previous->link = current->link; + free(current); + current = previous->link; + } + + return current; +} + + +void make_disk(char *token, const nodes_t *nodes) +{ + int i; + char temp[32]; + + for (i = 0; nodes[i].name != 0; i++) + { + if (strncmp(nodes[i].name, token, 3) == 0) + { + int m = atoi(&token[3]); + sprintf(temp, "/dev/%s", token); + mknod(temp, nodes[i].mode, makedev(nodes[i].major, nodes[i].minor + m)); + break; + } + } + sprintf(temp, "/media/%s", token); + bb_make_directory(temp, -1l, FILEUTILS_RECUR); +} + + +void make_ram_disk(int size, int number, char *place, int TMPFS) +{ + if (size > 0) + { + char *place2; + + bb_printf( "Creating ramdisk at %s\n", place); + bb_xasprintf(&place2, "%s2", place); + if (copy_file(place, place2, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS) >= 0) + remove_file(place, FILEUTILS_RECUR | FILEUTILS_FORCE); + bb_make_directory (place, -1l, 0); + if (TMPFS) + quick_mount("tmpfs", "/dev/null", place, "-n -o size=%i", size * 1024); + else + { + doit(QUIET, "mkfs.minix /dev/ram%i %i", number, size); + quick_mount("minix", "", "", "/dev/ram%i %s", number, place); + } + if (copy_file(place2, place, FILEUTILS_RECUR | FILEUTILS_PRESERVE_STATUS) >= 0) + remove_file(place2, FILEUTILS_RECUR | FILEUTILS_FORCE); + free(place2); + } +} + + +void quick_mount(char *type, char *device, char *path, char *data, ...) +{ + char *dataBuffer; + va_list p; + int r; + + va_start(p, data); + r = vasprintf(&dataBuffer, data, p); + va_end(p); + if (r < 0) + bb_perror_msg("quick_mount"); + else + { + doit(QUIET, "busybox mount -t %s %s %s %s", type, device, path, dataBuffer); + } + + free(dataBuffer); +} + + +char *quick_read(char *filename) +{ + char *result = NULL; + + if (stat(filename, &path_stat) == 0) + { +// if (S_ISREG(path_stat.st_mode)) + { + int ifd; + ssize_t size = path_stat.st_size; + + if (size <= 0) + size = 1024; + result = (char *) xmalloc (sizeof (char) * size + 1); + if ((ifd = open(filename, O_RDONLY)) < 0) + bb_perror_msg("%s", filename); + else + { + ssize_t total = bb_full_read(ifd, result, size); +// result[path_stat.st_size] = '\0'; + result[total] = '\0'; + if (close (ifd) < 0) + bb_perror_msg("%s", filename); + } + } + } + + return result; +} + + +void quick_write(const char *filename, const char *data, ...) +{ + char *dataBuffer; + va_list p; + int r; + + va_start(p, data); + r = vasprintf(&dataBuffer, data, p); + va_end(p); + if (r >= 0) + { + int ofd; + + if ((ofd = open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666)) < 0) + bb_perror_msg("%s", filename); + else + { + r = bb_full_write(ofd, dataBuffer, r); + if (close (ofd) < 0) + bb_perror_msg("%s", filename); + } + } + if (r < 0) + bb_perror_msg("quick_write"); + + free(dataBuffer); +} diff --git a/urunlevel/runlevel/lib_init_d.h b/urunlevel/runlevel/lib_init_d.h new file mode 100644 index 0000000..a9179d5 --- /dev/null +++ b/urunlevel/runlevel/lib_init_d.h @@ -0,0 +1,202 @@ +/* + * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#ifndef _INIT_D_H +#define _INIT_D_H + + +/* + * init script defines + */ + +#define INIT_D_COMMENT "\n#// " +#define INIT_D_BEGIN "\n### BEGIN INIT INFO " +#define INIT_D_PROV "\n# Provides: " +#define INIT_D_RSTART "\n# Required-Start: " +#define INIT_D_RSTOP "\n# Required-Stop: " +#define INIT_D_SSTART "\n# Should-Start: " +#define INIT_D_SSTOP "\n# Should-Stop: " +#define INIT_D_DSTART "\n# Default-Start: " +#define INIT_D_DSTOP "\n# Default-Stop: " +#define INIT_D_SDESC "\n# Short-Description: " +#define INIT_D_DESC "\n# Description: " +#define INIT_D_CONT "\n#\t" +#define INIT_D_CONT2 "\n# " +#define INIT_D_END "\n### END INIT INFO\n" +#define INIT_D_CUSTOM "\n# X-" + + +/* + * init info + */ + +typedef struct init_d_info_s { + char **provides; + char **reqstart; + char **reqstop; + char **shouldstart; + char **shouldstop; + int *defstart; + int *defstop; + char *shortdesc; + char *desc; + char *comment; + int sizes[11]; + char *path; + llist_t *start; +} init_d_info_t; + + +/* + * init commands + */ + +typedef struct init_d_handle_s { + int (*start)(struct init_d_handle_s *, int); + int (*stop)(struct init_d_handle_s *, int); + int (*restart)(struct init_d_handle_s *, int); + int (*try_restart)(struct init_d_handle_s *, int); + int (*reload)(struct init_d_handle_s *, int); + int (*force_reload)(struct init_d_handle_s *, int); + int (*status)(struct init_d_handle_s *, int); + int (*show_info)(struct init_d_handle_s *, int); + char *basename; + char *pathname; + char *args; + char *pidfile; + char *info; +} init_d_handle_t; + + +int do_init_from_main(int argc, char **argv, struct init_d_handle_s *init_d); +int do_init(struct init_d_handle_s *init_d, const char *command); + +int default_start(struct init_d_handle_s *, int); +int default_stop(struct init_d_handle_s *, int); +int default_restart(struct init_d_handle_s *, int); +int default_try_restart(struct init_d_handle_s *, int); +int default_reload(struct init_d_handle_s *, int); +int default_force_reload(struct init_d_handle_s *, int); +int default_status(struct init_d_handle_s *, int); +int default_show_info(struct init_d_handle_s *, int); + +int no_stop(struct init_d_handle_s *, int); +int no_reload(struct init_d_handle_s *, int); +int no_status(struct init_d_handle_s *, int); + +int sighup_reload(struct init_d_handle_s *, int); +int print_status(struct init_d_handle_s *init_d, int quiet, int status); + +/* + * error codes + */ + +#define INIT_D_OK 0 +#define INIT_D_ERROR_GENERIC 1 +#define INIT_D_ERROR_ARGS 2 +#define INIT_D_ERROR_NOT_IMPLEMENTED 3 +#define INIT_D_ERROR_SECURITY 4 +#define INIT_D_ERROR_NOT_INSTALLED 5 +#define INIT_D_ERROR_NOT_CONFIGURED 6 +#define INIT_D_ERROR_NOT_RUNNING 7 + + +/* + * internal error codes + * + * Only used internally to support just_checking. + */ + +#define INIT_D_ERROR_JUST_RUNNING 150 +#define INIT_D_ERROR_JUST_NOT_RUNNING 151 + + +/* + * status codes + */ + +#define INIT_D_STATUS_OK 0 +#define INIT_D_STATUS_DEAD_PID 1 +#define INIT_D_STATUS_DEAD_LOCK 2 +#define INIT_D_STATUS_NOT_RUNNING 3 +#define INIT_D_STATUS_UNKNOWN 4 + + +/* + * /lib/lsb/init-functions + */ +int start_daemon(int force, int nice_level, char *pidfile, char *pathname, char *args); +int killproc(char *pidfile, char *pathname, int my_signal); +int checkpid(char *pid); +int pidofproc(char *pidfile, char *pathname, char **pids); +void log_success_msg(char *message); +void log_failure_msg(char *message); +void log_warning_msg(char *message); + + +init_d_info_t *parse_init_info(char *info_text, char *name); +char *get_init_info(char *pathname); +llist_t *get_scripts(void); +llist_t *sort_scripts(llist_t *unsorted); + + +#define REDIR 1 +#define QUIET 2 +#define ERRONLY 4 +#define FORK 8 +#define NOFORK 16 +#define DAEMON 32 + +extern struct stat path_stat; + +typedef struct nodes_s +{ + const char *name; + mode_t mode; + int major; + int minor; + int count; +} nodes_t; + + +char *argv_cat(int argc, char **argv); +char *big_chomp(char *s); +int checkpid(char *pid); +char *doit(int mode, char *command, ...); + +#ifndef CONFIG_IFUPDOWN +#define RUNLEVEL_LIST 1 +#endif +#ifdef RUNLEVEL_LIST +// From ifupdown, so it should probably be in libbb. +llist_t *llist_add_to_end(llist_t *list_head, char *data); +#else +extern llist_t *llist_add_to_end(llist_t *list_head, char *data); +#endif + +llist_t *llist_delete(llist_t **unsorted, llist_t *previous, llist_t *current); +void make_disk(char *token, const nodes_t *nodes); +void make_ram_disk(int size, int number, char *place, int TMPFS); +void quick_mount(char *type, char *device, char *path, char *data, ...); +char *quick_read(char *filename); +void quick_write(const char *filename, const char *data, ...); + + +#endif diff --git a/urunlevel/runlevel/local_fs.c b/urunlevel/runlevel/local_fs.c new file mode 100644 index 0000000..17b45f6 --- /dev/null +++ b/urunlevel/runlevel/local_fs.c @@ -0,0 +1,199 @@ +/* + * Mini $local_fs boot implementation for busybox. + * + * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include +#include + +#include "busybox.h" +#include "lib_init_d.h" + + +const static nodes_t nodes[] = +{ + {"hda", S_IFBLK, 3, 0, 0}, + {"hdb", S_IFBLK, 3, 64, 0}, + {"hdc", S_IFBLK, 22, 0, 0}, + {"hdd", S_IFBLK, 22, 64, 0}, + {"ram", S_IFBLK, 1, 0, 9}, + {"fd", S_IFBLK, 2, 0, 1}, + {"loop", S_IFBLK, 7, 0,63}, + {"cloop", S_IFBLK, 240, 0, 7}, + {"vcs", S_IFBLK, 7, 0, 9}, + {"vcsa", S_IFBLK, 7, 0, 9}, + {0, 0, 0, 0, 0} +}; + + +static int start(struct init_d_handle_s *, int); +static int status(struct init_d_handle_s *, int); +static int stop(struct init_d_handle_s *, int); + + +static init_d_handle_t my_commands = +{ + &start, + &stop, + NULL, + NULL, + &no_reload, + NULL, + &status, + NULL, + "local_fs", + NULL, + NULL, + NULL, + INIT_D_BEGIN \ + INIT_D_PROV "$local_fs" \ + INIT_D_DSTART "1 2 3 4 5" \ + INIT_D_DSTOP "0 6" \ + INIT_D_SDESC "Mount all local file systems." \ + INIT_D_DESC "Mount all local file systems." \ + INIT_D_CONT "Including any left over partitions not otherwise mounted." \ + INIT_D_END +}; + + +static const char *i386_sys_types[] = +{ +// " 0Empty", +// " 1fat", +// " 4fat", +// " 6fat", +// " bvfat", + " cvfat", +// " evfat", +// " fvfat", + "80minix", + "81minix", + "82swap", + "83ext2", + "85Linux extended", + 0 +}; + + +int local_fs_main(int argc, char **argv) +{ + return do_init_from_main(argc, argv, &my_commands); +} + + +static int start(struct init_d_handle_s *init_d, int just_checking) +{ + int i; + char *CMDLINE = 0; + char *ROOT = 0; + char *CDEV = 0; + char *FDEV = 0; + char *token; + char *strtok_temp; + +sleep(5); // delay it for testing purposes +// Should fsck all non root partitions first. + doit(0, "/bin/mount -a"); + bb_xasprintf(&CMDLINE, "%s", doit(REDIR, "cat /proc/cmdline")); + for (token = strtok_r(CMDLINE, " \t\n\r", &strtok_temp); token != NULL; token = strtok_r(NULL, " \t\n\r", &strtok_temp)) + { + if (strncmp(token, "ROOT=", 5) == 0) + ROOT = &token[5]; + } + + bb_xasprintf(&CDEV, "%s", doit(REDIR, "dmesg | grep D-ROM | grep hd | cut -d: -f1 | sort | uniq")); + + bb_xasprintf(&FDEV, "%s %s", doit(REDIR, "dmesg | grep -v LDM | grep \"^ [sh]d[a-f]\" | cut -d':' -f2 | sort | uniq"), (CDEV != 0) ? CDEV : ""); + token = strtok_r(FDEV, " \r\n", &strtok_temp); + for (i = 0; token != NULL; i++) + { + if (strlen(token) > 2) + make_disk(token, nodes); + token = strtok_r(NULL, " \r\n", &strtok_temp); + } + + bb_xasprintf(&FDEV, "%s", doit(REDIR, "fdisk -l | grep \"^/dev/\" | cut -b6-10,52-55")); + token = strtok_r(FDEV, "\r\n", &strtok_temp); + for (i = 0; token != NULL; i++) + { + int j; + int found = 0; + char *type = &token[6]; + token[4] = '\0'; + for (j = 0; i386_sys_types[j] != 0; j++) + { + if (strncmp(i386_sys_types[j], type, 2) == 0) + { + char *DEV = 0; + char *MOUNT = 0; + char *TYPE = 0; + + bb_xasprintf(&DEV, "/dev/%s", token); + bb_xasprintf(&MOUNT, "/media/%s", token); + bb_xasprintf(&TYPE, "%s", &i386_sys_types[j][2]); + found = 1; + if (strncmp(&i386_sys_types[j][2], "swap", 4) == 0) + { + doit(QUIET, "mkswap %s", DEV); + doit(QUIET, "swapon %s", DEV); + } + else + { +// Should not mount it if it is already mounted. + if ((ROOT == 0) || strcmp(ROOT, DEV) != 0) /* Don't try to remount ROOT, */ + { + make_disk(token, nodes); + quick_mount(TYPE, DEV, MOUNT, "-o ro"); +// quick_mount("auto", DEV, MOUNT, "-o ro"); + } + } + + break; + } + } +// if (found == 0) +// bb_printf(" %s - unknown\n", token); + + token = strtok_r(NULL, "\r\n", &strtok_temp); + } + + free(FDEV); + free(CDEV); + free(ROOT); + free(CMDLINE); + + return INIT_D_OK; +} + + +static int status(struct init_d_handle_s *init_d, int quiet) +{ + return print_status(init_d, quiet, INIT_D_STATUS_OK); +} + + +static int stop(struct init_d_handle_s *init_d, int just_checking) +{ +// Should only umount things we mounted in the first place. +// Same for swap + doit(0, "/sbin/swapoff -a"); + doit(0, "/bin/umount -a -r"); + return INIT_D_OK; +} diff --git a/urunlevel/runlevel/log_failure_msg.c b/urunlevel/runlevel/log_failure_msg.c new file mode 100644 index 0000000..47f43f7 --- /dev/null +++ b/urunlevel/runlevel/log_failure_msg.c @@ -0,0 +1,54 @@ +/* + * Mini log_failure_msg implementation for busybox. + * + * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include + +#include "busybox.h" +#include "lib_init_d.h" + + +void log_failure_msg(char *message) +{ + bb_perror_msg("Failure - %s\n", message); +} + + +/* +log_failure_msg "message" + This requests the distribution to print a failure + message. The message should be relatively short; no + more than 60 characters is highly desirable. +*/ + +int log_failure_msg_main(int argc, char **argv) +{ + char *message = argv_cat(argc, argv); + + if (message != NULL) + { + log_failure_msg(message); + + free(message); + return EXIT_SUCCESS; + } + return EXIT_FAILURE; +} diff --git a/urunlevel/runlevel/log_success_msg.c b/urunlevel/runlevel/log_success_msg.c new file mode 100644 index 0000000..caa1eed --- /dev/null +++ b/urunlevel/runlevel/log_success_msg.c @@ -0,0 +1,54 @@ +/* + * Mini log_success_msg implementation for busybox. + * + * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include + +#include "busybox.h" +#include "lib_init_d.h" + + +void log_success_msg(char *message) +{ + bb_printf("Success - %s\n", message); +} + + +/* +log_success_msg "message" + This requests the distribution to print a success + message. The message should be relatively short; no + more than 60 characters is highly desirable. +*/ + +int log_success_msg_main(int argc, char **argv) +{ + char *message = argv_cat(argc, argv); + + if (message != NULL) + { + log_success_msg(message); + + free(message); + return EXIT_SUCCESS; + } + return EXIT_FAILURE; +} diff --git a/urunlevel/runlevel/log_warning_msg.c b/urunlevel/runlevel/log_warning_msg.c new file mode 100644 index 0000000..81ef204 --- /dev/null +++ b/urunlevel/runlevel/log_warning_msg.c @@ -0,0 +1,54 @@ +/* + * Mini log_warning_msg implementation for busybox. + * + * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include + +#include "busybox.h" +#include "lib_init_d.h" + + +void log_warning_msg(char *message) +{ + bb_perror_msg("Warning - %s\n", message); +} + + +/* +log_warning_msg "message" + This requests the distribution to print a warning + message. The message should be relatively short; no + more than 60 characters is highly desirable. +*/ + +int log_warning_msg_main(int argc, char **argv) +{ + char *message = argv_cat(argc, argv); + + if (message != NULL) + { + log_warning_msg(message); + + free(message); + return EXIT_SUCCESS; + } + return EXIT_FAILURE; +} diff --git a/urunlevel/runlevel/network.c b/urunlevel/runlevel/network.c new file mode 100644 index 0000000..dff5fc1 --- /dev/null +++ b/urunlevel/runlevel/network.c @@ -0,0 +1,146 @@ +/* + * Mini network boot implementation for busybox. + * + * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include +#include + +#include "busybox.h" +#include "lib_init_d.h" + + +static int start(struct init_d_handle_s *, int); +static int status(struct init_d_handle_s *init_d, int); +static int stop(struct init_d_handle_s *, int); + + +static init_d_handle_t my_commands = +{ + &start, + &stop, + NULL, + NULL, + NULL, + NULL, + &status, + NULL, + "network", + NULL, + NULL, + NULL, + INIT_D_BEGIN \ + INIT_D_PROV "$network" \ + INIT_D_RSTART "$syslog" \ + INIT_D_DSTART "3 4 5" \ + INIT_D_DSTOP "0 1 2 6" \ + INIT_D_SDESC "Basic network setup" \ + INIT_D_DESC "Configures all your network interfaces," \ + INIT_D_CONT "brings them all up and sets up routing." \ + INIT_D_CONT "Also configures things like port forwarding," \ + INIT_D_CONT "hostnames, etc." \ + INIT_D_END +}; + + +int network_main(int argc, char **argv) +{ + return do_init_from_main(argc, argv, &my_commands); +} + + +static int start(struct init_d_handle_s *init_d, int just_checking) +{ + int i; + int my_status = (init_d->status)(init_d, 0); + char *IPADDR = 0; + + if (my_status == INIT_D_STATUS_NOT_RUNNING) + { + my_status = INIT_D_ERROR_NOT_RUNNING; +// if (stat("/proc/net/pnp", &path_stat) == 0) +// copy_file("/proc/net/pnp", "/etc/resolv.conf", FILEUTILS_FORCE | FILEUTILS_PRESERVE_STATUS); + + fflush(stdout); + doit(QUIET, "ifup -af"); + for (i = 20; stat("/var/lib/network/ipaddr", &path_stat) != 0; i--) + { + bb_printf("."); + fflush(stdout); + sleep(2); + if (i <= 0) + { + bb_printf(" timeout."); + break; + } + } + + if (stat("/var/lib/network/ipaddr", &path_stat) == 0) + IPADDR = quick_read("/var/lib/network/ipaddr"); + + if ((IPADDR != 0) && (IPADDR[0] != '\0')) + { + if (stat("/proc/sys/net/ipv4/tcp_syn_retries", &path_stat) == 0) + quick_write("/proc/sys/net/ipv4/tcp_syn_retries", "7"); + if (stat("/var/lib/my_linux/config/ipfwd", &path_stat) == 0) + { + bb_printf("Enabling IP forwarding\n"); + quick_write("/proc/sys/net/ipv4/ip_forward", "1"); + } + if (stat("/var/lib/my_linux/config/noping", &path_stat) == 0) + quick_write("/proc/sys/net/ipv4/icmp_echo_ignore_all", "1"); + my_status = INIT_D_OK; + } + else + my_status = INIT_D_ERROR_GENERIC; + + free(IPADDR); + } + else + my_status = INIT_D_OK; + + return my_status; +} + + +static int status(struct init_d_handle_s *init_d, int quiet) +{ + int my_status = INIT_D_STATUS_NOT_RUNNING; + char *ip = NULL; + + bb_xasprintf(&ip, "%s", doit(REDIR, "ip -o addr | grep lo: | cut -d\" \" -f3 | cut -d\",\" -f2")); + if ((ip != NULL) && (strncmp("UP", ip, 2) == 0)) + my_status = INIT_D_STATUS_OK; + + return print_status(init_d, quiet, my_status); +} + + +static int stop(struct init_d_handle_s *init_d, int just_checking) +{ + int my_status = default_stop(init_d, 1); + + if (my_status == INIT_D_ERROR_JUST_RUNNING) + { + doit(QUIET, "ifdown -af"); + my_status = INIT_D_OK; + } + return my_status; +} diff --git a/urunlevel/runlevel/pidofproc.c b/urunlevel/runlevel/pidofproc.c new file mode 100644 index 0000000..6d03ae8 --- /dev/null +++ b/urunlevel/runlevel/pidofproc.c @@ -0,0 +1,192 @@ +/* + * Mini pidofproc implementation for busybox. + * + * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include +#include +#include + +#include "busybox.h" +#include "lib_init_d.h" + + +int checkpid(char *pid) +{ + int found = 0; + char proc[132]; + + sprintf(proc, "/proc/%s", pid); + if (stat(proc, &path_stat) == 0) + { + char *state = NULL; + + sprintf(proc, "/proc/%s/stat", pid); + state = quick_read(proc); + if (state != NULL) + { + /* Read and interpret the third space seperated field (State - DRSW = OK - ZX = DEAD_PID - T = STOPPED) */ + if (state[0] != '\0') + { + while (*state != ' ') state++; + while (*state == ' ') state++; + while (*state != ' ') state++ +// Should compare the name while scanning this. + ; + while (*state == ' ') state++; + switch (*state) + { + case 'D' : + case 'R' : + case 'S' : + case 'W' : + case 'T' : /* Until proven otherwise, I'm assuming this means OK. */ + found = 1; + } + } + } + else /* Paranoid fallbacks. */ + { + sprintf(proc, "/proc/%s/exe", pid); + if (stat(proc, &path_stat) == 0) + { +// Should check that it is a link to our executable. + found = 1; + } + else + { + sprintf(proc, "/proc/%s/cmdline", pid); + if (stat(proc, &path_stat) == 0) + { +// Should compare the name. + found = 1; + } + } + } + + } + + return found; +} + + +int pidofproc(char *pidfile, char *pathname, char **pids) +{ + int status = INIT_D_STATUS_UNKNOWN; + char *our_pidfile = pidfile; + char *our_pids = NULL; + + if (our_pidfile == NULL) + bb_xasprintf(&our_pidfile, "/var/run/%s.pid", bb_get_last_path_component(pathname)); + + our_pids = quick_read(our_pidfile); + + if (our_pids != NULL) + { + int i; + char *pid; + char *strtok_temp; + + status = INIT_D_STATUS_DEAD_PID; + if (pids != NULL) + { + (*pids) = (char *) xmalloc(sizeof (char) * strlen(our_pids) + 1); + (*pids)[0] = '\0'; + } + + pid = strtok_r(our_pids, " \n\r", &strtok_temp); + for (i = 0; pid != NULL; i++) + { + if (checkpid(pid)) + { + if (pids != NULL) + { + strcat(*pids, pid); + strcat(*pids, " "); + } + status = INIT_D_STATUS_OK; + } + + pid = strtok_r(NULL, " \n\r", &strtok_temp); + } + + free(our_pids); + } + else + status = INIT_D_STATUS_NOT_RUNNING; + + if (pidfile == NULL) + free(our_pidfile); + + return status; +} + + +/* +pidofproc [-p pidfile] pathname + This function returns one or more pid(s) for a particular + daemon using the algorithm given above. Only pids of running processes + should be returned. + + Multiple pid(s) shall be separated by a single space in the pidfile + and in the output of pidofproc. + + Compliant applications may use the basename instead of the pathname. + pidofproc should return the LSB defined exit status + codes for "status". It shall return 0 if the program is + running and not 0 otherwise. +*/ + +static const struct option long_options[] = +{ + { "pidfile", 1, NULL, 'p' }, + { 0, 0, 0, 0 } +}; + +int pidofproc_main(int argc, char **argv) +{ + int result = EXIT_FAILURE; + char *pidfile = NULL; + char *pids = NULL; + int opt; + + while ((opt = getopt_long (argc, argv, "p:", long_options, NULL)) > 0) + { + switch (opt) + { + case 'p': + pidfile = optarg; + break; + + default: + bb_show_usage(); + } + } + + /* We require exactly one argument: the path name */ + if (optind != (argc - 1)) + bb_show_usage(); + + result = pidofproc(pidfile, argv[optind], &pids); + if (pids != NULL) + bb_printf("%s\n", pids); + + return result; +} diff --git a/urunlevel/runlevel/rc.c b/urunlevel/runlevel/rc.c new file mode 100644 index 0000000..9efe84d --- /dev/null +++ b/urunlevel/runlevel/rc.c @@ -0,0 +1,1271 @@ +/* + * Mini rc implementation for busybox. + * + * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "busybox.h" +#include "lib_init_d.h" + + +const static char *commands[] = +{ + "start", + "stop", + "restart", + "try-restart", + "reload", + "force-reload", + "status", + "info", + NULL +}; + + +const static char *INFOS[] = +{ + INIT_D_BEGIN, + INIT_D_PROV, + INIT_D_RSTART, + INIT_D_RSTOP, + INIT_D_SSTART, + INIT_D_SSTOP, + INIT_D_DSTART, + INIT_D_DSTOP, + INIT_D_SDESC, + INIT_D_DESC, + INIT_D_COMMENT, + INIT_D_CONT, + INIT_D_CONT2, + INIT_D_END, + NULL +}; + + +int default_start(struct init_d_handle_s *init_d, int just_checking) +{ + int status = (init_d->status)(init_d, 0); + + switch (status) + { + case INIT_D_STATUS_OK : + { + status = INIT_D_OK; + break; + } + + case INIT_D_STATUS_DEAD_PID : + { + log_warning_msg("Stale pid file exists!"); + status = INIT_D_ERROR_GENERIC; // LSB is not clear on what to return, but this is an error condition. + break; + } + + case INIT_D_STATUS_DEAD_LOCK : + { + log_warning_msg("Stale lock file exists!"); + status = INIT_D_ERROR_GENERIC; // LSB is not clear on what to return, but this is an error condition. + break; + } + + case INIT_D_STATUS_NOT_RUNNING : + { + struct stat script_stat; + + if (stat(init_d->pathname, &script_stat) == 0) + { + if (just_checking) + status = INIT_D_ERROR_JUST_NOT_RUNNING; + else + status = start_daemon(0, 0, init_d->pidfile, init_d->pathname, init_d->args); + } + else + status = INIT_D_ERROR_NOT_INSTALLED; + break; + } + + default : + { + status = INIT_D_ERROR_GENERIC; + break; + } + } + + return status; +} + + +int default_stop(struct init_d_handle_s *init_d, int just_checking) +{ + int status = (init_d->status)(init_d, 0); + + switch (status) + { + case INIT_D_STATUS_OK : + { + if (just_checking) + status = INIT_D_ERROR_JUST_RUNNING; + else + status = killproc(init_d->pidfile, init_d->pathname, 0); + break; + } + + case INIT_D_STATUS_DEAD_PID : + { + log_warning_msg("Stale pid file exists!"); + status = INIT_D_ERROR_GENERIC; // LSB is not clear on what to return, but this is an error condition. + break; + } + + case INIT_D_STATUS_DEAD_LOCK : + { + log_warning_msg("Stale lock file exists!"); + status = INIT_D_ERROR_GENERIC; // LSB is not clear on what to return, but this is an error condition. + break; + } + + case INIT_D_STATUS_NOT_RUNNING : + { + status = INIT_D_OK; + break; + } + + default : + { + status = INIT_D_ERROR_GENERIC; + break; + } + } + + return status; +} + + +int default_restart(struct init_d_handle_s *init_d, int just_checking) +{ + int status = (init_d->status)(init_d, 0); + + switch (status) + { + case INIT_D_STATUS_OK : + { + status = (init_d->stop)(init_d, just_checking); + if ((status == INIT_D_OK) || (status == INIT_D_ERROR_NOT_RUNNING)) + status = INIT_D_STATUS_NOT_RUNNING; + else + status = INIT_D_STATUS_UNKNOWN; + break; + } + + case INIT_D_STATUS_DEAD_PID : + { + log_warning_msg("Stale pid file exists!"); + break; + } + + case INIT_D_STATUS_DEAD_LOCK : + { + log_warning_msg("Stale lock file exists!"); + break; + } + } + if (status == INIT_D_STATUS_NOT_RUNNING) + status = (init_d->start)(init_d, just_checking); + else + status = INIT_D_ERROR_GENERIC; + + return status; +} + + +int default_try_restart(struct init_d_handle_s *init_d, int just_checking) +{ + int status = (init_d->status)(init_d, 0); + + switch (status) + { + case INIT_D_STATUS_OK : + { + status = (init_d->stop)(init_d, just_checking); + if (status == INIT_D_OK) + status = (init_d->start)(init_d, just_checking); + else if (status == INIT_D_ERROR_NOT_RUNNING) /* I think this is what LSB 8.2.61 means. LSB 8.2.59 means that this should never happen though. */ + status = INIT_D_OK; + break; + } + + case INIT_D_STATUS_NOT_RUNNING : /* I think this is what LSB 8.2.61 means. */ + { /* If try-restart was meant to start a stopped service, then it would be no different from restart. + * LSB 8.2.42-44 may have some bearing on this, but the english is broken, rendering it unintelligable. + * OTH, try-restart is optional, so a broken implentation is no problem B-). + * OTGH, our force-reload uses this as it's fallback position. + */ + status = INIT_D_OK; + break; + } + + default : + { + status = INIT_D_ERROR_GENERIC; + } + } + + return status; +} + + +int default_reload(struct init_d_handle_s *init_d, int just_checking) +{ + return INIT_D_ERROR_NOT_IMPLEMENTED; +} + + +int sighup_reload(struct init_d_handle_s *init_d, int just_checking) +{ + int status = (init_d->status)(init_d, 0); + + switch (status) + { + case INIT_D_STATUS_OK : + { + if (just_checking) + status = INIT_D_ERROR_JUST_RUNNING; + else + status = killproc(init_d->pidfile, init_d->pathname, SIGHUP); + break; + } + + case INIT_D_STATUS_NOT_RUNNING : + { + status = INIT_D_ERROR_NOT_RUNNING; + break; + } + + default : + { + status = INIT_D_ERROR_GENERIC; + break; + } + } + + return status; +} + + +int default_force_reload(struct init_d_handle_s *init_d, int just_checking) +{ + int status = (init_d->reload)(init_d, just_checking); + + if (status == INIT_D_ERROR_NOT_IMPLEMENTED) + status = (init_d->try_restart)(init_d, just_checking); + + return status; +} + + +int print_status(struct init_d_handle_s *init_d, int quiet, int status) +{ + if (quiet) + switch (status) + { + case INIT_D_STATUS_OK : + { + bb_printf("%s is running.\n", init_d->basename); + break; + } + + case INIT_D_STATUS_DEAD_PID : + { + bb_printf("%s is not running, but there is a stale %s.\n", init_d->basename, init_d->pidfile); + break; + } + + case INIT_D_STATUS_DEAD_LOCK : + { + bb_printf("%s is not running, but there is a stale lock file.\n", init_d->basename); + break; + } + + case INIT_D_STATUS_NOT_RUNNING : + { + bb_printf("%s is not running.\n", init_d->basename); + break; + } + + default : + { + bb_printf("The status of %s is not known.\n", init_d->basename); + break; + } + } + + return status; +} + + +int default_status(struct init_d_handle_s *init_d, int quiet) +{ + return print_status(init_d, quiet, pidofproc(init_d->pidfile, init_d->pathname, NULL)); +} + + +int default_show_info(struct init_d_handle_s *init_d, int just_checking) +{ + bb_printf("%s", init_d->info); + return INIT_D_OK; +} + + +int no_stop(struct init_d_handle_s *init_d, int just_checking) +{ + return INIT_D_ERROR_NOT_IMPLEMENTED; +} + + +int no_reload(struct init_d_handle_s *init_d, int just_checking) +{ + return INIT_D_ERROR_NOT_IMPLEMENTED; +} + + +int no_status(struct init_d_handle_s *init_d, int quiet) +{ + return INIT_D_ERROR_NOT_IMPLEMENTED; +} + + +int do_init_from_main(int argc, char **argv, struct init_d_handle_s *init_d) +{ + return do_init(init_d, (argc > 1) ? argv[1] : NULL); +} + + +int do_init(struct init_d_handle_s *init_d, const char *command) +{ + int i; + int status = INIT_D_ERROR_NOT_IMPLEMENTED; + char *original_pidfile = init_d->pidfile; + + if (init_d->start == NULL) init_d->start = &default_start; + if (init_d->stop == NULL) init_d->stop = &default_stop; + if (init_d->restart == NULL) init_d->restart = &default_restart; + if (init_d->try_restart == NULL) init_d->try_restart = &default_try_restart; + if (init_d->reload == NULL) init_d->reload = &default_reload; + if (init_d->force_reload == NULL) init_d->force_reload = &default_force_reload; + if (init_d->status == NULL) init_d->status = &default_status; + if (init_d->show_info == NULL) init_d->show_info = &default_show_info; + if (init_d->basename == NULL) init_d->basename = bb_get_last_path_component(init_d->pathname); + if (init_d->pathname == NULL) init_d->pathname = init_d->basename; + if (init_d->args == NULL) init_d->args = ""; + if (init_d->pidfile == NULL) bb_xasprintf(&(init_d->pidfile), "/var/run/%s.pid", init_d->basename); + if (init_d->info == NULL) init_d->info = ""; + + if (command == NULL) + command = commands[2]; // Default to restart. + + for (i = 0; commands[i] != 0; i++) + { + if (strcmp(commands[i], command ) == 0) + { + switch (i) + { + case 0 : status = (init_d->start)(init_d, 0); break; + case 1 : status = (init_d->stop)(init_d, 0); break; + case 2 : status = (init_d->restart)(init_d, 0); break; + case 3 : status = (init_d->try_restart)(init_d, 0); break; + case 4 : status = (init_d->reload)(init_d, 0); break; + case 5 : status = (init_d->force_reload)(init_d, 0); break; + case 6 : status = (init_d->status)(init_d, 1); break; + case 7 : status = (init_d->show_info)(init_d, 0); break; + } + break; + } + } + + if (original_pidfile == NULL) + free(init_d->pidfile); + return status; +} + + +static int init_script(char *script, char *command) +{ + int status = INIT_D_ERROR_NOT_IMPLEMENTED; + + bb_printf("%c%s %s ... ", toupper(command[0]), &command[1], script); + fflush(stdout); + doit(0, "/etc/init.d/%s %s", script, command); + status = errno; + if (strcmp("status", command) != 0) + { + bb_printf("\t\t"); + switch (status) + { + case INIT_D_OK : bb_printf("OK"); break; + case INIT_D_ERROR_NOT_IMPLEMENTED : bb_printf("not implemented"); break; + case INIT_D_ERROR_NOT_INSTALLED : bb_printf("not installed"); break; + case INIT_D_ERROR_NOT_CONFIGURED : bb_printf("not configured"); break; + case INIT_D_ERROR_NOT_RUNNING : bb_printf("not running"); break; + case INIT_D_ERROR_GENERIC : bb_printf("failed"); break; + case INIT_D_ERROR_ARGS : bb_printf("invalid arguments"); break; + case INIT_D_ERROR_SECURITY : bb_printf("security failure"); break; + default : bb_printf("Failed!"); break; + } + bb_printf("\n"); + } + return status; +} + + +init_d_info_t *parse_init_info(char *info_text, char *name) +{ + init_d_info_t *info = NULL; + + // if init info found + if ((info_text != NULL) && (strncmp(info_text, INIT_D_BEGIN, strlen(INIT_D_BEGIN) - 1) == 0)) + { + if (strncmp(info_text, INIT_D_BEGIN, strlen(INIT_D_BEGIN) - 1) == 0) + { + int lastfound = -1; + char *strtok_line; + char *line; + char *linecopy; + + info = (init_d_info_t *) xcalloc(1, sizeof(init_d_info_t)); + bb_xasprintf(&info->path, "%s", name); + +//bb_printf("%s is an init script -%s", name, info_text); +//bb_printf("%s is an init script\n", name); + // parse info into structure + for (line = strtok_r(info_text, "\n\r", &strtok_line); line != NULL; line = strtok_r(NULL, "\n\r", &strtok_line)) + { + int count = 0; + int found = -1; + char *strtok_token; + char *token; + + bb_xasprintf(&linecopy, "%s", line); + for (token = strtok_r(line, " \t", &strtok_token); token != NULL; token = strtok_r(NULL, " \t", &strtok_token)) + { + switch (count++) + { + case 0 : break; /* Ignore the "#". */ + + case 1 : + { + int j; + for (j = 1; INFOS[j] != NULL; j++) + { +//bb_printf("%s = %s %s\n", linecopy, &(INFOS[j][1]), token); + if (strncmp(&(INFOS[j][1]), linecopy, strlen(&(INFOS[j][1])) - 1) == 0) + { + found = j - 1; + break; + } + } + break; + } + + default : + { + int multi = 1; + int string = 1; + void **kludge = (void **)info; + + switch (found) + { + case 5 : /* INIT_D_DSTART */ string = 0; break; + case 6 : /* INIT_D_DSTOP */ string = 0; break; + case 7 : /* INIT_D_SDESC */ multi = 0; break; + case 8 : /* INIT_D_DESC */ multi = 0; break; + case 10 : /* INIT_D_CONT */ + case 11 : /* INIT_D_CONT2 */ multi = 0; found = lastfound; break; + case 12 : /* INIT_D_END */ found = -1; break; + } + + if (found != -1) + { + void *temp = kludge[found]; + + if (multi == 1) + { + int size = info->sizes[found]; + + info->sizes[found]++; +// not LSB, but SuSE does it +if (token[0] == '$') + token = &token[1]; +// not LSB, but SuSE does it +if (strncmp(token, "boot.", 5) == 0) + token = &token[5]; + if (temp != NULL) + kludge[found] = xrealloc(kludge[found], sizeof (char **) * (size + 1)); + else + kludge[found] = xcalloc(1, sizeof (char **)); + if (string == 1) + bb_xasprintf(&((char **) kludge[found])[size], "%s", token); + else + { +// not LSB, but SuSE does it +if (token[0] == 'B') +{ + token[0] = '5'; + kludge[found] = xrealloc(kludge[found], sizeof (char **) * (10 + 1)); + ((int *) kludge[found])[0] = 1; + ((int *) kludge[found])[1] = 2; + ((int *) kludge[found])[2] = 3; + ((int *) kludge[found])[3] = 4; + size = 4; + info->sizes[found] = 5; +} +// not LSB, but SuSE does it +if (token[0] == 'S') + token[0] = '1'; + ((int *) kludge[found])[size] = atoi(token); + } + temp = NULL; + } + else + { + if (string == 1) + { + if (kludge[found] == NULL) + bb_xasprintf((char **) &kludge[found], "%s", token); + else + bb_xasprintf((char **) &kludge[found], "%s %s", (char *) kludge[found], token); + } + else + { +// Should never happen. int value = atoi(token); + temp = NULL; + } + } + + if (temp != NULL) + free(temp); + } + lastfound = found; + + break; + } + } + } + } + + +#if 0 +{ + int k; + + bb_printf("SCRIPT %s path %s\n", name, info->path); +// bb_printf("%s sizes ", name); +// for(k = 0; k < 10; k++) +// bb_printf("%d ", info->sizes[k]); +// bb_printf("\n"); + if (info->provides != NULL) + { + bb_printf("%s provides ", name); + for(k = 0; k < info->sizes[0]; k++) + bb_printf("%s ", info->provides[k]); + bb_printf("\n"); + } + if (info->reqstart != NULL) + { + bb_printf("%s reqstart ", name); + for(k = 0; k < info->sizes[1]; k++) + bb_printf("%s ", info->reqstart[k]); + bb_printf("\n"); + } + if (info->reqstop != NULL) + { + bb_printf("%s reqstop ", name); + for(k = 0; k < info->sizes[2]; k++) + bb_printf("%s ", info->reqstop[k]); + bb_printf("\n"); + } + + if (info->shouldstart != NULL) + { + bb_printf("%s shouldstart ", name); + for(k = 0; k < info->sizes[3]; k++) + bb_printf("%s ", info->shouldstart[k]); + bb_printf("\n"); + } + if (info->shouldstop != NULL) + { + bb_printf("%s shouldstop ", name); + for(k = 0; k < info->sizes[4]; k++) + bb_printf("%s ", info->shouldstop[k]); + bb_printf("\n"); + } + + if (info->defstart != NULL) + { + bb_printf("%s defstart ", name); + for(k = 0; k < info->sizes[5]; k++) + bb_printf("%d ", info->defstart[k]); + bb_printf("\n"); + } + if (info->defstop != NULL) + { + bb_printf("%s defstop ", name); + for(k = 0; k < info->sizes[6]; k++) + bb_printf("%d ", info->defstop[k]); + bb_printf("\n"); + } + if (info->shortdesc != NULL) + bb_printf("%s shortdes %s\n", name, info->shortdesc); + if (info->desc != NULL) + bb_printf("%s descript %s\n", name, info->desc); + bb_printf("\n"); +} +#endif + + // if database of runlevels per script includes overrides + // change info structure accordingly + } + } + + return info; +} + + +char *get_init_info(char *pathname) +{ + struct stat script_stat; + char *info_text = NULL; + char *base_name = bb_get_last_path_component(pathname); + + +//bb_printf("CHECKING %s, ", pathname); + // ignore rc, rcS, directories, non executables + if ((strcmp(base_name, "rc") != 0) && + (strcmp(base_name, "rcS") != 0) && + (stat(pathname, &script_stat) == 0)) + { + if ((!S_ISDIR(script_stat.st_mode)) && + S_ISREG(script_stat.st_mode) && + ((script_stat.st_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0 )) + { +//bb_printf("maybe init script, "); + // script info + if ((info_text == NULL) || (strncmp(info_text, INIT_D_BEGIN, strlen(INIT_D_BEGIN) - 1) != 0)) + bb_xasprintf(&info_text, "%s", doit(REDIR | QUIET, "%s info", pathname)); +//bb_printf("INFO = %s\n", info_text); + + // if not proper response + if ((info_text == NULL) || (strncmp(info_text, INIT_D_BEGIN, strlen(INIT_D_BEGIN) - 1) != 0)) + { + int count = 1; + int found = -1; + char *line; + FILE *contents; + +//bb_printf("search for INFO, "); + // search script for init info + info_text = (char *) xmalloc(sizeof (char) * 256 * 64); + info_text[0] = '\n'; + info_text[1] = '\0'; + contents = fopen(pathname, "r"); + if (contents != NULL) + { + do + { + line = fgets(&info_text[count], 255, contents); + if (line != NULL) + { + line--; + if ((found == -1) && (strncmp(line, INIT_D_BEGIN, strlen(INIT_D_BEGIN) - 1) == 0)) + found = 0; + + if (found != -1) + { + + if (strncmp(line, INIT_D_CUSTOM, strlen(INIT_D_CUSTOM)) != 0) + { + if (strncmp(line, INIT_D_END, strlen(INIT_D_END) - 1) == 0) + { +//bb_printf("INFO found, "); + line = NULL; + found = 64 + 1; + } + else + { + int cont = 0; + + if (strncmp(line, INIT_D_CONT, strlen(INIT_D_CONT)) == 0) + cont = 1; + if (strncmp(line, INIT_D_CONT2, strlen(INIT_D_CONT2)) == 0) + cont = 1; + if (cont == 1) + { +//bb_printf("\n\n\nCONT found%s\n\n\n, ", line); + info_text[count - 1] = ' '; + info_text[count] = ' '; + } + + found++; + count += strlen(line) - 1; + if (info_text[count - 1] != '\n') + { + info_text[count++] = '\n'; +// Should seek until the next \n, + } + } + info_text[count] = '\0'; + } + } + } + } while ((line != NULL) && (found < 64)); + + fclose(contents); + } + } + } + } +//bb_printf("\n"); + + return info_text; +} + + +llist_t *get_scripts(void) +{ + llist_t *result = NULL; + DIR *initd = opendir("/etc/init.d"); + + if (initd != NULL) + { + struct dirent *script; + + // foreach ls /etc/init.d + while ((script = readdir(initd)) != NULL) + { + char *info_text = NULL; + char *pathname = NULL; + init_d_info_t *info = NULL; + + bb_xasprintf(&pathname, "/etc/init.d/%s", script->d_name); + info_text = get_init_info(pathname); + info = parse_init_info(info_text, script->d_name); + if (info) + result = llist_add_to(result, (char *) info); + + free(info_text); + } + closedir(initd); + } + + return result; +} + + +llist_t *sort_scripts(llist_t *unsorted) +{ +// Should do something with info->shouldstart's + int count_moves = 0; + // all scripts start in unsorted list + llist_t *sorted = NULL; + llist_t *current = unsorted; + llist_t *previous = NULL; + + // pull out those with no deps and create a sorted list for each + while (current) + { + init_d_info_t *info = (init_d_info_t *) current->data; + + if (info->reqstart == NULL) + { + llist_t *new_list = NULL; + new_list = llist_add_to_end(new_list, (char *) info); + sorted = llist_add_to_end(sorted, (char *) new_list); + current = llist_delete(&unsorted, previous, current); + } + else + { + previous = current; + current = current->link; + } + } + + do + { + count_moves = 0; + current = unsorted; + previous = NULL; + // foreach in unsorted list + while (current) + { + int moved = 0; + init_d_info_t *info = (init_d_info_t *) current->data; + + if (info->reqstart != NULL) + { + int k; + llist_t *current_sort = sorted; + short done[info->sizes[1]]; + + // foreach sorted list + while (current_sort) + { + llist_t *current_list = (llist_t *) current_sort->data; + + // if ALL deps are in sorted list move script to end of sorted list + for(k = 0; k < info->sizes[1]; k++) + done[k] = 0; + while (current_list) + { + init_d_info_t *this_info = (init_d_info_t *) current_list->data; + + for(k = 0; k < info->sizes[1]; k++) + { + int i; + char *needs = info->reqstart[k]; + + if (done[k] == 0) + { +//bb_printf("%s NEEDS %s - ", info->path, needs); + for(i = 0; i < this_info->sizes[0]; i++) + { +//bb_printf("%s ", this_info->provides[i]); + if (strcmp(this_info->provides[i], needs) == 0) + { + done[k] = 1; + break; + } + } +//bb_printf("\n"); + } + } + current_list = current_list->link; + } + + moved = 1; + for(k = 0; k < info->sizes[1]; k++) + { + if (done[k] == 0) + { + moved = 0; + break; + } + } + if (moved == 1) + { + llist_t *list = (llist_t *) current_sort->data; + llist_add_to_end(list, (char *) info); + current = llist_delete(&unsorted, previous, current); + moved = 1; + count_moves++; + current_sort = NULL; + } + else + current_sort = current_sort->link; + } + } + + if (moved == 0) + { + previous = current; + current = current->link; + } + } + } while (count_moves != 0); + // until no more moves happen + + + do + { + count_moves = 0; + current = unsorted; + previous = NULL; + // foreach in unsorted list + while (current) + { + int moved = 1; + init_d_info_t *info = (init_d_info_t *) current->data; + short done[info->sizes[1]]; + + if (info->reqstart != NULL) + { + int k; + llist_t *current_sortof = sorted; + + // if ALL deps are in sorted lists + for(k = 0; k < info->sizes[1]; k++) + done[k] = 0; + while ((moved == 1) && (current_sortof != NULL)) + { + llist_t *current_listof = (llist_t *) current_sortof->data; + + while (current_listof) + { + init_d_info_t *this_info = (init_d_info_t *) current_listof->data; + + for(k = 0; k < info->sizes[1]; k++) + { + int i; + char *needs = info->reqstart[k]; + + if (done[k] == 0) + { +//bb_printf("%s NEEDS %s - ", info->path, needs); + for(i = 0; i < this_info->sizes[0]; i++) + { +//bb_printf("%s ", this_info->provides[i]); + if (strcmp(this_info->provides[i], needs) == 0) + { + done[k] = 1; + break; + } + } +//bb_printf("\n"); + } + } + current_listof = current_listof->link; + } + current_sortof = current_sortof->link; + } + + moved = 1; + for(k = 0; k < info->sizes[1]; k++) + { + if (done[k] == 0) + { + moved = 0; + break; + } + } + + if (moved == 1) + { + // create a merged list for script + llist_t *current_sort = sorted; + llist_t *new_list = NULL; + new_list = llist_add_to_end(new_list, (char *) info); + count_moves++; + + // foreach sorted | merged list + while (current_sort) + { + int found = 0; + llist_t *current_list = (llist_t *) current_sort->data; + + // if A dep is in s|m add s|m to end of new merged list & continue with next s|m + while (current_list) + { + init_d_info_t *this_info = (init_d_info_t *) current_list->data; + + for(k = 0; k < info->sizes[1]; k++) + { + int i; + char *needs = info->reqstart[k]; + + for(i = 0; i < this_info->sizes[0]; i++) + { + if (strcmp(this_info->provides[i], needs) == 0) + { + found = 1; + break; + } + } + if (found == 1) + break; + } + if (found == 1) + { + init_d_info_t *new_info = (init_d_info_t *) xcalloc(1, sizeof(init_d_info_t)); + new_info->start = current_sort; + new_list = llist_add_to_end(new_list, (char *) new_info); + current_list = NULL; + } + else + current_list = current_list->link; + } + + current_sort = current_sort->link; + } + + sorted = llist_add_to_end(sorted, (char *) new_list); + current = llist_delete(&unsorted, previous, current); + } + } + + if (moved == 0) + { + previous = current; + current = current->link; + } + } + } while (count_moves != 0); + // until no more creates happen + + + // unsorted list now contains unsatisfied and circular dependencies + // complain if not empty. + if (unsorted != NULL) + { + bb_printf("\nWARNING, the following init scripts have unresolved or circular dependencies -\n"); + current = unsorted; + + while (current) + { + init_d_info_t *info = (init_d_info_t *) current->data; + + bb_printf("%s\n", info->path); + current = current->link; +#if 0 +{ + int k; + + bb_printf("SCRIPT %s - ", info->path); + if (info->defstart != NULL) + { + bb_printf("\t\t "); + for(k = 0; k < info->sizes[5]; k++) + bb_printf("%d ", info->defstart[k]); +// bb_printf("\n"); + } + if (info->provides != NULL) + { + bb_printf("\t\t "); + for(k = 0; k < info->sizes[0]; k++) + bb_printf("%s ", info->provides[k]); +// bb_printf("\n"); + } + if (info->reqstart != NULL) + { + bb_printf("\n\t "); + for(k = 0; k < info->sizes[1]; k++) + bb_printf("%s ", info->reqstart[k]); +// bb_printf("\n"); + } + bb_printf("\n"); +} +#endif + } + bb_printf("\n"); + } + + return sorted; +} + + +static void call_scripts(llist_t *sorted, char *command, int oldlevel, int level) +{ + // call init_script(script, command) for each script in each list in created order + llist_t *current_sort = sorted; + + while (current_sort) + { + llist_t *current_list = (llist_t *) current_sort->data; + +//bb_printf("\nLIST\n"); + while (current_list) + { + init_d_info_t *info = (init_d_info_t *) current_list->data; + + if (info->path != NULL) + { + if (info->defstart != NULL) + { + int k; + int found = 0; + + // if info->DefaultStart includes level + for(k = 0; k < info->sizes[5]; k++) + { + if (info->defstart[k] == level) + { + found = 1; + break; + } + } + // if info->DefaultStart does not include previous level + for(k = 0; k < info->sizes[5]; k++) + { + if (info->defstart[k] == oldlevel) + { + found = 0; + break; + } + } + // add info structure to list + if (found == 1) + init_script(info->path, command); + } + +#if 0 +{ + int k; + + bb_printf("SCRIPT %s - ", info->path); + if (info->defstart != NULL) + { + bb_printf("\t\t "); + for(k = 0; k < info->sizes[5]; k++) + bb_printf("%d ", info->defstart[k]); +// bb_printf("\n"); + } + if (info->provides != NULL) + { + bb_printf("\t\t "); + for(k = 0; k < info->sizes[0]; k++) + bb_printf("%s ", info->provides[k]); +// bb_printf("\n"); + } + if (info->reqstart != NULL) + { + bb_printf("\n\t "); + for(k = 0; k < info->sizes[1]; k++) + bb_printf("%s ", info->reqstart[k]); +// bb_printf("\n"); + } + bb_printf("\n"); +} +#endif + } + current_list = current_list->link; + } + current_sort = current_sort->link; + } +} + + +int run_level(char *level) +{ + int oldlevel = 0; + int newlevel = atoi(level); + char *temp; + llist_t *sorted = NULL; + llist_t *reversed = NULL; + llist_t *current_sort = NULL; + + bb_printf("\n\nSwitching to run level %d", newlevel); + + // get previous run level + temp = quick_read("/var/lib/misc/runlevel"); + if (temp != NULL) + { + oldlevel = atoi(temp); + if (oldlevel < 0) + oldlevel = 1; + if (oldlevel > 6) + oldlevel = 5; + bb_printf(" from run level %d", oldlevel); + free(temp); + } + bb_printf(".\n\n"); + + // get scripts and sort dependencies, careful with circular dependencies + sorted = sort_scripts(get_scripts()); + + // reverse + current_sort = sorted; + while (current_sort) + { + llist_t *current_list = (llist_t *) current_sort->data; + llist_t *new_list = NULL; + + while (current_list) + { + new_list = llist_add_to(new_list, current_list->data); + current_list = current_list->link; + } + reversed = llist_add_to(reversed, (char *) new_list); + current_sort = current_sort->link; + } + + // call "stop" for each script + bb_printf("\n"); + call_scripts(reversed, "stop", newlevel, oldlevel); + + // call "start" for each script + bb_printf("\n"); + call_scripts(sorted, "start", oldlevel, newlevel); +// free all infos + + // set previous run level to new run level + quick_write("/var/lib/misc/runlevel", "%d", newlevel); + + +// Later, optionally call them in parallel when possible. + + +// Later, add a database of runlevels per script and allow editing them - +// rc network --runlevels 3 4 5 +// cat /etc/runlevels.conf +// runlevel="3" +// runlevel3="multi user with network." +// runlevel4="multi user with network and twin." +// runlevel5="multi user with network and X." +// local_fs="1 2 3 4 5" +// network="3 4 5" +// script1="2 3 5" +// script1="3 5" +// rc network --runlevels +// 3 4 5 +// rc network --runlevels -v +// The "network" service will be active during these run levels : +// 3 - multi user with network. +// 4 - multi user with network and twin. +// 5 - multi user with network and X. + + return EXIT_SUCCESS; +} + + +/* + * rc + * rc 1 + * rc network start + * rc network --runlevels + * rc network --runlevels -v + * rc network --runlevels 3 4 5 + */ + +int rc_main(int argc, char **argv) +{ + switch (argc) + { + case 0 : + case 1 : + { + return run_level(quick_read("/etc/runlevel")); + } + case 2 : return run_level(argv[1]); + case 3 : + { +// Should take care of dependencies for argv[1] script. + return init_script(argv[1], argv[2]); + } + default : + { + return INIT_D_ERROR_NOT_IMPLEMENTED; + } + } +} diff --git a/urunlevel/runlevel/remote_fs.c b/urunlevel/runlevel/remote_fs.c new file mode 100644 index 0000000..6da11f5 --- /dev/null +++ b/urunlevel/runlevel/remote_fs.c @@ -0,0 +1,83 @@ +/* + * Mini remote_fs boot implementation for busybox. + * + * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include + +#include "busybox.h" +#include "lib_init_d.h" + + +static int start(struct init_d_handle_s *, int); +static int status(struct init_d_handle_s *, int); +static int stop(struct init_d_handle_s *, int); + + +static init_d_handle_t my_commands = +{ + &start, + &stop, + NULL, + NULL, + &no_reload, + NULL, + &status, + NULL, + "remote_fs", + NULL, + NULL, + NULL, + INIT_D_BEGIN \ + INIT_D_PROV "$remote_fs" \ + INIT_D_RSTART "$network" \ + INIT_D_SSTART "nfs smbfs codafs" \ + INIT_D_DSTART "3 4 5" \ + INIT_D_DSTOP "0 1 2 6" \ + INIT_D_SDESC "Mount all remote file systems." \ + INIT_D_DESC "Mount all remote file systems. Actually, this is just a" \ + INIT_D_CONT "dummy that depends on all the init scripts that could" \ + INIT_D_CONT "possibly mount remote file systems." \ + INIT_D_END +}; + + +int remote_fs_main(int argc, char **argv) +{ + return do_init_from_main(argc, argv, &my_commands); +} + + +static int start(struct init_d_handle_s *init_d, int just_checking) +{ + return INIT_D_OK; +} + + +static int status(struct init_d_handle_s *init_d, int quiet) +{ + return print_status(init_d, quiet, INIT_D_STATUS_OK); +} + + +static int stop(struct init_d_handle_s *init_d, int just_checking) +{ + return INIT_D_OK; +} diff --git a/urunlevel/runlevel/remove_initd.c b/urunlevel/runlevel/remove_initd.c new file mode 100644 index 0000000..1224b03 --- /dev/null +++ b/urunlevel/runlevel/remove_initd.c @@ -0,0 +1,38 @@ +/* + * Mini remove_initd implementation for busybox. + * + * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include + +#include "busybox.h" +#include "lib_init_d.h" + + +int remove_initd_main(int argc, char **argv) +{ + llist_t *sorted = NULL; + llist_t *unsorted = get_scripts(); + +// Should remove this script from unsorted. + sorted = sort_scripts(unsorted); +// Should return 1 if there are unsatisfied dependencies if this is removed. + return EXIT_SUCCESS; +} diff --git a/urunlevel/runlevel/skeleton b/urunlevel/runlevel/skeleton new file mode 100755 index 0000000..cbd8b0e --- /dev/null +++ b/urunlevel/runlevel/skeleton @@ -0,0 +1,282 @@ +#! /bin/sh +# Copyright (c) 1995-2004 SUSE Linux AG, Nuernberg, Germany. +# All rights reserved. +# +# Author: Kurt Garloff +# Please send feedback to http://www.suse.de/feedback/ +# +# /etc/init.d/FOO +# and its symbolic link +# /(usr/)sbin/rcFOO +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# Template system startup script for some example service/daemon FOO +# +# LSB compatible service control script; see http://www.linuxbase.org/spec/ +# +# Note: This template uses functions rc_XXX defined in /etc/rc.status on +# UnitedLinux (UL) based Linux distributions. If you want to base your +# script on this template and ensure that it works on non UL based LSB +# compliant Linux distributions, you either have to provide the rc.status +# functions from UL or change the script to work without them. +# +### BEGIN INIT INFO +# Provides: FOO +# Required-Start: $syslog $remote_fs +# Should-Start: $time ypbind sendmail +# Required-Stop: $syslog $remote_fs +# Should-Stop: $time ypbind sendmail +# Default-Start: 3 5 +# Default-Stop: 0 1 2 6 +# Short-Description: FOO XYZ daemon providing ZYX +# Description: Start FOO to allow XY and provide YZ +# continued on second line by '#' +# should contain enough info for the runlevel editor +# to give admin some idea what this service does and +# what it's needed for ... +# (The Short-Description should already be a good hint.) +### END INIT INFO +# +# Any extensions to the keywords given above should be preceeded by +# X-VendorTag- (X-UnitedLinux- X-SuSE- for us) according to LSB. +# +# Notes on Required-Start/Should-Start: +# * There are two different issues that are solved by Required-Start +# and Should-Start +# (a) Hard dependencies: This is used by the runlevel editor to determine +# which services absolutely need to be started to make the start of +# this service make sense. Example: nfsserver should have +# Required-Start: $portmap +# Also, required services are started before the dependent ones. +# The runlevel editor will warn about such missing hard dependencies +# and suggest enabling. During system startup, you may expect an error, +# if the dependency is not fulfilled. +# (b) Specifying the init script ordering, not real (hard) dependencies. +# This is needed by insserv to determine which service should be +# started first (and at a later stage what services can be started +# in parallel). The tag Should-Start: is used for this. +# It tells, that if a service is available, it should be started +# before. If not, never mind. +# * When specifying hard dependencies or ordering requirements, you can +# use names of services (contents of their Provides: section) +# or pseudo names starting with a $. The following ones are available +# according to LSB (1.1): +# $local_fs all local file systems are mounted +# (most services should need this!) +# $remote_fs all remote file systems are mounted +# (note that /usr may be remote, so +# many services should Require this!) +# $syslog system logging facility up +# $network low level networking (eth card, ...) +# $named hostname resolution available +# $netdaemons all network daemons are running +# The $netdaemons pseudo service has been removed in LSB 1.2. +# For now, we still offer it for backward compatibility. +# These are new (LSB 1.2): +# $time the system time has been set correctly +# $portmap SunRPC portmapping service available +# UnitedLinux extensions: +# $ALL indicates that a script should be inserted +# at the end +# * The services specified in the stop tags +# (Required-Stop/Should-Stop) +# specify which services need to be still running when this service +# is shut down. Often the entries there are just copies or a subset +# from the respective start tag. +# * Should-Start/Stop are now part of LSB as of 2.0, +# formerly SUSE/Unitedlinux used X-UnitedLinux-Should-Start/-Stop. +# insserv does support both variants. +# * X-UnitedLinux-Default-Enabled: yes/no is used at installation time +# (%fillup_and_insserv macro in %post of many RPMs) to specify whether +# a startup script should default to be enabled after installation. +# It's not used by insserv. +# +# Note on runlevels: +# 0 - halt/poweroff 6 - reboot +# 1 - single user 2 - multiuser without network exported +# 3 - multiuser w/ network (text mode) 5 - multiuser w/ network and X11 (xdm) +# +# Note on script names: +# http://www.linuxbase.org/spec/refspecs/LSB_1.3.0/gLSB/gLSB/scrptnames.html +# A registry has been set up to manage the init script namespace. +# http://www.lanana.org/ +# Please use the names already registered or register one or use a +# vendor prefix. + + +# Check for missing binaries (stale symlinks should not happen) +# Note: Special treatment of stop for LSB conformance +FOO_BIN=/usr/sbin/FOO +test -x $FOO_BIN || { echo "$FOO_BIN not installed"; + if [ "$1" = "stop" ]; then exit 0; + else exit 5; fi; } + +# Check for existence of needed config file and read it +FOO_CONFIG=/etc/sysconfig/FOO +test -r $FOO_CONFIG || { echo "$FOO_CONFIG not existing"; + if [ "$1" = "stop" ]; then exit 0; + else exit 6; fi; } + +# Read config +. $FOO_CONFIG + +# Source LSB init functions +# providing start_daemon, killproc, pidofproc, +# log_success_msg, log_failure_msg and log_warning_msg. +# This is currently not used by UnitedLinux based distributions and +# not needed for init scripts for UnitedLinux only. If it is used, +# the functions from rc.status should not be sourced or used. +#. /lib/lsb/init-functions + +# Shell functions sourced from /etc/rc.status: +# rc_check check and set local and overall rc status +# rc_status check and set local and overall rc status +# rc_status -v be verbose in local rc status and clear it afterwards +# rc_status -v -r ditto and clear both the local and overall rc status +# rc_status -s display "skipped" and exit with status 3 +# rc_status -u display "unused" and exit with status 3 +# rc_failed set local and overall rc status to failed +# rc_failed set local and overall rc status to +# rc_reset clear both the local and overall rc status +# rc_exit exit appropriate to overall rc status +# rc_active checks whether a service is activated by symlinks +. /etc/rc.status + +# Reset status of this service +rc_reset + +# Return values acc. to LSB for all commands but status: +# 0 - success +# 1 - generic or unspecified error +# 2 - invalid or excess argument(s) +# 3 - unimplemented feature (e.g. "reload") +# 4 - user had insufficient privileges +# 5 - program is not installed +# 6 - program is not configured +# 7 - program is not running +# 8--199 - reserved (8--99 LSB, 100--149 distrib, 150--199 appl) +# +# Note that starting an already running service, stopping +# or restarting a not-running service as well as the restart +# with force-reload (in case signaling is not supported) are +# considered a success. + +case "$1" in + start) + echo -n "Starting FOO " + ## Start daemon with startproc(8). If this fails + ## the return value is set appropriately by startproc. + startproc $FOO_BIN + + # Remember status and be verbose + rc_status -v + ;; + stop) + echo -n "Shutting down FOO " + ## Stop daemon with killproc(8) and if this fails + ## killproc sets the return value according to LSB. + + killproc -TERM $FOO_BIN + + # Remember status and be verbose + rc_status -v + ;; + try-restart|condrestart) + ## Do a restart only if the service was active before. + ## Note: try-restart is now part of LSB (as of 1.9). + ## RH has a similar command named condrestart. + if test "$1" = "condrestart"; then + echo "${attn} Use try-restart ${done}(LSB)${attn} rather than condrestart ${warn}(RH)${norm}" + fi + $0 status + if test $? = 0; then + $0 restart + else + rc_reset # Not running is not a failure. + fi + # Remember status and be quiet + rc_status + ;; + restart) + ## Stop the service and regardless of whether it was + ## running or not, start it again. + $0 stop + $0 start + + # Remember status and be quiet + rc_status + ;; + force-reload) + ## Signal the daemon to reload its config. Most daemons + ## do this on signal 1 (SIGHUP). + ## If it does not support it, restart. + + echo -n "Reload service FOO " + ## if it supports it: + killproc -HUP $FOO_BIN + #touch /var/run/FOO.pid + rc_status -v + + ## Otherwise: + #$0 try-restart + #rc_status + ;; + reload) + ## Like force-reload, but if daemon does not support + ## signaling, do nothing (!) + + # If it supports signaling: + echo -n "Reload service FOO " + killproc -HUP $FOO_BIN + #touch /var/run/FOO.pid + rc_status -v + + ## Otherwise if it does not support reload: + #rc_failed 3 + #rc_status -v + ;; + status) + echo -n "Checking for service FOO " + ## Check status with checkproc(8), if process is running + ## checkproc will return with exit status 0. + + # Return value is slightly different for the status command: + # 0 - service up and running + # 1 - service dead, but /var/run/ pid file exists + # 2 - service dead, but /var/lock/ lock file exists + # 3 - service not running (unused) + # 4 - service status unknown :-( + # 5--199 reserved (5--99 LSB, 100--149 distro, 150--199 appl.) + + # NOTE: checkproc returns LSB compliant status values. + checkproc $FOO_BIN + # NOTE: rc_status knows that we called this init script with + # "status" option and adapts its messages accordingly. + rc_status -v + ;; + probe) + ## Optional: Probe for the necessity of a reload, print out the + ## argument to this init script which is required for a reload. + ## Note: probe is not (yet) part of LSB (as of 1.9) + + test /etc/FOO/FOO.conf -nt /var/run/FOO.pid && echo reload + ;; + *) + echo "Usage: $0 {start|stop|status|try-restart|restart|force-reload|reload|probe}" + exit 1 + ;; +esac +rc_exit diff --git a/urunlevel/runlevel/start_daemon.c b/urunlevel/runlevel/start_daemon.c new file mode 100644 index 0000000..ba922fa --- /dev/null +++ b/urunlevel/runlevel/start_daemon.c @@ -0,0 +1,153 @@ +/* + * Mini start_daemon implementation for busybox. + * + * Copyright (C) 2005 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include +#include +#include +#include +#include +#include + +#include "busybox.h" +#include "lib_init_d.h" + + +int start_daemon(int force, int nice_level, char *pidfile, char *pathname, char *args) +{ + int status = 0; + status = pidofproc(pidfile, pathname, NULL); + + if ((status != INIT_D_STATUS_OK) || (force)) + { + char *pids = NULL; + char *strtok_temp; + + doit(DAEMON, "start-stop-daemon -Sbmp %s -x %s -- %s", pidfile, pathname, args); +sleep(1); + status = pidofproc(pidfile, pathname, &pids); + if ((status == INIT_D_STATUS_OK) && (nice_level)) + { + int i; + char *pid; + + pid = strtok_r(pids, " ", &strtok_temp); + for (i = 0; pid != NULL; i++) + { + int ps = atoi(pid); + int oldp; + + errno = 0; + oldp = getpriority(PRIO_PROCESS, ps); + if (errno == 0) + setpriority(PRIO_PROCESS, ps, oldp + nice_level); + pid = strtok_r(NULL, " ", &strtok_temp); + } + } + } + + return status; +} + + +/* +start_daemon [-f] [-n nicelevel] [-p pidfile] pathname [args] + This runs the specified program as a daemon. + start_daemon shall check if the program is already running + using the algorithm given above. If so, it shall not + start another copy of the daemon unless the -f + option is given. The -n option specifies a nice + level. See nice(1). + + start_daemon should return the LSB defined exit status codes. It + shall return 0 if the program has been successfully started or + is running and not 0 otherwise. +*/ + + +int start_daemon_main(int argc, char **argv) +{ + int result = EXIT_FAILURE; + int force = 0; + int nice_level = 0; + char *pidfile = NULL; + char *pathname = NULL; + char *args = NULL; + int i; + + for (i = 1; i < argc; i++) + { + char *p = argv[i]; + + if (*p == '-') + { + while (*(++p)) + { + switch (*p) + { + case 'f' : + force = 1; + break; + + case 'n' : + if ((++i) < argc) + nice_level = atoi(argv[i]); + else + bb_show_usage(); + break; + + case 'p' : + if ((++i) < argc) + pidfile = argv[i]; + else + bb_show_usage(); + break; + + default: + bb_show_usage(); + } + } + } + else if (pathname == NULL) + { + pathname = p; + break; + } + else + bb_show_usage(); + } + + if (pathname == NULL) + bb_show_usage(); + + if (i < argc) + args = argv_cat(argc - i, &argv[i]); + +//bb_printf("ARGS - |%s|%s|%d|%d|%s\n", pidfile, pathname, force, nice_level, args); + result = start_daemon(force, nice_level, pidfile, pathname, args); + + if (args != NULL) + free(args); + + return result; +} + + diff --git a/urunlevel/runlevel/udhcpc_script.c b/urunlevel/runlevel/udhcpc_script.c new file mode 100644 index 0000000..5d5f592 --- /dev/null +++ b/urunlevel/runlevel/udhcpc_script.c @@ -0,0 +1,191 @@ +/* + * Mini udhcpc_script implementation for busybox. + * + * Copyright (C) 2004 by David Seikel won_fang@yahoo.com.au + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA + * 02111-1307 USA + * + */ + +#include +#include +#include + +#include "busybox.h" +#include "lib_init_d.h" + + +static void printit(char *name, char *description, char *value) +{ + if (value != NULL) + bb_printf("%s=%s\t\t- %s\n", name, value, description); +} + +int udhcpc_script_main(int argc, char **argv) +{ + argv += optind; + +#if 0 + printit("action", "What action the script should perform", *argv); + printit("HOME", "The set $HOME env or '/'", getenv("HOME")); + printit("PATH", "the set $PATH env or '/bin:/usr/bin:/sbin:/usr/sbin'", getenv("PATH")); + printit("interface", "The interface this was obtained on", getenv("interface")); + printit("ip", "The obtained IP", getenv("ip")); + printit("mask", "The number of bits in the netmask (ie: 24)", getenv("mask")); + printit("siaddr", "The bootp next server option", getenv("siaddr")); + printit("sname", "The bootp server name option", getenv("sname")); + printit("boot_file", "The bootp boot file option", getenv("boot_file")); + printit("subnet", "The assigend subnet mask", getenv("subnet")); + printit("timezone", "Offset in seconds from UTC", getenv("timezone")); + printit("router", "A list of routers", getenv("router")); + printit("timesvr", "A list of time servers", getenv("timesvr")); + printit("namesvr", "A list of IEN 116 name servers", getenv("namesvr")); + printit("dns", "A list of DNS server", getenv("dns")); + printit("logsvr", "A list of MIT-LCS UDP log servers", getenv("logsvr")); + printit("cookiesvr", "A list of RFC 865 cookie servers", getenv("cookiesvr")); + printit("lprsvr", "A list of LPR servers", getenv("lprsvr")); + printit("hostname", "The assigned hostname", getenv("hostname")); + printit("bootsize", "The length in 512 octect blocks of the bootfile", getenv("bootsize")); + printit("domain", "The domain name of the network", getenv("domain")); + printit("swapsvr", "The IP address of the client's swap server", getenv("swapsvr")); + printit("rootpath", "The path name of the client's root disk", getenv("rootpath")); + printit("ipttl", "The TTL to use for this network", getenv("ipttl")); + printit("mtu", "The MTU to use for this network", getenv("mtu")); + printit("broadcast", "The broadcast address for this network", getenv("broadcast")); + printit("ntpsrv", "A list of NTP servers", getenv("ntpsrv")); + printit("wins", "A list of WINS servers", getenv("wins")); + printit("lease", "The lease time, in seconds", getenv("lease")); + printit("dhcptype", "DHCP message type (safely ignored)", getenv("dhcptype")); + printit("serverid", "The IP of the server", getenv("serverid")); + printit("message", "Reason for a DHCPNAK", getenv("message")); + printit("tftp", "The TFTP server name", getenv("tftp")); + printit("bootfile", "The bootfile name", getenv("bootfile")); +#endif + + if (!*argv) + bb_printf("Error: should be called from udhcpc\n"); + else + { + char *interface = getenv("interface"); + + if (strcmp(*argv, "deconfig") == 0) + { +#ifdef CONFIG_FEATURE_IFUPDOWN_IP + doit(QUIET, "ip route flush dev %s", interface); + doit(QUIET, "ip addr flush dev %s", interface); + doit(QUIET, "ip link set %s up", interface); +#else + errno = 0; + while (errno == 0) + doit(QUIET, "route del default gw 0.0.0.0 dev %s", interface); + doit(QUIET, "ifconfig %s 0.0.0.0", interface); +#endif + } + else if (strcmp(*argv, "nak") == 0) + bb_printf("udhcpc received a NAK: %s\n", getenv("message")); + else if ((strcmp(*argv, "bound") == 0) || (strcmp(*argv, "renew") == 0)) + { + const char *RESOLV_CONF = "/etc/resolv.conf"; + char *broadcast = getenv("broadcast"); + char *subnet = getenv("subnet"); + char *mask = getenv("mask"); + char *ip = getenv("ip"); + char *hostname = getenv("hostname"); + char *domain = getenv("domain"); + char *router = getenv("router"); + char *dns = getenv("dns"); + char *siaddr = getenv("siaddr"); + char *tftp = getenv("tftp"); + char *BROADCAST = ""; + char *NETMASK = ""; + char *MASK = ""; + char *HOSTNAME = 0; + int i, metric = 0; + char *token; + char *strtok_temp; + + if (broadcast != 0) + bb_xasprintf(&BROADCAST, "broadcast %s", broadcast); + if (subnet != 0) + bb_xasprintf(&NETMASK, "netmask %s", subnet); + if (mask != 0) + bb_xasprintf(&MASK, "/%s", mask); + if (hostname != 0) + bb_xasprintf(&HOSTNAME, "/%s", hostname); +#ifdef CONFIG_FEATURE_IFUPDOWN_IP + doit(0, "ip addr add %s%s %s dev %s", ip, MASK, BROADCAST, interface); + doit(0, "ip link set %s up", interface); +#else + doit(0, "/sbin/ifconfig %s %s %s %s", interface, ip, BROADCAST, NETMASK); +#endif + if (router != 0) + { + token = strtok_r(router, " ,\t\r\n", &strtok_temp); + for (i = 0; token != NULL; i++) + { +#ifdef CONFIG_FEATURE_IFUPDOWN_IP + doit(0, "ip route add to default via %s dev %s", token, interface, metric++); +#else + doit(0, "route add default gw %s dev %s metric %d", token, interface, metric++); +#endif + token = strtok_r(NULL, " ,\t\r\n", &strtok_temp); + } + } + + doit(0, "echo -n > %s", RESOLV_CONF); + if (domain != 0) + doit(0, "echo \"search %s\" > %s", domain, RESOLV_CONF); + + token = strtok_r(dns, " \r\n", &strtok_temp); + for (i = 0; token != NULL; i++) + { + doit(0, "echo \"nameserver %s\" >> %s", token, RESOLV_CONF); + + token = strtok_r(NULL, " \r\n", &strtok_temp); + } + + if (HOSTNAME == 0) + { + bb_xasprintf(&HOSTNAME, doit(REDIR, "nslookup %s | grep -v default | grep Name | cut -d\":\" -f2 | tr -d ' ' | tail -n 1", ip)); + if ((HOSTNAME == 0) && (stat("/var/lib/my_linux/config/hostname", &path_stat) == 0)) + HOSTNAME = quick_read("/var/lib/my_linux/config/hostname"); + if (HOSTNAME == 0) + HOSTNAME = "my_linux"; + } + doit(0, "hostname %s", HOSTNAME); +// Should remove old entry + doit(0, "echo \"%s %s\" >> /etc/hosts", ip, HOSTNAME); + +// Should dump these in a per interface file + if (siaddr != NULL) + quick_write("/var/lib/network/nfsaddr", siaddr); + if (tftp != NULL) + quick_write("/var/lib/network/tftpaddr", tftp); + + /* This is what the network init script is waiting for. */ + quick_write("/var/lib/network/ipaddr", ip); + bb_printf("IP %s HOSTNAME %s\n", ip, HOSTNAME); + + free(HOSTNAME); + } + else + { + bb_printf("Huh?\n"); + } + } + + return EXIT_SUCCESS; +} diff --git a/urunlevel/sysdeps/linux/Config.in b/urunlevel/sysdeps/linux/Config.in new file mode 100644 index 0000000..2e364f2 --- /dev/null +++ b/urunlevel/sysdeps/linux/Config.in @@ -0,0 +1,296 @@ +# +# For a description of the syntax of this configuration file, +# see scripts/kbuild/config-language.txt. +# + +mainmenu "BusyBox Configuration" + +config HAVE_DOT_CONFIG + bool + default y + +menu "General Configuration" + +choice + prompt "Buffer allocation policy" + default CONFIG_FEATURE_BUFFERS_USE_MALLOC + help + There are 3 ways BusyBox can handle buffer allocations: + - Use malloc. This costs code size for the call to xmalloc. + - Put them on stack. For some very small machines with limited stack + space, this can be deadly. For most folks, this works just fine. + - Put them in BSS. This works beautifully for computers with a real + MMU (and OS support), but wastes runtime RAM for uCLinux. This + behavior was the only one available for BusyBox versions 0.48 and + earlier. + +config CONFIG_FEATURE_BUFFERS_USE_MALLOC + bool "Allocate with Malloc" + +config CONFIG_FEATURE_BUFFERS_GO_ON_STACK + bool "Allocate on the Stack" + +config CONFIG_FEATURE_BUFFERS_GO_IN_BSS + bool "Allocate in the .bss section" + +endchoice + +config CONFIG_FEATURE_VERBOSE_USAGE + bool "Show verbose applet usage messages" + default n + help + All BusyBox applets will show more verbose help messages when + busybox is invoked with --help. This will add a lot of text to the + busybox binary. In the default configuration, this will add about + 13k, but it can add much more depending on your configuration. + +config CONFIG_FEATURE_INSTALLER + bool "Support --install [-s] to install applet links at runtime" + default n + help + Enable 'busybox --install [-s]' support. This will allow you to use + busybox at runtime to create hard links or symlinks for all the + applets that are compiled into busybox. This feature requires the + /proc filesystem. + +config CONFIG_LOCALE_SUPPORT + bool "Enable locale support (system needs locale for this to work)" + default n + help + Enable this if your system has locale support and you would like + busybox to support locale settings. + +config CONFIG_FEATURE_DEVFS + bool "Support for devfs" + default n + help + Enable if you want BusyBox to work with devfs. + +config CONFIG_FEATURE_DEVPTS + bool "Use the devpts filesystem for Unix98 PTYs" + default y if CONFIG_FEATURE_DEVFS + help + Enable if you want BusyBox to use Unix98 PTY support. If enabled, + busybox will use /dev/ptmx for the master side of the pseudoterminal + and /dev/pts/ for the slave side. Otherwise, BSD style + /dev/ttyp will be used. To use this option, you should have + devpts or devfs mounted. + +config CONFIG_FEATURE_CLEAN_UP + bool "Clean up all memory before exiting (usually not needed)" + default n + help + As a size optimization, busybox by default does not cleanup memory + that is dynamically allocated or close files before exiting. This + saves space and is usually not needed since the OS will clean up for + us. Don't enable this unless you have a really good reason to clean + things up manually. + +config CONFIG_FEATURE_SUID + bool "Support for SUID/SGID handling" + default n + help + Support SUID and SGID binaries. + +config CONFIG_FEATURE_SUID_CONFIG + bool "Runtime SUID/SGID configuration via /etc/busybox.conf" + default y if CONFIG_FEATURE_SUID + depends on CONFIG_FEATURE_SUID + help + Allow the SUID / SGID state of an applet to be determined runtime by + checking /etc/busybox.conf. The format of this file is as follows: + + = [Ssx-][Ssx-][x-] (|).(|) + + An example might help: + + [SUID] + su = ssx root.0 # applet su can be run by anyone and runs with euid=0/egid=0 + su = ssx # exactly the same + + mount = sx- root.disk # applet mount can be run by root and members of group disk + # and runs with euid=0 + + cp = --- # disable applet cp for everyone + + Robert 'sandman' Griebl has more information here: + . + +config CONFIG_FEATURE_SUID_CONFIG_QUIET + bool "Suppress warning message if /etc/busybox.conf is not readable" + default n + depends on CONFIG_FEATURE_SUID_CONFIG + help + /etc/busybox.conf should be readable by the user needing the SUID, check + this option to avoid users to be notified about missing permissions. + +config CONFIG_SELINUX + bool "Support NSA Security Enhanced Linux" + default n + help + Enable support for SE Linux in applets ls, ps, and id. Also provide + the option of compiling in SE Linux applets. + + If you do not have a complete SE Linux Full Userland installed, this + stuff will not compile. Go visit + http://www.nsa.gov/selinux/index.html + to download the necessary stuff to allow busybox to compile with this + option enabled. + + Most people will leave this set to 'N'. + +endmenu + +menu 'Build Options' + +config CONFIG_STATIC + bool "Build BusyBox as a static binary (no shared libs)" + default n + help + If you want to build a static BusyBox binary, which does not + use or require any shared libraries, then enable this option. + This can cause BusyBox to be considerably larger, so you should + leave this option false unless you have a good reason (i.e. + your target platform does not support shared libraries, or + you are building an initrd which doesn't need anything but + BusyBox, etc). + + Most people will leave this set to 'N'. + +config CONFIG_LFS + bool "Build with Large File Support (for accessing files > 2 GB)" + default n + select FDISK_SUPPORT_LARGE_DISKS + help + If you want to build BusyBox with large file support, then enable + this option. This will have no effect if your kernel or your C + library lacks large file support for large files. Some of the + programs that can benefit from large file support include dd, gzip, + cp, mount, tar, and many others. If you want to access files larger + than 2 Gigabytes, enable this option. Otherwise, leave it set to 'N'. + +config USING_CROSS_COMPILER + bool "Do you want to build BusyBox with a Cross Compiler?" + default n + help + Do you want to build BusyBox with a Cross Compiler? If so, + then enable this option. Otherwise leave it set to 'N'. + +config CROSS_COMPILER_PREFIX + string "Cross Compiler prefix" + default "/usr/i386-linux-uclibc/bin/i386-uclibc-" + depends on USING_CROSS_COMPILER + help + If you want to build BusyBox with a cross compiler, then you + will need to set this to the cross-compiler prefix. For example, + if my cross-compiler is /usr/i386-linux-uclibc/bin/i386-uclibc-gcc + then I would enter '/usr/i386-linux-uclibc/bin/i386-uclibc-' here, + which will ensure the correct compiler is used. + +config EXTRA_CFLAGS_OPTIONS + string "Any extra CFLAGS options for the compiler?" + default "" + help + Do you want to pass any extra CFLAGS options to the compiler as + you build BusyBox? If so, this is the option for you... For example, + if you want to add some simple compiler switches (like -march=i686), + or check for warnings using -Werror, just those options here. + +endmenu + +menu 'Installation Options' + +config CONFIG_INSTALL_NO_USR + bool "Don't use /usr" + default n + help + Disable use of /usr. Don't activate this option if you don't know + that you really want this behaviour. + +config PREFIX + string "BusyBox installation prefix" + default "./_install" + help + Define your directory to install BusyBox files/subdirs in. + + + +endmenu + +source archival/Config.in +source coreutils/Config.in +source console-tools/Config.in +source debianutils/Config.in +source editors/Config.in +source findutils/Config.in +source my_linux/Config.in +source runlevel/Config.in +source init/Config.in +source loginutils/Config.in +source miscutils/Config.in +source modutils/Config.in +source networking/Config.in +source procps/Config.in +source shell/Config.in +source sysklogd/Config.in +source util-linux/Config.in + +menu 'Debugging Options' + +config CONFIG_DEBUG + bool "Build BusyBox with Debugging symbols" + default n + help + Say Y here if you wish to compile BusyBox with debugging symbols. + This will allow you to use a debugger to examine BusyBox internals + while applets are running. This increases the size of the binary + considerably and should only be used when doing development. + If you are doing development and want to debug BusyBox, answer Y. + + Most people should answer N. + +choice + prompt "Additional debugging library" + default CONFIG_NO_DEBUG_LIB + depends on CONFIG_DEBUG + help + Using an additional debugging library will make BusyBox become + considerable larger and will cause it to run more slowly. You + should always leave this option disabled for production use. + + dmalloc support: + ---------------- + This enables compiling with dmalloc ( http://dmalloc.com/ ) + which is an excellent public domain mem leak and malloc problem + detector. To enable dmalloc, before running busybox you will + want to properly set your environment, for example: + export DMALLOC_OPTIONS=debug=0x34f47d83,inter=100,log=logfile + The 'debug=' value is generated using the following command + dmalloc -p log-stats -p log-non-free -p log-bad-space -p log-elapsed-time \ + -p check-fence -p check-heap -p check-lists -p check-blank \ + -p check-funcs -p realloc-copy -p allow-free-null + + Electric-fence support: + ----------------------- + This enables compiling with Electric-fence support. Electric + fence is another very useful malloc debugging library which uses + your computer's virtual memory hardware to detect illegal memory + accesses. This support will make BusyBox be considerable larger + and run slower, so you should leave this option disabled unless + you are hunting a hard to find memory problem. + + +config CONFIG_NO_DEBUG_LIB + bool "None" + +config CONFIG_DMALLOC + bool "Dmalloc" + +config CONFIG_EFENCE + bool "Electric-fence" + +endchoice + + +endmenu + -- cgit v1.1