On Wednesday 11 July 2007 13:48:52 Alex Landau wrote:
> 
> Tito <[EMAIL PROTECTED]> wrote: Hi,
> this series of 7 patches is a first attempt to add an ioctl api to libbb
> and to use it in all applets where:
> 
> if ( ioctl() < 0 [!= 0])
>  bb_perror_msg{and_die}();
> 
> or similar code is used.
> [snip]
> 
> Critics, hints and help from the list is as always welcome.
> 
> Ciao,
> Tito
> 
> Hi,
> It looks really nice, only eye-tested though.
> One small comment: ioctl(...) != 0 doesn't mean it's an error. the ioctl() 
> may return a positive value, 
> so I'd better have an ioctl(...) < 0 test. Especially when you return ret 
> afterwards. 
> Regards,
> Alex
> 
Hi,
I know but i'm pretty sure that in all places in busybox where this test was 
used
[ !=0 ] it errored out, i double checked it, but nonetheless maybe its a good 
idea
to change it to [ < 0 ] to be more coherent with the original ioctl call.
So attached is a fixed patch.

Ciao,
Tito
--- busybox.orig/include/libbb.h	2007-07-05 08:20:25.000000000 +0200
+++ busybox/include/libbb.h	2007-07-09 21:27:21.000000000 +0200
@@ -780,6 +780,20 @@
 
 int get_terminal_width_height(const int fd, int *width, int *height);
 
+int ioctl_or_vperror(int fd, int request, void *argp, const char *fmt,...)__attribute__ ((format (printf, 4, 5)));
+void ioctl_or_vperror_and_die(int fd, int request, void *argp, const char *fmt,...) __attribute__ ((format (printf, 4, 5)));
+#if ENABLE_IOCTL_HEX2STR_ERROR
+int bb_ioctl_or_warn(int fd, int request, void *argp, const char *ioctl_name);
+void bb_ioctl_or_die(int fd, int request, void *argp, const char *ioctl_name);
+#define ioctl_or_warn(fd,request,argp) bb_ioctl_or_warn(fd,request,argp,#request)
+#define ioctl_or_die(fd,request,argp)  bb_ioctl_or_die(fd,request,argp,#request)
+#else
+int bb_ioctl_or_warn(int fd, int request, void *argp);
+void bb_ioctl_or_die(int fd, int request, void *argp);
+#define ioctl_or_warn(fd,request,argp) bb_ioctl_or_warn(fd,request,argp)
+#define ioctl_or_die(fd,request,argp)  bb_ioctl_or_die(fd,request,argp)
+#endif
+
 char *is_in_ino_dev_hashtable(const struct stat *statbuf);
 void add_to_ino_dev_hashtable(const struct stat *statbuf, const char *name);
 void reset_ino_dev_hashtable(void);
--- busybox.orig/libbb/Config.in	2007-06-19 22:39:56.000000000 +0200
+++ busybox/libbb/Config.in	2007-07-09 21:34:17.000000000 +0200
@@ -120,4 +120,11 @@
 	  will be used instead (which gives wrong results if date/time
 	  is reset).
 
+config IOCTL_HEX2STR_ERROR
+	bool "Use ioctl names rather than hex values in error messages"
+	default y
+	help
+	  Use ioctl names rather than hex values in error messages
+	  (e.g. VT_DISALLOCATE rather than 0x5608). If disabled this
+	  saves about 1375 bytes.
 endmenu
--- busybox.orig/libbb/xfuncs.c	2007-05-26 23:23:50.000000000 +0200
+++ busybox/libbb/xfuncs.c	2007-07-09 21:30:18.000000000 +0200
@@ -639,3 +639,62 @@
 
 	return ret;
 }
+
+void ioctl_or_vperror_and_die(int fd, int request, void *argp, const char *fmt,...)
+{
+	va_list p;
+
+	if (ioctl(fd, request, argp) < 0) {
+		va_start(p, fmt);
+		bb_vperror_msg(fmt, p);
+		xfunc_die();
+		/*va_end(p);*/
+	}
+}
+
+int ioctl_or_vperror(int fd, int request, void *argp, const char *fmt,...)
+{
+	va_list p;
+	int ret = ioctl(fd, request, argp);
+
+	if ( ret < 0) {
+		va_start(p, fmt);
+		bb_vperror_msg(fmt, p);
+		va_end(p);
+	}
+	return ret;
+}
+
+#if ENABLE_IOCTL_HEX2STR_ERROR
+int bb_ioctl_or_warn(int fd, int request, void *argp, const char *ioctl_name)
+{
+	int ret;
+	
+	ret = ioctl(fd, request, argp);
+	if (ret < 0)
+		bb_perror_msg("%s", ioctl_name);
+	return ret;
+}
+
+void bb_ioctl_or_die(int fd, int request, void *argp, const char *ioctl_name)
+{
+	if (ioctl(fd, request, argp) < 0)
+		bb_perror_msg_and_die("%s", ioctl_name);
+}
+#else
+int bb_ioctl_or_warn(int fd, int request, void *argp)
+{
+	int ret;
+	
+	ret = ioctl(fd, request, argp);
+	if (ret < 0)
+		bb_perror_msg("ioctl %#x failed", request);
+	return ret;
+}
+
+void bb_ioctl_or_die(int fd, int request, void *argp)
+{
+	if (ioctl(fd, request, argp) < 0)
+		bb_perror_msg_and_die("ioctl %#x failed", request);
+}
+#endif
--- busybox.orig/scripts/defconfig	2007-06-19 13:39:41.000000000 +0200
+++ busybox/scripts/defconfig	2007-07-09 21:32:52.000000000 +0200
@@ -77,6 +77,7 @@
 # CONFIG_FEATURE_USERNAME_COMPLETION is not set
 # CONFIG_FEATURE_EDITING_FANCY_PROMPT is not set
 # CONFIG_MONOTONIC_SYSCALL is not set
+CONFIG_IOCTL_HEX2STR_ERROR=y
 
 #
 # Applets
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to