Re: diff -Naur

2008-11-19 Thread Vladimir Dronnikov
>
> > Using the subj from current SVN I get the patches which do not substitute
> > /dev/null for missing or being deleted files.
> > Is it intended?
>
> Are you saying that older versions were doing this, and now it broke?


Nope. I simply did not pay attention. BB generated diffs do not apply
cleanly by Rob's toybox' patch. I use his toolchain in my building tree.
Although I can use vanilla patch the question is whether BB diff does things
right?

I see in diff.c text containing bb_dev_null like:
---
if (flags & D_EMPTY1)
/* can't be stdin, but xfopen_stdin() is smaller code */
f1 = xfopen_stdin(bb_dev_null);
else
f1 = xfopen_stdin(file1);
---

meaning diff copes with the problem of absent files, but the resulting patch
never uses /dev/null as filename.

Should we ask the author?

TIA,
--
Vladimir
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Re: inotifyd problems

2008-11-19 Thread Vladimir Dronnikov
>
> inotifyd agent file
> differs from
> inotifyd agent file1 file2
> This is easy to fix.


Elegantly solved!

Also I noticed bugs:


- unsigned mask = IN_ALL_EVENTS done just once,
>   must be done before each file


In fact it was intended. Specified mask was meant to propagate through
subsequent watches to save user typings. But it is ok.

I am applying this patch, please review.


Think it is ok, Denys. Please, apply.

--
Vladimir
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Re: cleanup:networking/interface.c

2008-11-19 Thread Denys Vlasenko
On Tuesday 18 November 2008 16:08, walter harms wrote:
> this is a cleanup patch that does not change code only rearrange it.
> the whole idea is to have better readable code.
> all size changes are due to the compiler.
> 
> NTL it would be nice if someone who used IPV6 could confirm that is still 
> works.
> 
> size interface.o.new  interface.o
>textdata bss dec hex filename
>8626   0  25865121cb interface.o.new
>8853   0  25887822ae interface.o

This would not compile:

+static void ife_print6(struct interface *ptr) { while(0) } ;

--
vda
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: diff -Naur

2008-11-19 Thread Denys Vlasenko
On Tuesday 18 November 2008 13:24, Vladimir Dronnikov wrote:
> Hello, Denys!
> 
> Using the subj from current SVN I get the patches which do not substitute
> /dev/null for missing or being deleted files.
> Is it intended?

Are you saying that older versions were doing this, and now it broke?
I just don't remember each applet's level of compatibility, sorry...
--
vda
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: [PATCH] wget: add timeout parameter

