2 Copyright (C) 2015-2020 IoT.bzh
4 author: José Bollo <jose.bollo@iot.bzh>
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
10 http://www.apache.org/licenses/LICENSE-2.0
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.
30 #include "utils-dir.h"
31 #include "secmgr-wrap.h"
32 #include "wgtpkg-unit.h"
36 /* uninstall the widget of idaver */
37 int uninstall_widget(const char *idaver, const char *root)
46 struct unitconf uconf;
49 NOTICE("-- UNINSTALLING widget of id %s from %s --", idaver, root);
51 /* find the last '@' of the id */
53 at = strrchr(idaver, '@');
55 ERROR("bad widget id '%s', no @", idaver);
59 id = strndupa(idaver, (size_t)(at - idaver));
60 ver = strdupa(at + 1);
62 /* compute the path */
63 rc = snprintf(path, sizeof path, "%s/%s/%s", root, id, ver);
65 rc = snprintf(path, sizeof path, "%s/%s", root, idaver);
68 if (rc >= (int)sizeof path) {
69 ERROR("bad widget id '%s', too long", idaver);
74 /* removes the units */
75 ifo = wgt_info_createat(AT_FDCWD, path, 1, 1, 1);
77 ERROR("can't read widget config in directory '%s': %m", path);
80 uconf.installdir = path;
81 uconf.icondir = FWK_ICON_DIR;
83 uconf.base_http_ports = 0;
84 unit_uninstall(ifo, &uconf);
87 /* removes the directory of the application */
88 rc = remove_directory(path, 1);
90 ERROR("while removing directory '%s': %m", path);
94 /* removes the icon of the application */
95 rc = snprintf(path, sizeof path, "%s/%s", FWK_ICON_DIR, idaver);
96 assert(rc < (int)sizeof path);
98 if (rc < 0 && errno != ENOENT)
99 ERROR("can't remove '%s': %m", path);
101 #if DISTINCT_VERSIONS
102 /* removes the parent directory if empty */
103 rc2 = snprintf(path, sizeof path, "%s/%s", root, id);
104 assert(rc2 < (int)sizeof path);
106 if (rc < 0 && errno == ENOTEMPTY)
109 ERROR("while removing directory '%s': %m", path);
114 * parent directory removed: last occurrence of the application
115 * uninstall it for the security-manager
117 rc2 = secmgr_init(id);
119 rc2 = secmgr_init(idaver);
122 ERROR("can't init security manager context");
125 rc2 = secmgr_uninstall();
127 ERROR("can't uninstall security manager context");