Re: utmp fallback not complete enough

2015-10-14 Thread ibid . ag
On Thu, Oct 15, 2015 at 04:17:03PM +1300, Alastair Hughes wrote:
> I've just tried to build busybox 1.24.0 against musl, however the build
> fails because musl does not define _PATH_WTMP in utmpx.h (it's defined
> in utmp.h).

musl does not *implement* the utmp(x) interfaces; it stubs them out.
The maintainer considers them a fundamentally harmful feature,
essentially equivalent to automatically posting your location on
Foursquare or (insert social site).
Internally, utmp* is generally a binary log of system events like
login/logout/runlevel changes, publicly available to all users (often
chmod a+rw).

(Of course, due to that last bit, it *should* not be used for things
like figuring out the current runlevel, or most of the uses that it's
put to...)

Your best bet is goingg to be disabling utmp* support completely;
anything that requires it wouldn't work right anyhow.

> This is caused by commit 86a7f18f211af1abda5c855d2674b0fcb53de524 
> (*: Switch to POSIX utmpx API), and the workaround for uclibc
> (7d86384b246434e7252f7f409a7aa9efeacb (include: Fallback to UTMP
> unless there is UTMPX support)) does not work for musl, as it only
> checks for __UCLIBC__ or __GLIBC__.
> 
> I'm not sure what would be an appropriate fix; POSIX appears to not
> include _PATH_WTMP [1] at all? What would be a good way of fixing this?

Maybe
#ifndef _PATH_WTMP
//define it to a default, or include paths.h

would work to get it building, but it won't actually help you.


HTH,
Isaac
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[PATCH] Ntpd config file support

2014-03-22 Thread ibid . ag
Hello,
I got tired of hearing numbers thrown around without basis in a 4-5 day old 
thread
when the subject was probably trivial, so I wrote a parser for ntp.conf
this morning.

This version falls back to /etc/ntp.conf when -p is not specified; if -p
is specified, ntp.conf is ignored. Only lines starting with "server" are
used.

Here (Debian Squeeze) the patch is +10 bytes without FEATURE_NTPD_CONF,
+250 bytes with it on. I could get rid of that +10 bytes easily; it's
just because I changed how it detects whether to error out.

HTH,
Isaac Dunham
>From 3e0a8c764d58d1637fdcbaf24b6b4f77b2216402 Mon Sep 17 00:00:00 2001
From: Isaac Dunham 
Date: Sat, 22 Mar 2014 11:44:30 -0700
Subject: [PATCH] ntpd: parse /etc/ntp.conf

This is a rudimentary parser for /etc/ntp.conf; it only looks for
lines like this:
server some.pool.ntp.org
server 0.0.0.0
All options are ignored.
+10 bytes when disabled, though I could make it +0.

Enabled, it's +250 bytes with gcc 4.4 and glibc 2.11.3:

function old new   delta
ntp_init 406 523+117
add_peers  - 107+107
.rodata   141382  141402 +20
packed_usage   29386   29392  +6
--
(add/remove: 1/0 grow/shrink: 3/0 up/down: 250/0) Total: 250 bytes
   text	   data	bss	dec	hex	filename
 759413	   2059	   9020	 770492	  bc1bc	busybox_old
 759657	   2059	   9020	 770736	  bc2b0	busybox_unstripped
---
 networking/Config.src |8 
 networking/ntpd.c |   29 +++--
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/networking/Config.src b/networking/Config.src
index ca0ddcd..fbad7ec 100644
--- a/networking/Config.src
+++ b/networking/Config.src
@@ -664,6 +664,14 @@ config FEATURE_NTPD_SERVER
 	  Make ntpd usable as a NTP server. If you disable this option
 	  ntpd will be usable only as a NTP client.
 
+config FEATURE_NTPD_CONF
+	bool "Make ntpd understand /etc/ntp.conf"
+	default y
+	depends on NTPD
+	help
+	  Make ntpd look in /etc/ntp.conf for peers. Only "server address"
+	  is supported.
+
 config PSCAN
 	bool "pscan"
 	default y
diff --git a/networking/ntpd.c b/networking/ntpd.c
index 44592ce..bbecdd3 100644
--- a/networking/ntpd.c
+++ b/networking/ntpd.c
@@ -42,6 +42,9 @@
 //usage:	)
 //usage: "\n	-S PROG	Run PROG after stepping time, stratum change, and every 11 mins"
 //usage: "\n	-p PEER	Obtain time from PEER (may be repeated)"
+//usage:	IF_FEATURE_NTPD_CONF(
+//usage: "\nIf -p is not specified, look in /etc/ntp.conf"
+//usage:	)
 
 #include "libbb.h"
 #include 
