فهرست منبع

vcc: it can now run

intirain 4 سال پیش
والد
کامیت
dd28f7ca1f
3فایلهای تغییر یافته به همراه13 افزوده شده و 5 حذف شده
  1. 1 1
      Makefile
  2. 1 1
      include/vcc/version.h
  3. 11 3
      main.c

+ 1 - 1
Makefile

@@ -1,6 +1,6 @@
 VCCD_MAJOR 		= 0
 VCCD_MINOR 		= 1
-VCCD_PATCH 		= 0
+VCCD_PATCH 		= 2
 VCCD_COMPILE_TIME 	= $(shell date)
 VCCD_COMPILE_BY 	= $(shell whoami)
 

+ 1 - 1
include/vcc/version.h

@@ -1 +1 @@
-#define VCCD_VERSION "vccd 0.1.0 Sat Mar  5 15:52:51 CST 2022 root"
+#define VCCD_VERSION "vccd 0.1.2 Sat Mar  5 16:18:03 CST 2022 root"

+ 11 - 3
main.c

@@ -118,7 +118,7 @@ static int read_msg(char *buf) {
 void alarm_handler(int nr) {
 	alarm(1);
 
-	empty_package[0] = 0xff;
+	memset(empty_package, 0xff, REQ_SIZE);
 	write(fd, empty_package, REQ_SIZE);
 
 	return;
@@ -151,7 +151,7 @@ int main(int argc, const char **argv) {
 
 	printf("Connected to server. \n");
 
-	if ((pid = fork())) {
+	if (!(pid = fork())) {
 		/* receive messages */
 
 		setup_alarm();
@@ -165,6 +165,9 @@ int main(int argc, const char **argv) {
 				break;
 			}
 
+			if (!*buf) 
+				continue;
+
 			printf("New message: %s\n", buf);
 		}
 	}
@@ -172,7 +175,12 @@ int main(int argc, const char **argv) {
 	else 
 		for (;;) {
 			memset(buf, 0, REQ_SIZE);
-			read(0, buf, REQ_SIZE);
+
+			if (read(0, buf, REQ_SIZE) <= 0) {
+				fprintf(stderr, "--- read() failed. \n");
+
+				continue;
+			}
 
 			if (!strcmp(buf, "quit")) 
 				break;