PERFORCE change 120613 for review
Andrew Turner
andrew at FreeBSD.org
Wed May 30 10:11:40 UTC 2007
http://perforce.freebsd.org/chv.cgi?CH=120613
Change 120613 by andrew at andrew_hermies on 2007/05/30 10:11:03
Make the back end use getopt to process commandline arguments and read a config file. The config file isn't processed yet.
Affected files ...
.. //depot/projects/soc2007/andrew-update/backend/Makefile#2 edit
.. //depot/projects/soc2007/andrew-update/backend/facund-be.c#3 edit
Differences ...
==== //depot/projects/soc2007/andrew-update/backend/Makefile#2 (text+ko) ====
@@ -1,6 +1,6 @@
PROG= facund-be
-LDADD+= -lmd
+LDADD+= -lutil -lmd
MAN=
==== //depot/projects/soc2007/andrew-update/backend/facund-be.c#3 (text+ko) ====
@@ -33,7 +33,9 @@
#include <sys/time.h>
#include <err.h>
+#include <errno.h>
#include <fcntl.h>
+#include <libutil.h>
#include <limits.h>
#include <sha256.h>
#include <stdio.h>
@@ -44,7 +46,8 @@
/* Check if there are updates every 30min */
static const time_t default_check_period = 30 * 60;
-#define UPDATE_DATA_DIR "/var/db/freebsd-update"
+#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 *);
@@ -161,7 +164,44 @@
main(int argc __unused, char *argv[] __unused)
{
const char *base_dirs[] = { "/", NULL };
+ const char *config_file;
+ int config_fd;
+ properties config_data;
+ char ch;
+
+ config_file = DEFAULT_CONFIG_FILE;
+
+ while ((ch = getopt(argc, argv, "c:h")) != -1) {
+ switch(ch) {
+ case 'c':
+ config_file = optarg;
+ break;
+ case 'h':
+ default:
+ fprintf(stderr, "usage: %s [-c config]\n",
+ getprogname());
+ exit(1);
+ }
+ }
+ argc -= optind;
+ argv += optind;
+
+ /* Read in the config file */
+ config_fd = open(config_file, O_RDONLY);
+ if (config_fd == -1 && errno != ENOENT) {
+ errx(1, "Could not open the config file");
+ } else if (config_fd != -1) {
+ /* Read in the config file */
+ config_data = properties_read(config_fd);
+
+ if (config_data == NULL) {
+ errx(1, "Could not read the config file");
+ }
+ properties_free(config_data);
+ }
+
look_for_updates(base_dirs);
+
return 0;
}
More information about the p4-projects
mailing list