@@ -2087,17 +2090,39 @@ static NOINLINE void ntp_init(char **argv)
 			"d" /* compat */
 			"46aAbgL", /* compat, ignored */
 			&peers, &G.script_name, &G.verbose);
-	if (!(opts & (OPT_p|OPT_l)))
-		bb_show_usage();
+
 //	if (opts & OPT_x) /* disable stepping, only slew is allowed */
 //		G.time_was_stepped = 1;
 	if (peers) {
 		while (peers)
 			add_peers(llist_pop(&peers));
 	} else {
+#if ENABLE_FEATURE_NTPD_CONF
+		size_t bsiz = 0, i=0;
+		char *buf = 0;
+		FILE *stream = fopen("/etc/ntp.conf","r");
+
+		while (stream && !errno) {
+			getline(&buf, &bsiz, stream);
+			if (!strncmp(buf, "server", 6)) {
+char *cbuf = buf+6;
+while (cbuf[0]=='\t' || cbuf[0]==' ')
+	cbuf++;
+while (cbuf[i] > 35) i++;
+cbuf[i] = 0;
+add_peers(xstrdup(cbuf));
+			}
+		}
+		if (buf) free(buf);
+		if (stream) fclose(stream);
+		errno = 0;
+	}
+	if ((opts & OPT_l) && !G.peer_cnt) {
+#endif
 		/* -l but no peers: "stratum 1 server" mode */
 		G.stratum = 1;
 	}
