Rename af-... files to afm-...
Add system daemon draft
Change-Id: I3f8b69ac9cc5af54be34b4ad11a512c57c0230b6
src/afm-user-daemon
+src/afm-system-daemon
wgtpkg-installer
wgtpkg-pack
wgtpkg-sign
# limitations under the License.
###########################################################################
+cmake_minimum_required(VERSION 2.8)
+
include(FindPkgConfig)
pkg_check_modules(EXTRAS REQUIRED
)
add_library(afm
- af-db.c
- af-launch.c
- af-run.c
+ afm-db.c
+ afm-launch.c
+ afm-run.c
)
add_executable(wgtpkg-sign wgtpkg-sign.c)
target_link_libraries(wgtpkg-sign wgtpkg utils)
-
add_executable(wgtpkg-pack wgtpkg-pack.c)
target_link_libraries(wgtpkg-pack wgtpkg utils)
-
add_executable(wgtpkg-info wgtpkg-info.c)
target_link_libraries(wgtpkg-info wgtpkg wgt utils)
-
add_executable(wgtpkg-installer wgtpkg-installer.c)
target_link_libraries(wgtpkg-installer wgtpkg wgt secwrp utils)
-
add_executable(afm-user-daemon afm-user-daemon.c)
target_link_libraries(afm-user-daemon afm secwrp wgt utils)
+add_executable(afm-system-daemon afm-system-daemon.c)
+target_link_libraries(afm-system-daemon wgtpkg afm secwrp wgt utils)
+
install(TARGETS wgtpkg-sign wgtpkg-pack wgtpkg-info wgtpkg-installer DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
install(TARGETS afm-user-daemon DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
+install(TARGETS afm-system-daemon DESTINATION ${CMAKE_INSTALL_FULL_BINDIR})
+++ /dev/null
-/*
- Copyright 2015 IoT.bzh
-
- author: José Bollo <jose.bollo@iot.bzh>
-
- Licensed under the Apache License, Version 2.0 (the "License");
- you may not use this file except in compliance with the License.
- You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing, software
- distributed under the License is distributed on an "AS IS" BASIS,
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- See the License for the specific language governing permissions and
- limitations under the License.
-*/
-
-struct af_db;
-
-extern struct af_db *af_db_create();
-extern void af_db_addref(struct af_db *afdb);
-extern void af_db_unref(struct af_db *afdb);
-
-extern int af_db_add_root(struct af_db *afdb, const char *path);
-extern int af_db_add_application(struct af_db *afdb, const char *path);
-extern int af_db_update_applications(struct af_db *afdb);
-extern int af_db_ensure_applications(struct af_db *afdb);
-
-extern struct json_object *af_db_application_list(struct af_db *afdb);
-extern struct json_object *af_db_get_application(struct af_db *afdb, const char *id);
-extern struct json_object *af_db_get_application_public(struct af_db *afdb, const char *id);
-
#include <json.h>
#include "wgt-info.h"
-#include "af-db.h"
+#include "afm-db.h"
struct afapps {
struct json_object *pubarr;
type_app
};
-struct af_db_dir {
- struct af_db_dir *next;
+struct afm_db_dir {
+ struct afm_db_dir *next;
char *path;
enum dir_type type;
};
-struct af_db {
+struct afm_db {
int refcount;
- struct af_db_dir *dirhead;
- struct af_db_dir *dirtail;
+ struct afm_db_dir *dirhead;
+ struct afm_db_dir *dirtail;
struct afapps applications;
};
-struct af_db *af_db_create()
+struct afm_db *afm_db_create()
{
- struct af_db *afdb = malloc(sizeof * afdb);
+ struct afm_db *afdb = malloc(sizeof * afdb);
if (afdb == NULL)
errno = ENOMEM;
else {
return afdb;
}
-void af_db_addref(struct af_db *afdb)
+void afm_db_addref(struct afm_db *afdb)
{
assert(afdb);
afdb->refcount++;
}
-void af_db_unref(struct af_db *afdb)
+void afm_db_unref(struct afm_db *afdb)
{
- struct af_db_dir *dir;
+ struct afm_db_dir *dir;
assert(afdb);
if (!--afdb->refcount) {
json_object_put(afdb->applications.pubarr);
}
}
-int add_dir(struct af_db *afdb, const char *path, enum dir_type type)
+int add_dir(struct afm_db *afdb, const char *path, enum dir_type type)
{
- struct af_db_dir *dir;
+ struct afm_db_dir *dir;
char *r;
assert(afdb);
return 0;
}
-int af_db_add_root(struct af_db *afdb, const char *path)
+int afm_db_add_root(struct afm_db *afdb, const char *path)
{
return add_dir(afdb, path, type_root);
}
-int af_db_add_application(struct af_db *afdb, const char *path)
+int afm_db_add_application(struct afm_db *afdb, const char *path)
{
return add_dir(afdb, path, type_app);
}
}
/* regenerate the list of applications */
-int af_db_update_applications(struct af_db *afdb)
+int afm_db_update_applications(struct afm_db *afdb)
{
int rc;
struct enumdata edata;
struct afapps oldapps;
- struct af_db_dir *dir;
+ struct afm_db_dir *dir;
/* create the result */
edata.apps.pubarr = json_object_new_array();
return -1;
}
-int af_db_ensure_applications(struct af_db *afdb)
+int afm_db_ensure_applications(struct afm_db *afdb)
{
- return afdb->applications.pubarr ? 0 : af_db_update_applications(afdb);
+ return afdb->applications.pubarr ? 0 : afm_db_update_applications(afdb);
}
-struct json_object *af_db_application_list(struct af_db *afdb)
+struct json_object *afm_db_application_list(struct afm_db *afdb)
{
- return af_db_ensure_applications(afdb) ? NULL : afdb->applications.pubarr;
+ return afm_db_ensure_applications(afdb) ? NULL : json_object_get(afdb->applications.pubarr);
}
-struct json_object *af_db_get_application(struct af_db *afdb, const char *id)
+struct json_object *afm_db_get_application(struct afm_db *afdb, const char *id)
{
struct json_object *result;
- if (!af_db_ensure_applications(afdb) && json_object_object_get_ex(afdb->applications.direct, id, &result))
- return result;
+ if (!afm_db_ensure_applications(afdb) && json_object_object_get_ex(afdb->applications.direct, id, &result))
+ return json_object_get(result);
return NULL;
}
-struct json_object *af_db_get_application_public(struct af_db *afdb, const char *id)
+struct json_object *afm_db_get_application_public(struct afm_db *afdb, const char *id)
{
- struct json_object *result = af_db_get_application(afdb, id);
- return result && json_object_object_get_ex(result, "public", &result) ? result : NULL;
+ struct json_object *result = afm_db_get_application(afdb, id);
+ return result && json_object_object_get_ex(result, "public", &result) ? json_object_get(result) : NULL;
}
#include <stdio.h>
int main()
{
-struct af_db *afdb = af_db_create();
-af_db_add_root(afdb,FWK_APP_DIR);
-af_db_update_applications(afdb);
+struct afm_db *afdb = afm_db_create();
+afm_db_add_root(afdb,FWK_APP_DIR);
+afm_db_update_applications(afdb);
printf("array = %s\n", json_object_to_json_string_ext(afdb->applications.pubarr, 3));
printf("direct = %s\n", json_object_to_json_string_ext(afdb->applications.direct, 3));
printf("byapp = %s\n", json_object_to_json_string_ext(afdb->applications.byapp, 3));
--- /dev/null
+/*
+ Copyright 2015 IoT.bzh
+
+ author: José Bollo <jose.bollo@iot.bzh>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+struct afm_db;
+
+extern struct afm_db *afm_db_create();
+extern void afm_db_addref(struct afm_db *afdb);
+extern void afm_db_unref(struct afm_db *afdb);
+
+extern int afm_db_add_root(struct afm_db *afdb, const char *path);
+extern int afm_db_add_application(struct afm_db *afdb, const char *path);
+extern int afm_db_update_applications(struct afm_db *afdb);
+extern int afm_db_ensure_applications(struct afm_db *afdb);
+
+extern struct json_object *afm_db_application_list(struct afm_db *afdb);
+extern struct json_object *afm_db_get_application(struct afm_db *afdb, const char *id);
+extern struct json_object *afm_db_get_application_public(struct afm_db *afdb, const char *id);
+
extern char **environ;
#include "verbose.h"
-#include "af-launch.h"
+#include "afm-launch.h"
#include "secmgr-wrap.h"
/*
const char *datadir;
};
-static char **instantiate_arguments(const char **args, struct af_launch_desc *desc, struct launchparam *params)
+static char **instantiate_arguments(const char **args, struct afm_launch_desc *desc, struct launchparam *params)
{
const char **iter, *p, *v;
char *data, **result, port[20], width[20], height[20], mini[3], c;
return port;
}
-int af_launch(struct af_launch_desc *desc, pid_t children[2])
+int afm_launch(struct afm_launch_desc *desc, pid_t children[2])
{
char datadir[PATH_MAX];
int ikl, nkl, rc;
limitations under the License.
*/
-struct af_launch_desc {
+struct afm_launch_desc {
const char *path;
const char *tag;
const char *appid;
int height;
};
-int af_launch(struct af_launch_desc *desc, pid_t children[2]);
+int afm_launch(struct afm_launch_desc *desc, pid_t children[2]);
#include "verbose.h"
#include "utils-dir.h"
-#include "af-launch.h"
+#include "afm-run.h"
+#include "afm-launch.h"
enum appstate {
as_starting,
}
}
-/**************** handle af_launch_desc *********************/
+/**************** handle afm_launch_desc *********************/
static int get_jstr(struct json_object *obj, const char *key, const char **value)
{
&& ((*value = (int)json_object_get_int(data)), 1);
}
-static int fill_launch_desc(struct json_object *appli, struct af_launch_desc *desc)
+static int fill_launch_desc(struct json_object *appli, struct afm_launch_desc *desc)
{
json_object *pub;
/**************** API handling ************************/
-int af_run_start(struct json_object *appli)
+int afm_run_start(struct json_object *appli)
{
static struct apprun *runner;
- struct af_launch_desc desc;
+ struct afm_launch_desc desc;
int rc;
sigset_t saved, blocked;
sigprocmask(SIG_BLOCK, &blocked, &saved);
/* launch now */
- rc = af_launch(&desc, runner->pids);
+ rc = afm_launch(&desc, runner->pids);
if (rc < 0) {
/* fork failed */
sigprocmask(SIG_SETMASK, &saved, NULL);
- ERROR("can't start, af_launch failed: %m");
+ ERROR("can't start, afm_launch failed: %m");
freerunner(runner);
return -1;
}
return rc;
}
-int af_run_terminate(int runid)
+int afm_run_terminate(int runid)
{
return killrunner(runid, SIGTERM, as_terminating);
}
-int af_run_stop(int runid)
+int afm_run_stop(int runid)
{
return killrunner(runid, SIGSTOP, as_stopped);
}
-int af_run_continue(int runid)
+int afm_run_continue(int runid)
{
return killrunner(runid, SIGCONT, as_running);
}
return NULL;
}
-struct json_object *af_run_list()
+struct json_object *afm_run_list()
{
struct json_object *result, *obj;
struct apprun *runner;
return result;
}
-struct json_object *af_run_state(int runid)
+struct json_object *afm_run_state(int runid)
{
struct apprun *runner = getrunner(runid);
if (runner == NULL || runner->state == as_terminating || runner->state == as_terminated) {
/**************** INITIALISATION **********************/
-int af_run_init()
+int afm_run_init()
{
char buf[2048];
char dir[PATH_MAX];
--- /dev/null
+/*
+ Copyright 2015 IoT.bzh
+
+ author: José Bollo <jose.bollo@iot.bzh>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+extern int afm_run_start(struct json_object *appli);
+extern int afm_run_terminate(int runid);
+extern int afm_run_stop(int runid);
+extern int afm_run_continue(int runid);
+extern struct json_object *afm_run_list();
+extern struct json_object *afm_run_state(int runid);
+
+extern int afm_run_init();
--- /dev/null
+/*
+ Copyright 2015 IoT.bzh
+
+ author: José Bollo <jose.bollo@iot.bzh>
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+*/
+
+#include <unistd.h>
+#include <stdio.h>
+#include <time.h>
+#include <getopt.h>
+
+#include <json.h>
+
+#include "verbose.h"
+#include "utils-jbus.h"
+#include "afm.h"
+#include "afm-db.h"
+
+static const char appname[] = "afm-system-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 afm_db *afdb;
+
+const char error_nothing[] = "[]";
+const char error_bad_request[] = "\"bad request\"";
+const char error_not_found[] = "\"not found\"";
+const char error_cant_start[] = "\"can't start\"";
+
+static const char *getappid(struct json_object *obj)
+{
+ return json_type_string == json_object_get_type(obj) ? json_object_get_string(obj) : NULL;
+}
+
+static void reply(struct jreq *jreq, struct json_object *resp, const char *errstr)
+{
+ if (resp)
+ jbus_reply_j(jreq, resp);
+ else
+ jbus_reply_error_s(jreq, errstr);
+}
+
+static void on_runnables(struct jreq *jreq, struct json_object *obj)
+{
+ struct json_object *resp = afm_db_application_list(afdb);
+ jbus_reply_j(jreq, resp);
+ json_object_put(resp);
+}
+
+static void on_detail(struct jreq *jreq, struct json_object *obj)
+{
+ const char *appid = getappid(obj);
+ struct json_object *resp = afm_db_get_application_public(afdb, appid);
+ reply(jreq, resp, error_not_found);
+ json_object_put(resp);
+}
+
+extern void install_widget(const char *wgtfile, const char *root, int force);
+static void on_install(struct jreq *jreq, struct json_object *obj)
+{
+ jbus_reply_error_s(jreq, "\"not yet implemented\"");
+}
+
+static void on_uninstall(struct jreq *jreq, struct json_object *obj)
+{
+ jbus_reply_error_s(jreq, "\"not yet implemented\"");
+}
+
+static int daemonize()
+{
+ int rc = fork();
+ if (rc < 0)
+ return rc;
+ if (rc)
+ _exit(0);
+ return 0;
+}
+
+int main(int ac, char **av)
+{
+ 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 framework */
+ afdb = afm_db_create();
+ if (!afdb) {
+ ERROR("afm_create failed");
+ return 1;
+ }
+ if (afm_db_add_root(afdb, FWK_APP_DIR)) {
+ 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 (afm_db_add_root(afdb, optarg)) {
+ ERROR("can't add root %s", optarg);
+ return 1;
+ }
+ break;
+ case 'a':
+ if (afm_db_add_application(afdb, optarg)) {
+ ERROR("can't add application %s", optarg);
+ return 1;
+ }
+ break;
+ }
+ }
+
+ /* update the database */
+ if (afm_db_update_applications(afdb)) {
+ ERROR("afm_update_applications failed");
+ return 1;
+ }
+
+ if (daemon && daemonize()) {
+ ERROR("daemonization failed");
+ return 1;
+ }
+
+ /* init service */
+ jbus = create_jbus(0, AFM_SYSTEM_DBUS_PATH);
+ if (!jbus) {
+ ERROR("create_jbus failed");
+ return 1;
+ }
+ if(jbus_add_service_j(jbus, "runnables", on_runnables)
+ || jbus_add_service_j(jbus, "detail", on_detail)
+ || jbus_add_service_j(jbus, "install", on_install)
+ || jbus_add_service_j(jbus, "uninstall", on_uninstall)) {
+ ERROR("adding services failed");
+ return 1;
+ }
+
+ /* start and run */
+ if (jbus_start_serving(jbus)) {
+ ERROR("cant start server");
+ return 1;
+ }
+ while (!jbus_read_write_dispatch(jbus, -1));
+ return 0;
+}
+
#include "verbose.h"
#include "utils-jbus.h"
-#include "af-db.h"
-#include "af-run.h"
+#include "afm.h"
+#include "afm-db.h"
+#include "afm-run.h"
static const char appname[] = "afm-user-daemon";
};
static struct jbus *jbus;
-static struct af_db *afdb;
+static struct jbus *jbusys;
+static struct afm_db *afdb;
const char error_nothing[] = "[]";
const char error_bad_request[] = "\"bad request\"";
static void on_runnables(struct jreq *jreq, struct json_object *obj)
{
- struct json_object *resp = af_db_application_list(afdb);
+ struct json_object *resp = afm_db_application_list(afdb);
jbus_reply_j(jreq, resp);
- json_object_put(obj);
+ json_object_put(resp);
}
static void on_detail(struct jreq *jreq, struct json_object *obj)
{
const char *appid = getappid(obj);
- struct json_object *resp = af_db_get_application_public(afdb, appid);
+ struct json_object *resp = afm_db_get_application_public(afdb, appid);
reply(jreq, resp, error_not_found);
- json_object_put(obj);
+ json_object_put(resp);
}
static void on_start(struct jreq *jreq, struct json_object *obj)
if (appid == NULL)
jbus_reply_error_s(jreq, error_bad_request);
else {
- appli = af_db_get_application(afdb, appid);
+ appli = afm_db_get_application(afdb, appid);
if (appli == NULL)
jbus_reply_error_s(jreq, error_not_found);
else {
- runid = af_run_start(appli);
+ runid = afm_run_start(appli);
if (runid <= 0)
jbus_reply_error_s(jreq, error_cant_start);
else {
}
}
}
- json_object_put(obj);
}
static void on_stop(struct jreq *jreq, struct json_object *obj)
{
int runid = getrunid(obj);
- int status = af_run_stop(runid);
+ int status = afm_run_stop(runid);
reply_status(jreq, status);
- json_object_put(obj);
}
static void on_continue(struct jreq *jreq, struct json_object *obj)
{
int runid = getrunid(obj);
- int status = af_run_continue(runid);
+ int status = afm_run_continue(runid);
reply_status(jreq, status);
- json_object_put(obj);
}
static void on_terminate(struct jreq *jreq, struct json_object *obj)
{
int runid = getrunid(obj);
- int status = af_run_terminate(runid);
+ int status = afm_run_terminate(runid);
reply_status(jreq, status);
- json_object_put(obj);
}
static void on_runners(struct jreq *jreq, struct json_object *obj)
{
- struct json_object *resp = af_run_list();
+ struct json_object *resp = afm_run_list();
jbus_reply_j(jreq, resp);
json_object_put(resp);
- json_object_put(obj);
}
static void on_state(struct jreq *jreq, struct json_object *obj)
{
int runid = getrunid(obj);
- struct json_object *resp = af_run_state(runid);
+ struct json_object *resp = afm_run_state(runid);
reply(jreq, resp, error_not_found);
json_object_put(resp);
- json_object_put(obj);
+}
+
+static void on_signal_changed(struct json_object *obj)
+{
+ /* update the database */
+ afm_db_update_applications(afdb);
+ /* propagate now */
+ jbus_send_signal_j(jbus, "changed", obj);
}
static int daemonize()
srandom((unsigned int)time(NULL));
/* init runners */
- if (af_run_init()) {
- ERROR("af_run_init failed");
+ if (afm_run_init()) {
+ ERROR("afm_run_init failed");
return 1;
}
/* init framework */
- afdb = af_db_create();
+ afdb = afm_db_create();
if (!afdb) {
- ERROR("af_create failed");
+ ERROR("afm_create failed");
return 1;
}
- if (af_db_add_root(afdb, FWK_APP_DIR)) {
+ if (afm_db_add_root(afdb, FWK_APP_DIR)) {
ERROR("can't add root %s", FWK_APP_DIR);
return 1;
}
while ((i = getopt_long(ac, av, "hdqvr:a:", options, NULL)) >= 0) {
switch (i) {
case 'r':
- if (af_db_add_root(afdb, optarg)) {
+ if (afm_db_add_root(afdb, optarg)) {
ERROR("can't add root %s", optarg);
return 1;
}
break;
case 'a':
- if (af_db_add_application(afdb, optarg)) {
+ if (afm_db_add_application(afdb, optarg)) {
ERROR("can't add application %s", optarg);
return 1;
}
}
/* update the database */
- if (af_db_update_applications(afdb)) {
- ERROR("af_update_applications failed");
+ if (afm_db_update_applications(afdb)) {
+ ERROR("afm_update_applications failed");
return 1;
}
return 1;
}
+ /* init observers */
+ jbusys = create_jbus(0, AFM_SYSTEM_DBUS_PATH);
+ if (!jbusys) {
+ ERROR("create_jbus failed for system");
+ return 1;
+ }
+ if(jbus_on_signal_j(jbusys, "changed", on_signal_changed)) {
+ ERROR("adding signal observer failed");
+ return 1;
+ }
+
/* init service */
- jbus = create_jbus(1, "/org/AGL/afmMain");
+ jbus = create_jbus(1, AFM_USER_DBUS_PATH);
if (!jbus) {
ERROR("create_jbus failed");
return 1;
limitations under the License.
*/
-extern int af_run_start(struct json_object *appli);
-extern int af_run_terminate(int runid);
-extern int af_run_stop(int runid);
-extern int af_run_continue(int runid);
-extern struct json_object *af_run_list();
-extern struct json_object *af_run_state(int runid);
+#define AFM_DBUS_PATH "/org/AGL/afm"
+#define AFM_SYSTEM_DBUS_PATH AFM_DBUS_PATH"/system"
+#define AFM_USER_DBUS_PATH AFM_DBUS_PATH"/user"
-extern int af_run_init();
reply = json_tokener_parse(str);
status = reply ? 0 : -1;
jrw->onresp_j(iserror ? -1 : status, reply, jrw->data);
+ json_object_put(reply);
}
free(jrw);
if (query == NULL)
return reply_invalid_request(jreq);
srv->oncall_j(jreq, query);
+ json_object_put(query);
}
return DBUS_HANDLER_RESULT_HANDLED;
}
else {
/* handling json only */
obj = json_tokener_parse(str);
- if (obj != NULL)
+ if (obj != NULL) {
sig->onsignal_j(obj);
+ json_object_put(obj);
+ }
}
}
return DBUS_HANDLER_RESULT_HANDLED;
struct json_object *jbus_call_sj_sync(struct jbus *jbus, const char *method, const char *query)
{
- const char *str = jbus_call_ss_sync(jbus, method, query);
- return str ? json_tokener_parse(str) : NULL;
+ struct json_object *obj;
+ char *str = jbus_call_ss_sync(jbus, method, query);
+ if (str == NULL)
+ obj = NULL;
+ else {
+ obj = json_tokener_parse(str);
+ free(str);
+ }
+ return obj;
}
-
char *jbus_call_js_sync(struct jbus *jbus, const char *method, struct json_object *query)
{
const char *str = json_object_to_json_string(query);
}
/* install the widget of the file */
-void install_widget(const char *wgtfile, const char *root, int force)
+int install_widget(const char *wgtfile, const char *root, int force)
{
struct wgt_info *ifo;
const struct wgt_desc *desc;
- NOTICE("-- INSTALLING widget %s --", wgtfile);
+ NOTICE("-- INSTALLING widget %s to %s --", wgtfile, root);
/* workdir */
create_directory(root, 0755, 1);
if (install_security(desc))
goto error3;
- return;
+ return 0;
error3:
wgt_info_unref(ifo);
remove_workdir();
error1:
- return;
+ return -1;
}
/**************************************************************/
/* from wgtpkg-install */
-extern void install_widget(const char *wgtfile, const char *root, int force);
+extern int install_widget(const char *wgtfile, const char *root, int force);
/**************************************************************/
/* from wgtpkg-permission */