From owner-p4-projects@FreeBSD.ORG Sat Jun 2 22:42:46 2007 Return-Path: X-Original-To: p4-projects@freebsd.org Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 8158A16A476; Sat, 2 Jun 2007 22:42:46 +0000 (UTC) X-Original-To: perforce@freebsd.org Delivered-To: perforce@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 181BA16A46E for ; Sat, 2 Jun 2007 22:42:46 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (repoman.freebsd.org [69.147.83.41]) by mx1.freebsd.org (Postfix) with ESMTP id 0885F13C48A for ; Sat, 2 Jun 2007 22:42:46 +0000 (UTC) (envelope-from andrew@freebsd.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.13.8/8.13.8) with ESMTP id l52Mgjs5017483 for ; Sat, 2 Jun 2007 22:42:45 GMT (envelope-from andrew@freebsd.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.13.8/8.13.8/Submit) id l52MgjvP017471 for perforce@freebsd.org; Sat, 2 Jun 2007 22:42:45 GMT (envelope-from andrew@freebsd.org) Date: Sat, 2 Jun 2007 22:42:45 GMT Message-Id: <200706022242.l52MgjvP017471@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 120803 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: Sat, 02 Jun 2007 22:42:46 -0000 http://perforce.freebsd.org/chv.cgi?CH=120803 Change 120803 by andrew@andrew_hermies on 2007/06/02 22:42:01 Bump WARNS up to 6 Add get_base_dirs that takes a space seperated string of base directories and returns an array of strings of base directories. It doesn't handle directories with spaces in them as it will split them. Read the base_dirs value from the config file Affected files ... .. //depot/projects/soc2007/andrew-update/backend/Makefile#3 edit .. //depot/projects/soc2007/andrew-update/backend/facund-be.c#4 edit .. //depot/projects/soc2007/andrew-update/backend/freebsd-config-control.conf#1 add Differences ... ==== //depot/projects/soc2007/andrew-update/backend/Makefile#3 (text+ko) ==== @@ -4,4 +4,6 @@ MAN= +WARNS= 6 + .include ==== //depot/projects/soc2007/andrew-update/backend/facund-be.c#4 (text+ko) ==== @@ -32,6 +32,7 @@ #include #include +#include #include #include #include @@ -49,8 +50,9 @@ #define DEFAULT_CONFIG_FILE "/etc/freebsd-update-control.conf" #define UPDATE_DATA_DIR "/var/db/freebsd-update" -static int has_update(const char *); -static void* look_for_updates(void *); +static int has_update(const char *); +static void *look_for_updates(void *); +static char **get_base_dirs(char *); /* * Looks for updates on the system with a root of basedir @@ -160,11 +162,72 @@ return NULL; } +/* + * Takes in a string of space seperated directories and returns + * a NULL terminated array of pointers to each directory + */ +char ** +get_base_dirs(char *str) +{ + char *ptr, **ret; + int dir_count; + + /* An empty string will contain no directories */ + if (str == NULL || str[0] == '\0') + return NULL; + + /* Count the number of dirs to read */ + dir_count = 0; + ptr = str; + while (ptr != NULL) { + /* Skip leading spaces */ + while (ptr[0] == ' ') + *ptr++; + + ptr = strchr(ptr, ' '); + dir_count++; + } + + /* + * There must be at least one directory utherwise + * the empty string check would have returned + */ + assert(dir_count > 0); + + /* create an array to hold pointers to the dir names */ + ret = calloc((dir_count + 1) * sizeof(char *), 1); + + + /* Set the point the ret array to the directories */ + dir_count = 0; + ptr = str; + while (ptr != NULL) { + /* Skip leading spaces */ + while (ptr[0] == ' ') + *ptr++; + + /* Point to the directory name */ + ret[dir_count] = ptr; + ptr = strchr(ptr, ' '); + + /* Make the previous directory null terminated */ + if (ptr != NULL) { + ptr[0] = '\0'; + *ptr++; + } + + dir_count++; + } + ret[dir_count] = NULL; + + return ret; +} + int main(int argc __unused, char *argv[] __unused) { - const char *base_dirs[] = { "/", NULL }; const char *config_file; + char *basedirs_string, **base_dirs; int config_fd; properties config_data; char ch; @@ -186,6 +249,8 @@ argc -= optind; argv += optind; + basedirs_string = NULL; + /* Read in the config file */ config_fd = open(config_file, O_RDONLY); if (config_fd == -1 && errno != ENOENT) { @@ -197,11 +262,28 @@ if (config_data == NULL) { errx(1, "Could not read the config file"); } + + basedirs_string = strdup(property_find(config_data, + "base_dirs")); + if (basedirs_string == NULL) { + errx(1, "Malloc failed"); + } + properties_free(config_data); } + /* Read in the base dirs */ + base_dirs = get_base_dirs(basedirs_string); + if (base_dirs == NULL) { + errx(1, "No base dirs were given, set base_dirs in %s", + config_file); + } + look_for_updates(base_dirs); + if (base_dirs != NULL) + free(base_dirs); + free(basedirs_string); return 0; }