2008-11-19 Thread Denys Vlasenko
On Tuesday 18 November 2008 13:56, Matthias Kaehlcke wrote:
> > Thanks for the updated patch, i'll test and apply it soon (unless
> > somebody beats me to it).
> > If you experience size-increase with using "quiet" instead of looking at
> > opt (i didn't try), then please follow-up.
> 
> here is a new version of the patch against busybox 1.13.0
> below the stats you asked me for
> 
> size busybox.org
>textdata bss dec hex filename
>  67876721689396  690331   a889b busybox
> size busybox
>textdata bss dec hex filename
>  67865121689396  690215   a8827 busybox
> 
> bloat-o-meter output:
> 
> function old new delta
> .rodata   123186  123201 +15
> --
> (add/remove: 0/0 grow/shrink: 1/0 up/down: 15/0)   Total: 15 bytes

Tried. On my machine bloat-o-meter says:

function old new   delta
timer  -  80 +80
wget_main   24572528 +71
static.wget_longopts 110 120 +10
packed_usage   25431   25441 +10
progressmeter814 749 -65
--
(add/remove: 1/0 grow/shrink: 3/1 up/down: 171/-65)   Total: 106 bytes

Testing:

# ./busybox wget -T2 
http://kernel.org/pub/linux/kernel/v2.6/linux-2.6.27.6.tar.bz2
Connecting to kernel.org (204.152.191.37:80)
linux-2.6.27.6.tar.b   1% |   |   566k 00:02:51 ETAw
get: download timed out

-T2 is supposed to be a read timeout, a timeout for single read.
You implemented it as timeout for the whole file to be downloaded.

You probably need to output a newline before timeout message.

> @@ -444,6 +469,8 @@
>  
>   INIT_G();
>  
> + flags = 0;

It is already 0.

> + if (opt & WGET_OPT_QUIET) {
> + flags |= WGET_QUIET;
> + }

You don't need this then. We have a global variable
option_mask32, you can just check (option_mask32 & WGET_OPT_QUIET)
instead of (flags & WGET_QUIET)


To be honest, whole dance with alarm() in wget needs rewriting,
poll(..., seconds*1000) + read() would allow signal-less handling
of progressmeter and/or timeout. Not your fault, of course...

--
vda
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: inotifyd problems

2008-11-19 Thread Denys Vlasenko
On Tuesday 18 November 2008 18:33, Vladimir Dronnikov wrote:
> >
> > So we should implicitly add IN_IGNORED to the watching mask regardless the
> > user specified it on not. Then, after we have wait()ed for the agent, we
> > should check whether IN_IGNORED is in received event mask, and exit if it
> > is. Right?
> >
> 
> Denys, please, take a look. May be so: http://drvv.ru/busybox/inotifyd.patch?

inotifyd agent file

differs from 

inotifyd agent file1 file2

This is easy to fix.

Also I noticed two bugs:
- FIONREAD should take int* parameter, not ssize_t*
- unsigned mask = IN_ALL_EVENTS done just once,
  must be done before each file

I am applying this patch, please review.
--
vda
diff -d -urpN busybox.4/miscutils/inotifyd.c busybox.5/miscutils/inotifyd.c
--- busybox.4/miscutils/inotifyd.c	2008-11-17 23:03:17.0 +0100
+++ busybox.5/miscutils/inotifyd.c	2008-11-20 02:11:33.0 +0100
@@ -44,6 +44,7 @@ static const char mask_names[] ALIGN1 =
 	"D"	// 0x0400	Self was deleted
 	"M"	// 0x0800	Self was moved
 	"\0"	// 0x1000   (unused)
+	// Kernel events, always reported:
 	"u"	// 0x2000   Backing fs was unmounted
 	"o"	// 0x4000   Event queued overflowed
 	"x"	// 0x8000   File is no longer watched (usually deleted)
@@ -56,27 +57,38 @@ extern int inotify_init(void);
 extern int inotify_add_watch(int fd, const char *path, uint32_t mask);
 
 int inotifyd_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
-int inotifyd_main(int argc UNUSED_PARAM, char **argv)
+int inotifyd_main(int argc, char **argv)
 {
 	int n;
-	unsigned mask = IN_ALL_EVENTS; // assume we want all events
+	unsigned mask;
 	struct pollfd pfd;
-	char **watched = ++argv; // watched name list
-	const char *args[] = { *argv, NULL, NULL, NULL, NULL };
+	char **watches; // names of files being watched
+	const char *args[5];
 
 	// sanity check: agent and at least one watch must be given
-	if (!argv[0] || !argv[1])
+	if (!argv[1] || !argv[2])
 		bb_show_usage();
 
+	argv++;
+	// inotify_add_watch will number watched files
+	// starting from 1, thus watches[0] is unimportant,
+	// and 1st file name is watches[1].
+	watches = argv;
+	args[0] = *argv;
+	args[4] = NULL;
+	argc -= 2; // number of files we watch
+
 	// open inotify
 	pfd.fd = inotify_init();
 	if (pfd.fd < 0)
 		bb_perror_msg_and_die("no kernel support");
 
-	// setup watched
+	// setup watches
 	while (*++argv) {
 		char *path = *argv;
 		char *masks = strchr(path, ':');
+
+		mask = 0x0fff; // assuming we want all non-kernel events
 		// if mask is specified ->
 		if (masks) {
 			*masks = '\0'; // split path and mask
@@ -102,10 +114,9 @@ int inotifyd_main(int argc UNUSED_PARAM,
 	// do watch
 	pfd.events = POLLIN;
 	while (1) {
-		ssize_t len;
+		int len;
 		void *buf;
 		struct inotify_event *ie;
-
  again:
 		if (bb_got_signal)
 			break;
@@ -124,6 +135,7 @@ int inotifyd_main(int argc UNUSED_PARAM,
 			break;
 
 		// read out all pending events
+		// (NB: len must be int, not ssize_t or long!)
 		xioctl(pfd.fd, FIONREAD, &len);
 #define eventbuf bb_common_bufsiz1
 		ie = buf = (len <= sizeof(eventbuf)) ? eventbuf : xmalloc(len);
@@ -142,11 +154,15 @@ int inotifyd_main(int argc UNUSED_PARAM,
 }
 *s = '\0';
 //bb_error_msg("exec %s %08X\t%s\t%s\t%s", args[0],
-//	ie->mask, events, watched[ie->wd], ie->len ? ie->name : "");
+//	ie->mask, events, watches[ie->wd], ie->len ? ie->name : "");
 args[1] = events;
-args[2] = watched[ie->wd];
+args[2] = watches[ie->wd];
 args[3] = ie->len ? ie->name : NULL;
 wait4pid(xspawn((char **)args));
+// we are done if all files got final x event
+if (ie->mask & 0x8000)
+	if (--argc <= 0)
+		goto done;
 			}
 			// next event
 			i = sizeof(struct inotify_event) + ie->len;
@@ -155,7 +171,7 @@ int inotifyd_main(int argc UNUSED_PARAM,
 		}
 		if (eventbuf != buf)
 			free(buf);
-	}
-
-	return EXIT_SUCCESS;
+	} // while (1)
+ done:
+	return bb_got_signal;
 }
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox

[Fwd: Re: dpkg version comparison bug]

2008-11-19 Thread Eugene T. Bordenkircher

Helps to hit Reply all rather than Reply

---
Hopefully this works better.

Eugene

Denys Vlasenko wrote:

On Wednesday 19 November 2008 22:54, Eugene T. Bordenkircher wrote:

Hello all,

Below, you'll find a patch against the current SVN head to fix a couple of bugs 
in the version comparison code for dpkg. As a brief explanation: (1) the old 
code did not handle epochs that were greater than a single digit, and (2) it 
did not compare alpha() portions of the version string correctly, most notably 
portions that included ~'s and other punctuation.


You'll notice that the solution is almost a mirror image of the official code 
in dpkg.  I looked at it and couldn't think of any better way than that to do 
the comparison.  I added the copyright information at the top to make it official.


So it correctly compares versions now and probably more importantly to some:

text   data bss dec hex filename
  688420   21689388  699976   aae48 busybox.orig/busybox
  688273   21689388  699829   aadb5 busybox.new/busybox

Enjoy, and let me know if there is anything I missed or need to do a bit 
differently.


Patch appears to be corrupted:

# patch -p1 


--
Eugene T. Bordenkircher
[EMAIL PROTECTED]

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIXwV3dDGWbBTETf8RAhvKAJ9EAwNxecoKh/cgToujZO+DmOv6GACeO0Jr
W+jn2V1RjJeVq9YsuBGJuJg=
=RS4u
-END PGP SIGNATURE-


--
Eugene T. Bordenkircher
[EMAIL PROTECTED]

-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.6 (GNU/Linux)

iD8DBQFIXwV3dDGWbBTETf8RAhvKAJ9EAwNxecoKh/cgToujZO+DmOv6GACeO0Jr
W+jn2V1RjJeVq9YsuBGJuJg=
=RS4u
-END PGP SIGNATURE-
--- busybox.orig/archival/dpkg.c	2008-11-19 12:48:29.0 -0800
+++ busybox.new/archival/dpkg.c	2008-11-19 12:56:43.0 -0800
@@ -6,6 +6,10 @@
  *  written by glenn mcgrath with the help of others
  *  copyright (c) 2001 by glenn mcgrath
  *
+ *  parts of the version comparison code is plucked from the real dpkg
+ *  application which is licensed GPLv2 and
+ *  copyright (c) 1995 Ian Jackson <[EMAIL PROTECTED]>
+ *
  *  started life as a busybox implementation of udpkg
  *
  * licensed under gplv2 or later, see file license in this tarball for details.
@@ -28,6 +32,8 @@
 #include 
 #include "unarchive.h"
 
+#include 
+
 /* note: if you vary hash_prime sizes be aware,
  * 1) tweaking these will have a big effect on how much memory this program uses.
  * 2) for computational efficiency these hash tables should be at least 20%
@@ -183,60 +189,41 @@
 	return probe_address;
 }
 
-/* Need to rethink version comparison, maybe the official dpkg has something i can use ? */
-static int version_compare_part(const char *version1, const char *version2)
+/* This code is taken from dpkg and was converted to a function to save
+ * a few bytes in the text section of busybox */
+static int order( char x )
 {
-	int upstream_len1 = 0;
-	int upstream_len2 = 0;
-	char *name1_char;
-	char *name2_char;
-	int len1 = 0;
-	int len2 = 0;
-	int tmp_int;
-	int ver_num1;
-	int ver_num2;
-
-	if (version1 == NULL) {
-		version1 = xstrdup("");
-	}
-	if (version2 == NULL) {
-		version2 = xstrdup("");
-	}
-	upstream_len1 = strlen(version1);
-	upstream_len2 = strlen(version2);
-
-	while ((len1 < upstream_len1) || (len2 < upstream_len2)) {
-		/* Compare non-digit section */
-		tmp_int = strcspn(&version1[len1], "0123456789");
-		name1_char = xstrndup(&version1[len1], tmp_int);
-		len1 += tmp_int;
-		tmp_int = strcspn(&version2[len2], "0123456789");
-		name2_char = xstrndup(&version2[len2], tmp_int);
-		len2 += tmp_int;
-		tmp_int = strcmp(name1_char, name2_char);
-		free(name1_char);
-		free(name2_char);
-		if (tmp_int != 0) {
-			return tmp_int;
-		}
-
-		/* Compare digits */
-		tmp_int = strspn(&version1[len1], "0123456789");
-		name1_char = xstrndup(&version1[len1], tmp_int);
-		len1 += tmp_int;
-		tmp_int = strspn(&version2[len2], "0123456789");
-		name2_char = xstrndup(&version2[len2], tmp_int);
-		len2 += tmp_int;
-		ver_num1 = atoi(name1_char);
-		ver_num2 = atoi(name2_char);
-		free(name1_char);
-		free(name2_char);
-		if (ver_num1 < ver_num2) {
-			return -1;
+	return ( x == '~' ? -1
+			 : isdigit(x) ? 0
+			 : !(x) ? 0
+			 : isalpha(x) ? x
+			 : x + 256 );
 		}
-		if (ver_num1 > ver_num2) {
-			return 1;
+
+/* This code is taken from dpkg and modified slightly to work with busybox */
+static int version_compare_part(const char *val, const char *ref)
+{
+	if (!val) val = "";
+	if (!ref) ref = "";
+
+	while (*val || *ref) {
+		int first_diff = 0;
+
+		while ( (*val && !isdigit(*val)) || (*ref && !isdigit(*ref)) ) {
+			int vc = order(*val), rc = order(*ref);
+			if (vc != rc) return vc - rc;
+			val++; ref++;
+		}
+
+		while ( *val == '0' ) val++;
+		while ( *ref == '0' ) ref++;
+		while (isdigit(*val) && isdigit(*ref)) {
+			if (!first_diff) first_diff = *val - *ref;
+			val++; ref++;
 		}
+		if (isdigit(*val)) return 1;
+		if (isdigit(*ref)) return -1;
+		if (first_diff

Re: klogd broken in 1.13.0?

2008-11-19 Thread Hamish Moffatt
On Thu, Nov 20, 2008 at 12:48:50AM +0100, Denys Vlasenko wrote:
> On Thursday 20 November 2008 00:41, Hamish Moffatt wrote:
> > On Wed, Nov 19, 2008 at 08:45:53AM +0100, Denys Vlasenko wrote:
> > > Does it help if you just add this one line?
> > > 
> > > /* "2 -- Read from the log." */
> > > n = klogctl(2, log_buffer + used, KLOGD_LOGBUF_SIZE-1 - 
> > > used);
> > > if (n < 0) {
> > > if (errno == EINTR)
> > > continue;
> > > syslog(LOG_ERR, "klogd: error %d in klogctl(2): 
> > > %m",
> > > errno);
> > > break;
> > > }
> > > +   log_buffer[used + n] = '\0';
> > 
> > Yes that works.
> 
> Minimal fix is here:
> 
> http://busybox.net/downloads/fixes-1.13.0/busybox-1.13.0-klogd.patch

It's working.

> and svn has a bit bigger fix (or shall I say "smaller" -
> code has shrank) is in svn.
> 
> Can you test svn version?

That works too.

thanks,
Hamish
-- 
Hamish Moffatt VK3SB <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: dpkg version comparison bug

2008-11-19 Thread Denys Vlasenko
On Wednesday 19 November 2008 22:54, Eugene T. Bordenkircher wrote:
> Hello all,
> 
> Below, you'll find a patch against the current SVN head to fix a couple of 
> bugs 
> in the version comparison code for dpkg. As a brief explanation: (1) the old 
> code did not handle epochs that were greater than a single digit, and (2) it 
> did not compare alpha() portions of the version string correctly, most 
> notably 
> portions that included ~'s and other punctuation.
> 
> You'll notice that the solution is almost a mirror image of the official code 
> in dpkg.  I looked at it and couldn't think of any better way than that to do 
> the comparison.  I added the copyright information at the top to make it 
> official.
> 
> So it correctly compares versions now and probably more importantly to some:
> 
> text data bss dec hex filename
>   688420 21689388  699976   aae48 busybox.orig/busybox
>   688273 21689388  699829   aadb5 busybox.new/busybox
> 
> Enjoy, and let me know if there is anything I missed or need to do a bit 
> differently.

Patch appears to be corrupted:

# patch -p1 http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: klogd broken in 1.13.0?

2008-11-19 Thread Denys Vlasenko
On Thursday 20 November 2008 00:41, Hamish Moffatt wrote:
> On Wed, Nov 19, 2008 at 08:45:53AM +0100, Denys Vlasenko wrote:
> > Does it help if you just add this one line?
> > 
> > /* "2 -- Read from the log." */
> > n = klogctl(2, log_buffer + used, KLOGD_LOGBUF_SIZE-1 - 
> > used);
> > if (n < 0) {
> > if (errno == EINTR)
> > continue;
> > syslog(LOG_ERR, "klogd: error %d in klogctl(2): %m",
> > errno);
> > break;
> > }
> > +   log_buffer[used + n] = '\0';
> 
> Yes that works.

Minimal fix is here:

http://busybox.net/downloads/fixes-1.13.0/busybox-1.13.0-klogd.patch

and svn has a bit bigger fix (or shall I say "smaller" -
code has shrank) is in svn.

Can you test svn version?

> > > http://busybox.net/cgi-bin/viewcvs.cgi/branches/busybox_1_13_stable/sysklogd/klogd.c?rev=23583&view=markup
> > Look at trunk, not branches/busybox_1_13_stable:
> > http://busybox.net/cgi-bin/viewcvs.cgi/trunk/busybox/sysklogd/klogd.c?rev=23583&view=markup
> 
> Looking at branches should work though?

Frankly, I don't know...
--
vda
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: klogd broken in 1.13.0?

2008-11-19 Thread Hamish Moffatt
On Wed, Nov 19, 2008 at 08:45:53AM +0100, Denys Vlasenko wrote:
> On Wednesday 19 November 2008 05:17, Hamish Moffatt wrote:
> > I just switched from busybox 1.11.2 to 1.13.0 for a project and now kernel 
> > message logging seems a bit busted. It starts ok but then goes wrong.
> > Application logging seems to work ok still (see the last 5 lines of this
> > example).
> > 
> > I backed out rev 23583 and now it works again.
> 
> Does it help if you just add this one line?
> 
> /* "2 -- Read from the log." */
> n = klogctl(2, log_buffer + used, KLOGD_LOGBUF_SIZE-1 - used);
> if (n < 0) {
> if (errno == EINTR)
> continue;
> syslog(LOG_ERR, "klogd: error %d in klogctl(2): %m",
> errno);
> break;
> }
> +   log_buffer[used + n] = '\0';

Yes that works.

> > http://busybox.net/cgi-bin/viewcvs.cgi/branches/busybox_1_13_stable/sysklogd/klogd.c?rev=23583&view=markup
> Look at trunk, not branches/busybox_1_13_stable:
> http://busybox.net/cgi-bin/viewcvs.cgi/trunk/busybox/sysklogd/klogd.c?rev=23583&view=markup

Looking at branches should work though?


thanks
Hamish
-- 
Hamish Moffatt VK3SB <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: inotifyd problems

2008-11-19 Thread Piotr Grudzinski
So I applied patches to inotifyd.c from SVN and can see the same problem. If 
the only event is IN_IGNORED
the 'goto done' will never be executed.


I tried it with BB 1.12.1.

  Always apply patches against current SVN unless the precise version is 
specified, Piotr. I should have told that, sorry.
  1.12.1 has no knowledge of IN_IGNORED.

  Please, try again current SVN?


  --
  Vladimir
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox

dpkg version comparison bug

2008-11-19 Thread Eugene T. Bordenkircher
Hello all,

Below, you'll find a patch against the current SVN head to fix a couple of bugs 
in the version comparison code for dpkg. As a brief explanation: (1) the old 
code did not handle epochs that were greater than a single digit, and (2) it 
did not compare alpha() portions of the version string correctly, most notably 
portions that included ~'s and other punctuation.

You'll notice that the solution is almost a mirror image of the official code 
in dpkg.  I looked at it and couldn't think of any better way than that to do 
the comparison.  I added the copyright information at the top to make it 
official.

So it correctly compares versions now and probably more importantly to some:

text   data bss dec hex filename
  688420   21689388  699976   aae48 busybox.orig/busybox
  688273   21689388  699829   aadb5 busybox.new/busybox

Enjoy, and let me know if there is anything I missed or need to do a bit 
differently.

-- 
Eugene T. Bordenkircher
[EMAIL PROTECTED] busybox.orig/archival/dpkg.c  2008-11-19 12:48:29.0 
-0800
+++ busybox.new/archival/dpkg.c 2008-11-19 12:56:43.0 -0800
@@ -6,6 +6,10 @@
   *  written by glenn mcgrath with the help of others
   *  copyright (c) 2001 by glenn mcgrath
   *
+ *  parts of the version comparison code is plucked from the real dpkg
+ *  application which is licensed GPLv2 and
+ *  copyright (c) 1995 Ian Jackson <[EMAIL PROTECTED]>
+ *
   *  started life as a busybox implementation of udpkg
   *
   * licensed under gplv2 or later, see file license in this tarball for 
details.
@@ -28,6 +32,8 @@
  #include 
  #include "unarchive.h"

+#include 
+
  /* note: if you vary hash_prime sizes be aware,
   * 1) tweaking these will have a big effect on how much memory this program 
uses.
   * 2) for computational efficiency these hash tables should be at least 20%
@@ -183,60 +189,41 @@
return probe_address;
  }

-/* Need to rethink version comparison, maybe the official dpkg has something i 
can use ? */
-static int version_compare_part(const char *version1, const char *version2)
+/* This code is taken from dpkg and was converted to a function to save
+ * a few bytes in the text section of busybox */
+static int order( char x )
  {
-   int upstream_len1 = 0;
-   int upstream_len2 = 0;
-   char *name1_char;
-   char *name2_char;
-   int len1 = 0;
-   int len2 = 0;
-   int tmp_int;
-   int ver_num1;
-   int ver_num2;
-
-   if (version1 == NULL) {
-   version1 = xstrdup("");
-   }
-   if (version2 == NULL) {
-   version2 = xstrdup("");
-   }
-   upstream_len1 = strlen(version1);
-   upstream_len2 = strlen(version2);
-
-   while ((len1 < upstream_len1) || (len2 < upstream_len2)) {
-   /* Compare non-digit section */
-   tmp_int = strcspn(&version1[len1], "0123456789");
-   name1_char = xstrndup(&version1[len1], tmp_int);
-   len1 += tmp_int;
-   tmp_int = strcspn(&version2[len2], "0123456789");
-   name2_char = xstrndup(&version2[len2], tmp_int);
-   len2 += tmp_int;
-   tmp_int = strcmp(name1_char, name2_char);
-   free(name1_char);
-   free(name2_char);
-   if (tmp_int != 0) {
-   return tmp_int;
-   }
-
-   /* Compare digits */
-   tmp_int = strspn(&version1[len1], "0123456789");
-   name1_char = xstrndup(&version1[len1], tmp_int);
-   len1 += tmp_int;
-   tmp_int = strspn(&version2[len2], "0123456789");
-   name2_char = xstrndup(&version2[len2], tmp_int);
-   len2 += tmp_int;
-   ver_num1 = atoi(name1_char);
-   ver_num2 = atoi(name2_char);
-   free(name1_char);
-   free(name2_char);
-   if (ver_num1 < ver_num2) {
-   return -1;
+   return ( x == '~' ? -1
+: isdigit(x) ? 0
+: !(x) ? 0
+: isalpha(x) ? x
+: x + 256 );
}
-   if (ver_num1 > ver_num2) {
-   return 1;
+
+/* This code is taken from dpkg and modified slightly to work with busybox */
+static int version_compare_part(const char *val, const char *ref)
+{
+   if (!val) val = "";
+   if (!ref) ref = "";
+
+   while (*val || *ref) {
+   int first_diff = 0;
+
+   while ( (*val && !isdigit(*val)) || (*ref && !isdigit(*ref)) ) {
+   int vc = order(*val), rc = order(*ref);
+   if (vc != rc) return vc - rc;
+   val++; ref++;
+   }
+
+   while ( *val == '0' ) val++;
+   while ( *ref == '0' ) ref++;
+   while (isdigit(*val) && isdigit(*ref)) {
+   

Re: inotifyd problems

2008-11-19 Thread Vladimir Dronnikov
>
> I tried it with BB 1.12.1.
>

Always apply patches against current SVN unless the precise version is
specified, Piotr. I should have told that, sorry.
1.12.1 has no knowledge of IN_IGNORED.

Please, try again current SVN?

--
Vladimir
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Re: inotifyd problems

2008-11-19 Thread Piotr Grudzinski
I tried it with BB 1.12.1. If the only event is IN_IGNORED (0x8000) the if(m) 
is false and 'goto done' is never executed.
On my system the agent program is always called with one event at a time.

Piotr


So we should implicitly add IN_IGNORED to the watching mask regardless the 
user specified it on not. Then, after we have wait()ed for the agent, we should 
check whether IN_IGNORED is in received event mask, and exit if it is. Right?

  Denys, please, take a look. May be so: http://drvv.ru/busybox/inotifyd.patch ?


--
Vladimir


___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Re: mysterious segfault with busybox 1.13.0 ash

2008-11-19 Thread Natanael Copa
On Wed, 2008-11-19 at 21:17 +0100, Natanael Copa wrote:
> On Wed, 2008-11-19 at 21:11 +0100, Natanael Copa wrote:
> 
> > 
> > interestingly enough, this happens only on a grsecurity kernel, but not
> > on a default gentoo kernel (in chroot). tested in kvm only so far.
> 
> my bad. it does segfault on my desktop too with a normal gentoo kernel.
> 
> shorter testcase:
> 
> ash -c "foo() { ! false && echo foo; }; foo"
> 
> -nc

and gdb output:

(gdb) run
Starting program: /busybox/busybox-1.13.0/busybox_unstripped ash -c "foo() { ! 
false && echo foo;} ; foo"

Program received signal SIGSEGV, Segmentation fault.
0x080a9278 in evaltree (n=Cannot access memory at address 0xff177f5c
) at shell/ash.c:7904
7904{
(gdb) bt
#0  0x080a9278 in evaltree (n=Cannot access memory at address 0xff177f5c
) at shell/ash.c:7904
#1  0x080a9316 in evaltree (n=0x8188a44, flags=134910742) at shell/ash.c:7940
#2  0x080a9316 in evaltree (n=0x8188a44, flags=134910742) at shell/ash.c:7940
#3  0x080a9316 in evaltree (n=0x8188a44, flags=134910742) at shell/ash.c:7940
...
#10474 0x080a9316 in evaltree (n=0x8188a44, flags=134910742)
at shell/ash.c:7940

etc...


I think that should point you in right direction. Looks like a recursive func 
that is going bad.

-nc

___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: mysterious segfault with busybox 1.13.0 ash

2008-11-19 Thread Natanael Copa
On Wed, 2008-11-19 at 21:11 +0100, Natanael Copa wrote:

> 
> interestingly enough, this happens only on a grsecurity kernel, but not
> on a default gentoo kernel (in chroot). tested in kvm only so far.

my bad. it does segfault on my desktop too with a normal gentoo kernel.

shorter testcase:

ash -c "foo() { ! false && echo foo; }; foo"

-nc

___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: mysterious segfault with busybox 1.13.0 ash

2008-11-19 Thread Natanael Copa
On Wed, 2008-11-19 at 20:57 +0100, Natanael Copa wrote:
> Hi,
> 
> I have not been able to reproduce it in a small test script but it
> happens exactly here:
> http://dev.alpinelinux.org/cgit/cgit.cgi/alpine-baselayout/tree/init.d/runtimes#n178

...

Actually, I was able to create a smaller test script immediatly after i
posted the previous mail:

#!/bin/sh

func() {
! false && echo foo
}

! false && echo "no problem"
func


it will echo "no problem" and then segfault.

interestingly enough, this happens only on a grsecurity kernel, but not
on a default gentoo kernel (in chroot). tested in kvm only so far.

-nc

___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


mysterious segfault with busybox 1.13.0 ash

2008-11-19 Thread Natanael Copa
Hi,

I have not been able to reproduce it in a small test script but it
happens exactly here:
http://dev.alpinelinux.org/cgit/cgit.cgi/alpine-baselayout/tree/init.d/runtimes#n178

row 178.

I suspect it is related to the ! operator. If I insert:

! false && echo foo

the script will segfault and no "foo" will be echoed.

If i insert:

false || echo foo

the "foo" will be echoed and ash segfaults, at the "if ! tar ..."

Unfortunally, I'm not able to reproduce in a smaller script.

ideas on how to narrow it down?

-nc

___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: shell script implementation of man

2008-11-19 Thread Matthew Hiles
On Wed, Nov 19, 2008 at 1:11 PM, Cathey, Jim <[EMAIL PROTECTED]> wrote:
> One more optimization it needs, it should check
> to see that stdout is a tty and only run the
> pager if it is, else cat.  ("man foo >foofile")
> -- Jim

hm.. well the easiest way to code this in is to add a line after the
line that checks to see if PAGER is set. I.E.

[ -z $PAGER ] && PAGER=less
tty -s <&1 || PAGER=cat
#okay, found the page, try decompressing and displaying


Admittedly it's not the efficient way, but it was the first thing that
popped into my head.
~Matthew Hiles
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: shell script implementation of man

2008-11-19 Thread Paul Smith
On Wed, 2008-11-19 at 19:12 +0100, Yann E. MORIN wrote:
> What makes you say it's /far more portable than $()/ ?

Just because there are still shells out there that don't implement $()
(msh in busybox is one example, but also IIRC the Solaris /bin/sh falls
into this category).

___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


RE: shell script implementation of man

2008-11-19 Thread Cathey, Jim
>What makes you say it's /far more portable than $()/ ?
>Is that because $() was introduced after `` (if so is the case)?

It is the case.  Every shell I've ever heard of does ``, the $()
thing showed up with the Korn shell and got propagated into various
other shells.  I believe `` is more widely supported, and for a
maximally portable shell script (which admittedly this does not
need to be) is thus superior wherever it will do the job.  If
one of BB's own shells doesn't support $() then that right away
tells you which style to prefer for this script.

-- Jim




___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: shell script implementation of man

2008-11-19 Thread Yann E. MORIN
Paul,
All,

On Wednesday 19 November 2008 18:28:33 Paul Smith wrote:
> On Wed, 2008-11-19 at 18:01 +0100, Yann E. MORIN wrote:
> > Do not forget that back-ticks are not POSIX, while $() is.
> Uh... what?!?!  That's absolutely not true.  Backticks are
> unquestionably defined in the POSIX sh definition.  They are not marked
> as "old" or "deprecated" or anything similar.

Woops... Sorry... I was too quick and didn't check. I thought I read that
somewhere, but couldn't find it again. I just checked with:
http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02
and you're right.

Next time, I won't trust my memory without checking first. Sorry.

> It's easier to nest command substitutions with $() and there is a very
> slight difference in handling backslashes, but otherwise there is no
> difference between them.

Yes.

> > Even bash considers the use of back-ticks (backquotes) to
> > be /old-style/.
> They don't mean it in a pejorative sense. They just mean it as a 
> description: it _IS_ old-style.  But that doesn't make backticks wrong
> or bad or to be avoided.  Full quote:
> When the old-style backquote form of substitution is used, ...

I didn't mean it was pejorative. I was just using /old-style/ as quoting
the bash manual.

> Since `` is perfectly standards-compliant AND it's far more portable
> than $(),

What makes you say it's /far more portable than $()/ ? Is that because $()
was introduced after `` (if so is the case)?

> I don't see any reason to avoid `` except as a matter of 
> style.

Right. I do apologise.

Regards,
Yann E. MORIN.

-- 
.-..--..
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +0/33 662376056 | Software  Designer | \ / CAMPAIGN |  ___   |
| --==< ^_^ >==-- `.---:  X  AGAINST  |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL|   v   conspiracy.  |
`--^---^--^'

___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


RE: shell script implementation of man

2008-11-19 Thread Cathey, Jim
>if someone were lacking less and more they can just set PAGER to
>cat a viola, lots of scrolling.

With viola you get lots of screeching!  :-)

You can even have a PAGER-less run find
its own hierarchy of less/more/cat for them,
et voila, perfect script!

One more optimization it needs, it should check
to see that stdout is a tty and only run the
pager if it is, else cat.  ("man foo >foofile")

Once upon a time in a career far away we had a
shell-script man, before it got rewritten in C
to handle running nroff if necessary, and handling
remote server man pages and the like.  It did the
usual catman stuff, too.  (The network wasn't tcp/ip,
though, it was DNET.  Extra points for ever having
heard of it, or naming the country of origin.)

-- Jim




___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: shell script implementation of man

2008-11-19 Thread Matthew Hiles
 On Wed, Nov 19, 2008 at 12:13 PM, Cathey, Jim <[EMAIL PROTECTED]> wrote:
> I believe it is customary to use an environment
> variable PAGER to allow overriding of less (or
> more, or whatever the system default is).  In ksh-speak:
>
> case $pagefile in
> *.bz2)
>bzcat $pagefile | ${PAGER:-less} ;;
> *.gz)
>zcat $pagefile | ${PAGER:-less} ;;
> *)
>${PAGER:-less} $pagefile ;;
> esac
>
> -- Jim
>


Ah, I forgot about the PAGER variable. Good catch :D.
Doesn't seem like msh and bb's sh have the nice default value
expansion like ksh and bash have. The following works just as well
though:

[ -z $PAGER ] && PAGER=less
#okay, found the page, try decompressing and displaying
case $pagefile in
*.bz2)
   bzcat $pagefile | $PAGER ;;
*.gz)
   zcat $pagefile | $PAGER ;;
*)
   $PAGER $pagefile ;;
esac
and if someone were lacking less and more they can just set PAGER to
cat a viola, lots of scrolling.

~Matthew Hiles
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: shell script implementation of man

2008-11-19 Thread Paul Smith
On Wed, 2008-11-19 at 18:01 +0100, Yann E. MORIN wrote:
> Do not forget that back-ticks are not POSIX, while $() is.

Uh... what?!?!  That's absolutely not true.  Backticks are
unquestionably defined in the POSIX sh definition.  They are not marked
as "old" or "deprecated" or anything similar.

It's easier to nest command substitutions with $() and there is a very
slight difference in handling backslashes, but otherwise there is no
difference between them.

> Even bash considers the use of back-ticks (backquotes) to
> be /old-style/.

They don't mean it in a pejorative sense.  They just mean it as a
description: it _IS_ old-style.  But that doesn't make backticks wrong
or bad or to be avoided.  Full quote:

When the old-style backquote form of substitution is used, ...

> I'd say that such shell scripts should be POSIX compliant. That sure
> rules out non-POSIX shells, but is standards-compliant.

Since `` is perfectly standards-compliant AND it's far more portable
than $(), I don't see any reason to avoid `` except as a matter of
style.

___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: shell script implementation of man

2008-11-19 Thread Yann E. MORIN
Hello Matthew!
Hello all!

On Wednesday 19 November 2008 16:58:15 Matthew Hiles wrote:
> msh does not appear to support
> $() style command substitution, it does support backticks. I've
> changed the script and it appears to work with msh without any issues.

Do not forget that back-ticks are not POSIX, while $() is. Even bash
considers the use of back-ticks (backquotes) to be /old-style/.

I'd say that such shell scripts should be POSIX compliant. That sure
rules out non-POSIX shells, but is standards-compliant.

My 2 cents.

Regards,
Yann E. MORIN.

-- 
.-..--..
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +0/33 662376056 | Software  Designer | \ / CAMPAIGN |  ___   |
| --==< ^_^ >==-- `.---:  X  AGAINST  |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL|   v   conspiracy.  |
`--^---^--^'

___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


RE: shell script implementation of man

2008-11-19 Thread Cathey, Jim
I believe it is customary to use an environment
variable PAGER to allow overriding of less (or
more, or whatever the system default is).  In ksh-speak:

case $pagefile in
*.bz2)
bzcat $pagefile | ${PAGER:-less} ;;
*.gz)
zcat $pagefile | ${PAGER:-less} ;;
*)
${PAGER:-less} $pagefile ;;
esac

-- Jim




___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: shell script implementation of man

2008-11-19 Thread Matthew Hiles
On Wed, Nov 19, 2008 at 12:01 PM, Yann E. MORIN
<[EMAIL PROTECTED]> wrote:
> Hello Matthew!
> Hello all!
>
> On Wednesday 19 November 2008 16:58:15 Matthew Hiles wrote:
>> msh does not appear to support
>> $() style command substitution, it does support backticks. I've
>> changed the script and it appears to work with msh without any issues.
>
> Do not forget that back-ticks are not POSIX, while $() is. Even bash
> considers the use of back-ticks (backquotes) to be /old-style/.
>
> I'd say that such shell scripts should be POSIX compliant. That sure
> rules out non-POSIX shells, but is standards-compliant.
>
> My 2 cents.
>
> Regards,
> Yann E. MORIN.
>
> --
> .-..--..
> |  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' 
> conspiracy: |
> | +0/33 662376056 | Software  Designer | \ / CAMPAIGN |  ___  
>  |
> | --==< ^_^ >==-- `.---:  X  AGAINST  |  \e/  There is no 
>  |
> | http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL|   v   conspiracy. 
>  |
> `--^---^--^'
>
>

I agree about preferring $() over backticks, but msh doesn't like $()
and does like backticks. Remember, this man script is meant to be an
extra for busybox. I don't see it being used without busybox and thus
busybox compatibility is my priority.  I suppose the best thing to do
is add support for $() in msh. Anyone else care to comment?

~Matthew Hiles
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: shell script implementation of man

2008-11-19 Thread Matthew Hiles
I'll address all the replies at once.

> I assume that you did not see miscutils/man.c, i fear.

It appears man.c is for nroff files.  This is a smaller, simpler
implementation meant to answer the request in the TODO.  :D


> Did you test this with msh ?

The first version I posted, I did not. msh does not appear to support
$() style command substitution, it does support backticks. I've
changed the script and it appears to work with msh without any issues.


> Native French speaking: you could handle LANG and/or -L option (maybe
 not) !

I will try, but later.


>This should default to /usr/share/man

Fixed.


So here's the updated version:

#!/bin/sh

# man - a simple man program for ASCII pages
# Copyright (c) 2008 Matthew Hiles
#
# Licensed under GPLv2 or later, see file LICENSE in this tarball for details.

## requires: find, head, sort, tr, grep/egrep, and less
## optional: zcat, bzcat

#check to see if MANPATH is set and show warning if not
if [ -z "$MANPATH" ]; then
echo "Warning: MANPATH is not set, assuming /usr/share/man." >&2
MANPATH=/usr/share/man
fi

case $# in
1)
pagearg=$1 ;;
2)
section=man$1
pagearg=$2 ;;
*)
echo "Usage: man [section] "
exit
esac

paths=`echo "$MANPATH" | tr ":" " "`
pagefile=`find $paths | grep "/$section" | grep "/$pagearg\." | sort | head -n1`

if [ -z $pagefile ]; then
echo -n No manual entry for $pagearg
[ $section ] && echo -n " in section $1 of the manual."
echo
exit
fi

#okay, found the page, try decompressing and displaying
case $pagefile in
*.bz2)
bzcat $pagefile | less ;;
*.gz)
zcat $pagefile | less ;;
*)
less $pagefile ;;
esac

