PERFORCE change 124309 for review
Andrew Turner
andrew at FreeBSD.org
Sun Jul 29 11:50:20 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=124309
Change 124309 by andrew at andrew_hermies on 2007/07/29 11:49:45
Decode lines from the tag file. These contain information about patch levels avaliable to us
Affected files ...
.. //depot/projects/soc2007/andrew-update/backend/facund-be.c#19 edit
Differences ...
==== //depot/projects/soc2007/andrew-update/backend/facund-be.c#19 (text+ko) ====
@@ -58,6 +58,8 @@
#define DEFAULT_CONFIG_FILE "/etc/freebsd-update-control.conf"
#define UPDATE_DATA_DIR "/var/db/freebsd-update"
+static struct fbsd_tag_line *facund_tag_decode_line(const char *);
+static void facund_tag_free(struct fbsd_tag_line *);
static int facund_has_update(unsigned int);
static void *look_for_updates(void *);
static int facund_read_base_dirs(const char *);
@@ -93,19 +95,128 @@
char *db_base;
char *db_dir;
int db_fd;
+
+ char *db_tag_file;
};
static unsigned int watched_db_count = 0;
static struct fbsd_update_db *watched_db = NULL;
+struct fbsd_tag_line {
+ char *tag_platform;
+ char *tag_release;
+ char *tag_patch;
+ char tag_tindexhash[65];
+ char tag_eol[11];
+};
+
/*
+ * Decodes the data in a line from the tag file
+ */
+static struct fbsd_tag_line *
+facund_tag_decode_line(const char *buf)
+{
+ struct fbsd_tag_line *line;
+ unsigned int len, item;
+ const char *str, *ptr;
+
+ if (buf == NULL)
+ return NULL;
+
+ line = calloc(sizeof(struct fbsd_tag_line), 1);
+ if (line == NULL)
+ return NULL;
+
+ str = buf;
+ ptr = NULL;
+
+ for (item = 0, ptr = strchr(str, '|'); ptr != NULL;
+ ptr = strchr(str, '|')) {
+ len = ptr - str;
+
+ switch (item) {
+ case 0:
+ if (strncmp("freebsd-update", str, len) != 0)
+ goto facund_decode_tag_line_exit;
+ break;
+ case 1:
+ line->tag_platform = malloc(len + 1);
+ if (line->tag_platform == NULL)
+ goto facund_decode_tag_line_exit;
+
+ strlcpy(line->tag_platform, str, len + 1);
+ break;
+ case 2:
+ line->tag_release = malloc(len + 1);
+ if (line->tag_release == NULL)
+ goto facund_decode_tag_line_exit;
+
+ strlcpy(line->tag_release, str, len + 1);
+ break;
+ case 3:
+ line->tag_patch = malloc(len + 1);
+ if (line->tag_patch == NULL)
+ goto facund_decode_tag_line_exit;
+
+ strlcpy(line->tag_patch, str, len + 1);
+ break;
+ case 4:
+ if (len != 64)
+ goto facund_decode_tag_line_exit;
+
+ strlcpy(line->tag_tindexhash, str, 65);
+ break;
+ }
+
+ str = ptr + 1;
+ item++;
+ }
+ if (item != 5) {
+ goto facund_decode_tag_line_exit;
+ } else {
+ if (strlen(str) != 11)
+ goto facund_decode_tag_line_exit;
+
+ strlcpy(line->tag_eol, str, 11);
+ }
+
+ return line;
+
+facund_decode_tag_line_exit:
+ /* Clean up on failure */
+ facund_tag_free(line);
+
+ return NULL;
+}
+
+static void
+facund_tag_free(struct fbsd_tag_line *line)
+{
+ if (line == NULL)
+ return;
+
+ if (line->tag_platform != NULL)
+ free(line->tag_platform);
+
+ if (line->tag_release != NULL)
+ free(line->tag_release);
+
+ if (line->tag_patch != NULL)
+ free(line->tag_patch);
+
+ free(line);
+}
+
+/*
* Looks for updates on the system with a root of basedir
*/
static int
facund_has_update(unsigned int pos)
{
struct stat sb;
- char install_link[PATH_MAX], sha_base[PATH_MAX], sum[65];
+ FILE *tag_fd;
+ char install_link[PATH_MAX], sha_base[PATH_MAX], sum[65], buf[1024];
+ struct fbsd_tag_line *line;
assert(pos < watched_db_count);
snprintf(sha_base, PATH_MAX, "%s\n", watched_db[pos].db_base);
@@ -115,8 +226,17 @@
/* Look for the install link and check if it is a symlink */
if (lstat(install_link, &sb) == 0) {
- if (S_ISLNK(sb.st_mode))
+ if (S_ISLNK(sb.st_mode)) {
+ tag_fd = fopen(watched_db[pos].db_tag_file, "r");
+ while (fgets(buf, sizeof buf, tag_fd) != NULL) {
+ line = facund_tag_decode_line(buf);
+ if (line != NULL) {
+ facund_tag_free(line);
+ }
+ }
+ fclose(tag_fd);
return 1;
+ }
}
return 0;
}
@@ -324,7 +444,18 @@
strlcpy(watched_db[pos].db_base, ptr, len);
asprintf(&watched_db[pos].db_dir, "%s" UPDATE_DATA_DIR,
watched_db[pos].db_base);
- printf("%s\n", watched_db[pos].db_dir);
+ if (watched_db[pos].db_dir == NULL) {
+ free(watched_db[pos].db_base);
+ return -1;
+ }
+
+ asprintf(&watched_db[pos].db_tag_file, "%s/tag",
+ watched_db[pos].db_dir);
+ if (watched_db[pos].db_dir == NULL) {
+ free(watched_db[pos].db_base);
+ free(watched_db[pos].db_dir);
+ return -1;
+ }
ptr = next_ptr;
if (ptr[0] == '\0') {
More information about the p4-projects
mailing list