Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59248bad97 | ||
|
|
84b009256f | ||
|
|
b52a218c95 | ||
|
|
59017e80da | ||
|
|
cf53687376 | ||
|
|
2cb55077e2 | ||
|
|
c5ff0165ad | ||
|
|
3157b1fba9 | ||
|
|
a3e0d7928b | ||
|
|
9835541c54 | ||
|
|
21818c8a80 | ||
|
|
70e2f0b111 | ||
|
|
14c82b64c9 | ||
|
|
2ad2afd05c | ||
|
|
059f152a7a | ||
|
|
29fcc90f3e | ||
|
|
6805d5d69e | ||
|
|
f95ca97d1b | ||
|
|
395b216a2e | ||
|
|
7a98606d85 | ||
|
|
0f5e1ab949 | ||
|
|
f0758dd6ba | ||
|
|
1792f8c489 | ||
|
|
c24db7b591 | ||
|
|
8cd6a1f9a2 | ||
|
|
48091fb3d3 | ||
|
|
abc0f4f8f9 | ||
|
|
2285f367e2 | ||
|
|
fcdb57a0fc | ||
|
|
d29edf34d6 | ||
|
|
485b9550fd | ||
|
|
d00c262847 | ||
|
|
0ecb54a0f3 | ||
|
|
14ec6cf3c2 | ||
|
|
de1d61268e | ||
|
|
b186d980d6 | ||
|
|
77619b9dda | ||
|
|
bb58702833 | ||
|
|
03018f7551 | ||
|
|
1667fb4b63 | ||
|
|
c054b21f7d | ||
|
|
4c78147755 | ||
|
|
ec33d45e89 | ||
|
|
befda6e4ed | ||
|
|
3843e96252 | ||
|
|
b99df0fd65 | ||
|
|
394f764e7d | ||
|
|
cb41c2e83b | ||
|
|
5d44d1fda5 | ||
|
|
0f4c0848c7 | ||
|
|
0727458a97 | ||
|
|
fa213cd71e | ||
|
|
e1850ddde4 | ||
|
|
6a76e652aa | ||
|
|
08b1034f4f | ||
|
|
ab746abfc0 | ||
|
|
1c43d0c5af | ||
|
|
b052b47722 | ||
|
|
ded6259f62 | ||
|
|
d80e851dc0 | ||
|
|
a9c95ea655 | ||
|
|
80974fad03 | ||
|
|
b6a44b8d39 | ||
|
|
eded54bd96 | ||
|
|
96bcfd346b | ||
|
|
0dfac6b9ce | ||
|
|
c296b54827 | ||
|
|
d73dc5b073 | ||
|
|
84d8568071 | ||
|
|
5556c1874b | ||
|
|
3e2bb288da | ||
|
|
add0158554 | ||
|
|
3d8dbe1ca0 | ||
|
|
50d6360771 | ||
|
|
fbb39c83b6 | ||
|
|
07e5297ca7 | ||
|
|
dc6301e7ca |
No files matched your search
@@ -1,3 +1,138 @@
|
||||
0.39
|
||||
* New Apps: ping and hostname contributed by Randolph Chung
|
||||
<tausq@debian.org>. 2 items off the TODO list!
|
||||
* I wrote free (just calls "cat /proc/meminfo").
|
||||
* Added tail, based on tail from GNU textutils-1.19, but adjusted
|
||||
to suit my evil purposes. Costs 6k. I'll make it smaller sometime.
|
||||
* on reboot, init called 'umount -a -n', which caused errors
|
||||
when BB_MTAB was not enabled. Changed to 'umount -a',
|
||||
which does the right thing.
|
||||
* init will now try to run /sbin/getty if it is present (for easy
|
||||
integration with the about-to-be-released tinylogin.)
|
||||
* kill now behaves itself properly, added 'kill -l' to list signals
|
||||
* 'ls -l' was failing on long directories, since my_getid was leaking
|
||||
one file descriptor per file. Oops.
|
||||
* Fixed rebooting from init. I'd accidently left some debugging code in
|
||||
which blocked reboots.
|
||||
* Fixed reboot, halt (and added poweroff) such that they handle it when
|
||||
init is not at PID 1 (like when running in an initrd).
|
||||
* Added a prelinary du implementation. Some parameter parsing
|
||||
stuff still needs to be added. -beppu (John Beppu <beppu@lineo.com>)
|
||||
* Implemented tee. -beppu
|
||||
* Implemented head. -beppu
|
||||
|
||||
-Erik Andrsen, Dec 10, 1999
|
||||
|
||||
0.38
|
||||
* Fixed a segfault in 'umount -a' when a badly formed /etc/fstab
|
||||
file existed.
|
||||
* df will not exit on error, but will stat all mounted filesystems.
|
||||
* Fixed tar so uid/gid/permissions on extracted tarballs will be correct.
|
||||
* Fixed find -name so it properly uses shell wildcard patterns
|
||||
(i.e. `*', `?', and `[]') instead of regular expressions, which
|
||||
was causing some confusing and unexpected behavior.
|
||||
* Added klogd to syslogd, so now the log will contain both system and
|
||||
kernel messages.
|
||||
* syslogd now creates the /dev/log socket to make sure it is there, and
|
||||
is actually a socket with the right permissions.
|
||||
* I've taken a first step to making busybox not need the /proc
|
||||
filesystem. Most apps don't need it. Those that _require_ it,
|
||||
will complain if you enable them when you disable
|
||||
BB_FEATURE_USE_PROCFS.
|
||||
|
||||
-Erik Andrsen, Dec 5, 1999
|
||||
|
||||
0.37
|
||||
* Wrote a micro syslogd, and a logger util (to log things to the syslog
|
||||
from the command line or scripts) With both compiled in, costs 4k.
|
||||
* Fixed 'make install' so symlinks are installed in their proper locations.
|
||||
* Changed the build system slightly so that features can now be enabled
|
||||
or disabled from the busybox.defs.h header file, without trying to
|
||||
compile in a source file named after that featue (unless that file exists).
|
||||
* Several options are now moved into busybox.defs.h
|
||||
* Now 'rm -R' and 'rm -r' both work.
|
||||
* dd now properly handles input beyond 1 block from stdin.
|
||||
* Fixed a bug where tar unpacked everything a directories. Moved some code
|
||||
from createPath into mkdir where it belonged, thereby making tar work properly.
|
||||
* Fixed an off-by-one bug in cat. Given a list of file it wouldn't cat out the
|
||||
last file in the list.
|
||||
* Fixed 'ls -ln' so numeric group/uid are presented properly, and fixed 'ls -l'
|
||||
so when uid/gid is not in /etc/{passwd,group} the numeric group/uid are
|
||||
presented properly.
|
||||
* Also added a TODO.
|
||||
|
||||
|
||||
-Erik Andrsen, Nov 25, 1999
|
||||
|
||||
0.36
|
||||
* fixed dd so it properly defaults to stdin and stdout when no
|
||||
if= and of= are set (fix thanks to Eric Delaunay).
|
||||
* Don't try to close the file descriptor of a pipein tar. (fix also from
|
||||
Eric Delaunay).
|
||||
* Made createPath be quiet (again thanks to Eric Delaunay).
|
||||
* If BB_CONSOLE_CMD_IF_RC_SCRIPT_EXITS is defined, then whatever
|
||||
command you define it as will be run if the init script exits.
|
||||
* Updated install.sh to make it more robust (thanks to Adam Di Carlo)
|
||||
* NFS support added to mount by Eric Delaunay. It costs 10k when compiled
|
||||
in, but that is still a big win for those that use NFS.
|
||||
* Made 'rm -f' be silent for non-existant files (thanks to Eric Delaunay).
|
||||
* changed zcat.c to gunzip.c. It now obeys the principle of least surprise
|
||||
and acts as god intended gunzip and zcat to act. They answer --help and
|
||||
obey the '-c' flag.
|
||||
* Fixed a bug in mv which caused it to not move files when the destination
|
||||
was a directory.
|
||||
* Fixed a decimal-instead-of-octal bug causing mkdir to make directories
|
||||
with very wrong permissions.
|
||||
* chmod would overwrite file permissions instead of modifying them.
|
||||
Now it properly modifies permissions.
|
||||
* Init now sends warnings destined for the console to /dev/console to ensure
|
||||
they show up on whatever the active console it. Otherwise important
|
||||
messages (for example that the system is rebooting) were not seen when
|
||||
switched to a different VT.
|
||||
|
||||
-Erik Andersen, Nov 17, 1999
|
||||
|
||||
0.35
|
||||
* gzip now obeys the principle of least surprise and acts like god intended
|
||||
(i.e. it accepts a file name, answers --help, and obeys the '-c' flag
|
||||
and only then outputs to stdout).
|
||||
* Fixed more.c to compile autowidth on sparc and set initial winsize
|
||||
to 0,0 in case the TIOCGWINSZ ioctl fails. Fix thanks to Eric Delaunay.
|
||||
* Fixed tar so it now works as expected (it had TRUE/FALSE backwards)
|
||||
* tar now accepts --help
|
||||
* chmod, chown, and chgrp usage now works
|
||||
* General usage (i.e. --help) cleanups for most apps
|
||||
* umount now parses options correctly
|
||||
* tar can now unpack tarballs containing device special files,
|
||||
sockets, and fifos (though it can't pack them up) thanks
|
||||
to Matt Porter. Creating archives containing these is still
|
||||
left to the interested student.
|
||||
* fixed up the license in more.c to properly point to Bruce Perens.
|
||||
|
||||
-Erik Andersen, Nov 11, 1999
|
||||
|
||||
0.34
|
||||
* ls -l now displays link names outside the current directory,
|
||||
Patch thanks to Eric Delaunay
|
||||
* init now properly handles sparc serial consoles and does a
|
||||
better job of finding the real console device rather than using
|
||||
/dev/console which doesn't support job control. Patch also
|
||||
thanks to Eric Delaunay.
|
||||
* more started to read from stdin after the last file was finished, and
|
||||
options were not parsed correctly (fix thanks to Eric Delaunay).
|
||||
* more will now use the terminal size if BB_FEATURE_AUTOWIDTH is on.
|
||||
* rm wouldn't remove a symlink unless the symlink was valid. This was
|
||||
a side effect of the busybox 0.32 recursiveAction() fix. Things
|
||||
should now work correctly.
|
||||
* grep wouldn't grep stdin. Now it does.
|
||||
* sed wouldn't sed stdin. Now it does.
|
||||
* sed was appending a \n to the end of lines with replacements.
|
||||
Now it doesn't do that.
|
||||
* ls -l now bypasses libc6 nss when displaying user/group names.
|
||||
Now uses my_getpwuid and my_getgrgid.
|
||||
|
||||
-Erik Andersen, Nov 8, 1999
|
||||
|
||||
0.33
|
||||
* Fixed a bug where init could hang instead of rebooting.
|
||||
* Removed some debugging noise from init.c
|
||||
@@ -8,6 +143,8 @@
|
||||
state the real root device name)
|
||||
* merged some redundant code from mtab.c/df.c into utility.c
|
||||
|
||||
-Erik Andersen, Nov 5, 1999
|
||||
|
||||
0.32
|
||||
* More changes -- many thanks to Lineo for paying me to work on
|
||||
busybox. If you have any problems please let me know ASAP
|
||||
@@ -35,7 +172,7 @@
|
||||
as the name suggests. Fix thanks to Matt Porter <porter@debian.org>.
|
||||
|
||||
|
||||
-Erik Andersen
|
||||
-Erik Andersen, Nov 4, 1999
|
||||
|
||||
0.31
|
||||
* I added a changelog for version 0.30.
|
||||
@@ -50,7 +187,7 @@
|
||||
it wasn't supported before GNU libc 2.1, and some folks use
|
||||
glibc 2.0.7 since it is much smaller than that latest and greatest.
|
||||
|
||||
-Erik Andersen
|
||||
-Erik Andersen, Oct 21, 1999
|
||||
|
||||
0.30
|
||||
Major changes -- lots of stuff rewritten. Many thanks to Lineo for
|
||||
@@ -119,7 +256,11 @@
|
||||
* sfdisk -- Added from util-linux (minus internationalization and such).
|
||||
* Probably some other changes that I forgot to document...
|
||||
|
||||
-Erik Andersen
|
||||
-Erik Andersen, Oct 20, 1999
|
||||
|
||||
0.29
|
||||
This version was a messy pre-alpha. stay away or it will bite you.
|
||||
-Erik Andersen, Sep 24, 1999
|
||||
|
||||
0.28
|
||||
mini-netcat (mnc) rewritten.
|
||||
|
||||
@@ -17,15 +17,362 @@ Copyright 1998 Dave Cinege <dcinege@psychosis.com>
|
||||
mini-gzip(gzip), mini-netcat(mnc)
|
||||
Copyright 1998 Charles P. Wright <cpwright@villagenet.com>
|
||||
|
||||
|
||||
bunches of stuff as noted in header files
|
||||
Tons of new stuff as noted in header files
|
||||
Copyright (C) 1999 by Lineo, inc. and written by
|
||||
Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
|
||||
copyright and license info.
|
||||
|
||||
This program suite may be distributed under the GNU General Public License.
|
||||
|
||||
|
||||
Please send patches, suggestions, insults, and bribes to <andersee@debian.org>.
|
||||
Please feed suggestions, bug reports, insults, and bribes back to:
|
||||
Erik Andersen
|
||||
<andersen@lineo.com>
|
||||
<andersee@deban.org>
|
||||
|
||||
|
||||
|
||||
Busybox may be used and distributed under the GNU General Public License.
|
||||
|
||||
---------------------------------------------------------------------------
|
||||
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 2, June 1991
|
||||
|
||||
Copyright (C) 1989, 1991 Free Software Foundation, Inc.
|
||||
59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The licenses for most software are designed to take away your
|
||||
freedom to share and change it. By contrast, the GNU General Public
|
||||
License is intended to guarantee your freedom to share and change free
|
||||
software--to make sure the software is free for all its users. This
|
||||
General Public License applies to most of the Free Software
|
||||
Foundation's software and to any other program whose authors commit to
|
||||
using it. (Some other Free Software Foundation software is covered by
|
||||
the GNU Library General Public License instead.) You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
this service if you wish), that you receive source code or can get it
|
||||
if you want it, that you can change the software or use pieces of it
|
||||
in new free programs; and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to make restrictions that forbid
|
||||
anyone to deny you these rights or to ask you to surrender the rights.
|
||||
These restrictions translate to certain responsibilities for you if you
|
||||
distribute copies of the software, or if you modify it.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must give the recipients all the rights that
|
||||
you have. You must make sure that they, too, receive or can get the
|
||||
source code. And you must show them these terms so they know their
|
||||
rights.
|
||||
|
||||
We protect your rights with two steps: (1) copyright the software, and
|
||||
(2) offer you this license which gives you legal permission to copy,
|
||||
distribute and/or modify the software.
|
||||
|
||||
Also, for each author's protection and ours, we want to make certain
|
||||
that everyone understands that there is no warranty for this free
|
||||
software. If the software is modified by someone else and passed on, we
|
||||
want its recipients to know that what they have is not the original, so
|
||||
that any problems introduced by others will not reflect on the original
|
||||
authors' reputations.
|
||||
|
||||
Finally, any free program is threatened constantly by software
|
||||
patents. We wish to avoid the danger that redistributors of a free
|
||||
program will individually obtain patent licenses, in effect making the
|
||||
program proprietary. To prevent this, we have made it clear that any
|
||||
patent must be licensed for everyone's free use or not licensed at all.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
|
||||
|
||||
0. This License applies to any program or other work which contains
|
||||
a notice placed by the copyright holder saying it may be distributed
|
||||
under the terms of this General Public License. The "Program", below,
|
||||
refers to any such program or work, and a "work based on the Program"
|
||||
means either the Program or any derivative work under copyright law:
|
||||
that is to say, a work containing the Program or a portion of it,
|
||||
either verbatim or with modifications and/or translated into another
|
||||
language. (Hereinafter, translation is included without limitation in
|
||||
the term "modification".) Each licensee is addressed as "you".
|
||||
|
||||
Activities other than copying, distribution and modification are not
|
||||
covered by this License; they are outside its scope. The act of
|
||||
running the Program is not restricted, and the output from the Program
|
||||
is covered only if its contents constitute a work based on the
|
||||
Program (independent of having been made by running the Program).
|
||||
Whether that is true depends on what the Program does.
|
||||
|
||||
1. You may copy and distribute verbatim copies of the Program's
|
||||
source code as you receive it, in any medium, provided that you
|
||||
conspicuously and appropriately publish on each copy an appropriate
|
||||
copyright notice and disclaimer of warranty; keep intact all the
|
||||
notices that refer to this License and to the absence of any warranty;
|
||||
and give any other recipients of the Program a copy of this License
|
||||
along with the Program.
|
||||
|
||||
You may charge a fee for the physical act of transferring a copy, and
|
||||
you may at your option offer warranty protection in exchange for a fee.
|
||||
|
||||
2. You may modify your copy or copies of the Program or any portion
|
||||
of it, thus forming a work based on the Program, and copy and
|
||||
distribute such modifications or work under the terms of Section 1
|
||||
above, provided that you also meet all of these conditions:
|
||||
|
||||
a) You must cause the modified files to carry prominent notices
|
||||
stating that you changed the files and the date of any change.
|
||||
|
||||
b) You must cause any work that you distribute or publish, that in
|
||||
whole or in part contains or is derived from the Program or any
|
||||
part thereof, to be licensed as a whole at no charge to all third
|
||||
parties under the terms of this License.
|
||||
|
||||
c) If the modified program normally reads commands interactively
|
||||
when run, you must cause it, when started running for such
|
||||
interactive use in the most ordinary way, to print or display an
|
||||
announcement including an appropriate copyright notice and a
|
||||
notice that there is no warranty (or else, saying that you provide
|
||||
a warranty) and that users may redistribute the program under
|
||||
these conditions, and telling the user how to view a copy of this
|
||||
License. (Exception: if the Program itself is interactive but
|
||||
does not normally print such an announcement, your work based on
|
||||
the Program is not required to print an announcement.)
|
||||
|
||||
These requirements apply to the modified work as a whole. If
|
||||
identifiable sections of that work are not derived from the Program,
|
||||
and can be reasonably considered independent and separate works in
|
||||
themselves, then this License, and its terms, do not apply to those
|
||||
sections when you distribute them as separate works. But when you
|
||||
distribute the same sections as part of a whole which is a work based
|
||||
on the Program, the distribution of the whole must be on the terms of
|
||||
this License, whose permissions for other licensees extend to the
|
||||
entire whole, and thus to each and every part regardless of who wrote it.
|
||||
|
||||
Thus, it is not the intent of this section to claim rights or contest
|
||||
your rights to work written entirely by you; rather, the intent is to
|
||||
exercise the right to control the distribution of derivative or
|
||||
collective works based on the Program.
|
||||
|
||||
In addition, mere aggregation of another work not based on the Program
|
||||
with the Program (or with a work based on the Program) on a volume of
|
||||
a storage or distribution medium does not bring the other work under
|
||||
the scope of this License.
|
||||
|
||||
3. You may copy and distribute the Program (or a work based on it,
|
||||
under Section 2) in object code or executable form under the terms of
|
||||
Sections 1 and 2 above provided that you also do one of the following:
|
||||
|
||||
a) Accompany it with the complete corresponding machine-readable
|
||||
source code, which must be distributed under the terms of Sections
|
||||
1 and 2 above on a medium customarily used for software interchange; or,
|
||||
|
||||
b) Accompany it with a written offer, valid for at least three
|
||||
years, to give any third party, for a charge no more than your
|
||||
cost of physically performing source distribution, a complete
|
||||
machine-readable copy of the corresponding source code, to be
|
||||
distributed under the terms of Sections 1 and 2 above on a medium
|
||||
customarily used for software interchange; or,
|
||||
|
||||
c) Accompany it with the information you received as to the offer
|
||||
to distribute corresponding source code. (This alternative is
|
||||
allowed only for noncommercial distribution and only if you
|
||||
received the program in object code or executable form with such
|
||||
an offer, in accord with Subsection b above.)
|
||||
|
||||
The source code for a work means the preferred form of the work for
|
||||
making modifications to it. For an executable work, complete source
|
||||
code means all the source code for all modules it contains, plus any
|
||||
associated interface definition files, plus the scripts used to
|
||||
control compilation and installation of the executable. However, as a
|
||||
special exception, the source code distributed need not include
|
||||
anything that is normally distributed (in either source or binary
|
||||
form) with the major components (compiler, kernel, and so on) of the
|
||||
operating system on which the executable runs, unless that component
|
||||
itself accompanies the executable.
|
||||
|
||||
If distribution of executable or object code is made by offering
|
||||
access to copy from a designated place, then offering equivalent
|
||||
access to copy the source code from the same place counts as
|
||||
distribution of the source code, even though third parties are not
|
||||
compelled to copy the source along with the object code.
|
||||
|
||||
4. You may not copy, modify, sublicense, or distribute the Program
|
||||
except as expressly provided under this License. Any attempt
|
||||
otherwise to copy, modify, sublicense or distribute the Program is
|
||||
void, and will automatically terminate your rights under this License.
|
||||
However, parties who have received copies, or rights, from you under
|
||||
this License will not have their licenses terminated so long as such
|
||||
parties remain in full compliance.
|
||||
|
||||
5. You are not required to accept this License, since you have not
|
||||
signed it. However, nothing else grants you permission to modify or
|
||||
distribute the Program or its derivative works. These actions are
|
||||
prohibited by law if you do not accept this License. Therefore, by
|
||||
modifying or distributing the Program (or any work based on the
|
||||
Program), you indicate your acceptance of this License to do so, and
|
||||
all its terms and conditions for copying, distributing or modifying
|
||||
the Program or works based on it.
|
||||
|
||||
6. Each time you redistribute the Program (or any work based on the
|
||||
Program), the recipient automatically receives a license from the
|
||||
original licensor to copy, distribute or modify the Program subject to
|
||||
these terms and conditions. You may not impose any further
|
||||
restrictions on the recipients' exercise of the rights granted herein.
|
||||
You are not responsible for enforcing compliance by third parties to
|
||||
this License.
|
||||
|
||||
7. If, as a consequence of a court judgment or allegation of patent
|
||||
infringement or for any other reason (not limited to patent issues),
|
||||
conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot
|
||||
distribute so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you
|
||||
may not distribute the Program at all. For example, if a patent
|
||||
license would not permit royalty-free redistribution of the Program by
|
||||
all those who receive copies directly or indirectly through you, then
|
||||
the only way you could satisfy both it and this License would be to
|
||||
refrain entirely from distribution of the Program.
|
||||
|
||||
If any portion of this section is held invalid or unenforceable under
|
||||
any particular circumstance, the balance of the section is intended to
|
||||
apply and the section as a whole is intended to apply in other
|
||||
circumstances.
|
||||
|
||||
It is not the purpose of this section to induce you to infringe any
|
||||
patents or other property right claims or to contest validity of any
|
||||
such claims; this section has the sole purpose of protecting the
|
||||
integrity of the free software distribution system, which is
|
||||
implemented by public license practices. Many people have made
|
||||
generous contributions to the wide range of software distributed
|
||||
through that system in reliance on consistent application of that
|
||||
system; it is up to the author/donor to decide if he or she is willing
|
||||
to distribute software through any other system and a licensee cannot
|
||||
impose that choice.
|
||||
|
||||
This section is intended to make thoroughly clear what is believed to
|
||||
be a consequence of the rest of this License.
|
||||
|
||||
8. If the distribution and/or use of the Program is restricted in
|
||||
certain countries either by patents or by copyrighted interfaces, the
|
||||
original copyright holder who places the Program under this License
|
||||
may add an explicit geographical distribution limitation excluding
|
||||
those countries, so that distribution is permitted only in or among
|
||||
countries not thus excluded. In such case, this License incorporates
|
||||
the limitation as if written in the body of this License.
|
||||
|
||||
9. The Free Software Foundation may publish revised and/or new versions
|
||||
of the General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the Program
|
||||
specifies a version number of this License which applies to it and "any
|
||||
later version", you have the option of following the terms and conditions
|
||||
either of that version or of any later version published by the Free
|
||||
Software Foundation. If the Program does not specify a version number of
|
||||
this License, you may choose any version ever published by the Free Software
|
||||
Foundation.
|
||||
|
||||
10. If you wish to incorporate parts of the Program into other free
|
||||
programs whose distribution conditions are different, write to the author
|
||||
to ask for permission. For software which is copyrighted by the Free
|
||||
Software Foundation, write to the Free Software Foundation; we sometimes
|
||||
make exceptions for this. Our decision will be guided by the two goals
|
||||
of preserving the free status of all derivatives of our free software and
|
||||
of promoting the sharing and reuse of software generally.
|
||||
|
||||
NO WARRANTY
|
||||
|
||||
11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
|
||||
FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
|
||||
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
|
||||
PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
|
||||
OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
|
||||
TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
|
||||
PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
|
||||
REPAIR OR CORRECTION.
|
||||
|
||||
12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
|
||||
REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
|
||||
INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
|
||||
OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
|
||||
TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
|
||||
YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
|
||||
PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
|
||||
POSSIBILITY OF SUCH DAMAGES.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
convey the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
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
|
||||
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program is interactive, make it output a short notice like this
|
||||
when it starts in an interactive mode:
|
||||
|
||||
Gnomovision version 69, Copyright (C) year name of author
|
||||
Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, the commands you use may
|
||||
be called something other than `show w' and `show c'; they could even be
|
||||
mouse-clicks or menu items--whatever suits your program.
|
||||
|
||||
You should also get your employer (if you work as a programmer) or your
|
||||
school, if any, to sign a "copyright disclaimer" for the program, if
|
||||
necessary. Here is a sample; alter the names:
|
||||
|
||||
Yoyodyne, Inc., hereby disclaims all copyright interest in the program
|
||||
`Gnomovision' (which makes passes at compilers) written by James Hacker.
|
||||
|
||||
<signature of Ty Coon>, 1 April 1989
|
||||
Ty Coon, President of Vice
|
||||
|
||||
This General Public License does not permit incorporating your program into
|
||||
proprietary programs. If your program is a subroutine library, you may
|
||||
consider it more useful to permit linking proprietary applications with the
|
||||
library. If this is what you want to do, use the GNU Library General
|
||||
Public License instead of this License.
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
|
||||
|
||||
PROG=busybox
|
||||
VERSION=0.33
|
||||
VERSION=0.39
|
||||
BUILDTIME=$(shell date "+%Y%m%d-%H%M")
|
||||
|
||||
# Comment out the following to make a debuggable build
|
||||
@@ -31,14 +31,38 @@ DOSTATIC=false
|
||||
#This will choke on a non-debian system
|
||||
ARCH=`uname -m | sed -e 's/i.86/i386/' | sed -e 's/sparc.*/sparc/'`
|
||||
|
||||
GCCMAJVERSION=`$(CC) --version | sed -n "s/^\([0-9]\)\.\([0-9].*\)[\.].*/\1/p"`
|
||||
GCCMINVERSION=`$(CC) --version | sed -n "s/^\([0-9]\)\.\([0-9].*\)[\.].*/\2/p"`
|
||||
|
||||
GCCSUPPORTSOPTSIZE=$(shell \
|
||||
if ( test $(GCCMAJVERSION) -eq 2 ) ; then \
|
||||
if ( test $(GCCMINVERSION) -ge 91 ) ; then \
|
||||
echo "true"; \
|
||||
else \
|
||||
echo "false"; \
|
||||
fi; \
|
||||
else \
|
||||
if ( test $(GCCMAJVERSION) -gt 2 ) ; then \
|
||||
echo "true"; \
|
||||
else \
|
||||
echo "false"; \
|
||||
fi; \
|
||||
fi; )
|
||||
|
||||
|
||||
ifeq ($(GCCSUPPORTSOPTSIZE), true)
|
||||
OPTIMIZATION=-Os
|
||||
else
|
||||
OPTIMIZATION=-O2
|
||||
endif
|
||||
|
||||
# -D_GNU_SOURCE is needed because environ is used in init.c
|
||||
ifeq ($(DODEBUG),true)
|
||||
CFLAGS=-Wall -g -D_GNU_SOURCE -DDEBUG_INIT
|
||||
CFLAGS+=-Wall -g -D_GNU_SOURCE -DDEBUG_INIT
|
||||
STRIP=
|
||||
LDFLAGS=
|
||||
else
|
||||
CFLAGS=-Wall -Os -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
|
||||
CFLAGS+=-Wall $(OPTIMIZATION) -fomit-frame-pointer -fno-builtin -D_GNU_SOURCE
|
||||
LDFLAGS= -s
|
||||
STRIP= strip --remove-section=.note --remove-section=.comment $(PROG)
|
||||
#Only staticly link when _not_ debugging
|
||||
@@ -48,35 +72,42 @@ else
|
||||
|
||||
endif
|
||||
|
||||
ifndef $(prefix)
|
||||
prefix=`pwd`
|
||||
ifndef $(PREFIX)
|
||||
PREFIX=`pwd`/_install
|
||||
endif
|
||||
BINDIR=$(prefix)
|
||||
|
||||
LIBRARIES=
|
||||
OBJECTS=$(shell ./busybox.sh)
|
||||
CFLAGS+= -DBB_VER='"$(VERSION)"'
|
||||
CFLAGS+= -DBB_BT='"$(BUILDTIME)"'
|
||||
ifdef BB_INIT_RC_EXIT_CMD
|
||||
CFLAGS += -DBB_INIT_CMD_IF_RC_SCRIPT_EXITS=${BB_INIT_RC_EXIT_CMD}
|
||||
endif
|
||||
|
||||
all: busybox links
|
||||
all: busybox busybox.links
|
||||
|
||||
busybox: $(OBJECTS)
|
||||
$(CC) $(LDFLAGS) -o $(PROG) $(OBJECTS) $(LIBRARIES)
|
||||
$(STRIP)
|
||||
|
||||
links:
|
||||
- ./busybox.mkll | sort >busybox.links
|
||||
|
||||
busybox.links:
|
||||
- ./busybox.mkll | sort >$@
|
||||
|
||||
clean:
|
||||
- rm -f $(PROG) busybox.links *~ *.o core
|
||||
- rm -rf _install
|
||||
|
||||
distclean: clean
|
||||
- rm -f $(PROG)
|
||||
|
||||
force:
|
||||
|
||||
$(OBJECTS): busybox.def.h internal.h Makefile
|
||||
|
||||
install: $(PROG)
|
||||
install.sh $(BINDIR)
|
||||
install: busybox busybox.links
|
||||
./install.sh $(PREFIX)
|
||||
|
||||
dist: release
|
||||
|
||||
release: distclean
|
||||
(cd .. ; rm -rf busybox-$(VERSION) ; cp -a busybox busybox-$(VERSION); rm -rf busybox-$(VERSION)/CVS busybox-$(VERSION)/.cvsignore ; tar -cvzf busybox-$(VERSION).tar.gz busybox-$(VERSION))
|
||||
|
||||
|
||||
@@ -1,26 +1,30 @@
|
||||
Please see the LICENSE file for copyright information.
|
||||
|
||||
Busybox is a multicall binary used to provide a minimal subset of
|
||||
POSIX style commands and specialized functions.
|
||||
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
|
||||
provides a pretty complete POSIX environment in a very small package.
|
||||
Just add a kernel, "ash" (Keith Almquists tiny Bourne shell clone), and
|
||||
an editor such as "elvis-tiny" or "ae", and you have a working system.
|
||||
Busybox was begun to support the Debian Rescue/Install disks, but it
|
||||
also makes an excellent environment for any small or embedded system.
|
||||
|
||||
It is geared toward the very small, i.e. boot floppies, embedded-
|
||||
systems, etc. Specifically it is used in the Debian Rescue/Install
|
||||
system (which caused the original busybox to be made), the Linux Router
|
||||
Project, and others.
|
||||
As of version 0.20 there is a version number. : ) Also as of version
|
||||
0.20, BB is now modularized to easily allow you to build of only the
|
||||
BB parts you need, thereby reducing binary size. To turn off unwanted
|
||||
Busybox components, simply edit the file busybox.def.h and comment out
|
||||
the parts you do not need using C++ style (//) comments.
|
||||
|
||||
As of version 0.20 there is a version number. : )
|
||||
Also as of version 0.20, BB is modularized to allow an easy build of
|
||||
only the BB parts you need, to reduce binary size.
|
||||
After the build is complete a busybox.links file is generated which is
|
||||
then used by 'make install' to create symlinks to the busybox binary
|
||||
for all compiled in functions. By default, 'make install' will place
|
||||
the symlink forest into `pwd`/_install unless you have defined the
|
||||
PREFIX environment variable.
|
||||
|
||||
Edit the file busybox.def.h and comment out the parts you do not need
|
||||
using C++ comments (//)
|
||||
Please feed suggestions, bug reports, insults, and bribes back to:
|
||||
Erik Andersen
|
||||
<andersen@lineo.com>
|
||||
<andersee@deban.org>
|
||||
|
||||
After the build is complete a busybox.links file is generated to allow
|
||||
you to easily make the sym/hard links to the busybox binary.
|
||||
<blatent plug>
|
||||
Many thanks to go to Lineo for paying me to work on busybox.
|
||||
</blatent plug>
|
||||
|
||||
Note the modular system is Makefile based, and purposely very
|
||||
simplistic. It does no dependency checking. That is left for you
|
||||
to figure out by trial and error.
|
||||
|
||||
Please feed patches back to:
|
||||
Erik Andersen <andersee@deban.org>
|
||||
@@ -0,0 +1,27 @@
|
||||
TODO list for busybox in no particular order. Just because something
|
||||
is listed here doesn't mean that it is going to be added to busybox,
|
||||
or that doing so is even a good idea. It just means that I _might_ get
|
||||
around to it some time. If you have any good ideas, please let me know.
|
||||
|
||||
-Erik
|
||||
|
||||
-----------
|
||||
|
||||
* Allow tar to create archives with sockets, devices, and other special files
|
||||
* Add in a mini insmod, rmmod, lsmod
|
||||
* init clearly needs to support some type of minimalist /etc/inittab. I
|
||||
currently have _way_ too much policy hardcoded in the source. Adding
|
||||
support for getty has made me realize how much that sucks.
|
||||
* dnsdomainname
|
||||
* traceroute/nslookup/netstat
|
||||
* rdate
|
||||
* hwclock
|
||||
* killall
|
||||
* stty
|
||||
* sort/uniq
|
||||
* wc
|
||||
* tr
|
||||
* expr (maybe?) (ash builtin?)
|
||||
* login/sulogin/passwd/getty (These are actully now part of tinylogin, which
|
||||
I've just started to maintain).
|
||||
|
||||
+46
-13
@@ -27,6 +27,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_CLEAR //usr/bin
|
||||
{"clear", clear_main},
|
||||
#endif
|
||||
#ifdef BB_CHVT //usr/bin
|
||||
{"chvt", chvt_main},
|
||||
#endif
|
||||
#ifdef BB_CP //bin
|
||||
{"cp", cp_main},
|
||||
#endif
|
||||
@@ -42,6 +45,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_DMESG //bin
|
||||
{"dmesg", dmesg_main},
|
||||
#endif
|
||||
#ifdef BB_DU //bin
|
||||
{"du", du_main},
|
||||
#endif
|
||||
#ifdef BB_DUTMP //usr/sbin
|
||||
{"dutmp", dutmp_main},
|
||||
#endif
|
||||
@@ -51,8 +57,8 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_FIND //usr/bin
|
||||
{"find", find_main},
|
||||
#endif
|
||||
#ifdef BB_CHVT //usr/bin
|
||||
{"chvt", chvt_main},
|
||||
#ifdef BB_FREE //usr/bin
|
||||
{"free", free_main},
|
||||
#endif
|
||||
#ifdef BB_DEALLOCVT //usr/bin
|
||||
{"deallocvt", deallocvt_main},
|
||||
@@ -69,9 +75,18 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_HALT //sbin
|
||||
{"halt", halt_main},
|
||||
#endif
|
||||
#ifdef BB_HEAD //bin
|
||||
{"head", head_main},
|
||||
#endif
|
||||
#ifdef BB_HOSTNAME //bin
|
||||
{"hostname", hostname_main},
|
||||
#endif
|
||||
#ifdef BB_INIT //sbin
|
||||
{"init", init_main},
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LINUXRC //
|
||||
{"linuxrc", init_main},
|
||||
#endif
|
||||
#ifdef BB_KILL //bin
|
||||
{"kill", kill_main},
|
||||
#endif
|
||||
@@ -120,6 +135,12 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_MV //bin
|
||||
{"mv", mv_main},
|
||||
#endif
|
||||
#ifdef BB_PING //bin
|
||||
{"ping", ping_main},
|
||||
#endif
|
||||
#ifdef BB_POWEROFF //sbin
|
||||
{"poweroff", poweroff_main},
|
||||
#endif
|
||||
#ifdef BB_PRINTF //usr/bin
|
||||
{"printf", printf_main},
|
||||
#endif
|
||||
@@ -148,15 +169,27 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_SLEEP //bin
|
||||
{"sleep", sleep_main},
|
||||
#endif
|
||||
#ifdef BB_TAR //bin
|
||||
{"tar", tar_main},
|
||||
#ifdef BB_SYNC //bin
|
||||
{"sync", sync_main},
|
||||
#endif
|
||||
#ifdef BB_SYSLOGD //sbin
|
||||
{"syslogd", syslogd_main},
|
||||
#endif
|
||||
#ifdef BB_LOGGER //usr/bin
|
||||
{"logger", logger_main},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF //sbin
|
||||
{"swapon", swap_on_off_main},
|
||||
{"swapoff", swap_on_off_main},
|
||||
#endif
|
||||
#ifdef BB_SYNC //bin
|
||||
{"sync", sync_main},
|
||||
#ifdef BB_TAIL //usr/bin
|
||||
{"tail", tail_main},
|
||||
#endif
|
||||
#ifdef BB_TAR //bin
|
||||
{"tar", tar_main},
|
||||
#endif
|
||||
#ifdef BB_TEE //bin
|
||||
{"tee", tee_main},
|
||||
#endif
|
||||
#ifdef BB_TOUCH //usr/bin
|
||||
{"touch", touch_main},
|
||||
@@ -174,9 +207,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_UPDATE //sbin
|
||||
{"update", update_main},
|
||||
#endif
|
||||
#ifdef BB_ZCAT //bin
|
||||
{"zcat", zcat_main},
|
||||
{"gunzip", zcat_main},
|
||||
#ifdef BB_GUNZIP //bin
|
||||
{"zcat", gunzip_main},
|
||||
{"gunzip", gunzip_main},
|
||||
#endif
|
||||
#ifdef BB_GZIP //bin
|
||||
{"gzip", gzip_main},
|
||||
@@ -220,12 +253,12 @@ int busybox_main(int argc, char **argv)
|
||||
|
||||
if (been_there_done_that == 1 || argc < 1) {
|
||||
const struct Applet *a = applets;
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n",
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
|
||||
BB_VER, BB_BT);
|
||||
fprintf(stderr, "\nUsage:\t[function] [arguments]...\n");
|
||||
fprintf(stderr, "\tbusybox [function] [arguments]...\n");
|
||||
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
|
||||
fprintf(stderr, " or: [function] [arguments]...\n\n");
|
||||
fprintf(stderr,
|
||||
"\n\tMost people will create a symlink to busybox for each\n"
|
||||
"\tMost people will create a symlink to busybox for each\n"
|
||||
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
|
||||
fprintf(stderr, "\nCurrently defined functions:\n");
|
||||
|
||||
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
sed -n '/^#define/{s/.*BB_//; s/$/.o/p; }' busybox.def.h | \
|
||||
tr [:upper:] [:lower:]
|
||||
ls -1 `sed -n '/^#define/{s/.*BB_// ; s/$/.c/p; }' busybox.def.h | \
|
||||
tr [:upper:] [:lower:]` 2> /dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
if [ "$1" == "" ]; then
|
||||
echo "No installation directory, aborting."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
h=`sort busybox.links | uniq`
|
||||
|
||||
for i in $h ; do
|
||||
echo " $1$i -> /bin/busybox"
|
||||
mkdir -p $1/`echo $i | sed -e 's/\/[^\/]*$//' `
|
||||
ln -fs /bin/busybox $1$i
|
||||
done
|
||||
rm -f $1/bin/busybox
|
||||
install -m 755 busybox $1/bin/busybox
|
||||
|
||||
exit 0
|
||||
+125
-37
@@ -4,11 +4,11 @@
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
static const char zcat_usage[] = "zcat\n"
|
||||
"\n"
|
||||
"\tuncompress gzipped data from stdin to stdout\n";
|
||||
|
||||
|
||||
static const char gunzip_usage[] =
|
||||
"gunzip [OPTION]... FILE\n\n"
|
||||
"Uncompress FILE (or standard input if FILE is '-').\n\n"
|
||||
"Options:\n"
|
||||
"\t-c\tWrite output to standard output\n";
|
||||
|
||||
/* gzip (GNU zip) -- compress files with zip algorithm and 'compress' interface
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly
|
||||
@@ -220,9 +220,6 @@ extern long bytes_in; /* number of input bytes */
|
||||
extern long bytes_out; /* number of output bytes */
|
||||
extern long header_bytes;/* number of bytes in gzip header */
|
||||
|
||||
extern int ifd; /* input file descriptor */
|
||||
extern int ofd; /* output file descriptor */
|
||||
|
||||
extern long ifile_size; /* input file size, -1 for devices (debug only) */
|
||||
|
||||
typedef int file_t; /* Do not use stdio */
|
||||
@@ -262,7 +259,6 @@ extern int exit_code; /* program exit code */
|
||||
extern int verbose; /* be verbose (-v) */
|
||||
extern int level; /* compression level */
|
||||
extern int test; /* check .z file integrity */
|
||||
extern int to_stdout; /* output to stdout (-c) */
|
||||
extern int save_orig_name; /* set if original name must be saved */
|
||||
|
||||
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
|
||||
@@ -681,18 +677,48 @@ long header_bytes; /* number of bytes in gzip header */
|
||||
|
||||
/* local functions */
|
||||
|
||||
local void treat_stdin OF((void));
|
||||
local int get_method OF((int in));
|
||||
local void do_exit OF((int exitcode));
|
||||
int main OF((int argc, char **argv));
|
||||
int (*work) OF((int infile, int outfile)) = unzip; /* function to call */
|
||||
local void do_exit(int exitcode) __attribute__ ((noreturn));
|
||||
|
||||
#define strequ(s1, s2) (strcmp((s1),(s2)) == 0)
|
||||
|
||||
/* ======================================================================== */
|
||||
int zcat_main (int argc, char * * argv)
|
||||
int gunzip_main (int argc, char** argv)
|
||||
{
|
||||
int file_count; /* number of files to precess */
|
||||
int to_stdout = 0;
|
||||
int fromstdin = 0;
|
||||
int result;
|
||||
int inFileNum;
|
||||
int outFileNum;
|
||||
int delInputFile=0;
|
||||
struct stat statBuf;
|
||||
char* delFileName;
|
||||
char ifname[MAX_PATH_LEN]; /* input file name */
|
||||
char ofname[MAX_PATH_LEN]; /* output file name */
|
||||
|
||||
if (argc==1)
|
||||
usage(gunzip_usage);
|
||||
|
||||
if (strcmp(*argv, "zcat")==0)
|
||||
to_stdout = 1;
|
||||
|
||||
/* Parse any options */
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
if (*((*argv)+1) == '\0') {
|
||||
fromstdin = 1;
|
||||
to_stdout = 1;
|
||||
}
|
||||
while (*(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 'c':
|
||||
to_stdout = 1;
|
||||
break;
|
||||
default:
|
||||
usage(gunzip_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
||||
if (foreground) {
|
||||
@@ -723,31 +749,90 @@ int zcat_main (int argc, char * * argv)
|
||||
ALLOC(ush, tab_prefix1, 1L<<(BITS-1));
|
||||
#endif
|
||||
|
||||
/* And get to work */
|
||||
treat_stdin();
|
||||
if (fromstdin==1) {
|
||||
strcpy(ofname, "stdin");
|
||||
|
||||
do_exit(exit_code);
|
||||
return exit_code; /* just to avoid lint warning */
|
||||
}
|
||||
inFileNum=fileno(stdin);
|
||||
ifile_size = -1L; /* convention for unknown size */
|
||||
} else {
|
||||
/* Open up the input file */
|
||||
if (*argv=='\0')
|
||||
usage(gunzip_usage);
|
||||
strncpy(ifname, *argv, MAX_PATH_LEN);
|
||||
|
||||
/* ========================================================================
|
||||
* Compress or decompress stdin
|
||||
*/
|
||||
local void treat_stdin()
|
||||
{
|
||||
ifile_size = -1L; /* convention for unknown size */
|
||||
|
||||
clear_bufs(); /* clear input and output buffers */
|
||||
part_nb = 0;
|
||||
|
||||
method = get_method(ifd);
|
||||
|
||||
if (method < 0) {
|
||||
do_exit(exit_code); /* error message already emitted */
|
||||
/* Open input fille */
|
||||
inFileNum=open( ifname, O_RDONLY);
|
||||
if (inFileNum < 0) {
|
||||
perror(ifname);
|
||||
do_exit(WARNING);
|
||||
}
|
||||
/* Get the time stamp on the input file. */
|
||||
result = stat(ifname, &statBuf);
|
||||
if (result < 0) {
|
||||
perror(ifname);
|
||||
do_exit(WARNING);
|
||||
}
|
||||
ifile_size = statBuf.st_size;
|
||||
}
|
||||
|
||||
(*work)(fileno(stdin), fileno(stdout));
|
||||
if (to_stdout==1) {
|
||||
/* And get to work */
|
||||
strcpy(ofname, "stdout");
|
||||
outFileNum=fileno(stdout);
|
||||
|
||||
clear_bufs(); /* clear input and output buffers */
|
||||
part_nb = 0;
|
||||
|
||||
/* Actually do the compression/decompression. */
|
||||
unzip(inFileNum, outFileNum);
|
||||
|
||||
} else {
|
||||
char* pos;
|
||||
|
||||
/* And get to work */
|
||||
strncpy(ofname, ifname, MAX_PATH_LEN-4);
|
||||
pos=strstr(ofname, ".gz");
|
||||
if (pos != NULL) {
|
||||
*pos='\0';
|
||||
delInputFile=1;
|
||||
} else {
|
||||
pos=strstr(ofname, ".tgz");
|
||||
if (pos != NULL) {
|
||||
*pos='\0';
|
||||
strcat( pos, ".tar");
|
||||
delInputFile=1;
|
||||
}
|
||||
}
|
||||
|
||||
/* Open output fille */
|
||||
outFileNum=open( ofname, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW);
|
||||
if (outFileNum < 0) {
|
||||
perror(ofname);
|
||||
do_exit(WARNING);
|
||||
}
|
||||
/* Set permissions on the file */
|
||||
fchmod(outFileNum, statBuf.st_mode);
|
||||
|
||||
clear_bufs(); /* clear input and output buffers */
|
||||
part_nb = 0;
|
||||
|
||||
/* Actually do the compression/decompression. */
|
||||
result=unzip(inFileNum, outFileNum);
|
||||
|
||||
close( outFileNum);
|
||||
close( inFileNum);
|
||||
/* Delete the original file */
|
||||
if (result == OK)
|
||||
delFileName=ifname;
|
||||
else
|
||||
delFileName=ofname;
|
||||
|
||||
if (delInputFile == 1 && unlink (delFileName) < 0) {
|
||||
perror (delFileName);
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
do_exit(exit_code);
|
||||
}
|
||||
|
||||
|
||||
@@ -795,7 +880,6 @@ local int get_method(in)
|
||||
exit_code = ERROR;
|
||||
return -1;
|
||||
}
|
||||
work = unzip;
|
||||
flags = (uch)get_byte();
|
||||
|
||||
(ulg)get_byte(); /* Ignore time stamp */
|
||||
@@ -940,6 +1024,10 @@ int unzip(in, out)
|
||||
|
||||
ifd = in;
|
||||
ofd = out;
|
||||
method = get_method(ifd);
|
||||
if (method < 0) {
|
||||
do_exit(exit_code); /* error message already emitted */
|
||||
}
|
||||
|
||||
updcrc(NULL, 0); /* initialize crc */
|
||||
|
||||
@@ -1025,7 +1113,7 @@ int unzip(in, out)
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
const ulg crc_32_tab[]; /* crc table, defined below */
|
||||
static const ulg crc_32_tab[]; /* crc table, defined below */
|
||||
|
||||
/* ===========================================================================
|
||||
* Run a set of bytes through the crc shift register. If s is a NULL
|
||||
@@ -1239,7 +1327,7 @@ voidp xmalloc (size)
|
||||
/* ========================================================================
|
||||
* Table of CRC-32's of all single-byte values (made by makecrc.c)
|
||||
*/
|
||||
const ulg crc_32_tab[] = {
|
||||
static const ulg crc_32_tab[] = {
|
||||
0x00000000L, 0x77073096L, 0xee0e612cL, 0x990951baL, 0x076dc419L,
|
||||
0x706af48fL, 0xe963a535L, 0x9e6495a3L, 0x0edb8832L, 0x79dcb8a4L,
|
||||
0xe0d5e91eL, 0x97d2d988L, 0x09b64c2bL, 0x7eb17cbdL, 0xe7b82d07L,
|
||||
+113
-36
@@ -7,11 +7,17 @@
|
||||
#include "internal.h"
|
||||
#ifdef BB_GZIP
|
||||
|
||||
#ifndef BB_ZCAT
|
||||
#error you need zcat to have gzip support!
|
||||
#endif
|
||||
//#ifndef BB_ZCAT
|
||||
//#error you need zcat to have gzip support!
|
||||
//#endif
|
||||
|
||||
static const char gzip_usage[] =
|
||||
"gzip [OPTION]... FILE\n\n"
|
||||
"Compress FILE with maximum compression.\n"
|
||||
"When FILE is -, reads standard input. Implies -c.\n\n"
|
||||
"Options:\n"
|
||||
"\t-c\tWrite output to standard output instead of FILE.gz\n";
|
||||
|
||||
static const char gzip_usage[] = "gzip\nignores all command line arguments\ncompress stdin to stdout with -9 compression\n";
|
||||
|
||||
/* gzip.h -- common declarations for all gzip modules
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
@@ -210,7 +216,6 @@ extern int exit_code; /* program exit code */
|
||||
extern int verbose; /* be verbose (-v) */
|
||||
extern int quiet; /* be quiet (-q) */
|
||||
extern int test; /* check .z file integrity */
|
||||
extern int to_stdout; /* output to stdout (-c) */
|
||||
extern int save_orig_name; /* set if original name must be saved */
|
||||
|
||||
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
|
||||
@@ -272,7 +277,7 @@ extern int save_orig_name; /* set if original name must be saved */
|
||||
#define WARN(msg) {if (!quiet) fprintf msg ; \
|
||||
if (exit_code == OK) exit_code = WARNING;}
|
||||
|
||||
local void do_exit(int exitcode);
|
||||
local void do_exit(int exitcode) __attribute__ ((noreturn));
|
||||
|
||||
/* in zip.c: */
|
||||
extern int zip OF((int in, int out));
|
||||
@@ -1726,7 +1731,6 @@ DECLARE(uch, window, 2L*WSIZE);
|
||||
/* local variables */
|
||||
|
||||
int ascii = 0; /* convert end-of-lines to local OS conventions */
|
||||
int to_stdout = 0; /* output to stdout (-c) */
|
||||
int decompress = 0; /* decompress (-d) */
|
||||
int no_name = -1; /* don't save or restore the original file name */
|
||||
int no_time = -1; /* don't save or restore the original file time */
|
||||
@@ -1758,17 +1762,42 @@ unsigned outcnt; /* bytes in output buffer */
|
||||
|
||||
/* local functions */
|
||||
|
||||
local void treat_stdin OF((void));
|
||||
static int (*work) OF((int infile, int outfile)) = zip; /* function to call */
|
||||
|
||||
#define strequ(s1, s2) (strcmp((s1),(s2)) == 0)
|
||||
|
||||
/* ======================================================================== */
|
||||
// int main (argc, argv)
|
||||
// int argc;
|
||||
// char **argv;
|
||||
int gzip_main(int argc, char * * argv)
|
||||
int gzip_main(int argc, char ** argv)
|
||||
{
|
||||
int result;
|
||||
int inFileNum;
|
||||
int outFileNum;
|
||||
struct stat statBuf;
|
||||
char* delFileName;
|
||||
int tostdout = 0;
|
||||
int fromstdin = 0;
|
||||
|
||||
if (argc==1)
|
||||
usage(gzip_usage);
|
||||
|
||||
/* Parse any options */
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
if (*((*argv)+1) == '\0') {
|
||||
fromstdin = 1;
|
||||
tostdout = 1;
|
||||
}
|
||||
while (*(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 'c':
|
||||
tostdout = 1;
|
||||
break;
|
||||
default:
|
||||
usage(gzip_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
||||
if (foreground) {
|
||||
(void) signal (SIGINT, (sig_type)abort_gzip);
|
||||
@@ -1787,8 +1816,6 @@ int gzip_main(int argc, char * * argv)
|
||||
strncpy(z_suffix, Z_SUFFIX, sizeof(z_suffix)-1);
|
||||
z_len = strlen(z_suffix);
|
||||
|
||||
to_stdout = 1;
|
||||
|
||||
/* Allocate all global buffers (for DYN_ALLOC option) */
|
||||
ALLOC(uch, inbuf, INBUFSIZ +INBUF_EXTRA);
|
||||
ALLOC(uch, outbuf, OUTBUFSIZ+OUTBUF_EXTRA);
|
||||
@@ -1801,33 +1828,84 @@ int gzip_main(int argc, char * * argv)
|
||||
ALLOC(ush, tab_prefix1, 1L<<(BITS-1));
|
||||
#endif
|
||||
|
||||
/* And get to work */
|
||||
treat_stdin();
|
||||
do_exit(exit_code);
|
||||
return exit_code; /* just to avoid lint warning */
|
||||
}
|
||||
if (fromstdin==1) {
|
||||
strcpy(ofname, "stdin");
|
||||
|
||||
/* ========================================================================
|
||||
* Compress or decompress stdin
|
||||
*/
|
||||
local void treat_stdin()
|
||||
{
|
||||
inFileNum=fileno(stdin);
|
||||
time_stamp = 0; /* time unknown by default */
|
||||
ifile_size = -1L; /* convention for unknown size */
|
||||
} else {
|
||||
/* Open up the input file */
|
||||
if (*argv=='\0')
|
||||
usage(gzip_usage);
|
||||
strncpy(ifname, *argv, MAX_PATH_LEN);
|
||||
|
||||
/* Open input fille */
|
||||
inFileNum=open( ifname, O_RDONLY);
|
||||
if (inFileNum < 0) {
|
||||
perror(ifname);
|
||||
do_exit(WARNING);
|
||||
}
|
||||
/* Get the time stamp on the input file. */
|
||||
result = stat(ifname, &statBuf);
|
||||
if (result < 0) {
|
||||
perror(ifname);
|
||||
do_exit(WARNING);
|
||||
}
|
||||
time_stamp = statBuf.st_ctime;
|
||||
ifile_size = statBuf.st_size;
|
||||
}
|
||||
|
||||
|
||||
if (tostdout==1) {
|
||||
/* And get to work */
|
||||
strcpy(ofname, "stdout");
|
||||
outFileNum=fileno(stdout);
|
||||
SET_BINARY_MODE(fileno(stdout));
|
||||
strcpy(ifname, "stdin");
|
||||
strcpy(ofname, "stdout");
|
||||
|
||||
/* Get the time stamp on the input file. */
|
||||
time_stamp = 0; /* time unknown by default */
|
||||
clear_bufs(); /* clear input and output buffers */
|
||||
part_nb = 0;
|
||||
|
||||
ifile_size = -1L; /* convention for unknown size */
|
||||
/* Actually do the compression/decompression. */
|
||||
zip(inFileNum, outFileNum);
|
||||
|
||||
clear_bufs(); /* clear input and output buffers */
|
||||
to_stdout = 1;
|
||||
part_nb = 0;
|
||||
} else {
|
||||
|
||||
/* Actually do the compression/decompression. Loop over zipped members.
|
||||
*/
|
||||
if ((*work)(fileno(stdin), fileno(stdout)) != OK) return;
|
||||
/* And get to work */
|
||||
strncpy(ofname, ifname, MAX_PATH_LEN-4);
|
||||
strcat(ofname, ".gz");
|
||||
|
||||
|
||||
/* Open output fille */
|
||||
outFileNum=open( ofname, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW);
|
||||
if (outFileNum < 0) {
|
||||
perror(ofname);
|
||||
do_exit(WARNING);
|
||||
}
|
||||
SET_BINARY_MODE(outFileNum);
|
||||
/* Set permissions on the file */
|
||||
fchmod(outFileNum, statBuf.st_mode);
|
||||
|
||||
clear_bufs(); /* clear input and output buffers */
|
||||
part_nb = 0;
|
||||
|
||||
/* Actually do the compression/decompression. */
|
||||
result=zip(inFileNum, outFileNum);
|
||||
close( outFileNum);
|
||||
close( inFileNum);
|
||||
/* Delete the original file */
|
||||
if (result == OK)
|
||||
delFileName=ifname;
|
||||
else
|
||||
delFileName=ofname;
|
||||
|
||||
if (unlink (delFileName) < 0) {
|
||||
perror (delFileName);
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
do_exit(exit_code);
|
||||
}
|
||||
|
||||
/* ========================================================================
|
||||
@@ -2941,8 +3019,6 @@ local void set_file_type()
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
extern ulg crc_32_tab[]; /* crc table, defined below */
|
||||
|
||||
/* ===========================================================================
|
||||
* Copy input to output unchanged: zcat == cat with --force.
|
||||
* IN assertion: insize bytes have already been read in inbuf.
|
||||
@@ -3150,6 +3226,7 @@ int zip(in, out)
|
||||
|
||||
/* Write the header to the gzip file. See algorithm.doc for the format */
|
||||
|
||||
|
||||
method = DEFLATED;
|
||||
put_byte(GZIP_MAGIC[0]); /* magic header */
|
||||
put_byte(GZIP_MAGIC[1]);
|
||||
|
||||
+94
-50
@@ -10,6 +10,9 @@
|
||||
* Modified for busybox by Erik Andersen <andersee@debian.org>
|
||||
* Adjusted to grok stdin/stdout options.
|
||||
*
|
||||
* Modified to handle device special files by Matt Porter
|
||||
* <porter@debian.org>
|
||||
*
|
||||
* 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
|
||||
@@ -34,13 +37,16 @@
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/sysmacros.h>
|
||||
|
||||
|
||||
static const char tar_usage[] =
|
||||
"tar -[cxtvOf] [tarFileName] [FILE] ...\n"
|
||||
"Create, extract, or list files from a tar file\n\n"
|
||||
"\tc=create, x=extract, t=list contents, v=verbose,\n"
|
||||
"\tO=extract to stdout, f=tarfile or \"-\" for stdin\n";
|
||||
"tar -[cxtvOf] [tarFileName] [FILE] ...\n\n"
|
||||
"Create, extract, or list files from a tar file\n\n"
|
||||
"Options:\n"
|
||||
"\tc=create, x=extract, t=list contents, v=verbose,\n"
|
||||
"\tO=extract to stdout, f=tarfile or \"-\" for stdin\n";
|
||||
|
||||
|
||||
|
||||
@@ -92,7 +98,7 @@ static int createFlag;
|
||||
static int verboseFlag;
|
||||
static int tostdoutFlag;
|
||||
|
||||
static int inHeader;
|
||||
static int inHeader; // <- check me
|
||||
static int badHeader;
|
||||
static int errorFlag;
|
||||
static int skipFileFlag;
|
||||
@@ -169,10 +175,9 @@ extern int tar_main (int argc, char **argv)
|
||||
/*
|
||||
* Parse the options.
|
||||
*/
|
||||
options = *argv++;
|
||||
argc--;
|
||||
|
||||
if (**argv == '-') {
|
||||
options = (*argv++) + 1;
|
||||
argc--;
|
||||
for (; *options; options++) {
|
||||
switch (*options) {
|
||||
case 'f':
|
||||
@@ -208,10 +213,13 @@ extern int tar_main (int argc, char **argv)
|
||||
break;
|
||||
|
||||
case '-':
|
||||
usage( tar_usage);
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf (stderr, "Unknown tar flag '%c'\n", *options);
|
||||
fprintf (stderr, "Unknown tar flag '%c'\n"
|
||||
"Try `tar --help' for more information\n",
|
||||
*options);
|
||||
|
||||
exit (FALSE);
|
||||
}
|
||||
@@ -221,7 +229,7 @@ extern int tar_main (int argc, char **argv)
|
||||
/*
|
||||
* Validate the options.
|
||||
*/
|
||||
if (extractFlag + listFlag + createFlag != 1) {
|
||||
if (extractFlag + listFlag + createFlag != (TRUE+FALSE+FALSE)) {
|
||||
fprintf (stderr,
|
||||
"Exactly one of 'c', 'x' or 't' must be specified\n");
|
||||
|
||||
@@ -232,13 +240,13 @@ extern int tar_main (int argc, char **argv)
|
||||
* Do the correct type of action supplying the rest of the
|
||||
* command line arguments as the list of files to process.
|
||||
*/
|
||||
if (createFlag)
|
||||
if (createFlag==TRUE)
|
||||
writeTarFile (argc, argv);
|
||||
else
|
||||
readTarFile (argc, argv);
|
||||
if (errorFlag)
|
||||
if (errorFlag==TRUE)
|
||||
fprintf (stderr, "\n");
|
||||
exit (errorFlag);
|
||||
exit (!errorFlag);
|
||||
}
|
||||
|
||||
|
||||
@@ -269,7 +277,7 @@ static void readTarFile (int fileCount, char **fileTable)
|
||||
* Open the tar file for reading.
|
||||
*/
|
||||
if ((tarName == NULL) || !strcmp (tarName, "-")) {
|
||||
tarFd = STDIN;
|
||||
tarFd = fileno(stdin);
|
||||
} else
|
||||
tarFd = open (tarName, O_RDONLY);
|
||||
|
||||
@@ -283,7 +291,7 @@ static void readTarFile (int fileCount, char **fileTable)
|
||||
* Read blocks from the file until an end of file header block
|
||||
* has been seen. (A real end of file from a read is an error.)
|
||||
*/
|
||||
while (!eofFlag) {
|
||||
while (eofFlag==FALSE) {
|
||||
/*
|
||||
* Read the next block of data if necessary.
|
||||
* This will be a large block if possible, which we will
|
||||
@@ -310,7 +318,7 @@ static void readTarFile (int fileCount, char **fileTable)
|
||||
/*
|
||||
* If we are expecting a header block then examine it.
|
||||
*/
|
||||
if (inHeader) {
|
||||
if (inHeader==TRUE) {
|
||||
readHeader ((const TarHeader *) cp, fileCount, fileTable);
|
||||
|
||||
cp += TAR_BLOCK_SIZE;
|
||||
@@ -374,12 +382,15 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
int uid;
|
||||
int gid;
|
||||
int checkSum;
|
||||
unsigned int major;
|
||||
unsigned int minor;
|
||||
long size;
|
||||
time_t mtime;
|
||||
const char *name;
|
||||
int cc;
|
||||
int hardLink;
|
||||
int softLink;
|
||||
int devFileFlag;
|
||||
|
||||
/*
|
||||
* If the block is completely empty, then this is the end of the
|
||||
@@ -408,9 +419,11 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
size = getOctal (hp->size, sizeof (hp->size));
|
||||
mtime = getOctal (hp->mtime, sizeof (hp->mtime));
|
||||
checkSum = getOctal (hp->checkSum, sizeof (hp->checkSum));
|
||||
major = getOctal (hp->devMajor, sizeof (hp->devMajor));
|
||||
minor = getOctal (hp->devMinor, sizeof (hp->devMinor));
|
||||
|
||||
if ((mode < 0) || (uid < 0) || (gid < 0) || (size < 0)) {
|
||||
if (!badHeader)
|
||||
if (badHeader==FALSE)
|
||||
fprintf (stderr, "Bad tar header, skipping\n");
|
||||
|
||||
badHeader = TRUE;
|
||||
@@ -420,6 +433,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
|
||||
badHeader = FALSE;
|
||||
skipFileFlag = FALSE;
|
||||
devFileFlag = FALSE;
|
||||
|
||||
/*
|
||||
* Check for the file modes.
|
||||
@@ -431,12 +445,10 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
(hp->typeFlag == TAR_TYPE_SOFT_LINK - '0'));
|
||||
|
||||
/*
|
||||
* Check for a directory or a regular file.
|
||||
* Check for a directory.
|
||||
*/
|
||||
if (name[strlen (name) - 1] == '/')
|
||||
mode |= S_IFDIR;
|
||||
else if ((mode & S_IFMT) == 0)
|
||||
mode |= S_IFREG;
|
||||
|
||||
/*
|
||||
* Check for absolute paths in the file.
|
||||
@@ -446,7 +458,7 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
while (*name == '/')
|
||||
name++;
|
||||
|
||||
if (!warnedRoot) {
|
||||
if (warnedRoot==FALSE) {
|
||||
fprintf (stderr,
|
||||
"Absolute path detected, removing leading slashes\n");
|
||||
}
|
||||
@@ -458,9 +470,10 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
* See if we want this file to be restored.
|
||||
* If not, then set up to skip it.
|
||||
*/
|
||||
if (!wantFileName (name, fileCount, fileTable)) {
|
||||
if (!hardLink && !softLink && S_ISREG (mode)) {
|
||||
inHeader = (size == 0);
|
||||
if (wantFileName (name, fileCount, fileTable) == FALSE) {
|
||||
if ( !hardLink && !softLink && (S_ISREG (mode) || S_ISCHR (mode)
|
||||
|| S_ISBLK (mode) || S_ISSOCK(mode) || S_ISFIFO(mode) ) ) {
|
||||
inHeader = (size == 0)? TRUE : FALSE;
|
||||
dataCc = size;
|
||||
}
|
||||
|
||||
@@ -473,19 +486,23 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
* This file is to be handled.
|
||||
* If we aren't extracting then just list information about the file.
|
||||
*/
|
||||
if (!extractFlag) {
|
||||
if (verboseFlag) {
|
||||
printf ("%s %3d/%-d %9ld %s %s", modeString (mode),
|
||||
uid, gid, size, timeString (mtime), name);
|
||||
} else
|
||||
printf ("%s", name);
|
||||
if (extractFlag==FALSE) {
|
||||
if (verboseFlag==TRUE) {
|
||||
printf ("%s %3d/%-d ", modeString (mode), uid, gid);
|
||||
if( S_ISCHR (mode) || S_ISBLK (mode) )
|
||||
printf ("%4d,%4d %s ", major,minor, timeString (mtime));
|
||||
else
|
||||
printf ("%9ld %s ", size, timeString (mtime));
|
||||
}
|
||||
printf ("%s", name);
|
||||
|
||||
if (hardLink)
|
||||
printf (" (link to \"%s\")", hp->linkName);
|
||||
else if (softLink)
|
||||
printf (" (symlink to \"%s\")", hp->linkName);
|
||||
else if (S_ISREG (mode)) {
|
||||
inHeader = (size == 0);
|
||||
else if (S_ISREG (mode) || S_ISCHR (mode) || S_ISBLK (mode) ||
|
||||
S_ISSOCK(mode) || S_ISFIFO(mode) ) {
|
||||
inHeader = (size == 0)? TRUE : FALSE;
|
||||
dataCc = size;
|
||||
}
|
||||
|
||||
@@ -497,13 +514,14 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
/*
|
||||
* We really want to extract the file.
|
||||
*/
|
||||
if (verboseFlag)
|
||||
if (verboseFlag==TRUE)
|
||||
printf ("x %s\n", name);
|
||||
|
||||
if (hardLink) {
|
||||
if (link (hp->linkName, name) < 0)
|
||||
perror (name);
|
||||
|
||||
chmod(name, mode);
|
||||
chown(name, uid, gid);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -511,48 +529,70 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
||||
#ifdef S_ISLNK
|
||||
if (symlink (hp->linkName, name) < 0)
|
||||
perror (name);
|
||||
chmod(name, mode);
|
||||
chown(name, uid, gid);
|
||||
#else
|
||||
fprintf (stderr, "Cannot create symbolic links\n");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
/* Set the umask for this process so it doesn't
|
||||
* screw things up. */
|
||||
umask(0);
|
||||
|
||||
/*
|
||||
* If the file is a directory, then just create the path.
|
||||
*/
|
||||
if (S_ISDIR (mode)) {
|
||||
createPath (name, mode);
|
||||
chmod(name, mode);
|
||||
chown(name, uid, gid);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/*
|
||||
* There is a file to write.
|
||||
* First create the path to it if necessary with a default permission.
|
||||
* First create the path to it if necessary with default permissions.
|
||||
*/
|
||||
createPath (name, 0777);
|
||||
|
||||
inHeader = (size == 0);
|
||||
inHeader = (size == 0)? TRUE : FALSE;
|
||||
dataCc = size;
|
||||
|
||||
/*
|
||||
* Start the output file.
|
||||
*/
|
||||
if (tostdoutFlag == TRUE)
|
||||
outFd = STDOUT;
|
||||
else
|
||||
outFd = open (name, O_WRONLY | O_CREAT | O_TRUNC, mode);
|
||||
outFd = fileno(stdout);
|
||||
else {
|
||||
if ( S_ISCHR(mode) || S_ISBLK(mode) || S_ISSOCK(mode) ) {
|
||||
devFileFlag = TRUE;
|
||||
outFd = mknod (name, mode, makedev(major, minor) );
|
||||
}
|
||||
else if (S_ISFIFO(mode) ) {
|
||||
devFileFlag = TRUE;
|
||||
outFd = mkfifo(name, mode);
|
||||
} else {
|
||||
outFd = open (name, O_WRONLY | O_CREAT | O_TRUNC, mode);
|
||||
}
|
||||
}
|
||||
|
||||
if (outFd < 0) {
|
||||
perror (name);
|
||||
skipFileFlag = TRUE;
|
||||
return;
|
||||
}
|
||||
if (tostdoutFlag == FALSE) {
|
||||
fchmod(outFd, mode);
|
||||
fchown(outFd, uid, gid);
|
||||
}
|
||||
|
||||
/*
|
||||
* If the file is empty, then that's all we need to do.
|
||||
*/
|
||||
if (size == 0 && tostdoutFlag == FALSE) {
|
||||
if (size == 0 && (tostdoutFlag == FALSE) && (devFileFlag == FALSE)) {
|
||||
(void) close (outFd);
|
||||
outFd = -1;
|
||||
}
|
||||
@@ -578,7 +618,7 @@ static void readData (const char *cp, int count)
|
||||
* If we aren't extracting files or this file is being
|
||||
* skipped then do nothing more.
|
||||
*/
|
||||
if (!extractFlag || skipFileFlag)
|
||||
if (extractFlag==FALSE || skipFileFlag==TRUE)
|
||||
return;
|
||||
|
||||
/*
|
||||
@@ -627,7 +667,7 @@ static void writeTarFile (int fileCount, char **fileTable)
|
||||
*/
|
||||
if ((tarName == NULL) || !strcmp (tarName, "-")) {
|
||||
tostdoutFlag = TRUE;
|
||||
tarFd = STDOUT;
|
||||
tarFd = fileno(stdout);
|
||||
} else
|
||||
tarFd = open (tarName, O_WRONLY | O_CREAT | O_TRUNC, 0666);
|
||||
|
||||
@@ -648,12 +688,12 @@ static void writeTarFile (int fileCount, char **fileTable)
|
||||
|
||||
tarDev = statbuf.st_dev;
|
||||
tarInode = statbuf.st_ino;
|
||||
|
||||
|
||||
/*
|
||||
* Append each file name into the archive file.
|
||||
* Follow symbolic links for these top level file names.
|
||||
*/
|
||||
while (!errorFlag && (fileCount-- > 0)) {
|
||||
while (errorFlag==FALSE && (fileCount-- > 0)) {
|
||||
saveFile (*fileTable++, FALSE);
|
||||
}
|
||||
|
||||
@@ -685,7 +725,7 @@ static void saveFile (const char *fileName, int seeLinks)
|
||||
int mode;
|
||||
struct stat statbuf;
|
||||
|
||||
if (verboseFlag)
|
||||
if (verboseFlag==TRUE)
|
||||
printf ("a %s\n", fileName);
|
||||
|
||||
/*
|
||||
@@ -701,7 +741,7 @@ static void saveFile (const char *fileName, int seeLinks)
|
||||
* Find out about the file.
|
||||
*/
|
||||
#ifdef S_ISLNK
|
||||
if (seeLinks)
|
||||
if (seeLinks==TRUE)
|
||||
status = lstat (fileName, &statbuf);
|
||||
else
|
||||
#endif
|
||||
@@ -732,12 +772,16 @@ static void saveFile (const char *fileName, int seeLinks)
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (S_ISREG (mode)) {
|
||||
saveRegularFile (fileName, &statbuf);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
/* Some day add support for tarring these up... but not today. :) */
|
||||
// if (S_ISLNK(mode) || S_ISFIFO(mode) || S_ISBLK(mode) || S_ISCHR (mode) ) {
|
||||
// fprintf (stderr, "%s: This version of tar can't store this type of file\n", fileName);
|
||||
// }
|
||||
|
||||
/*
|
||||
* The file is a strange type of file, ignore it.
|
||||
@@ -801,7 +845,7 @@ saveRegularFile (const char *fileName, const struct stat *statbuf)
|
||||
*/
|
||||
cc = 0;
|
||||
|
||||
if (!sawEof) {
|
||||
if (sawEof==FALSE) {
|
||||
cc = fullRead (fileFd, data, dataCount);
|
||||
|
||||
if (cc < 0) {
|
||||
@@ -890,7 +934,7 @@ static void saveDirectory (const char *dirName, const struct stat *statbuf)
|
||||
* Read all of the directory entries and check them,
|
||||
* except for the current and parent directory entries.
|
||||
*/
|
||||
while (!errorFlag && ((entry = readdir (dir)) != NULL)) {
|
||||
while (errorFlag==FALSE && ((entry = readdir (dir)) != NULL)) {
|
||||
if ((strcmp (entry->d_name, ".") == 0) ||
|
||||
(strcmp (entry->d_name, "..") == 0)) {
|
||||
continue;
|
||||
@@ -989,7 +1033,7 @@ static void writeTarBlock (const char *buf, int len)
|
||||
/*
|
||||
* If we had a write error before, then do nothing more.
|
||||
*/
|
||||
if (errorFlag)
|
||||
if (errorFlag==TRUE)
|
||||
return;
|
||||
|
||||
/*
|
||||
|
||||
@@ -27,6 +27,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_CLEAR //usr/bin
|
||||
{"clear", clear_main},
|
||||
#endif
|
||||
#ifdef BB_CHVT //usr/bin
|
||||
{"chvt", chvt_main},
|
||||
#endif
|
||||
#ifdef BB_CP //bin
|
||||
{"cp", cp_main},
|
||||
#endif
|
||||
@@ -42,6 +45,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_DMESG //bin
|
||||
{"dmesg", dmesg_main},
|
||||
#endif
|
||||
#ifdef BB_DU //bin
|
||||
{"du", du_main},
|
||||
#endif
|
||||
#ifdef BB_DUTMP //usr/sbin
|
||||
{"dutmp", dutmp_main},
|
||||
#endif
|
||||
@@ -51,8 +57,8 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_FIND //usr/bin
|
||||
{"find", find_main},
|
||||
#endif
|
||||
#ifdef BB_CHVT //usr/bin
|
||||
{"chvt", chvt_main},
|
||||
#ifdef BB_FREE //usr/bin
|
||||
{"free", free_main},
|
||||
#endif
|
||||
#ifdef BB_DEALLOCVT //usr/bin
|
||||
{"deallocvt", deallocvt_main},
|
||||
@@ -69,9 +75,18 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_HALT //sbin
|
||||
{"halt", halt_main},
|
||||
#endif
|
||||
#ifdef BB_HEAD //bin
|
||||
{"head", head_main},
|
||||
#endif
|
||||
#ifdef BB_HOSTNAME //bin
|
||||
{"hostname", hostname_main},
|
||||
#endif
|
||||
#ifdef BB_INIT //sbin
|
||||
{"init", init_main},
|
||||
#endif
|
||||
#ifdef BB_FEATURE_LINUXRC //
|
||||
{"linuxrc", init_main},
|
||||
#endif
|
||||
#ifdef BB_KILL //bin
|
||||
{"kill", kill_main},
|
||||
#endif
|
||||
@@ -120,6 +135,12 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_MV //bin
|
||||
{"mv", mv_main},
|
||||
#endif
|
||||
#ifdef BB_PING //bin
|
||||
{"ping", ping_main},
|
||||
#endif
|
||||
#ifdef BB_POWEROFF //sbin
|
||||
{"poweroff", poweroff_main},
|
||||
#endif
|
||||
#ifdef BB_PRINTF //usr/bin
|
||||
{"printf", printf_main},
|
||||
#endif
|
||||
@@ -148,15 +169,27 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_SLEEP //bin
|
||||
{"sleep", sleep_main},
|
||||
#endif
|
||||
#ifdef BB_TAR //bin
|
||||
{"tar", tar_main},
|
||||
#ifdef BB_SYNC //bin
|
||||
{"sync", sync_main},
|
||||
#endif
|
||||
#ifdef BB_SYSLOGD //sbin
|
||||
{"syslogd", syslogd_main},
|
||||
#endif
|
||||
#ifdef BB_LOGGER //usr/bin
|
||||
{"logger", logger_main},
|
||||
#endif
|
||||
#ifdef BB_SWAPONOFF //sbin
|
||||
{"swapon", swap_on_off_main},
|
||||
{"swapoff", swap_on_off_main},
|
||||
#endif
|
||||
#ifdef BB_SYNC //bin
|
||||
{"sync", sync_main},
|
||||
#ifdef BB_TAIL //usr/bin
|
||||
{"tail", tail_main},
|
||||
#endif
|
||||
#ifdef BB_TAR //bin
|
||||
{"tar", tar_main},
|
||||
#endif
|
||||
#ifdef BB_TEE //bin
|
||||
{"tee", tee_main},
|
||||
#endif
|
||||
#ifdef BB_TOUCH //usr/bin
|
||||
{"touch", touch_main},
|
||||
@@ -174,9 +207,9 @@ static const struct Applet applets[] = {
|
||||
#ifdef BB_UPDATE //sbin
|
||||
{"update", update_main},
|
||||
#endif
|
||||
#ifdef BB_ZCAT //bin
|
||||
{"zcat", zcat_main},
|
||||
{"gunzip", zcat_main},
|
||||
#ifdef BB_GUNZIP //bin
|
||||
{"zcat", gunzip_main},
|
||||
{"gunzip", gunzip_main},
|
||||
#endif
|
||||
#ifdef BB_GZIP //bin
|
||||
{"gzip", gzip_main},
|
||||
@@ -220,12 +253,12 @@ int busybox_main(int argc, char **argv)
|
||||
|
||||
if (been_there_done_that == 1 || argc < 1) {
|
||||
const struct Applet *a = applets;
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n",
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n",
|
||||
BB_VER, BB_BT);
|
||||
fprintf(stderr, "\nUsage:\t[function] [arguments]...\n");
|
||||
fprintf(stderr, "\tbusybox [function] [arguments]...\n");
|
||||
fprintf(stderr, "Usage: busybox [function] [arguments]...\n");
|
||||
fprintf(stderr, " or: [function] [arguments]...\n\n");
|
||||
fprintf(stderr,
|
||||
"\n\tMost people will create a symlink to busybox for each\n"
|
||||
"\tMost people will create a symlink to busybox for each\n"
|
||||
"\tfunction name, and busybox will act like whatever you invoke it as.\n");
|
||||
fprintf(stderr, "\nCurrently defined functions:\n");
|
||||
|
||||
|
||||
+39
-3
@@ -14,20 +14,26 @@
|
||||
#define BB_DF
|
||||
#define BB_DMESG
|
||||
//#define BB_DUTMP
|
||||
#define BB_DU
|
||||
//#define BB_FDFLUSH
|
||||
#define BB_FIND
|
||||
#define BB_FREE
|
||||
#define BB_FSCK_MINIX
|
||||
#define BB_MKFS_MINIX
|
||||
#define BB_CHVT
|
||||
#define BB_DEALLOCVT
|
||||
#define BB_GREP
|
||||
//#define BB_HALT
|
||||
#define BB_HEAD
|
||||
#define BB_HOSTNAME
|
||||
#define BB_INIT
|
||||
#define BB_KILL
|
||||
#define BB_KLOGD
|
||||
//#define BB_LENGTH
|
||||
#define BB_LN
|
||||
#define BB_LOADFONT
|
||||
#define BB_LOADKMAP
|
||||
#define BB_LOGGER
|
||||
#define BB_LS
|
||||
//#define BB_MAKEDEVS
|
||||
//#define BB_MATH
|
||||
@@ -37,9 +43,12 @@
|
||||
//#define BB_MNC
|
||||
#define BB_MORE
|
||||
#define BB_MOUNT
|
||||
#define BB_NFSMOUNT
|
||||
//#define BB_MT
|
||||
//#define BB_MTAB
|
||||
#define BB_MV
|
||||
#define BB_PING
|
||||
#define BB_POWEROFF
|
||||
//#define BB_PRINTF
|
||||
#define BB_PS
|
||||
#define BB_PWD
|
||||
@@ -52,14 +61,41 @@
|
||||
#define BB_SLEEP
|
||||
#define BB_SWAPONOFF
|
||||
#define BB_SYNC
|
||||
#define BB_SYSLOGD
|
||||
#define BB_TAIL
|
||||
#define BB_TAR
|
||||
#define BB_TEE
|
||||
#define BB_TOUCH
|
||||
//#define BB_TRUE_FALSE // Supplied by ash
|
||||
#define BB_TRUE_FALSE
|
||||
#define BB_UMOUNT
|
||||
#define BB_UPDATE
|
||||
#define BB_UNAME
|
||||
#define BB_ZCAT
|
||||
//#define BB_GZIP
|
||||
#define BB_GZIP
|
||||
#define BB_GUNZIP
|
||||
// Don't turn BB_UTILITY off. It contains support code
|
||||
// that compiles to 0 if everything else if turned off.
|
||||
#define BB_UTILITY
|
||||
//
|
||||
//
|
||||
//
|
||||
// This is where feature definitions go. Generally speaking,
|
||||
// turning this stuff off makes things a bit smaller (and less
|
||||
// pretty/useful).
|
||||
//
|
||||
//
|
||||
// enable a second console on TTY2 in init
|
||||
#define BB_FEATURE_INIT_SECOND_CONSOLE
|
||||
// enable features that use the /proc filesystem
|
||||
#define BB_FEATURE_USE_PROCFS
|
||||
//Enable init being called as /linuxrc
|
||||
#define BB_FEATURE_LINUXRC
|
||||
// Use termios to manipulate the screen ('more' is prettier with this on)
|
||||
#define BB_FEATURE_USE_TERMIOS
|
||||
// calculate terminal & column widths
|
||||
#define BB_FEATURE_AUTOWIDTH
|
||||
// show username/groupnames (bypasses libc6 NSS)
|
||||
#define BB_FEATURE_LS_USERNAME
|
||||
// show file timestamps
|
||||
#define BB_FEATURE_LS_TIMESTAMPS
|
||||
// enable ls -p and -F
|
||||
#define BB_FEATURE_LS_FILETYPES
|
||||
+2
-2
@@ -1,4 +1,4 @@
|
||||
#!/bin/sh
|
||||
sed -n '/^#define/{s/.*BB_//; s/$/.o/p; }' busybox.def.h | \
|
||||
tr [:upper:] [:lower:]
|
||||
ls -1 `sed -n '/^#define/{s/.*BB_// ; s/$/.c/p; }' busybox.def.h | \
|
||||
tr [:upper:] [:lower:]` 2> /dev/null | sed -e 's/\.c$/\.o/g'
|
||||
|
||||
+4
-12
@@ -1,5 +1,5 @@
|
||||
Name: busybox
|
||||
Version: 0.32
|
||||
Version: 0.39
|
||||
Release: 1
|
||||
Group: System/Utilities
|
||||
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
||||
@@ -7,7 +7,7 @@ Copyright: GPL
|
||||
Packager : Erik Andersen <andersen@lineo.com>
|
||||
Conflicts: fileutils grep shellutils
|
||||
Buildroot: /tmp/%{Name}-%{Version}
|
||||
Source: busybox-0.32.tar.gz
|
||||
Source: %{Name}-%{Version}.tar.gz
|
||||
|
||||
%Description
|
||||
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
|
||||
@@ -18,22 +18,14 @@ is makes an excellent environment for a "rescue" disk or any small or
|
||||
embedded system.
|
||||
|
||||
%Prep
|
||||
%setup -q -n busybox
|
||||
%setup -q -n %{Name}-%{Version}
|
||||
|
||||
%Build
|
||||
make
|
||||
|
||||
%Install
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
mkdir -p $RPM_BUILD_ROOT/bin
|
||||
h=`cat busybox.links`
|
||||
|
||||
for i in $h ; do
|
||||
mkdir -p $RPM_BUILD_ROOT/`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\1/g' `
|
||||
(cd $RPM_BUILD_ROOT/bin ; ln -s busybox `echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' ` );
|
||||
done
|
||||
rm -f $RPM_BUILD_ROOT/bin/busybox
|
||||
install -m 755 busybox $RPM_BUILD_ROOT/bin/busybox
|
||||
make PREFIX=$RPM_BUILD_ROOT install
|
||||
|
||||
%Clean
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
@@ -46,17 +46,14 @@ extern int cat_main(int argc, char **argv)
|
||||
usage ("cat [file ...]\n");
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
while (argc-- > 0) {
|
||||
while (argc-- > 0 && *(argv++) != '\0' && strlen(*argv) ) {
|
||||
file = fopen(*argv, "r");
|
||||
if (file == NULL) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
}
|
||||
print_file( file);
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
exit(TRUE);
|
||||
}
|
||||
+20
-20
@@ -31,23 +31,23 @@ static uid_t uid=-1;
|
||||
static gid_t gid=-1;
|
||||
static int whichApp;
|
||||
static char* invocationName=NULL;
|
||||
static mode_t mode=0644;
|
||||
static char* theMode=NULL;
|
||||
|
||||
|
||||
#define CHGRP_APP 1
|
||||
#define CHOWN_APP 2
|
||||
#define CHMOD_APP 3
|
||||
|
||||
static const char chgrp_usage[] = "[OPTION]... GROUP FILE...\n"
|
||||
static const char chgrp_usage[] = "chgrp [OPTION]... GROUP FILE...\n\n"
|
||||
"Change the group membership of each FILE to GROUP.\n"
|
||||
"\n\tOptions:\n" "\t-R\tchange files and directories recursively\n";
|
||||
static const char chown_usage[] = "[OPTION]... OWNER[.[GROUP] FILE...\n"
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively\n";
|
||||
static const char chown_usage[] = "chown [OPTION]... OWNER[.[GROUP] FILE...\n\n"
|
||||
"Change the owner and/or group of each FILE to OWNER and/or GROUP.\n"
|
||||
"\n\tOptions:\n" "\t-R\tchange files and directories recursively\n";
|
||||
static const char chmod_usage[] = "[-R] MODE[,MODE]... FILE...\n"
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively\n";
|
||||
static const char chmod_usage[] = "chmod [-R] MODE[,MODE]... FILE...\n\n"
|
||||
"Each MODE is one or more of the letters ugoa, one of the symbols +-= and\n"
|
||||
"one or more of the letters rwxst.\n\n"
|
||||
"\t-R\tchange files and directories recursively.\n";
|
||||
"\nOptions:\n\t-R\tchange files and directories recursively.\n";
|
||||
|
||||
|
||||
static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
@@ -61,7 +61,12 @@ static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
}
|
||||
break;
|
||||
case CHMOD_APP:
|
||||
if (chmod(fileName, mode) == 0)
|
||||
/* Parse the specified modes */
|
||||
if ( parse_mode(theMode, &(statbuf->st_mode)) == FALSE ) {
|
||||
fprintf(stderr, "%s: Unknown mode: %s\n", invocationName, theMode);
|
||||
exit( FALSE);
|
||||
}
|
||||
if (chmod(fileName, statbuf->st_mode) == 0)
|
||||
return( TRUE);
|
||||
break;
|
||||
}
|
||||
@@ -73,14 +78,14 @@ int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
{
|
||||
int recursiveFlag=FALSE;
|
||||
char *groupName;
|
||||
const char *appUsage;
|
||||
|
||||
whichApp = (strcmp(*argv, "chown")==0)? CHOWN_APP : (strcmp(*argv, "chmod")==0)? CHMOD_APP : CHGRP_APP;
|
||||
|
||||
if (argc < 2) {
|
||||
fprintf(stderr, "Usage: %s %s", *argv,
|
||||
(whichApp==TRUE)? chown_usage : chgrp_usage);
|
||||
exit( FALSE);
|
||||
}
|
||||
appUsage = (whichApp==CHOWN_APP)? chown_usage : (whichApp==CHMOD_APP)? chmod_usage : chgrp_usage;
|
||||
|
||||
if (argc < 2)
|
||||
usage( appUsage);
|
||||
invocationName=*argv;
|
||||
argc--;
|
||||
argv++;
|
||||
@@ -93,19 +98,14 @@ int chmod_chown_chgrp_main(int argc, char **argv)
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unknown option: %c\n", **argv);
|
||||
exit( FALSE);
|
||||
usage( appUsage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
if ( whichApp == CHMOD_APP ) {
|
||||
/* Find the specified modes */
|
||||
mode = 0;
|
||||
if ( parse_mode(*argv, &mode) == FALSE ) {
|
||||
fprintf(stderr, "%s: Unknown mode: %s\n", invocationName, *argv);
|
||||
exit( FALSE);
|
||||
}
|
||||
theMode=*argv;
|
||||
} else {
|
||||
|
||||
/* Find the selected group */
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
static const char chroot_usage[] = "NEWROOT [COMMAND...]\n"
|
||||
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n\n"
|
||||
"Run COMMAND with root directory set to NEWROOT.\n";
|
||||
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ chvt_main(int argc, char** argv)
|
||||
int fd, num;
|
||||
|
||||
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
|
||||
usage ("chvt </dev/ttyN>\n");
|
||||
usage ("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
|
||||
}
|
||||
fd = get_console_fd("/dev/console");
|
||||
num = atoi(argv[1]);
|
||||
|
||||
@@ -19,7 +19,7 @@ chvt_main(int argc, char** argv)
|
||||
int fd, num;
|
||||
|
||||
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
|
||||
usage ("chvt </dev/ttyN>\n");
|
||||
usage ("chvt N\n\nChange foreground virtual terminal to /dev/ttyN\n");
|
||||
}
|
||||
fd = get_console_fd("/dev/console");
|
||||
num = atoi(argv[1]);
|
||||
|
||||
@@ -17,8 +17,10 @@ int
|
||||
deallocvt_main(int argc, char *argv[]) {
|
||||
int fd, num, i;
|
||||
|
||||
if (argc < 1) /* unlikely */
|
||||
exit(1);
|
||||
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
|
||||
usage ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
|
||||
}
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
fd = get_console_fd("/dev/console");
|
||||
|
||||
+1
-4
@@ -46,17 +46,14 @@ extern int cat_main(int argc, char **argv)
|
||||
usage ("cat [file ...]\n");
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
while (argc-- > 0) {
|
||||
while (argc-- > 0 && *(argv++) != '\0' && strlen(*argv) ) {
|
||||
file = fopen(*argv, "r");
|
||||
if (file == NULL) {
|
||||
perror(*argv);
|
||||
exit(FALSE);
|
||||
}
|
||||
print_file( file);
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
exit(TRUE);
|
||||
}
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
static const char chroot_usage[] = "NEWROOT [COMMAND...]\n"
|
||||
static const char chroot_usage[] = "chroot NEWROOT [COMMAND...]\n\n"
|
||||
"Run COMMAND with root directory set to NEWROOT.\n";
|
||||
|
||||
|
||||
|
||||
+3
-1
@@ -28,7 +28,7 @@
|
||||
#include <dirent.h>
|
||||
|
||||
static const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n"
|
||||
" or: cp [OPTION]... SOURCE... DIRECTORY\n"
|
||||
" or: cp [OPTION]... SOURCE... DIRECTORY\n\n"
|
||||
"Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
|
||||
"\n"
|
||||
"\t-a\tsame as -dpR\n"
|
||||
@@ -54,6 +54,8 @@ static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
strcat(newdestName, "/");
|
||||
if ( skipName != NULL)
|
||||
strcat(newdestName, strstr(fileName, skipName));
|
||||
else
|
||||
strcat(newdestName, srcName);
|
||||
}
|
||||
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
|
||||
}
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@
|
||||
mail commands */
|
||||
|
||||
static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n"
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n\n"
|
||||
"Display the current time in the given FORMAT, or set the system date.\n"
|
||||
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
|
||||
"\t-s\t\tset time described by STRING\n"
|
||||
|
||||
+30
-70
@@ -29,12 +29,18 @@
|
||||
|
||||
|
||||
#include "internal.h"
|
||||
#include <features.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#if (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1)
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
typedef unsigned long long int uintmax_t;
|
||||
#endif
|
||||
|
||||
static const char dd_usage[] =
|
||||
"dd [if=name] [of=name] [bs=n] [count=n]\n"
|
||||
"dd [if=name] [of=name] [bs=n] [count=n]\n\n"
|
||||
"Copy a file, converting and formatting according to options\n\n"
|
||||
"\tif=FILE\tread from FILE instead of stdin\n"
|
||||
"\tof=FILE\twrite to FILE instead of stout\n"
|
||||
@@ -42,77 +48,26 @@ static const char dd_usage[] =
|
||||
"\tcount=n\tcopy only n input blocks\n"
|
||||
//"\tskip=n\tskip n input blocks\n"
|
||||
"\n"
|
||||
"BYTES may be suffixed: by k for x1024, b for x512, and w for x2.\n";
|
||||
"BYTES may be suffixed by w (x2), k (x1024), b (x512), or m (x1024^2).\n";
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Read a number with a possible multiplier.
|
||||
* Returns -1 if the number format is illegal.
|
||||
*/
|
||||
static long getNum (const char *cp)
|
||||
{
|
||||
long value;
|
||||
|
||||
if (!isDecimal (*cp))
|
||||
return -1;
|
||||
|
||||
value = 0;
|
||||
|
||||
while (isDecimal (*cp))
|
||||
value = value * 10 + *cp++ - '0';
|
||||
|
||||
switch (*cp++) {
|
||||
case 'k':
|
||||
value *= 1024;
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
value *= 512;
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
value *= 2;
|
||||
break;
|
||||
|
||||
case '\0':
|
||||
return value;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*cp)
|
||||
return -1;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
extern int dd_main (int argc, char **argv)
|
||||
{
|
||||
const char *inFile;
|
||||
const char *outFile;
|
||||
const char *inFile = NULL;
|
||||
const char *outFile = NULL;
|
||||
char *cp;
|
||||
int inFd;
|
||||
int outFd;
|
||||
int inCc = 0;
|
||||
int outCc;
|
||||
int skipBlocks;
|
||||
int blockSize;
|
||||
long count;
|
||||
long intotal;
|
||||
long outTotal;
|
||||
size_t blockSize = 512;
|
||||
//uintmax_t skipBlocks = 0;
|
||||
uintmax_t count = (uintmax_t)-1;
|
||||
uintmax_t intotal;
|
||||
uintmax_t outTotal;
|
||||
unsigned char *buf;
|
||||
|
||||
inFile = NULL;
|
||||
outFile = NULL;
|
||||
blockSize = 512;
|
||||
skipBlocks = 0;
|
||||
count = 1;
|
||||
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
@@ -125,14 +80,14 @@ extern int dd_main (int argc, char **argv)
|
||||
else if (strncmp("count", *argv, 5) == 0) {
|
||||
count = getNum ((strchr(*argv, '='))+1);
|
||||
if (count <= 0) {
|
||||
fprintf (stderr, "Bad count value %ld\n", count);
|
||||
fprintf (stderr, "Bad count value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
else if (strncmp(*argv, "bs", 2) == 0) {
|
||||
blockSize = getNum ((strchr(*argv, '='))+1);
|
||||
if (blockSize <= 0) {
|
||||
fprintf (stderr, "Bad block size value %d\n", blockSize);
|
||||
fprintf (stderr, "Bad block size value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
@@ -152,8 +107,6 @@ extern int dd_main (int argc, char **argv)
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
if ( inFile == NULL || outFile == NULL)
|
||||
goto usage;
|
||||
|
||||
buf = malloc (blockSize);
|
||||
if (buf == NULL) {
|
||||
@@ -165,7 +118,7 @@ extern int dd_main (int argc, char **argv)
|
||||
outTotal = 0;
|
||||
|
||||
if (inFile == NULL)
|
||||
inFd = STDIN;
|
||||
inFd = fileno(stdin);
|
||||
else
|
||||
inFd = open (inFile, 0);
|
||||
|
||||
@@ -176,7 +129,7 @@ extern int dd_main (int argc, char **argv)
|
||||
}
|
||||
|
||||
if (outFile == NULL)
|
||||
outFd = STDOUT;
|
||||
outFd = fileno(stdout);
|
||||
else
|
||||
outFd = creat (outFile, 0666);
|
||||
|
||||
@@ -188,11 +141,17 @@ extern int dd_main (int argc, char **argv)
|
||||
}
|
||||
|
||||
//lseek(inFd, skipBlocks*blockSize, SEEK_SET);
|
||||
//
|
||||
//TODO: Convert to using fullRead & fullWrite
|
||||
// from utilitity.c
|
||||
// -Erik
|
||||
while (outTotal < count * blockSize) {
|
||||
inCc = read (inFd, buf, blockSize);
|
||||
if (inCc < 0) {
|
||||
perror (inFile);
|
||||
goto cleanup;
|
||||
} else if (inCc == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
intotal += inCc;
|
||||
cp = buf;
|
||||
@@ -204,6 +163,8 @@ extern int dd_main (int argc, char **argv)
|
||||
if (outCc < 0) {
|
||||
perror (outFile);
|
||||
goto cleanup;
|
||||
} else if (outCc == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
inCc -= outCc;
|
||||
@@ -220,15 +181,14 @@ extern int dd_main (int argc, char **argv)
|
||||
close (outFd);
|
||||
free (buf);
|
||||
|
||||
printf ("%ld+%d records in\n", intotal / blockSize,
|
||||
printf ("%ld+%d records in\n", (long)(intotal / blockSize),
|
||||
(intotal % blockSize) != 0);
|
||||
printf ("%ld+%d records out\n", outTotal / blockSize,
|
||||
printf ("%ld+%d records out\n", (long)(outTotal / blockSize),
|
||||
(outTotal % blockSize) != 0);
|
||||
exit( TRUE);
|
||||
usage:
|
||||
|
||||
fprintf (stderr, "%s", dd_usage);
|
||||
exit( FALSE);
|
||||
usage( dd_usage);
|
||||
}
|
||||
|
||||
|
||||
+7
-9
@@ -42,7 +42,7 @@ static int df(char *device, const char *mountPoint)
|
||||
|
||||
if (statfs(mountPoint, &s) != 0) {
|
||||
perror(mountPoint);
|
||||
return 1;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (s.f_blocks > 0) {
|
||||
@@ -64,7 +64,7 @@ static int df(char *device, const char *mountPoint)
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
extern int df_main(int argc, char **argv)
|
||||
@@ -83,15 +83,15 @@ extern int df_main(int argc, char **argv)
|
||||
if ((mountEntry = findMountPoint(argv[1], mtab_file)) ==
|
||||
0) {
|
||||
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
|
||||
return 1;
|
||||
exit( FALSE);
|
||||
}
|
||||
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
if (status != 0)
|
||||
return status;
|
||||
exit( status);
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
return 0;
|
||||
exit( TRUE);
|
||||
} else {
|
||||
FILE *mountTable;
|
||||
struct mntent *mountEntry;
|
||||
@@ -103,12 +103,10 @@ extern int df_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
while ((mountEntry = getmntent(mountTable))) {
|
||||
int status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
if (status)
|
||||
return status;
|
||||
df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
}
|
||||
endmntent(mountTable);
|
||||
}
|
||||
|
||||
return 0;
|
||||
exit( TRUE);
|
||||
}
|
||||
+121
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Mini du implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* 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 "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#if 0
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
static const char du_usage[] =
|
||||
"Usage: du [OPTION]... [FILE]...\n";
|
||||
|
||||
typedef void (Display)(size_t, char *);
|
||||
|
||||
static void
|
||||
print(size_t size, char *filename)
|
||||
{
|
||||
fprintf(stdout, "%-7d %s\n", (size >> 1), filename);
|
||||
}
|
||||
|
||||
/* tiny recursive du */
|
||||
static size_t
|
||||
du(char *filename)
|
||||
{
|
||||
struct stat statbuf;
|
||||
size_t sum;
|
||||
|
||||
if ((lstat(filename, &statbuf)) != 0) {
|
||||
fprintf(stdout, "du: %s: %s\n", filename, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
sum = statbuf.st_blocks;
|
||||
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
|
||||
dir = opendir(filename);
|
||||
if (!dir) { return 0; }
|
||||
while ((entry = readdir(dir))) {
|
||||
char newfile[512];
|
||||
char *name = entry->d_name;
|
||||
|
||||
if ( (strcmp(name, "..") == 0)
|
||||
|| (strcmp(name, ".") == 0))
|
||||
{ continue; }
|
||||
|
||||
sprintf(newfile, "%s/%s", filename, name);
|
||||
sum += du(newfile);
|
||||
}
|
||||
closedir(dir);
|
||||
print(sum, filename);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
int
|
||||
du_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char opt;
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 's':
|
||||
break;
|
||||
case 'h':
|
||||
usage(du_usage);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "du: invalid option -- %c\n", opt);
|
||||
usage(du_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* go through remaining args (if any) */
|
||||
if (i >= argc) {
|
||||
du(".");
|
||||
} else {
|
||||
int sum;
|
||||
for ( ; i < argc; i++) {
|
||||
sum = du(argv[i]) >> 1;
|
||||
if (sum) printf("%-7d %s\n", sum, argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: du.c,v 1.5 1999/12/10 15:23:47 beppu Exp $ */
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Mini head implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* 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 "internal.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
const char head_usage[] =
|
||||
"Usage: head [FILE]...\n\n"
|
||||
"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";
|
||||
|
||||
int
|
||||
head(int len, FILE *src)
|
||||
{
|
||||
int i;
|
||||
char buffer[1024];
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
fgets(buffer, 1024, src);
|
||||
if (feof(src)) { break; }
|
||||
fputs(buffer, stdout);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* BusyBoxed head(1) */
|
||||
int
|
||||
head_main(int argc, char **argv)
|
||||
{
|
||||
int i = 1;
|
||||
char opt;
|
||||
int len = 10;
|
||||
|
||||
/* 1st option is potentially special */
|
||||
if ((argv[1][0] == '-') && isDecimal(argv[1][1])) {
|
||||
int tmplen = atoi(&argv[1][1]);
|
||||
if (tmplen) { len = tmplen; }
|
||||
i = 2;
|
||||
}
|
||||
|
||||
/* parse argv[] */
|
||||
for ( ; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case '-':
|
||||
case 'h':
|
||||
usage(head_usage);
|
||||
default:
|
||||
fprintf(stderr, "head: invalid option -- %c\n", opt);
|
||||
usage(head_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* get rest of argv[] or stdin if nothing's left */
|
||||
if (i >= argc) {
|
||||
head(len, stdin);
|
||||
|
||||
} else {
|
||||
int need_headers = ((argc - i) > 1);
|
||||
for ( ; i < argc; i++) {
|
||||
FILE *src;
|
||||
src = fopen(argv[i], "r");
|
||||
if (!src) {
|
||||
fprintf(stderr,"head: %s: %s\n", argv[i], strerror(errno));
|
||||
} else {
|
||||
/* emulating GNU behaviour */
|
||||
if (need_headers) {
|
||||
fprintf(stdout, "==> %s <==\n", argv[i]);
|
||||
}
|
||||
head(len, src);
|
||||
if (i < argc - 1) {
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: head.c,v 1.2 1999/12/10 08:29:20 andersen Exp $ */
|
||||
+3
-3
@@ -27,9 +27,9 @@
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n"
|
||||
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n"
|
||||
"\nOptions:\n"
|
||||
static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
|
||||
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
|
||||
"Options:\n"
|
||||
"\t-s\tmake symbolic links instead of hard links\n"
|
||||
"\t-f\tremove existing destination files\n";
|
||||
|
||||
|
||||
+54
-87
@@ -40,11 +40,6 @@
|
||||
* 1. requires lstat (BSD) - how do you do it without?
|
||||
*/
|
||||
|
||||
//#define FEATURE_USERNAME /* show username/groupnames (libc6 uses NSS) */
|
||||
#define FEATURE_TIMESTAMPS /* show file timestamps */
|
||||
#define FEATURE_AUTOWIDTH /* calculate terminal & column widths */
|
||||
#define FEATURE_FILETYPECHAR /* enable -p and -F */
|
||||
|
||||
#define TERMINAL_WIDTH 80 /* use 79 if your terminal has linefold bug */
|
||||
#define COLUMN_WIDTH 14 /* default if AUTOWIDTH not defined */
|
||||
#define COLUMN_GAP 2 /* includes the file type char, if present */
|
||||
@@ -64,17 +59,13 @@
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#ifdef FEATURE_USERNAME
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#endif
|
||||
#ifdef FEATURE_TIMESTAMPS
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
|
||||
#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
#define APPCHAR(mode) ("\0|\0\0/\0\0\0\0\0@\0=\0\0\0" [TYPEINDEX(mode)])
|
||||
#endif
|
||||
|
||||
@@ -83,27 +74,6 @@
|
||||
#define MINOR(dev) ((dev)&0xff)
|
||||
#endif
|
||||
|
||||
#define MODE1 "rwxrwxrwx"
|
||||
#define MODE0 "---------"
|
||||
#define SMODE1 "..s..s..t"
|
||||
#define SMODE0 "..S..S..T"
|
||||
|
||||
/* The 9 mode bits to test */
|
||||
|
||||
static const mode_t MBIT[] = {
|
||||
S_IRUSR, S_IWUSR, S_IXUSR,
|
||||
S_IRGRP, S_IWGRP, S_IXGRP,
|
||||
S_IROTH, S_IWOTH, S_IXOTH
|
||||
};
|
||||
|
||||
/* The special bits. If set, display SMODE0/1 instead of MODE0/1 */
|
||||
|
||||
static const mode_t SBIT[] = {
|
||||
0, 0, S_ISUID,
|
||||
0, 0, S_ISGID,
|
||||
0, 0, S_ISVTX
|
||||
};
|
||||
|
||||
#define FMT_AUTO 0
|
||||
#define FMT_LONG 1 /* one record per line, extended info */
|
||||
#define FMT_SINGLE 2 /* one record per line */
|
||||
@@ -128,14 +98,14 @@ static unsigned char display_fmt = FMT_AUTO;
|
||||
static unsigned short opts = 0;
|
||||
static unsigned short column = 0;
|
||||
|
||||
#ifdef FEATURE_AUTOWIDTH
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
static unsigned short terminal_width = 0, column_width = 0;
|
||||
#else
|
||||
#define terminal_width TERMINAL_WIDTH
|
||||
#define column_width COLUMN_WIDTH
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_TIMESTAMPS
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
static unsigned char time_fmt = TIME_MOD;
|
||||
#endif
|
||||
|
||||
@@ -188,7 +158,7 @@ static void tab(short col)
|
||||
#undef nspaces
|
||||
}
|
||||
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
static char append_char(mode_t mode)
|
||||
{
|
||||
if (!(opts & DISP_FTYPE))
|
||||
@@ -206,55 +176,52 @@ static char append_char(mode_t mode)
|
||||
**
|
||||
**/
|
||||
|
||||
static void list_single(const char *name, struct stat *info)
|
||||
static void list_single(const char *name, struct stat *info, const char *fullname)
|
||||
{
|
||||
char scratch[PATH_MAX];
|
||||
short len = strlen(name);
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
char append = append_char(info->st_mode);
|
||||
#endif
|
||||
|
||||
if (display_fmt == FMT_LONG) {
|
||||
mode_t mode = info->st_mode;
|
||||
int i;
|
||||
|
||||
scratch[0] = TYPECHAR(mode);
|
||||
for (i=0; i<9; i++)
|
||||
if (mode & SBIT[i])
|
||||
scratch[i+1] = (mode & MBIT[i])
|
||||
? SMODE1[i]
|
||||
: SMODE0[i];
|
||||
else
|
||||
scratch[i+1] = (mode & MBIT[i])
|
||||
? MODE1[i]
|
||||
: MODE0[i];
|
||||
newline();
|
||||
wr(scratch, 10);
|
||||
wr(modeString(mode), 10);
|
||||
column=10;
|
||||
writenum((long)info->st_nlink,(short)4);
|
||||
writenum((long)info->st_nlink,(short)5);
|
||||
fputs(" ", stdout);
|
||||
#ifdef FEATURE_USERNAME
|
||||
#ifdef BB_FEATURE_LS_USERNAME
|
||||
if (!(opts & DISP_NUMERIC)) {
|
||||
struct passwd *pw = getpwuid(info->st_uid);
|
||||
if (pw)
|
||||
fputs(pw->pw_name, stdout);
|
||||
else
|
||||
writenum((long)info->st_uid,(short)0);
|
||||
scratch[0]='\0';
|
||||
my_getpwuid( scratch, info->st_uid);
|
||||
scratch[8]='\0';
|
||||
if (*scratch)
|
||||
wr(scratch,8);
|
||||
else {
|
||||
writenum((long) info->st_uid,(short)8);
|
||||
fputs(" ", stdout);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
writenum((long)info->st_uid,(short)0);
|
||||
tab(24);
|
||||
#ifdef FEATURE_USERNAME
|
||||
{
|
||||
writenum((long) info->st_uid,(short)8);
|
||||
fputs(" ", stdout);
|
||||
}
|
||||
tab(16);
|
||||
#ifdef BB_FEATURE_LS_USERNAME
|
||||
if (!(opts & DISP_NUMERIC)) {
|
||||
struct group *gr = getgrgid(info->st_gid);
|
||||
if (gr)
|
||||
fputs(gr->gr_name, stdout);
|
||||
else
|
||||
writenum((long)info->st_gid,(short)0);
|
||||
scratch[0]='\0';
|
||||
my_getgrgid( scratch, info->st_gid);
|
||||
scratch[8]='\0';
|
||||
if (*scratch)
|
||||
wr(scratch,8);
|
||||
else
|
||||
writenum((long) info->st_gid,(short)8);
|
||||
} else
|
||||
#endif
|
||||
writenum((long)info->st_gid,(short)0);
|
||||
tab(33);
|
||||
writenum((long) info->st_gid,(short)8);
|
||||
tab(17);
|
||||
if (S_ISBLK(mode) || S_ISCHR(mode)) {
|
||||
writenum((long)MAJOR(info->st_rdev),(short)3);
|
||||
fputs(", ", stdout);
|
||||
@@ -263,7 +230,7 @@ static void list_single(const char *name, struct stat *info)
|
||||
else
|
||||
writenum((long)info->st_size,(short)8);
|
||||
fputs(" ", stdout);
|
||||
#ifdef FEATURE_TIMESTAMPS
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
{
|
||||
time_t cal;
|
||||
char *string;
|
||||
@@ -297,12 +264,12 @@ static void list_single(const char *name, struct stat *info)
|
||||
wr(name, len);
|
||||
if (S_ISLNK(mode)) {
|
||||
wr(" -> ", 4);
|
||||
len = readlink(name, scratch, sizeof scratch);
|
||||
len = readlink(fullname, scratch, sizeof scratch);
|
||||
if (len > 0) fwrite(scratch, 1, len, stdout);
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
/* show type of destination */
|
||||
if (opts & DISP_FTYPE) {
|
||||
if (!stat(name, info)) {
|
||||
if (!stat(fullname, info)) {
|
||||
append = append_char(info->st_mode);
|
||||
if (append)
|
||||
fputc(append, stdout);
|
||||
@@ -310,7 +277,7 @@ static void list_single(const char *name, struct stat *info)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
else if (append)
|
||||
wr(&append, 1);
|
||||
#endif
|
||||
@@ -324,7 +291,7 @@ static void list_single(const char *name, struct stat *info)
|
||||
newline();
|
||||
else {
|
||||
if (nexttab + column_width > terminal_width
|
||||
#ifndef FEATURE_AUTOWIDTH
|
||||
#ifndef BB_FEATURE_AUTOWIDTH
|
||||
|| nexttab + len >= terminal_width
|
||||
#endif
|
||||
)
|
||||
@@ -333,7 +300,7 @@ static void list_single(const char *name, struct stat *info)
|
||||
tab(nexttab);
|
||||
}
|
||||
/* work out where next column starts */
|
||||
#ifdef FEATURE_AUTOWIDTH
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
/* we know the calculated width is big enough */
|
||||
nexttab = column + column_width + COLUMN_GAP;
|
||||
#else
|
||||
@@ -346,7 +313,7 @@ static void list_single(const char *name, struct stat *info)
|
||||
/* now write the data */
|
||||
wr(name, len);
|
||||
column = column + len;
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
if (append)
|
||||
wr(&append, 1), column++;
|
||||
#endif
|
||||
@@ -372,7 +339,7 @@ static int list_item(const char *name)
|
||||
|
||||
if (!S_ISDIR(info.st_mode) ||
|
||||
(opts & DIR_NOLIST)) {
|
||||
list_single(name, &info);
|
||||
list_single(name, &info, name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -387,7 +354,7 @@ static int list_item(const char *name)
|
||||
|
||||
dir = opendir(name);
|
||||
if (!dir) goto listerr;
|
||||
#ifdef FEATURE_AUTOWIDTH
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
column_width = 0;
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
short w = strlen(entry->d_name);
|
||||
@@ -424,7 +391,7 @@ static int list_item(const char *name)
|
||||
strcpy(fnend, entry->d_name);
|
||||
if (lstat(fullname, &info))
|
||||
goto direrr; /* (shouldn't fail) */
|
||||
list_single(entry->d_name, &info);
|
||||
list_single(entry->d_name, &info, fullname);
|
||||
}
|
||||
closedir(dir);
|
||||
return 0;
|
||||
@@ -438,22 +405,22 @@ listerr:
|
||||
}
|
||||
|
||||
static const char ls_usage[] = "ls [-1a"
|
||||
#ifdef FEATURE_TIMESTAMPS
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"c"
|
||||
#endif
|
||||
"d"
|
||||
#ifdef FEATURE_TIMESTAMPS
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"e"
|
||||
#endif
|
||||
"ln"
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
"p"
|
||||
#endif
|
||||
#ifdef FEATURE_TIMESTAMPS
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"u"
|
||||
#endif
|
||||
"xAC"
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
"F"
|
||||
#endif
|
||||
#ifdef FEATURE_RECURSIVE
|
||||
@@ -486,7 +453,7 @@ ls_main(int argc, char * * argv)
|
||||
case '1': display_fmt = FMT_SINGLE; break;
|
||||
case 'x': display_fmt = FMT_ROWS; break;
|
||||
case 'C': display_fmt = FMT_COLUMNS; break;
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
case 'p': opts |= DISP_FTYPE; break;
|
||||
case 'F': opts |= DISP_FTYPE|DISP_EXEC; break;
|
||||
#endif
|
||||
@@ -497,7 +464,7 @@ ls_main(int argc, char * * argv)
|
||||
#ifdef FEATURE_RECURSIVE
|
||||
case 'R': opts |= DIR_RECURSE; break;
|
||||
#endif
|
||||
#ifdef FEATURE_TIMESTAMPS
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
case 'u': time_fmt = TIME_ACCESS; break;
|
||||
case 'c': time_fmt = TIME_CHANGE; break;
|
||||
case 'e': opts |= DISP_FULLTIME; break;
|
||||
@@ -510,10 +477,10 @@ ls_main(int argc, char * * argv)
|
||||
|
||||
/* choose a display format */
|
||||
if (display_fmt == FMT_AUTO)
|
||||
display_fmt = isatty(STDOUT_FILENO) ? FMT_COLUMNS : FMT_SINGLE;
|
||||
display_fmt = isatty(fileno(stdout)) ? FMT_COLUMNS : FMT_SINGLE;
|
||||
if (argi < argc - 1)
|
||||
opts |= DISP_DIRNAME; /* 2 or more items? label directories */
|
||||
#ifdef FEATURE_AUTOWIDTH
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
/* could add a -w option and/or TIOCGWINSZ call */
|
||||
if (terminal_width < 1) terminal_width = TERMINAL_WIDTH;
|
||||
|
||||
|
||||
+16
-10
@@ -26,14 +26,15 @@
|
||||
#include <errno.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
static const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n"
|
||||
static const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n\n"
|
||||
"Create the DIRECTORY(ies), if they do not already exist\n\n"
|
||||
"-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
|
||||
"-p\tno error if existing, make parent directories as needed\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\n";
|
||||
|
||||
|
||||
static int parentFlag = FALSE;
|
||||
static mode_t mode = 777;
|
||||
static mode_t mode = 0777;
|
||||
|
||||
|
||||
extern int mkdir_main(int argc, char **argv)
|
||||
@@ -79,16 +80,21 @@ extern int mkdir_main(int argc, char **argv)
|
||||
while (argc > 0) {
|
||||
int status;
|
||||
struct stat statBuf;
|
||||
status=stat(*argv, &statBuf);
|
||||
char buf[NAME_MAX];
|
||||
|
||||
strcpy (buf, *argv);
|
||||
status=stat(buf, &statBuf);
|
||||
if (status != -1 && status != ENOENT ) {
|
||||
fprintf(stderr, "%s: File exists\n", *argv);
|
||||
fprintf(stderr, "%s: File exists\n", buf);
|
||||
exit( FALSE);
|
||||
}
|
||||
if (parentFlag == TRUE)
|
||||
createPath(*argv, mode);
|
||||
if (parentFlag == TRUE) {
|
||||
strcat( buf, "/");
|
||||
createPath(buf, mode);
|
||||
}
|
||||
else {
|
||||
if (mkdir (*argv, mode) != 0) {
|
||||
perror(*argv);
|
||||
if (mkdir (buf, mode) != 0) {
|
||||
perror(buf);
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -27,9 +27,9 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static const char mknod_usage[] = "mknod file b|c|u|p major minor\n"
|
||||
"\tMake special files.\n"
|
||||
"\n"
|
||||
static const char mknod_usage[] = "mknod [OPTION]... NAME TYPE MAJOR MINOR\n\n"
|
||||
"Make block or character special files.\n\n"
|
||||
"Options:\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";
|
||||
|
||||
+7
-2
@@ -29,7 +29,7 @@
|
||||
|
||||
|
||||
static const char mv_usage[] = "mv SOURCE DEST\n"
|
||||
" or: mv SOURCE... DIRECTORY\n"
|
||||
" or: mv SOURCE... DIRECTORY\n\n"
|
||||
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n";
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ extern int mv_main(int argc, char **argv)
|
||||
fprintf(stderr, "%s: not a directory\n", destName);
|
||||
exit (FALSE);
|
||||
}
|
||||
|
||||
|
||||
while (argc-- > 1) {
|
||||
srcName = *(argv++);
|
||||
skipName = strrchr(srcName, '/');
|
||||
@@ -67,6 +67,11 @@ extern int mv_main(int argc, char **argv)
|
||||
strcat(newdestName, "/");
|
||||
if ( skipName != NULL)
|
||||
strcat(newdestName, strstr(srcName, skipName));
|
||||
else
|
||||
strcat(newdestName, srcName);
|
||||
fprintf(stderr, "srcName='%s'\n", srcName);
|
||||
fprintf(stderr, "skipName='%s'\n", skipName);
|
||||
fprintf(stderr, "newdestName='%s'\n", newdestName);
|
||||
}
|
||||
if (copyFile(srcName, newdestName, FALSE, FALSE) == FALSE) {
|
||||
exit( FALSE);
|
||||
|
||||
+15
-6
@@ -26,11 +26,13 @@
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char* rm_usage = "rm [OPTION]... FILE...\n"
|
||||
static const char* rm_usage = "rm [OPTION]... FILE...\n\n"
|
||||
"Remove (unlink) the FILE(s).\n\n"
|
||||
"\t-f\tremove existing destinations, never prompt\n"
|
||||
"\t-r\tremove the contents of directories recursively\n";
|
||||
"Options:\n"
|
||||
"\t-f\t\tremove existing destinations, never prompt\n"
|
||||
"\t-r or -R\tremove the contents of directories recursively\n";
|
||||
|
||||
|
||||
static int recursiveFlag = FALSE;
|
||||
@@ -58,6 +60,7 @@ static int dirAction(const char *fileName, struct stat* statbuf)
|
||||
|
||||
extern int rm_main(int argc, char **argv)
|
||||
{
|
||||
struct stat statbuf;
|
||||
|
||||
if (argc < 2) {
|
||||
usage( rm_usage);
|
||||
@@ -69,6 +72,7 @@ extern int rm_main(int argc, char **argv)
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'R':
|
||||
case 'r':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
@@ -84,9 +88,14 @@ extern int rm_main(int argc, char **argv)
|
||||
|
||||
while (argc-- > 0) {
|
||||
srcName = *(argv++);
|
||||
if (recursiveAction( srcName, recursiveFlag, TRUE, TRUE,
|
||||
fileAction, dirAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
if (forceFlag == TRUE && lstat(srcName, &statbuf) != 0 && errno == ENOENT) {
|
||||
/* do not reports errors for non-existent files if -f, just skip them */
|
||||
}
|
||||
else {
|
||||
if (recursiveAction( srcName, recursiveFlag, FALSE,
|
||||
TRUE, fileAction, dirAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@
|
||||
extern int rmdir_main(int argc, char **argv)
|
||||
{
|
||||
if ( argc==1 || **(argv+1) == '-' ) {
|
||||
usage( "rmdir [OPTION]... DIRECTORY...\nRemove the DIRECTORY(ies), if they are empty.");
|
||||
usage( "rmdir [OPTION]... DIRECTORY...\n\nRemove the DIRECTORY(ies), if they are empty.\n");
|
||||
}
|
||||
|
||||
while (--argc > 0) {
|
||||
|
||||
+2
-2
@@ -23,8 +23,8 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
const char sleep_usage[] = " NUMBER\n"
|
||||
"Pause for NUMBER seconds.\n";
|
||||
const char sleep_usage[] = "sleep N\n\n"
|
||||
"Pause for N seconds.\n";
|
||||
|
||||
extern int
|
||||
sleep_main(int argc, char * * argv)
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@ extern int
|
||||
sync_main(int argc, char * * argv)
|
||||
{
|
||||
if ( argc>1 && **(argv+1) == '-' ) {
|
||||
usage( "sync\nWrite all buffered filesystem blocks to disk.\n");
|
||||
usage( "sync\n\nWrite all buffered filesystem blocks to disk.\n");
|
||||
}
|
||||
exit( sync());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,909 @@
|
||||
/* tail -- output the last part of file(s)
|
||||
Copyright (C) 89, 90, 91, 95, 1996 Free Software Foundation, Inc.
|
||||
|
||||
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, 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.
|
||||
|
||||
Original version by Paul Rubin <phr@ocf.berkeley.edu>.
|
||||
Extensions by David MacKenzie <djm@gnu.ai.mit.edu>.
|
||||
tail -f for multiple files by Ian Lance Taylor <ian@airs.com>.
|
||||
|
||||
Rewrote the option parser, removed locales support,
|
||||
and generally busyboxed, Erik Andersen <andersen@lineo.com>
|
||||
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
|
||||
/* Disable assertions. Some systems have broken assert macros. */
|
||||
#define NDEBUG 1
|
||||
|
||||
|
||||
static void error(int i, int errnum, char* fmt, ...)
|
||||
{
|
||||
va_list arguments;
|
||||
|
||||
va_start(arguments, fmt);
|
||||
vfprintf(stderr, fmt, arguments);
|
||||
fprintf(stderr, "\n%s\n", strerror( errnum));
|
||||
va_end(arguments);
|
||||
exit(i);
|
||||
}
|
||||
|
||||
|
||||
#define XWRITE(fd, buffer, n_bytes) \
|
||||
do \
|
||||
{ \
|
||||
assert ((fd) == 1); \
|
||||
assert ((n_bytes) >= 0); \
|
||||
if (n_bytes > 0 && fwrite ((buffer), 1, (n_bytes), stdout) == 0) \
|
||||
error (EXIT_FAILURE, errno, "write error"); \
|
||||
} \
|
||||
while (0)
|
||||
|
||||
/* Number of items to tail. */
|
||||
#define DEFAULT_N_LINES 10
|
||||
|
||||
/* Size of atomic reads. */
|
||||
#ifndef BUFSIZ
|
||||
#define BUFSIZ (512 * 8)
|
||||
#endif
|
||||
|
||||
/* If nonzero, interpret the numeric argument as the number of lines.
|
||||
Otherwise, interpret it as the number of bytes. */
|
||||
static int count_lines;
|
||||
|
||||
/* If nonzero, read from the end of one file until killed. */
|
||||
static int forever;
|
||||
|
||||
/* If nonzero, read from the end of multiple files until killed. */
|
||||
static int forever_multiple;
|
||||
|
||||
/* Array of file descriptors if forever_multiple is 1. */
|
||||
static int *file_descs;
|
||||
|
||||
/* Array of file sizes if forever_multiple is 1. */
|
||||
static off_t *file_sizes;
|
||||
|
||||
/* If nonzero, count from start of file instead of end. */
|
||||
static int from_start;
|
||||
|
||||
/* If nonzero, print filename headers. */
|
||||
static int print_headers;
|
||||
|
||||
/* When to print the filename banners. */
|
||||
enum header_mode
|
||||
{
|
||||
multiple_files, always, never
|
||||
};
|
||||
|
||||
char *xmalloc ();
|
||||
|
||||
/* The name this program was run with. */
|
||||
char *program_name;
|
||||
|
||||
/* Nonzero if we have ever read standard input. */
|
||||
static int have_read_stdin;
|
||||
|
||||
|
||||
static const char tail_usage[] =
|
||||
"tail [OPTION]... [FILE]...\n\
|
||||
\n\
|
||||
Print last 10 lines of each FILE to standard output.\n\
|
||||
With more than one FILE, precede each with a header giving the file name.\n\
|
||||
With no FILE, or when FILE is -, read standard input.\n\
|
||||
\n\
|
||||
-c=N[kbm] output the last N bytes\n\
|
||||
-f output appended data as the file grows\n\
|
||||
-n=N output the last N lines, instead of last 10\n\
|
||||
-q never output headers giving file names\n\
|
||||
-v always output headers giving file names\n\
|
||||
--help display this help and exit\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).\n\n";
|
||||
|
||||
static void
|
||||
write_header (const char *filename, const char *comment)
|
||||
{
|
||||
static int first_file = 1;
|
||||
|
||||
printf ("%s==> %s%s%s <==\n", (first_file ? "" : "\n"), filename,
|
||||
(comment ? ": " : ""),
|
||||
(comment ? comment : ""));
|
||||
first_file = 0;
|
||||
}
|
||||
|
||||
/* Print the last N_LINES lines from the end of file FD.
|
||||
Go backward through the file, reading `BUFSIZ' bytes at a time (except
|
||||
probably the first), until we hit the start of the file or have
|
||||
read NUMBER newlines.
|
||||
POS starts out as the length of the file (the offset of the last
|
||||
byte of the file + 1).
|
||||
Return 0 if successful, 1 if an error occurred. */
|
||||
|
||||
static int
|
||||
file_lines (const char *filename, int fd, long int n_lines, off_t pos)
|
||||
{
|
||||
char buffer[BUFSIZ];
|
||||
int bytes_read;
|
||||
int i; /* Index into `buffer' for scanning. */
|
||||
|
||||
if (n_lines == 0)
|
||||
return 0;
|
||||
|
||||
/* Set `bytes_read' to the size of the last, probably partial, buffer;
|
||||
0 < `bytes_read' <= `BUFSIZ'. */
|
||||
bytes_read = pos % BUFSIZ;
|
||||
if (bytes_read == 0)
|
||||
bytes_read = BUFSIZ;
|
||||
/* Make `pos' a multiple of `BUFSIZ' (0 if the file is short), so that all
|
||||
reads will be on block boundaries, which might increase efficiency. */
|
||||
pos -= bytes_read;
|
||||
lseek (fd, pos, SEEK_SET);
|
||||
bytes_read = fullRead (fd, buffer, bytes_read);
|
||||
if (bytes_read == -1)
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Count the incomplete line on files that don't end with a newline. */
|
||||
if (bytes_read && buffer[bytes_read - 1] != '\n')
|
||||
--n_lines;
|
||||
|
||||
do
|
||||
{
|
||||
/* Scan backward, counting the newlines in this bufferfull. */
|
||||
for (i = bytes_read - 1; i >= 0; i--)
|
||||
{
|
||||
/* Have we counted the requested number of newlines yet? */
|
||||
if (buffer[i] == '\n' && n_lines-- == 0)
|
||||
{
|
||||
/* If this newline wasn't the last character in the buffer,
|
||||
print the text after it. */
|
||||
if (i != bytes_read - 1)
|
||||
XWRITE (STDOUT_FILENO, &buffer[i + 1], bytes_read - (i + 1));
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
/* Not enough newlines in that bufferfull. */
|
||||
if (pos == 0)
|
||||
{
|
||||
/* Not enough lines in the file; print the entire file. */
|
||||
lseek (fd, (off_t) 0, SEEK_SET);
|
||||
return 0;
|
||||
}
|
||||
pos -= BUFSIZ;
|
||||
lseek (fd, pos, SEEK_SET);
|
||||
}
|
||||
while ((bytes_read = fullRead (fd, buffer, BUFSIZ)) > 0);
|
||||
if (bytes_read == -1)
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Print the last N_LINES lines from the end of the standard input,
|
||||
open for reading as pipe FD.
|
||||
Buffer the text as a linked list of LBUFFERs, adding them as needed.
|
||||
Return 0 if successful, 1 if an error occured. */
|
||||
|
||||
static int
|
||||
pipe_lines (const char *filename, int fd, long int n_lines)
|
||||
{
|
||||
struct linebuffer
|
||||
{
|
||||
int nbytes, nlines;
|
||||
char buffer[BUFSIZ];
|
||||
struct linebuffer *next;
|
||||
};
|
||||
typedef struct linebuffer LBUFFER;
|
||||
LBUFFER *first, *last, *tmp;
|
||||
int i; /* Index into buffers. */
|
||||
int total_lines = 0; /* Total number of newlines in all buffers. */
|
||||
int errors = 0;
|
||||
|
||||
first = last = (LBUFFER *) xmalloc (sizeof (LBUFFER));
|
||||
first->nbytes = first->nlines = 0;
|
||||
first->next = NULL;
|
||||
tmp = (LBUFFER *) xmalloc (sizeof (LBUFFER));
|
||||
|
||||
/* Input is always read into a fresh buffer. */
|
||||
while ((tmp->nbytes = fullRead (fd, tmp->buffer, BUFSIZ)) > 0)
|
||||
{
|
||||
tmp->nlines = 0;
|
||||
tmp->next = NULL;
|
||||
|
||||
/* Count the number of newlines just read. */
|
||||
for (i = 0; i < tmp->nbytes; i++)
|
||||
if (tmp->buffer[i] == '\n')
|
||||
++tmp->nlines;
|
||||
total_lines += tmp->nlines;
|
||||
|
||||
/* If there is enough room in the last buffer read, just append the new
|
||||
one to it. This is because when reading from a pipe, `nbytes' can
|
||||
often be very small. */
|
||||
if (tmp->nbytes + last->nbytes < BUFSIZ)
|
||||
{
|
||||
memcpy (&last->buffer[last->nbytes], tmp->buffer, tmp->nbytes);
|
||||
last->nbytes += tmp->nbytes;
|
||||
last->nlines += tmp->nlines;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If there's not enough room, link the new buffer onto the end of
|
||||
the list, then either free up the oldest buffer for the next
|
||||
read if that would leave enough lines, or else malloc a new one.
|
||||
Some compaction mechanism is possible but probably not
|
||||
worthwhile. */
|
||||
last = last->next = tmp;
|
||||
if (total_lines - first->nlines > n_lines)
|
||||
{
|
||||
tmp = first;
|
||||
total_lines -= first->nlines;
|
||||
first = first->next;
|
||||
}
|
||||
else
|
||||
tmp = (LBUFFER *) xmalloc (sizeof (LBUFFER));
|
||||
}
|
||||
}
|
||||
if (tmp->nbytes == -1)
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
errors = 1;
|
||||
free ((char *) tmp);
|
||||
goto free_lbuffers;
|
||||
}
|
||||
|
||||
free ((char *) tmp);
|
||||
|
||||
/* This prevents a core dump when the pipe contains no newlines. */
|
||||
if (n_lines == 0)
|
||||
goto free_lbuffers;
|
||||
|
||||
/* Count the incomplete line on files that don't end with a newline. */
|
||||
if (last->buffer[last->nbytes - 1] != '\n')
|
||||
{
|
||||
++last->nlines;
|
||||
++total_lines;
|
||||
}
|
||||
|
||||
/* Run through the list, printing lines. First, skip over unneeded
|
||||
buffers. */
|
||||
for (tmp = first; total_lines - tmp->nlines > n_lines; tmp = tmp->next)
|
||||
total_lines -= tmp->nlines;
|
||||
|
||||
/* Find the correct beginning, then print the rest of the file. */
|
||||
if (total_lines > n_lines)
|
||||
{
|
||||
char *cp;
|
||||
|
||||
/* Skip `total_lines' - `n_lines' newlines. We made sure that
|
||||
`total_lines' - `n_lines' <= `tmp->nlines'. */
|
||||
cp = tmp->buffer;
|
||||
for (i = total_lines - n_lines; i; --i)
|
||||
while (*cp++ != '\n')
|
||||
/* Do nothing. */ ;
|
||||
i = cp - tmp->buffer;
|
||||
}
|
||||
else
|
||||
i = 0;
|
||||
XWRITE (STDOUT_FILENO, &tmp->buffer[i], tmp->nbytes - i);
|
||||
|
||||
for (tmp = tmp->next; tmp; tmp = tmp->next)
|
||||
XWRITE (STDOUT_FILENO, tmp->buffer, tmp->nbytes);
|
||||
|
||||
free_lbuffers:
|
||||
while (first)
|
||||
{
|
||||
tmp = first->next;
|
||||
free ((char *) first);
|
||||
first = tmp;
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
/* Print the last N_BYTES characters from the end of pipe FD.
|
||||
This is a stripped down version of pipe_lines.
|
||||
Return 0 if successful, 1 if an error occurred. */
|
||||
|
||||
static int
|
||||
pipe_bytes (const char *filename, int fd, off_t n_bytes)
|
||||
{
|
||||
struct charbuffer
|
||||
{
|
||||
int nbytes;
|
||||
char buffer[BUFSIZ];
|
||||
struct charbuffer *next;
|
||||
};
|
||||
typedef struct charbuffer CBUFFER;
|
||||
CBUFFER *first, *last, *tmp;
|
||||
int i; /* Index into buffers. */
|
||||
int total_bytes = 0; /* Total characters in all buffers. */
|
||||
int errors = 0;
|
||||
|
||||
first = last = (CBUFFER *) xmalloc (sizeof (CBUFFER));
|
||||
first->nbytes = 0;
|
||||
first->next = NULL;
|
||||
tmp = (CBUFFER *) xmalloc (sizeof (CBUFFER));
|
||||
|
||||
/* Input is always read into a fresh buffer. */
|
||||
while ((tmp->nbytes = fullRead (fd, tmp->buffer, BUFSIZ)) > 0)
|
||||
{
|
||||
tmp->next = NULL;
|
||||
|
||||
total_bytes += tmp->nbytes;
|
||||
/* If there is enough room in the last buffer read, just append the new
|
||||
one to it. This is because when reading from a pipe, `nbytes' can
|
||||
often be very small. */
|
||||
if (tmp->nbytes + last->nbytes < BUFSIZ)
|
||||
{
|
||||
memcpy (&last->buffer[last->nbytes], tmp->buffer, tmp->nbytes);
|
||||
last->nbytes += tmp->nbytes;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* If there's not enough room, link the new buffer onto the end of
|
||||
the list, then either free up the oldest buffer for the next
|
||||
read if that would leave enough characters, or else malloc a new
|
||||
one. Some compaction mechanism is possible but probably not
|
||||
worthwhile. */
|
||||
last = last->next = tmp;
|
||||
if (total_bytes - first->nbytes > n_bytes)
|
||||
{
|
||||
tmp = first;
|
||||
total_bytes -= first->nbytes;
|
||||
first = first->next;
|
||||
}
|
||||
else
|
||||
{
|
||||
tmp = (CBUFFER *) xmalloc (sizeof (CBUFFER));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tmp->nbytes == -1)
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
errors = 1;
|
||||
free ((char *) tmp);
|
||||
goto free_cbuffers;
|
||||
}
|
||||
|
||||
free ((char *) tmp);
|
||||
|
||||
/* Run through the list, printing characters. First, skip over unneeded
|
||||
buffers. */
|
||||
for (tmp = first; total_bytes - tmp->nbytes > n_bytes; tmp = tmp->next)
|
||||
total_bytes -= tmp->nbytes;
|
||||
|
||||
/* Find the correct beginning, then print the rest of the file.
|
||||
We made sure that `total_bytes' - `n_bytes' <= `tmp->nbytes'. */
|
||||
if (total_bytes > n_bytes)
|
||||
i = total_bytes - n_bytes;
|
||||
else
|
||||
i = 0;
|
||||
XWRITE (STDOUT_FILENO, &tmp->buffer[i], tmp->nbytes - i);
|
||||
|
||||
for (tmp = tmp->next; tmp; tmp = tmp->next)
|
||||
XWRITE (STDOUT_FILENO, tmp->buffer, tmp->nbytes);
|
||||
|
||||
free_cbuffers:
|
||||
while (first)
|
||||
{
|
||||
tmp = first->next;
|
||||
free ((char *) first);
|
||||
first = tmp;
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
|
||||
/* Skip N_BYTES characters from the start of pipe FD, and print
|
||||
any extra characters that were read beyond that.
|
||||
Return 1 on error, 0 if ok. */
|
||||
|
||||
static int
|
||||
start_bytes (const char *filename, int fd, off_t n_bytes)
|
||||
{
|
||||
char buffer[BUFSIZ];
|
||||
int bytes_read = 0;
|
||||
|
||||
while (n_bytes > 0 && (bytes_read = fullRead (fd, buffer, BUFSIZ)) > 0)
|
||||
n_bytes -= bytes_read;
|
||||
if (bytes_read == -1)
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
return 1;
|
||||
}
|
||||
else if (n_bytes < 0)
|
||||
XWRITE (STDOUT_FILENO, &buffer[bytes_read + n_bytes], -n_bytes);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Skip N_LINES lines at the start of file or pipe FD, and print
|
||||
any extra characters that were read beyond that.
|
||||
Return 1 on error, 0 if ok. */
|
||||
|
||||
static int
|
||||
start_lines (const char *filename, int fd, long int n_lines)
|
||||
{
|
||||
char buffer[BUFSIZ];
|
||||
int bytes_read = 0;
|
||||
int bytes_to_skip = 0;
|
||||
|
||||
while (n_lines && (bytes_read = fullRead (fd, buffer, BUFSIZ)) > 0)
|
||||
{
|
||||
bytes_to_skip = 0;
|
||||
while (bytes_to_skip < bytes_read)
|
||||
if (buffer[bytes_to_skip++] == '\n' && --n_lines == 0)
|
||||
break;
|
||||
}
|
||||
if (bytes_read == -1)
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
return 1;
|
||||
}
|
||||
else if (bytes_to_skip < bytes_read)
|
||||
{
|
||||
XWRITE (STDOUT_FILENO, &buffer[bytes_to_skip],
|
||||
bytes_read - bytes_to_skip);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Display file FILENAME from the current position in FD to the end.
|
||||
If `forever' is nonzero, keep reading from the end of the file
|
||||
until killed. Return the number of bytes read from the file. */
|
||||
|
||||
static long
|
||||
dump_remainder (const char *filename, int fd)
|
||||
{
|
||||
char buffer[BUFSIZ];
|
||||
int bytes_read;
|
||||
long total;
|
||||
|
||||
total = 0;
|
||||
output:
|
||||
while ((bytes_read = fullRead (fd, buffer, BUFSIZ)) > 0)
|
||||
{
|
||||
XWRITE (STDOUT_FILENO, buffer, bytes_read);
|
||||
total += bytes_read;
|
||||
}
|
||||
if (bytes_read == -1)
|
||||
error (EXIT_FAILURE, errno, "%s", filename);
|
||||
if (forever)
|
||||
{
|
||||
fflush (stdout);
|
||||
sleep (1);
|
||||
goto output;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (forever_multiple)
|
||||
fflush (stdout);
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
/* Tail NFILES (>1) files forever until killed. The file names are in
|
||||
NAMES. The open file descriptors are in `file_descs', and the size
|
||||
at which we stopped tailing them is in `file_sizes'. We loop over
|
||||
each of them, doing an fstat to see if they have changed size. If
|
||||
none of them have changed size in one iteration, we sleep for a
|
||||
second and try again. We do this until the user interrupts us. */
|
||||
|
||||
static void
|
||||
tail_forever (char **names, int nfiles)
|
||||
{
|
||||
int last;
|
||||
|
||||
last = -1;
|
||||
|
||||
while (1)
|
||||
{
|
||||
int i;
|
||||
int changed;
|
||||
|
||||
changed = 0;
|
||||
for (i = 0; i < nfiles; i++)
|
||||
{
|
||||
struct stat stats;
|
||||
|
||||
if (file_descs[i] < 0)
|
||||
continue;
|
||||
if (fstat (file_descs[i], &stats) < 0)
|
||||
{
|
||||
error (0, errno, "%s", names[i]);
|
||||
file_descs[i] = -1;
|
||||
continue;
|
||||
}
|
||||
if (stats.st_size == file_sizes[i])
|
||||
continue;
|
||||
|
||||
/* This file has changed size. Print out what we can, and
|
||||
then keep looping. */
|
||||
|
||||
changed = 1;
|
||||
|
||||
if (stats.st_size < file_sizes[i])
|
||||
{
|
||||
write_header (names[i], "file truncated");
|
||||
last = i;
|
||||
lseek (file_descs[i], stats.st_size, SEEK_SET);
|
||||
file_sizes[i] = stats.st_size;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (i != last)
|
||||
{
|
||||
if (print_headers)
|
||||
write_header (names[i], NULL);
|
||||
last = i;
|
||||
}
|
||||
file_sizes[i] += dump_remainder (names[i], file_descs[i]);
|
||||
}
|
||||
|
||||
/* If none of the files changed size, sleep. */
|
||||
if (! changed)
|
||||
sleep (1);
|
||||
}
|
||||
}
|
||||
|
||||
/* Output the last N_BYTES bytes of file FILENAME open for reading in FD.
|
||||
Return 0 if successful, 1 if an error occurred. */
|
||||
|
||||
static int
|
||||
tail_bytes (const char *filename, int fd, off_t n_bytes)
|
||||
{
|
||||
struct stat stats;
|
||||
|
||||
/* FIXME: resolve this like in dd.c. */
|
||||
/* Use fstat instead of checking for errno == ESPIPE because
|
||||
lseek doesn't work on some special files but doesn't return an
|
||||
error, either. */
|
||||
if (fstat (fd, &stats))
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (from_start)
|
||||
{
|
||||
if (S_ISREG (stats.st_mode))
|
||||
lseek (fd, n_bytes, SEEK_CUR);
|
||||
else if (start_bytes (filename, fd, n_bytes))
|
||||
return 1;
|
||||
dump_remainder (filename, fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (S_ISREG (stats.st_mode))
|
||||
{
|
||||
off_t current_pos, end_pos;
|
||||
size_t bytes_remaining;
|
||||
|
||||
if ((current_pos = lseek (fd, (off_t) 0, SEEK_CUR)) != -1
|
||||
&& (end_pos = lseek (fd, (off_t) 0, SEEK_END)) != -1)
|
||||
{
|
||||
off_t diff;
|
||||
/* Be careful here. The current position may actually be
|
||||
beyond the end of the file. */
|
||||
bytes_remaining = (diff = end_pos - current_pos) < 0 ? 0 : diff;
|
||||
}
|
||||
else
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (bytes_remaining <= n_bytes)
|
||||
{
|
||||
/* From the current position to end of file, there are no
|
||||
more bytes than have been requested. So reposition the
|
||||
file pointer to the incoming current position and print
|
||||
everything after that. */
|
||||
lseek (fd, current_pos, SEEK_SET);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* There are more bytes remaining than were requested.
|
||||
Back up. */
|
||||
lseek (fd, -n_bytes, SEEK_END);
|
||||
}
|
||||
dump_remainder (filename, fd);
|
||||
}
|
||||
else
|
||||
return pipe_bytes (filename, fd, n_bytes);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Output the last N_LINES lines of file FILENAME open for reading in FD.
|
||||
Return 0 if successful, 1 if an error occurred. */
|
||||
|
||||
static int
|
||||
tail_lines (const char *filename, int fd, long int n_lines)
|
||||
{
|
||||
struct stat stats;
|
||||
off_t length;
|
||||
|
||||
if (fstat (fd, &stats))
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
return 1;
|
||||
}
|
||||
|
||||
if (from_start)
|
||||
{
|
||||
if (start_lines (filename, fd, n_lines))
|
||||
return 1;
|
||||
dump_remainder (filename, fd);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Use file_lines only if FD refers to a regular file with
|
||||
its file pointer positioned at beginning of file. */
|
||||
/* FIXME: adding the lseek conjunct is a kludge.
|
||||
Once there's a reasonable test suite, fix the true culprit:
|
||||
file_lines. file_lines shouldn't presume that the input
|
||||
file pointer is initially positioned to beginning of file. */
|
||||
if (S_ISREG (stats.st_mode)
|
||||
&& lseek (fd, (off_t) 0, SEEK_CUR) == (off_t) 0)
|
||||
{
|
||||
length = lseek (fd, (off_t) 0, SEEK_END);
|
||||
if (length != 0 && file_lines (filename, fd, n_lines, length))
|
||||
return 1;
|
||||
dump_remainder (filename, fd);
|
||||
}
|
||||
else
|
||||
return pipe_lines (filename, fd, n_lines);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Display the last N_UNITS units of file FILENAME, open for reading
|
||||
in FD.
|
||||
Return 0 if successful, 1 if an error occurred. */
|
||||
|
||||
static int
|
||||
tail (const char *filename, int fd, off_t n_units)
|
||||
{
|
||||
if (count_lines)
|
||||
return tail_lines (filename, fd, (long) n_units);
|
||||
else
|
||||
return tail_bytes (filename, fd, n_units);
|
||||
}
|
||||
|
||||
/* Display the last N_UNITS units of file FILENAME.
|
||||
"-" for FILENAME means the standard input.
|
||||
FILENUM is this file's index in the list of files the user gave.
|
||||
Return 0 if successful, 1 if an error occurred. */
|
||||
|
||||
static int
|
||||
tail_file (const char *filename, off_t n_units, int filenum)
|
||||
{
|
||||
int fd, errors;
|
||||
struct stat stats;
|
||||
|
||||
if (!strcmp (filename, "-"))
|
||||
{
|
||||
have_read_stdin = 1;
|
||||
filename = "standard input";
|
||||
if (print_headers)
|
||||
write_header (filename, NULL);
|
||||
errors = tail (filename, 0, n_units);
|
||||
if (forever_multiple)
|
||||
{
|
||||
if (fstat (0, &stats) < 0)
|
||||
{
|
||||
error (0, errno, "standard input");
|
||||
errors = 1;
|
||||
}
|
||||
else if (!S_ISREG (stats.st_mode))
|
||||
{
|
||||
error (0, 0,
|
||||
"standard input: cannot follow end of non-regular file");
|
||||
errors = 1;
|
||||
}
|
||||
if (errors)
|
||||
file_descs[filenum] = -1;
|
||||
else
|
||||
{
|
||||
file_descs[filenum] = 0;
|
||||
file_sizes[filenum] = stats.st_size;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Not standard input. */
|
||||
fd = open (filename, O_RDONLY);
|
||||
if (fd == -1)
|
||||
{
|
||||
if (forever_multiple)
|
||||
file_descs[filenum] = -1;
|
||||
error (0, errno, "%s", filename);
|
||||
errors = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (print_headers)
|
||||
write_header (filename, NULL);
|
||||
errors = tail (filename, fd, n_units);
|
||||
if (forever_multiple)
|
||||
{
|
||||
if (fstat (fd, &stats) < 0)
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
errors = 1;
|
||||
}
|
||||
else if (!S_ISREG (stats.st_mode))
|
||||
{
|
||||
error (0, 0, "%s: cannot follow end of non-regular file",
|
||||
filename);
|
||||
errors = 1;
|
||||
}
|
||||
if (errors)
|
||||
{
|
||||
close (fd);
|
||||
file_descs[filenum] = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
file_descs[filenum] = fd;
|
||||
file_sizes[filenum] = stats.st_size;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (close (fd))
|
||||
{
|
||||
error (0, errno, "%s", filename);
|
||||
errors = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return errors;
|
||||
}
|
||||
|
||||
extern int
|
||||
tail_main (int argc, char **argv)
|
||||
{
|
||||
int stopit = 0;
|
||||
enum header_mode header_mode = multiple_files;
|
||||
int exit_status = 0;
|
||||
/* If from_start, the number of items to skip before printing; otherwise,
|
||||
the number of items at the end of the file to print. Initially, -1
|
||||
means the value has not been set. */
|
||||
off_t n_units = -1;
|
||||
int n_files;
|
||||
char **file;
|
||||
|
||||
program_name = argv[0];
|
||||
have_read_stdin = 0;
|
||||
count_lines = 1;
|
||||
forever = forever_multiple = from_start = print_headers = 0;
|
||||
|
||||
/* Parse any options */
|
||||
//fprintf(stderr, "argc=%d, argv=%s\n", argc, *argv);
|
||||
while (--argc > 0 && ( **(++argv) == '-' || **argv == '+' )) {
|
||||
if (**argv == '+') {
|
||||
from_start = 1;
|
||||
}
|
||||
stopit = 0;
|
||||
while (stopit == 0 && *(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 'c':
|
||||
count_lines = 0;
|
||||
|
||||
if (--argc < 1) {
|
||||
usage(tail_usage);
|
||||
}
|
||||
n_units = getNum(*(++argv));
|
||||
stopit = 1;
|
||||
break;
|
||||
|
||||
case 'f':
|
||||
forever = 1;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
count_lines = 1;
|
||||
|
||||
if (--argc < 1) {
|
||||
usage(tail_usage);
|
||||
}
|
||||
n_units = atol(*(++argv));
|
||||
stopit = 1;
|
||||
break;
|
||||
|
||||
case 'q':
|
||||
header_mode = never;
|
||||
break;
|
||||
|
||||
case 'v':
|
||||
header_mode = always;
|
||||
break;
|
||||
|
||||
default:
|
||||
usage (tail_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (n_units == -1)
|
||||
n_units = DEFAULT_N_LINES;
|
||||
|
||||
/* To start printing with item N_UNITS from the start of the file, skip
|
||||
N_UNITS - 1 items. `tail +0' is actually meaningless, but for Unix
|
||||
compatibility it's treated the same as `tail +1'. */
|
||||
if (from_start)
|
||||
{
|
||||
if (n_units)
|
||||
--n_units;
|
||||
}
|
||||
|
||||
n_files = argc;
|
||||
file = argv;
|
||||
|
||||
if (n_files > 1 && forever)
|
||||
{
|
||||
forever_multiple = 1;
|
||||
forever = 0;
|
||||
file_descs = (int *) xmalloc (n_files * sizeof (int));
|
||||
file_sizes = (off_t *) xmalloc (n_files * sizeof (off_t));
|
||||
}
|
||||
|
||||
if (header_mode == always
|
||||
|| (header_mode == multiple_files && n_files > 1))
|
||||
print_headers = 1;
|
||||
|
||||
if (n_files == 0)
|
||||
{
|
||||
exit_status |= tail_file ("-", n_units, 0);
|
||||
}
|
||||
else
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < n_files; i++)
|
||||
exit_status |= tail_file (file[i], n_units, i);
|
||||
|
||||
if (forever_multiple)
|
||||
tail_forever (file, n_files);
|
||||
}
|
||||
|
||||
if (have_read_stdin && close (0) < 0)
|
||||
error (EXIT_FAILURE, errno, "-");
|
||||
if (fclose (stdout) == EOF)
|
||||
error (EXIT_FAILURE, errno, "write error");
|
||||
exit (exit_status == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
|
||||
}
|
||||
+126
@@ -0,0 +1,126 @@
|
||||
/*
|
||||
* Mini tee implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* 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 "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
static const char tee_usage[] =
|
||||
"tee [OPTION]... [FILE]...\n\n"
|
||||
"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"
|
||||
#if 0
|
||||
"\t-i\tignore interrupt signals\n"
|
||||
#endif
|
||||
;
|
||||
|
||||
|
||||
/* FileList _______________________________________________________________ */
|
||||
|
||||
#define FL_MAX 1024
|
||||
static FILE *FileList[FL_MAX];
|
||||
static int FL_end;
|
||||
|
||||
typedef void (FL_Function)(FILE *file, char c);
|
||||
|
||||
|
||||
/* apply a function to everything in FileList */
|
||||
static void
|
||||
FL_apply(FL_Function *f, char c)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i <= FL_end; i++) {
|
||||
f(FileList[i], c);
|
||||
}
|
||||
}
|
||||
|
||||
/* FL_Function for writing to files*/
|
||||
static void
|
||||
tee_fwrite(FILE *file, char c)
|
||||
{
|
||||
fputc(c, file);
|
||||
}
|
||||
|
||||
/* FL_Function for closing files */
|
||||
static void
|
||||
tee_fclose(FILE *file, char c)
|
||||
{
|
||||
fclose(file);
|
||||
}
|
||||
|
||||
/* ________________________________________________________________________ */
|
||||
|
||||
/* BusyBoxed tee(1) */
|
||||
int
|
||||
tee_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char c;
|
||||
char opt;
|
||||
char opt_fopen[2] = "w";
|
||||
FILE *file;
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 'a':
|
||||
opt_fopen[0] = 'a';
|
||||
break;
|
||||
#if 0
|
||||
case 'i':
|
||||
fprintf(stderr, "ignore interrupt not implemented\n");
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
usage(tee_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* init FILE pointers */
|
||||
FL_end = 0;
|
||||
FileList[0] = stdout;
|
||||
for ( ; i < argc; i++) {
|
||||
/* add a file to FileList */
|
||||
file = fopen(argv[i], opt_fopen);
|
||||
if (!file) { continue; }
|
||||
if (FL_end < FL_MAX) {
|
||||
FileList[++FL_end] = file;
|
||||
}
|
||||
}
|
||||
|
||||
/* read and redirect */
|
||||
while ((c = (char) getchar()) && (!feof(stdin))) {
|
||||
FL_apply(tee_fwrite, c);
|
||||
}
|
||||
|
||||
/* clean up */
|
||||
FL_apply(tee_fclose, 0);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: tee.c,v 1.4 1999/12/10 08:25:07 andersen Exp $ */
|
||||
+2
-2
@@ -31,7 +31,7 @@
|
||||
|
||||
|
||||
static const char touch_usage[] = "touch [-c] file [file ...]\n\n"
|
||||
"\tUpdate the last-modified date on the given file[s].\n";
|
||||
"Update the last-modified date on the given file[s].\n";
|
||||
|
||||
|
||||
|
||||
@@ -54,7 +54,7 @@ touch_main(int argc, char **argv)
|
||||
create = FALSE;
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "Unknown option: %c\n", **argv);
|
||||
usage( touch_usage);
|
||||
exit( FALSE);
|
||||
}
|
||||
argc--;
|
||||
|
||||
+3
-2
@@ -41,8 +41,9 @@
|
||||
|
||||
|
||||
static const char uname_usage[] =
|
||||
"uname [OPTION]...\n"
|
||||
"Print certain system information. With no OPTION, same as -s.\n"
|
||||
"uname [OPTION]...\n\n"
|
||||
"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"
|
||||
|
||||
@@ -28,7 +28,7 @@
|
||||
#include <dirent.h>
|
||||
|
||||
static const char cp_usage[] = "cp [OPTION]... SOURCE DEST\n"
|
||||
" or: cp [OPTION]... SOURCE... DIRECTORY\n"
|
||||
" or: cp [OPTION]... SOURCE... DIRECTORY\n\n"
|
||||
"Copy SOURCE to DEST, or multiple SOURCE(s) to DIRECTORY.\n"
|
||||
"\n"
|
||||
"\t-a\tsame as -dpR\n"
|
||||
@@ -54,6 +54,8 @@ static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
strcat(newdestName, "/");
|
||||
if ( skipName != NULL)
|
||||
strcat(newdestName, strstr(fileName, skipName));
|
||||
else
|
||||
strcat(newdestName, srcName);
|
||||
}
|
||||
return (copyFile(fileName, newdestName, preserveFlag, followLinks));
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@
|
||||
mail commands */
|
||||
|
||||
static const char date_usage[] = "date [OPTION]... [+FORMAT]\n"
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n"
|
||||
" or: date [OPTION] [MMDDhhmm[[CC]YY][.ss]]\n\n"
|
||||
"Display the current time in the given FORMAT, or set the system date.\n"
|
||||
"\nOptions:\n\t-R\t\toutput RFC-822 compliant date string\n"
|
||||
"\t-s\t\tset time described by STRING\n"
|
||||
|
||||
@@ -29,12 +29,18 @@
|
||||
|
||||
|
||||
#include "internal.h"
|
||||
#include <features.h>
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <errno.h>
|
||||
#if (__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1)
|
||||
#include <inttypes.h>
|
||||
#else
|
||||
typedef unsigned long long int uintmax_t;
|
||||
#endif
|
||||
|
||||
static const char dd_usage[] =
|
||||
"dd [if=name] [of=name] [bs=n] [count=n]\n"
|
||||
"dd [if=name] [of=name] [bs=n] [count=n]\n\n"
|
||||
"Copy a file, converting and formatting according to options\n\n"
|
||||
"\tif=FILE\tread from FILE instead of stdin\n"
|
||||
"\tof=FILE\twrite to FILE instead of stout\n"
|
||||
@@ -42,77 +48,26 @@ static const char dd_usage[] =
|
||||
"\tcount=n\tcopy only n input blocks\n"
|
||||
//"\tskip=n\tskip n input blocks\n"
|
||||
"\n"
|
||||
"BYTES may be suffixed: by k for x1024, b for x512, and w for x2.\n";
|
||||
"BYTES may be suffixed by w (x2), k (x1024), b (x512), or m (x1024^2).\n";
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Read a number with a possible multiplier.
|
||||
* Returns -1 if the number format is illegal.
|
||||
*/
|
||||
static long getNum (const char *cp)
|
||||
{
|
||||
long value;
|
||||
|
||||
if (!isDecimal (*cp))
|
||||
return -1;
|
||||
|
||||
value = 0;
|
||||
|
||||
while (isDecimal (*cp))
|
||||
value = value * 10 + *cp++ - '0';
|
||||
|
||||
switch (*cp++) {
|
||||
case 'k':
|
||||
value *= 1024;
|
||||
break;
|
||||
|
||||
case 'b':
|
||||
value *= 512;
|
||||
break;
|
||||
|
||||
case 'w':
|
||||
value *= 2;
|
||||
break;
|
||||
|
||||
case '\0':
|
||||
return value;
|
||||
|
||||
default:
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (*cp)
|
||||
return -1;
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
|
||||
extern int dd_main (int argc, char **argv)
|
||||
{
|
||||
const char *inFile;
|
||||
const char *outFile;
|
||||
const char *inFile = NULL;
|
||||
const char *outFile = NULL;
|
||||
char *cp;
|
||||
int inFd;
|
||||
int outFd;
|
||||
int inCc = 0;
|
||||
int outCc;
|
||||
int skipBlocks;
|
||||
int blockSize;
|
||||
long count;
|
||||
long intotal;
|
||||
long outTotal;
|
||||
size_t blockSize = 512;
|
||||
//uintmax_t skipBlocks = 0;
|
||||
uintmax_t count = (uintmax_t)-1;
|
||||
uintmax_t intotal;
|
||||
uintmax_t outTotal;
|
||||
unsigned char *buf;
|
||||
|
||||
inFile = NULL;
|
||||
outFile = NULL;
|
||||
blockSize = 512;
|
||||
skipBlocks = 0;
|
||||
count = 1;
|
||||
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
@@ -125,14 +80,14 @@ extern int dd_main (int argc, char **argv)
|
||||
else if (strncmp("count", *argv, 5) == 0) {
|
||||
count = getNum ((strchr(*argv, '='))+1);
|
||||
if (count <= 0) {
|
||||
fprintf (stderr, "Bad count value %ld\n", count);
|
||||
fprintf (stderr, "Bad count value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
else if (strncmp(*argv, "bs", 2) == 0) {
|
||||
blockSize = getNum ((strchr(*argv, '='))+1);
|
||||
if (blockSize <= 0) {
|
||||
fprintf (stderr, "Bad block size value %d\n", blockSize);
|
||||
fprintf (stderr, "Bad block size value %s\n", *argv);
|
||||
goto usage;
|
||||
}
|
||||
}
|
||||
@@ -152,8 +107,6 @@ extern int dd_main (int argc, char **argv)
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
if ( inFile == NULL || outFile == NULL)
|
||||
goto usage;
|
||||
|
||||
buf = malloc (blockSize);
|
||||
if (buf == NULL) {
|
||||
@@ -165,7 +118,7 @@ extern int dd_main (int argc, char **argv)
|
||||
outTotal = 0;
|
||||
|
||||
if (inFile == NULL)
|
||||
inFd = STDIN;
|
||||
inFd = fileno(stdin);
|
||||
else
|
||||
inFd = open (inFile, 0);
|
||||
|
||||
@@ -176,7 +129,7 @@ extern int dd_main (int argc, char **argv)
|
||||
}
|
||||
|
||||
if (outFile == NULL)
|
||||
outFd = STDOUT;
|
||||
outFd = fileno(stdout);
|
||||
else
|
||||
outFd = creat (outFile, 0666);
|
||||
|
||||
@@ -188,11 +141,17 @@ extern int dd_main (int argc, char **argv)
|
||||
}
|
||||
|
||||
//lseek(inFd, skipBlocks*blockSize, SEEK_SET);
|
||||
//
|
||||
//TODO: Convert to using fullRead & fullWrite
|
||||
// from utilitity.c
|
||||
// -Erik
|
||||
while (outTotal < count * blockSize) {
|
||||
inCc = read (inFd, buf, blockSize);
|
||||
if (inCc < 0) {
|
||||
perror (inFile);
|
||||
goto cleanup;
|
||||
} else if (inCc == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
intotal += inCc;
|
||||
cp = buf;
|
||||
@@ -204,6 +163,8 @@ extern int dd_main (int argc, char **argv)
|
||||
if (outCc < 0) {
|
||||
perror (outFile);
|
||||
goto cleanup;
|
||||
} else if (outCc == 0) {
|
||||
goto cleanup;
|
||||
}
|
||||
|
||||
inCc -= outCc;
|
||||
@@ -220,15 +181,14 @@ extern int dd_main (int argc, char **argv)
|
||||
close (outFd);
|
||||
free (buf);
|
||||
|
||||
printf ("%ld+%d records in\n", intotal / blockSize,
|
||||
printf ("%ld+%d records in\n", (long)(intotal / blockSize),
|
||||
(intotal % blockSize) != 0);
|
||||
printf ("%ld+%d records out\n", outTotal / blockSize,
|
||||
printf ("%ld+%d records out\n", (long)(outTotal / blockSize),
|
||||
(outTotal % blockSize) != 0);
|
||||
exit( TRUE);
|
||||
usage:
|
||||
|
||||
fprintf (stderr, "%s", dd_usage);
|
||||
exit( FALSE);
|
||||
usage( dd_usage);
|
||||
}
|
||||
|
||||
|
||||
+4
-2
@@ -17,8 +17,10 @@ int
|
||||
deallocvt_main(int argc, char *argv[]) {
|
||||
int fd, num, i;
|
||||
|
||||
if (argc < 1) /* unlikely */
|
||||
exit(1);
|
||||
if ( ( argc != 2) || (**(argv+1) == '-' ) ) {
|
||||
usage ("deallocvt N\n\nDeallocate unused virtual terminal /dev/ttyN\n");
|
||||
}
|
||||
|
||||
progname = argv[0];
|
||||
|
||||
fd = get_console_fd("/dev/console");
|
||||
|
||||
@@ -42,7 +42,7 @@ static int df(char *device, const char *mountPoint)
|
||||
|
||||
if (statfs(mountPoint, &s) != 0) {
|
||||
perror(mountPoint);
|
||||
return 1;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
if (s.f_blocks > 0) {
|
||||
@@ -64,7 +64,7 @@ static int df(char *device, const char *mountPoint)
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
extern int df_main(int argc, char **argv)
|
||||
@@ -83,15 +83,15 @@ extern int df_main(int argc, char **argv)
|
||||
if ((mountEntry = findMountPoint(argv[1], mtab_file)) ==
|
||||
0) {
|
||||
fprintf(stderr, "%s: can't find mount point.\n", argv[1]);
|
||||
return 1;
|
||||
exit( FALSE);
|
||||
}
|
||||
status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
if (status != 0)
|
||||
return status;
|
||||
exit( status);
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
return 0;
|
||||
exit( TRUE);
|
||||
} else {
|
||||
FILE *mountTable;
|
||||
struct mntent *mountEntry;
|
||||
@@ -103,12 +103,10 @@ extern int df_main(int argc, char **argv)
|
||||
}
|
||||
|
||||
while ((mountEntry = getmntent(mountTable))) {
|
||||
int status = df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
if (status)
|
||||
return status;
|
||||
df(mountEntry->mnt_fsname, mountEntry->mnt_dir);
|
||||
}
|
||||
endmntent(mountTable);
|
||||
}
|
||||
|
||||
return 0;
|
||||
exit( TRUE);
|
||||
}
|
||||
@@ -0,0 +1,121 @@
|
||||
/*
|
||||
* Mini du implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* 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 "internal.h"
|
||||
#include <sys/types.h>
|
||||
#include <fcntl.h>
|
||||
#include <dirent.h>
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#if 0
|
||||
#include <unistd.h>
|
||||
#include <sys/stat.h>
|
||||
#endif
|
||||
|
||||
static const char du_usage[] =
|
||||
"Usage: du [OPTION]... [FILE]...\n";
|
||||
|
||||
typedef void (Display)(size_t, char *);
|
||||
|
||||
static void
|
||||
print(size_t size, char *filename)
|
||||
{
|
||||
fprintf(stdout, "%-7d %s\n", (size >> 1), filename);
|
||||
}
|
||||
|
||||
/* tiny recursive du */
|
||||
static size_t
|
||||
du(char *filename)
|
||||
{
|
||||
struct stat statbuf;
|
||||
size_t sum;
|
||||
|
||||
if ((lstat(filename, &statbuf)) != 0) {
|
||||
fprintf(stdout, "du: %s: %s\n", filename, strerror(errno));
|
||||
return 0;
|
||||
}
|
||||
sum = statbuf.st_blocks;
|
||||
|
||||
if (S_ISDIR(statbuf.st_mode)) {
|
||||
DIR *dir;
|
||||
struct dirent *entry;
|
||||
|
||||
dir = opendir(filename);
|
||||
if (!dir) { return 0; }
|
||||
while ((entry = readdir(dir))) {
|
||||
char newfile[512];
|
||||
char *name = entry->d_name;
|
||||
|
||||
if ( (strcmp(name, "..") == 0)
|
||||
|| (strcmp(name, ".") == 0))
|
||||
{ continue; }
|
||||
|
||||
sprintf(newfile, "%s/%s", filename, name);
|
||||
sum += du(newfile);
|
||||
}
|
||||
closedir(dir);
|
||||
print(sum, filename);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
int
|
||||
du_main(int argc, char **argv)
|
||||
{
|
||||
int i;
|
||||
char opt;
|
||||
|
||||
/* parse argv[] */
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case 's':
|
||||
break;
|
||||
case 'h':
|
||||
usage(du_usage);
|
||||
break;
|
||||
default:
|
||||
fprintf(stderr, "du: invalid option -- %c\n", opt);
|
||||
usage(du_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* go through remaining args (if any) */
|
||||
if (i >= argc) {
|
||||
du(".");
|
||||
} else {
|
||||
int sum;
|
||||
for ( ; i < argc; i++) {
|
||||
sum = du(argv[i]) >> 1;
|
||||
if (sum) printf("%-7d %s\n", sum, argv[i]);
|
||||
}
|
||||
}
|
||||
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: du.c,v 1.5 1999/12/10 15:23:47 beppu Exp $ */
|
||||
@@ -19,7 +19,7 @@ static const char dutmp_usage[] = "dutmp\n"
|
||||
"\tDump file or stdin utmp file format to stdout, pipe delimited.\n"
|
||||
"\tdutmp /var/run/utmp\n";
|
||||
|
||||
static int dutmp_main (int argc, char **argv)
|
||||
extern int dutmp_main (int argc, char **argv)
|
||||
{
|
||||
|
||||
FILE *f = stdin;
|
||||
|
||||
+44
-42
@@ -32,22 +32,36 @@
|
||||
#include <ctype.h>
|
||||
|
||||
static const char sed_usage[] =
|
||||
"sed [-n] [-e script] [file...]\n"
|
||||
"Allowed scripts come in the following form:\n\n"
|
||||
"'s/regexp/replacement/[gp]'\n"
|
||||
"\tattempt to match regexp against the pattern space\n"
|
||||
"\tand if successful replaces the matched portion with replacement.\n\n"
|
||||
"sed [-n] [-e script] [file...]\n\n"
|
||||
"Allowed sed scripts come in the following form:\n"
|
||||
"\t's/regexp/replacement/[gp]'\n"
|
||||
"which attempt to match regexp against the pattern space\n"
|
||||
"and if successful replaces the matched portion with replacement.\n\n"
|
||||
"Options:\n"
|
||||
"-e\tadd the script to the commands to be executed\n"
|
||||
"-n\tsuppress automatic printing of pattern space\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of sed matches full regexps.\n";
|
||||
"This version of sed matches full regular expresions.\n";
|
||||
#else
|
||||
"This version of sed matches strings (not full regexps).\n";
|
||||
"This version of sed matches strings (not full regular expresions).\n";
|
||||
#endif
|
||||
|
||||
|
||||
static void do_sed(FILE *fp, char *needle, char *newNeedle, int ignoreCase, int printFlag, int quietFlag)
|
||||
{
|
||||
int foundOne=FALSE;
|
||||
char haystack[1024];
|
||||
|
||||
|
||||
while (fgets (haystack, 1023, fp)) {
|
||||
foundOne = replace_match(haystack, needle, newNeedle, ignoreCase);
|
||||
if (foundOne==TRUE && printFlag==TRUE) {
|
||||
fprintf(stdout, haystack);
|
||||
}
|
||||
if (quietFlag==FALSE) {
|
||||
fprintf(stdout, haystack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern int sed_main (int argc, char **argv)
|
||||
{
|
||||
@@ -56,11 +70,9 @@ extern int sed_main (int argc, char **argv)
|
||||
char *name;
|
||||
char *cp;
|
||||
int ignoreCase=FALSE;
|
||||
int foundOne=FALSE;
|
||||
int printFlag=FALSE;
|
||||
int quietFlag=FALSE;
|
||||
int stopNow;
|
||||
char *haystack;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
@@ -73,24 +85,23 @@ extern int sed_main (int argc, char **argv)
|
||||
cp = *argv++;
|
||||
stopNow=FALSE;
|
||||
|
||||
while (*++cp && stopNow==FALSE)
|
||||
while (*++cp && stopNow==FALSE) {
|
||||
switch (*cp) {
|
||||
case 'n':
|
||||
quietFlag = TRUE;
|
||||
break;
|
||||
case 'e':
|
||||
if (*(cp+1)==0 && --argc < 0) {
|
||||
fprintf(stderr, "A\n");
|
||||
usage( sed_usage);
|
||||
}
|
||||
cp = *argv++;
|
||||
if ( *++cp != 's')
|
||||
cp = *argv++;
|
||||
while( *cp ) {
|
||||
if (*cp == 's' && strlen(cp) > 3 && *(cp+1) == '/') {
|
||||
char* pos=needle=cp+2;
|
||||
for(;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos==NULL) {
|
||||
fprintf(stderr, "B\n");
|
||||
usage( sed_usage);
|
||||
}
|
||||
if (*(pos-1) == '\\') {
|
||||
@@ -104,7 +115,6 @@ extern int sed_main (int argc, char **argv)
|
||||
for(;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos==NULL) {
|
||||
fprintf(stderr, "C\n");
|
||||
usage( sed_usage);
|
||||
}
|
||||
if (*(pos-1) == '\\') {
|
||||
@@ -116,7 +126,6 @@ extern int sed_main (int argc, char **argv)
|
||||
*pos=0;
|
||||
if (pos+2 != 0) {
|
||||
while (*++pos) {
|
||||
fprintf(stderr, "pos='%s'\n", pos);
|
||||
switch (*pos) {
|
||||
case 'i':
|
||||
ignoreCase=TRUE;
|
||||
@@ -134,42 +143,35 @@ extern int sed_main (int argc, char **argv)
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle);
|
||||
//fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle);
|
||||
stopNow=TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "D\n");
|
||||
usage(sed_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
if (argc==0) {
|
||||
do_sed( stdin, needle, newNeedle, ignoreCase, printFlag, quietFlag);
|
||||
} else {
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
|
||||
fp = fopen (name, "r");
|
||||
if (fp == NULL) {
|
||||
perror (name);
|
||||
continue;
|
||||
fp = fopen (name, "r");
|
||||
if (fp == NULL) {
|
||||
perror (name);
|
||||
continue;
|
||||
}
|
||||
|
||||
do_sed( fp, needle, newNeedle, ignoreCase, printFlag, quietFlag);
|
||||
|
||||
if (ferror (fp))
|
||||
perror (name);
|
||||
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
haystack = (char*)malloc( 1024);
|
||||
while (fgets (haystack, 1023, fp)) {
|
||||
|
||||
foundOne = replace_match(haystack, needle, newNeedle, ignoreCase);
|
||||
if (foundOne==TRUE && printFlag==TRUE)
|
||||
fputs (haystack, stdout);
|
||||
if (quietFlag==FALSE)
|
||||
fputs (haystack, stdout);
|
||||
/* Avoid any mem leaks */
|
||||
free(haystack);
|
||||
haystack = (char*)malloc( BUF_SIZE);
|
||||
}
|
||||
|
||||
if (ferror (fp))
|
||||
perror (name);
|
||||
|
||||
fclose (fp);
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
+4
-12
@@ -1,5 +1,5 @@
|
||||
Name: busybox
|
||||
Version: 0.32
|
||||
Version: 0.39
|
||||
Release: 1
|
||||
Group: System/Utilities
|
||||
Summary: BusyBox is a tiny suite of Unix utilities in a multi-call binary.
|
||||
@@ -7,7 +7,7 @@ Copyright: GPL
|
||||
Packager : Erik Andersen <andersen@lineo.com>
|
||||
Conflicts: fileutils grep shellutils
|
||||
Buildroot: /tmp/%{Name}-%{Version}
|
||||
Source: busybox-0.32.tar.gz
|
||||
Source: %{Name}-%{Version}.tar.gz
|
||||
|
||||
%Description
|
||||
BusyBox is a suite of "tiny" Unix utilities in a multi-call binary. It
|
||||
@@ -18,22 +18,14 @@ is makes an excellent environment for a "rescue" disk or any small or
|
||||
embedded system.
|
||||
|
||||
%Prep
|
||||
%setup -q -n busybox
|
||||
%setup -q -n %{Name}-%{Version}
|
||||
|
||||
%Build
|
||||
make
|
||||
|
||||
%Install
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
mkdir -p $RPM_BUILD_ROOT/bin
|
||||
h=`cat busybox.links`
|
||||
|
||||
for i in $h ; do
|
||||
mkdir -p $RPM_BUILD_ROOT/`echo $i | sed -e 's/\(^.*\/\)\(.*\)/\1/g' `
|
||||
(cd $RPM_BUILD_ROOT/bin ; ln -s busybox `echo $i | sed -e 's/\(^.*\/\)\(.*\)/\2/g' ` );
|
||||
done
|
||||
rm -f $RPM_BUILD_ROOT/bin/busybox
|
||||
install -m 755 busybox $RPM_BUILD_ROOT/bin/busybox
|
||||
make PREFIX=$RPM_BUILD_ROOT install
|
||||
|
||||
%Clean
|
||||
rm -rf $RPM_BUILD_ROOT
|
||||
|
||||
@@ -32,9 +32,18 @@ static char* pattern=NULL;
|
||||
static char* directory=".";
|
||||
static int dereferenceFlag=FALSE;
|
||||
|
||||
static const char find_usage[] = "find [path...] [expression]\n"
|
||||
"default path is the current directory; default expression is -print\n"
|
||||
"expression may consist of:\n";
|
||||
static const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n"
|
||||
"Search for files in a directory hierarchy. The default PATH is\n"
|
||||
"the current directory; default EXPRESSION is '-print'\n\n"
|
||||
"\nEXPRESSION may consist of:\n"
|
||||
"\t-follow\n\t\tDereference symbolic links.\n"
|
||||
"\t-name PATTERN\n\t\tFile name (with leading directories removed) matches PATTERN.\n"
|
||||
"\t-print\n\t\tprint the full file name followed by a newline to stdout.\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of find matches full regular expresions.\n";
|
||||
#else
|
||||
"This version of find matches strings (not regular expresions).\n";
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -42,8 +51,15 @@ static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
if (pattern==NULL)
|
||||
fprintf(stdout, "%s\n", fileName);
|
||||
else if (find_match((char*)fileName, pattern, TRUE) == TRUE)
|
||||
fprintf(stdout, "%s\n", fileName);
|
||||
else {
|
||||
char* tmp = strrchr( fileName, '/');
|
||||
if (tmp == NULL)
|
||||
tmp = (char*)fileName;
|
||||
else
|
||||
tmp++;
|
||||
if (check_wildcard_match(tmp, pattern) == TRUE)
|
||||
fprintf(stdout, "%s\n", fileName);
|
||||
}
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
|
||||
+21
-5
@@ -32,9 +32,18 @@ static char* pattern=NULL;
|
||||
static char* directory=".";
|
||||
static int dereferenceFlag=FALSE;
|
||||
|
||||
static const char find_usage[] = "find [path...] [expression]\n"
|
||||
"default path is the current directory; default expression is -print\n"
|
||||
"expression may consist of:\n";
|
||||
static const char find_usage[] = "find [PATH...] [EXPRESSION]\n\n"
|
||||
"Search for files in a directory hierarchy. The default PATH is\n"
|
||||
"the current directory; default EXPRESSION is '-print'\n\n"
|
||||
"\nEXPRESSION may consist of:\n"
|
||||
"\t-follow\n\t\tDereference symbolic links.\n"
|
||||
"\t-name PATTERN\n\t\tFile name (with leading directories removed) matches PATTERN.\n"
|
||||
"\t-print\n\t\tprint the full file name followed by a newline to stdout.\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of find matches full regular expresions.\n";
|
||||
#else
|
||||
"This version of find matches strings (not regular expresions).\n";
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -42,8 +51,15 @@ static int fileAction(const char *fileName, struct stat* statbuf)
|
||||
{
|
||||
if (pattern==NULL)
|
||||
fprintf(stdout, "%s\n", fileName);
|
||||
else if (find_match((char*)fileName, pattern, TRUE) == TRUE)
|
||||
fprintf(stdout, "%s\n", fileName);
|
||||
else {
|
||||
char* tmp = strrchr( fileName, '/');
|
||||
if (tmp == NULL)
|
||||
tmp = (char*)fileName;
|
||||
else
|
||||
tmp++;
|
||||
if (check_wildcard_match(tmp, pattern) == TRUE)
|
||||
fprintf(stdout, "%s\n", fileName);
|
||||
}
|
||||
return( TRUE);
|
||||
}
|
||||
|
||||
|
||||
+50
-39
@@ -32,29 +32,55 @@
|
||||
#include <ctype.h>
|
||||
|
||||
static const char grep_usage[] =
|
||||
"grep [-ihn]... PATTERN [FILE]...\n"
|
||||
"grep [OPTIONS]... PATTERN [FILE]...\n\n"
|
||||
"Search for PATTERN in each FILE or standard input.\n\n"
|
||||
"OPTIONS:\n"
|
||||
"\t-h\tsuppress the prefixing filename on output\n"
|
||||
"\t-i\tignore case distinctions\n"
|
||||
"\t-n\tprint line number with output lines\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of grep matches full regexps.\n";
|
||||
"This version of grep matches full regular expresions.\n";
|
||||
#else
|
||||
"This version of grep matches strings (not full regexps).\n";
|
||||
"This version of grep matches strings (not regular expresions).\n";
|
||||
#endif
|
||||
|
||||
|
||||
static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine)
|
||||
{
|
||||
char *cp;
|
||||
long line = 0;
|
||||
char haystack[BUF_SIZE];
|
||||
|
||||
while (fgets (haystack, sizeof (haystack), fp)) {
|
||||
line++;
|
||||
cp = &haystack[strlen (haystack) - 1];
|
||||
|
||||
if (*cp != '\n')
|
||||
fprintf (stderr, "%s: Line too long\n", fileName);
|
||||
|
||||
if (find_match(haystack, needle, ignoreCase) == TRUE) {
|
||||
if (tellName==TRUE)
|
||||
printf ("%s:", fileName);
|
||||
|
||||
if (tellLine==TRUE)
|
||||
printf ("%ld:", line);
|
||||
|
||||
fputs (haystack, stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern int grep_main (int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
char *needle;
|
||||
char *name;
|
||||
char *cp;
|
||||
int tellName=TRUE;
|
||||
char *needle;
|
||||
char *fileName;
|
||||
int tellName=FALSE;
|
||||
int ignoreCase=FALSE;
|
||||
int tellLine=FALSE;
|
||||
long line;
|
||||
char haystack[BUF_SIZE];
|
||||
|
||||
|
||||
ignoreCase = FALSE;
|
||||
tellLine = FALSE;
|
||||
@@ -76,7 +102,7 @@ extern int grep_main (int argc, char **argv)
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
tellName = FALSE;
|
||||
tellName = TRUE;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
@@ -91,39 +117,24 @@ extern int grep_main (int argc, char **argv)
|
||||
needle = *argv++;
|
||||
argc--;
|
||||
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
if (argc==0) {
|
||||
do_grep( stdin, needle, "stdin", FALSE, ignoreCase, tellLine);
|
||||
} else {
|
||||
while (argc-- > 0) {
|
||||
fileName = *argv++;
|
||||
|
||||
fp = fopen (name, "r");
|
||||
if (fp == NULL) {
|
||||
perror (name);
|
||||
continue;
|
||||
}
|
||||
|
||||
line = 0;
|
||||
|
||||
while (fgets (haystack, sizeof (haystack), fp)) {
|
||||
line++;
|
||||
cp = &haystack[strlen (haystack) - 1];
|
||||
|
||||
if (*cp != '\n')
|
||||
fprintf (stderr, "%s: Line too long\n", name);
|
||||
|
||||
if (find_match(haystack, needle, ignoreCase) == TRUE) {
|
||||
if (tellName==TRUE)
|
||||
printf ("%s: ", name);
|
||||
|
||||
if (tellLine==TRUE)
|
||||
printf ("%ld: ", line);
|
||||
|
||||
fputs (haystack, stdout);
|
||||
fp = fopen (fileName, "r");
|
||||
if (fp == NULL) {
|
||||
perror (fileName);
|
||||
continue;
|
||||
}
|
||||
|
||||
do_grep( fp, needle, fileName, tellName, ignoreCase, tellLine);
|
||||
|
||||
if (ferror (fp))
|
||||
perror (fileName);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
if (ferror (fp))
|
||||
perror (name);
|
||||
|
||||
fclose (fp);
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Mini free implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* 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 "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#if ! defined BB_FEATURE_USE_PROCFS
|
||||
#error Sorry, I depend on the /proc filesystem right now.
|
||||
#endif
|
||||
|
||||
extern int free_main(int argc, char **argv)
|
||||
{
|
||||
char* cmd[] = { "cat", "/proc/meminfo", "\0" };
|
||||
exit(cat_main( 3, cmd));
|
||||
}
|
||||
+11
-3
@@ -191,9 +191,17 @@ static void leave(int status)
|
||||
}
|
||||
|
||||
static void show_usage(void) {
|
||||
fprintf(stderr,
|
||||
"Usage: %s [-larvsmf] /dev/name\n",
|
||||
program_name);
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT);
|
||||
fprintf(stderr, "Usage: %s [-larvsmf] /dev/name\n\n", program_name);
|
||||
fprintf(stderr, "Performs a consistency check for MINIX filesystems.\n\n");
|
||||
fprintf(stderr, "OPTIONS:\n");
|
||||
fprintf(stderr, "\t-l\tLists all filenames\n");
|
||||
fprintf(stderr, "\t-r\tPerform interactive repairs\n");
|
||||
fprintf(stderr, "\t-a\tPerform automatic repairs\n");
|
||||
fprintf(stderr, "\t-v\tverbose\n");
|
||||
fprintf(stderr, "\t-s\tOutputs super-block information\n");
|
||||
fprintf(stderr, "\t-m\tActivates MINIX-like \"mode not cleared\" warnings\n");
|
||||
fprintf(stderr, "\t-f\tForce file system check.\n\n");
|
||||
leave(16);
|
||||
}
|
||||
|
||||
|
||||
@@ -32,29 +32,55 @@
|
||||
#include <ctype.h>
|
||||
|
||||
static const char grep_usage[] =
|
||||
"grep [-ihn]... PATTERN [FILE]...\n"
|
||||
"grep [OPTIONS]... PATTERN [FILE]...\n\n"
|
||||
"Search for PATTERN in each FILE or standard input.\n\n"
|
||||
"OPTIONS:\n"
|
||||
"\t-h\tsuppress the prefixing filename on output\n"
|
||||
"\t-i\tignore case distinctions\n"
|
||||
"\t-n\tprint line number with output lines\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of grep matches full regexps.\n";
|
||||
"This version of grep matches full regular expresions.\n";
|
||||
#else
|
||||
"This version of grep matches strings (not full regexps).\n";
|
||||
"This version of grep matches strings (not regular expresions).\n";
|
||||
#endif
|
||||
|
||||
|
||||
static void do_grep(FILE *fp, char* needle, char *fileName, int tellName, int ignoreCase, int tellLine)
|
||||
{
|
||||
char *cp;
|
||||
long line = 0;
|
||||
char haystack[BUF_SIZE];
|
||||
|
||||
while (fgets (haystack, sizeof (haystack), fp)) {
|
||||
line++;
|
||||
cp = &haystack[strlen (haystack) - 1];
|
||||
|
||||
if (*cp != '\n')
|
||||
fprintf (stderr, "%s: Line too long\n", fileName);
|
||||
|
||||
if (find_match(haystack, needle, ignoreCase) == TRUE) {
|
||||
if (tellName==TRUE)
|
||||
printf ("%s:", fileName);
|
||||
|
||||
if (tellLine==TRUE)
|
||||
printf ("%ld:", line);
|
||||
|
||||
fputs (haystack, stdout);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
extern int grep_main (int argc, char **argv)
|
||||
{
|
||||
FILE *fp;
|
||||
char *needle;
|
||||
char *name;
|
||||
char *cp;
|
||||
int tellName=TRUE;
|
||||
char *needle;
|
||||
char *fileName;
|
||||
int tellName=FALSE;
|
||||
int ignoreCase=FALSE;
|
||||
int tellLine=FALSE;
|
||||
long line;
|
||||
char haystack[BUF_SIZE];
|
||||
|
||||
|
||||
ignoreCase = FALSE;
|
||||
tellLine = FALSE;
|
||||
@@ -76,7 +102,7 @@ extern int grep_main (int argc, char **argv)
|
||||
break;
|
||||
|
||||
case 'h':
|
||||
tellName = FALSE;
|
||||
tellName = TRUE;
|
||||
break;
|
||||
|
||||
case 'n':
|
||||
@@ -91,39 +117,24 @@ extern int grep_main (int argc, char **argv)
|
||||
needle = *argv++;
|
||||
argc--;
|
||||
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
if (argc==0) {
|
||||
do_grep( stdin, needle, "stdin", FALSE, ignoreCase, tellLine);
|
||||
} else {
|
||||
while (argc-- > 0) {
|
||||
fileName = *argv++;
|
||||
|
||||
fp = fopen (name, "r");
|
||||
if (fp == NULL) {
|
||||
perror (name);
|
||||
continue;
|
||||
}
|
||||
|
||||
line = 0;
|
||||
|
||||
while (fgets (haystack, sizeof (haystack), fp)) {
|
||||
line++;
|
||||
cp = &haystack[strlen (haystack) - 1];
|
||||
|
||||
if (*cp != '\n')
|
||||
fprintf (stderr, "%s: Line too long\n", name);
|
||||
|
||||
if (find_match(haystack, needle, ignoreCase) == TRUE) {
|
||||
if (tellName==TRUE)
|
||||
printf ("%s: ", name);
|
||||
|
||||
if (tellLine==TRUE)
|
||||
printf ("%ld: ", line);
|
||||
|
||||
fputs (haystack, stdout);
|
||||
fp = fopen (fileName, "r");
|
||||
if (fp == NULL) {
|
||||
perror (fileName);
|
||||
continue;
|
||||
}
|
||||
|
||||
do_grep( fp, needle, fileName, tellName, ignoreCase, tellLine);
|
||||
|
||||
if (ferror (fp))
|
||||
perror (fileName);
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
if (ferror (fp))
|
||||
perror (name);
|
||||
|
||||
fclose (fp);
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
@@ -7,11 +7,17 @@
|
||||
#include "internal.h"
|
||||
#ifdef BB_GZIP
|
||||
|
||||
#ifndef BB_ZCAT
|
||||
#error you need zcat to have gzip support!
|
||||
#endif
|
||||
//#ifndef BB_ZCAT
|
||||
//#error you need zcat to have gzip support!
|
||||
//#endif
|
||||
|
||||
static const char gzip_usage[] =
|
||||
"gzip [OPTION]... FILE\n\n"
|
||||
"Compress FILE with maximum compression.\n"
|
||||
"When FILE is -, reads standard input. Implies -c.\n\n"
|
||||
"Options:\n"
|
||||
"\t-c\tWrite output to standard output instead of FILE.gz\n";
|
||||
|
||||
static const char gzip_usage[] = "gzip\nignores all command line arguments\ncompress stdin to stdout with -9 compression\n";
|
||||
|
||||
/* gzip.h -- common declarations for all gzip modules
|
||||
* Copyright (C) 1992-1993 Jean-loup Gailly.
|
||||
@@ -210,7 +216,6 @@ extern int exit_code; /* program exit code */
|
||||
extern int verbose; /* be verbose (-v) */
|
||||
extern int quiet; /* be quiet (-q) */
|
||||
extern int test; /* check .z file integrity */
|
||||
extern int to_stdout; /* output to stdout (-c) */
|
||||
extern int save_orig_name; /* set if original name must be saved */
|
||||
|
||||
#define get_byte() (inptr < insize ? inbuf[inptr++] : fill_inbuf(0))
|
||||
@@ -272,7 +277,7 @@ extern int save_orig_name; /* set if original name must be saved */
|
||||
#define WARN(msg) {if (!quiet) fprintf msg ; \
|
||||
if (exit_code == OK) exit_code = WARNING;}
|
||||
|
||||
local void do_exit(int exitcode);
|
||||
local void do_exit(int exitcode) __attribute__ ((noreturn));
|
||||
|
||||
/* in zip.c: */
|
||||
extern int zip OF((int in, int out));
|
||||
@@ -1726,7 +1731,6 @@ DECLARE(uch, window, 2L*WSIZE);
|
||||
/* local variables */
|
||||
|
||||
int ascii = 0; /* convert end-of-lines to local OS conventions */
|
||||
int to_stdout = 0; /* output to stdout (-c) */
|
||||
int decompress = 0; /* decompress (-d) */
|
||||
int no_name = -1; /* don't save or restore the original file name */
|
||||
int no_time = -1; /* don't save or restore the original file time */
|
||||
@@ -1758,17 +1762,42 @@ unsigned outcnt; /* bytes in output buffer */
|
||||
|
||||
/* local functions */
|
||||
|
||||
local void treat_stdin OF((void));
|
||||
static int (*work) OF((int infile, int outfile)) = zip; /* function to call */
|
||||
|
||||
#define strequ(s1, s2) (strcmp((s1),(s2)) == 0)
|
||||
|
||||
/* ======================================================================== */
|
||||
// int main (argc, argv)
|
||||
// int argc;
|
||||
// char **argv;
|
||||
int gzip_main(int argc, char * * argv)
|
||||
int gzip_main(int argc, char ** argv)
|
||||
{
|
||||
int result;
|
||||
int inFileNum;
|
||||
int outFileNum;
|
||||
struct stat statBuf;
|
||||
char* delFileName;
|
||||
int tostdout = 0;
|
||||
int fromstdin = 0;
|
||||
|
||||
if (argc==1)
|
||||
usage(gzip_usage);
|
||||
|
||||
/* Parse any options */
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
if (*((*argv)+1) == '\0') {
|
||||
fromstdin = 1;
|
||||
tostdout = 1;
|
||||
}
|
||||
while (*(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 'c':
|
||||
tostdout = 1;
|
||||
break;
|
||||
default:
|
||||
usage(gzip_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreground = signal(SIGINT, SIG_IGN) != SIG_IGN;
|
||||
if (foreground) {
|
||||
(void) signal (SIGINT, (sig_type)abort_gzip);
|
||||
@@ -1787,8 +1816,6 @@ int gzip_main(int argc, char * * argv)
|
||||
strncpy(z_suffix, Z_SUFFIX, sizeof(z_suffix)-1);
|
||||
z_len = strlen(z_suffix);
|
||||
|
||||
to_stdout = 1;
|
||||
|
||||
/* Allocate all global buffers (for DYN_ALLOC option) */
|
||||
ALLOC(uch, inbuf, INBUFSIZ +INBUF_EXTRA);
|
||||
ALLOC(uch, outbuf, OUTBUFSIZ+OUTBUF_EXTRA);
|
||||
@@ -1801,33 +1828,84 @@ int gzip_main(int argc, char * * argv)
|
||||
ALLOC(ush, tab_prefix1, 1L<<(BITS-1));
|
||||
#endif
|
||||
|
||||
/* And get to work */
|
||||
treat_stdin();
|
||||
do_exit(exit_code);
|
||||
return exit_code; /* just to avoid lint warning */
|
||||
}
|
||||
if (fromstdin==1) {
|
||||
strcpy(ofname, "stdin");
|
||||
|
||||
/* ========================================================================
|
||||
* Compress or decompress stdin
|
||||
*/
|
||||
local void treat_stdin()
|
||||
{
|
||||
inFileNum=fileno(stdin);
|
||||
time_stamp = 0; /* time unknown by default */
|
||||
ifile_size = -1L; /* convention for unknown size */
|
||||
} else {
|
||||
/* Open up the input file */
|
||||
if (*argv=='\0')
|
||||
usage(gzip_usage);
|
||||
strncpy(ifname, *argv, MAX_PATH_LEN);
|
||||
|
||||
/* Open input fille */
|
||||
inFileNum=open( ifname, O_RDONLY);
|
||||
if (inFileNum < 0) {
|
||||
perror(ifname);
|
||||
do_exit(WARNING);
|
||||
}
|
||||
/* Get the time stamp on the input file. */
|
||||
result = stat(ifname, &statBuf);
|
||||
if (result < 0) {
|
||||
perror(ifname);
|
||||
do_exit(WARNING);
|
||||
}
|
||||
time_stamp = statBuf.st_ctime;
|
||||
ifile_size = statBuf.st_size;
|
||||
}
|
||||
|
||||
|
||||
if (tostdout==1) {
|
||||
/* And get to work */
|
||||
strcpy(ofname, "stdout");
|
||||
outFileNum=fileno(stdout);
|
||||
SET_BINARY_MODE(fileno(stdout));
|
||||
strcpy(ifname, "stdin");
|
||||
strcpy(ofname, "stdout");
|
||||
|
||||
/* Get the time stamp on the input file. */
|
||||
time_stamp = 0; /* time unknown by default */
|
||||
clear_bufs(); /* clear input and output buffers */
|
||||
part_nb = 0;
|
||||
|
||||
ifile_size = -1L; /* convention for unknown size */
|
||||
/* Actually do the compression/decompression. */
|
||||
zip(inFileNum, outFileNum);
|
||||
|
||||
clear_bufs(); /* clear input and output buffers */
|
||||
to_stdout = 1;
|
||||
part_nb = 0;
|
||||
} else {
|
||||
|
||||
/* Actually do the compression/decompression. Loop over zipped members.
|
||||
*/
|
||||
if ((*work)(fileno(stdin), fileno(stdout)) != OK) return;
|
||||
/* And get to work */
|
||||
strncpy(ofname, ifname, MAX_PATH_LEN-4);
|
||||
strcat(ofname, ".gz");
|
||||
|
||||
|
||||
/* Open output fille */
|
||||
outFileNum=open( ofname, O_RDWR|O_CREAT|O_EXCL|O_NOFOLLOW);
|
||||
if (outFileNum < 0) {
|
||||
perror(ofname);
|
||||
do_exit(WARNING);
|
||||
}
|
||||
SET_BINARY_MODE(outFileNum);
|
||||
/* Set permissions on the file */
|
||||
fchmod(outFileNum, statBuf.st_mode);
|
||||
|
||||
clear_bufs(); /* clear input and output buffers */
|
||||
part_nb = 0;
|
||||
|
||||
/* Actually do the compression/decompression. */
|
||||
result=zip(inFileNum, outFileNum);
|
||||
close( outFileNum);
|
||||
close( inFileNum);
|
||||
/* Delete the original file */
|
||||
if (result == OK)
|
||||
delFileName=ifname;
|
||||
else
|
||||
delFileName=ofname;
|
||||
|
||||
if (unlink (delFileName) < 0) {
|
||||
perror (delFileName);
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
do_exit(exit_code);
|
||||
}
|
||||
|
||||
/* ========================================================================
|
||||
@@ -2941,8 +3019,6 @@ local void set_file_type()
|
||||
extern int errno;
|
||||
#endif
|
||||
|
||||
extern ulg crc_32_tab[]; /* crc table, defined below */
|
||||
|
||||
/* ===========================================================================
|
||||
* Copy input to output unchanged: zcat == cat with --force.
|
||||
* IN assertion: insize bytes have already been read in inbuf.
|
||||
@@ -3150,6 +3226,7 @@ int zip(in, out)
|
||||
|
||||
/* Write the header to the gzip file. See algorithm.doc for the format */
|
||||
|
||||
|
||||
method = DEFLATED;
|
||||
put_byte(GZIP_MAGIC[0]); /* magic header */
|
||||
put_byte(GZIP_MAGIC[1]);
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
extern int
|
||||
halt_main(int argc, char ** argv)
|
||||
{
|
||||
exit( kill(1, SIGUSR1));
|
||||
/* don't assume init's pid == 1 */
|
||||
exit( kill(findInitPid(), SIGUSR1));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* Mini head implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by John Beppu <beppu@lineo.com>
|
||||
*
|
||||
* 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 "internal.h"
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
const char head_usage[] =
|
||||
"Usage: head [FILE]...\n\n"
|
||||
"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";
|
||||
|
||||
int
|
||||
head(int len, FILE *src)
|
||||
{
|
||||
int i;
|
||||
char buffer[1024];
|
||||
|
||||
for (i = 0; i < len; i++) {
|
||||
fgets(buffer, 1024, src);
|
||||
if (feof(src)) { break; }
|
||||
fputs(buffer, stdout);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* BusyBoxed head(1) */
|
||||
int
|
||||
head_main(int argc, char **argv)
|
||||
{
|
||||
int i = 1;
|
||||
char opt;
|
||||
int len = 10;
|
||||
|
||||
/* 1st option is potentially special */
|
||||
if ((argv[1][0] == '-') && isDecimal(argv[1][1])) {
|
||||
int tmplen = atoi(&argv[1][1]);
|
||||
if (tmplen) { len = tmplen; }
|
||||
i = 2;
|
||||
}
|
||||
|
||||
/* parse argv[] */
|
||||
for ( ; i < argc; i++) {
|
||||
if (argv[i][0] == '-') {
|
||||
opt = argv[i][1];
|
||||
switch (opt) {
|
||||
case '-':
|
||||
case 'h':
|
||||
usage(head_usage);
|
||||
default:
|
||||
fprintf(stderr, "head: invalid option -- %c\n", opt);
|
||||
usage(head_usage);
|
||||
}
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* get rest of argv[] or stdin if nothing's left */
|
||||
if (i >= argc) {
|
||||
head(len, stdin);
|
||||
|
||||
} else {
|
||||
int need_headers = ((argc - i) > 1);
|
||||
for ( ; i < argc; i++) {
|
||||
FILE *src;
|
||||
src = fopen(argv[i], "r");
|
||||
if (!src) {
|
||||
fprintf(stderr,"head: %s: %s\n", argv[i], strerror(errno));
|
||||
} else {
|
||||
/* emulating GNU behaviour */
|
||||
if (need_headers) {
|
||||
fprintf(stdout, "==> %s <==\n", argv[i]);
|
||||
}
|
||||
head(len, src);
|
||||
if (i < argc - 1) {
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
exit(0);
|
||||
}
|
||||
|
||||
/* $Id: head.c,v 1.2 1999/12/10 08:29:20 andersen Exp $ */
|
||||
+138
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* $Id: hostname.c,v 1.5 1999/12/09 06:11:36 andersen Exp $
|
||||
* Mini hostname implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
|
||||
*
|
||||
* adjusted by Erik Andersen <andersee@debian.org> to remove
|
||||
* use of long options and GNU getopt. Improved the usage info.
|
||||
*
|
||||
* 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 "internal.h"
|
||||
#include <errno.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static const char* hostname_usage =
|
||||
"hostname [OPTION] {hostname | -F file}\n\n"
|
||||
"Get or set the hostname or DNS domain name. If a hostname is given\n"
|
||||
"(or a file with the -F parameter), the host name will be set.\n\n"
|
||||
"Options:\n"
|
||||
"\t-s\t\tShort\n"
|
||||
"\t-i\t\tAddresses for the hostname\n"
|
||||
"\t-d\t\tDNS domain name\n"
|
||||
"\t-F FILE\t\tUse the contents of FILE to specify the hostname\n";
|
||||
|
||||
|
||||
void do_sethostname(char *s, int isfile)
|
||||
{
|
||||
FILE *f;
|
||||
char buf[255];
|
||||
|
||||
if (!s) return;
|
||||
if (!isfile) {
|
||||
if (sethostname(s, strlen(s)) < 0) {
|
||||
if (errno == EPERM)
|
||||
fprintf(stderr, "hostname: you must be root to change the hostname\n");
|
||||
else
|
||||
perror("sethostname");
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
if ((f = fopen(s, "r")) == NULL) {
|
||||
perror(s);
|
||||
exit(1);
|
||||
} else {
|
||||
fgets(buf, 255, f);
|
||||
fclose(f);
|
||||
if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
|
||||
if (sethostname(buf, strlen(buf)) < 0) {
|
||||
perror("sethostname");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int hostname_main(int argc, char **argv)
|
||||
{
|
||||
int opt_short = 0;
|
||||
int opt_domain = 0;
|
||||
int opt_ip = 0;
|
||||
struct hostent *h;
|
||||
char *filename = NULL;
|
||||
char buf[255];
|
||||
char *s = NULL;
|
||||
|
||||
if (argc < 1) usage(hostname_usage);
|
||||
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
while (*(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 's':
|
||||
opt_short = 1;
|
||||
break;
|
||||
case 'i':
|
||||
opt_ip = 1;
|
||||
break;
|
||||
case 'd':
|
||||
opt_domain = 1;
|
||||
break;
|
||||
case 'F':
|
||||
filename = optarg;
|
||||
if (--argc == 0) {
|
||||
usage(hostname_usage);
|
||||
}
|
||||
filename = *(++argv);
|
||||
break;
|
||||
default:
|
||||
usage(hostname_usage);
|
||||
}
|
||||
if (filename!=NULL)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc >= 1) {
|
||||
do_sethostname(*argv, 0);
|
||||
} else if (filename!=NULL) {
|
||||
do_sethostname(filename, 1);
|
||||
} else {
|
||||
gethostname(buf, 255);
|
||||
if (opt_short) {
|
||||
s = strchr(buf, '.');
|
||||
if (!s) s = buf; *s = 0;
|
||||
printf("%s\n", buf);
|
||||
} else if (opt_domain) {
|
||||
s = strchr(buf, '.');
|
||||
printf("%s\n", (s ? s+1 : ""));
|
||||
} else if (opt_ip) {
|
||||
h = gethostbyname(buf);
|
||||
if (!h) {
|
||||
printf("Host not found\n");
|
||||
exit(1);
|
||||
}
|
||||
printf("%s\n", inet_ntoa(*(struct in_addr *)(h->h_addr)));
|
||||
} else {
|
||||
printf("%s\n", buf);
|
||||
}
|
||||
}
|
||||
exit( 0);
|
||||
}
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <paths.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -40,20 +41,27 @@
|
||||
#include <linux/serial.h> /* for serial_struct */
|
||||
#include <sys/vt.h> /* for vt_stat */
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef BB_SYSLOGD
|
||||
#include <sys/syslog.h>
|
||||
#endif
|
||||
|
||||
#if ! defined BB_FEATURE_USE_PROCFS
|
||||
#error Sorry, I depend on the /proc filesystem right now.
|
||||
#endif
|
||||
|
||||
|
||||
#define VT_CONSOLE "/dev/console" /* Logical system console */
|
||||
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
|
||||
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
|
||||
#define VT_LOG "/dev/tty3" /* Virtual console */
|
||||
#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */
|
||||
#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
|
||||
#define GETTY "/sbin/getty" /* Default location of getty */
|
||||
#define SHELL "/bin/sh" /* Default shell */
|
||||
#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */
|
||||
#define PATH_DEFAULT "PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
|
||||
|
||||
#define LOG 0x1
|
||||
#define CONSOLE 0x2
|
||||
static char *console = VT_CONSOLE;
|
||||
static char *console = _PATH_CONSOLE;
|
||||
static char *second_console = VT_SECONDARY;
|
||||
static char *log = VT_LOG;
|
||||
static int kernel_version = 0;
|
||||
@@ -83,27 +91,47 @@ int device_open(char *device, int mode)
|
||||
void message(int device, char *fmt, ...)
|
||||
{
|
||||
int fd;
|
||||
static int log_fd=-1;
|
||||
va_list arguments;
|
||||
#ifdef BB_SYSLOGD
|
||||
|
||||
/* Log the message to syslogd */
|
||||
if (device & LOG ) {
|
||||
char msg[1024];
|
||||
va_start(arguments, fmt);
|
||||
vsnprintf(msg, sizeof(msg), fmt, arguments);
|
||||
va_end(arguments);
|
||||
syslog(LOG_DAEMON|LOG_NOTICE, msg);
|
||||
}
|
||||
|
||||
#else
|
||||
static int log_fd=-1;
|
||||
|
||||
/* Take full control of the log tty, and never close it.
|
||||
* It's mine, all mine! Muhahahaha! */
|
||||
if (log_fd==-1) {
|
||||
if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
|
||||
if (log_fd < 0) {
|
||||
if (log == NULL) {
|
||||
/* don't even try to log, because there is no such console */
|
||||
log_fd = -2;
|
||||
/* log to main console instead */
|
||||
device = CONSOLE;
|
||||
}
|
||||
else if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
|
||||
log_fd=-1;
|
||||
fprintf(stderr, "Bummer, can't write to log on %s!\r\n", log);
|
||||
fflush(stderr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( (device & LOG) && (log_fd != -1) ) {
|
||||
if ( (device & LOG) && (log_fd >= 0) ) {
|
||||
va_start(arguments, fmt);
|
||||
vdprintf(log_fd, fmt, arguments);
|
||||
va_end(arguments);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (device & CONSOLE) {
|
||||
if ((fd = device_open(console, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) {
|
||||
/* Always send console messages to /dev/console so people will see them. */
|
||||
if ((fd = device_open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) {
|
||||
va_start(arguments, fmt);
|
||||
vdprintf(fd, fmt, arguments);
|
||||
va_end(arguments);
|
||||
@@ -124,31 +152,31 @@ void set_term( int fd)
|
||||
{
|
||||
struct termios tty;
|
||||
static const char control_characters[] = {
|
||||
'\003', '\034', '\177', '\030', '\004', '\0',
|
||||
'\003', '\034', '\177', '\025', '\004', '\0',
|
||||
'\1', '\0', '\021', '\023', '\032', '\0', '\022',
|
||||
'\017', '\027', '\026', '\0'
|
||||
};
|
||||
|
||||
tcgetattr(fd, &tty);
|
||||
|
||||
/* Make it be sane */
|
||||
tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
|
||||
tty.c_cflag |= HUPCL|CLOCAL;
|
||||
|
||||
/* input modes */
|
||||
tty.c_iflag = IGNPAR|ICRNL|IXON|IXOFF|IXANY;
|
||||
/* set control chars */
|
||||
memcpy(tty.c_cc, control_characters, sizeof(control_characters));
|
||||
|
||||
/* use line dicipline 0 */
|
||||
tty.c_line = 0;
|
||||
|
||||
/* Make it be sane */
|
||||
//tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
|
||||
//tty.c_cflag |= HUPCL|CLOCAL;
|
||||
|
||||
/* input modes */
|
||||
tty.c_iflag = ICRNL|IXON|IXOFF;
|
||||
|
||||
/* output modes */
|
||||
tty.c_oflag = OPOST|ONLCR;
|
||||
|
||||
/* local modes */
|
||||
tty.c_lflag = ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOPRT|ECHOKE|IEXTEN;
|
||||
|
||||
/* control chars */
|
||||
memcpy(tty.c_cc, control_characters, sizeof(control_characters));
|
||||
tty.c_lflag = ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOKE|IEXTEN;
|
||||
|
||||
tcsetattr(fd, TCSANOW, &tty);
|
||||
}
|
||||
@@ -180,32 +208,47 @@ static void console_init()
|
||||
int fd;
|
||||
int tried_devcons = 0;
|
||||
int tried_vtprimary = 0;
|
||||
struct serial_struct sr;
|
||||
char *s;
|
||||
|
||||
if ((s = getenv("CONSOLE")) != NULL) {
|
||||
console = s;
|
||||
/* Apparently the sparc does wierd things... */
|
||||
#if defined (__sparc__)
|
||||
if (strncmp( s, "/dev/tty", 8 )==0) {
|
||||
switch( s[8]) {
|
||||
case 'a':
|
||||
s=SERIAL_CON0;
|
||||
break;
|
||||
case 'b':
|
||||
s=SERIAL_CON1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if #cpu(sparc)
|
||||
/* sparc kernel supports console=tty[ab] parameter which is also
|
||||
* passed to init, so catch it here */
|
||||
else if ((s = getenv("console")) != NULL) {
|
||||
/* remap tty[ab] to /dev/ttyS[01] */
|
||||
if (strcmp( s, "ttya" )==0)
|
||||
console = SERIAL_CON0;
|
||||
else if (strcmp( s, "ttyb" )==0)
|
||||
console = SERIAL_CON1;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
console = VT_CONSOLE;
|
||||
tried_devcons++;
|
||||
else {
|
||||
struct vt_stat vt;
|
||||
static char the_console[13];
|
||||
|
||||
console = the_console;
|
||||
/* 2.2 kernels: identify the real console backend and try to use it */
|
||||
if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
|
||||
/* this is a serial console */
|
||||
snprintf( the_console, sizeof the_console, "/dev/ttyS%d", sr.line );
|
||||
}
|
||||
else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
|
||||
/* this is linux virtual tty */
|
||||
snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
|
||||
} else {
|
||||
console = _PATH_CONSOLE;
|
||||
tried_devcons++;
|
||||
}
|
||||
}
|
||||
|
||||
while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) {
|
||||
/* Can't open selected console -- try /dev/console */
|
||||
if (!tried_devcons) {
|
||||
tried_devcons++;
|
||||
console = VT_CONSOLE;
|
||||
console = _PATH_CONSOLE;
|
||||
continue;
|
||||
}
|
||||
/* Can't open selected console -- try vt1 */
|
||||
@@ -219,8 +262,16 @@ static void console_init()
|
||||
if (fd < 0)
|
||||
/* Perhaps we should panic here? */
|
||||
console = "/dev/null";
|
||||
else
|
||||
else {
|
||||
/* check for serial console and disable logging to tty3 & running a
|
||||
* shell to tty2 */
|
||||
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
|
||||
message(LOG|CONSOLE, "serial console detected. Disabling 2nd virtual terminal.\r\n", console );
|
||||
log = NULL;
|
||||
second_console = NULL;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
message(LOG, "console=%s\n", console );
|
||||
}
|
||||
|
||||
@@ -285,9 +336,9 @@ static pid_t run(const char * const* command,
|
||||
}
|
||||
|
||||
/* Log the process name and args */
|
||||
message(LOG, "Starting pid %d, console %s: '", getpid(), terminal);
|
||||
while ( *cmd) message(LOG, "%s ", *cmd++);
|
||||
message(LOG, "'\r\n");
|
||||
message(LOG|CONSOLE, "Starting pid %d, console %s: '", getpid(), terminal);
|
||||
while ( *cmd) message(LOG|CONSOLE, "%s ", *cmd++);
|
||||
message(LOG|CONSOLE, "'\r\n");
|
||||
|
||||
/* Now run it. The new program will take over this PID,
|
||||
* so nothing further in init.c should be run. */
|
||||
@@ -327,13 +378,13 @@ goodnight:
|
||||
static void shutdown_system(void)
|
||||
{
|
||||
const char* const swap_off_cmd[] = { "swapoff", "swapoff", "-a", 0};
|
||||
const char* const umount_cmd[] = { "umount", "umount", "-a", "-n", 0};
|
||||
const char* const umount_cmd[] = { "umount", "umount", "-a", 0};
|
||||
|
||||
#ifndef DEBUG_INIT
|
||||
/* Allow Ctrl-Alt-Del to reboot system. */
|
||||
reboot(RB_ENABLE_CAD);
|
||||
#endif
|
||||
message(CONSOLE, "The system is going down NOW !!\r\n");
|
||||
message(CONSOLE, "\r\nThe system is going down NOW !!\r\n");
|
||||
sync();
|
||||
/* Send signals to every process _except_ pid 1 */
|
||||
message(CONSOLE, "Sending SIGHUP to all processes.\r\n");
|
||||
@@ -347,7 +398,9 @@ static void shutdown_system(void)
|
||||
kill(-1, SIGKILL);
|
||||
#endif
|
||||
sleep(1);
|
||||
message(CONSOLE, "Disabling swap.\r\n");
|
||||
waitfor(run( swap_off_cmd, console, FALSE));
|
||||
message(CONSOLE, "Unmounting filesystems.\r\n");
|
||||
waitfor(run( umount_cmd, console, FALSE));
|
||||
sync();
|
||||
if (kernel_version > 0 && kernel_version <= 2 * 65536 + 2 * 256 + 11) {
|
||||
@@ -365,8 +418,10 @@ static void halt_signal(int sig)
|
||||
"The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
|
||||
sync();
|
||||
#ifndef DEBUG_INIT
|
||||
reboot(RB_HALT_SYSTEM);
|
||||
//reboot(RB_POWER_OFF);
|
||||
if (sig == SIGUSR2)
|
||||
reboot(RB_POWER_OFF);
|
||||
else
|
||||
reboot(RB_HALT_SYSTEM);
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
@@ -384,15 +439,26 @@ static void reboot_signal(int sig)
|
||||
|
||||
extern int init_main(int argc, char **argv)
|
||||
{
|
||||
int run_rc = TRUE;
|
||||
int wait_for_enter = TRUE;
|
||||
int run_rc = FALSE;
|
||||
int single = FALSE;
|
||||
int wait_for_enter_tty1 = TRUE;
|
||||
int wait_for_enter_tty2 = TRUE;
|
||||
pid_t pid1 = 0;
|
||||
pid_t pid2 = 0;
|
||||
struct stat statbuf;
|
||||
const char* const init_commands[] = { INITSCRIPT, INITSCRIPT, 0};
|
||||
const char* const shell_commands[] = { SHELL, "-" SHELL, 0};
|
||||
const char* const* tty0_commands = shell_commands;
|
||||
const char* const* tty1_commands = shell_commands;
|
||||
char which_vt1[30];
|
||||
char which_vt2[30];
|
||||
const char* const rc_script_command[] = { INITSCRIPT, INITSCRIPT, 0};
|
||||
const char* const getty1_command[] = { GETTY, GETTY, "38400", which_vt1, 0};
|
||||
const char* const getty2_command[] = { GETTY, GETTY, "38400", which_vt2, 0};
|
||||
const char* const shell_command[] = { SHELL, "-" SHELL, 0};
|
||||
const char* const* tty1_command = shell_command;
|
||||
const char* const* tty2_command = shell_command;
|
||||
#ifdef BB_INIT_CMD_IF_RC_SCRIPT_EXITS
|
||||
const char* const rc_exit_command[] = { "BB_INIT_CMD_IF_RC_SCRIPT_EXITS",
|
||||
"BB_INIT_CMD_IF_RC_SCRIPT_EXITS", 0 };
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_INIT
|
||||
char *hello_msg_format =
|
||||
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n";
|
||||
@@ -402,13 +468,14 @@ extern int init_main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
|
||||
/* Check if we are supposed to be in single user mode */
|
||||
if ( argc > 1 && (!strcmp(argv[1], "single") ||
|
||||
!strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
|
||||
run_rc = FALSE;
|
||||
#ifndef DEBUG_INIT
|
||||
/* Expect to be PID 1 iff we are run as init (not linuxrc) */
|
||||
if (getpid() != 1 && strstr(argv[0], "init")!=NULL ) {
|
||||
usage( "init\n\nInit is the parent of all processes.\n\n"
|
||||
"This version of init is designed to be run only by the kernel\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Set up sig handlers -- be sure to
|
||||
* clear all of these in run() */
|
||||
signal(SIGUSR1, halt_signal);
|
||||
@@ -433,7 +500,7 @@ extern int init_main(int argc, char **argv)
|
||||
setsid();
|
||||
|
||||
/* Make sure PATH is set to something sane */
|
||||
putenv(PATH_DEFAULT);
|
||||
putenv(_PATH_STDPATH);
|
||||
|
||||
|
||||
/* Hello world */
|
||||
@@ -454,27 +521,59 @@ extern int init_main(int argc, char **argv)
|
||||
/* Make sure there is enough memory to do something useful. */
|
||||
check_memory();
|
||||
|
||||
|
||||
/* Make sure an init script exists before trying to run it */
|
||||
if (run_rc == TRUE && stat(INITSCRIPT, &statbuf)==0) {
|
||||
wait_for_enter = FALSE;
|
||||
tty0_commands = init_commands;
|
||||
/* Check if we are supposed to be in single user mode */
|
||||
if ( argc > 1 && (!strcmp(argv[1], "single") ||
|
||||
!strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
|
||||
single = TRUE;
|
||||
tty1_command = shell_command;
|
||||
tty2_command = shell_command;
|
||||
}
|
||||
|
||||
/* Make sure an init script exists before trying to run it */
|
||||
if (single==FALSE && stat(INITSCRIPT, &statbuf)==0) {
|
||||
run_rc = TRUE;
|
||||
wait_for_enter_tty1 = FALSE;
|
||||
tty1_command = rc_script_command;
|
||||
}
|
||||
|
||||
/* Make sure /sbin/getty exists before trying to run it */
|
||||
if (stat(GETTY, &statbuf)==0) {
|
||||
char* where;
|
||||
/* First do tty2 */
|
||||
wait_for_enter_tty2 = FALSE;
|
||||
where = strrchr( second_console, '/');
|
||||
if ( where != NULL) {
|
||||
where++;
|
||||
strncpy( which_vt2, where, sizeof(which_vt2));
|
||||
}
|
||||
tty2_command = getty2_command;
|
||||
|
||||
/* Ok, now launch the rc script and/or prepare to
|
||||
* start up some VTs if somebody hits enter...
|
||||
*/
|
||||
/* Check on hooking a getty onto tty1 */
|
||||
if (run_rc == FALSE && single==FALSE) {
|
||||
wait_for_enter_tty1 = FALSE;
|
||||
where = strrchr( console, '/');
|
||||
if ( where != NULL) {
|
||||
where++;
|
||||
strncpy( which_vt1, where, sizeof(which_vt1));
|
||||
}
|
||||
tty1_command = getty1_command;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Ok, now launch the tty1_command and tty2_command */
|
||||
for (;;) {
|
||||
pid_t wpid;
|
||||
int status;
|
||||
|
||||
if (pid1 == 0 && tty0_commands) {
|
||||
pid1 = run(tty0_commands, console, wait_for_enter);
|
||||
if (pid1 == 0 && tty1_command) {
|
||||
pid1 = run(tty1_command, console, wait_for_enter_tty1);
|
||||
}
|
||||
if (pid2 == 0 && tty1_commands) {
|
||||
pid2 = run(tty1_commands, second_console, TRUE);
|
||||
#ifdef BB_FEATURE_INIT_SECOND_CONSOLE
|
||||
if (pid2 == 0 && tty2_command && second_console) {
|
||||
pid2 = run(tty2_command, second_console, wait_for_enter_tty2);
|
||||
}
|
||||
#endif
|
||||
wpid = wait(&status);
|
||||
if (wpid > 0 ) {
|
||||
message(LOG, "pid %d exited, status=%x.\n", wpid, status);
|
||||
@@ -483,19 +582,21 @@ extern int init_main(int argc, char **argv)
|
||||
if (wpid == pid1) {
|
||||
if (run_rc == FALSE) {
|
||||
pid1 = 0;
|
||||
}
|
||||
#if 0
|
||||
/* Turn this on to start a shell on the console if the init script exits.... */
|
||||
}
|
||||
#ifdef BB_INIT_CMD_IF_RC_SCRIPT_EXITS
|
||||
else {
|
||||
pid1 = 0;
|
||||
run_rc=FALSE;
|
||||
wait_for_enter=TRUE;
|
||||
tty0_commands=shell_commands;
|
||||
wait_for_enter_tty1=TRUE;
|
||||
tty1_command=rc_exit_command;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef BB_FEATURE_INIT_SECOND_CONSOLE
|
||||
if (wpid == pid2) {
|
||||
pid2 = 0;
|
||||
}
|
||||
#endif
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
+2
-1
@@ -26,6 +26,7 @@
|
||||
extern int
|
||||
halt_main(int argc, char ** argv)
|
||||
{
|
||||
exit( kill(1, SIGUSR1));
|
||||
/* don't assume init's pid == 1 */
|
||||
exit( kill(findInitPid(), SIGUSR1));
|
||||
}
|
||||
|
||||
+173
-72
@@ -29,6 +29,7 @@
|
||||
#include <errno.h>
|
||||
#include <signal.h>
|
||||
#include <termios.h>
|
||||
#include <paths.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/fcntl.h>
|
||||
#include <sys/wait.h>
|
||||
@@ -40,20 +41,27 @@
|
||||
#include <linux/serial.h> /* for serial_struct */
|
||||
#include <sys/vt.h> /* for vt_stat */
|
||||
#include <sys/ioctl.h>
|
||||
#ifdef BB_SYSLOGD
|
||||
#include <sys/syslog.h>
|
||||
#endif
|
||||
|
||||
#if ! defined BB_FEATURE_USE_PROCFS
|
||||
#error Sorry, I depend on the /proc filesystem right now.
|
||||
#endif
|
||||
|
||||
|
||||
#define VT_CONSOLE "/dev/console" /* Logical system console */
|
||||
#define VT_PRIMARY "/dev/tty1" /* Primary virtual console */
|
||||
#define VT_SECONDARY "/dev/tty2" /* Virtual console */
|
||||
#define VT_LOG "/dev/tty3" /* Virtual console */
|
||||
#define SERIAL_CON0 "/dev/ttyS0" /* Primary serial console */
|
||||
#define SERIAL_CON1 "/dev/ttyS1" /* Serial console */
|
||||
#define GETTY "/sbin/getty" /* Default location of getty */
|
||||
#define SHELL "/bin/sh" /* Default shell */
|
||||
#define INITSCRIPT "/etc/init.d/rcS" /* Initscript. */
|
||||
#define PATH_DEFAULT "PATH=/usr/local/sbin:/sbin:/bin:/usr/sbin:/usr/bin"
|
||||
|
||||
#define LOG 0x1
|
||||
#define CONSOLE 0x2
|
||||
static char *console = VT_CONSOLE;
|
||||
static char *console = _PATH_CONSOLE;
|
||||
static char *second_console = VT_SECONDARY;
|
||||
static char *log = VT_LOG;
|
||||
static int kernel_version = 0;
|
||||
@@ -83,27 +91,47 @@ int device_open(char *device, int mode)
|
||||
void message(int device, char *fmt, ...)
|
||||
{
|
||||
int fd;
|
||||
static int log_fd=-1;
|
||||
va_list arguments;
|
||||
#ifdef BB_SYSLOGD
|
||||
|
||||
/* Log the message to syslogd */
|
||||
if (device & LOG ) {
|
||||
char msg[1024];
|
||||
va_start(arguments, fmt);
|
||||
vsnprintf(msg, sizeof(msg), fmt, arguments);
|
||||
va_end(arguments);
|
||||
syslog(LOG_DAEMON|LOG_NOTICE, msg);
|
||||
}
|
||||
|
||||
#else
|
||||
static int log_fd=-1;
|
||||
|
||||
/* Take full control of the log tty, and never close it.
|
||||
* It's mine, all mine! Muhahahaha! */
|
||||
if (log_fd==-1) {
|
||||
if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
|
||||
if (log_fd < 0) {
|
||||
if (log == NULL) {
|
||||
/* don't even try to log, because there is no such console */
|
||||
log_fd = -2;
|
||||
/* log to main console instead */
|
||||
device = CONSOLE;
|
||||
}
|
||||
else if ((log_fd = device_open(log, O_RDWR|O_NDELAY)) < 0) {
|
||||
log_fd=-1;
|
||||
fprintf(stderr, "Bummer, can't write to log on %s!\r\n", log);
|
||||
fflush(stderr);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if ( (device & LOG) && (log_fd != -1) ) {
|
||||
if ( (device & LOG) && (log_fd >= 0) ) {
|
||||
va_start(arguments, fmt);
|
||||
vdprintf(log_fd, fmt, arguments);
|
||||
va_end(arguments);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (device & CONSOLE) {
|
||||
if ((fd = device_open(console, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) {
|
||||
/* Always send console messages to /dev/console so people will see them. */
|
||||
if ((fd = device_open(_PATH_CONSOLE, O_WRONLY|O_NOCTTY|O_NDELAY)) >= 0) {
|
||||
va_start(arguments, fmt);
|
||||
vdprintf(fd, fmt, arguments);
|
||||
va_end(arguments);
|
||||
@@ -124,31 +152,31 @@ void set_term( int fd)
|
||||
{
|
||||
struct termios tty;
|
||||
static const char control_characters[] = {
|
||||
'\003', '\034', '\177', '\030', '\004', '\0',
|
||||
'\003', '\034', '\177', '\025', '\004', '\0',
|
||||
'\1', '\0', '\021', '\023', '\032', '\0', '\022',
|
||||
'\017', '\027', '\026', '\0'
|
||||
};
|
||||
|
||||
tcgetattr(fd, &tty);
|
||||
|
||||
/* Make it be sane */
|
||||
tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
|
||||
tty.c_cflag |= HUPCL|CLOCAL;
|
||||
|
||||
/* input modes */
|
||||
tty.c_iflag = IGNPAR|ICRNL|IXON|IXOFF|IXANY;
|
||||
/* set control chars */
|
||||
memcpy(tty.c_cc, control_characters, sizeof(control_characters));
|
||||
|
||||
/* use line dicipline 0 */
|
||||
tty.c_line = 0;
|
||||
|
||||
/* Make it be sane */
|
||||
//tty.c_cflag &= CBAUD|CBAUDEX|CSIZE|CSTOPB|PARENB|PARODD;
|
||||
//tty.c_cflag |= HUPCL|CLOCAL;
|
||||
|
||||
/* input modes */
|
||||
tty.c_iflag = ICRNL|IXON|IXOFF;
|
||||
|
||||
/* output modes */
|
||||
tty.c_oflag = OPOST|ONLCR;
|
||||
|
||||
/* local modes */
|
||||
tty.c_lflag = ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOPRT|ECHOKE|IEXTEN;
|
||||
|
||||
/* control chars */
|
||||
memcpy(tty.c_cc, control_characters, sizeof(control_characters));
|
||||
tty.c_lflag = ISIG|ICANON|ECHO|ECHOE|ECHOK|ECHOCTL|ECHOKE|IEXTEN;
|
||||
|
||||
tcsetattr(fd, TCSANOW, &tty);
|
||||
}
|
||||
@@ -180,32 +208,47 @@ static void console_init()
|
||||
int fd;
|
||||
int tried_devcons = 0;
|
||||
int tried_vtprimary = 0;
|
||||
struct serial_struct sr;
|
||||
char *s;
|
||||
|
||||
if ((s = getenv("CONSOLE")) != NULL) {
|
||||
console = s;
|
||||
/* Apparently the sparc does wierd things... */
|
||||
#if defined (__sparc__)
|
||||
if (strncmp( s, "/dev/tty", 8 )==0) {
|
||||
switch( s[8]) {
|
||||
case 'a':
|
||||
s=SERIAL_CON0;
|
||||
break;
|
||||
case 'b':
|
||||
s=SERIAL_CON1;
|
||||
}
|
||||
}
|
||||
}
|
||||
#if #cpu(sparc)
|
||||
/* sparc kernel supports console=tty[ab] parameter which is also
|
||||
* passed to init, so catch it here */
|
||||
else if ((s = getenv("console")) != NULL) {
|
||||
/* remap tty[ab] to /dev/ttyS[01] */
|
||||
if (strcmp( s, "ttya" )==0)
|
||||
console = SERIAL_CON0;
|
||||
else if (strcmp( s, "ttyb" )==0)
|
||||
console = SERIAL_CON1;
|
||||
}
|
||||
#endif
|
||||
} else {
|
||||
console = VT_CONSOLE;
|
||||
tried_devcons++;
|
||||
else {
|
||||
struct vt_stat vt;
|
||||
static char the_console[13];
|
||||
|
||||
console = the_console;
|
||||
/* 2.2 kernels: identify the real console backend and try to use it */
|
||||
if (ioctl(0, TIOCGSERIAL, &sr) == 0) {
|
||||
/* this is a serial console */
|
||||
snprintf( the_console, sizeof the_console, "/dev/ttyS%d", sr.line );
|
||||
}
|
||||
else if (ioctl(0, VT_GETSTATE, &vt) == 0) {
|
||||
/* this is linux virtual tty */
|
||||
snprintf( the_console, sizeof the_console, "/dev/tty%d", vt.v_active );
|
||||
} else {
|
||||
console = _PATH_CONSOLE;
|
||||
tried_devcons++;
|
||||
}
|
||||
}
|
||||
|
||||
while ((fd = open(console, O_RDONLY | O_NONBLOCK)) < 0) {
|
||||
/* Can't open selected console -- try /dev/console */
|
||||
if (!tried_devcons) {
|
||||
tried_devcons++;
|
||||
console = VT_CONSOLE;
|
||||
console = _PATH_CONSOLE;
|
||||
continue;
|
||||
}
|
||||
/* Can't open selected console -- try vt1 */
|
||||
@@ -219,8 +262,16 @@ static void console_init()
|
||||
if (fd < 0)
|
||||
/* Perhaps we should panic here? */
|
||||
console = "/dev/null";
|
||||
else
|
||||
else {
|
||||
/* check for serial console and disable logging to tty3 & running a
|
||||
* shell to tty2 */
|
||||
if (ioctl(0,TIOCGSERIAL,&sr) == 0) {
|
||||
message(LOG|CONSOLE, "serial console detected. Disabling 2nd virtual terminal.\r\n", console );
|
||||
log = NULL;
|
||||
second_console = NULL;
|
||||
}
|
||||
close(fd);
|
||||
}
|
||||
message(LOG, "console=%s\n", console );
|
||||
}
|
||||
|
||||
@@ -285,9 +336,9 @@ static pid_t run(const char * const* command,
|
||||
}
|
||||
|
||||
/* Log the process name and args */
|
||||
message(LOG, "Starting pid %d, console %s: '", getpid(), terminal);
|
||||
while ( *cmd) message(LOG, "%s ", *cmd++);
|
||||
message(LOG, "'\r\n");
|
||||
message(LOG|CONSOLE, "Starting pid %d, console %s: '", getpid(), terminal);
|
||||
while ( *cmd) message(LOG|CONSOLE, "%s ", *cmd++);
|
||||
message(LOG|CONSOLE, "'\r\n");
|
||||
|
||||
/* Now run it. The new program will take over this PID,
|
||||
* so nothing further in init.c should be run. */
|
||||
@@ -327,13 +378,13 @@ goodnight:
|
||||
static void shutdown_system(void)
|
||||
{
|
||||
const char* const swap_off_cmd[] = { "swapoff", "swapoff", "-a", 0};
|
||||
const char* const umount_cmd[] = { "umount", "umount", "-a", "-n", 0};
|
||||
const char* const umount_cmd[] = { "umount", "umount", "-a", 0};
|
||||
|
||||
#ifndef DEBUG_INIT
|
||||
/* Allow Ctrl-Alt-Del to reboot system. */
|
||||
reboot(RB_ENABLE_CAD);
|
||||
#endif
|
||||
message(CONSOLE, "The system is going down NOW !!\r\n");
|
||||
message(CONSOLE, "\r\nThe system is going down NOW !!\r\n");
|
||||
sync();
|
||||
/* Send signals to every process _except_ pid 1 */
|
||||
message(CONSOLE, "Sending SIGHUP to all processes.\r\n");
|
||||
@@ -347,7 +398,9 @@ static void shutdown_system(void)
|
||||
kill(-1, SIGKILL);
|
||||
#endif
|
||||
sleep(1);
|
||||
message(CONSOLE, "Disabling swap.\r\n");
|
||||
waitfor(run( swap_off_cmd, console, FALSE));
|
||||
message(CONSOLE, "Unmounting filesystems.\r\n");
|
||||
waitfor(run( umount_cmd, console, FALSE));
|
||||
sync();
|
||||
if (kernel_version > 0 && kernel_version <= 2 * 65536 + 2 * 256 + 11) {
|
||||
@@ -365,8 +418,10 @@ static void halt_signal(int sig)
|
||||
"The system is halted. Press CTRL-ALT-DEL or turn off power\r\n");
|
||||
sync();
|
||||
#ifndef DEBUG_INIT
|
||||
reboot(RB_HALT_SYSTEM);
|
||||
//reboot(RB_POWER_OFF);
|
||||
if (sig == SIGUSR2)
|
||||
reboot(RB_POWER_OFF);
|
||||
else
|
||||
reboot(RB_HALT_SYSTEM);
|
||||
#endif
|
||||
exit(0);
|
||||
}
|
||||
@@ -384,15 +439,26 @@ static void reboot_signal(int sig)
|
||||
|
||||
extern int init_main(int argc, char **argv)
|
||||
{
|
||||
int run_rc = TRUE;
|
||||
int wait_for_enter = TRUE;
|
||||
int run_rc = FALSE;
|
||||
int single = FALSE;
|
||||
int wait_for_enter_tty1 = TRUE;
|
||||
int wait_for_enter_tty2 = TRUE;
|
||||
pid_t pid1 = 0;
|
||||
pid_t pid2 = 0;
|
||||
struct stat statbuf;
|
||||
const char* const init_commands[] = { INITSCRIPT, INITSCRIPT, 0};
|
||||
const char* const shell_commands[] = { SHELL, "-" SHELL, 0};
|
||||
const char* const* tty0_commands = shell_commands;
|
||||
const char* const* tty1_commands = shell_commands;
|
||||
char which_vt1[30];
|
||||
char which_vt2[30];
|
||||
const char* const rc_script_command[] = { INITSCRIPT, INITSCRIPT, 0};
|
||||
const char* const getty1_command[] = { GETTY, GETTY, "38400", which_vt1, 0};
|
||||
const char* const getty2_command[] = { GETTY, GETTY, "38400", which_vt2, 0};
|
||||
const char* const shell_command[] = { SHELL, "-" SHELL, 0};
|
||||
const char* const* tty1_command = shell_command;
|
||||
const char* const* tty2_command = shell_command;
|
||||
#ifdef BB_INIT_CMD_IF_RC_SCRIPT_EXITS
|
||||
const char* const rc_exit_command[] = { "BB_INIT_CMD_IF_RC_SCRIPT_EXITS",
|
||||
"BB_INIT_CMD_IF_RC_SCRIPT_EXITS", 0 };
|
||||
#endif
|
||||
|
||||
#ifdef DEBUG_INIT
|
||||
char *hello_msg_format =
|
||||
"init(%d) started: BusyBox v%s (%s) multi-call binary\r\n";
|
||||
@@ -402,13 +468,14 @@ extern int init_main(int argc, char **argv)
|
||||
#endif
|
||||
|
||||
|
||||
/* Check if we are supposed to be in single user mode */
|
||||
if ( argc > 1 && (!strcmp(argv[1], "single") ||
|
||||
!strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
|
||||
run_rc = FALSE;
|
||||
#ifndef DEBUG_INIT
|
||||
/* Expect to be PID 1 iff we are run as init (not linuxrc) */
|
||||
if (getpid() != 1 && strstr(argv[0], "init")!=NULL ) {
|
||||
usage( "init\n\nInit is the parent of all processes.\n\n"
|
||||
"This version of init is designed to be run only by the kernel\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/* Set up sig handlers -- be sure to
|
||||
* clear all of these in run() */
|
||||
signal(SIGUSR1, halt_signal);
|
||||
@@ -433,7 +500,7 @@ extern int init_main(int argc, char **argv)
|
||||
setsid();
|
||||
|
||||
/* Make sure PATH is set to something sane */
|
||||
putenv(PATH_DEFAULT);
|
||||
putenv(_PATH_STDPATH);
|
||||
|
||||
|
||||
/* Hello world */
|
||||
@@ -454,27 +521,59 @@ extern int init_main(int argc, char **argv)
|
||||
/* Make sure there is enough memory to do something useful. */
|
||||
check_memory();
|
||||
|
||||
|
||||
/* Make sure an init script exists before trying to run it */
|
||||
if (run_rc == TRUE && stat(INITSCRIPT, &statbuf)==0) {
|
||||
wait_for_enter = FALSE;
|
||||
tty0_commands = init_commands;
|
||||
/* Check if we are supposed to be in single user mode */
|
||||
if ( argc > 1 && (!strcmp(argv[1], "single") ||
|
||||
!strcmp(argv[1], "-s") || !strcmp(argv[1], "1"))) {
|
||||
single = TRUE;
|
||||
tty1_command = shell_command;
|
||||
tty2_command = shell_command;
|
||||
}
|
||||
|
||||
/* Make sure an init script exists before trying to run it */
|
||||
if (single==FALSE && stat(INITSCRIPT, &statbuf)==0) {
|
||||
run_rc = TRUE;
|
||||
wait_for_enter_tty1 = FALSE;
|
||||
tty1_command = rc_script_command;
|
||||
}
|
||||
|
||||
/* Make sure /sbin/getty exists before trying to run it */
|
||||
if (stat(GETTY, &statbuf)==0) {
|
||||
char* where;
|
||||
/* First do tty2 */
|
||||
wait_for_enter_tty2 = FALSE;
|
||||
where = strrchr( second_console, '/');
|
||||
if ( where != NULL) {
|
||||
where++;
|
||||
strncpy( which_vt2, where, sizeof(which_vt2));
|
||||
}
|
||||
tty2_command = getty2_command;
|
||||
|
||||
/* Ok, now launch the rc script and/or prepare to
|
||||
* start up some VTs if somebody hits enter...
|
||||
*/
|
||||
/* Check on hooking a getty onto tty1 */
|
||||
if (run_rc == FALSE && single==FALSE) {
|
||||
wait_for_enter_tty1 = FALSE;
|
||||
where = strrchr( console, '/');
|
||||
if ( where != NULL) {
|
||||
where++;
|
||||
strncpy( which_vt1, where, sizeof(which_vt1));
|
||||
}
|
||||
tty1_command = getty1_command;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* Ok, now launch the tty1_command and tty2_command */
|
||||
for (;;) {
|
||||
pid_t wpid;
|
||||
int status;
|
||||
|
||||
if (pid1 == 0 && tty0_commands) {
|
||||
pid1 = run(tty0_commands, console, wait_for_enter);
|
||||
if (pid1 == 0 && tty1_command) {
|
||||
pid1 = run(tty1_command, console, wait_for_enter_tty1);
|
||||
}
|
||||
if (pid2 == 0 && tty1_commands) {
|
||||
pid2 = run(tty1_commands, second_console, TRUE);
|
||||
#ifdef BB_FEATURE_INIT_SECOND_CONSOLE
|
||||
if (pid2 == 0 && tty2_command && second_console) {
|
||||
pid2 = run(tty2_command, second_console, wait_for_enter_tty2);
|
||||
}
|
||||
#endif
|
||||
wpid = wait(&status);
|
||||
if (wpid > 0 ) {
|
||||
message(LOG, "pid %d exited, status=%x.\n", wpid, status);
|
||||
@@ -483,19 +582,21 @@ extern int init_main(int argc, char **argv)
|
||||
if (wpid == pid1) {
|
||||
if (run_rc == FALSE) {
|
||||
pid1 = 0;
|
||||
}
|
||||
#if 0
|
||||
/* Turn this on to start a shell on the console if the init script exits.... */
|
||||
}
|
||||
#ifdef BB_INIT_CMD_IF_RC_SCRIPT_EXITS
|
||||
else {
|
||||
pid1 = 0;
|
||||
run_rc=FALSE;
|
||||
wait_for_enter=TRUE;
|
||||
tty0_commands=shell_commands;
|
||||
wait_for_enter_tty1=TRUE;
|
||||
tty1_command=rc_exit_command;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef BB_FEATURE_INIT_SECOND_CONSOLE
|
||||
if (wpid == pid2) {
|
||||
pid2 = 0;
|
||||
}
|
||||
#endif
|
||||
sleep(1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Mini poweroff implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
* 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 "internal.h"
|
||||
#include <signal.h>
|
||||
|
||||
extern int
|
||||
poweroff_main(int argc, char ** argv)
|
||||
{
|
||||
/* don't assume init's pid == 1 */
|
||||
exit( kill(findInitPid(), SIGUSR2));
|
||||
}
|
||||
+2
-1
@@ -26,5 +26,6 @@
|
||||
extern int
|
||||
reboot_main(int argc, char ** argv)
|
||||
{
|
||||
exit( kill(1, SIGUSR2));
|
||||
/* don't assume init's pid == 1 */
|
||||
exit( kill(findInitPid(), SIGINT));
|
||||
}
|
||||
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
|
||||
set -e
|
||||
|
||||
if [ "$1" == "" ]; then
|
||||
echo "No installation directory, aborting."
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
h=`sort busybox.links | uniq`
|
||||
|
||||
for i in $h ; do
|
||||
echo " $1$i -> /bin/busybox"
|
||||
mkdir -p $1/`echo $i | sed -e 's/\/[^\/]*$//' `
|
||||
ln -fs /bin/busybox $1$i
|
||||
done
|
||||
rm -f $1/bin/busybox
|
||||
install -m 755 busybox $1/bin/busybox
|
||||
|
||||
exit 0
|
||||
+19
-4
@@ -33,8 +33,6 @@
|
||||
|
||||
|
||||
/* Some useful definitions */
|
||||
#define STDIN 0
|
||||
#define STDOUT 1
|
||||
#define FALSE ((int) 1)
|
||||
#define TRUE ((int) 0)
|
||||
|
||||
@@ -65,6 +63,7 @@ extern int date_main(int argc, char** argv);
|
||||
extern int dd_main(int argc, char** argv);
|
||||
extern int df_main(int argc, char** argv);
|
||||
extern int dmesg_main(int argc, char** argv);
|
||||
extern int du_main(int argc, char** argv);
|
||||
extern int dutmp_main(int argc, char** argv);
|
||||
extern int false_main(int argc, char** argv);
|
||||
extern int fdisk_main(int argc, char** argv);
|
||||
@@ -72,8 +71,11 @@ extern int fdflush_main(int argc, char **argv);
|
||||
extern int fsck_minix_main(int argc, char **argv);
|
||||
extern int mkfs_minix_main(int argc, char **argv);
|
||||
extern int find_main(int argc, char** argv);
|
||||
extern int free_main(int argc, char** argv);
|
||||
extern int grep_main(int argc, char** argv);
|
||||
extern int halt_main(int argc, char** argv);
|
||||
extern int head_main(int argc, char** argv);
|
||||
extern int hostname_main(int argc, char** argv);
|
||||
extern int init_main(int argc, char** argv);
|
||||
extern int kill_main(int argc, char** argv);
|
||||
extern int length_main(int argc, char** argv);
|
||||
@@ -93,6 +95,8 @@ extern int mnc_main(int argc, char** argv);
|
||||
extern int mount_main(int argc, char** argv);
|
||||
extern int mt_main(int argc, char** argv);
|
||||
extern int mv_main(int argc, char** argv);
|
||||
extern int ping_main(int argc, char **argv);
|
||||
extern int poweroff_main(int argc, char **argv);
|
||||
extern int printf_main(int argc, char** argv);
|
||||
extern int ps_main(int argc, char** argv);
|
||||
extern int pwd_main(int argc, char** argv);
|
||||
@@ -106,7 +110,11 @@ extern int sed_main(int argc, char** argv);
|
||||
extern int sleep_main(int argc, char** argv);
|
||||
extern int swap_on_off_main(int argc, char** argv);
|
||||
extern int sync_main(int argc, char** argv);
|
||||
extern int syslogd_main(int argc, char **argv);
|
||||
extern int logger_main(int argc, char **argv);
|
||||
extern int tar_main(int argc, char** argv);
|
||||
extern int tail_main(int argc, char** argv);
|
||||
extern int tee_main(int argc, char** argv);
|
||||
extern int touch_main(int argc, char** argv);
|
||||
extern int tput_main(int argc, char** argv);
|
||||
extern int true_main(int argc, char** argv);
|
||||
@@ -114,7 +122,7 @@ extern int tryopen_main(int argc, char** argv);
|
||||
extern int umount_main(int argc, char** argv);
|
||||
extern int update_main(int argc, char** argv);
|
||||
extern int uname_main(int argc, char** argv);
|
||||
extern int zcat_main(int argc, char** argv);
|
||||
extern int gunzip_main (int argc, char** argv);
|
||||
extern int gzip_main(int argc, char** argv);
|
||||
|
||||
|
||||
@@ -138,7 +146,7 @@ const char* timeString(time_t timeVal);
|
||||
|
||||
extern void createPath (const char *name, int mode);
|
||||
extern int parse_mode( const char* s, mode_t* theMode);
|
||||
extern volatile void usage(const char *usage);
|
||||
extern void usage(const char *usage) __attribute__ ((noreturn));
|
||||
|
||||
extern uid_t my_getpwnam(char *name);
|
||||
extern gid_t my_getgrnam(char *name);
|
||||
@@ -150,6 +158,9 @@ extern struct mntent *findMountPoint(const char *name, const char *table);
|
||||
extern void write_mtab(char* blockDevice, char* directory,
|
||||
char* filesystemType, long flags, char* string_flags);
|
||||
extern void erase_mtab(const char * name);
|
||||
extern int check_wildcard_match(const char* text, const char* pattern);
|
||||
extern long getNum (const char *cp);
|
||||
extern pid_t findInitPid();
|
||||
|
||||
|
||||
#if defined BB_MTAB
|
||||
@@ -158,6 +169,10 @@ extern void erase_mtab(const char * name);
|
||||
extern void whine_if_fstab_is_missing();
|
||||
#endif
|
||||
|
||||
#if defined BB_NFSMOUNT
|
||||
int nfsmount(const char *spec, const char *node, unsigned long *flags,
|
||||
char **extra_opts, char **mount_opts, int running_bg);
|
||||
#endif
|
||||
|
||||
#if defined (BB_FSCK_MINIX) || defined (BB_MKFS_MINIX)
|
||||
|
||||
|
||||
@@ -26,8 +26,14 @@
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static const char* kill_usage = "kill [-signal] process-id [process-id ...]\n\n"
|
||||
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
|
||||
"Options:\n"
|
||||
"\t-l\tList all signal names and numbers.\n\n";
|
||||
|
||||
const char kill_usage[] = "kill [-signal] process-id [process-id ...]\n";
|
||||
|
||||
struct signal_name {
|
||||
const char *name;
|
||||
@@ -114,42 +120,92 @@ const struct signal_name signames[] = {
|
||||
extern int kill_main (int argc, char **argv)
|
||||
{
|
||||
int sig = SIGTERM;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
/* Parse any options */
|
||||
if (argc < 1)
|
||||
usage(kill_usage);
|
||||
|
||||
if ( argc < 2 )
|
||||
usage (kill_usage);
|
||||
while (argc > 0 && **argv == '-') {
|
||||
while (*++(*argv)) {
|
||||
switch (**argv) {
|
||||
case 'l':
|
||||
{
|
||||
int col=0;
|
||||
const struct signal_name *s = signames;
|
||||
|
||||
if ( **(argv+1) == '-' ) {
|
||||
if (isdigit( *(*(++argv)+1) )) {
|
||||
sig = atoi (*argv);
|
||||
if (sig < 0 || sig >= NSIG)
|
||||
goto end;
|
||||
}
|
||||
else {
|
||||
const struct signal_name *s = signames;
|
||||
while (s->name != 0) {
|
||||
if (strcasecmp (s->name, *argv+1) == 0) {
|
||||
sig = s->number;
|
||||
break;
|
||||
while (s->name != 0) {
|
||||
col+=fprintf(stderr, "%2d) %-8s", s->number, (s++)->name);
|
||||
if (col>60) {
|
||||
fprintf(stderr, "\n");
|
||||
col=0;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "\n\n");
|
||||
exit( TRUE);
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
usage(kill_usage);
|
||||
default:
|
||||
{
|
||||
if (isdigit( **argv)) {
|
||||
sig = atoi (*argv);
|
||||
if (sig < 0 || sig >= NSIG)
|
||||
goto end;
|
||||
else {
|
||||
argc--;
|
||||
argv++;
|
||||
goto do_it_now;
|
||||
}
|
||||
}
|
||||
else {
|
||||
const struct signal_name *s = signames;
|
||||
while (s->name != 0) {
|
||||
if (strcasecmp (s->name, *argv) == 0) {
|
||||
sig = s->number;
|
||||
argc--;
|
||||
argv++;
|
||||
goto do_it_now;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
if (s->name == 0)
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
s++;
|
||||
}
|
||||
if (s->name == 0)
|
||||
goto end;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
}
|
||||
|
||||
while (--argc > 1) {
|
||||
int pid;
|
||||
if (! isdigit( **(++argv))) {
|
||||
fprintf(stderr, "bad PID: %s\n", *argv);
|
||||
exit( FALSE);
|
||||
}
|
||||
pid = atoi (*argv);
|
||||
if (kill (pid, sig) != 0) {
|
||||
perror (*argv);
|
||||
exit ( FALSE);
|
||||
do_it_now:
|
||||
|
||||
while (argc >= 1) {
|
||||
int pid;
|
||||
struct stat statbuf;
|
||||
char pidpath[20]="/proc/";
|
||||
|
||||
if (! isdigit( **argv)) {
|
||||
fprintf(stderr, "bad PID: %s\n", *argv);
|
||||
exit( FALSE);
|
||||
}
|
||||
pid = atoi (*argv);
|
||||
snprintf(pidpath, 20, "/proc/%s/stat", *argv);
|
||||
if (stat( pidpath, &statbuf)!=0) {
|
||||
fprintf(stderr, "kill: (%d) - No such pid\n", pid);
|
||||
exit( FALSE);
|
||||
}
|
||||
if (kill (pid, sig) != 0) {
|
||||
perror (*argv);
|
||||
exit ( FALSE);
|
||||
}
|
||||
argv++;
|
||||
}
|
||||
exit ( TRUE);
|
||||
|
||||
|
||||
end:
|
||||
fprintf(stderr, "bad signal name: %s\n", *argv);
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
#include <errno.h>
|
||||
|
||||
|
||||
static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n"
|
||||
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n"
|
||||
"\nOptions:\n"
|
||||
static const char ln_usage[] = "ln [OPTION] TARGET... LINK_NAME|DIRECTORY\n\n"
|
||||
"Create a link named LINK_NAME or DIRECTORY to the specified TARGET\n\n"
|
||||
"Options:\n"
|
||||
"\t-s\tmake symbolic links instead of hard links\n"
|
||||
"\t-f\tremove existing destination files\n";
|
||||
|
||||
|
||||
@@ -0,0 +1,196 @@
|
||||
/*
|
||||
* Mini logger implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* 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 "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
#include <time.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <ctype.h>
|
||||
#include <netdb.h>
|
||||
|
||||
#if !defined BB_SYSLOGD
|
||||
|
||||
#define SYSLOG_NAMES
|
||||
#include <sys/syslog.h>
|
||||
|
||||
#else
|
||||
/* We have to do this since the header file defines static
|
||||
* structues. Argh.... bad libc, bad, bad...
|
||||
*/
|
||||
#include <sys/syslog.h>
|
||||
typedef struct _code {
|
||||
char *c_name;
|
||||
int c_val;
|
||||
} CODE;
|
||||
extern CODE prioritynames[];
|
||||
extern CODE facilitynames[];
|
||||
#endif
|
||||
|
||||
static const char logger_usage[] =
|
||||
"logger [OPTION]... [MESSAGE]\n\n"
|
||||
"Write MESSAGE to the system log. If MESSAGE is '-', log stdin.\n\n"
|
||||
"Options:\n"
|
||||
"\t-s\tLog to stderr as well as the system log.\n"
|
||||
"\t-p\tEnter the message with the specified priority.\n"
|
||||
"\t\tThis may be numerical or a ``facility.level'' pair.\n";
|
||||
|
||||
|
||||
/* Decode a symbolic name to a numeric value
|
||||
* this function is based on code
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*/
|
||||
static int
|
||||
decode(char* name, CODE* codetab)
|
||||
{
|
||||
CODE *c;
|
||||
|
||||
if (isdigit(*name))
|
||||
return (atoi(name));
|
||||
for (c = codetab; c->c_name; c++) {
|
||||
if (!strcasecmp(name, c->c_name)) {
|
||||
return (c->c_val);
|
||||
}
|
||||
}
|
||||
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Decode a symbolic name to a numeric value
|
||||
* this function is based on code
|
||||
* Copyright (c) 1983, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*/
|
||||
static int
|
||||
pencode(char* s)
|
||||
{
|
||||
char *save;
|
||||
int lev, fac=LOG_USER;
|
||||
|
||||
for (save = s; *s && *s != '.'; ++s);
|
||||
if (*s) {
|
||||
*s = '\0';
|
||||
fac = decode(save, facilitynames);
|
||||
if (fac < 0) {
|
||||
fprintf(stderr, "unknown facility name: %s\n", save);
|
||||
exit( FALSE);
|
||||
}
|
||||
*s++ = '.';
|
||||
}
|
||||
else {
|
||||
s = save;
|
||||
}
|
||||
lev = decode(s, prioritynames);
|
||||
if (lev < 0) {
|
||||
fprintf(stderr, "unknown priority name: %s\n", save);
|
||||
exit( FALSE);
|
||||
}
|
||||
return ((lev & LOG_PRIMASK) | (fac & LOG_FACMASK));
|
||||
}
|
||||
|
||||
|
||||
extern int logger_main(int argc, char **argv)
|
||||
{
|
||||
struct sockaddr_un sunx;
|
||||
int fd, pri = LOG_USER|LOG_NOTICE;
|
||||
int fromStdinFlag=FALSE;
|
||||
int toStdErrFlag=FALSE;
|
||||
char *message, buf[1024], buf1[1024];
|
||||
time_t now;
|
||||
size_t addrLength;
|
||||
|
||||
/* Parse any options */
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
if (*((*argv)+1) == '\0') {
|
||||
fromStdinFlag=TRUE;
|
||||
}
|
||||
while (*(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 's':
|
||||
toStdErrFlag = TRUE;
|
||||
break;
|
||||
case 'p':
|
||||
if (--argc == 0) {
|
||||
usage(logger_usage);
|
||||
}
|
||||
pri = pencode(*(++argv));
|
||||
if (--argc == 0) {
|
||||
usage(logger_usage);
|
||||
}
|
||||
++argv;
|
||||
break;
|
||||
default:
|
||||
usage(logger_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fromStdinFlag==TRUE) {
|
||||
/* read from stdin */
|
||||
int i=0;
|
||||
char c;
|
||||
while ((c = getc(stdin)) != EOF && i<sizeof(buf1)) {
|
||||
buf1[i++]=c;
|
||||
}
|
||||
message=buf1;
|
||||
} else {
|
||||
if (argc>=1) {
|
||||
message=*argv;
|
||||
} else {
|
||||
fprintf(stderr, "No message\n");
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
memset(&sunx, 0, sizeof(sunx));
|
||||
sunx.sun_family = AF_UNIX; /* Unix domain socket */
|
||||
strncpy(sunx.sun_path, _PATH_LOG, sizeof(sunx.sun_path));
|
||||
if ((fd = socket(PF_UNIX, SOCK_STREAM, 0)) < 0 ) {
|
||||
perror("Couldn't obtain descriptor for socket " _PATH_LOG);
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
addrLength = sizeof(sunx.sun_family) + strlen(sunx.sun_path);
|
||||
|
||||
if (connect(fd, (struct sockaddr *) &sunx, addrLength)) {
|
||||
perror("Could not connect to socket " _PATH_LOG);
|
||||
exit( FALSE);
|
||||
}
|
||||
|
||||
time(&now);
|
||||
snprintf (buf, sizeof(buf), "<%d>%.15s %s", pri, ctime(&now)+4, message);
|
||||
|
||||
if (toStdErrFlag==TRUE)
|
||||
fprintf(stderr, "%s\n", buf);
|
||||
|
||||
write( fd, buf, sizeof(buf));
|
||||
|
||||
close(fd);
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
@@ -40,11 +40,6 @@
|
||||
* 1. requires lstat (BSD) - how do you do it without?
|
||||
*/
|
||||
|
||||
//#define FEATURE_USERNAME /* show username/groupnames (libc6 uses NSS) */
|
||||
#define FEATURE_TIMESTAMPS /* show file timestamps */
|
||||
#define FEATURE_AUTOWIDTH /* calculate terminal & column widths */
|
||||
#define FEATURE_FILETYPECHAR /* enable -p and -F */
|
||||
|
||||
#define TERMINAL_WIDTH 80 /* use 79 if your terminal has linefold bug */
|
||||
#define COLUMN_WIDTH 14 /* default if AUTOWIDTH not defined */
|
||||
#define COLUMN_GAP 2 /* includes the file type char, if present */
|
||||
@@ -64,17 +59,13 @@
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
#ifdef FEATURE_USERNAME
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#endif
|
||||
#ifdef FEATURE_TIMESTAMPS
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
#include <time.h>
|
||||
#endif
|
||||
|
||||
#define TYPEINDEX(mode) (((mode) >> 12) & 0x0f)
|
||||
#define TYPECHAR(mode) ("0pcCd?bB-?l?s???" [TYPEINDEX(mode)])
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
#define APPCHAR(mode) ("\0|\0\0/\0\0\0\0\0@\0=\0\0\0" [TYPEINDEX(mode)])
|
||||
#endif
|
||||
|
||||
@@ -83,27 +74,6 @@
|
||||
#define MINOR(dev) ((dev)&0xff)
|
||||
#endif
|
||||
|
||||
#define MODE1 "rwxrwxrwx"
|
||||
#define MODE0 "---------"
|
||||
#define SMODE1 "..s..s..t"
|
||||
#define SMODE0 "..S..S..T"
|
||||
|
||||
/* The 9 mode bits to test */
|
||||
|
||||
static const mode_t MBIT[] = {
|
||||
S_IRUSR, S_IWUSR, S_IXUSR,
|
||||
S_IRGRP, S_IWGRP, S_IXGRP,
|
||||
S_IROTH, S_IWOTH, S_IXOTH
|
||||
};
|
||||
|
||||
/* The special bits. If set, display SMODE0/1 instead of MODE0/1 */
|
||||
|
||||
static const mode_t SBIT[] = {
|
||||
0, 0, S_ISUID,
|
||||
0, 0, S_ISGID,
|
||||
0, 0, S_ISVTX
|
||||
};
|
||||
|
||||
#define FMT_AUTO 0
|
||||
#define FMT_LONG 1 /* one record per line, extended info */
|
||||
#define FMT_SINGLE 2 /* one record per line */
|
||||
@@ -128,14 +98,14 @@ static unsigned char display_fmt = FMT_AUTO;
|
||||
static unsigned short opts = 0;
|
||||
static unsigned short column = 0;
|
||||
|
||||
#ifdef FEATURE_AUTOWIDTH
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
static unsigned short terminal_width = 0, column_width = 0;
|
||||
#else
|
||||
#define terminal_width TERMINAL_WIDTH
|
||||
#define column_width COLUMN_WIDTH
|
||||
#endif
|
||||
|
||||
#ifdef FEATURE_TIMESTAMPS
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
static unsigned char time_fmt = TIME_MOD;
|
||||
#endif
|
||||
|
||||
@@ -188,7 +158,7 @@ static void tab(short col)
|
||||
#undef nspaces
|
||||
}
|
||||
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
static char append_char(mode_t mode)
|
||||
{
|
||||
if (!(opts & DISP_FTYPE))
|
||||
@@ -206,55 +176,52 @@ static char append_char(mode_t mode)
|
||||
**
|
||||
**/
|
||||
|
||||
static void list_single(const char *name, struct stat *info)
|
||||
static void list_single(const char *name, struct stat *info, const char *fullname)
|
||||
{
|
||||
char scratch[PATH_MAX];
|
||||
short len = strlen(name);
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
char append = append_char(info->st_mode);
|
||||
#endif
|
||||
|
||||
if (display_fmt == FMT_LONG) {
|
||||
mode_t mode = info->st_mode;
|
||||
int i;
|
||||
|
||||
scratch[0] = TYPECHAR(mode);
|
||||
for (i=0; i<9; i++)
|
||||
if (mode & SBIT[i])
|
||||
scratch[i+1] = (mode & MBIT[i])
|
||||
? SMODE1[i]
|
||||
: SMODE0[i];
|
||||
else
|
||||
scratch[i+1] = (mode & MBIT[i])
|
||||
? MODE1[i]
|
||||
: MODE0[i];
|
||||
newline();
|
||||
wr(scratch, 10);
|
||||
wr(modeString(mode), 10);
|
||||
column=10;
|
||||
writenum((long)info->st_nlink,(short)4);
|
||||
writenum((long)info->st_nlink,(short)5);
|
||||
fputs(" ", stdout);
|
||||
#ifdef FEATURE_USERNAME
|
||||
#ifdef BB_FEATURE_LS_USERNAME
|
||||
if (!(opts & DISP_NUMERIC)) {
|
||||
struct passwd *pw = getpwuid(info->st_uid);
|
||||
if (pw)
|
||||
fputs(pw->pw_name, stdout);
|
||||
else
|
||||
writenum((long)info->st_uid,(short)0);
|
||||
scratch[0]='\0';
|
||||
my_getpwuid( scratch, info->st_uid);
|
||||
scratch[8]='\0';
|
||||
if (*scratch)
|
||||
wr(scratch,8);
|
||||
else {
|
||||
writenum((long) info->st_uid,(short)8);
|
||||
fputs(" ", stdout);
|
||||
}
|
||||
} else
|
||||
#endif
|
||||
writenum((long)info->st_uid,(short)0);
|
||||
tab(24);
|
||||
#ifdef FEATURE_USERNAME
|
||||
{
|
||||
writenum((long) info->st_uid,(short)8);
|
||||
fputs(" ", stdout);
|
||||
}
|
||||
tab(16);
|
||||
#ifdef BB_FEATURE_LS_USERNAME
|
||||
if (!(opts & DISP_NUMERIC)) {
|
||||
struct group *gr = getgrgid(info->st_gid);
|
||||
if (gr)
|
||||
fputs(gr->gr_name, stdout);
|
||||
else
|
||||
writenum((long)info->st_gid,(short)0);
|
||||
scratch[0]='\0';
|
||||
my_getgrgid( scratch, info->st_gid);
|
||||
scratch[8]='\0';
|
||||
if (*scratch)
|
||||
wr(scratch,8);
|
||||
else
|
||||
writenum((long) info->st_gid,(short)8);
|
||||
} else
|
||||
#endif
|
||||
writenum((long)info->st_gid,(short)0);
|
||||
tab(33);
|
||||
writenum((long) info->st_gid,(short)8);
|
||||
tab(17);
|
||||
if (S_ISBLK(mode) || S_ISCHR(mode)) {
|
||||
writenum((long)MAJOR(info->st_rdev),(short)3);
|
||||
fputs(", ", stdout);
|
||||
@@ -263,7 +230,7 @@ static void list_single(const char *name, struct stat *info)
|
||||
else
|
||||
writenum((long)info->st_size,(short)8);
|
||||
fputs(" ", stdout);
|
||||
#ifdef FEATURE_TIMESTAMPS
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
{
|
||||
time_t cal;
|
||||
char *string;
|
||||
@@ -297,12 +264,12 @@ static void list_single(const char *name, struct stat *info)
|
||||
wr(name, len);
|
||||
if (S_ISLNK(mode)) {
|
||||
wr(" -> ", 4);
|
||||
len = readlink(name, scratch, sizeof scratch);
|
||||
len = readlink(fullname, scratch, sizeof scratch);
|
||||
if (len > 0) fwrite(scratch, 1, len, stdout);
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
/* show type of destination */
|
||||
if (opts & DISP_FTYPE) {
|
||||
if (!stat(name, info)) {
|
||||
if (!stat(fullname, info)) {
|
||||
append = append_char(info->st_mode);
|
||||
if (append)
|
||||
fputc(append, stdout);
|
||||
@@ -310,7 +277,7 @@ static void list_single(const char *name, struct stat *info)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
else if (append)
|
||||
wr(&append, 1);
|
||||
#endif
|
||||
@@ -324,7 +291,7 @@ static void list_single(const char *name, struct stat *info)
|
||||
newline();
|
||||
else {
|
||||
if (nexttab + column_width > terminal_width
|
||||
#ifndef FEATURE_AUTOWIDTH
|
||||
#ifndef BB_FEATURE_AUTOWIDTH
|
||||
|| nexttab + len >= terminal_width
|
||||
#endif
|
||||
)
|
||||
@@ -333,7 +300,7 @@ static void list_single(const char *name, struct stat *info)
|
||||
tab(nexttab);
|
||||
}
|
||||
/* work out where next column starts */
|
||||
#ifdef FEATURE_AUTOWIDTH
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
/* we know the calculated width is big enough */
|
||||
nexttab = column + column_width + COLUMN_GAP;
|
||||
#else
|
||||
@@ -346,7 +313,7 @@ static void list_single(const char *name, struct stat *info)
|
||||
/* now write the data */
|
||||
wr(name, len);
|
||||
column = column + len;
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
if (append)
|
||||
wr(&append, 1), column++;
|
||||
#endif
|
||||
@@ -372,7 +339,7 @@ static int list_item(const char *name)
|
||||
|
||||
if (!S_ISDIR(info.st_mode) ||
|
||||
(opts & DIR_NOLIST)) {
|
||||
list_single(name, &info);
|
||||
list_single(name, &info, name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -387,7 +354,7 @@ static int list_item(const char *name)
|
||||
|
||||
dir = opendir(name);
|
||||
if (!dir) goto listerr;
|
||||
#ifdef FEATURE_AUTOWIDTH
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
column_width = 0;
|
||||
while ((entry = readdir(dir)) != NULL) {
|
||||
short w = strlen(entry->d_name);
|
||||
@@ -424,7 +391,7 @@ static int list_item(const char *name)
|
||||
strcpy(fnend, entry->d_name);
|
||||
if (lstat(fullname, &info))
|
||||
goto direrr; /* (shouldn't fail) */
|
||||
list_single(entry->d_name, &info);
|
||||
list_single(entry->d_name, &info, fullname);
|
||||
}
|
||||
closedir(dir);
|
||||
return 0;
|
||||
@@ -438,22 +405,22 @@ listerr:
|
||||
}
|
||||
|
||||
static const char ls_usage[] = "ls [-1a"
|
||||
#ifdef FEATURE_TIMESTAMPS
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"c"
|
||||
#endif
|
||||
"d"
|
||||
#ifdef FEATURE_TIMESTAMPS
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"e"
|
||||
#endif
|
||||
"ln"
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
"p"
|
||||
#endif
|
||||
#ifdef FEATURE_TIMESTAMPS
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
"u"
|
||||
#endif
|
||||
"xAC"
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
"F"
|
||||
#endif
|
||||
#ifdef FEATURE_RECURSIVE
|
||||
@@ -486,7 +453,7 @@ ls_main(int argc, char * * argv)
|
||||
case '1': display_fmt = FMT_SINGLE; break;
|
||||
case 'x': display_fmt = FMT_ROWS; break;
|
||||
case 'C': display_fmt = FMT_COLUMNS; break;
|
||||
#ifdef FEATURE_FILETYPECHAR
|
||||
#ifdef BB_FEATURE_LS_FILETYPES
|
||||
case 'p': opts |= DISP_FTYPE; break;
|
||||
case 'F': opts |= DISP_FTYPE|DISP_EXEC; break;
|
||||
#endif
|
||||
@@ -497,7 +464,7 @@ ls_main(int argc, char * * argv)
|
||||
#ifdef FEATURE_RECURSIVE
|
||||
case 'R': opts |= DIR_RECURSE; break;
|
||||
#endif
|
||||
#ifdef FEATURE_TIMESTAMPS
|
||||
#ifdef BB_FEATURE_LS_TIMESTAMPS
|
||||
case 'u': time_fmt = TIME_ACCESS; break;
|
||||
case 'c': time_fmt = TIME_CHANGE; break;
|
||||
case 'e': opts |= DISP_FULLTIME; break;
|
||||
@@ -510,10 +477,10 @@ ls_main(int argc, char * * argv)
|
||||
|
||||
/* choose a display format */
|
||||
if (display_fmt == FMT_AUTO)
|
||||
display_fmt = isatty(STDOUT_FILENO) ? FMT_COLUMNS : FMT_SINGLE;
|
||||
display_fmt = isatty(fileno(stdout)) ? FMT_COLUMNS : FMT_SINGLE;
|
||||
if (argi < argc - 1)
|
||||
opts |= DISP_DIRNAME; /* 2 or more items? label directories */
|
||||
#ifdef FEATURE_AUTOWIDTH
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
/* could add a -w option and/or TIOCGWINSZ call */
|
||||
if (terminal_width < 1) terminal_width = TERMINAL_WIDTH;
|
||||
|
||||
|
||||
+1
-1
@@ -19,7 +19,7 @@ static const char dutmp_usage[] = "dutmp\n"
|
||||
"\tDump file or stdin utmp file format to stdout, pipe delimited.\n"
|
||||
"\tdutmp /var/run/utmp\n";
|
||||
|
||||
static int dutmp_main (int argc, char **argv)
|
||||
extern int dutmp_main (int argc, char **argv)
|
||||
{
|
||||
|
||||
FILE *f = stdin;
|
||||
|
||||
@@ -26,14 +26,15 @@
|
||||
#include <errno.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
static const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n"
|
||||
static const char mkdir_usage[] = "Usage: mkdir [OPTION] DIRECTORY...\n\n"
|
||||
"Create the DIRECTORY(ies), if they do not already exist\n\n"
|
||||
"-m\tset permission mode (as in chmod), not rwxrwxrwx - umask\n"
|
||||
"-p\tno error if existing, make parent directories as needed\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\n";
|
||||
|
||||
|
||||
static int parentFlag = FALSE;
|
||||
static mode_t mode = 777;
|
||||
static mode_t mode = 0777;
|
||||
|
||||
|
||||
extern int mkdir_main(int argc, char **argv)
|
||||
@@ -79,16 +80,21 @@ extern int mkdir_main(int argc, char **argv)
|
||||
while (argc > 0) {
|
||||
int status;
|
||||
struct stat statBuf;
|
||||
status=stat(*argv, &statBuf);
|
||||
char buf[NAME_MAX];
|
||||
|
||||
strcpy (buf, *argv);
|
||||
status=stat(buf, &statBuf);
|
||||
if (status != -1 && status != ENOENT ) {
|
||||
fprintf(stderr, "%s: File exists\n", *argv);
|
||||
fprintf(stderr, "%s: File exists\n", buf);
|
||||
exit( FALSE);
|
||||
}
|
||||
if (parentFlag == TRUE)
|
||||
createPath(*argv, mode);
|
||||
if (parentFlag == TRUE) {
|
||||
strcat( buf, "/");
|
||||
createPath(buf, mode);
|
||||
}
|
||||
else {
|
||||
if (mkdir (*argv, mode) != 0) {
|
||||
perror(*argv);
|
||||
if (mkdir (buf, mode) != 0) {
|
||||
perror(buf);
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
|
||||
+9
-4
@@ -171,10 +171,15 @@ static volatile void die(char *str) {
|
||||
|
||||
static volatile void show_usage()
|
||||
{
|
||||
fprintf(stderr, "%s\n", program_name);
|
||||
fprintf(stderr,
|
||||
"Usage: %s [-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]\n",
|
||||
program_name);
|
||||
fprintf(stderr, "BusyBox v%s (%s) multi-call binary -- GPL2\n\n", BB_VER, BB_BT);
|
||||
fprintf(stderr, "Usage: %s [-c | -l filename] [-nXX] [-iXX] /dev/name [blocks]\n\n", program_name);
|
||||
fprintf(stderr, "Make a MINIX filesystem.\n\n");
|
||||
fprintf(stderr, "OPTIONS:\n");
|
||||
fprintf(stderr, "\t-c\t\tCheck the device for bad blocks\n");
|
||||
fprintf(stderr, "\t-n [14|30]\tSpecify the maximum length of filenames\n");
|
||||
fprintf(stderr, "\t-i\t\tSpecify the number of inodes for the filesystem\n");
|
||||
fprintf(stderr, "\t-l FILENAME\tRead the bad blocks list from FILENAME\n");
|
||||
fprintf(stderr, "\t-v\t\tMake a Minix version 2 filesystem\n\n");
|
||||
exit(16);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static const char mknod_usage[] = "mknod file b|c|u|p major minor\n"
|
||||
"\tMake special files.\n"
|
||||
"\n"
|
||||
static const char mknod_usage[] = "mknod [OPTION]... NAME TYPE MAJOR MINOR\n\n"
|
||||
"Make block or character special files.\n\n"
|
||||
"Options:\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";
|
||||
|
||||
@@ -47,11 +47,12 @@
|
||||
/* we also get PAGE_SIZE via getpagesize() */
|
||||
|
||||
|
||||
static const char mkswap_usage[] = "mkswap [-c] [-v0|-v1] device [block-count]\n"
|
||||
static const char mkswap_usage[] = "mkswap [-c] [-v0|-v1] device [block-count]\n\n"
|
||||
"Prepare a disk partition to be used as a swap partition.\n\n"
|
||||
"\t-c\tCheck for read-ability.\n"
|
||||
"\t-v0\tMake version 0 swap [max 128 Megs].\n"
|
||||
"\t-v1\tMake version 1 swap [big!] (default for kernels > 2.1.117).\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 > 2.1.117).\n"
|
||||
"\tblock-count\tNumber of block to use (default is entire partition).\n";
|
||||
|
||||
|
||||
|
||||
@@ -40,8 +40,8 @@
|
||||
#define BUFSIZE 100
|
||||
|
||||
static const char mnc_usage[] =
|
||||
"mini-netcat 0.0.3 -- Open pipe to IP:port\n"
|
||||
"\tmnc [IP] [port]\n";
|
||||
"mnc [IP] [port]\n\n"
|
||||
"mini-netcat opens a pipe to IP:port\n";
|
||||
|
||||
int
|
||||
mnc_main(int argc, char **argv)
|
||||
@@ -56,9 +56,15 @@ mnc_main(int argc, char **argv)
|
||||
|
||||
fd_set readfds, testfds;
|
||||
|
||||
if (argc<=1 || **(argv+1) == '-' ) {
|
||||
usage( mnc_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
sfd = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
hostinfo = (struct hostent *) gethostbyname(argv[1]);
|
||||
hostinfo = (struct hostent *) gethostbyname(*argv);
|
||||
|
||||
if (!hostinfo)
|
||||
{
|
||||
@@ -67,7 +73,7 @@ mnc_main(int argc, char **argv)
|
||||
|
||||
address.sin_family = AF_INET;
|
||||
address.sin_addr = *(struct in_addr *) *hostinfo->h_addr_list;
|
||||
address.sin_port = htons(atoi(argv[2]));
|
||||
address.sin_port = htons(atoi(*(++argv)));
|
||||
|
||||
len = sizeof(address);
|
||||
|
||||
|
||||
@@ -2,10 +2,11 @@
|
||||
* Mini more implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Blended by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
* based on the original more implementation and code from the Debian
|
||||
* boot-floppies team.
|
||||
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
* Latest version blended together by Erik Andersen <andersen@lineo.com>,
|
||||
* based on the original more implementation by Bruce, and code from the
|
||||
* Debian boot-floppies team.
|
||||
*
|
||||
* 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
|
||||
@@ -23,29 +24,20 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/* Turning this off makes things a bit smaller (and less pretty) */
|
||||
#define BB_MORE_TERM
|
||||
|
||||
|
||||
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
#include <fcntl.h>
|
||||
#include <signal.h>
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
|
||||
static const char more_usage[] = "[file ...]";
|
||||
|
||||
static const char more_usage[] = "more [file ...]\n";
|
||||
|
||||
/* ED: sparc termios is broken: revert back to old termio handling. */
|
||||
#ifdef BB_MORE_TERM
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
|
||||
|
||||
#if defined (__sparc__)
|
||||
#if #cpu(sparc)
|
||||
# define USE_OLD_TERMIO
|
||||
# include <termio.h>
|
||||
# include <sys/ioctl.h>
|
||||
# define termios termio
|
||||
# define stty(fd,argp) ioctl(fd,TCSETAF,argp)
|
||||
#else
|
||||
@@ -58,24 +50,43 @@ static const char more_usage[] = "[file ...]";
|
||||
|
||||
void gotsig(int sig) {
|
||||
stty(fileno(cin), &initial_settings);
|
||||
fprintf(stdout, "\n");
|
||||
exit( TRUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#define TERMINAL_WIDTH 79 /* not 80 in case terminal has linefold bug */
|
||||
#define TERMINAL_HEIGHT 24
|
||||
|
||||
|
||||
#if defined BB_FEATURE_AUTOWIDTH
|
||||
static int terminal_width = 0, terminal_height = 0;
|
||||
#else
|
||||
#define terminal_width TERMINAL_WIDTH
|
||||
#define terminal_height TERMINAL_HEIGHT
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
extern int more_main(int argc, char **argv)
|
||||
{
|
||||
int c, lines=0, input=0;
|
||||
int next_page=0;
|
||||
struct stat st;
|
||||
FILE *file;
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
struct winsize win = {0,0};
|
||||
#endif
|
||||
|
||||
if ( strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0 ) {
|
||||
usage (more_usage);
|
||||
}
|
||||
argc--;
|
||||
argv++;
|
||||
|
||||
while (argc >= 0) {
|
||||
if ( argc > 0 && (strcmp(*argv,"--help")==0 || strcmp(*argv,"-h")==0) ) {
|
||||
usage (more_usage);
|
||||
}
|
||||
do {
|
||||
if (argc==0) {
|
||||
file = stdin;
|
||||
}
|
||||
@@ -88,7 +99,7 @@ extern int more_main(int argc, char **argv)
|
||||
}
|
||||
fstat(fileno(file), &st);
|
||||
|
||||
#ifdef BB_MORE_TERM
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
cin = fopen("/dev/tty", "r");
|
||||
if (!cin)
|
||||
cin = fopen("/dev/console", "r");
|
||||
@@ -101,8 +112,18 @@ extern int more_main(int argc, char **argv)
|
||||
new_settings.c_lflag &= ~ICANON;
|
||||
new_settings.c_lflag &= ~ECHO;
|
||||
stty(fileno(cin), &new_settings);
|
||||
|
||||
|
||||
#ifdef BB_FEATURE_AUTOWIDTH
|
||||
ioctl(fileno(stdout), TIOCGWINSZ, &win);
|
||||
if (win.ws_row > 4)
|
||||
terminal_height = win.ws_row - 2;
|
||||
if (win.ws_col > 0)
|
||||
terminal_width = win.ws_col - 1;
|
||||
#endif
|
||||
|
||||
(void) signal(SIGINT, gotsig);
|
||||
(void) signal(SIGQUIT, gotsig);
|
||||
(void) signal(SIGTERM, gotsig);
|
||||
|
||||
#endif
|
||||
while ((c = getc(file)) != EOF) {
|
||||
@@ -117,7 +138,7 @@ extern int more_main(int argc, char **argv)
|
||||
st.st_size);
|
||||
}
|
||||
len += fprintf(stdout, "%s",
|
||||
#ifdef BB_MORE_TERM
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
""
|
||||
#else
|
||||
"\n"
|
||||
@@ -127,34 +148,40 @@ extern int more_main(int argc, char **argv)
|
||||
fflush(stdout);
|
||||
input = getc( cin);
|
||||
|
||||
#ifdef BB_MORE_TERM
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
/* Erase the "More" message */
|
||||
while(len-- > 0)
|
||||
while(--len >= 0)
|
||||
putc('\b', stdout);
|
||||
while(len++ < 79)
|
||||
while(++len <= terminal_width)
|
||||
putc(' ', stdout);
|
||||
while(len-- > 0)
|
||||
while(--len >= 0)
|
||||
putc('\b', stdout);
|
||||
fflush(stdout);
|
||||
#endif
|
||||
|
||||
}
|
||||
if (input=='q')
|
||||
goto end;
|
||||
if (input==' ' && c == '\n' )
|
||||
next_page = 1;
|
||||
if ( c == '\n' && ++lines == 24 )
|
||||
next_page = 1;
|
||||
if (c == '\n' ) {
|
||||
switch(input) {
|
||||
case 'q':
|
||||
goto end;
|
||||
case '\n':
|
||||
/* increment by just one line if we are at
|
||||
* the end of this line*/
|
||||
next_page = 1;
|
||||
break;
|
||||
}
|
||||
if ( ++lines == terminal_height )
|
||||
next_page = 1;
|
||||
}
|
||||
putc(c, stdout);
|
||||
}
|
||||
fclose(file);
|
||||
fflush(stdout);
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
} while (--argc > 0);
|
||||
end:
|
||||
#ifdef BB_MORE_TERM
|
||||
#ifdef BB_FEATURE_USE_TERMIOS
|
||||
gotsig(0);
|
||||
#endif
|
||||
exit(TRUE);
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
|
||||
extern const char mtab_file[]; /* Defined in utility.c */
|
||||
|
||||
static const char mount_usage[] = "Usage:\tmount [flags]\n"
|
||||
static const char mount_usage[] = "\tmount [flags]\n"
|
||||
"\tmount [flags] device directory [-o options,more-options]\n"
|
||||
"\n"
|
||||
"Flags:\n"
|
||||
@@ -92,12 +92,12 @@ static const struct mount_options mount_options[] = {
|
||||
};
|
||||
|
||||
#if ! defined BB_MTAB
|
||||
#define do_mount(specialfile, dir, filesystemtype, flags, string_flags, useMtab, fakeIt) \
|
||||
#define do_mount(specialfile, dir, filesystemtype, flags, string_flags, useMtab, fakeIt, mtab_opts) \
|
||||
mount(specialfile, dir, filesystemtype, flags, string_flags)
|
||||
#else
|
||||
static int
|
||||
do_mount(char* specialfile, char* dir, char* filesystemtype,
|
||||
long flags, void* string_flags, int useMtab, int fakeIt)
|
||||
long flags, void* string_flags, int useMtab, int fakeIt, char* mtab_opts)
|
||||
{
|
||||
int status=0;
|
||||
|
||||
@@ -106,7 +106,7 @@ do_mount(char* specialfile, char* dir, char* filesystemtype,
|
||||
|
||||
if ( status == 0 ) {
|
||||
if ( useMtab==TRUE )
|
||||
write_mtab(specialfile, dir, filesystemtype, flags, string_flags);
|
||||
write_mtab(specialfile, dir, filesystemtype, flags, mtab_opts);
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
@@ -157,12 +157,13 @@ parse_mount_options ( char *options, unsigned long *flags, char *strflags)
|
||||
|
||||
int
|
||||
mount_one(char *blockDevice, char *directory, char *filesystemType,
|
||||
unsigned long flags, char *string_flags, int useMtab, int fakeIt)
|
||||
unsigned long flags, char *string_flags, int useMtab, int fakeIt, char *mtab_opts)
|
||||
{
|
||||
int status = 0;
|
||||
|
||||
char buf[255];
|
||||
|
||||
#if defined BB_FEATURE_USE_PROCFS
|
||||
if (strcmp(filesystemType, "auto") == 0) {
|
||||
FILE *f = fopen ("/proc/filesystems", "r");
|
||||
|
||||
@@ -182,15 +183,19 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
|
||||
filesystemType++; // hop past tab
|
||||
|
||||
status = do_mount (blockDevice, directory, filesystemType,
|
||||
flags | MS_MGC_VAL, string_flags, useMtab, fakeIt);
|
||||
flags | MS_MGC_VAL, string_flags, useMtab,
|
||||
fakeIt, mtab_opts);
|
||||
if (status == 0)
|
||||
break;
|
||||
}
|
||||
}
|
||||
fclose (f);
|
||||
} else {
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
status = do_mount (blockDevice, directory, filesystemType,
|
||||
flags | MS_MGC_VAL, string_flags, useMtab, fakeIt);
|
||||
flags | MS_MGC_VAL, string_flags, useMtab,
|
||||
fakeIt, mtab_opts);
|
||||
}
|
||||
|
||||
if (status) {
|
||||
@@ -203,7 +208,9 @@ mount_one(char *blockDevice, char *directory, char *filesystemType,
|
||||
|
||||
extern int mount_main (int argc, char **argv)
|
||||
{
|
||||
char string_flags[1024]="";
|
||||
char string_flags_buf[1024]="";
|
||||
char *string_flags = string_flags_buf;
|
||||
char *extra_opts = string_flags_buf;
|
||||
unsigned long flags = 0;
|
||||
char *filesystemType = "auto";
|
||||
char *device = NULL;
|
||||
@@ -245,27 +252,22 @@ extern int mount_main (int argc, char **argv)
|
||||
argv++;
|
||||
while (i > 0 && **argv) {
|
||||
if (**argv == '-') {
|
||||
while (i>0 && *++(*argv)) switch (**argv) {
|
||||
char *opt = *argv;
|
||||
while (i>0 && *++opt) switch (*opt) {
|
||||
case 'o':
|
||||
if (--i == 0) {
|
||||
fprintf (stderr, "%s\n", mount_usage);
|
||||
exit( FALSE);
|
||||
goto goodbye;
|
||||
}
|
||||
parse_mount_options (*(++argv), &flags, string_flags);
|
||||
--i;
|
||||
++argv;
|
||||
break;
|
||||
case 'r':
|
||||
flags |= MS_RDONLY;
|
||||
break;
|
||||
case 't':
|
||||
if (--i == 0) {
|
||||
fprintf (stderr, "%s\n", mount_usage);
|
||||
exit( FALSE);
|
||||
goto goodbye;
|
||||
}
|
||||
filesystemType = *(++argv);
|
||||
--i;
|
||||
++argv;
|
||||
break;
|
||||
case 'w':
|
||||
flags &= ~MS_RDONLY;
|
||||
@@ -284,9 +286,7 @@ extern int mount_main (int argc, char **argv)
|
||||
case 'v':
|
||||
case 'h':
|
||||
case '-':
|
||||
fprintf (stderr, "%s\n", mount_usage);
|
||||
exit( TRUE);
|
||||
break;
|
||||
goto goodbye;
|
||||
}
|
||||
} else {
|
||||
if (device == NULL)
|
||||
@@ -294,8 +294,7 @@ extern int mount_main (int argc, char **argv)
|
||||
else if (directory == NULL)
|
||||
directory=*argv;
|
||||
else {
|
||||
fprintf (stderr, "%s\n", mount_usage);
|
||||
exit( TRUE);
|
||||
goto goodbye;
|
||||
}
|
||||
}
|
||||
i--;
|
||||
@@ -322,18 +321,26 @@ extern int mount_main (int argc, char **argv)
|
||||
*string_flags = '\0';
|
||||
parse_mount_options(m->mnt_opts, &flags, string_flags);
|
||||
mount_one (m->mnt_fsname, m->mnt_dir, m->mnt_type,
|
||||
flags, string_flags, useMtab, fakeIt);
|
||||
flags, string_flags, useMtab, fakeIt, extra_opts);
|
||||
}
|
||||
}
|
||||
endmntent (f);
|
||||
} else {
|
||||
if (device && directory) {
|
||||
#ifdef BB_NFSMOUNT
|
||||
if (strcmp(filesystemType, "nfs") == 0) {
|
||||
if (nfsmount(device, directory, &flags, &extra_opts, &string_flags, 1) != 0)
|
||||
exit(FALSE);
|
||||
}
|
||||
#endif
|
||||
exit (mount_one (device, directory, filesystemType,
|
||||
flags, string_flags, useMtab, fakeIt));
|
||||
flags, string_flags, useMtab, fakeIt, extra_opts));
|
||||
} else {
|
||||
fprintf (stderr, "%s\n", mount_usage);
|
||||
exit( FALSE);
|
||||
goto goodbye;
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
|
||||
goodbye:
|
||||
usage( mount_usage);
|
||||
}
|
||||
@@ -26,8 +26,14 @@ erase_mtab(const char * name)
|
||||
FILE *mountTable = setmntent(mtab_file, "r");
|
||||
struct mntent * m;
|
||||
|
||||
if ( mountTable == 0
|
||||
&& (mountTable = setmntent("/proc/mounts", "r")) == 0 ) {
|
||||
/* Check if reading the mtab file failed */
|
||||
if ( mountTable == 0
|
||||
#if ! defined BB_FEATURE_USE_PROCFS
|
||||
) {
|
||||
#else
|
||||
/* Bummer. fall back on trying the /proc filesystem */
|
||||
&& (mountTable = setmntent("/proc/mounts", "r")) == 0 ) {
|
||||
#endif
|
||||
perror(mtab_file);
|
||||
return;
|
||||
}
|
||||
@@ -76,13 +82,14 @@ write_mtab(char* blockDevice, char* directory,
|
||||
if ( length > 1 && directory[length - 1] == '/' )
|
||||
directory[length - 1] = '\0';
|
||||
|
||||
#ifdef BB_FEATURE_USE_PROCFS
|
||||
if ( filesystemType == 0 ) {
|
||||
struct mntent * p
|
||||
= findMountPoint(blockDevice, "/proc/mounts");
|
||||
struct mntent *p = findMountPoint(blockDevice, "/proc/mounts");
|
||||
|
||||
if ( p && p->mnt_type )
|
||||
filesystemType = p->mnt_type;
|
||||
}
|
||||
#endif
|
||||
m.mnt_fsname = blockDevice;
|
||||
m.mnt_dir = directory;
|
||||
m.mnt_type = filesystemType ? filesystemType : "default";
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
|
||||
|
||||
static const char mv_usage[] = "mv SOURCE DEST\n"
|
||||
" or: mv SOURCE... DIRECTORY\n"
|
||||
" or: mv SOURCE... DIRECTORY\n\n"
|
||||
"Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.\n";
|
||||
|
||||
|
||||
@@ -56,7 +56,7 @@ extern int mv_main(int argc, char **argv)
|
||||
fprintf(stderr, "%s: not a directory\n", destName);
|
||||
exit (FALSE);
|
||||
}
|
||||
|
||||
|
||||
while (argc-- > 1) {
|
||||
srcName = *(argv++);
|
||||
skipName = strrchr(srcName, '/');
|
||||
@@ -67,6 +67,11 @@ extern int mv_main(int argc, char **argv)
|
||||
strcat(newdestName, "/");
|
||||
if ( skipName != NULL)
|
||||
strcat(newdestName, strstr(srcName, skipName));
|
||||
else
|
||||
strcat(newdestName, srcName);
|
||||
fprintf(stderr, "srcName='%s'\n", srcName);
|
||||
fprintf(stderr, "skipName='%s'\n", skipName);
|
||||
fprintf(stderr, "newdestName='%s'\n", newdestName);
|
||||
}
|
||||
if (copyFile(srcName, newdestName, FALSE, FALSE) == FALSE) {
|
||||
exit( FALSE);
|
||||
|
||||
@@ -0,0 +1,138 @@
|
||||
/*
|
||||
* $Id: hostname.c,v 1.5 1999/12/09 06:11:36 andersen Exp $
|
||||
* Mini hostname implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
|
||||
*
|
||||
* adjusted by Erik Andersen <andersee@debian.org> to remove
|
||||
* use of long options and GNU getopt. Improved the usage info.
|
||||
*
|
||||
* 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 "internal.h"
|
||||
#include <errno.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
|
||||
static const char* hostname_usage =
|
||||
"hostname [OPTION] {hostname | -F file}\n\n"
|
||||
"Get or set the hostname or DNS domain name. If a hostname is given\n"
|
||||
"(or a file with the -F parameter), the host name will be set.\n\n"
|
||||
"Options:\n"
|
||||
"\t-s\t\tShort\n"
|
||||
"\t-i\t\tAddresses for the hostname\n"
|
||||
"\t-d\t\tDNS domain name\n"
|
||||
"\t-F FILE\t\tUse the contents of FILE to specify the hostname\n";
|
||||
|
||||
|
||||
void do_sethostname(char *s, int isfile)
|
||||
{
|
||||
FILE *f;
|
||||
char buf[255];
|
||||
|
||||
if (!s) return;
|
||||
if (!isfile) {
|
||||
if (sethostname(s, strlen(s)) < 0) {
|
||||
if (errno == EPERM)
|
||||
fprintf(stderr, "hostname: you must be root to change the hostname\n");
|
||||
else
|
||||
perror("sethostname");
|
||||
exit(1);
|
||||
}
|
||||
} else {
|
||||
if ((f = fopen(s, "r")) == NULL) {
|
||||
perror(s);
|
||||
exit(1);
|
||||
} else {
|
||||
fgets(buf, 255, f);
|
||||
fclose(f);
|
||||
if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
|
||||
if (sethostname(buf, strlen(buf)) < 0) {
|
||||
perror("sethostname");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int hostname_main(int argc, char **argv)
|
||||
{
|
||||
int opt_short = 0;
|
||||
int opt_domain = 0;
|
||||
int opt_ip = 0;
|
||||
struct hostent *h;
|
||||
char *filename = NULL;
|
||||
char buf[255];
|
||||
char *s = NULL;
|
||||
|
||||
if (argc < 1) usage(hostname_usage);
|
||||
|
||||
while (--argc > 0 && **(++argv) == '-') {
|
||||
while (*(++(*argv))) {
|
||||
switch (**argv) {
|
||||
case 's':
|
||||
opt_short = 1;
|
||||
break;
|
||||
case 'i':
|
||||
opt_ip = 1;
|
||||
break;
|
||||
case 'd':
|
||||
opt_domain = 1;
|
||||
break;
|
||||
case 'F':
|
||||
filename = optarg;
|
||||
if (--argc == 0) {
|
||||
usage(hostname_usage);
|
||||
}
|
||||
filename = *(++argv);
|
||||
break;
|
||||
default:
|
||||
usage(hostname_usage);
|
||||
}
|
||||
if (filename!=NULL)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc >= 1) {
|
||||
do_sethostname(*argv, 0);
|
||||
} else if (filename!=NULL) {
|
||||
do_sethostname(filename, 1);
|
||||
} else {
|
||||
gethostname(buf, 255);
|
||||
if (opt_short) {
|
||||
s = strchr(buf, '.');
|
||||
if (!s) s = buf; *s = 0;
|
||||
printf("%s\n", buf);
|
||||
} else if (opt_domain) {
|
||||
s = strchr(buf, '.');
|
||||
printf("%s\n", (s ? s+1 : ""));
|
||||
} else if (opt_ip) {
|
||||
h = gethostbyname(buf);
|
||||
if (!h) {
|
||||
printf("Host not found\n");
|
||||
exit(1);
|
||||
}
|
||||
printf("%s\n", inet_ntoa(*(struct in_addr *)(h->h_addr)));
|
||||
} else {
|
||||
printf("%s\n", buf);
|
||||
}
|
||||
}
|
||||
exit( 0);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,371 @@
|
||||
/*
|
||||
* $Id: ping.c,v 1.5 1999/12/09 06:11:36 andersen Exp $
|
||||
* Mini ping implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* This version of ping is adapted from the ping in netkit-base 0.10,
|
||||
* which is:
|
||||
*
|
||||
* Copyright (c) 1989 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Mike Muuss.
|
||||
*
|
||||
* Original copyright notice is retained at the end of this file.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
#include <sys/signal.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define DEFDATALEN 56
|
||||
#define MAXIPLEN 60
|
||||
#define MAXICMPLEN 76
|
||||
#define MAXPACKET 65468
|
||||
#define MAX_DUP_CHK (8 * 128)
|
||||
#define MAXWAIT 10
|
||||
#define PINGINTERVAL 1 /* second */
|
||||
|
||||
#define O_QUIET (1 << 0)
|
||||
|
||||
#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
|
||||
#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
|
||||
#define SET(bit) (A(bit) |= B(bit))
|
||||
#define CLR(bit) (A(bit) &= (~B(bit)))
|
||||
#define TST(bit) (A(bit) & B(bit))
|
||||
|
||||
static const char* ping_usage = "ping [OPTION]... host\n\n"
|
||||
"Send ICMP ECHO_REQUEST packets to network hosts.\n\n"
|
||||
"Options:\n"
|
||||
"\t-q\t\tQuiet mode, only displays output at start and when finished.\n"
|
||||
"\t-c COUNT\tSend only COUNT pings.\n";
|
||||
|
||||
static char *hostname = NULL;
|
||||
static struct sockaddr_in pingaddr;
|
||||
static int pingsock = -1;
|
||||
static long ntransmitted = 0, nreceived = 0, nrepeats = 0, pingcount = 0;
|
||||
static int myid = 0, options = 0;
|
||||
static unsigned long tmin = ULONG_MAX, tmax = 0, tsum = 0;
|
||||
static char rcvd_tbl[MAX_DUP_CHK / 8];
|
||||
|
||||
static void pingstats(int);
|
||||
static void sendping(int);
|
||||
static void unpack(char *, int, struct sockaddr_in *);
|
||||
static void ping(char *);
|
||||
static int in_cksum(unsigned short *, int);
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
static int in_cksum(unsigned short *buf, int sz)
|
||||
{
|
||||
int nleft = sz;
|
||||
int sum = 0;
|
||||
unsigned short *w = buf;
|
||||
unsigned short ans = 0;
|
||||
|
||||
while (nleft > 1) {
|
||||
sum += *w++;
|
||||
nleft -= 2;
|
||||
}
|
||||
|
||||
if (nleft == 1) {
|
||||
*(unsigned char *)(&ans) = *(unsigned char *)w;
|
||||
sum += ans;
|
||||
}
|
||||
|
||||
sum = (sum >> 16) + (sum & 0xFFFF);
|
||||
sum += (sum >> 16);
|
||||
ans = ~sum;
|
||||
return(ans);
|
||||
}
|
||||
|
||||
static void pingstats(int ign) {
|
||||
signal(SIGINT, SIG_IGN);
|
||||
|
||||
printf("\n--- %s ping statistics ---\n", hostname);
|
||||
printf("%ld packets transmitted, ", ntransmitted);
|
||||
printf("%ld packets received, ", nreceived);
|
||||
if (nrepeats)
|
||||
printf("%ld duplicates, ", nrepeats);
|
||||
if (ntransmitted)
|
||||
printf("%ld%% packet loss\n",
|
||||
(ntransmitted - nreceived)*100/ntransmitted);
|
||||
if (nreceived)
|
||||
printf("round-trip min/avg/max = %lu.%lu/%lu.%lu/%lu.%lu ms\n",
|
||||
tmin/10, tmin%10,
|
||||
(tsum/(nreceived+nrepeats))/10,
|
||||
(tsum/(nreceived+nrepeats))%10,
|
||||
tmax/10, tmax%10);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void sendping(int ign)
|
||||
{
|
||||
struct icmp *pkt;
|
||||
int i;
|
||||
char packet[DEFDATALEN + 8];
|
||||
|
||||
pkt = (struct icmp *)packet;
|
||||
|
||||
pkt->icmp_type = ICMP_ECHO;
|
||||
pkt->icmp_code = 0;
|
||||
pkt->icmp_cksum = 0;
|
||||
pkt->icmp_seq = ntransmitted++;
|
||||
pkt->icmp_id = myid;
|
||||
CLR(pkt->icmp_seq % MAX_DUP_CHK);
|
||||
|
||||
gettimeofday((struct timeval *)&packet[8], NULL);
|
||||
pkt->icmp_cksum = in_cksum((unsigned short *)pkt, sizeof(packet));
|
||||
|
||||
i = sendto(pingsock, packet, sizeof(packet), 0,
|
||||
(struct sockaddr *)&pingaddr, sizeof(struct sockaddr_in));
|
||||
|
||||
if (i < 0 || i != sizeof(packet)) {
|
||||
if (i < 0) perror("ping");
|
||||
fprintf(stderr, "ping wrote %d chars; %d expected\n", i, sizeof(packet));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
signal(SIGALRM, sendping);
|
||||
if (pingcount == 0 || ntransmitted < pingcount) { /* schedule next in 1s */
|
||||
alarm(PINGINTERVAL);
|
||||
} else { /* done, wait for the last ping to come back */
|
||||
/* todo, don't necessarily need to wait so long... */
|
||||
signal(SIGALRM, pingstats);
|
||||
alarm(MAXWAIT);
|
||||
}
|
||||
}
|
||||
|
||||
static void unpack(char *buf, int sz, struct sockaddr_in *from)
|
||||
{
|
||||
struct icmp *icmppkt;
|
||||
struct iphdr *iphdr;
|
||||
struct timeval tv, *tp;
|
||||
int hlen, dupflag;
|
||||
unsigned long triptime;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
/* check IP header */
|
||||
iphdr = (struct iphdr *)buf;
|
||||
hlen = iphdr->ihl << 2;
|
||||
/* discard if too short */
|
||||
if (sz < (DEFDATALEN + ICMP_MINLEN)) return;
|
||||
|
||||
sz -= hlen;
|
||||
icmppkt = (struct icmp *)(buf + hlen);
|
||||
|
||||
if (icmppkt->icmp_type == ICMP_ECHOREPLY) {
|
||||
if (icmppkt->icmp_id != myid) return; /* not our ping */
|
||||
++nreceived;
|
||||
tp = (struct timeval *)icmppkt->icmp_data;
|
||||
|
||||
if ((tv.tv_usec -= tp->tv_usec) < 0) {
|
||||
--tv.tv_sec;
|
||||
tv.tv_usec += 1000000;
|
||||
}
|
||||
tv.tv_sec -= tp->tv_sec;
|
||||
|
||||
triptime = tv.tv_sec * 10000 + (tv.tv_usec / 100);
|
||||
tsum += triptime;
|
||||
if (triptime < tmin) tmin = triptime;
|
||||
if (triptime > tmax) tmax = triptime;
|
||||
|
||||
if (TST(icmppkt->icmp_seq % MAX_DUP_CHK)) {
|
||||
++nrepeats;
|
||||
--nreceived;
|
||||
dupflag = 1;
|
||||
} else {
|
||||
SET(icmppkt->icmp_seq % MAX_DUP_CHK);
|
||||
dupflag = 0;
|
||||
}
|
||||
|
||||
if (options & O_QUIET) return;
|
||||
|
||||
printf("%d bytes from %s: icmp_seq=%u", sz,
|
||||
inet_ntoa(*(struct in_addr *)&from->sin_addr.s_addr),
|
||||
icmppkt->icmp_seq);
|
||||
printf(" ttl=%d", iphdr->ttl);
|
||||
printf(" time=%lu.%lu ms", triptime/10, triptime%10);
|
||||
if (dupflag) printf(" (DUP!)");
|
||||
printf("\n");
|
||||
} else {
|
||||
fprintf(stderr, "Warning: unknown ICMP packet received (not echo-reply)\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void ping(char *host)
|
||||
{
|
||||
struct protoent *proto;
|
||||
struct hostent *h;
|
||||
char buf[MAXHOSTNAMELEN];
|
||||
char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
|
||||
int sockopt;
|
||||
|
||||
if (!(proto = getprotobyname("icmp"))) {
|
||||
fprintf(stderr, "ping: unknown protocol icmp\n");
|
||||
exit(1);
|
||||
}
|
||||
if ((pingsock = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0) {
|
||||
if (errno == EPERM) {
|
||||
fprintf(stderr, "ping: permission denied. (are you root?)\n");
|
||||
} else {
|
||||
perror("ping");
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* drop root privs if running setuid */
|
||||
setuid(getuid());
|
||||
|
||||
memset(&pingaddr, 0, sizeof(struct sockaddr_in));
|
||||
pingaddr.sin_family = AF_INET;
|
||||
if (inet_aton(host, &pingaddr.sin_addr)) {
|
||||
hostname = host;
|
||||
} else {
|
||||
if (!(h = gethostbyname(host))) {
|
||||
fprintf(stderr, "ping: unknown host %s\n", host);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (h->h_addrtype != AF_INET) {
|
||||
fprintf(stderr, "ping: unknown address type; only AF_INET is currently supported.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pingaddr.sin_family = AF_INET; /* h->h_addrtype */
|
||||
memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
|
||||
strncpy(buf, h->h_name, sizeof(buf)-1);
|
||||
hostname = buf;
|
||||
}
|
||||
|
||||
/* enable broadcast pings */
|
||||
sockopt = 1;
|
||||
setsockopt(pingsock, SOL_SOCKET, SO_BROADCAST, (char *)&sockopt, sizeof(sockopt));
|
||||
|
||||
/* set recv buf for broadcast pings */
|
||||
sockopt = 48 * 1024;
|
||||
setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, (char *)&sockopt, sizeof(sockopt));
|
||||
|
||||
printf("PING %s (%s): %d data bytes\n",
|
||||
hostname, inet_ntoa(*(struct in_addr *)&pingaddr.sin_addr.s_addr),
|
||||
DEFDATALEN);
|
||||
|
||||
signal(SIGINT, pingstats);
|
||||
|
||||
/* start the ping's going ... */
|
||||
sendping(0);
|
||||
|
||||
/* listen for replies */
|
||||
while (1) {
|
||||
struct sockaddr_in from;
|
||||
size_t fromlen = sizeof(from);
|
||||
int c;
|
||||
|
||||
if ((c = recvfrom(pingsock, packet, sizeof(packet), 0,
|
||||
(struct sockaddr *)&from, &fromlen)) < 0) {
|
||||
if (errno == EINTR) continue;
|
||||
perror("ping");
|
||||
continue;
|
||||
}
|
||||
unpack(packet, c, &from);
|
||||
if (pingcount > 0 && nreceived >= pingcount) break;
|
||||
}
|
||||
pingstats(0);
|
||||
}
|
||||
|
||||
extern int ping_main(int argc, char **argv)
|
||||
{
|
||||
char *thisarg;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
options = 0;
|
||||
/* Parse any options */
|
||||
while (argc > 1) {
|
||||
if (**argv != '-') usage(ping_usage);
|
||||
thisarg = *argv; thisarg++;
|
||||
switch (*thisarg) {
|
||||
case 'q': options |= O_QUIET; break;
|
||||
case 'c':
|
||||
argc--; argv++;
|
||||
pingcount = atoi(*argv);
|
||||
break;
|
||||
default:
|
||||
usage(ping_usage);
|
||||
}
|
||||
argc--; argv++;
|
||||
}
|
||||
if (argc < 1) usage(ping_usage);
|
||||
|
||||
myid = getpid() & 0xFFFF;
|
||||
ping(*argv);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Mike Muuss.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
+1309
File diff suppressed because it is too large.
Load diff
+325
@@ -0,0 +1,325 @@
|
||||
/*
|
||||
* Please do not edit this file.
|
||||
* It was generated using rpcgen.
|
||||
*/
|
||||
|
||||
#ifndef _NFSMOUNT_H_RPCGEN
|
||||
#define _NFSMOUNT_H_RPCGEN
|
||||
|
||||
#include <rpc/rpc.h>
|
||||
|
||||
/*
|
||||
* Sun RPC is a product of Sun Microsystems, Inc. and is provided for
|
||||
* unrestricted use provided that this legend is included on all tape
|
||||
* media and as a part of the software program in whole or part. Users
|
||||
* may copy or modify Sun RPC without charge, but are not authorized
|
||||
* to license or distribute it to anyone else except as part of a product or
|
||||
* program developed by the user or with the express written consent of
|
||||
* Sun Microsystems, Inc.
|
||||
*
|
||||
* SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
|
||||
* WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
|
||||
*
|
||||
* Sun RPC is provided with no support and without any obligation on the
|
||||
* part of Sun Microsystems, Inc. to assist in its use, correction,
|
||||
* modification or enhancement.
|
||||
*
|
||||
* SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
|
||||
* INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
|
||||
* OR ANY PART THEREOF.
|
||||
*
|
||||
* In no event will Sun Microsystems, Inc. be liable for any lost revenue
|
||||
* or profits or other special, indirect and consequential damages, even if
|
||||
* Sun has been advised of the possibility of such damages.
|
||||
*
|
||||
* Sun Microsystems, Inc.
|
||||
* 2550 Garcia Avenue
|
||||
* Mountain View, California 94043
|
||||
*/
|
||||
/*
|
||||
* Copyright (c) 1985, 1990 by Sun Microsystems, Inc.
|
||||
*/
|
||||
|
||||
/* from @(#)mount.x 1.3 91/03/11 TIRPC 1.0 */
|
||||
#ifndef _rpcsvc_mount_h
|
||||
#define _rpcsvc_mount_h
|
||||
#define MNTPATHLEN 1024
|
||||
#define MNTNAMLEN 255
|
||||
#define FHSIZE 32
|
||||
|
||||
typedef char fhandle[FHSIZE];
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_fhandle(XDR *, fhandle);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_fhandle(XDR *, fhandle);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_fhandle();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
struct fhstatus {
|
||||
u_int fhs_status;
|
||||
union {
|
||||
fhandle fhs_fhandle;
|
||||
} fhstatus_u;
|
||||
};
|
||||
typedef struct fhstatus fhstatus;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_fhstatus(XDR *, fhstatus*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_fhstatus(XDR *, fhstatus*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_fhstatus();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
typedef char *dirpath;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_dirpath(XDR *, dirpath*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_dirpath(XDR *, dirpath*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_dirpath();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
typedef char *name;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_name(XDR *, name*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_name(XDR *, name*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_name();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
typedef struct mountbody *mountlist;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_mountlist(XDR *, mountlist*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_mountlist(XDR *, mountlist*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_mountlist();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
struct mountbody {
|
||||
name ml_hostname;
|
||||
dirpath ml_directory;
|
||||
mountlist ml_next;
|
||||
};
|
||||
typedef struct mountbody mountbody;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_mountbody(XDR *, mountbody*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_mountbody(XDR *, mountbody*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_mountbody();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
typedef struct groupnode *groups;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_groups(XDR *, groups*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_groups(XDR *, groups*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_groups();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
struct groupnode {
|
||||
name gr_name;
|
||||
groups gr_next;
|
||||
};
|
||||
typedef struct groupnode groupnode;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_groupnode(XDR *, groupnode*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_groupnode(XDR *, groupnode*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_groupnode();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
typedef struct exportnode *exports;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_exports(XDR *, exports*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_exports(XDR *, exports*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_exports();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
struct exportnode {
|
||||
dirpath ex_dir;
|
||||
groups ex_groups;
|
||||
exports ex_next;
|
||||
};
|
||||
typedef struct exportnode exportnode;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_exportnode(XDR *, exportnode*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_exportnode(XDR *, exportnode*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_exportnode();
|
||||
#endif /* Old Style C */
|
||||
|
||||
|
||||
struct ppathcnf {
|
||||
int pc_link_max;
|
||||
short pc_max_canon;
|
||||
short pc_max_input;
|
||||
short pc_name_max;
|
||||
short pc_path_max;
|
||||
short pc_pipe_buf;
|
||||
u_char pc_vdisable;
|
||||
char pc_xxx;
|
||||
short pc_mask[2];
|
||||
};
|
||||
typedef struct ppathcnf ppathcnf;
|
||||
#ifdef __cplusplus
|
||||
extern "C" bool_t xdr_ppathcnf(XDR *, ppathcnf*);
|
||||
#elif __STDC__
|
||||
extern bool_t xdr_ppathcnf(XDR *, ppathcnf*);
|
||||
#else /* Old Style C */
|
||||
bool_t xdr_ppathcnf();
|
||||
#endif /* Old Style C */
|
||||
|
||||
#endif /*!_rpcsvc_mount_h*/
|
||||
|
||||
#define MOUNTPROG ((u_long)100005)
|
||||
#define MOUNTVERS ((u_long)1)
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define MOUNTPROC_NULL ((u_long)0)
|
||||
extern "C" void * mountproc_null_1(void *, CLIENT *);
|
||||
extern "C" void * mountproc_null_1_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_MNT ((u_long)1)
|
||||
extern "C" fhstatus * mountproc_mnt_1(dirpath *, CLIENT *);
|
||||
extern "C" fhstatus * mountproc_mnt_1_svc(dirpath *, struct svc_req *);
|
||||
#define MOUNTPROC_DUMP ((u_long)2)
|
||||
extern "C" mountlist * mountproc_dump_1(void *, CLIENT *);
|
||||
extern "C" mountlist * mountproc_dump_1_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_UMNT ((u_long)3)
|
||||
extern "C" void * mountproc_umnt_1(dirpath *, CLIENT *);
|
||||
extern "C" void * mountproc_umnt_1_svc(dirpath *, struct svc_req *);
|
||||
#define MOUNTPROC_UMNTALL ((u_long)4)
|
||||
extern "C" void * mountproc_umntall_1(void *, CLIENT *);
|
||||
extern "C" void * mountproc_umntall_1_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_EXPORT ((u_long)5)
|
||||
extern "C" exports * mountproc_export_1(void *, CLIENT *);
|
||||
extern "C" exports * mountproc_export_1_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_EXPORTALL ((u_long)6)
|
||||
extern "C" exports * mountproc_exportall_1(void *, CLIENT *);
|
||||
extern "C" exports * mountproc_exportall_1_svc(void *, struct svc_req *);
|
||||
|
||||
#elif __STDC__
|
||||
#define MOUNTPROC_NULL ((u_long)0)
|
||||
extern void * mountproc_null_1(void *, CLIENT *);
|
||||
extern void * mountproc_null_1_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_MNT ((u_long)1)
|
||||
extern fhstatus * mountproc_mnt_1(dirpath *, CLIENT *);
|
||||
extern fhstatus * mountproc_mnt_1_svc(dirpath *, struct svc_req *);
|
||||
#define MOUNTPROC_DUMP ((u_long)2)
|
||||
extern mountlist * mountproc_dump_1(void *, CLIENT *);
|
||||
extern mountlist * mountproc_dump_1_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_UMNT ((u_long)3)
|
||||
extern void * mountproc_umnt_1(dirpath *, CLIENT *);
|
||||
extern void * mountproc_umnt_1_svc(dirpath *, struct svc_req *);
|
||||
#define MOUNTPROC_UMNTALL ((u_long)4)
|
||||
extern void * mountproc_umntall_1(void *, CLIENT *);
|
||||
extern void * mountproc_umntall_1_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_EXPORT ((u_long)5)
|
||||
extern exports * mountproc_export_1(void *, CLIENT *);
|
||||
extern exports * mountproc_export_1_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_EXPORTALL ((u_long)6)
|
||||
extern exports * mountproc_exportall_1(void *, CLIENT *);
|
||||
extern exports * mountproc_exportall_1_svc(void *, struct svc_req *);
|
||||
|
||||
#else /* Old Style C */
|
||||
#define MOUNTPROC_NULL ((u_long)0)
|
||||
extern void * mountproc_null_1();
|
||||
extern void * mountproc_null_1_svc();
|
||||
#define MOUNTPROC_MNT ((u_long)1)
|
||||
extern fhstatus * mountproc_mnt_1();
|
||||
extern fhstatus * mountproc_mnt_1_svc();
|
||||
#define MOUNTPROC_DUMP ((u_long)2)
|
||||
extern mountlist * mountproc_dump_1();
|
||||
extern mountlist * mountproc_dump_1_svc();
|
||||
#define MOUNTPROC_UMNT ((u_long)3)
|
||||
extern void * mountproc_umnt_1();
|
||||
extern void * mountproc_umnt_1_svc();
|
||||
#define MOUNTPROC_UMNTALL ((u_long)4)
|
||||
extern void * mountproc_umntall_1();
|
||||
extern void * mountproc_umntall_1_svc();
|
||||
#define MOUNTPROC_EXPORT ((u_long)5)
|
||||
extern exports * mountproc_export_1();
|
||||
extern exports * mountproc_export_1_svc();
|
||||
#define MOUNTPROC_EXPORTALL ((u_long)6)
|
||||
extern exports * mountproc_exportall_1();
|
||||
extern exports * mountproc_exportall_1_svc();
|
||||
#endif /* Old Style C */
|
||||
#define MOUNTVERS_POSIX ((u_long)2)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" void * mountproc_null_2(void *, CLIENT *);
|
||||
extern "C" void * mountproc_null_2_svc(void *, struct svc_req *);
|
||||
extern "C" fhstatus * mountproc_mnt_2(dirpath *, CLIENT *);
|
||||
extern "C" fhstatus * mountproc_mnt_2_svc(dirpath *, struct svc_req *);
|
||||
extern "C" mountlist * mountproc_dump_2(void *, CLIENT *);
|
||||
extern "C" mountlist * mountproc_dump_2_svc(void *, struct svc_req *);
|
||||
extern "C" void * mountproc_umnt_2(dirpath *, CLIENT *);
|
||||
extern "C" void * mountproc_umnt_2_svc(dirpath *, struct svc_req *);
|
||||
extern "C" void * mountproc_umntall_2(void *, CLIENT *);
|
||||
extern "C" void * mountproc_umntall_2_svc(void *, struct svc_req *);
|
||||
extern "C" exports * mountproc_export_2(void *, CLIENT *);
|
||||
extern "C" exports * mountproc_export_2_svc(void *, struct svc_req *);
|
||||
extern "C" exports * mountproc_exportall_2(void *, CLIENT *);
|
||||
extern "C" exports * mountproc_exportall_2_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_PATHCONF ((u_long)7)
|
||||
extern "C" ppathcnf * mountproc_pathconf_2(dirpath *, CLIENT *);
|
||||
extern "C" ppathcnf * mountproc_pathconf_2_svc(dirpath *, struct svc_req *);
|
||||
|
||||
#elif __STDC__
|
||||
extern void * mountproc_null_2(void *, CLIENT *);
|
||||
extern void * mountproc_null_2_svc(void *, struct svc_req *);
|
||||
extern fhstatus * mountproc_mnt_2(dirpath *, CLIENT *);
|
||||
extern fhstatus * mountproc_mnt_2_svc(dirpath *, struct svc_req *);
|
||||
extern mountlist * mountproc_dump_2(void *, CLIENT *);
|
||||
extern mountlist * mountproc_dump_2_svc(void *, struct svc_req *);
|
||||
extern void * mountproc_umnt_2(dirpath *, CLIENT *);
|
||||
extern void * mountproc_umnt_2_svc(dirpath *, struct svc_req *);
|
||||
extern void * mountproc_umntall_2(void *, CLIENT *);
|
||||
extern void * mountproc_umntall_2_svc(void *, struct svc_req *);
|
||||
extern exports * mountproc_export_2(void *, CLIENT *);
|
||||
extern exports * mountproc_export_2_svc(void *, struct svc_req *);
|
||||
extern exports * mountproc_exportall_2(void *, CLIENT *);
|
||||
extern exports * mountproc_exportall_2_svc(void *, struct svc_req *);
|
||||
#define MOUNTPROC_PATHCONF ((u_long)7)
|
||||
extern ppathcnf * mountproc_pathconf_2(dirpath *, CLIENT *);
|
||||
extern ppathcnf * mountproc_pathconf_2_svc(dirpath *, struct svc_req *);
|
||||
|
||||
#else /* Old Style C */
|
||||
extern void * mountproc_null_2();
|
||||
extern void * mountproc_null_2_svc();
|
||||
extern fhstatus * mountproc_mnt_2();
|
||||
extern fhstatus * mountproc_mnt_2_svc();
|
||||
extern mountlist * mountproc_dump_2();
|
||||
extern mountlist * mountproc_dump_2_svc();
|
||||
extern void * mountproc_umnt_2();
|
||||
extern void * mountproc_umnt_2_svc();
|
||||
extern void * mountproc_umntall_2();
|
||||
extern void * mountproc_umntall_2_svc();
|
||||
extern exports * mountproc_export_2();
|
||||
extern exports * mountproc_export_2_svc();
|
||||
extern exports * mountproc_exportall_2();
|
||||
extern exports * mountproc_exportall_2_svc();
|
||||
#define MOUNTPROC_PATHCONF ((u_long)7)
|
||||
extern ppathcnf * mountproc_pathconf_2();
|
||||
extern ppathcnf * mountproc_pathconf_2_svc();
|
||||
#endif /* Old Style C */
|
||||
|
||||
#endif /* !_NFSMOUNT_H_RPCGEN */
|
||||
@@ -0,0 +1,371 @@
|
||||
/*
|
||||
* $Id: ping.c,v 1.5 1999/12/09 06:11:36 andersen Exp $
|
||||
* Mini ping implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* This version of ping is adapted from the ping in netkit-base 0.10,
|
||||
* which is:
|
||||
*
|
||||
* Copyright (c) 1989 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Mike Muuss.
|
||||
*
|
||||
* Original copyright notice is retained at the end of this file.
|
||||
*/
|
||||
|
||||
#include "internal.h"
|
||||
#include <sys/param.h>
|
||||
#include <sys/socket.h>
|
||||
#include <sys/file.h>
|
||||
#include <sys/time.h>
|
||||
#include <sys/times.h>
|
||||
#include <sys/signal.h>
|
||||
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/ip.h>
|
||||
#include <netinet/ip_icmp.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <netdb.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <errno.h>
|
||||
|
||||
#define DEFDATALEN 56
|
||||
#define MAXIPLEN 60
|
||||
#define MAXICMPLEN 76
|
||||
#define MAXPACKET 65468
|
||||
#define MAX_DUP_CHK (8 * 128)
|
||||
#define MAXWAIT 10
|
||||
#define PINGINTERVAL 1 /* second */
|
||||
|
||||
#define O_QUIET (1 << 0)
|
||||
|
||||
#define A(bit) rcvd_tbl[(bit)>>3] /* identify byte in array */
|
||||
#define B(bit) (1 << ((bit) & 0x07)) /* identify bit in byte */
|
||||
#define SET(bit) (A(bit) |= B(bit))
|
||||
#define CLR(bit) (A(bit) &= (~B(bit)))
|
||||
#define TST(bit) (A(bit) & B(bit))
|
||||
|
||||
static const char* ping_usage = "ping [OPTION]... host\n\n"
|
||||
"Send ICMP ECHO_REQUEST packets to network hosts.\n\n"
|
||||
"Options:\n"
|
||||
"\t-q\t\tQuiet mode, only displays output at start and when finished.\n"
|
||||
"\t-c COUNT\tSend only COUNT pings.\n";
|
||||
|
||||
static char *hostname = NULL;
|
||||
static struct sockaddr_in pingaddr;
|
||||
static int pingsock = -1;
|
||||
static long ntransmitted = 0, nreceived = 0, nrepeats = 0, pingcount = 0;
|
||||
static int myid = 0, options = 0;
|
||||
static unsigned long tmin = ULONG_MAX, tmax = 0, tsum = 0;
|
||||
static char rcvd_tbl[MAX_DUP_CHK / 8];
|
||||
|
||||
static void pingstats(int);
|
||||
static void sendping(int);
|
||||
static void unpack(char *, int, struct sockaddr_in *);
|
||||
static void ping(char *);
|
||||
static int in_cksum(unsigned short *, int);
|
||||
|
||||
/**************************************************************************/
|
||||
|
||||
static int in_cksum(unsigned short *buf, int sz)
|
||||
{
|
||||
int nleft = sz;
|
||||
int sum = 0;
|
||||
unsigned short *w = buf;
|
||||
unsigned short ans = 0;
|
||||
|
||||
while (nleft > 1) {
|
||||
sum += *w++;
|
||||
nleft -= 2;
|
||||
}
|
||||
|
||||
if (nleft == 1) {
|
||||
*(unsigned char *)(&ans) = *(unsigned char *)w;
|
||||
sum += ans;
|
||||
}
|
||||
|
||||
sum = (sum >> 16) + (sum & 0xFFFF);
|
||||
sum += (sum >> 16);
|
||||
ans = ~sum;
|
||||
return(ans);
|
||||
}
|
||||
|
||||
static void pingstats(int ign) {
|
||||
signal(SIGINT, SIG_IGN);
|
||||
|
||||
printf("\n--- %s ping statistics ---\n", hostname);
|
||||
printf("%ld packets transmitted, ", ntransmitted);
|
||||
printf("%ld packets received, ", nreceived);
|
||||
if (nrepeats)
|
||||
printf("%ld duplicates, ", nrepeats);
|
||||
if (ntransmitted)
|
||||
printf("%ld%% packet loss\n",
|
||||
(ntransmitted - nreceived)*100/ntransmitted);
|
||||
if (nreceived)
|
||||
printf("round-trip min/avg/max = %lu.%lu/%lu.%lu/%lu.%lu ms\n",
|
||||
tmin/10, tmin%10,
|
||||
(tsum/(nreceived+nrepeats))/10,
|
||||
(tsum/(nreceived+nrepeats))%10,
|
||||
tmax/10, tmax%10);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
static void sendping(int ign)
|
||||
{
|
||||
struct icmp *pkt;
|
||||
int i;
|
||||
char packet[DEFDATALEN + 8];
|
||||
|
||||
pkt = (struct icmp *)packet;
|
||||
|
||||
pkt->icmp_type = ICMP_ECHO;
|
||||
pkt->icmp_code = 0;
|
||||
pkt->icmp_cksum = 0;
|
||||
pkt->icmp_seq = ntransmitted++;
|
||||
pkt->icmp_id = myid;
|
||||
CLR(pkt->icmp_seq % MAX_DUP_CHK);
|
||||
|
||||
gettimeofday((struct timeval *)&packet[8], NULL);
|
||||
pkt->icmp_cksum = in_cksum((unsigned short *)pkt, sizeof(packet));
|
||||
|
||||
i = sendto(pingsock, packet, sizeof(packet), 0,
|
||||
(struct sockaddr *)&pingaddr, sizeof(struct sockaddr_in));
|
||||
|
||||
if (i < 0 || i != sizeof(packet)) {
|
||||
if (i < 0) perror("ping");
|
||||
fprintf(stderr, "ping wrote %d chars; %d expected\n", i, sizeof(packet));
|
||||
exit(1);
|
||||
}
|
||||
|
||||
signal(SIGALRM, sendping);
|
||||
if (pingcount == 0 || ntransmitted < pingcount) { /* schedule next in 1s */
|
||||
alarm(PINGINTERVAL);
|
||||
} else { /* done, wait for the last ping to come back */
|
||||
/* todo, don't necessarily need to wait so long... */
|
||||
signal(SIGALRM, pingstats);
|
||||
alarm(MAXWAIT);
|
||||
}
|
||||
}
|
||||
|
||||
static void unpack(char *buf, int sz, struct sockaddr_in *from)
|
||||
{
|
||||
struct icmp *icmppkt;
|
||||
struct iphdr *iphdr;
|
||||
struct timeval tv, *tp;
|
||||
int hlen, dupflag;
|
||||
unsigned long triptime;
|
||||
|
||||
gettimeofday(&tv, NULL);
|
||||
|
||||
/* check IP header */
|
||||
iphdr = (struct iphdr *)buf;
|
||||
hlen = iphdr->ihl << 2;
|
||||
/* discard if too short */
|
||||
if (sz < (DEFDATALEN + ICMP_MINLEN)) return;
|
||||
|
||||
sz -= hlen;
|
||||
icmppkt = (struct icmp *)(buf + hlen);
|
||||
|
||||
if (icmppkt->icmp_type == ICMP_ECHOREPLY) {
|
||||
if (icmppkt->icmp_id != myid) return; /* not our ping */
|
||||
++nreceived;
|
||||
tp = (struct timeval *)icmppkt->icmp_data;
|
||||
|
||||
if ((tv.tv_usec -= tp->tv_usec) < 0) {
|
||||
--tv.tv_sec;
|
||||
tv.tv_usec += 1000000;
|
||||
}
|
||||
tv.tv_sec -= tp->tv_sec;
|
||||
|
||||
triptime = tv.tv_sec * 10000 + (tv.tv_usec / 100);
|
||||
tsum += triptime;
|
||||
if (triptime < tmin) tmin = triptime;
|
||||
if (triptime > tmax) tmax = triptime;
|
||||
|
||||
if (TST(icmppkt->icmp_seq % MAX_DUP_CHK)) {
|
||||
++nrepeats;
|
||||
--nreceived;
|
||||
dupflag = 1;
|
||||
} else {
|
||||
SET(icmppkt->icmp_seq % MAX_DUP_CHK);
|
||||
dupflag = 0;
|
||||
}
|
||||
|
||||
if (options & O_QUIET) return;
|
||||
|
||||
printf("%d bytes from %s: icmp_seq=%u", sz,
|
||||
inet_ntoa(*(struct in_addr *)&from->sin_addr.s_addr),
|
||||
icmppkt->icmp_seq);
|
||||
printf(" ttl=%d", iphdr->ttl);
|
||||
printf(" time=%lu.%lu ms", triptime/10, triptime%10);
|
||||
if (dupflag) printf(" (DUP!)");
|
||||
printf("\n");
|
||||
} else {
|
||||
fprintf(stderr, "Warning: unknown ICMP packet received (not echo-reply)\n");
|
||||
}
|
||||
}
|
||||
|
||||
static void ping(char *host)
|
||||
{
|
||||
struct protoent *proto;
|
||||
struct hostent *h;
|
||||
char buf[MAXHOSTNAMELEN];
|
||||
char packet[DEFDATALEN + MAXIPLEN + MAXICMPLEN];
|
||||
int sockopt;
|
||||
|
||||
if (!(proto = getprotobyname("icmp"))) {
|
||||
fprintf(stderr, "ping: unknown protocol icmp\n");
|
||||
exit(1);
|
||||
}
|
||||
if ((pingsock = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0) {
|
||||
if (errno == EPERM) {
|
||||
fprintf(stderr, "ping: permission denied. (are you root?)\n");
|
||||
} else {
|
||||
perror("ping");
|
||||
}
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* drop root privs if running setuid */
|
||||
setuid(getuid());
|
||||
|
||||
memset(&pingaddr, 0, sizeof(struct sockaddr_in));
|
||||
pingaddr.sin_family = AF_INET;
|
||||
if (inet_aton(host, &pingaddr.sin_addr)) {
|
||||
hostname = host;
|
||||
} else {
|
||||
if (!(h = gethostbyname(host))) {
|
||||
fprintf(stderr, "ping: unknown host %s\n", host);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (h->h_addrtype != AF_INET) {
|
||||
fprintf(stderr, "ping: unknown address type; only AF_INET is currently supported.\n");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
pingaddr.sin_family = AF_INET; /* h->h_addrtype */
|
||||
memcpy(&pingaddr.sin_addr, h->h_addr, sizeof(pingaddr.sin_addr));
|
||||
strncpy(buf, h->h_name, sizeof(buf)-1);
|
||||
hostname = buf;
|
||||
}
|
||||
|
||||
/* enable broadcast pings */
|
||||
sockopt = 1;
|
||||
setsockopt(pingsock, SOL_SOCKET, SO_BROADCAST, (char *)&sockopt, sizeof(sockopt));
|
||||
|
||||
/* set recv buf for broadcast pings */
|
||||
sockopt = 48 * 1024;
|
||||
setsockopt(pingsock, SOL_SOCKET, SO_RCVBUF, (char *)&sockopt, sizeof(sockopt));
|
||||
|
||||
printf("PING %s (%s): %d data bytes\n",
|
||||
hostname, inet_ntoa(*(struct in_addr *)&pingaddr.sin_addr.s_addr),
|
||||
DEFDATALEN);
|
||||
|
||||
signal(SIGINT, pingstats);
|
||||
|
||||
/* start the ping's going ... */
|
||||
sendping(0);
|
||||
|
||||
/* listen for replies */
|
||||
while (1) {
|
||||
struct sockaddr_in from;
|
||||
size_t fromlen = sizeof(from);
|
||||
int c;
|
||||
|
||||
if ((c = recvfrom(pingsock, packet, sizeof(packet), 0,
|
||||
(struct sockaddr *)&from, &fromlen)) < 0) {
|
||||
if (errno == EINTR) continue;
|
||||
perror("ping");
|
||||
continue;
|
||||
}
|
||||
unpack(packet, c, &from);
|
||||
if (pingcount > 0 && nreceived >= pingcount) break;
|
||||
}
|
||||
pingstats(0);
|
||||
}
|
||||
|
||||
extern int ping_main(int argc, char **argv)
|
||||
{
|
||||
char *thisarg;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
options = 0;
|
||||
/* Parse any options */
|
||||
while (argc > 1) {
|
||||
if (**argv != '-') usage(ping_usage);
|
||||
thisarg = *argv; thisarg++;
|
||||
switch (*thisarg) {
|
||||
case 'q': options |= O_QUIET; break;
|
||||
case 'c':
|
||||
argc--; argv++;
|
||||
pingcount = atoi(*argv);
|
||||
break;
|
||||
default:
|
||||
usage(ping_usage);
|
||||
}
|
||||
argc--; argv++;
|
||||
}
|
||||
if (argc < 1) usage(ping_usage);
|
||||
|
||||
myid = getpid() & 0xFFFF;
|
||||
ping(*argv);
|
||||
exit(TRUE);
|
||||
}
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989 The Regents of the University of California.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Mike Muuss.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
+31
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Mini poweroff implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 1995, 1996 by Bruce Perens <bruce@pixar.com>.
|
||||
*
|
||||
* 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 "internal.h"
|
||||
#include <signal.h>
|
||||
|
||||
extern int
|
||||
poweroff_main(int argc, char ** argv)
|
||||
{
|
||||
/* don't assume init's pid == 1 */
|
||||
exit( kill(findInitPid(), SIGUSR2));
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Mini free implementation for busybox
|
||||
*
|
||||
* Copyright (C) 1999 by Lineo, inc.
|
||||
* Written by Erik Andersen <andersen@lineo.com>, <andersee@debian.org>
|
||||
*
|
||||
* 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 "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
|
||||
#if ! defined BB_FEATURE_USE_PROCFS
|
||||
#error Sorry, I depend on the /proc filesystem right now.
|
||||
#endif
|
||||
|
||||
extern int free_main(int argc, char **argv)
|
||||
{
|
||||
char* cmd[] = { "cat", "/proc/meminfo", "\0" };
|
||||
exit(cat_main( 3, cmd));
|
||||
}
|
||||
+84
-28
@@ -26,8 +26,14 @@
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include <ctype.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static const char* kill_usage = "kill [-signal] process-id [process-id ...]\n\n"
|
||||
"Send a signal (default is SIGTERM) to the specified process(es).\n\n"
|
||||
"Options:\n"
|
||||
"\t-l\tList all signal names and numbers.\n\n";
|
||||
|
||||
const char kill_usage[] = "kill [-signal] process-id [process-id ...]\n";
|
||||
|
||||
struct signal_name {
|
||||
const char *name;
|
||||
@@ -114,42 +120,92 @@ const struct signal_name signames[] = {
|
||||
extern int kill_main (int argc, char **argv)
|
||||
{
|
||||
int sig = SIGTERM;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
/* Parse any options */
|
||||
if (argc < 1)
|
||||
usage(kill_usage);
|
||||
|
||||
if ( argc < 2 )
|
||||
usage (kill_usage);
|
||||
while (argc > 0 && **argv == '-') {
|
||||
while (*++(*argv)) {
|
||||
switch (**argv) {
|
||||
case 'l':
|
||||
{
|
||||
int col=0;
|
||||
const struct signal_name *s = signames;
|
||||
|
||||
if ( **(argv+1) == '-' ) {
|
||||
if (isdigit( *(*(++argv)+1) )) {
|
||||
sig = atoi (*argv);
|
||||
if (sig < 0 || sig >= NSIG)
|
||||
goto end;
|
||||
}
|
||||
else {
|
||||
const struct signal_name *s = signames;
|
||||
while (s->name != 0) {
|
||||
if (strcasecmp (s->name, *argv+1) == 0) {
|
||||
sig = s->number;
|
||||
break;
|
||||
while (s->name != 0) {
|
||||
col+=fprintf(stderr, "%2d) %-8s", s->number, (s++)->name);
|
||||
if (col>60) {
|
||||
fprintf(stderr, "\n");
|
||||
col=0;
|
||||
}
|
||||
}
|
||||
fprintf(stderr, "\n\n");
|
||||
exit( TRUE);
|
||||
}
|
||||
break;
|
||||
case '-':
|
||||
usage(kill_usage);
|
||||
default:
|
||||
{
|
||||
if (isdigit( **argv)) {
|
||||
sig = atoi (*argv);
|
||||
if (sig < 0 || sig >= NSIG)
|
||||
goto end;
|
||||
else {
|
||||
argc--;
|
||||
argv++;
|
||||
goto do_it_now;
|
||||
}
|
||||
}
|
||||
else {
|
||||
const struct signal_name *s = signames;
|
||||
while (s->name != 0) {
|
||||
if (strcasecmp (s->name, *argv) == 0) {
|
||||
sig = s->number;
|
||||
argc--;
|
||||
argv++;
|
||||
goto do_it_now;
|
||||
}
|
||||
s++;
|
||||
}
|
||||
if (s->name == 0)
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
s++;
|
||||
}
|
||||
if (s->name == 0)
|
||||
goto end;
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
}
|
||||
|
||||
while (--argc > 1) {
|
||||
int pid;
|
||||
if (! isdigit( **(++argv))) {
|
||||
fprintf(stderr, "bad PID: %s\n", *argv);
|
||||
exit( FALSE);
|
||||
}
|
||||
pid = atoi (*argv);
|
||||
if (kill (pid, sig) != 0) {
|
||||
perror (*argv);
|
||||
exit ( FALSE);
|
||||
do_it_now:
|
||||
|
||||
while (argc >= 1) {
|
||||
int pid;
|
||||
struct stat statbuf;
|
||||
char pidpath[20]="/proc/";
|
||||
|
||||
if (! isdigit( **argv)) {
|
||||
fprintf(stderr, "bad PID: %s\n", *argv);
|
||||
exit( FALSE);
|
||||
}
|
||||
pid = atoi (*argv);
|
||||
snprintf(pidpath, 20, "/proc/%s/stat", *argv);
|
||||
if (stat( pidpath, &statbuf)!=0) {
|
||||
fprintf(stderr, "kill: (%d) - No such pid\n", pid);
|
||||
exit( FALSE);
|
||||
}
|
||||
if (kill (pid, sig) != 0) {
|
||||
perror (*argv);
|
||||
exit ( FALSE);
|
||||
}
|
||||
argv++;
|
||||
}
|
||||
exit ( TRUE);
|
||||
|
||||
|
||||
end:
|
||||
fprintf(stderr, "bad signal name: %s\n", *argv);
|
||||
|
||||
+5
-2
@@ -28,6 +28,9 @@
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#if ! defined BB_FEATURE_USE_PROCFS
|
||||
#error Sorry, I depend on the /proc filesystem right now.
|
||||
#endif
|
||||
|
||||
typedef struct proc_s {
|
||||
char
|
||||
@@ -74,7 +77,7 @@ static void parse_proc_status(char* S, proc_t* P)
|
||||
);
|
||||
else fprintf(stderr, "Internal error!\n");
|
||||
|
||||
/* For busybox, ignoring effecting, saved, etc */
|
||||
/* For busybox, ignoring effective, saved, etc */
|
||||
tmp = strstr (S,"Uid:");
|
||||
if(tmp) sscanf (tmp,
|
||||
"Uid:\t%d", &P->ruid);
|
||||
@@ -100,7 +103,7 @@ extern int ps_main(int argc, char **argv)
|
||||
int i, c;
|
||||
|
||||
if ( argc>1 && **(argv+1) == '-' ) {
|
||||
usage ("ps - report process status\nThis version of ps accepts no options.\n");
|
||||
usage ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n");
|
||||
}
|
||||
|
||||
dir = opendir("/proc");
|
||||
|
||||
@@ -28,6 +28,9 @@
|
||||
#include <fcntl.h>
|
||||
#include <ctype.h>
|
||||
|
||||
#if ! defined BB_FEATURE_USE_PROCFS
|
||||
#error Sorry, I depend on the /proc filesystem right now.
|
||||
#endif
|
||||
|
||||
typedef struct proc_s {
|
||||
char
|
||||
@@ -74,7 +77,7 @@ static void parse_proc_status(char* S, proc_t* P)
|
||||
);
|
||||
else fprintf(stderr, "Internal error!\n");
|
||||
|
||||
/* For busybox, ignoring effecting, saved, etc */
|
||||
/* For busybox, ignoring effective, saved, etc */
|
||||
tmp = strstr (S,"Uid:");
|
||||
if(tmp) sscanf (tmp,
|
||||
"Uid:\t%d", &P->ruid);
|
||||
@@ -100,7 +103,7 @@ extern int ps_main(int argc, char **argv)
|
||||
int i, c;
|
||||
|
||||
if ( argc>1 && **(argv+1) == '-' ) {
|
||||
usage ("ps - report process status\nThis version of ps accepts no options.\n");
|
||||
usage ("ps\n\nReport process status\n\nThis version of ps accepts no options.\n");
|
||||
}
|
||||
|
||||
dir = opendir("/proc");
|
||||
|
||||
@@ -26,5 +26,6 @@
|
||||
extern int
|
||||
reboot_main(int argc, char ** argv)
|
||||
{
|
||||
exit( kill(1, SIGUSR2));
|
||||
/* don't assume init's pid == 1 */
|
||||
exit( kill(findInitPid(), SIGINT));
|
||||
}
|
||||
@@ -7,7 +7,7 @@
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
#if ( defined BB_GREP || defined BB_FIND || defined BB_SED)
|
||||
#if ( defined BB_GREP || defined BB_SED)
|
||||
|
||||
/* This also tries to find a needle in a haystack, but uses
|
||||
* real regular expressions.... The fake regular expression
|
||||
@@ -50,7 +50,6 @@ extern int replace_match(char *haystack, char *needle, char *newNeedle, int igno
|
||||
} while (regexec(re, s, FALSE, ignoreCase) == TRUE);
|
||||
/* copy stuff from after the match */
|
||||
while ( (*d++ = *s++) ) {}
|
||||
d[-1] = '\n';
|
||||
d[0] = '\0';
|
||||
strcpy(haystack, buf);
|
||||
}
|
||||
@@ -99,7 +98,9 @@ extern int replace_match(char *haystack, char *needle, char *newNeedle, int igno
|
||||
|
||||
|
||||
static char *previous; /* the previous regexp, used when null regexp is given */
|
||||
#if defined BB_SED
|
||||
static char *previous1; /* a copy of the text from the previous substitution for regsub()*/
|
||||
#endif
|
||||
|
||||
|
||||
/* These are used to classify or recognize meta-characters */
|
||||
@@ -136,7 +137,7 @@ static char *retext; /* points to the text being compiled */
|
||||
|
||||
/* error-handling stuff */
|
||||
jmp_buf errorhandler;
|
||||
#define FAIL(why) fprintf(stderr, why); longjmp(errorhandler, 1)
|
||||
#define FAIL(why) do {fprintf(stderr, why); longjmp(errorhandler, 1);} while (0)
|
||||
|
||||
|
||||
|
||||
@@ -505,7 +506,7 @@ extern regexp *regcomp(char* text)
|
||||
int token;
|
||||
int peek;
|
||||
char *build;
|
||||
regexp *re;
|
||||
regexp *re; // Ignore compiler whining. If we longjmp, we don't use re anymore.
|
||||
|
||||
|
||||
/* prepare for error handling */
|
||||
|
||||
@@ -26,11 +26,13 @@
|
||||
#include <time.h>
|
||||
#include <utime.h>
|
||||
#include <dirent.h>
|
||||
#include <errno.h>
|
||||
|
||||
static const char* rm_usage = "rm [OPTION]... FILE...\n"
|
||||
static const char* rm_usage = "rm [OPTION]... FILE...\n\n"
|
||||
"Remove (unlink) the FILE(s).\n\n"
|
||||
"\t-f\tremove existing destinations, never prompt\n"
|
||||
"\t-r\tremove the contents of directories recursively\n";
|
||||
"Options:\n"
|
||||
"\t-f\t\tremove existing destinations, never prompt\n"
|
||||
"\t-r or -R\tremove the contents of directories recursively\n";
|
||||
|
||||
|
||||
static int recursiveFlag = FALSE;
|
||||
@@ -58,6 +60,7 @@ static int dirAction(const char *fileName, struct stat* statbuf)
|
||||
|
||||
extern int rm_main(int argc, char **argv)
|
||||
{
|
||||
struct stat statbuf;
|
||||
|
||||
if (argc < 2) {
|
||||
usage( rm_usage);
|
||||
@@ -69,6 +72,7 @@ extern int rm_main(int argc, char **argv)
|
||||
while (**argv == '-') {
|
||||
while (*++(*argv))
|
||||
switch (**argv) {
|
||||
case 'R':
|
||||
case 'r':
|
||||
recursiveFlag = TRUE;
|
||||
break;
|
||||
@@ -84,9 +88,14 @@ extern int rm_main(int argc, char **argv)
|
||||
|
||||
while (argc-- > 0) {
|
||||
srcName = *(argv++);
|
||||
if (recursiveAction( srcName, recursiveFlag, TRUE, TRUE,
|
||||
fileAction, dirAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
if (forceFlag == TRUE && lstat(srcName, &statbuf) != 0 && errno == ENOENT) {
|
||||
/* do not reports errors for non-existent files if -f, just skip them */
|
||||
}
|
||||
else {
|
||||
if (recursiveAction( srcName, recursiveFlag, FALSE,
|
||||
TRUE, fileAction, dirAction) == FALSE) {
|
||||
exit( FALSE);
|
||||
}
|
||||
}
|
||||
}
|
||||
exit( TRUE);
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
extern int rmdir_main(int argc, char **argv)
|
||||
{
|
||||
if ( argc==1 || **(argv+1) == '-' ) {
|
||||
usage( "rmdir [OPTION]... DIRECTORY...\nRemove the DIRECTORY(ies), if they are empty.");
|
||||
usage( "rmdir [OPTION]... DIRECTORY...\n\nRemove the DIRECTORY(ies), if they are empty.\n");
|
||||
}
|
||||
|
||||
while (--argc > 0) {
|
||||
|
||||
@@ -32,22 +32,36 @@
|
||||
#include <ctype.h>
|
||||
|
||||
static const char sed_usage[] =
|
||||
"sed [-n] [-e script] [file...]\n"
|
||||
"Allowed scripts come in the following form:\n\n"
|
||||
"'s/regexp/replacement/[gp]'\n"
|
||||
"\tattempt to match regexp against the pattern space\n"
|
||||
"\tand if successful replaces the matched portion with replacement.\n\n"
|
||||
"sed [-n] [-e script] [file...]\n\n"
|
||||
"Allowed sed scripts come in the following form:\n"
|
||||
"\t's/regexp/replacement/[gp]'\n"
|
||||
"which attempt to match regexp against the pattern space\n"
|
||||
"and if successful replaces the matched portion with replacement.\n\n"
|
||||
"Options:\n"
|
||||
"-e\tadd the script to the commands to be executed\n"
|
||||
"-n\tsuppress automatic printing of pattern space\n\n"
|
||||
#if defined BB_REGEXP
|
||||
"This version of sed matches full regexps.\n";
|
||||
"This version of sed matches full regular expresions.\n";
|
||||
#else
|
||||
"This version of sed matches strings (not full regexps).\n";
|
||||
"This version of sed matches strings (not full regular expresions).\n";
|
||||
#endif
|
||||
|
||||
|
||||
static void do_sed(FILE *fp, char *needle, char *newNeedle, int ignoreCase, int printFlag, int quietFlag)
|
||||
{
|
||||
int foundOne=FALSE;
|
||||
char haystack[1024];
|
||||
|
||||
|
||||
while (fgets (haystack, 1023, fp)) {
|
||||
foundOne = replace_match(haystack, needle, newNeedle, ignoreCase);
|
||||
if (foundOne==TRUE && printFlag==TRUE) {
|
||||
fprintf(stdout, haystack);
|
||||
}
|
||||
if (quietFlag==FALSE) {
|
||||
fprintf(stdout, haystack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern int sed_main (int argc, char **argv)
|
||||
{
|
||||
@@ -56,11 +70,9 @@ extern int sed_main (int argc, char **argv)
|
||||
char *name;
|
||||
char *cp;
|
||||
int ignoreCase=FALSE;
|
||||
int foundOne=FALSE;
|
||||
int printFlag=FALSE;
|
||||
int quietFlag=FALSE;
|
||||
int stopNow;
|
||||
char *haystack;
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
@@ -73,24 +85,23 @@ extern int sed_main (int argc, char **argv)
|
||||
cp = *argv++;
|
||||
stopNow=FALSE;
|
||||
|
||||
while (*++cp && stopNow==FALSE)
|
||||
while (*++cp && stopNow==FALSE) {
|
||||
switch (*cp) {
|
||||
case 'n':
|
||||
quietFlag = TRUE;
|
||||
break;
|
||||
case 'e':
|
||||
if (*(cp+1)==0 && --argc < 0) {
|
||||
fprintf(stderr, "A\n");
|
||||
usage( sed_usage);
|
||||
}
|
||||
cp = *argv++;
|
||||
if ( *++cp != 's')
|
||||
cp = *argv++;
|
||||
while( *cp ) {
|
||||
if (*cp == 's' && strlen(cp) > 3 && *(cp+1) == '/') {
|
||||
char* pos=needle=cp+2;
|
||||
for(;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos==NULL) {
|
||||
fprintf(stderr, "B\n");
|
||||
usage( sed_usage);
|
||||
}
|
||||
if (*(pos-1) == '\\') {
|
||||
@@ -104,7 +115,6 @@ extern int sed_main (int argc, char **argv)
|
||||
for(;;) {
|
||||
pos = strchr(pos, '/');
|
||||
if (pos==NULL) {
|
||||
fprintf(stderr, "C\n");
|
||||
usage( sed_usage);
|
||||
}
|
||||
if (*(pos-1) == '\\') {
|
||||
@@ -116,7 +126,6 @@ extern int sed_main (int argc, char **argv)
|
||||
*pos=0;
|
||||
if (pos+2 != 0) {
|
||||
while (*++pos) {
|
||||
fprintf(stderr, "pos='%s'\n", pos);
|
||||
switch (*pos) {
|
||||
case 'i':
|
||||
ignoreCase=TRUE;
|
||||
@@ -134,42 +143,35 @@ extern int sed_main (int argc, char **argv)
|
||||
}
|
||||
cp++;
|
||||
}
|
||||
fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle);
|
||||
//fprintf(stderr, "replace '%s' with '%s'\n", needle, newNeedle);
|
||||
stopNow=TRUE;
|
||||
break;
|
||||
|
||||
default:
|
||||
fprintf(stderr, "D\n");
|
||||
usage(sed_usage);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
if (argc==0) {
|
||||
do_sed( stdin, needle, newNeedle, ignoreCase, printFlag, quietFlag);
|
||||
} else {
|
||||
while (argc-- > 0) {
|
||||
name = *argv++;
|
||||
|
||||
fp = fopen (name, "r");
|
||||
if (fp == NULL) {
|
||||
perror (name);
|
||||
continue;
|
||||
fp = fopen (name, "r");
|
||||
if (fp == NULL) {
|
||||
perror (name);
|
||||
continue;
|
||||
}
|
||||
|
||||
do_sed( fp, needle, newNeedle, ignoreCase, printFlag, quietFlag);
|
||||
|
||||
if (ferror (fp))
|
||||
perror (name);
|
||||
|
||||
fclose (fp);
|
||||
}
|
||||
|
||||
haystack = (char*)malloc( 1024);
|
||||
while (fgets (haystack, 1023, fp)) {
|
||||
|
||||
foundOne = replace_match(haystack, needle, newNeedle, ignoreCase);
|
||||
if (foundOne==TRUE && printFlag==TRUE)
|
||||
fputs (haystack, stdout);
|
||||
if (quietFlag==FALSE)
|
||||
fputs (haystack, stdout);
|
||||
/* Avoid any mem leaks */
|
||||
free(haystack);
|
||||
haystack = (char*)malloc( BUF_SIZE);
|
||||
}
|
||||
|
||||
if (ferror (fp))
|
||||
perror (name);
|
||||
|
||||
fclose (fp);
|
||||
}
|
||||
exit( TRUE);
|
||||
}
|
||||
|
||||
@@ -23,8 +23,8 @@
|
||||
#include "internal.h"
|
||||
#include <stdio.h>
|
||||
|
||||
const char sleep_usage[] = " NUMBER\n"
|
||||
"Pause for NUMBER seconds.\n";
|
||||
const char sleep_usage[] = "sleep N\n\n"
|
||||
"Pause for N seconds.\n";
|
||||
|
||||
extern int
|
||||
sleep_main(int argc, char * * argv)
|
||||
|
||||
@@ -27,7 +27,7 @@ extern int
|
||||
sync_main(int argc, char * * argv)
|
||||
{
|
||||
if ( argc>1 && **(argv+1) == '-' ) {
|
||||
usage( "sync\nWrite all buffered filesystem blocks to disk.\n");
|
||||
usage( "sync\n\nWrite all buffered filesystem blocks to disk.\n");
|
||||
}
|
||||
exit( sync());
|
||||
}
|
||||
|
||||
Loaded 100 of 118 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user