Compare commits
No files matched your search
@@ -258,6 +258,7 @@ LIBBUSYBOX_SONAME:=$(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL
|
||||
DO_INSTALL_LIBS:=$(LD_LIBBUSYBOX) \
|
||||
$(LD_LIBBUSYBOX).$(MAJOR_VERSION) \
|
||||
$(LD_LIBBUSYBOX).$(MAJOR_VERSION).$(MINOR_VERSION)
|
||||
endif # CONFIG_BUILD_LIBBUSYBOX
|
||||
|
||||
ifeq ($(strip $(CONFIG_BUILD_AT_ONCE)),y)
|
||||
ifneq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
|
||||
@@ -269,7 +270,6 @@ $(LIBBUSYBOX_SONAME): $(LIBRARY_SRC)
|
||||
else # CONFIG_BUILD_AT_ONCE
|
||||
$(LIBBUSYBOX_SONAME): $(libbusybox-obj)
|
||||
endif # CONFIG_BUILD_AT_ONCE
|
||||
endif # CONFIG_BUILD_LIBBUSYBOX
|
||||
|
||||
ifeq ($(strip $(CONFIG_FEATURE_SHARED_BUSYBOX)),y)
|
||||
LDBUSYBOX:=-L$(top_builddir) -lbusybox
|
||||
|
||||
@@ -14,7 +14,7 @@ endif
|
||||
PROG := busybox
|
||||
MAJOR_VERSION :=1
|
||||
MINOR_VERSION :=1
|
||||
SUBLEVEL_VERSION:=1
|
||||
SUBLEVEL_VERSION:=3
|
||||
EXTRAVERSION :=
|
||||
VERSION :=$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL_VERSION)$(EXTRAVERSION)
|
||||
BUILDTIME := $(shell TZ=UTC date -u "+%Y.%m.%d-%H:%M%z")
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/applets
|
||||
APPLETS_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
ARCHIVAL_DIR:=./
|
||||
srcdir=$(top_srcdir)/archival
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
@@ -25,7 +25,7 @@ top_builddir=../..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/archival/libunarchive
|
||||
LIBUNARCHIVE_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/console/tools
|
||||
CONSOLETOOLS_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/coreutils
|
||||
SHELLUTILS_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
+4
-18
@@ -4,21 +4,7 @@
|
||||
*
|
||||
* Copyright (C) 2005 by Robert Sullivan <cogito.ergo.cogito@gmail.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
|
||||
*
|
||||
* Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
@@ -75,16 +61,16 @@ static void cmp_files(char **infiles)
|
||||
fgets(thisline[i], LINE_LEN, streams[i]);
|
||||
}
|
||||
|
||||
while (thisline[0] || thisline[1]) {
|
||||
while (*thisline[0] || *thisline[1]) {
|
||||
int order = 0;
|
||||
|
||||
i = 0;
|
||||
if (feof(streams[0])) i |= BB_EOF_0;
|
||||
if (feof(streams[1])) i |= BB_EOF_1;
|
||||
|
||||
if (!thisline[0])
|
||||
if (!*thisline[0])
|
||||
order = 1;
|
||||
else if (!thisline[1])
|
||||
else if (!*thisline[1])
|
||||
order = -1;
|
||||
else {
|
||||
int tl0_len, tl1_len;
|
||||
|
||||
@@ -25,7 +25,7 @@ top_builddir=../..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/coreutils/libcoreutils
|
||||
LIBCOREUTILS_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
|
||||
|
||||
+11
-7
@@ -350,20 +350,18 @@ static struct dnode **dnalloc(int num)
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FEATURE_LS_RECURSIVE
|
||||
static void dfree(struct dnode **dnp)
|
||||
static void dfree(struct dnode **dnp, int nfiles)
|
||||
{
|
||||
struct dnode *cur, *next;
|
||||
int i;
|
||||
|
||||
if (dnp == NULL)
|
||||
return;
|
||||
|
||||
cur = dnp[0];
|
||||
while (cur != NULL) {
|
||||
for (i = 0; i < nfiles; i++) {
|
||||
struct dnode *cur = dnp[i];
|
||||
if(cur->allocated)
|
||||
free(cur->fullname); /* free the filename */
|
||||
next = cur->next;
|
||||
free(cur); /* free the dnode */
|
||||
cur = next;
|
||||
}
|
||||
free(dnp); /* free the array holding the dnode pointers */
|
||||
}
|
||||
@@ -573,7 +571,7 @@ static void showdirs(struct dnode **dn, int ndirs, int first)
|
||||
free(dnd); /* free the array of dnode pointers to the dirs */
|
||||
}
|
||||
}
|
||||
dfree(subdnp); /* free the dnodes and the fullname mem */
|
||||
dfree(subdnp, nfiles); /* free the dnodes and the fullname mem */
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1164,13 +1162,19 @@ int ls_main(int argc, char **argv)
|
||||
shellsort(dnf, dnfiles);
|
||||
#endif
|
||||
showfiles(dnf, dnfiles);
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(dnf);
|
||||
}
|
||||
if (dndirs > 0) {
|
||||
#ifdef CONFIG_FEATURE_LS_SORTFILES
|
||||
shellsort(dnd, dndirs);
|
||||
#endif
|
||||
showdirs(dnd, dndirs, dnfiles == 0);
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
free(dnd);
|
||||
}
|
||||
}
|
||||
if (ENABLE_FEATURE_CLEAN_UP)
|
||||
dfree(dnp, nfiles);
|
||||
return (status);
|
||||
}
|
||||
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/debianutils
|
||||
DEBIANUTILS_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
@@ -25,7 +25,7 @@ int readlink_main(int argc, char **argv)
|
||||
bb_show_usage();
|
||||
|
||||
if (opt & READLINK_FLAG_f)
|
||||
buf = realpath(argv[optind], NULL);
|
||||
buf = realpath(argv[optind], bb_common_bufsiz1);
|
||||
else
|
||||
buf = xreadlink(argv[ENABLE_FEATURE_READLINK_FOLLOW ? optind : 1]);
|
||||
|
||||
@@ -33,7 +33,8 @@ int readlink_main(int argc, char **argv)
|
||||
return EXIT_FAILURE;
|
||||
puts(buf);
|
||||
|
||||
if (ENABLE_FEATURE_CLEAN_UP) free(buf);
|
||||
if (ENABLE_FEATURE_CLEAN_UP && buf != bb_common_bufsiz1)
|
||||
free(buf);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -13,7 +13,7 @@ font-family: monospace; font-size: smaller;" width="100">
|
||||
|
||||
|
||||
$ ./busybox
|
||||
BusyBox v1.01 (2005.08.16-22:44+0000) multi-call binary
|
||||
BusyBox v1.1.2 (2006.04.11-08:27+0000) multi-call binary
|
||||
|
||||
Usage: busybox [function] [arguments]...
|
||||
or: [function] [arguments]...
|
||||
@@ -24,29 +24,35 @@ Usage: busybox [function] [arguments]...
|
||||
will act like whatever it was invoked as!
|
||||
|
||||
Currently defined functions:
|
||||
[, addgroup, adduser, adjtimex, ar, arping, ash, awk, basename,
|
||||
bunzip2, busybox, bzcat, cal, cat, chgrp, chmod, chown, chroot,
|
||||
chvt, clear, cmp, cp, cpio, crond, crontab, cut, date, dc, dd,
|
||||
deallocvt, delgroup, deluser, devfsd, df, dirname, dmesg, dos2unix,
|
||||
dpkg, dpkg-deb, du, dumpkmap, dumpleases, echo, egrep, env, expr,
|
||||
false, fbset, fdflush, fdformat, fdisk, fgrep, find, fold, free,
|
||||
freeramdisk, fsck.minix, ftpget, ftpput, getopt, getty, grep,
|
||||
gunzip, gzip, halt, hdparm, head, hexdump, hostid, hostname, httpd,
|
||||
hush, hwclock, id, ifconfig, ifdown, ifup, inetd, init, insmod,
|
||||
install, ip, ipaddr, ipcalc, iplink, iproute, iptunnel, kill,
|
||||
killall, klogd, lash, last, length, linuxrc, ln, loadfont, loadkmap,
|
||||
logger, login, logname, logread, losetup, ls, lsmod, makedevs,
|
||||
md5sum, mesg, mkdir, mkfifo, mkfs.minix, mknod, mkswap, mktemp,
|
||||
modprobe, more, mount, msh, mt, mv, nameif, nc, netstat, nslookup,
|
||||
od, openvt, passwd, patch, pidof, ping, ping6, pipe_progress,
|
||||
pivot_root, poweroff, printf, ps, pwd, rdate, readlink, realpath,
|
||||
reboot, renice, reset, rm, rmdir, rmmod, route, rpm, rpm2cpio,
|
||||
run-parts, rx, sed, seq, setkeycodes, sha1sum, sleep, sort, start-stop-daemon,
|
||||
strings, stty, su, sulogin, swapoff, swapon, sync, sysctl, syslogd,
|
||||
tail, tar, tee, telnet, telnetd, test, tftp, time, top, touch,
|
||||
traceroute, true, tty, udhcpc, udhcpd, umount, uname, uncompress,
|
||||
uniq, unix2dos, unzip, uptime, usleep, uudecode, uuencode, vconfig,
|
||||
vi, vlock, watch, wc, wget, which, who, whoami, xargs, yes, zcat
|
||||
[, [[, addgroup, adduser, adjtimex, ar, arping, ash, awk, basename,
|
||||
bbconfig, bunzip2, busybox, bzcat, cal, cat, chattr, chgrp, chmod,
|
||||
chown, chroot, chvt, clear, cmp, comm, cp, cpio, crond, crontab,
|
||||
cut, date, dc, dd, deallocvt, delgroup, deluser, devfsd, df, dirname,
|
||||
dmesg, dnsd, dos2unix, dpkg, dpkg-deb, du, dumpkmap, dumpleases,
|
||||
e2fsck, e2label, echo, egrep, eject, env, ether-wake, expr, fakeidentd,
|
||||
false, fbset, fdflush, fdformat, fdisk, fgrep, find, findfs, fold,
|
||||
free, freeramdisk, fsck, fsck.ext2, fsck.ext3, fsck.minix, ftpget,
|
||||
ftpput, fuser, getopt, getty, grep, gunzip, gzip, halt, hdparm,
|
||||
head, hexdump, hostid, hostname, httpd, hush, hwclock, id, ifconfig,
|
||||
ifdown, ifup, inetd, init, insmod, install, ip, ipaddr, ipcalc,
|
||||
ipcrm, ipcs, iplink, iproute, iptunnel, kill, killall, klogd,
|
||||
lash, last, length, less, linux32, linux64, linuxrc, ln, loadfont,
|
||||
loadkmap, logger, login, logname, logread, losetup, ls, lsattr,
|
||||
lsmod, lzmacat, makedevs, md5sum, mdev, mesg, mkdir, mke2fs, mkfifo,
|
||||
mkfs.ext2, mkfs.ext3, mkfs.minix, mknod, mkswap, mktemp, modprobe,
|
||||
more, mount, mountpoint, msh, mt, mv, nameif, nc, netstat, nice,
|
||||
nohup, nslookup, od, openvt, passwd, patch, pidof, ping, ping6,
|
||||
pipe_progress, pivot_root, poweroff, printenv, printf, ps, pwd,
|
||||
rdate, readlink, readprofile, realpath, reboot, renice, reset,
|
||||
rm, rmdir, rmmod, route, rpm, rpm2cpio, run-parts, runlevel, rx,
|
||||
sed, seq, setarch, setconsole, setkeycodes, setsid, sha1sum, sleep,
|
||||
sort, start-stop-daemon, stat, strings, stty, su, sulogin, sum,
|
||||
swapoff, swapon, switch_root, sync, sysctl, syslogd, tail, tar,
|
||||
tee, telnet, telnetd, test, tftp, time, top, touch, tr, traceroute,
|
||||
true, tty, tune2fs, udhcpc, udhcpd, umount, uname, uncompress,
|
||||
uniq, unix2dos, unlzma, unzip, uptime, usleep, uudecode, uuencode,
|
||||
vconfig, vi, vlock, watch, watchdog, wc, wget, which, who, whoami,
|
||||
xargs, yes, zcat, zcip
|
||||
|
||||
$ <span style="text-decoration:blink;">_</span>
|
||||
|
||||
|
||||
+1
-1
@@ -13,7 +13,7 @@ endif
|
||||
srcdir=$(top_srcdir)/e2fsprogs
|
||||
E2FSPROGS_DIR:=./
|
||||
include $(top_builddir)/.config
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include Makefile.in
|
||||
all: $(libraries-y)
|
||||
-include $(top_builddir)/.depend
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/editors
|
||||
EDITOR_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
+6
-16
@@ -54,29 +54,19 @@ static unsigned int copy_lines(FILE *src_stream, FILE *dest_stream, const unsign
|
||||
|
||||
static char *extract_filename(char *line, int patch_level)
|
||||
{
|
||||
char *filename_start_ptr = line + 4;
|
||||
char *temp, *filename_start_ptr = line + 4;
|
||||
int i;
|
||||
|
||||
/* Terminate string at end of source filename */
|
||||
{
|
||||
char *line_ptr;
|
||||
line_ptr = strchr(filename_start_ptr, '\t');
|
||||
if (!line_ptr) {
|
||||
bb_perror_msg("Malformed line %s", line);
|
||||
return(NULL);
|
||||
}
|
||||
*line_ptr = '\0';
|
||||
}
|
||||
temp = strchr(filename_start_ptr, '\t');
|
||||
if (temp)
|
||||
*temp = 0;
|
||||
|
||||
/* Skip over (patch_level) number of leading directories */
|
||||
for (i = 0; i < patch_level; i++) {
|
||||
char *dirname_ptr;
|
||||
|
||||
dirname_ptr = strchr(filename_start_ptr, '/');
|
||||
if (!dirname_ptr) {
|
||||
if (!(temp = strchr(filename_start_ptr, '/')))
|
||||
break;
|
||||
}
|
||||
filename_start_ptr = dirname_ptr + 1;
|
||||
filename_start_ptr = temp + 1;
|
||||
}
|
||||
|
||||
return(bb_xstrdup(filename_start_ptr));
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/findutils
|
||||
FINDUTILS_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
@@ -387,12 +387,6 @@ int is_in_ino_dev_hashtable(const struct stat *statbuf, char **name);
|
||||
void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
|
||||
void reset_ino_dev_hashtable(void);
|
||||
|
||||
/* Stupid gcc always includes its own builtin strlen()... */
|
||||
extern size_t bb_strlen(const char *string);
|
||||
#ifndef BB_STRLEN_IMPLEMENTATION
|
||||
#define strlen(x) bb_strlen(x)
|
||||
#endif
|
||||
|
||||
char *bb_xasprintf(const char *format, ...) __attribute__ ((format (printf, 1, 2)));
|
||||
|
||||
#define FAIL_DELAY 3
|
||||
|
||||
+12
-21
@@ -32,40 +32,29 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
/* Attribute __malloc__ on functions was valid as of gcc 2.96. */
|
||||
#ifndef ATTRIBUTE_MALLOC
|
||||
# if __GNUC_PREREQ (2,96)
|
||||
# define ATTRIBUTE_MALLOC __attribute__ ((__malloc__))
|
||||
# else
|
||||
# define ATTRIBUTE_MALLOC
|
||||
# endif /* GNUC >= 2.96 */
|
||||
#endif /* ATTRIBUTE_MALLOC */
|
||||
#endif
|
||||
|
||||
#ifndef ATTRIBUTE_UNUSED
|
||||
# define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
|
||||
#define ATTRIBUTE_UNUSED __attribute__ ((__unused__))
|
||||
#endif /* ATTRIBUTE_UNUSED */
|
||||
|
||||
#ifndef ATTRIBUTE_NORETURN
|
||||
# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
|
||||
#define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
|
||||
#endif /* ATTRIBUTE_NORETURN */
|
||||
|
||||
#ifndef ATTRIBUTE_PACKED
|
||||
# define ATTRIBUTE_PACKED __attribute__ ((__packed__))
|
||||
#endif /* ATTRIBUTE_PACKED */
|
||||
#define ATTRIBUTE_PACKED __attribute__ ((__packed__))
|
||||
#endif /* ATTRIBUTE_NORETURN */
|
||||
|
||||
#ifndef ATTRIBUTE_ALIGNED
|
||||
# define ATTRIBUTE_ALIGNED(m) __attribute__ ((__aligned__(m)))
|
||||
#define ATTRIBUTE_ALIGNED(m) __attribute__ ((__aligned__(m)))
|
||||
#endif /* ATTRIBUTE_ALIGNED */
|
||||
|
||||
/* -fwhole-program makes all symbols local. The attribute externally_visible
|
||||
forces a symbol global. */
|
||||
#ifndef ATTRIBUTE_EXTERNALLY_VISIBLE
|
||||
# if __GNUC_PREREQ (4,1)
|
||||
# define ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((__externally_visible__))
|
||||
# define ATTRIBUTE_EXTERNALLY_VISIBLE __attribute__ ((__externally_visible__))
|
||||
# else
|
||||
# define ATTRIBUTE_EXTERNALLY_VISIBLE
|
||||
# define ATTRIBUTE_EXTERNALLY_VISIBLE
|
||||
# endif /* GNUC >= 4.1 */
|
||||
#endif /* ATTRIBUTE_EXTERNALLY_VISIBLE */
|
||||
|
||||
@@ -78,6 +67,11 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define strlen(x) bb_strlen(x)
|
||||
extern size_t bb_strlen(const char *string);
|
||||
#endif
|
||||
|
||||
/* ---- Endian Detection ------------------------------------ */
|
||||
#ifndef __APPLE__
|
||||
# include <byteswap.h>
|
||||
@@ -86,13 +80,10 @@
|
||||
|
||||
#ifdef __BIG_ENDIAN__
|
||||
# define BB_BIG_ENDIAN 1
|
||||
# define BB_LITTLE_ENDIAN 0
|
||||
#elif __BYTE_ORDER == __BIG_ENDIAN
|
||||
# define BB_BIG_ENDIAN 1
|
||||
# define BB_LITTLE_ENDIAN 0
|
||||
#else
|
||||
# define BB_BIG_ENDIAN 0
|
||||
# define BB_LITTLE_ENDIAN 1
|
||||
#endif
|
||||
|
||||
/* ---- Networking ------------------------------------------ */
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/init
|
||||
INIT_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include $(srcdir)/Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/libbb
|
||||
LIBBB_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
+4
-9
@@ -14,16 +14,8 @@
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
/* Since gcc always inlines strlen(), this saves a byte or two, but we need
|
||||
* the #undef here to avoid endless loop from #define strlen bb_strlen */
|
||||
#ifdef L_strlen
|
||||
#define BB_STRLEN_IMPLEMENTATION
|
||||
#endif
|
||||
|
||||
#include "libbb.h"
|
||||
|
||||
|
||||
#ifndef DMALLOC
|
||||
#ifdef L_xmalloc
|
||||
void *xmalloc(size_t size)
|
||||
@@ -175,10 +167,13 @@ void bb_xfflush_stdout(void)
|
||||
}
|
||||
#endif
|
||||
|
||||
/* GCC forces inlining of strlen everywhere, which is generally a byte
|
||||
larger than calling a function, and it's called a lot so it adds up.
|
||||
*/
|
||||
#ifdef L_strlen
|
||||
size_t bb_strlen(const char *string)
|
||||
{
|
||||
return(strlen(string));
|
||||
return(__builtin_strlen(string));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/libpwgrp
|
||||
LIBPWDGRP_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/loginutils
|
||||
LOGINUTILS_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
+11
-3
@@ -322,6 +322,7 @@ static int new_password(const struct passwd *pw, int amroot, int algo)
|
||||
char *clear;
|
||||
char *cipher;
|
||||
char *cp;
|
||||
char salt[12]; /* "$N$XXXXXXXX" or "XX" */
|
||||
char orig[200];
|
||||
char pass[200];
|
||||
|
||||
@@ -376,11 +377,18 @@ static int new_password(const struct passwd *pw, int amroot, int algo)
|
||||
}
|
||||
memset(cp, 0, strlen(cp));
|
||||
memset(orig, 0, sizeof(orig));
|
||||
memset(salt, 0, sizeof(salt));
|
||||
|
||||
if (algo == 1) {
|
||||
cp = pw_encrypt(pass, "$1$");
|
||||
} else
|
||||
cp = pw_encrypt(pass, crypt_make_salt());
|
||||
strcpy(salt, "$1$");
|
||||
strcat(salt, crypt_make_salt());
|
||||
strcat(salt, crypt_make_salt());
|
||||
strcat(salt, crypt_make_salt());
|
||||
}
|
||||
|
||||
strcat(salt, crypt_make_salt());
|
||||
cp = pw_encrypt(pass, salt);
|
||||
|
||||
memset(pass, 0, sizeof pass);
|
||||
safe_strncpy(crypt_passwd, cp, sizeof(crypt_passwd));
|
||||
return 0;
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/miscutils
|
||||
MISCUTILS_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
+182
-204
@@ -2,24 +2,12 @@
|
||||
/*
|
||||
* Mini less implementation for busybox
|
||||
*
|
||||
*
|
||||
* Copyright (C) 2005 by Rob Sullivan <cogito.ergo.cogito@gmail.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
|
||||
*
|
||||
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
||||
*/
|
||||
|
||||
/*
|
||||
* This program needs a lot of development, so consider it in a beta stage
|
||||
* at best.
|
||||
*
|
||||
@@ -116,11 +104,11 @@ static int num_marks;
|
||||
|
||||
#ifdef CONFIG_FEATURE_LESS_REGEXP
|
||||
static int match_found;
|
||||
static int match_lines[100];
|
||||
static int *match_lines;
|
||||
static int match_pos;
|
||||
static int num_matches;
|
||||
static int match_backwards;
|
||||
static int num_back_match = 1;
|
||||
static regex_t old_pattern;
|
||||
#endif
|
||||
|
||||
/* Needed termios structures */
|
||||
@@ -130,19 +118,21 @@ static struct termios term_orig, term_vi;
|
||||
static FILE *inp;
|
||||
|
||||
/* Reset terminal input to normal */
|
||||
static void set_tty_cooked(void) {
|
||||
static void set_tty_cooked(void)
|
||||
{
|
||||
fflush(stdout);
|
||||
tcsetattr(fileno(inp), TCSANOW, &term_orig);
|
||||
}
|
||||
|
||||
/* Set terminal input to raw mode (taken from vi.c) */
|
||||
static void set_tty_raw(void) {
|
||||
static void set_tty_raw(void)
|
||||
{
|
||||
tcsetattr(fileno(inp), TCSANOW, &term_vi);
|
||||
}
|
||||
|
||||
/* Exit the program gracefully */
|
||||
static void tless_exit(int code) {
|
||||
|
||||
static void tless_exit(int code)
|
||||
{
|
||||
/* TODO: We really should save the terminal state when we start,
|
||||
and restore it when we exit. Less does this with the
|
||||
"ti" and "te" termcap commands; can this be done with
|
||||
@@ -155,8 +145,8 @@ static void tless_exit(int code) {
|
||||
/* Grab a character from input without requiring the return key. If the
|
||||
character is ASCII \033, get more characters and assign certain sequences
|
||||
special return codes. Note that this function works best with raw input. */
|
||||
static int tless_getch(void) {
|
||||
|
||||
static int tless_getch(void)
|
||||
{
|
||||
int input;
|
||||
|
||||
set_tty_raw();
|
||||
@@ -191,18 +181,20 @@ static int tless_getch(void) {
|
||||
|
||||
/* Move the cursor to a position (x,y), where (0,0) is the
|
||||
top-left corner of the console */
|
||||
static void move_cursor(int x, int y) {
|
||||
static void move_cursor(int x, int y)
|
||||
{
|
||||
printf("\033[%i;%iH", x, y);
|
||||
}
|
||||
|
||||
static void clear_line(void) {
|
||||
static void clear_line(void)
|
||||
{
|
||||
move_cursor(height, 0);
|
||||
printf("\033[K");
|
||||
}
|
||||
|
||||
/* This adds line numbers to every line, as the -N flag necessitates */
|
||||
static void add_linenumbers(void) {
|
||||
|
||||
static void add_linenumbers(void)
|
||||
{
|
||||
char current_line[256];
|
||||
int i;
|
||||
|
||||
@@ -212,8 +204,8 @@ static void add_linenumbers(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void data_readlines(void) {
|
||||
|
||||
static void data_readlines(void)
|
||||
{
|
||||
int i;
|
||||
char current_line[256];
|
||||
FILE *fp;
|
||||
@@ -223,7 +215,7 @@ static void data_readlines(void) {
|
||||
for (i = 0; (feof(fp)==0) && (i <= MAXLINES); i++) {
|
||||
strcpy(current_line, "");
|
||||
fgets(current_line, 256, fp);
|
||||
if(fp != stdin)
|
||||
if (fp != stdin)
|
||||
bb_xferror(fp, filename);
|
||||
flines = xrealloc(flines, (i+1) * sizeof(char *));
|
||||
flines[i] = bb_xstrdup(current_line);
|
||||
@@ -237,31 +229,25 @@ static void data_readlines(void) {
|
||||
|
||||
fclose(fp);
|
||||
|
||||
if(inp == NULL)
|
||||
if (inp == NULL)
|
||||
inp = (inp_stdin) ? bb_xfopen(CURRENT_TTY, "r") : stdin;
|
||||
|
||||
if (flags & FLAG_N)
|
||||
add_linenumbers();
|
||||
}
|
||||
|
||||
/* Turn a percentage into a line number */
|
||||
static int reverse_percent(int percentage) {
|
||||
double linenum = percentage;
|
||||
linenum = ((linenum / 100) * num_flines) - 1;
|
||||
return(linenum);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FEATURE_LESS_FLAGS
|
||||
|
||||
/* Interestingly, writing calc_percent as a function and not a prototype saves around 32 bytes
|
||||
* on my build. */
|
||||
static int calc_percent(void) {
|
||||
static int calc_percent(void)
|
||||
{
|
||||
return ((100 * (line_pos + height - 2) / num_flines) + 1);
|
||||
}
|
||||
|
||||
/* Print a status line if -M was specified */
|
||||
static void m_status_print(void) {
|
||||
|
||||
static void m_status_print(void)
|
||||
{
|
||||
int percentage;
|
||||
|
||||
if (!past_eof) {
|
||||
@@ -295,8 +281,8 @@ static void m_status_print(void) {
|
||||
}
|
||||
|
||||
/* Print a status line if -m was specified */
|
||||
static void medium_status_print(void) {
|
||||
|
||||
static void medium_status_print(void)
|
||||
{
|
||||
int percentage;
|
||||
percentage = calc_percent();
|
||||
|
||||
@@ -310,8 +296,8 @@ static void medium_status_print(void) {
|
||||
#endif
|
||||
|
||||
/* Print the status line */
|
||||
static void status_print(void) {
|
||||
|
||||
static void status_print(void)
|
||||
{
|
||||
/* Change the status if flags have been set */
|
||||
#ifdef CONFIG_FEATURE_LESS_FLAGS
|
||||
if (flags & FLAG_M)
|
||||
@@ -340,8 +326,8 @@ static void status_print(void) {
|
||||
}
|
||||
|
||||
/* Print the buffer */
|
||||
static void buffer_print(void) {
|
||||
|
||||
static void buffer_print(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
printf("%s", CLEAR);
|
||||
@@ -360,11 +346,11 @@ static void buffer_print(void) {
|
||||
}
|
||||
|
||||
/* Initialise the buffer */
|
||||
static void buffer_init(void) {
|
||||
|
||||
static void buffer_init(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
if(buffer == NULL) {
|
||||
if (buffer == NULL) {
|
||||
/* malloc the number of lines needed for the buffer */
|
||||
buffer = xrealloc(buffer, height * sizeof(char *));
|
||||
} else {
|
||||
@@ -385,8 +371,8 @@ static void buffer_init(void) {
|
||||
}
|
||||
|
||||
/* Move the buffer up and down in the file in order to scroll */
|
||||
static void buffer_down(int nlines) {
|
||||
|
||||
static void buffer_down(int nlines)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (!past_eof) {
|
||||
@@ -415,8 +401,8 @@ static void buffer_down(int nlines) {
|
||||
}
|
||||
}
|
||||
|
||||
static void buffer_up(int nlines) {
|
||||
|
||||
static void buffer_up(int nlines)
|
||||
{
|
||||
int i;
|
||||
int tilde_line;
|
||||
|
||||
@@ -467,15 +453,14 @@ static void buffer_up(int nlines) {
|
||||
}
|
||||
}
|
||||
|
||||
static void buffer_line(int linenum) {
|
||||
|
||||
static void buffer_line(int linenum)
|
||||
{
|
||||
int i;
|
||||
|
||||
past_eof = 0;
|
||||
|
||||
if (linenum < 1 || linenum > num_flines) {
|
||||
if (linenum < 0 || linenum > num_flines) {
|
||||
clear_line();
|
||||
printf("%s%s%i%s", HIGHLIGHT, "Cannot seek to line number ", linenum, NORMAL);
|
||||
printf("%s%s%i%s", HIGHLIGHT, "Cannot seek to line number ", linenum + 1, NORMAL);
|
||||
}
|
||||
else if (linenum < (num_flines - height - 2)) {
|
||||
for (i = 0; i < (height - 1); i++) {
|
||||
@@ -483,6 +468,7 @@ static void buffer_line(int linenum) {
|
||||
buffer[i] = bb_xstrdup(flines[linenum + i]);
|
||||
}
|
||||
line_pos = linenum;
|
||||
buffer_print();
|
||||
}
|
||||
else {
|
||||
for (i = 0; i < (height - 1); i++) {
|
||||
@@ -495,12 +481,13 @@ static void buffer_line(int linenum) {
|
||||
line_pos = linenum;
|
||||
/* Set past_eof so buffer_down and buffer_up act differently */
|
||||
past_eof = 1;
|
||||
buffer_print();
|
||||
}
|
||||
}
|
||||
|
||||
/* Reinitialise everything for a new file - free the memory and start over */
|
||||
static void reinitialise(void) {
|
||||
|
||||
static void reinitialise(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i <= num_flines; i++)
|
||||
@@ -512,8 +499,8 @@ static void reinitialise(void) {
|
||||
buffer_print();
|
||||
}
|
||||
|
||||
static void examine_file(void) {
|
||||
|
||||
static void examine_file(void)
|
||||
{
|
||||
int newline_offset;
|
||||
|
||||
clear_line();
|
||||
@@ -538,7 +525,8 @@ static void examine_file(void) {
|
||||
* 0: go to the first file
|
||||
* 1: go forward one file
|
||||
*/
|
||||
static void change_file (int direction) {
|
||||
static void change_file(int direction)
|
||||
{
|
||||
if (current_file != ((direction > 0) ? num_files : 1)) {
|
||||
current_file = direction ? current_file + direction : 1;
|
||||
strcpy(filename, files[current_file - 1]);
|
||||
@@ -550,8 +538,8 @@ static void change_file (int direction) {
|
||||
}
|
||||
}
|
||||
|
||||
static void remove_current_file(void) {
|
||||
|
||||
static void remove_current_file(void)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (current_file != 1) {
|
||||
@@ -571,8 +559,8 @@ static void remove_current_file(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void colon_process(void) {
|
||||
|
||||
static void colon_process(void)
|
||||
{
|
||||
int keypress;
|
||||
|
||||
/* Clear the current line and print a prompt */
|
||||
@@ -616,100 +604,48 @@ static void colon_process(void) {
|
||||
/* Get a regular expression from the user, and then go through the current
|
||||
file line by line, running a processing regex function on each one. */
|
||||
|
||||
static char *insert_highlights (char *line, int start, int end) {
|
||||
|
||||
return bb_xasprintf("%.*s%s%.*s%s%s", start, line, HIGHLIGHT,
|
||||
end - start, line + start, NORMAL, line + end);
|
||||
}
|
||||
|
||||
static char *process_regex_on_line(char *line, regex_t *pattern) {
|
||||
static char *process_regex_on_line(char *line, regex_t *pattern, int action)
|
||||
{
|
||||
/* This function takes the regex and applies it to the line.
|
||||
Each part of the line that matches has the HIGHLIGHT
|
||||
and NORMAL escape sequences placed around it by
|
||||
insert_highlights, and then the line is returned. */
|
||||
|
||||
insert_highlights if action = 1, or has the escape sequences
|
||||
removed if action = 0, and then the line is returned. */
|
||||
int match_status;
|
||||
char *line2 = (char *) malloc((sizeof(char) * (strlen(line) + 1)) + 64);
|
||||
char sub_line[256];
|
||||
int prev_eo = 0;
|
||||
char *line2 = (char *) xmalloc((sizeof(char) * (strlen(line) + 1)) + 64);
|
||||
char *growline = "";
|
||||
regmatch_t match_structs;
|
||||
|
||||
memset(sub_line, 0, 256);
|
||||
strcpy(line2, line);
|
||||
line2 = bb_xstrdup(line);
|
||||
|
||||
match_found = 0;
|
||||
match_status = regexec(pattern, line2, 1, &match_structs, 0);
|
||||
|
||||
|
||||
while (match_status == 0) {
|
||||
|
||||
memset(sub_line, 0, 256);
|
||||
|
||||
if (match_found == 0)
|
||||
match_found = 1;
|
||||
|
||||
line2 = insert_highlights(line2, match_structs.rm_so + prev_eo, match_structs.rm_eo + prev_eo);
|
||||
if ((size_t)match_structs.rm_eo + 11 + prev_eo < strlen(line2))
|
||||
strcat(sub_line, line2 + match_structs.rm_eo + 11 + prev_eo);
|
||||
|
||||
prev_eo += match_structs.rm_eo + 11;
|
||||
match_status = regexec(pattern, sub_line, 1, &match_structs, REG_NOTBOL);
|
||||
}
|
||||
|
||||
return line2;
|
||||
}
|
||||
|
||||
static void regex_process(void) {
|
||||
|
||||
char uncomp_regex[100];
|
||||
char current_line[256];
|
||||
int i;
|
||||
int j = 0;
|
||||
regex_t *pattern;
|
||||
|
||||
/* Reset variables */
|
||||
match_lines[0] = -1;
|
||||
match_pos = 0;
|
||||
num_matches = 0;
|
||||
match_found = 0;
|
||||
|
||||
pattern = (regex_t *) malloc(sizeof(regex_t));
|
||||
memset(pattern, 0, sizeof(regex_t));
|
||||
|
||||
/* Get the uncompiled regular expression from the user */
|
||||
clear_line();
|
||||
putchar((match_backwards) ? '?' : '/');
|
||||
uncomp_regex[0] = 0;
|
||||
fgets(uncomp_regex, sizeof(uncomp_regex), stdin);
|
||||
i = strlen(uncomp_regex);
|
||||
if(i > 0) {
|
||||
if(uncomp_regex[i-1] == '\n')
|
||||
uncomp_regex[i-1] = '\0';
|
||||
else
|
||||
while((i = getchar()) != '\n' && i != EOF);
|
||||
}
|
||||
|
||||
/* Compile the regex and check for errors */
|
||||
xregcomp(pattern, uncomp_regex, 0);
|
||||
|
||||
/* Run the regex on each line of the current file here */
|
||||
for (i = 0; i <= num_flines; i++) {
|
||||
strcpy(current_line, process_regex_on_line(flines[i], pattern));
|
||||
flines[i] = bb_xstrdup(current_line);
|
||||
if (match_found) {
|
||||
match_lines[j] = i;
|
||||
j++;
|
||||
|
||||
if (action) {
|
||||
growline = bb_xasprintf("%s%.*s%s%.*s%s", growline, match_structs.rm_so, line2, HIGHLIGHT, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so, NORMAL);
|
||||
}
|
||||
else {
|
||||
growline = bb_xasprintf("%s%.*s%.*s", growline, match_structs.rm_so - 4, line2, match_structs.rm_eo - match_structs.rm_so, line2 + match_structs.rm_so);
|
||||
}
|
||||
|
||||
line2 += match_structs.rm_eo;
|
||||
match_status = regexec(pattern, line2, 1, &match_structs, REG_NOTBOL);
|
||||
}
|
||||
|
||||
num_matches = j;
|
||||
if ((match_lines[0] != -1) && (num_flines > height - 2))
|
||||
buffer_line(match_lines[0]);
|
||||
else
|
||||
buffer_init();
|
||||
|
||||
growline = bb_xasprintf("%s%s", growline, line2);
|
||||
|
||||
return (match_found ? growline : line);
|
||||
|
||||
free(growline);
|
||||
free(line2);
|
||||
}
|
||||
|
||||
static void goto_match(int match) {
|
||||
|
||||
static void goto_match(int match)
|
||||
{
|
||||
/* This goes to a specific match - all line positions of matches are
|
||||
stored within the match_lines[] array. */
|
||||
if ((match < num_matches) && (match >= 0)) {
|
||||
@@ -718,30 +654,78 @@ static void goto_match(int match) {
|
||||
}
|
||||
}
|
||||
|
||||
static void search_backwards(void) {
|
||||
|
||||
int current_linepos = line_pos;
|
||||
static void regex_process(void)
|
||||
{
|
||||
char uncomp_regex[100];
|
||||
char *current_line;
|
||||
int i;
|
||||
int j = 0;
|
||||
regex_t pattern;
|
||||
/* Get the uncompiled regular expression from the user */
|
||||
clear_line();
|
||||
putchar((match_backwards) ? '?' : '/');
|
||||
uncomp_regex[0] = 0;
|
||||
fgets(uncomp_regex, sizeof(uncomp_regex), inp);
|
||||
|
||||
if (strlen(uncomp_regex) == 1) {
|
||||
if (num_matches)
|
||||
goto_match(match_backwards ? match_pos - 1 : match_pos + 1);
|
||||
else
|
||||
buffer_print();
|
||||
return;
|
||||
}
|
||||
uncomp_regex[strlen(uncomp_regex) - 1] = '\0';
|
||||
|
||||
/* Compile the regex and check for errors */
|
||||
xregcomp(&pattern, uncomp_regex, 0);
|
||||
|
||||
match_backwards = 1;
|
||||
regex_process();
|
||||
|
||||
for (i = 0; i < num_matches; i++) {
|
||||
if (match_lines[i] > current_linepos) {
|
||||
buffer_line(match_lines[i - num_back_match]);
|
||||
break;
|
||||
if (num_matches) {
|
||||
/* Get rid of all the highlights we added previously */
|
||||
for (i = 0; i <= num_flines; i++) {
|
||||
current_line = process_regex_on_line(flines[i], &old_pattern, 0);
|
||||
flines[i] = bb_xstrdup(current_line);
|
||||
}
|
||||
}
|
||||
|
||||
old_pattern = pattern;
|
||||
|
||||
/* Reset variables */
|
||||
match_backwards = 0;
|
||||
num_back_match = 1;
|
||||
|
||||
match_lines = xrealloc(match_lines, sizeof(int));
|
||||
match_lines[0] = -1;
|
||||
match_pos = 0;
|
||||
num_matches = 0;
|
||||
match_found = 0;
|
||||
/* Run the regex on each line of the current file here */
|
||||
for (i = 0; i <= num_flines; i++) {
|
||||
current_line = process_regex_on_line(flines[i], &pattern, 1);
|
||||
flines[i] = bb_xstrdup(current_line);
|
||||
if (match_found) {
|
||||
match_lines = xrealloc(match_lines, (j + 1) * sizeof(int));
|
||||
match_lines[j] = i;
|
||||
j++;
|
||||
}
|
||||
}
|
||||
|
||||
num_matches = j;
|
||||
if ((match_lines[0] != -1) && (num_flines > height - 2)) {
|
||||
if (match_backwards) {
|
||||
for (i = 0; i < num_matches; i++) {
|
||||
if (match_lines[i] > line_pos) {
|
||||
match_pos = i - 1;
|
||||
buffer_line(match_lines[match_pos]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
buffer_line(match_lines[0]);
|
||||
}
|
||||
else
|
||||
buffer_init();
|
||||
}
|
||||
#endif
|
||||
|
||||
static void number_process(int first_digit) {
|
||||
|
||||
static void number_process(int first_digit)
|
||||
{
|
||||
int i = 1;
|
||||
int num;
|
||||
char num_input[80];
|
||||
@@ -764,8 +748,10 @@ static void number_process(int first_digit) {
|
||||
keypress = num_input[i];
|
||||
num_input[i] = '\0';
|
||||
num = strtol(num_input, &endptr, 10);
|
||||
if (endptr==num_input || *endptr!='\0' || num < 1 || num > MAXLINES)
|
||||
goto END;
|
||||
if (endptr==num_input || *endptr!='\0' || num < 1 || num > MAXLINES) {
|
||||
buffer_print();
|
||||
return;
|
||||
}
|
||||
|
||||
/* We now know the number and the letter entered, so we process them */
|
||||
switch (keypress) {
|
||||
@@ -780,31 +766,29 @@ static void number_process(int first_digit) {
|
||||
buffer_line(num - 1);
|
||||
break;
|
||||
case 'p': case '%':
|
||||
buffer_line(reverse_percent(num));
|
||||
buffer_line(((num / 100) * num_flines) - 1);
|
||||
break;
|
||||
#ifdef CONFIG_FEATURE_LESS_REGEXP
|
||||
case 'n':
|
||||
goto_match(match_pos + num - 1);
|
||||
goto_match(match_pos + num);
|
||||
break;
|
||||
case '/':
|
||||
match_backwards = 0;
|
||||
regex_process();
|
||||
goto_match(num - 1);
|
||||
break;
|
||||
case '?':
|
||||
num_back_match = num;
|
||||
search_backwards();
|
||||
match_backwards = 1;
|
||||
regex_process();
|
||||
break;
|
||||
#endif
|
||||
default:
|
||||
break;
|
||||
}
|
||||
END:
|
||||
buffer_print();
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FEATURE_LESS_FLAGCS
|
||||
static void flag_change(void) {
|
||||
|
||||
static void flag_change(void)
|
||||
{
|
||||
int keypress;
|
||||
|
||||
clear_line();
|
||||
@@ -829,8 +813,8 @@ static void flag_change(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void show_flag_status(void) {
|
||||
|
||||
static void show_flag_status(void)
|
||||
{
|
||||
int keypress;
|
||||
int flag_val;
|
||||
|
||||
@@ -864,18 +848,17 @@ static void show_flag_status(void) {
|
||||
}
|
||||
#endif
|
||||
|
||||
static void full_repaint(void) {
|
||||
|
||||
static void full_repaint(void)
|
||||
{
|
||||
int temp_line_pos = line_pos;
|
||||
data_readlines();
|
||||
buffer_init();
|
||||
buffer_line(temp_line_pos);
|
||||
buffer_print();
|
||||
}
|
||||
|
||||
|
||||
static void save_input_to_file(void) {
|
||||
|
||||
static void save_input_to_file(void)
|
||||
{
|
||||
char current_line[256];
|
||||
int i;
|
||||
FILE *fp;
|
||||
@@ -884,7 +867,7 @@ static void save_input_to_file(void) {
|
||||
printf("Log file: ");
|
||||
fgets(current_line, 256, inp);
|
||||
current_line[strlen(current_line) - 1] = '\0';
|
||||
if (strlen(current_line)) {
|
||||
if (strlen(current_line) > 1) {
|
||||
fp = bb_xfopen(current_line, "w");
|
||||
for (i = 0; i < num_flines; i++)
|
||||
fprintf(fp, "%s", flines[i]);
|
||||
@@ -896,8 +879,8 @@ static void save_input_to_file(void) {
|
||||
}
|
||||
|
||||
#ifdef CONFIG_FEATURE_LESS_MARKS
|
||||
static void add_mark(void) {
|
||||
|
||||
static void add_mark(void)
|
||||
{
|
||||
int letter;
|
||||
int mark_line;
|
||||
|
||||
@@ -922,8 +905,8 @@ static void add_mark(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void goto_mark(void) {
|
||||
|
||||
static void goto_mark(void)
|
||||
{
|
||||
int letter;
|
||||
int i;
|
||||
|
||||
@@ -949,8 +932,8 @@ static void goto_mark(void) {
|
||||
|
||||
#ifdef CONFIG_FEATURE_LESS_BRACKETS
|
||||
|
||||
static char opp_bracket (char bracket) {
|
||||
|
||||
static char opp_bracket(char bracket)
|
||||
{
|
||||
switch (bracket) {
|
||||
case '{': case '[':
|
||||
return bracket + 2;
|
||||
@@ -970,8 +953,8 @@ static char opp_bracket (char bracket) {
|
||||
}
|
||||
}
|
||||
|
||||
static void match_right_bracket(char bracket) {
|
||||
|
||||
static void match_right_bracket(char bracket)
|
||||
{
|
||||
int bracket_line = -1;
|
||||
int i;
|
||||
|
||||
@@ -991,12 +974,11 @@ static void match_right_bracket(char bracket) {
|
||||
printf("%s%s%s", HIGHLIGHT, "No matching bracket found", NORMAL);
|
||||
|
||||
buffer_line(bracket_line - height + 2);
|
||||
buffer_print();
|
||||
}
|
||||
}
|
||||
|
||||
static void match_left_bracket (char bracket) {
|
||||
|
||||
static void match_left_bracket(char bracket)
|
||||
{
|
||||
int bracket_line = -1;
|
||||
int i;
|
||||
|
||||
@@ -1019,13 +1001,13 @@ static void match_left_bracket (char bracket) {
|
||||
printf("%s%s%s", HIGHLIGHT, "No matching bracket found", NORMAL);
|
||||
|
||||
buffer_line(bracket_line);
|
||||
buffer_print();
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CONFIG_FEATURE_LESS_BRACKETS */
|
||||
|
||||
static void keypress_process(int keypress) {
|
||||
static void keypress_process(int keypress)
|
||||
{
|
||||
switch (keypress) {
|
||||
case KEY_DOWN: case 'e': case 'j': case '\015':
|
||||
buffer_down(1);
|
||||
@@ -1052,12 +1034,10 @@ static void keypress_process(int keypress) {
|
||||
buffer_print();
|
||||
break;
|
||||
case 'g': case 'p': case '<': case '%':
|
||||
buffer_up(num_flines + 1);
|
||||
buffer_print();
|
||||
buffer_line(0);
|
||||
break;
|
||||
case 'G': case '>':
|
||||
buffer_down(num_flines + 1);
|
||||
buffer_print();
|
||||
buffer_line(num_flines - height + 2);
|
||||
break;
|
||||
case 'q': case 'Q':
|
||||
tless_exit(0);
|
||||
@@ -1093,20 +1073,18 @@ static void keypress_process(int keypress) {
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_LESS_REGEXP
|
||||
case '/':
|
||||
match_backwards = 0;
|
||||
regex_process();
|
||||
buffer_print();
|
||||
break;
|
||||
case 'n':
|
||||
goto_match(match_pos + 1);
|
||||
buffer_print();
|
||||
break;
|
||||
case 'N':
|
||||
goto_match(match_pos - 1);
|
||||
buffer_print();
|
||||
break;
|
||||
case '?':
|
||||
search_backwards();
|
||||
buffer_print();
|
||||
match_backwards = 1;
|
||||
regex_process();
|
||||
break;
|
||||
#endif
|
||||
#ifdef CONFIG_FEATURE_LESS_FLAGCS
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/modutils
|
||||
MODUTILS_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
+2
-2
@@ -681,9 +681,9 @@ static enum obj_reloc arch_apply_relocation (struct obj_file *f,
|
||||
ElfW(RelM) *rel, ElfW(Addr) value);
|
||||
|
||||
static void arch_create_got (struct obj_file *f);
|
||||
#if ENABLE_FEATURE_CHECK_TAINTED_MODULE
|
||||
|
||||
static int obj_gpl_license(struct obj_file *f, const char **license);
|
||||
#endif /* ENABLE_FEATURE_CHECK_TAINTED_MODULE */
|
||||
|
||||
#endif /* obj.h */
|
||||
//----------------------------------------------------------------------------
|
||||
//--------end of modutils obj.h
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/networking
|
||||
NETWORKING_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
@@ -25,7 +25,7 @@ top_builddir=../..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/networking/libiproute
|
||||
LIBIPROUTE_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
# Makefile for busybox
|
||||
#
|
||||
# Copyright (C) 1999-2004 by Erik Andersen <andersen@codepoet.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
|
||||
#
|
||||
|
||||
ifndef top_srcdir
|
||||
top_srcdir=../..
|
||||
endif
|
||||
ifndef top_builddir
|
||||
top_builddir=../..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/networking/udhcp
|
||||
UDHCP_DIR:=./
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include Makefile.in
|
||||
all: $(libraries-y)
|
||||
-include $(top_builddir)/.depend
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a $(AR_TARGET)
|
||||
|
||||
@@ -0,0 +1,573 @@
|
||||
/* dhcpc.c
|
||||
*
|
||||
* udhcp DHCP client
|
||||
*
|
||||
* Russ Dill <Russ.Dill@asu.edu> July 2001
|
||||
*
|
||||
* Licensed under the GPL v2 or later, see the file LICENSE in this tarball.
|
||||
*/
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <sys/file.h>
|
||||
#include <unistd.h>
|
||||
#include <getopt.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <arpa/inet.h>
|
||||
#include <signal.h>
|
||||
#include <time.h>
|
||||
#include <string.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <net/if.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "dhcpd.h"
|
||||
#include "dhcpc.h"
|
||||
#include "options.h"
|
||||
#include "clientpacket.h"
|
||||
#include "clientsocket.h"
|
||||
#include "script.h"
|
||||
#include "socket.h"
|
||||
#include "signalpipe.h"
|
||||
|
||||
static int state;
|
||||
static unsigned long requested_ip; /* = 0 */
|
||||
static unsigned long server_addr;
|
||||
static unsigned long timeout;
|
||||
static int packet_num; /* = 0 */
|
||||
static int fd = -1;
|
||||
|
||||
#define LISTEN_NONE 0
|
||||
#define LISTEN_KERNEL 1
|
||||
#define LISTEN_RAW 2
|
||||
static int listen_mode;
|
||||
|
||||
struct client_config_t client_config = {
|
||||
/* Default options. */
|
||||
.abort_if_no_lease = 0,
|
||||
.foreground = 0,
|
||||
.quit_after_lease = 0,
|
||||
.background_if_no_lease = 0,
|
||||
.interface = "eth0",
|
||||
.pidfile = NULL,
|
||||
.script = DEFAULT_SCRIPT,
|
||||
.clientid = NULL,
|
||||
.vendorclass = NULL,
|
||||
.hostname = NULL,
|
||||
.fqdn = NULL,
|
||||
.ifindex = 0,
|
||||
.retries = 3,
|
||||
.timeout = 3,
|
||||
.arp = "\0\0\0\0\0\0", /* appease gcc-3.0 */
|
||||
};
|
||||
|
||||
#ifndef IN_BUSYBOX
|
||||
static void ATTRIBUTE_NORETURN show_usage(void)
|
||||
{
|
||||
printf(
|
||||
"Usage: udhcpc [OPTIONS]\n\n"
|
||||
" -c, --clientid=CLIENTID Set client identifier - type is first char\n"
|
||||
" -C, --clientid-none Suppress default client identifier\n"
|
||||
" -V, --vendorclass=CLASSID Set vendor class identifier\n"
|
||||
" -H, --hostname=HOSTNAME Client hostname\n"
|
||||
" -h Alias for -H\n"
|
||||
" -F, --fqdn=FQDN Client fully qualified domain name\n"
|
||||
" -f, --foreground Do not fork after getting lease\n"
|
||||
" -b, --background Fork to background if lease cannot be\n"
|
||||
" immediately negotiated.\n"
|
||||
" -i, --interface=INTERFACE Interface to use (default: eth0)\n"
|
||||
" -n, --now Exit with failure if lease cannot be\n"
|
||||
" immediately negotiated.\n"
|
||||
" -p, --pidfile=file Store process ID of daemon in file\n"
|
||||
" -q, --quit Quit after obtaining lease\n"
|
||||
" -r, --request=IP IP address to request (default: none)\n"
|
||||
" -s, --script=file Run file at dhcp events (default:\n"
|
||||
" " DEFAULT_SCRIPT ")\n"
|
||||
" -T, --timeout=seconds Try to get the lease for the amount of\n"
|
||||
" seconds (default: 3)\n"
|
||||
" -t, --retries=NUM Send up to NUM request packets\n"
|
||||
" -v, --version Display version\n"
|
||||
);
|
||||
exit(0);
|
||||
}
|
||||
#else
|
||||
#define show_usage bb_show_usage
|
||||
extern void show_usage(void) ATTRIBUTE_NORETURN;
|
||||
#endif
|
||||
|
||||
|
||||
/* just a little helper */
|
||||
static void change_mode(int new_mode)
|
||||
{
|
||||
DEBUG(LOG_INFO, "entering %s listen mode",
|
||||
new_mode ? (new_mode == 1 ? "kernel" : "raw") : "none");
|
||||
if (fd >= 0) close(fd);
|
||||
fd = -1;
|
||||
listen_mode = new_mode;
|
||||
}
|
||||
|
||||
|
||||
/* perform a renew */
|
||||
static void perform_renew(void)
|
||||
{
|
||||
LOG(LOG_INFO, "Performing a DHCP renew");
|
||||
switch (state) {
|
||||
case BOUND:
|
||||
change_mode(LISTEN_KERNEL);
|
||||
case RENEWING:
|
||||
case REBINDING:
|
||||
state = RENEW_REQUESTED;
|
||||
break;
|
||||
case RENEW_REQUESTED: /* impatient are we? fine, square 1 */
|
||||
run_script(NULL, "deconfig");
|
||||
case REQUESTING:
|
||||
case RELEASED:
|
||||
change_mode(LISTEN_RAW);
|
||||
state = INIT_SELECTING;
|
||||
break;
|
||||
case INIT_SELECTING:
|
||||
break;
|
||||
}
|
||||
|
||||
/* start things over */
|
||||
packet_num = 0;
|
||||
|
||||
/* Kill any timeouts because the user wants this to hurry along */
|
||||
timeout = 0;
|
||||
}
|
||||
|
||||
|
||||
/* perform a release */
|
||||
static void perform_release(void)
|
||||
{
|
||||
char buffer[16];
|
||||
struct in_addr temp_addr;
|
||||
|
||||
/* send release packet */
|
||||
if (state == BOUND || state == RENEWING || state == REBINDING) {
|
||||
temp_addr.s_addr = server_addr;
|
||||
sprintf(buffer, "%s", inet_ntoa(temp_addr));
|
||||
temp_addr.s_addr = requested_ip;
|
||||
LOG(LOG_INFO, "Unicasting a release of %s to %s",
|
||||
inet_ntoa(temp_addr), buffer);
|
||||
send_release(server_addr, requested_ip); /* unicast */
|
||||
run_script(NULL, "deconfig");
|
||||
}
|
||||
LOG(LOG_INFO, "Entering released state");
|
||||
|
||||
change_mode(LISTEN_NONE);
|
||||
state = RELEASED;
|
||||
timeout = 0x7fffffff;
|
||||
}
|
||||
|
||||
|
||||
static void client_background(void)
|
||||
{
|
||||
background(client_config.pidfile);
|
||||
client_config.foreground = 1; /* Do not fork again. */
|
||||
client_config.background_if_no_lease = 0;
|
||||
}
|
||||
|
||||
|
||||
#ifdef COMBINED_BINARY
|
||||
int udhcpc_main(int argc, char *argv[])
|
||||
#else
|
||||
int main(int argc, char *argv[])
|
||||
#endif
|
||||
{
|
||||
uint8_t *temp, *message;
|
||||
unsigned long t1 = 0, t2 = 0, xid = 0;
|
||||
unsigned long start = 0, lease;
|
||||
fd_set rfds;
|
||||
int retval;
|
||||
struct timeval tv;
|
||||
int c, len;
|
||||
struct dhcpMessage packet;
|
||||
struct in_addr temp_addr;
|
||||
long now;
|
||||
int max_fd;
|
||||
int sig;
|
||||
int no_clientid = 0;
|
||||
|
||||
static const struct option arg_options[] = {
|
||||
{"clientid", required_argument, 0, 'c'},
|
||||
{"clientid-none", no_argument, 0, 'C'},
|
||||
{"vendorclass", required_argument, 0, 'V'},
|
||||
{"foreground", no_argument, 0, 'f'},
|
||||
{"background", no_argument, 0, 'b'},
|
||||
{"hostname", required_argument, 0, 'H'},
|
||||
{"hostname", required_argument, 0, 'h'},
|
||||
{"fqdn", required_argument, 0, 'F'},
|
||||
{"interface", required_argument, 0, 'i'},
|
||||
{"now", no_argument, 0, 'n'},
|
||||
{"pidfile", required_argument, 0, 'p'},
|
||||
{"quit", no_argument, 0, 'q'},
|
||||
{"request", required_argument, 0, 'r'},
|
||||
{"script", required_argument, 0, 's'},
|
||||
{"timeout", required_argument, 0, 'T'},
|
||||
{"version", no_argument, 0, 'v'},
|
||||
{"retries", required_argument, 0, 't'},
|
||||
{0, 0, 0, 0}
|
||||
};
|
||||
|
||||
/* get options */
|
||||
while (1) {
|
||||
int option_index = 0;
|
||||
c = getopt_long(argc, argv, "c:CV:fbH:h:F:i:np:qr:s:T:t:v", arg_options, &option_index);
|
||||
if (c == -1) break;
|
||||
|
||||
switch (c) {
|
||||
case 'c':
|
||||
if (no_clientid) show_usage();
|
||||
len = strlen(optarg) > 255 ? 255 : strlen(optarg);
|
||||
free(client_config.clientid);
|
||||
client_config.clientid = xmalloc(len + 2);
|
||||
client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID;
|
||||
client_config.clientid[OPT_LEN] = len;
|
||||
client_config.clientid[OPT_DATA] = '\0';
|
||||
strncpy((char*)client_config.clientid + OPT_DATA, optarg, len);
|
||||
break;
|
||||
case 'C':
|
||||
if (client_config.clientid) show_usage();
|
||||
no_clientid = 1;
|
||||
break;
|
||||
case 'V':
|
||||
len = strlen(optarg) > 255 ? 255 : strlen(optarg);
|
||||
free(client_config.vendorclass);
|
||||
client_config.vendorclass = xmalloc(len + 2);
|
||||
client_config.vendorclass[OPT_CODE] = DHCP_VENDOR;
|
||||
client_config.vendorclass[OPT_LEN] = len;
|
||||
strncpy((char*)client_config.vendorclass + OPT_DATA, optarg, len);
|
||||
break;
|
||||
case 'f':
|
||||
client_config.foreground = 1;
|
||||
break;
|
||||
case 'b':
|
||||
client_config.background_if_no_lease = 1;
|
||||
break;
|
||||
case 'h':
|
||||
case 'H':
|
||||
len = strlen(optarg) > 255 ? 255 : strlen(optarg);
|
||||
free(client_config.hostname);
|
||||
client_config.hostname = xmalloc(len + 2);
|
||||
client_config.hostname[OPT_CODE] = DHCP_HOST_NAME;
|
||||
client_config.hostname[OPT_LEN] = len;
|
||||
strncpy((char*)client_config.hostname + 2, optarg, len);
|
||||
break;
|
||||
case 'F':
|
||||
len = strlen(optarg) > 255 ? 255 : strlen(optarg);
|
||||
free(client_config.fqdn);
|
||||
client_config.fqdn = xmalloc(len + 5);
|
||||
client_config.fqdn[OPT_CODE] = DHCP_FQDN;
|
||||
client_config.fqdn[OPT_LEN] = len + 3;
|
||||
/* Flags: 0000NEOS
|
||||
S: 1 => Client requests Server to update A RR in DNS as well as PTR
|
||||
O: 1 => Server indicates to client that DNS has been updated regardless
|
||||
E: 1 => Name data is DNS format, i.e. <4>host<6>domain<4>com<0> not "host.domain.com"
|
||||
N: 1 => Client requests Server to not update DNS
|
||||
*/
|
||||
client_config.fqdn[OPT_LEN + 1] = 0x1;
|
||||
client_config.fqdn[OPT_LEN + 2] = 0;
|
||||
client_config.fqdn[OPT_LEN + 3] = 0;
|
||||
strncpy((char*)client_config.fqdn + 5, optarg, len);
|
||||
break;
|
||||
case 'i':
|
||||
client_config.interface = optarg;
|
||||
break;
|
||||
case 'n':
|
||||
client_config.abort_if_no_lease = 1;
|
||||
break;
|
||||
case 'p':
|
||||
client_config.pidfile = optarg;
|
||||
break;
|
||||
case 'q':
|
||||
client_config.quit_after_lease = 1;
|
||||
break;
|
||||
case 'r':
|
||||
requested_ip = inet_addr(optarg);
|
||||
break;
|
||||
case 's':
|
||||
client_config.script = optarg;
|
||||
break;
|
||||
case 'T':
|
||||
client_config.timeout = atoi(optarg);
|
||||
break;
|
||||
case 't':
|
||||
client_config.retries = atoi(optarg);
|
||||
break;
|
||||
case 'v':
|
||||
printf("udhcpcd, version %s\n\n", VERSION);
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
show_usage();
|
||||
}
|
||||
}
|
||||
|
||||
/* Start the log, sanitize fd's, and write a pid file */
|
||||
start_log_and_pid("udhcpc", client_config.pidfile);
|
||||
|
||||
if (read_interface(client_config.interface, &client_config.ifindex,
|
||||
NULL, client_config.arp) < 0)
|
||||
return 1;
|
||||
|
||||
/* if not set, and not suppressed, setup the default client ID */
|
||||
if (!client_config.clientid && !no_clientid) {
|
||||
client_config.clientid = xmalloc(6 + 3);
|
||||
client_config.clientid[OPT_CODE] = DHCP_CLIENT_ID;
|
||||
client_config.clientid[OPT_LEN] = 7;
|
||||
client_config.clientid[OPT_DATA] = 1;
|
||||
memcpy(client_config.clientid + 3, client_config.arp, 6);
|
||||
}
|
||||
|
||||
if (!client_config.vendorclass) {
|
||||
client_config.vendorclass = xmalloc(sizeof("udhcp "VERSION) + 2);
|
||||
client_config.vendorclass[OPT_CODE] = DHCP_VENDOR;
|
||||
client_config.vendorclass[OPT_LEN] = sizeof("udhcp "VERSION) - 1;
|
||||
client_config.vendorclass[OPT_DATA] = 1;
|
||||
memcpy(&client_config.vendorclass[OPT_DATA],
|
||||
"udhcp "VERSION, sizeof("udhcp "VERSION) - 1);
|
||||
}
|
||||
|
||||
|
||||
/* setup the signal pipe */
|
||||
udhcp_sp_setup();
|
||||
|
||||
state = INIT_SELECTING;
|
||||
run_script(NULL, "deconfig");
|
||||
change_mode(LISTEN_RAW);
|
||||
|
||||
for (;;) {
|
||||
|
||||
tv.tv_sec = timeout - uptime();
|
||||
tv.tv_usec = 0;
|
||||
|
||||
if (listen_mode != LISTEN_NONE && fd < 0) {
|
||||
if (listen_mode == LISTEN_KERNEL)
|
||||
fd = listen_socket(INADDR_ANY, CLIENT_PORT, client_config.interface);
|
||||
else
|
||||
fd = raw_socket(client_config.ifindex);
|
||||
if (fd < 0) {
|
||||
LOG(LOG_ERR, "FATAL: couldn't listen on socket, %m");
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
max_fd = udhcp_sp_fd_set(&rfds, fd);
|
||||
|
||||
if (tv.tv_sec > 0) {
|
||||
DEBUG(LOG_INFO, "Waiting on select...");
|
||||
retval = select(max_fd + 1, &rfds, NULL, NULL, &tv);
|
||||
} else retval = 0; /* If we already timed out, fall through */
|
||||
|
||||
now = uptime();
|
||||
if (retval == 0) {
|
||||
/* timeout dropped to zero */
|
||||
switch (state) {
|
||||
case INIT_SELECTING:
|
||||
if (packet_num < client_config.retries) {
|
||||
if (packet_num == 0)
|
||||
xid = random_xid();
|
||||
|
||||
/* send discover packet */
|
||||
send_discover(xid, requested_ip); /* broadcast */
|
||||
|
||||
timeout = now + client_config.timeout;
|
||||
packet_num++;
|
||||
} else {
|
||||
run_script(NULL, "leasefail");
|
||||
if (client_config.background_if_no_lease) {
|
||||
LOG(LOG_INFO, "No lease, forking to background.");
|
||||
client_background();
|
||||
} else if (client_config.abort_if_no_lease) {
|
||||
LOG(LOG_INFO, "No lease, failing.");
|
||||
return 1;
|
||||
}
|
||||
/* wait to try again */
|
||||
packet_num = 0;
|
||||
timeout = now + 60;
|
||||
}
|
||||
break;
|
||||
case RENEW_REQUESTED:
|
||||
case REQUESTING:
|
||||
if (packet_num < client_config.retries) {
|
||||
/* send request packet */
|
||||
if (state == RENEW_REQUESTED)
|
||||
send_renew(xid, server_addr, requested_ip); /* unicast */
|
||||
else send_selecting(xid, server_addr, requested_ip); /* broadcast */
|
||||
|
||||
timeout = now + ((packet_num == 2) ? 10 : 2);
|
||||
packet_num++;
|
||||
} else {
|
||||
/* timed out, go back to init state */
|
||||
if (state == RENEW_REQUESTED) run_script(NULL, "deconfig");
|
||||
state = INIT_SELECTING;
|
||||
timeout = now;
|
||||
packet_num = 0;
|
||||
change_mode(LISTEN_RAW);
|
||||
}
|
||||
break;
|
||||
case BOUND:
|
||||
/* Lease is starting to run out, time to enter renewing state */
|
||||
state = RENEWING;
|
||||
change_mode(LISTEN_KERNEL);
|
||||
DEBUG(LOG_INFO, "Entering renew state");
|
||||
/* fall right through */
|
||||
case RENEWING:
|
||||
/* Either set a new T1, or enter REBINDING state */
|
||||
if ((t2 - t1) <= (lease / 14400 + 1)) {
|
||||
/* timed out, enter rebinding state */
|
||||
state = REBINDING;
|
||||
timeout = now + (t2 - t1);
|
||||
DEBUG(LOG_INFO, "Entering rebinding state");
|
||||
} else {
|
||||
/* send a request packet */
|
||||
send_renew(xid, server_addr, requested_ip); /* unicast */
|
||||
|
||||
t1 = (t2 - t1) / 2 + t1;
|
||||
timeout = t1 + start;
|
||||
}
|
||||
break;
|
||||
case REBINDING:
|
||||
/* Either set a new T2, or enter INIT state */
|
||||
if ((lease - t2) <= (lease / 14400 + 1)) {
|
||||
/* timed out, enter init state */
|
||||
state = INIT_SELECTING;
|
||||
LOG(LOG_INFO, "Lease lost, entering init state");
|
||||
run_script(NULL, "deconfig");
|
||||
timeout = now;
|
||||
packet_num = 0;
|
||||
change_mode(LISTEN_RAW);
|
||||
} else {
|
||||
/* send a request packet */
|
||||
send_renew(xid, 0, requested_ip); /* broadcast */
|
||||
|
||||
t2 = (lease - t2) / 2 + t2;
|
||||
timeout = t2 + start;
|
||||
}
|
||||
break;
|
||||
case RELEASED:
|
||||
/* yah, I know, *you* say it would never happen */
|
||||
timeout = 0x7fffffff;
|
||||
break;
|
||||
}
|
||||
} else if (retval > 0 && listen_mode != LISTEN_NONE && FD_ISSET(fd, &rfds)) {
|
||||
/* a packet is ready, read it */
|
||||
|
||||
if (listen_mode == LISTEN_KERNEL)
|
||||
len = get_packet(&packet, fd);
|
||||
else len = get_raw_packet(&packet, fd);
|
||||
|
||||
if (len == -1 && errno != EINTR) {
|
||||
DEBUG(LOG_INFO, "error on read, %m, reopening socket");
|
||||
change_mode(listen_mode); /* just close and reopen */
|
||||
}
|
||||
if (len < 0) continue;
|
||||
|
||||
if (packet.xid != xid) {
|
||||
DEBUG(LOG_INFO, "Ignoring XID %lx (our xid is %lx)",
|
||||
(unsigned long) packet.xid, xid);
|
||||
continue;
|
||||
}
|
||||
/* Ignore packets that aren't for us */
|
||||
if (memcmp(packet.chaddr, client_config.arp, 6)) {
|
||||
DEBUG(LOG_INFO, "packet does not have our chaddr -- ignoring");
|
||||
continue;
|
||||
}
|
||||
|
||||
if ((message = get_option(&packet, DHCP_MESSAGE_TYPE)) == NULL) {
|
||||
DEBUG(LOG_ERR, "couldnt get option from packet -- ignoring");
|
||||
continue;
|
||||
}
|
||||
|
||||
switch (state) {
|
||||
case INIT_SELECTING:
|
||||
/* Must be a DHCPOFFER to one of our xid's */
|
||||
if (*message == DHCPOFFER) {
|
||||
if ((temp = get_option(&packet, DHCP_SERVER_ID))) {
|
||||
memcpy(&server_addr, temp, 4);
|
||||
xid = packet.xid;
|
||||
requested_ip = packet.yiaddr;
|
||||
|
||||
/* enter requesting state */
|
||||
state = REQUESTING;
|
||||
timeout = now;
|
||||
packet_num = 0;
|
||||
} else {
|
||||
DEBUG(LOG_ERR, "No server ID in message");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RENEW_REQUESTED:
|
||||
case REQUESTING:
|
||||
case RENEWING:
|
||||
case REBINDING:
|
||||
if (*message == DHCPACK) {
|
||||
if (!(temp = get_option(&packet, DHCP_LEASE_TIME))) {
|
||||
LOG(LOG_ERR, "No lease time with ACK, using 1 hour lease");
|
||||
lease = 60 * 60;
|
||||
} else {
|
||||
memcpy(&lease, temp, 4);
|
||||
lease = ntohl(lease);
|
||||
}
|
||||
|
||||
/* enter bound state */
|
||||
t1 = lease / 2;
|
||||
|
||||
/* little fixed point for n * .875 */
|
||||
t2 = (lease * 0x7) >> 3;
|
||||
temp_addr.s_addr = packet.yiaddr;
|
||||
LOG(LOG_INFO, "Lease of %s obtained, lease time %ld",
|
||||
inet_ntoa(temp_addr), lease);
|
||||
start = now;
|
||||
timeout = t1 + start;
|
||||
requested_ip = packet.yiaddr;
|
||||
run_script(&packet,
|
||||
((state == RENEWING || state == REBINDING) ? "renew" : "bound"));
|
||||
|
||||
state = BOUND;
|
||||
change_mode(LISTEN_NONE);
|
||||
if (client_config.quit_after_lease)
|
||||
return 0;
|
||||
if (!client_config.foreground)
|
||||
client_background();
|
||||
|
||||
} else if (*message == DHCPNAK) {
|
||||
/* return to init state */
|
||||
LOG(LOG_INFO, "Received DHCP NAK");
|
||||
run_script(&packet, "nak");
|
||||
if (state != REQUESTING)
|
||||
run_script(NULL, "deconfig");
|
||||
state = INIT_SELECTING;
|
||||
timeout = now;
|
||||
requested_ip = 0;
|
||||
packet_num = 0;
|
||||
change_mode(LISTEN_RAW);
|
||||
sleep(3); /* avoid excessive network traffic */
|
||||
}
|
||||
break;
|
||||
/* case BOUND, RELEASED: - ignore all packets */
|
||||
}
|
||||
} else if (retval > 0 && (sig = udhcp_sp_read(&rfds))) {
|
||||
switch (sig) {
|
||||
case SIGUSR1:
|
||||
perform_renew();
|
||||
break;
|
||||
case SIGUSR2:
|
||||
perform_release();
|
||||
break;
|
||||
case SIGTERM:
|
||||
LOG(LOG_INFO, "Received SIGTERM");
|
||||
return 0;
|
||||
}
|
||||
} else if (retval == -1 && errno == EINTR) {
|
||||
/* a signal was caught */
|
||||
} else {
|
||||
/* An error occured */
|
||||
DEBUG(LOG_ERR, "Error on select");
|
||||
}
|
||||
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
+1
-1
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/procps
|
||||
PROCPS_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/shell
|
||||
SHELL_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
@@ -3026,6 +3026,10 @@ forkexec(REGISTER struct op *t, int *pin, int *pout, int act, char **wp)
|
||||
if (resetsig) {
|
||||
signal(SIGINT, SIG_DFL);
|
||||
signal(SIGQUIT, SIG_DFL);
|
||||
} else {
|
||||
/* put non-interactive processes into a different process group.
|
||||
* we don't support jobs, but this is at least sane: see Bug 659 */
|
||||
setpgrp();
|
||||
}
|
||||
|
||||
if (t->type == TPAREN)
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/sysklogd
|
||||
SYSKLOGD_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@ top_builddir=..
|
||||
endif
|
||||
srcdir=$(top_srcdir)/util-linux
|
||||
UTILLINUX_DIR:=./
|
||||
include $(top_builddir)/Rules.mak
|
||||
include $(top_srcdir)/Rules.mak
|
||||
include $(top_builddir)/.config
|
||||
include Makefile.in
|
||||
all: $(libraries-y)
|
||||
|
||||
+13
-9
@@ -284,6 +284,7 @@ static int singlemount(struct mntent *mp)
|
||||
return 1;
|
||||
} else {
|
||||
// Strangely enough, nfsmount() doesn't actually mount() anything.
|
||||
mp->mnt_type = "nfs";
|
||||
rc = mount_it_now(mp, vfsflags, filteropts);
|
||||
if (ENABLE_FEATURE_CLEAN_UP) free(filteropts);
|
||||
|
||||
@@ -291,11 +292,11 @@ static int singlemount(struct mntent *mp)
|
||||
}
|
||||
}
|
||||
|
||||
// Look at the file. (Not found isn't a failure for remount.)
|
||||
// Look at the file. (Not found isn't a failure for remount, or for
|
||||
// a synthetic filesystem like proc or sysfs.)
|
||||
|
||||
if (lstat(mp->mnt_fsname, &st));
|
||||
|
||||
if (!(vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE))) {
|
||||
else if (!(vfsflags & (MS_REMOUNT | MS_BIND | MS_MOVE))) {
|
||||
// Do we need to allocate a loopback device for it?
|
||||
|
||||
if (ENABLE_FEATURE_MOUNT_LOOP && S_ISREG(st.st_mode)) {
|
||||
@@ -475,8 +476,9 @@ int mount_main(int argc, char **argv)
|
||||
|
||||
// Get next fstab entry
|
||||
|
||||
if (!getmntent_r(fstab, mtcur, bb_common_bufsiz1,
|
||||
sizeof(bb_common_bufsiz1)))
|
||||
if (!getmntent_r(fstab, mtcur, bb_common_bufsiz1
|
||||
+ (mtcur==mtpair ? sizeof(bb_common_bufsiz1)/2 : 0),
|
||||
sizeof(bb_common_bufsiz1)/2))
|
||||
{
|
||||
// Were we looking for something specific?
|
||||
|
||||
@@ -531,11 +533,13 @@ int mount_main(int argc, char **argv)
|
||||
|
||||
// Mount this thing.
|
||||
|
||||
rc = singlemount(mtcur);
|
||||
if (rc) {
|
||||
if (singlemount(mtcur)) {
|
||||
// Don't whine about already mounted fs when mounting all.
|
||||
if (errno == EBUSY) rc = 0;
|
||||
else break;
|
||||
// Note: we should probably change return value to indicate
|
||||
// failure, without causing a duplicate error message.
|
||||
if (errno != EBUSY) bb_perror_msg("Mounting %s on %s failed",
|
||||
mtcur->mnt_fsname, mtcur->mnt_dir);
|
||||
rc = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user