Re: [PATCH] Add a gzip fastpath for the xmalloc readers, v3

2014-12-07 Thread Lauri Kasanen
On Sun, Dec 7, 2014, at 01:51, Denys Vlasenko wrote:
  It misses the plus one zero byte behavior of the non-compressed path
  (xmalloc_read). I bet some callers depend on it, using str* functions on
  the returned buffer.
 
 Fixed, and committed to git. Please try it.

Results are correct and speed is equal to my patch. All good, thanks.

- Lauri

-- 
http://www.fastmail.com - Send your email first class

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


[PATCH] Add option -e to swapon and swapoff

2014-12-07 Thread René Rhéaume
Hello,
I added the -e option to swapon and swapoff to match util-linux.
OpenRC on Linux requires this option in its swap init script. See
https://bugs.gentoo.org/show_bug.cgi?id=468598 for details.

There are three versions of the patch : for 1.20 and 1.21, for 1.22
and for the master branch.
--- a/util-linux/swaponoff.c
+++ b/util-linux/swaponoff.c
@@ -8,19 +8,21 @@
  */
 
 //usage:#define swapon_trivial_usage
-//usage:   [-a] IF_FEATURE_SWAPON_PRI( [-p PRI])  [DEVICE]
+//usage:   [-a] [-e] IF_FEATURE_SWAPON_PRI( [-p PRI])  [DEVICE]
 //usage:#define swapon_full_usage \n\n
 //usage:   Start swapping on DEVICE\n
 //usage: \n	-a	Start swapping on all swap devices
+//usage: \n	-e	Silently skip devices that do not exist
 //usage:	IF_FEATURE_SWAPON_PRI(
 //usage: \n	-p PRI	Set swap device priority
 //usage:	)
 //usage:
 //usage:#define swapoff_trivial_usage
-//usage:   [-a] [DEVICE]
+//usage:   [-a] [-e] [DEVICE]
 //usage:#define swapoff_full_usage \n\n
 //usage:   Stop swapping on DEVICE\n
 //usage: \n	-a	Stop swapping on all swap devices
+//usage: \n	-e	Silently skip devices that do not exist
 
 #include libbb.h
 #include mntent.h
@@ -49,13 +51,14 @@ struct globals {
 #endif
 #define INIT_G() do { } while (0)
 
-static int swap_enable_disable(char *device)
+static int swap_enable_disable(char *device, bool ifexists)
 {
 	int status;
 	struct stat st;
 
 	resolve_mount_spec(device);
-	xstat(device, st);
+	if (!ifexists)
+		xstat(device, st);
 
 #if ENABLE_DESKTOP
 	/* test for holes */
@@ -70,14 +73,16 @@ static int swap_enable_disable(char *device)
 		status = swapoff(device);
 
 	if (status != 0) {
-		bb_simple_perror_msg(device);
-		return 1;
+		if ((!ifexists) || (errno != ENOENT)) {
+			bb_simple_perror_msg(device);
+			return 1;
+		}
 	}
 
 	return 0;
 }
 
-static int do_em_all(void)
+static int do_em_all(bool ifexists)
 {
 	struct mntent *m;
 	FILE *f;
@@ -95,7 +100,7 @@ static int do_em_all(void)
 			if (applet_name[5] != 'n'
 			 || hasmntopt(m, MNTOPT_NOAUTO) == NULL
 			) {
-err += swap_enable_disable(m-mnt_fsname);
+err += swap_enable_disable(m-mnt_fsname, ifexists);
 			}
 		}
 	}
@@ -114,21 +119,21 @@ int swap_on_off_main(int argc UNUSED_PARAM, char **argv)
 	INIT_G();
 
 #if !ENABLE_FEATURE_SWAPON_PRI
-	ret = getopt32(argv, a);
+	ret = getopt32(argv, ae);
 #else
 	if (applet_name[5] == 'n')
 		opt_complementary = p+;