#cleanup, just incase
paths=
pagefile=
pagearg=
section=
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: shell script implementation of man

2008-11-19 Thread Bernhard Reutner-Fischer
On Wed, Nov 19, 2008 at 09:15:51AM -0500, Matthew Hiles wrote:
>So I saw this in the TODO file:
>
>>man
>>  It would be nice to have a man command.  Not one that handles troff or
>>  anything, just one that can handle preformatted ascii man pages, possibly
>>  compressed.  This could probably be a script in the extras directory that
>>  calls cat/zcat/bzcat | less
>>
>>  (How doclifter might work into this is anybody's guess.)
>
>
>So here is my first test version. I've verified it works with busybox 1.13.
>Obviously it can be trimmed down some to save space and needs proper
>legal wordage.

the proper legal wording can be found in any file, like (preferably):
/*
 * foo - describe what foo does
 * Copyright (c) 2008 Your Name
 *
 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
 */


I assume that you did not see miscutils/man.c, i fear.

>#!/bin/sh
>
>## man - a simple man program for busybox
>##   this does NOT handle nroff pages,
>##   only simple asii pages

s/asii/ascii/
>
>## Copyright (c) 2008, Matthew Hiles, insert proper busybox license here.
>
>## requires: find, head, sort, tr, grep/egrep, and less
>## optional: zcat, bzcat
>
>#check to see if MANPATH is set and show warning if not
>
>if [ -z $MANPATH ]; then
>echo "Warning: MANPATH is not set, assuming /usr/local/man." >&2

This should default to /usr/share/man

>MANPATH=/usr/local/man
>fi
>
>case $# in
>1)

