From owner-p4-projects@FreeBSD.ORG Sun Aug 19 11:09:07 2007 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 35BEC16A41A; Sun, 19 Aug 2007 11:09:07 +0000 (UTC) Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id EF2A316A417 for ; Sun, 19 Aug 2007 11:09:06 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id DE8D613C428 for ; Sun, 19 Aug 2007 11:09:06 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.1/8.14.1) with ESMTP id l7JB96CH010350 for ; Sun, 19 Aug 2007 11:09:06 GMT (envelope-from andrew@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.1/8.14.1/Submit) id l7JB964L010347 for perforce@freebsd.org; Sun, 19 Aug 2007 11:09:06 GMT (envelope-from andrew@freebsd.org) Date: Sun, 19 Aug 2007 11:09:06 GMT Message-Id: <200708191109.l7JB964L010347@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to andrew@freebsd.org using -f From: Andrew Turner To: Perforce Change Reviews Cc: Subject: PERFORCE change 125341 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 19 Aug 2007 11:09:07 -0000 http://perforce.freebsd.org/chv.cgi?CH=125341 Change 125341 by andrew@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);