Avoid to exit in setting permission list
authorJosé Bollo <jose.bollo@iot.bzh>
Mon, 12 Sep 2016 12:52:30 +0000 (14:52 +0200)
committerJosé Bollo <jose.bollo@iot.bzh>
Mon, 12 Sep 2016 12:52:30 +0000 (14:52 +0200)
Change-Id: I623546a8c134b54f7b62b42a980f603202e42868
Signed-off-by: José Bollo <jose.bollo@iot.bzh>
src/wgtpkg-installer.c
src/wgtpkg-permissions.c
src/wgtpkg-permissions.h

index ea08fce..792e8c2 100644 (file)
@@ -66,7 +66,7 @@ static struct option options[] = {
 /* install the widgets of the list */
 int main(int ac, char **av)
 {
-       int i;
+       int i, rc;
        struct wgt_info *ifo;
 
        LOGAUTH(appname);
@@ -93,7 +93,11 @@ int main(int ac, char **av)
                        verbosity++;
                        break;
                case 'p':
-                       grant_permission_list(optarg);
+                       rc = grant_permission_list(optarg);
+                       if (rc < 0) {
+                               ERROR("Can't set granted permission list");
+                               exit(1);
+                       }
                        break;
                case ':':
                        ERROR("missing argument value");
index 9e061c8..6aed31f 100644 (file)
@@ -94,7 +94,7 @@ void crop_permissions(unsigned level)
 }
 
 /* add permissions granted for installation */
-void grant_permission_list(const char *list)
+int grant_permission_list(const char *list)
 {
        struct permission *p;
        char *iter, c;
@@ -109,14 +109,15 @@ void grant_permission_list(const char *list)
                iter[n] = 0;
                p = add_permission(iter);
                if (!p) {
-                       ERROR("Can't allocate permission");
-                       exit(1);
+                       errno = ENOMEM;
+                       return -1;
                }
                p->granted = 1;
                iter += n;
                *iter =c;
                iter += strspn(iter, separators);
        }
+       return 0;
 }
 
 /* checks if the permission 'name' is recorded */
index b052063..9a99c4c 100644 (file)
@@ -19,7 +19,7 @@
 extern int is_standard_permission(const char *name);
 extern void reset_permissions();
 extern void crop_permissions(unsigned level);
-extern void grant_permission_list(const char *list);
+extern int grant_permission_list(const char *list);
 extern int permission_exists(const char *name);
 extern int request_permission(const char *name);
 extern const char *first_usable_permission();