Did you test this with msh ?
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: shell script implementation of man

2008-11-19 Thread Vladimir Dronnikov
I think there is a bunch of such useful scripts. They are smaller than their
C implementation and are extremely useful. The question still exists where
to place them in the building tree?

Regards,
--
Vladimir
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Re: shell script implementation of man

2008-11-19 Thread Loïc Grenié
2008/11/19, Matthew Hiles <[EMAIL PROTECTED]>:
> So I saw this in the TODO file:
>
>  >man
>  >  It would be nice to have a man command.  Not one that handles troff or
>  >  anything, just one that can handle preformatted ascii man pages, possibly
>  >  compressed.  This could probably be a script in the extras directory that
>  >  calls cat/zcat/bzcat | less
>  >
>  >  (How doclifter might work into this is anybody's guess.)
>
>
>  So here is my first test version. I've verified it works with busybox 1.13.
>  Obviously it can be trimmed down some to save space and needs proper
>  legal wordage.

Native French speaking: you could handle LANG and/or -L option (maybe
  not) !

As for /usr/local/man, I suggest using a DEFAULT_MANPATH
  variable (or whatever name you wish to use) as follows:

DEFAULT_MANPATH=/usr/local/man

if [ -z "$MANPATH" ]; then
   echo "Warning: MANPATH is not set, assuming $DEFAULT_MANPATH." >&2
   MANPATH="$DEFAULT_MANPATH"
fi

  Additionally, I think it would be better to put quotes around $MANPATH.

  Cheers,

Loïc
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


shell script implementation of man

2008-11-19 Thread Matthew Hiles
So I saw this in the TODO file:

>man
>  It would be nice to have a man command.  Not one that handles troff or
>  anything, just one that can handle preformatted ascii man pages, possibly
>  compressed.  This could probably be a script in the extras directory that
>  calls cat/zcat/bzcat | less
>
>  (How doclifter might work into this is anybody's guess.)


So here is my first test version. I've verified it works with busybox 1.13.
Obviously it can be trimmed down some to save space and needs proper
legal wordage.

#!/bin/sh

## man - a simple man program for busybox
##   this does NOT handle nroff pages,
##   only simple asii pages

## Copyright (c) 2008, Matthew Hiles, insert proper busybox license here.

## requires: find, head, sort, tr, grep/egrep, and less
## optional: zcat, bzcat

#check to see if MANPATH is set and show warning if not

if [ -z $MANPATH ]; then
echo "Warning: MANPATH is not set, assuming /usr/local/man." >&2
MANPATH=/usr/local/man
fi

case $# in
1)
pagearg=$1 ;;
2)
section=man$1
pagearg=$2 ;;
*)
echo "Usage: man [section] "
exit
esac

