aboutsummaryrefslogtreecommitdiffstats
path: root/src/afm-user-daemon.c
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2015-12-22 11:45:02 +0100
committerJosé Bollo <jose.bollo@iot.bzh>2015-12-22 11:45:02 +0100
commite2f138ca6b0f61d1a1cde1fd305dd7f0aaf4aa0e (patch)
tree1ca181160b36caed48cc42b3d482860cf3fa62ef /src/afm-user-daemon.c
parent658c4a1fe18f6dee5063f899a449ea7020c99828 (diff)
allows to add directories
Change-Id: I574a09d4ce3dcfe84e4744ea8f0ae4abf1277a1d
Diffstat (limited to 'src/afm-user-daemon.c')
-rw-r--r--src/afm-user-daemon.c89
1 files changed, 86 insertions, 3 deletions
diff --git a/src/afm-user-daemon.c b/src/afm-user-daemon.c
index 4990ff7..346c58b 100644
--- a/src/afm-user-daemon.c
+++ b/src/afm-user-daemon.c
@@ -19,6 +19,7 @@
#include <unistd.h>
#include <stdio.h>
#include <time.h>
+#include <getopt.h>
#include <json.h>
@@ -27,6 +28,33 @@
#include "af-db.h"
#include "af-run.h"
+static const char appname[] = "afm-user-daemon";
+
+static void usage()
+{
+ printf(
+ "usage: %s [-q] [-v] [-r rootdir]... [-a appdir]...\n"
+ "\n"
+ " -a appdir adds an application directory\n"
+ " -r rootdir adds a root directory of applications\n"
+ " -d run as a daemon\n"
+ " -q quiet\n"
+ " -v verbose\n"
+ "\n",
+ appname
+ );
+}
+
+static struct option options[] = {
+ { "root", required_argument, NULL, 'r' },
+ { "application", required_argument, NULL, 'a' },
+ { "daemon", no_argument, NULL, 'd' },
+ { "quiet", no_argument, NULL, 'q' },
+ { "verbose", no_argument, NULL, 'v' },
+ { "help", no_argument, NULL, 'h' },
+ { NULL, 0, NULL, 0 }
+};
+
static struct jbus *jbus;
static struct af_db *afdb;
@@ -157,7 +185,38 @@ static int daemonize()
int main(int ac, char **av)
{
- LOGAUTH("afm-main-daemon");
+ int i, daemon = 0;
+
+ LOGAUTH(appname);
+
+ /* first interpretation of arguments */
+ while ((i = getopt_long(ac, av, "hdqvr:a:", options, NULL)) >= 0) {
+ switch (i) {
+ case 'h':
+ usage();
+ return 0;
+ case 'q':
+ if (verbosity)
+ verbosity--;
+ break;
+ case 'v':
+ verbosity++;
+ break;
+ case 'd':
+ daemon = 1;
+ break;
+ case 'r':
+ break;
+ case 'a':
+ break;
+ case ':':
+ ERROR("missing argument value");
+ return 1;
+ default:
+ ERROR("unrecognized option");
+ return 1;
+ }
+ }
/* init random generator */
srandom((unsigned int)time(NULL));
@@ -178,11 +237,37 @@ int main(int ac, char **av)
ERROR("can't add root %s", FWK_APP_DIR);
return 1;
}
+
+ /* second interpretation of arguments */
+ optind = 1;
+ while ((i = getopt_long(ac, av, "hdqvr:a:", options, NULL)) >= 0) {
+ switch (i) {
+ case 'r':
+ if (af_db_add_root(afdb, optarg)) {
+ ERROR("can't add root %s", optarg);
+ return 1;
+ }
+ break;
+ case 'a':
+ if (af_db_add_application(afdb, optarg)) {
+ ERROR("can't add application %s", optarg);
+ return 1;
+ }
+ break;
+ }
+ }
+
+ /* update the database */
if (af_db_update_applications(afdb)) {
ERROR("af_update_applications failed");
return 1;
}
+ if (daemon && daemonize()) {
+ ERROR("daemonization failed");
+ return 1;
+ }
+
/* init service */
jbus = create_jbus(1, "/org/AGL/afmMain");
if (!jbus) {
@@ -210,5 +295,3 @@ int main(int ac, char **av)
return 0;
}
-
-