+	if (!(opts & OPT_l) && !G.peer_cnt) bb_show_usage();
 	if (!(opts & OPT_n)) {
 		bb_daemonize_or_rexec(DAEMON_DEVNULL_STDIO, argv);
 		logmode = LOGMODE_NONE;
-- 
1.7.10.4

___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

Re: Ntpd config file support (sample sed)

2014-03-19 Thread ibid . ag
On Tue, Mar 18, 2014 at 10:15:21PM +0100, Harald Becker wrote:
> Hi Mike !
> 
> On 18-03-2014 15:12 Mike Dean  wrote:
> ># Put your ntp nameservers here
> 
> To clarify: It's not a name server, it's a time server (NTP =
> network time protocol).
> 
> ... and what makes it difficult to write such things in a file,
> use an sed filter to read that config into a script variable,
> then use the arguments from variable when invoking Busybox ntpd?
> 
> With some clever sed rules you can filter out empty lines and
> comments, pick lines which start with "timeserver" then add the
> required "-p" parameter prefix to any such lines

Here's what that sed could look like:

[ -e /etc/ntp.conf ] && NTP_SERVERS="`sed -ne 's/#.*//' -e 
's/^timeserver/-p/p'`"

Just saying this because it's not even clever.


HTH,
Isaac Dunham
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: RFC: 3 shells (ash, dash, bash), 3 different behaviours

2014-03-13 Thread ibid . ag
On Fri, Mar 14, 2014 at 12:24:51AM +0100, Cristian Ionescu-Idbohrn wrote:
> On Thu, 13 Mar 2014, Cristian Ionescu-Idbohrn wrote:
> 
> > Date: Thu, 13 Mar 2014 21:00:32 +0100
> > From: Cristian Ionescu-Idbohrn 
> > Reply-To: "busybox@busybox.net" 
> > To: "busybox@busybox.net" 
> > Subject: RFC: 3 shells (ash, dash, bash), 3 different behaviours
> >
> > It's explained here:
> >
> > http://pubs.opengroup.org/onlinepubs/009695399/utilities/sh.html
> >
> > IFS
> >
> > (Input Field Separators.) A string treated as a list of
> > characters that shall be used for field splitting and to split
> > lines into words with the read command.  See Field Splitting.
> > If IFS is not set, the shell shall behave as if the value of
> > IFS were , , and .
> > Implementations may ignore the value of IFS in the environment
> > at the time sh is invoked, treating IFS as if it were not set.
> >
> > What bothers me is the last phrase:
> 
> Reading this again:
> 
> > Implementations may ignore the value of IFS in the environment
> > at the time sh is invoked, treating IFS as if it were not set.
> 
> My mother tongue isn't english, but what I make of it is that the
> shell may ignore an environment IFS set outside a shell(script)?.
> Thoughts?
> 
Correct. 

If you use either of these:
 export IFS=" -_"; sh #or ./script.sh ...

 IFS=" -_" sh

the shell is _permitted_ (but not required) to ignore the value of IFS.

The reverse sequence, 

 sh
 $ IFS=" -_"

cannot be ignored, however.

So the shell could unconditionally unset IFS on start.


HTH,
Isaac Dunham
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: Looking for simple ifplugd example script

2014-02-20 Thread ibid . ag
On Thu, Feb 20, 2014 at 04:14:12PM +, Bryan Evenson wrote:
> I am using busybox-1.20.2 on an embedded Debian Linux machine, and I have 
> configured Busybox to include ifplugd.  I would like ifplugd to do the 
> following:
> 
> 1. When the Ethernet cable is plugged in, attempt DHCP on eth0
> 2. If DHCP fails, use a set static IP address
> 3. When the Ethernet cable is unplugged, unconfigure eth0
> 
> At this point, ifplugd is not running.  After some poking around, 
> I see that there is no default daemon script for ifplugd included 
> with Busybox.  I'm assuming a script to do the above isn't that 
> difficult, but I can't seem to find any examples on how to do this. 
> Does anyone have a simple example that I can go by?  I did see the 
> example in the Busybox source under examples/var_service/ifplugd_if, 
> but I couldn't make any sense of what that script did and how to make use of 
> it.
DISCLAIMER: I haven't tried any of this, it's based on my reading of the
documentation.

I'm not sure what init system it's aimed at (runit?), but here's what I
can make out:

examples/var_service/ifplugd_if/run: starts ifplugd with ifplugd_handler
as the script.

examples/var_service/ifplugd_if/ifplugd_handler: ifplugd script; called
as 
$SCRIPT  up
$SCRIPT  down

A script for that would be something like:
===begin /lib/busybox/ifplugd_script===
#!/bin/sh
IP="192.268.2.1"

case $2 in
up)
dhclient $1 || ifconfig $1 $IP
;;
down)
ifconfig $1 down
esac
===end /lib/busybox/ifplugd_script===

You may need a good bit more magic in there, and may want to change 
the commands used.
And you'd start it with something like this commandline:

ifplugd -IfM -t 5 -i eth0 -r /lib/busybox/ifplugd_script

> 
> On a related note, I have eth0 setup in /etc/network/interfaces as:
> auto eth0
> iface eth0 inet dhcp
> 
> If I want to use a static IP address if DHCP fails, do I need to add 
> something to /etc/network/interfaces, or is that something that would belong 
> in the ifplugd script?
> 
> Thanks,
> Bryan

I'm not sure what's the proper approach. I see notes that a static IP can be
configured via the DHCP client...

HTH,
Isaac Dunham
___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


Re: [PATCH] unbreak uncomressed files with tar, modutils, and man

2014-01-26 Thread ibid . ag
On Thu, Jan 16, 2014 at 09:25:32PM -0800, ibid...@gmail.com wrote:
> This afternoon I updated a small system to git HEAD, rebooted, 
> and discovered that modprobe no longer worked.
> Specifically, it spat out an error like this:
> modprobe: no gzip/bzip2/xz magic
> grep helped me track this down to archival/libarchive/open_transformer.c.
> 
> I'm using uncompressed modules, so I need modprobe to simply proceed on
> when an uncompressed file is encountered.
> This was the most obvious way to do that; in the process, I happened to find
> and fix similar issues in man and tar.
> 
> I'm not sure how far back this is an issue; it looks like it may be from 
> this commit:
> 
> commit 7c47b560a8fc97956dd8132bd7f1863d83c19866
> Author: Denys Vlasenko 
> Date:   Fri Jan 10 14:06:57 2014 +0100
> 
> libarchive: open_zipped() does not need to check extensions for e.g. gzip
 

Did this get lost in the mail?

 
Thanks,
Isaac Dunham


___
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox


[PATCH] unbreak uncomressed files with tar, modutils, and man

2014-01-16 Thread ibid . ag
This afternoon I updated a small system to git HEAD, rebooted, 
and discovered that modprobe no longer worked.
Specifically, it spat out an error like this:
modprobe: no gzip/bzip2/xz magic
grep helped me track this down to archival/libarchive/open_transformer.c.

I'm using uncompressed modules, so I need modprobe to simply proceed on
when an uncompressed file is encountered.
This was the most obvious way to do that; in the process, I happened to find
and fix similar issues in man and tar.

I'm not sure how far back this is an issue; it looks like it may be from 
this commit:

commit 7c47b560a8fc97956dd8132bd7f1863d83c19866
Author: Denys Vlasenko 
Date:   Fri Jan 10 14:06:57 2014 +0100

libarchive: open_zipped() does not need to check extensions for e.g. gzip


Thanks,
Isaac Dunham>From daba7a86bede551c5ab14a4c99426c3711b530c9 Mon Sep 17 00:00:00 2001
From: Isaac Dunham 
Date: Thu, 16 Jan 2014 19:28:09 -0800
Subject: [PATCH] Unbreak modutils, tar, man for uncompressed files.

Several tools broke because open_zipped() exited on uncompressed
files.
To reproduce, use a defconfig busybox and run these commands:
$ ./busybox tar cf new.tar LICENSE
$ ./busybox tar tf new.tar
tar: no gzip/bzip2/xz magic

This fixes the issue.
fbsplash and bunzip/gunzip/un* still have the old behavior.

function old new   delta
fbsplash_main   10091014  +5
bbunpack 739 744  +5
open_zipped   88  89  +1
xmalloc_open_zipped_read_close67  63  -4
cut_main 918 887 -31
--
(add/remove: 0/0 grow/shrink: 3/2 up/down: 11/-35)Total: -24 bytes
---
 archival/bbunzip.c |2 +-
 archival/libarchive/open_transformer.c |6 +++---
 archival/tar.c |2 +-
 include/libbb.h|4 ++--
 miscutils/fbsplash.c   |2 +-
 miscutils/man.c|2 +-
 6 files changed, 9 insertions(+), 9 deletions(-)

diff --git a/archival/bbunzip.c b/archival/bbunzip.c
index b3fb90f..0a10c3e 100644
--- a/archival/bbunzip.c
+++ b/archival/bbunzip.c
@@ -72,7 +72,7 @@ int FAST_FUNC bbunpack(char **argv,
 	goto err;
 			} else {
 /* "clever zcat" with FILE */
-int fd = open_zipped(filename);
+int fd = open_zipped(filename, /*fail_if_not_detected*/ 1);
 if (fd < 0)
 	goto err_name;
 xmove_fd(fd, STDIN_FILENO);
diff --git a/archival/libarchive/open_transformer.c b/archival/libarchive/open_transformer.c
index 1aeba13..ad34072 100644
--- a/archival/libarchive/open_transformer.c
+++ b/archival/libarchive/open_transformer.c
@@ -180,7 +180,7 @@ int FAST_FUNC setup_unzip_on_fd(int fd, int fail_if_not_detected)
 	return 0;
 }
 
-int FAST_FUNC open_zipped(const char *fname)
+int FAST_FUNC open_zipped(const char *fname, int fail_if_not_detected)
 {
 	int fd;
 
@@ -200,7 +200,7 @@ int FAST_FUNC open_zipped(const char *fname)
 	 || (ENABLE_FEATURE_SEAMLESS_BZ2)
 	 || (ENABLE_FEATURE_SEAMLESS_XZ)
 	) {
-		setup_unzip_on_fd(fd, /*fail_if_not_detected:*/ 1);
+		setup_unzip_on_fd(fd, fail_if_not_detected);
 	}
 
 	return fd;
@@ -213,7 +213,7 @@ void* FAST_FUNC xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_
 	int fd;
 	char *image;
 
-	fd = open_zipped(fname);
+	fd = open_zipped(fname, 0); //all users need to open uncompressed files
 	if (fd < 0)
 		return NULL;
 
diff --git a/archival/tar.c b/archival/tar.c
index bd61abd..ec06b38 100644
--- a/archival/tar.c
+++ b/archival/tar.c
@@ -1137,7 +1137,7 @@ int tar_main(int argc UNUSED_PARAM, char **argv)
 			 && flags == O_RDONLY
 			 && !(opt & OPT_ANY_COMPRESS)
 			) {
-tar_handle->src_fd = open_zipped(tar_filename);
+tar_handle->src_fd = open_zipped(tar_filename, /*fail_if_not_opened*/ 0);
 if (tar_handle->src_fd < 0)
 	bb_perror_msg_and_die("can't open '%s'", tar_filename);
 			} else {
diff --git a/include/libbb.h b/include/libbb.h
index 64167bb..d2cb7d8 100644
--- a/include/libbb.h
+++ b/include/libbb.h
@@ -738,10 +738,10 @@ extern void *xmalloc_xopen_read_close(const char *filename, size_t *maxsz_p) FAS
 /* Autodetects gzip/bzip2 formats. fd may be in the middle of the file! */
 extern int setup_unzip_on_fd(int fd, int fail_if_not_detected) FAST_FUNC;
 /* Autodetects .gz etc */
-extern int open_zipped(const char *fname) FAST_FUNC;
+extern int open_zipped(const char *fname, int fail_if_not_detected) FAST_FUNC;
 #else
 # define setup_unzip_on_fd(...) (0)
-# define open_zipped(fname) open((fname), O_RDONLY);
+# define open_zipped(fname, ignore) open((fname), O_RDONLY);
 #endif
 extern void *xmalloc_open_zipped_read_close(const char *fname, size_t *maxsz_p) FAST_FUNC RETURNS_MALLOC;
 
diff --git a/miscutils/f