Sven Velt 11 년 전
부모
커밋
8e169472f2
2개의 변경된 파일21개의 추가작업 그리고 6개의 파일을 삭제
  1. 2 2
      Makefile
  2. 19 4
      arexxd.c

+ 2 - 2
Makefile

@@ -1,9 +1,9 @@
-VERSION=1.3
+VERSION=1.4
 ARCHIVE=arexxd-$(VERSION).tar.gz
 
 CC=gcc
 LD=gcc
-CFLAGS=-O2 -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wredundant-decls -std=gnu99
+CFLAGS=-O2 -Wall -W -Wno-parentheses -Wstrict-prototypes -Wmissing-prototypes -Wundef -Wredundant-decls -std=gnu99 -DAREXXD_VERSION='"$(VERSION)"'
 LDLIBS=-lusb-1.0 -lm -lrrd
 
 all: arexxd

+ 19 - 4
arexxd.c

@@ -141,6 +141,7 @@ static void rrd_point(time_t t, const char *name, double val, char *unit)
 		rrd_create(arg_cnt, arg_ptr);
 		if (rrd_test_error()) {
 			log_error("rrd_create on %s failed: %s", rr_name, rrd_get_error());
+			rrd_clear_error();
 			return;
 		}
 	}
@@ -149,8 +150,10 @@ static void rrd_point(time_t t, const char *name, double val, char *unit)
 	arg_push(rr_name);
 	arg_push("%d:%f", t, val);
 	rrd_update(arg_cnt, arg_ptr);
-	if (rrd_test_error())
+	if (rrd_test_error()) {
 		log_error("rrd_update on %s failed: %s", rr_name, rrd_get_error());
+		rrd_clear_error();
+	}
 }
 
 /*** Transforms ***/
@@ -407,6 +410,12 @@ static void dump_packet(byte *pkt)
 	}
 }
 
+static void my_msleep(int ms)
+{
+	struct timespec ts = { .tv_sec = ms/1000, .tv_nsec = (ms%1000) * 1000000 };
+	nanosleep(&ts, NULL);
+}
+
 static int send_and_receive(byte *req, byte *reply)
 {
 	if (debug_packets) {
@@ -433,6 +442,7 @@ static int send_and_receive(byte *req, byte *reply)
 		log_pkt(">> xmit %d bytes\n", transferred);
 		dump_packet(req);
 	}
+	my_msleep(1);
 	if (err = libusb_bulk_transfer(devh, rx_endpoint, reply, 64, &transferred, 200)) {
 		if (err == LIBUSB_ERROR_TIMEOUT) {
 			log_pkt("<< recv timed out\n");
@@ -552,8 +562,7 @@ static void sigterm_handler(int sig __attribute__((unused)))
 static void interruptible_msleep(int ms)
 {
 	sigprocmask(SIG_UNBLOCK, &term_sigs, NULL);
-	struct timespec ts = { .tv_sec = ms/1000, .tv_nsec = (ms%1000) * 1000000 };
-	nanosleep(&ts, NULL);
+	my_msleep(ms);
 	sigprocmask(SIG_BLOCK, &term_sigs, NULL);
 }
 
@@ -562,6 +571,7 @@ static const struct option long_options[] = {
 	{ "log-dir",		1, NULL, 'l' },
 	{ "debug-packets",	0, NULL, 'p' },
 	{ "debug-raw",		0, NULL, 'r' },
+	{ "version",		0, NULL, 'V' },
 	{ NULL,			0, NULL, 0 },
 };
 
@@ -576,6 +586,7 @@ Options:\n\
 -p, --debug-packets	Log all packets sent and received\n\
 -r, --debug-raw		Log conversion from raw values\n\
 -u, --debug-usb		Enable libusb debug messages (to stdout/stderr)\n\
+-V, --version		Show daemon version\n\
 ");
 	exit(1);
 }
@@ -583,7 +594,7 @@ Options:\n\
 int main(int argc, char **argv)
 {
 	int opt;
-	while ((opt = getopt_long(argc, argv, "dl:pru", long_options, NULL)) >= 0)
+	while ((opt = getopt_long(argc, argv, "dl:pruV", long_options, NULL)) >= 0)
 		switch (opt) {
 			case 'd':
 				debug_mode++;
@@ -600,6 +611,10 @@ int main(int argc, char **argv)
 			case 'u':
 				debug_usb++;
 				break;
+			case 'V':
+				printf("arexxd " AREXXD_VERSION "\n");
+				printf("(c) 2011-2012 Martin Mares <mj@ucw.cz>\n");
+				return 0;
 			default:
 				usage();
 		}