fix missing encoded_id related change & code clearing.
[platform/core/appfw/app2sd.git] / plugin / app2sd / src / app2sd_server.c
1 /*
2  * app2sd-server
3  *
4  * Copyright (c) 2016 Samsung Electronics Co., Ltd. All rights reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  */
19
20 #include <gio/gio.h>
21
22 #include "app2sd_internals.h"
23
24 GMainLoop *app2sd_mainloop = NULL;
25
26 gboolean __exit_app2sd_server(void *data)
27 {
28         _D("exit app2sd_server");
29
30         g_main_loop_quit(app2sd_mainloop);
31
32         return FALSE;
33 }
34
35 static int __app2sd_get_sender_unixinfo(GDBusConnection *conn,
36                 const char *sender_name, const char *type)
37 {
38         GDBusMessage *msg = NULL;
39         GDBusMessage *reply = NULL;
40         GError *err = NULL;
41         GVariant *body;
42         int ret = -1;
43         unsigned int value;
44
45         msg = g_dbus_message_new_method_call("org.freedesktop.DBus",
46                 "/org/freedesktop/DBus", "org.freedesktop.DBus", type);
47         if (!msg) {
48                 _E("Can't allocate new method call");
49                 goto out;
50         }
51
52         g_dbus_message_set_body(msg, g_variant_new("(s)", sender_name));
53         reply = g_dbus_connection_send_message_with_reply_sync(conn, msg,
54                 G_DBUS_SEND_MESSAGE_FLAGS_NONE, -1, NULL, NULL, &err);
55
56         if (!reply) {
57                 if (err != NULL) {
58                         _E("Failed to get info [%s]", err->message);
59                         g_error_free(err);
60                 }
61                 goto out;
62         }
63
64         body = g_dbus_message_get_body(reply);
65         g_variant_get(body, "(u)", &value);
66         ret = (int)value;
67
68 out:
69         if (msg)
70                 g_object_unref(msg);
71         if (reply)
72                 g_object_unref(reply);
73
74         return ret;
75 }
76
77 /*
78 static int __app2sd_get_sender_pid(GDBusConnection *conn,
79                 const char *sender_name)
80 {
81         int pid = 0;
82
83         pid = __app2sd_get_sender_unixinfo(conn, sender_name,
84                 "GetConnectionUnixProcessID");
85         if (pid < 0) {
86                 _E("failed to get pid");
87                 pid = 0;
88         }
89
90         _D("sender_name(%s), pid(%d)", sender_name, pid);
91
92         return pid;
93 }
94 */
95
96 static int __app2sd_get_sender_uid(GDBusConnection *conn,
97                 const char *sender_name)
98 {
99         int uid = -1;
100
101         uid = __app2sd_get_sender_unixinfo(conn, sender_name,
102                 "GetConnectionUnixUser");
103         if (uid < 0) {
104                 _E("failed to get uid");
105         }
106
107         _D("sender_name(%s), uid(%d)", sender_name, uid);
108
109         return uid;
110 }
111
112 static GDBusNodeInfo *introspection_data;
113 static const gchar introspection_xml[] =
114 "<node>"
115 "       <interface name='org.tizen.app2sd'>"
116 "               <method name='PreAppInstall'>"
117 "                       <arg type='s' name='pkgid' direction='in'/>"
118 "                       <arg type='i' name='size' direction='in'/>"
119 "                       <arg type='a(si)' name='dir_list' direction='in'/>"
120 "                       <arg type='i' name='uid' direction='in'/>"
121 "                       <arg type='i' name='result' direction='out'/>"
122 "               </method>"
123 "               <method name='PostAppInstall'>"
124 "                       <arg type='s' name='pkgid' direction='in'/>"
125 "                       <arg type='i' name='install_status' direction='in'/>"
126 "                       <arg type='i' name='uid' direction='in'/>"
127 "                       <arg type='i' name='result' direction='out'/>"
128 "               </method>"
129 "               <method name='PreAppUpgrade'>"
130 "                       <arg type='s' name='pkgid' direction='in'/>"
131 "                       <arg type='i' name='size' direction='in'/>"
132 "                       <arg type='a(si)' name='dir_list' direction='in'/>"
133 "                       <arg type='i' name='uid' direction='in'/>"
134 "                       <arg type='i' name='result' direction='out'/>"
135 "               </method>"
136 "               <method name='PostAppUpgrade'>"
137 "                       <arg type='s' name='pkgid' direction='in'/>"
138 "                       <arg type='i' name='install_status' direction='in'/>"
139 "                       <arg type='i' name='uid' direction='in'/>"
140 "                       <arg type='i' name='result' direction='out'/>"
141 "               </method>"
142 "               <method name='PreAppUninstall'>"
143 "                       <arg type='s' name='pkgid' direction='in'/>"
144 "                       <arg type='i' name='uid' direction='in'/>"
145 "                       <arg type='i' name='result' direction='out'/>"
146 "               </method>"
147 "               <method name='PostAppUninstall'>"
148 "                       <arg type='s' name='pkgid' direction='in'/>"
149 "                       <arg type='i' name='uid' direction='in'/>"
150 "                       <arg type='i' name='result' direction='out'/>"
151 "               </method>"
152 "               <method name='OndemandSetupInit'>"
153 "                       <arg type='s' name='pkgid' direction='in'/>"
154 "                       <arg type='i' name='uid' direction='in'/>"
155 "                       <arg type='i' name='result' direction='out'/>"
156 "               </method>"
157 "               <method name='OndemandSetupExit'>"
158 "                       <arg type='s' name='pkgid' direction='in'/>"
159 "                       <arg type='i' name='uid' direction='in'/>"
160 "                       <arg type='i' name='result' direction='out'/>"
161 "               </method>"
162 "               <method name='MoveInstalledApp'>"
163 "                       <arg type='s' name='pkgid' direction='in'/>"
164 "                       <arg type='i' name='move_type' direction='in'/>"
165 "                       <arg type='a(si)' name='dir_list' direction='in'/>"
166 "                       <arg type='i' name='uid' direction='in'/>"
167 "                       <arg type='i' name='result' direction='out'/>"
168 "               </method>"
169 "       </interface>"
170 "</node>";
171
172 static void _app2sd_server_return_method_error(GDBusMethodInvocation *invocation, int result)
173 {
174         GVariant *param = NULL;
175
176         param = g_variant_new("(i)", result);
177         g_dbus_method_invocation_return_value(invocation, param);
178 }
179
180 static void _app2sd_server_pre_app_install(GDBusConnection *connection, const gchar *sender,
181         GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
182 {
183         GVariant *param = NULL;
184         int result = APP2EXT_SUCCESS;
185         int size;
186         char *pkgid = NULL;
187         GVariantIter *iter;
188         gchar *str = NULL;
189         int type;
190         int ret = 0;
191         uid_t target_uid = -1;
192         GList *dir_list = NULL;
193         GList *list = NULL;
194         app2ext_dir_details *dir_detail = NULL;
195
196         g_variant_get(parameters, "(&sia(si)i)", &pkgid, &size, &iter, &target_uid);
197
198         _D("pkgid(%s), size(%d),sender_uid(%d), target_uid(%d)",
199                 pkgid, size, sender_uid, target_uid);
200
201         if (sender_uid != 0 && sender_uid != target_uid) {
202                 _E("Not permitted user!");
203                 g_variant_iter_free(iter);
204                 _app2sd_server_return_method_error(invocation,
205                         APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
206                 return;
207         }
208
209         while (g_variant_iter_loop(iter, "(si)", &str, &type)) {
210                 if (str) {
211                         _D("str(%s), type(%d)", str, type);
212
213                         /* generate dir_list */
214                         dir_detail = (app2ext_dir_details *)calloc(1, sizeof(app2ext_dir_details));
215                         if (dir_detail == NULL) {
216                                 _E("memory allocation failed");
217                                 result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
218                                 break;
219                         }
220
221                         dir_detail->name = strdup((char *)str);
222                         if (dir_detail->name == NULL) {
223                                 _E("out of memory");
224                                 free(dir_detail);
225                                 result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
226                                 break;
227                         }
228
229                         dir_detail->type = type;
230                         list = g_list_append(list, dir_detail);
231                 }
232         }
233         g_variant_iter_free(iter);
234
235         dir_list = g_list_first(list);
236         ret = app2sd_usr_pre_app_install(pkgid, dir_list, size, target_uid);
237         if (ret) {
238                 _E("error(%d)", ret);
239                 result = ret;
240         }
241
242         param = g_variant_new("(i)", result);
243         g_dbus_method_invocation_return_value(invocation, param);
244 }
245
246 static void _app2sd_server_post_app_install(GDBusConnection *connection, const gchar *sender,
247         GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
248 {
249         GVariant *param = NULL;
250         int result = APP2EXT_SUCCESS;
251         char *pkgid = NULL;
252         int install_status = 0;
253         int target_uid = -1;
254         int ret = 0;
255
256         g_variant_get(parameters, "(&sii)", &pkgid, &install_status, &target_uid);
257
258         _D("pkgid(%s), install_status(%d), sender_uid(%d), target_uid(%d)",
259                 pkgid, install_status, sender_uid, target_uid);
260
261         if (sender_uid != 0 && sender_uid != target_uid) {
262                 _E("Not permitted user!");
263                 _app2sd_server_return_method_error(invocation,
264                         APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
265                 return;
266         }
267
268         ret = app2sd_usr_post_app_install(pkgid, install_status, target_uid);
269         if (ret) {
270                 _E("error(%d)", ret);
271                 result = ret;
272         }
273
274         param = g_variant_new("(i)", result);
275         g_dbus_method_invocation_return_value(invocation, param);
276 }
277
278 static void _app2sd_server_pre_app_upgrade(GDBusConnection *connection, const gchar *sender,
279         GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
280 {
281         GVariant *param = NULL;
282         int result = APP2EXT_SUCCESS;
283         int size;
284         char *pkgid = NULL;
285         GVariantIter *iter;
286         gchar *str = NULL;
287         int type;
288         uid_t target_uid = -1;
289         int ret = 0;
290         GList *dir_list = NULL;
291         GList *list = NULL;
292         app2ext_dir_details *dir_detail = NULL;
293
294         g_variant_get(parameters, "(&sia(si)i)", &pkgid, &size, &iter, &target_uid);
295
296         _D("pkgid(%s), size(%d), sender_uid(%d), target_uid(%d)",
297                 pkgid, size, sender_uid, target_uid);
298
299         if (sender_uid != 0 && sender_uid != target_uid) {
300                 _E("Not permitted user!");
301                 g_variant_iter_free(iter);
302                 _app2sd_server_return_method_error(invocation,
303                         APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
304                 return;
305         }
306
307         while (g_variant_iter_loop(iter, "(si)", &str, &type)) {
308                 if (str) {
309                         _D("str(%s), type(%d)", str, type);
310
311                         /* generate dir_list */
312                         dir_detail = (app2ext_dir_details *)calloc(1, sizeof(app2ext_dir_details));
313                         if (dir_detail == NULL) {
314                                 _E("memory allocation failed");
315                                 result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
316                                 break;
317                         }
318
319                         dir_detail->name = strdup((char *)str);
320                         if (dir_detail->name == NULL) {
321                                 _E("out of memory");
322                                 free(dir_detail);
323                                 result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
324                                 break;
325                         }
326
327                         dir_detail->type = type;
328                         list = g_list_append(list, dir_detail);
329                 }
330         }
331         g_variant_iter_free(iter);
332
333         dir_list = g_list_first(list);
334         ret = app2sd_usr_pre_app_upgrade(pkgid, dir_list, size, target_uid);
335         if (ret) {
336                 _E("error(%d)", ret);
337                 result = ret;
338         }
339
340         param = g_variant_new("(i)", result);
341         g_dbus_method_invocation_return_value(invocation, param);
342 }
343
344 static void _app2sd_server_post_app_upgrade(GDBusConnection *connection, const gchar *sender,
345         GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
346 {
347         GVariant *param = NULL;
348         int result = APP2EXT_SUCCESS;
349         char *pkgid = NULL;
350         int install_status = 0;
351         uid_t target_uid = -1;
352         int ret = 0;
353
354         g_variant_get(parameters, "(&sii)", &pkgid, &install_status, &target_uid);
355
356         _D("pkgid(%s), install_status(%d), sender_uid(%d), target_uid(%d)",
357                 pkgid, install_status, sender_uid, target_uid);
358
359         if (sender_uid != 0 && sender_uid != target_uid) {
360                 _E("Not permitted user!");
361                 _app2sd_server_return_method_error(invocation,
362                         APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
363                 return;
364         }
365
366         ret = app2sd_usr_post_app_upgrade(pkgid, install_status, target_uid);
367         if (ret) {
368                 _E("error(%d)", ret);
369                 result = ret;
370         }
371
372         param = g_variant_new("(i)", result);
373         g_dbus_method_invocation_return_value(invocation, param);
374 }
375
376 static void _app2sd_server_pre_app_uninstall(GDBusConnection *connection, const gchar *sender,
377         GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
378 {
379         GVariant *param = NULL;
380         int result = APP2EXT_SUCCESS;
381         char *pkgid = NULL;
382         uid_t target_uid = -1;
383         int ret = 0;
384
385         g_variant_get(parameters, "(&si)", &pkgid, &target_uid);
386
387         _D("pkgid(%s), sender_uid(%d), target_uid(%d)",
388                 pkgid, sender_uid, target_uid);
389
390         if (sender_uid != 0 && sender_uid != target_uid) {
391                 _E("Not permitted user!");
392                 _app2sd_server_return_method_error(invocation,
393                         APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
394                 return;
395         }
396
397         ret = app2sd_usr_pre_app_uninstall(pkgid, target_uid);
398         if (ret) {
399                 _E("error(%d)", ret);
400                 result = ret;
401         }
402
403         param = g_variant_new("(i)", result);
404         g_dbus_method_invocation_return_value(invocation, param);
405 }
406
407 static void _app2sd_server_post_app_uninstall(GDBusConnection *connection, const gchar *sender,
408         GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
409 {
410         GVariant *param = NULL;
411         int result = APP2EXT_SUCCESS;
412         char *pkgid = NULL;
413         uid_t target_uid = -1;
414         int ret = 0;
415
416         g_variant_get(parameters, "(&si)", &pkgid, &target_uid);
417
418         _D("pkgid(%s), sender_uid(%d), target_uid(%d)",
419                 pkgid, sender_uid, target_uid);
420
421         if (sender_uid != 0 && sender_uid != target_uid) {
422                 _E("Not permitted user!");
423                 _app2sd_server_return_method_error(invocation,
424                         APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
425                 return;
426         }
427
428         ret = app2sd_usr_post_app_uninstall(pkgid, target_uid);
429         if (ret) {
430                 _E("error(%d)", ret);
431                 result = ret;
432         }
433
434         param = g_variant_new("(i)", result);
435         g_dbus_method_invocation_return_value(invocation, param);
436 }
437
438 static void _app2sd_server_ondemand_setup_init(GDBusConnection *connection, const gchar *sender,
439         GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
440 {
441         GVariant *param = NULL;
442         int result = APP2EXT_SUCCESS;
443         char *pkgid = NULL;
444         uid_t target_uid = -1;
445         int ret = 0;
446
447         g_variant_get(parameters, "(&si)", &pkgid, &target_uid);
448
449         _D("pkgid(%s), sender_uid(%d), target_uid(%d)",
450                 pkgid, sender_uid, target_uid);
451
452         if (sender_uid != 0 && sender_uid != target_uid) {
453                 _E("Not permitted user!");
454                 _app2sd_server_return_method_error(invocation,
455                         APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
456                 return;
457         }
458
459         ret = app2sd_usr_on_demand_setup_init(pkgid, target_uid);
460         if (ret) {
461                 _E("error(%d)", ret);
462                 result = ret;
463         }
464
465         param = g_variant_new("(i)", result);
466         g_dbus_method_invocation_return_value(invocation, param);
467 }
468
469 static void _app2sd_server_ondemand_setup_exit(GDBusConnection *connection, const gchar *sender,
470         GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
471 {
472         GVariant *param = NULL;
473         int result = APP2EXT_SUCCESS;
474         char *pkgid = NULL;
475         uid_t target_uid = -1;
476         int ret = 0;
477
478         g_variant_get(parameters, "(&si)", &pkgid, &target_uid);
479
480         _D("pkgid(%s), sender_uid(%d), target_uid(%d)",
481                 pkgid, sender_uid, target_uid);
482
483         if (sender_uid != 0 && sender_uid != target_uid) {
484                 _E("Not permitted user!");
485                 _app2sd_server_return_method_error(invocation,
486                         APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
487                 return;
488         }
489
490         ret = app2sd_usr_on_demand_setup_exit(pkgid, target_uid);
491         if (ret) {
492                 _E("error(%d)", ret);
493                 result = ret;
494         }
495
496         param = g_variant_new("(i)", result);
497         g_dbus_method_invocation_return_value(invocation, param);
498 }
499
500 static void _app2sd_server_move_installed_app(GDBusConnection *connection, const gchar *sender,
501         GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
502 {
503         GVariant *param = NULL;
504         int result = APP2EXT_SUCCESS;
505         int move_type;
506         char *pkgid = NULL;
507         GVariantIter *iter;
508         gchar *str = NULL;
509         int type;
510         int ret = 0;
511         uid_t target_uid = -1;
512         GList *dir_list = NULL;
513         GList *list = NULL;
514         app2ext_dir_details *dir_detail = NULL;
515
516         g_variant_get(parameters, "(&sia(si)i)", &pkgid, &move_type, &iter, &target_uid);
517
518         _D("pkgid(%s), move_type(%d),sender_uid(%d), target_uid(%d)",
519                 pkgid, move_type, sender_uid, target_uid);
520
521         if (sender_uid != 0 && sender_uid != target_uid) {
522                 _E("Not permitted user!");
523                 g_variant_iter_free(iter);
524                 _app2sd_server_return_method_error(invocation,
525                         APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
526                 return;
527         }
528
529         while (g_variant_iter_loop(iter, "(si)", &str, &type)) {
530                 if (str) {
531                         _D("str(%s), type(%d)", str, type);
532
533                         /* generate dir_list */
534                         dir_detail = (app2ext_dir_details *)calloc(1, sizeof(app2ext_dir_details));
535                         if (dir_detail == NULL) {
536                                 _E("memory allocation failed");
537                                 result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
538                                 break;
539                         }
540
541                         dir_detail->name = strdup((char *)str);
542                         if (dir_detail->name == NULL) {
543                                 _E("out of memory");
544                                 free(dir_detail);
545                                 result = APP2EXT_ERROR_MEMORY_ALLOC_FAILED;
546                                 break;
547                         }
548
549                         dir_detail->type = type;
550                         list = g_list_append(list, dir_detail);
551                 }
552         }
553         g_variant_iter_free(iter);
554
555         dir_list = g_list_first(list);
556         ret = app2sd_usr_move_installed_app(pkgid, dir_list, move_type, target_uid);
557         if (ret) {
558                 _E("usr_move error(%d)", ret);
559                 result = ret;
560         }
561
562         param = g_variant_new("(i)", result);
563         g_dbus_method_invocation_return_value(invocation, param);
564 }
565
566 static void handle_method_call(GDBusConnection *connection,
567         const gchar *sender, const gchar *object_path,
568         const gchar *interface_name, const gchar *method_name,
569         GVariant *parameters, GDBusMethodInvocation *invocation,
570         gpointer user_data)
571 {
572         uid_t sender_uid = -1;
573
574         sender_uid = (uid_t)__app2sd_get_sender_uid(connection, sender);
575
576         if (g_strcmp0(method_name, "PreAppInstall") == 0) {
577                 _app2sd_server_pre_app_install(connection, sender,
578                         parameters, invocation, sender_uid);
579         } else if (g_strcmp0(method_name, "PostAppInstall") == 0) {
580                 _app2sd_server_post_app_install(connection, sender,
581                         parameters, invocation, sender_uid);
582         } else if (g_strcmp0(method_name, "PreAppUpgrade") == 0) {
583                 _app2sd_server_pre_app_upgrade(connection, sender,
584                         parameters, invocation, sender_uid);
585         } else if (g_strcmp0(method_name, "PostAppUpgrade") == 0) {
586                 _app2sd_server_post_app_upgrade(connection, sender,
587                         parameters, invocation, sender_uid);
588         } else if (g_strcmp0(method_name, "PreAppUninstall") == 0) {
589                 _app2sd_server_pre_app_uninstall(connection, sender,
590                         parameters, invocation, sender_uid);
591         } else if (g_strcmp0(method_name, "PostAppUninstall") == 0) {
592                 _app2sd_server_post_app_uninstall(connection, sender,
593                         parameters, invocation, sender_uid);
594         } else if (g_strcmp0(method_name, "OndemandSetupInit") == 0) {
595                 _app2sd_server_ondemand_setup_init(connection, sender,
596                         parameters, invocation, sender_uid);
597         } else if (g_strcmp0(method_name, "OndemandSetupExit") == 0) {
598                 _app2sd_server_ondemand_setup_exit(connection, sender,
599                         parameters, invocation, sender_uid);
600         } else if (g_strcmp0(method_name, "MoveInstalledApp") == 0) {
601                 _app2sd_server_move_installed_app(connection, sender,
602                         parameters, invocation, sender_uid);
603         }
604
605         g_timeout_add_seconds(5, __exit_app2sd_server, NULL);
606 }
607
608 static const GDBusInterfaceVTable interface_vtable = {
609         handle_method_call,
610         NULL,
611         NULL
612 };
613
614 static void __app2sd_on_bus_acquired(GDBusConnection *connection,
615                 const gchar *name, gpointer user_data)
616 {
617         _I("bus acquired(%s)", name);
618
619         guint reg_id = 0;
620         GError *error = NULL;
621
622         reg_id = g_dbus_connection_register_object(connection,
623                 APP2SD_OBJECT_PATH,
624                 introspection_data->interfaces[0],
625                 &interface_vtable,
626                 NULL, NULL, &error);
627         if (reg_id == 0) {
628                 _E("g_dbus_connection_register_object error(%s)", error->message);
629                 g_error_free(error);
630         }
631 }
632
633 static void __app2sd_on_name_acquired(GDBusConnection *connection,
634                 const gchar *name, gpointer user_data)
635 {
636         _I("name acquired(%s)", name);
637 }
638
639 static void __app2sd_on_name_lost(GDBusConnection *connection,
640                 const gchar *name, gpointer user_data)
641 {
642         _E("name lost(%s)", name);
643 }
644
645 static int __app2sd_server_init()
646 {
647         GError *error = NULL;
648         guint owner_id = 0;
649
650         /* gdbus setup for method call */
651         introspection_data = g_dbus_node_info_new_for_xml(introspection_xml, &error);
652         if (!introspection_data) {
653                 _E("g_dbus_node_info_new_for_xml error(%s)", error->message);
654                 g_error_free(error);
655                 return -1;
656         }
657
658         owner_id = g_bus_own_name(G_BUS_TYPE_SYSTEM,
659                 APP2SD_BUS_NAME,
660                 G_BUS_NAME_OWNER_FLAGS_NONE,
661                 __app2sd_on_bus_acquired,
662                 __app2sd_on_name_acquired,
663                 __app2sd_on_name_lost,
664                 NULL, NULL);
665         if (!owner_id) {
666                 _E("g_bus_own_name error");
667                 g_dbus_node_info_unref(introspection_data);
668                 return -1;
669         }
670
671         /* add timer */
672
673         return 0;
674 }
675
676 static void __app2sd_finalize(void)
677 {
678         _D("app2sd finalize");
679
680         if (introspection_data)
681                 g_dbus_node_info_unref(introspection_data);
682
683         _D("app2sd finalize end");
684 }
685
686 int main(int argc, char *argv[])
687 {
688         int ret = 0;
689
690         _I("app2sd_server : start");
691
692         ret = __app2sd_server_init();
693         if (ret) {
694                 _E("app2sd_server init failed(%d)", ret);
695                 return -1;
696         }
697
698         app2sd_mainloop = g_main_loop_new(NULL, FALSE);
699         if (!app2sd_mainloop) {
700                 _E("g_main_loop_new failed");
701                 return -1;
702         }
703
704         g_main_loop_run(app2sd_mainloop);
705
706         __app2sd_finalize();
707
708         _I("app2sd_server : end");
709
710         return 0;
711 }