-	ret = getopt32(argv, (applet_name[5] == 'n') ? ap: : a, g_flags);
+	ret = getopt32(argv, (applet_name[5] == 'n') ? aep: : ae, g_flags);
 
-	if (ret  2) { // -p
+	if (ret  4) { // -p
 		g_flags = SWAP_FLAG_PREFER |
 			((g_flags  SWAP_FLAG_PRIO_MASK)  SWAP_FLAG_PRIO_SHIFT);
 		ret = 1;
 	}
 #endif
 
-	if (ret /*  1: not needed */) // -a
-		return do_em_all();
+	if (ret  1) // -a
+		return do_em_all((ret  2)  0);
 
 	argv += optind;
 	if (!*argv)
@@ -136,7 +141,7 @@ int swap_on_off_main(int argc UNUSED_PARAM, char **argv)
 
 	/* ret = 0; redundant */
 	do {
-		ret += swap_enable_disable(*argv);
+		ret += swap_enable_disable(*argv, ((ret  2)  0));
 	} while (*++argv);
 
 	return ret;
--- a/util-linux/swaponoff.c
+++ b/util-linux/swaponoff.c
@@ -8,19 +8,21 @@
  */
 
 //usage:#define swapon_trivial_usage
-//usage:   [-a] IF_FEATURE_SWAPON_PRI( [-p PRI])  [DEVICE]
+//usage:   [-a] [-e] IF_FEATURE_SWAPON_PRI( [-p PRI])  [DEVICE]
 //usage:#define swapon_full_usage \n\n
 //usage:   Start swapping on DEVICE\n
 //usage: \n	-a	Start swapping on all swap devices
+//usage: \n	-e	Silently skip devices that do not exist
 //usage:	IF_FEATURE_SWAPON_PRI(
 //usage: \n	-p PRI	Set swap device priority
 //usage:	)
 //usage:
 //usage:#define swapoff_trivial_usage
-//usage:   [-a] [DEVICE]
+//usage:   [-a] [-e] [DEVICE]
 //usage:#define swapoff_full_usage \n\n
 //usage:   Stop swapping on DEVICE\n
 //usage: \n	-a	Stop swapping on all swap devices
+//usage: \n	-e	Silently skip devices that do not exist
 
 #include libbb.h
 #include mntent.h
@@ -49,13 +51,14 @@ struct globals {
 #endif
 #define INIT_G() do { } while (0)
 
-static int swap_enable_disable(char *device)
+static int swap_enable_disable(char *device, bool ifexists)
 {
 	int status;
 	struct stat st;
 
 	resolve_mount_spec(device);
-	xstat(device, st);
+	if (!ifexists)
+		xstat(device, st);
 
 #if ENABLE_DESKTOP
 	/* test for holes */
@@ -70,14 +73,16 @@ static int swap_enable_disable(char *device)
 		status = swapoff(device);
 
 	if (status != 0) {
-		bb_simple_perror_msg(device);
-		return 1;
+		if ((!ifexists) || (errno != ENOENT)) {
+			bb_simple_perror_msg(device);
+			return 1;
+		}
 	}
 
 	return 0;
 }
 
-static int do_em_all(void)
+static int do_em_all(bool ifexists)
 {
 	struct mntent *m;
 	FILE *f;
@@ -109,7 +114,7 @@ static int do_em_all(void)
 	}
 }
 #endif
-err += swap_enable_disable(m-mnt_fsname);
+err += swap_enable_disable(m-mnt_fsname, ifexists);
 			}
 		}
 	}
