PERFORCE change 125341 for review

Andrew Turner andrew at FreeBSD.org
Sun Aug 19 04:09:07 PDT 2007


http://perforce.freebsd.org/chv.cgi?CH=125341

Change 125341 by andrew at andrew_hermies on 2007/08/19 11:08:43

	Make the db_next_patch and db_rollback_count values volatile as they could be changed at any time by the thread watching freebsd-update
	When there were updated avaliable but they were installed the value was not reset. Fix this.
	Clear the kqueue when it fires. This stops the backend using all avaliable CPU clearing out the events on an update.
	Fix the number given to installed patches
	Run freebsd-update. This has been tested on a jail donated by marcus@
	Check the return value of property_find before attempting to strdup it
	Make /tmp/facund 0777 so everyone will be able to access it.
	Let the UNAME_r environment override the release value from uname(3)

Affected files ...

.. //depot/projects/soc2007/andrew-update/backend/facund-be.c#24 edit

Differences ...

==== //depot/projects/soc2007/andrew-update/backend/facund-be.c#24 (text+ko) ====

@@ -110,8 +110,8 @@
 	char	 *db_dir;
 	int	  db_fd;
 
-	unsigned int db_next_patch;
-	unsigned int db_rollback_count;
+	volatile unsigned int db_next_patch;
+	volatile unsigned int db_rollback_count;
 
 	char	 *db_tag_file;
 	struct fbsd_tag_line *db_tag_line;
@@ -262,6 +262,8 @@
 	    lstat(install_link, &sb) == 0 && S_ISLNK(sb.st_mode)) {
 		watched_db[pos].db_next_patch =
 		    watched_db[pos].db_tag_line->tag_patch;
+	} else {
+		watched_db[pos].db_next_patch = 0;
 	}
 
 	/* Look for the rollback link and check if it is a symlink */
@@ -321,8 +323,9 @@
 		watched_db[pos].db_fd = open(watched_db[pos].db_dir, O_RDONLY);
 
 		/* Create an event to look for files being added to the dir */
-		EV_SET(&event, watched_db[pos].db_fd, EVFILT_VNODE, EV_ADD,
-		    NOTE_WRITE | NOTE_DELETE | NOTE_EXTEND, 0, (void *)pos);
+		EV_SET(&event, watched_db[pos].db_fd, EVFILT_VNODE,
+		    EV_ADD | EV_CLEAR, NOTE_WRITE | NOTE_DELETE | NOTE_EXTEND,
+		    0, (void *)pos);
 
 		kevent(kq, &event, 1, NULL, 0, NULL);
 	}
@@ -385,14 +388,6 @@
 			break;
 		}
 
-		/*
-		 * Wait for any disk activity to
-		 * quieten down before waiting again
-		 */
-		if (use_kqueue) {
-			sleep(10);
-		}
-
 		/* Wait for posible updates */
 		if (use_kqueue == 1) {
 			/* Wait for posible updates ready to be installed */
@@ -503,6 +498,7 @@
 		if (ptr[0] == '\0') {
 			return 0;
 		}
+
 		pos++;
 	}
 	return -1;
@@ -898,7 +894,7 @@
 
 				/* Calculate the patch level */
 				level = watched_db[i].db_tag_line->tag_patch;
-				level -= rollback_pos + 1;
+				level -= rollback_pos - 1;
 				if (watched_db[i].db_next_patch > 0)
 					level--;
 
@@ -989,9 +985,8 @@
 		if (arg == NULL)
 			return -1;
 	}
-	asprintf(&cmd, "echo " FREEBSD_COMMAND " %s %s",
-	    (arg == NULL ? "" : arg), command);
-	//asprintf(&command, FREEBSD_COMMAND " install");
+	asprintf(&cmd, FREEBSD_COMMAND " %s %s", (arg == NULL ? "" : arg),
+	    command);
 
 	free(arg);
 	if (cmd == NULL) {
@@ -1118,7 +1113,7 @@
 	pthread_t update_thread, comms_thread;
 	struct facund_conn *conn;
 	const char *config_file;
-	char *basedirs_string;
+	char *basedirs_string, *uname_r;
 	unsigned int pos;
 	int config_fd;
 	properties config_data;
@@ -1166,8 +1161,11 @@
 			errx(1, "Could not read the config file");
 		}
 
-		basedirs_string = strdup(property_find(config_data,
-		    "base_dirs"));
+		basedirs_string = property_find(config_data, "base_dirs");
+		if (basedirs_string == NULL) {
+			errx(1, "Incorrect config file");
+		}
+		basedirs_string = strdup(basedirs_string);
 		if (basedirs_string == NULL) {
 			errx(1, "Malloc failed");
 		}
@@ -1186,11 +1184,17 @@
 	if (conn == NULL) {
 		errx(1, "Could not open a socket: %s\n", strerror(errno));
 	}
+	chmod("/tmp/facund", 0777);
 
 	/* Get the uname data */
 	if (uname(&facund_uname) != 0) {
 		errx(1, "Could not get the Operating System version\n");
 	}
+	uname_r = getenv("UNAME_r");
+	if (uname_r != NULL) {
+		strlcpy(facund_uname.release, uname_r,
+		    sizeof facund_uname.release);
+	}
 
 	/* Add the callbacks for each call */
 	facund_server_add_call("ping", facund_call_ping);


More information about the p4-projects mailing list