thermferm/server.c

changeset 240
6bdda35b4a13
parent 237
51a294d683cd
child 245
b01b6238eb67
--- a/thermferm/server.c	Thu Aug 14 22:02:33 2014 +0200
+++ b/thermferm/server.c	Thu Aug 14 22:43:41 2014 +0200
@@ -97,12 +97,18 @@
 
     for (device = Config.devices; device; device = device->next) {
 	if (strcmp(device->uuid, uuid) == 0) {
+#ifdef HAVE_WIRINGPI_H
+	    piLock(LOCK_DEVICES);
+#endif
 	    if (plus == TRUE) {
 		device->inuse++;
 	    } else {
 		if (device->inuse)
 		    device->inuse--;
 	    }
+#ifdef HAVE_WIRINGPI_H
+	    piUnlock(LOCK_DEVICES);
+#endif
 	}
     }
 }
@@ -215,7 +221,7 @@
     char		*opt, *param, *kwd, *val, ibuf[SS_BUFSIZE];
     devices_list	*device, *tmpd;
     socklen_t		fromlen;
-    int			i, rlen, ival;
+    int			i, rc, rlen, ival;
     uuid_t		uu;
 
     opt = strtok(buf, " \0");
@@ -265,6 +271,9 @@
 	    device->description = xstrcpy((char *)"Describe me here");
 	    device->comment = xstrcpy((char *)"Comment here");
 
+#ifdef HAVE_WIRINGPI_H
+	    piLock(LOCK_DEVICES);
+#endif
 	    if (Config.devices == NULL) {
 		Config.devices = device;
 	    } else {
@@ -275,6 +284,9 @@
 		    }
 		}
 	    }
+#ifdef HAVE_WIRINGPI_H
+	    piUnlock(LOCK_DEVICES);
+#endif
 	    syslog(LOG_NOTICE, "Device %s added", device->uuid);
 	    srv_send((char *)"211 Device %s added", device->uuid);
 	    return 0;
@@ -287,7 +299,14 @@
 
     if (strcmp(opt, (char *)"DEL") == 0) {
 	
-	if (delete_Device(param)) {
+#ifdef HAVE_WIRINGPI_H
+	piLock(LOCK_DEVICES);
+#endif
+	rc = delete_Device(param);
+#ifdef HAVE_WIRINGPI_H
+	piUnlock(LOCK_DEVICES);
+#endif
+	if (rc) {
 	    syslog(LOG_NOTICE, "Device %s deleted", param);
 	    srv_send((char *)"211 Device %s deleted", param);
 	    return 0;

mercurial