pagefile=$( find $( echo "$MANPATH" | tr ":" " "  ) | grep "/$section"
| grep "/$pagearg\." | sort | head -n1 )

if [ -z $pagefile ]; then
echo -n No manual entry for $pagearg
[ $section ] && echo -n " in section $1 of the manual."
echo
exit
fi

#okay, found the page, try decompressing and displaying
case $pagefile in
*.bz2)
bzcat $pagefile | less ;;
*.gz)
zcat $pagefile | less ;;
*)
less $pagefile ;;
esac
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


Re: old vi bug still alive ...

2008-11-19 Thread Denys Vlasenko
On Tue, Nov 18, 2008 at 7:48 PM, walter harms <[EMAIL PROTECTED]> wrote:
> hi list,
> i was trying the lasted vi and found the old bug i found in this summer still 
> alive.
>
> how to reproduce
> *compile vi with ENABLE_FEATURE_VI_SETOPTS
> *start vi
> *choose insert mode
> *type 
> use clip&paste to repeat that often
> vi will intend the line to the right.
> after some time vi crashes in this line
>
>for (; isblank(*q); q++) {
>
> q is the start of the previous line
>q = prev_line(p);
>
> but the results in the debugger are confusing
> (gdb)  p p
> $37 = 0xb7cc8805 "\t\n"
> (gdb)  p prev_line(p)
> $38 = 0xb7cc7dcf ' ' ...
> (gdb) p q
> $39 = 0x81afa14 
>
> i added a printf to see what happens to the pointer.
> here the results of the last round:

Well, the code is:

for (; isblank(*q); q++) {
p = stupid_insert(p, *q);
}

and stupid_insert() might reallocate text[] (!),
after which q points nowhere.

Lots and lots of places in vi.c do not expect that to happen.
(Because vi.c was so stupid it did not even allow for
significantly growing files until recently!)

Does attached patch help?
--
vda
diff -d -urpN busybox.4/editors/vi.c busybox.5/editors/vi.c
--- busybox.4/editors/vi.c	2008-11-05 14:19:38.0 +0100
+++ busybox.5/editors/vi.c	2008-11-19 14:10:51.0 +0100
@@ -300,13 +300,17 @@ static void dot_delete(void);	// delete 
 static char *bound_dot(char *);	// make sure  text[0] <= P < "end"
 static char *new_screen(int, int);	// malloc virtual screen memory
 static char *char_insert(char *, char);	// insert the char c at 'p'
-static char *stupid_insert(char *, char);	// stupidly insert the char c at 'p'
+// might reallocate text[]! use p += stupid_insert(p, ...),
+// and be careful to not use pointers into potentially freed text[]!
+static uintptr_t stupid_insert(char *, char);	// stupidly insert the char c at 'p'
 static int find_range(char **, char **, char);	// return pointers for an object
 static int st_test(char *, int, int, char *);	// helper for skip_thing()
 static char *skip_thing(char *, int, int, int);	// skip some object
 static char *find_pair(char *, char);	// find matching pair ()  []  {}
 static char *text_hole_delete(char *, char *);	// at "p", delete a 'size' byte hole
-static char *text_hole_make(char *, int);	// at "p", make a 'size' byte hole
+// might reallocate text[]! use p += text_hole_make(p, ...),
+// and be careful to not use pointers into potentially freed text[]!
+static uintptr_t text_hole_make(char *, int);	// at "p", make a 'size' byte hole
 static char *yank_delete(char *, char *, int, int);	// yank text[] into register then delete
 static void show_help(void);	// display some help info
 static void rawmode(void);	// set "raw" mode on tty
@@ -316,11 +320,11 @@ static int mysleep(int);
 static int readit(void);	// read (maybe cursor) key from stdin
 static int get_one_char(void);	// read 1 char from stdin
 static int file_size(const char *);   // what is the byte size of "fn"
-#if ENABLE_FEATURE_VI_READONLY
-static int file_insert(const char *, char *, int);
-#else
-static int file_insert(const char *, char *);
+#if !ENABLE_FEATURE_VI_READONLY
+#define file_insert(fn, p, update_ro_status) file_insert(fn, p)
 #endif
+// file_insert might reallocate text[]!
+static int file_insert(const char *, char *, int);
 static int file_write(char *, char *, char *);
 #if !ENABLE_FEATURE_VI_OPTIMIZE_CURSOR
 #define place_cursor(a, b, optimize) place_cursor(a, b)
@@ -370,7 +374,9 @@ static void end_cmd_q(void);	// stop sav
 static void showmatching(char *);	// show the matching pair ()  []  {}
 #endif
 #if ENABLE_FEATURE_VI_YANKMARK || (ENABLE_FEATURE_VI_COLON && ENABLE_FEATURE_VI_SEARCH) || ENABLE_FEATURE_VI_CRASHME
-static char *string_insert(char *, char *);	// insert the string at 'p'
+// might reallocate text[]! use p += string_insert(p, ...),
+// and be careful to not use pointers into potentially freed text[]!
+static uintptr_t string_insert(char *, const char *);	// insert the string at 'p'
 #endif
 #if ENABLE_FEATURE_VI_YANKMARK
 static char *text_yank(char *, char *, int);	// save copy of "p" into a register
@@ -486,8 +492,7 @@ static int init_text_buffer(char *fn)
 		char_insert(text, '\n');
 		rc = 0;
 	} else {
-		rc = file_insert(fn, text
-			USE_FEATURE_VI_READONLY(, 1));
+		rc = file_insert(fn, text, 1);
 	}
 	file_modified = 0;
 	last_file_modified = -1;