@@ -128,21 +133,21 @@ int swap_on_off_main(int argc 

Re: [PATCH] Add acpi applet

2014-12-07 Thread Isaac Dunham
On Fri, Oct 10, 2014 at 11:24:15PM -0700, Isaac Dunham wrote:
 On several occasions I've wished for a tool that can show battery charge,
 whether the power supply is working, and similar things.
 Some time back I wrote the original version of this for toybox;
 I just ported it to BusyBox.
 
 If anyone could review it, I'd appreciate that.
 
 Thanks,
 Isaac Dunham

Any comments? (Denys?)
Is it within scope?
(I'd love to hear anything, even if it's that belongs elsewhere. 
There's been a lot of silence...)

Thanks,
Isaac Dunham

 From 0c0fad3ae324aa2383a9367715d205e41269d0c0 Mon Sep 17 00:00:00 2001
 From: Isaac Dunham ibid...@gmail.com
 Date: Fri, 10 Oct 2014 22:53:36 -0700
 Subject: [PATCH] Add acpi applet.
 
 A tool to monitor power, temperature, and similar things.
 Ported from toybox; subset clone of acpi-1.7.
 
 function old new   delta
 acpi_main  - 919+919
 .rodata   134270  134673+403
 read_int_at- 129+129
 read_type_at   - 119+119
 packed_usage   29647   29721 +74
 applet_names24512456  +5
 applet_main 14281432  +4
 applet_nameofs   714 716  +2
 --
 (add/remove: 4/0 grow/shrink: 5/0 up/down: 1655/0)   Total: 1655 bytes
text  data bss dec hex filename
  887409  75121644  896565   dae35 busybox_old
  889140  75281644  898312   db508 busybox_unstripped
 ---
  miscutils/acpi.c | 171 
 +++
  1 file changed, 171 insertions(+)
  create mode 100644 miscutils/acpi.c
 
 diff --git a/miscutils/acpi.c b/miscutils/acpi.c
 new file mode 100644
 index 000..f2a5601
 --- /dev/null
 +++ b/miscutils/acpi.c
 @@ -0,0 +1,171 @@
 +/* acpi.c - show power state
 + *
 + * Copyright 2013-2014 A.D., Isaac Dunham
 + *
 + * Based on toybox 0.5.0+ acpi.
 + * 
 + * Permission to use, copy, modify, and/or distribute this software for any
 + * purpose with or without fee is hereby granted.
 + *
 + * THE SOFTWARE IS PROVIDED AS IS AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 + */
 +
 +//config:config ACPI
 +//config:bool acpi
 +//config:default y
 +//config:select PLATFORM_LINUX
 +//config:help
 +//config:  Show status of power sources and thermal devices.
 +
 +//applet:IF_ACPI(APPLET(acpi, BB_DIR_USR_BIN, BB_SUID_DROP))
 +//kbuild:lib-$(CONFIG_ACPI) += acpi.o
 +
 +//usage:#define acpi_trivial_usage
 +//usage:[-abctV]
 +//usage:#define acpi_full_usage \n\n
 +//usage:Show status of power sources and thermal devices.\n
 +//usage:-a  show power adapters\n
 +//usage:-b  show batteries\n
 +//usage:-c  show cooling device state\n
 +//usage:-t  show temperatures\n
 +//usage:-V  show everything
 +
 +
 +#define FLAG_a   1
 +#define FLAG_b   2
 +#define FLAG_c   4
 +#define FLAG_t   8
 +#define FLAG_V   16
 +
 +#include libbb.h
 +#include glob.h
 +
 +#define G_BUFSIZ 64
 +struct globals {
 +int ac;
 +int bat;
 +int therm;
 +int cool;
 +char buf[G_BUFSIZ];
 +} FIX_ALIASING;
 +#define G (*(struct globals*)bb_common_bufsiz1)
 +
 +static int read_int_at(int dirfd, const char *name)
 +{
 +int fd, ret = 0;
 +FILE *fil;
 +
 +if ((fd = openat(dirfd, name, O_RDONLY))  0)
 + return -1;
 +fscanf(fil = fdopen(fd, r), %d, ret);
 +fclose(fil);
 +
 +return ret;
 +}
 +
 +static char *read_type_at(int dirfd)
 +{
 +int fd;
 +if ((fd = openat(dirfd, type, O_RDONLY))  0)
 + return 0;
 +read(fd, G.buf, G_BUFSIZ-1);
 +close(fd);
 +if errno
 + return 0;
 +return G.buf;
 +}
 +
 +int acpi_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
 +int acpi_main(int argc UNUSED_PARAM, char **argv)
 +{
 +glob_t files;
 +int dfd, on, cur, max, temp, i;
 +unsigned opts = getopt32(argv, abctV);
 +
 +if (opts  FLAG_V)
 + opts = FLAG_a | FLAG_b | FLAG_c | FLAG_t;
 +if (!opts)
 + opts = FLAG_b;
 +if (opts  (FLAG_a | FLAG_b)) {
 + glob(/sys/class/power_supply/*/, GLOB_NOSORT, NULL, files);
 + for (i = 0; i  files.gl_pathc; i++) {
 + 

custom snmpset coding not working-giving-error

2014-12-07 Thread Akhilesh kumar
Hi all

i am writing my own implementation code for snmpset command. I have written
the below code but it gives error. I cant figure out how to correct Bad
variable type error.



#include stdio.h
#include net-snmp/net-snmp-config.h
#include net-snmp/net-snmp-includes.h
#include string.h
#include net-snmp/varbind_api.h

int main(int argc, char ** argv)
{

struct snmp_session session;
struct snmp_session *sess_handle;
struct snmp_pdu *pdu;
struct snmp_pdu *response;
struct variable_list *vars;
oid id_oid[MAX_OID_LEN];
size_t id_len = MAX_OID_LEN;
size_t name_length;
int status;
char set_var_cval[30],set_var[50];
int choose_option=0;
char *p=NULL, get_var[51];
int set_var_ival=0,failures=0,count;
char   *names[SNMP_MAX_CMDLINE_OIDS];
chartypes[SNMP_MAX_CMDLINE_OIDS];
unsigned int*values[SNMP_MAX_CMDLINE_OIDS];
oid name[MAX_OID_LEN];
char type='i';
const char
*dirname=/usr/local/share/snmp/mibs/,*filename=DDS-ENGINE-MIB.mib;
unsigned int value_ptr;



add_mibdir(/usr/local/share/snmp/mibs/);
read_mib(DDS-ENGINE-MIB.mib);
printf(Enter the OID to set value\n);
scanf(%s,set_var);
printf(The OID to be set is %s\n,set_var);

init_snmp(snmpdemoapp);
snmp_sess_init( session );
session.version = SNMP_VERSION_1;
session.community = public;
session.community_len = strlen(session.community);
session.peername = argv[1];
sess_handle = snmp_open(session);
pdu = snmp_pdu_create(SNMP_MSG_SET);


count=0;
names[0]=set_var;
printf(Enter the value to be set with\n);
scanf(%d,value_ptr);
values[0]=value_ptr;
types[0]=i;
name_length=strlen(names[0]);

if (snmp_add_var(pdu, name, name_length, types[count],
values[count]))
{ snmp_perror(names[count]); failures++; }



status = snmp_synch_response(sess_handle, pdu, response);






snmp_free_pdu(response);
snmp_close(sess_handle);
exit(1);

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

Re: custom snmpset coding not working-giving-error

2014-12-07 Thread Laszlo Papp
Please stop sending these messages to this mailing list. This is _not_
an SNMP mailing list. If you need programming help, go to trainings or
other sites, like Stack Overflow.

On Mon, Dec 8, 2014 at 5:57 AM, Akhilesh kumar 95aku...@gmail.com wrote:
 Hi all

 i am writing my own implementation code for snmpset command. I have written
 the below code but it gives error. I cant figure out how to correct Bad
 variable type error.



 #include stdio.h
 #include net-snmp/net-snmp-config.h
 #include net-snmp/net-snmp-includes.h
 #include string.h
 #include net-snmp/varbind_api.h

 int main(int argc, char ** argv)
 {

 struct snmp_session session;
 struct snmp_session *sess_handle;
 struct snmp_pdu *pdu;
 struct snmp_pdu *response;
 struct variable_list *vars;
 oid id_oid[MAX_OID_LEN];
 size_t id_len = MAX_OID_LEN;
 size_t name_length;
 int status;
 char set_var_cval[30],set_var[50];
 int choose_option=0;
 char *p=NULL, get_var[51];
 int set_var_ival=0,failures=0,count;
 char   *names[SNMP_MAX_CMDLINE_OIDS];
 chartypes[SNMP_MAX_CMDLINE_OIDS];
 unsigned int*values[SNMP_MAX_CMDLINE_OIDS];
 oid name[MAX_OID_LEN];
 char type='i';
 const char
 *dirname=/usr/local/share/snmp/mibs/,*filename=DDS-ENGINE-MIB.mib;
 unsigned int value_ptr;



 add_mibdir(/usr/local/share/snmp/mibs/);
 read_mib(DDS-ENGINE-MIB.mib);
 printf(Enter the OID to set value\n);
 scanf(%s,set_var);
 printf(The OID to be set is %s\n,set_var);

 init_snmp(snmpdemoapp);
 snmp_sess_init( session );
 session.version = SNMP_VERSION_1;
 session.community = public;
 session.community_len = strlen(session.community);
 session.peername = argv[1];
 sess_handle = snmp_open(session);
 pdu = snmp_pdu_create(SNMP_MSG_SET);


 count=0;
 names[0]=set_var;
 printf(Enter the value to be set with\n);
 scanf(%d,value_ptr);
 values[0]=value_ptr;
 types[0]=i;
 name_length=strlen(names[0]);

 if (snmp_add_var(pdu, name, name_length, types[count],
 values[count]))
 { snmp_perror(names[count]); failures++; }



 status = snmp_synch_response(sess_handle, pdu, response);






 snmp_free_pdu(response);
 snmp_close(sess_handle);
 exit(1);

 }


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


[PATCH] dpkg: update supported compression methods

2014-12-07 Thread Ron Yorston
According to the deb(5) man page the tar files contained in a deb
file can be compressed as follows:

   control.tar:  uncompressed, gz, xz
   data.tar: uncompressed, gz, bz2, lzma, xz

Signed-off-by: Ron Yorston r...@tigress.co.uk
---
 archival/dpkg.c   | 12 ++--
 archival/dpkg_deb.c   |  8 ++--
 archival/libarchive/Kbuild.src|  1 +
 archival/libarchive/filter_accept_list_reassign.c | 10 ++
 include/bb_archive.h  |  1 +
 5 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/archival/dpkg.c b/archival/dpkg.c
index 2893cfc..104f47d 100644
--- a/archival/dpkg.c
+++ b/archival/dpkg.c
@@ -1472,11 +1472,12 @@ static void init_archive_deb_control(archive_handle_t 
*ar_handle)
tar_handle-src_fd = ar_handle-src_fd;
 
/* We don't care about data.tar.* or debian-binary, just control.tar.* 
*/
+   llist_add_to((ar_handle-accept), (char*)control.tar);
 #if ENABLE_FEATURE_SEAMLESS_GZ
llist_add_to((ar_handle-accept), (char*)control.tar.gz);
 #endif
-#if ENABLE_FEATURE_SEAMLESS_BZ2
-   llist_add_to((ar_handle-accept), (char*)control.tar.bz2);
+#if ENABLE_FEATURE_SEAMLESS_XZ
+   llist_add_to((ar_handle-accept), (char*)control.tar.xz);
 #endif
 
/* Assign the tar handle as a subarchive of the ar handle */
@@ -1492,12 +1493,19 @@ static void init_archive_deb_data(archive_handle_t 
*ar_handle)
tar_handle-src_fd = ar_handle-src_fd;
 
/* We don't care about control.tar.* or debian-binary, just data.tar.* 
*/
+   llist_add_to((ar_handle-accept), (char*)data.tar);
 #if ENABLE_FEATURE_SEAMLESS_GZ
llist_add_to((ar_handle-accept), (char*)data.tar.gz);
 #endif
 #if ENABLE_FEATURE_SEAMLESS_BZ2
llist_add_to((ar_handle-accept), (char*)data.tar.bz2);
 #endif
+#if ENABLE_FEATURE_SEAMLESS_LZMA
+   llist_add_to((ar_handle-accept), (char*)data.tar.lzma);
+#endif
+#if ENABLE_FEATURE_SEAMLESS_XZ
+   llist_add_to((ar_handle-accept), (char*)data.tar.xz);
+#endif
 
/* Assign the tar handle as a subarchive of the ar handle */
ar_handle-dpkg__sub_archive = tar_handle;
diff --git a/archival/dpkg_deb.c b/archival/dpkg_deb.c
index 13f9db9..b1e46a8 100644
--- a/archival/dpkg_deb.c
+++ b/archival/dpkg_deb.c
@@ -70,17 +70,21 @@ int dpkg_deb_main(int argc, char **argv)
ar_archive-dpkg__sub_archive = tar_archive;
ar_archive-filter = filter_accept_list_reassign;
 
+   llist_add_to(ar_archive-accept, (char*)data.tar);
+   llist_add_to(control_tar_llist, (char*)control.tar);
 #if ENABLE_FEATURE_SEAMLESS_GZ
llist_add_to(ar_archive-accept, (char*)data.tar.gz);
llist_add_to(control_tar_llist, (char*)control.tar.gz);
 #endif
 #if ENABLE_FEATURE_SEAMLESS_BZ2
llist_add_to(ar_archive-accept, (char*)data.tar.bz2);
-   llist_add_to(control_tar_llist, (char*)control.tar.bz2);
 #endif
 #if ENABLE_FEATURE_SEAMLESS_LZMA
llist_add_to(ar_archive-accept, (char*)data.tar.lzma);
-   llist_add_to(control_tar_llist, (char*)control.tar.lzma);
+#endif
+#if ENABLE_FEATURE_SEAMLESS_XZ
+   llist_add_to(ar_archive-accept, (char*)data.tar.xz);
+   llist_add_to(control_tar_llist, (char*)control.tar.xz);
 #endif
 
opt_complementary = c--efXx:e--cfXx:f--ceXx:X--cefx:x--cefX;
diff --git a/archival/libarchive/Kbuild.src b/archival/libarchive/Kbuild.src
index 968fdf8..7e89e9e 100644
--- a/archival/libarchive/Kbuild.src
+++ b/archival/libarchive/Kbuild.src
@@ -35,6 +35,7 @@ DPKG_FILES:= \
get_header_tar_gz.o \
get_header_tar_bz2.o \
get_header_tar_lzma.o \
+   get_header_tar_xz.o \
 
 INSERT
 
diff --git a/archival/libarchive/filter_accept_list_reassign.c 
b/archival/libarchive/filter_accept_list_reassign.c
index 3d19abe..b9acfbc 100644
--- a/archival/libarchive/filter_accept_list_reassign.c
+++ b/archival/libarchive/filter_accept_list_reassign.c
@@ -28,6 +28,10 @@ char FAST_FUNC filter_accept_list_reassign(archive_handle_t 
*archive_handle)
name_ptr++;
 
/* Modify the subarchive handler based on the extension */
+   if (strcmp(name_ptr, tar) == 0) {
+   archive_handle-dpkg__action_data_subarchive = 
get_header_tar;
+   return EXIT_SUCCESS;
+   }
if (ENABLE_FEATURE_SEAMLESS_GZ
  strcmp(name_ptr, gz) == 0
) {
@@ -46,6 +50,12 @@ char FAST_FUNC filter_accept_list_reassign(archive_handle_t 
*archive_handle)
archive_handle-dpkg__action_data_subarchive = 
get_header_tar_lzma;
return EXIT_SUCCESS;
}
+   if (ENABLE_FEATURE_SEAMLESS_XZ
+ strcmp(name_ptr, xz) == 0
+   ) {
+   archive_handle-dpkg__action_data_subarchive = 
get_header_tar_xz;
+   return EXIT_SUCCESS;
+