Patch for prevous code sent. Increases compatility, reduces code, fix typos.
>From 915bd5cd6c5ec424c751a2bba531fdcb3571949f Mon Sep 17 00:00:00 2001
From: Marek Becka <[email protected]>
Date: Wed, 20 Apr 2011 17:03:56 +0200
Subject: [PATCH 2/2] setserial fixups

---
 miscutils/setserial.c |   35 ++++++++++++++++-------------------
 1 files changed, 16 insertions(+), 19 deletions(-)

diff --git a/miscutils/setserial.c b/miscutils/setserial.c
index 8618067..1a89d23 100644
--- a/miscutils/setserial.c
+++ b/miscutils/setserial.c
@@ -28,11 +28,11 @@
 //usage:	"Parameters:	(* = Takes an argument, ^ = Can be turned off by preceding '^')\n"
 //usage:	"	*port, *irq, *divisor, *uart, *baund_base, *close_delay, *closing_wait,\n"
 //usage:	"	^fourport, ^auto_irq, ^skip_test, ^sak, ^session_lockout, ^pgrp_lockout,\n"
-//usage:	"	^callout_nohup, ^split_termios, ^hup_notify, ^low_latency, autoconfig\n"
+//usage:	"	^callout_nohup, ^split_termios, ^hup_notify, ^low_latency, autoconfig,\n"
 //usage:	"	spd_normal, spd_hi, spd_vhi, spd_shi, spd_warp, spd_cust\n\n"
 //usage:	"UART types:\n"
 //usage:	"	unknown, 8250, 16450, 16550, 16550A, Cirrus, 16650, 16650V2, 16750,\n"
-//usage:	"	16950, 16954, 16654, 16850, RSA, NS16550A, XSCALE, RM9000, OCTEON, AR7\n"
+//usage:	"	16950, 16954, 16654, 16850, RSA, NS16550A, XSCALE, RM9000, OCTEON, AR7,\n"
 //usage:	"	U6_16550A"
 
 #ifndef PORT_UNKNOWN
@@ -232,12 +232,11 @@ struct serial_struct {
 #define OPT_MODE_MASK \
 (OPT_PRINT_ALL | OPT_PRINT_SUMMARY | OPT_PRINT_FEDBACK)
 
-#define	CTL_OPEN		(1 << 0)
-#define CTL_GET			(1 << 1)
-#define CTL_CONFIG		(1 << 2)
-#define CTL_SET			(1 << 3)
-#define CTL_CLOSE		(1 << 4)
-#define CTL_NODIE		(1 << 5)
+#define CTL_SET			(1 << 0)
+#define CTL_CONFIG		(1 << 1)
+#define CTL_GET			(1 << 2)
+#define CTL_CLOSE		(1 << 3)
+#define CTL_NODIE		(1 << 4)
 
 static const char *serial_types =
 	"unknown\0"		/* 0 */
@@ -463,12 +462,12 @@ static int get_uart(const char *arg)
 	return uart;
 }
 
-static int serial_open(const char *dev)
+static int serial_open(const char *dev, bool quiet)
 {
 	int fd;
 
 	fd = device_open(dev, O_RDWR | O_NONBLOCK);
-	if (fd < 0)
+	if (fd < 0 && !quiet)
 		bb_simple_perror_msg(dev);
 	
 	return fd;
@@ -476,7 +475,7 @@ static int serial_open(const char *dev)
 
 static int serial_ctl(int fd, int ops, struct serial_struct *serinfo)
 {
-	int ret;
+	int ret = 0;
 	const char *err;
 	
 	if (ops & CTL_SET) {
@@ -502,22 +501,20 @@ static int serial_ctl(int fd, int ops, struct serial_struct *serinfo)
 			goto fail;
 		}
 	}
-
+nodie:
 	if (ops & CTL_CLOSE)
 		close(fd);
 
-	return 0;
+	return ret;
 fail:
 	bb_simple_perror_msg(err);
 	if (ops & CTL_NODIE)
-		return ret;
+		goto nodie;
 	exit(EXIT_FAILURE);
 }
-
 static void print_flag(const char **prefix, const char *flag)
 {
-	fputs(*prefix, stdout);
-	fputs(flag, stdout);
+	printf("%s%s", *prefix, flag);
 	*prefix = " ";
 }
 
@@ -561,7 +558,7 @@ static void serial_get(const char *device, enum print_mode mode)
 	const char *uart, *prefix, *postfix;
 	struct serial_struct serinfo;
 
-	fd = serial_open(device);
+	fd = serial_open(device, mode == PRINT_SUMMARY);
 	if (fd < 0)
 		return;
 
@@ -628,7 +625,7 @@ static void serial_set(char **arg, int opts)
 	bool invert;
 	int fd;
 
-	fd = serial_open(*arg++);
+	fd = serial_open(*arg++, false);
 	if (fd < 0)
 		exit(201);
 
-- 
1.7.2.2
_______________________________________________
busybox mailing list
[email protected]
http://lists.busybox.net/mailman/listinfo/busybox

Reply via email to