@@ -584,7 +589,8 @@ static void edit_file(char *fn)
 crash_dummy();	// generate a random command
 			} else {
 crashme = 0;
-dot = string_insert(text, "\n\n#  Ran out of text to work on.  #\n\n"); // insert the string
+string_insert(text, "\n\n#  Ran out of text to work on.  #\n\n"); // insert the string
+dot = text;
 refresh(FALSE);
 			}
 		}
@@ -976,7 +982,11 @@ static void colon(char *buf)
 		// read after current line- unless user said ":0r foo"
 		if (b != 0)
 			q = next_line(q);
-		ch = file_insert(fn, q  USE_FEATURE_VI_READONLY(, 0));
+

Re: Add megabytes display format to free

2008-11-19 Thread Matthew Hiles
On Tue, Nov 18, 2008 at 4:47 PM, Bernhard Reutner-Fischer
<[EMAIL PROTECTED]> wrote:
> On Tue, Nov 18, 2008 at 10:06:47PM +0100, Tito wrote:
>>On Tuesday 18 November 2008 20:01:59 Matthew Hiles wrote:
>>> Hello Busybox mailing list:
>>>
>>> I just joined the mailing list because I'm interested in helping out
>>> with busybox.
>>>
>>> I've been reading TODOs and the bug tracker to find out what I can do.
>
> we have a TODO in the toplevel directory. Worth a read :)
>
>>> I'm not sure how opposed everyone is to feature creep, as I'm sure
>>> it's an issue, but one thing that always bothered me when using a
>>> busybox system was the lack of the -m option for free.
>>>
>>> I also checked out the TODO in free about fixing the integer overflow
>>> on systems with >4gb of RAM. I tried busybox's free command on a 6 GB
>>> system and it did not overflow--it showed exactly the same output as
>>> the in-distro free command. Does anyone know what's up with that?
>>>
>>> The following patch allows free to display in megabytes.
>>>
>>>
>>> --- procps/free.c2008-11-18 09:08:29.0 -0500
>>> +++ procps/free.c2008-11-18 08:06:16.0 -0500
>>> @@ -46,8 +46,21 @@
>>>  info.bufferram*=info.mem_unit;
>>>  }
>>>
>>> -if (argc > 1 && *argv[1] == '-')
>>> -bb_show_usage();
>>> +if ( argc > 1 )
>>> +{
>>> +if ( argv[1][1] == 'm' ) /* I see no point invoking getopt */
>>> +{/* or even strcmp for one option */
>>> +/* give output in megabytes */
>>> +info.totalram /= 1024;
>>> +info.freeram /= 1024;
>>> +info.sharedram /= 1024;
>>> +info.bufferram /= 1024;
>>> +#ifndef __uClinux__
>>> +info.totalswap /= 1024;
>>> +info.freeswap /= 1024;
>>> +#endif
>>> +} else bb_show_usage();
>>> +}
>>>
>>>  printf("%6s%13s%13s%13s%13s%13s\n", "", "total", "used", "free",
>>>  "shared", "buffers");
>>
>>Hi,
>>you should add -m also to the help text in busybox/include/usage.h
>
> and also post the size(1) output from before and after your patch or
> ./scripts/bloat-o-meter.
>
> Let me note that we have make_human_readable_str()
>
> cheers,
> Bernhard
>

Output of bloat-o-meter:

./scripts/bloat-o-meter  ../orig_bb/busybox-1.13.0/busybox_unstripped
busybox_unstripped
function old new   delta
free_main383 416 +33
--
(add/remove: 0/0 grow/shrink: 1/0 up/down: 33/0)


I don't think 33 bytes is too bad, no?

Here's the usage.h patch:

--- usage.h2008-11-08 16:38:23.0 -0500
+++ usage.h2008-11-18 16:35:36.723676970 -0500
@@ -1182,7 +1182,7 @@
#define free_trivial_usage \
  ""
#define free_full_usage "\n\n" \
-   "Display the amount of free and used system memory"
+   "Display the amount of free and used system memory. Add -m to
display in megabytes."
#define free_example_usage \
  "$ free\n" \
  "  total used free   shared
buffers\n" \



Regarding this:
> Let me note that we have make_human_readable_str()

Thanks, I didn't know that and it's nice to know (is there some
well-organized, elaborated documentation on libbb and it's functions
somewhere?), however I have to argue against its use in this case.
The only ways I can see using it would make the free command a lot
bigger unnecessarily. The printf()s would have to be changed or the
returned string of make_human_readable_str() would have to be modified
then converted back to an int. If someone can suggest a better way,
I'd love to learn how.

Cheers,
Matthew

Oh yeah, and about the top level TODO. I've completed one of them and
am currently testing. :D
___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox


[Fwd: [alpine-devel] fdisk segmentation fault]

2008-11-19 Thread Natanael Copa
I'm forwarding this. He has busybox-1.12.1 and as far i can see there
are no fixes for fdisk for 1.12.1 or 1.12.2

the following config options might be of interest:
CONFIG_LFS=y
CONFIG_FDISK=y
CONFIG_FDISK_SUPPORT_LARGE_DISKS=y
CONFIG_FEATURE_FDISK_WRITABLE=y
CONFIG_FEATURE_FDISK_ADVANCED=y

thanks!

 Forwarded Message 
> From: Ted Trask <[EMAIL PROTECTED]>
> To: Alpine Developers <[EMAIL PROTECTED]>
> Subject: [alpine-devel] fdisk segmentation fault
> Date: Tue, 18 Nov 2008 14:04:57 -0800 (PST)
> 
> I'm running alpine-linux-1.7.24.
> 
> I have one 750 GB SATA hard-drive installed on my system.  When I run
> fdisk /dev/sda I get a warning about having more than 1024 cylinders
> (there are 91201) and then a Segmentation fault.
> 
> Running fdisk -l shows 
> 
> Disk /dev/sda: 750.1 GB, 750156374016 bytes
> 255 heads, 63 sectors/track, 91201 cylinders
> Units = cylinders of 16065 * 512 = 8225280 bytes
> 
>Device Boot  Start End  Blocks Id System
> /dev/sda1  1  91202732571648  7 HPFS/NTFS
> 
> Any idea why I get a segmentation fault?  Seems like a bug in busybox to me.
> 
> Ted Trask


___
busybox mailing list
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox