X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=tool%2Fsrc%2Fail_fota.c;h=c24027959477478843150847161cb6be799ec57b;hb=refs%2Ftags%2Fsubmit%2Ftizen_common%2F20151229.144031;hp=20d17c58cf10e83e1a130e16372ab70aa1783eec;hpb=3edbd0fad8dae864d431f7cd410c41ce3bd0833a;p=platform%2Fcore%2Fappfw%2Fail.git diff --git a/tool/src/ail_fota.c b/tool/src/ail_fota.c index 20d17c5..c240279 100644 --- a/tool/src/ail_fota.c +++ b/tool/src/ail_fota.c @@ -27,6 +27,8 @@ #include #include #include +#include +#include #include #include @@ -36,16 +38,20 @@ #ifdef _E #undef _E #endif -#define _E(fmt, arg...) fprintf(stderr, "[AIL_INITDB][E][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); +#define _E(fmt, arg...) fprintf(stderr, "[AIL_INITDB][E][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg) #ifdef _D #undef _D #endif -#define _D(fmt, arg...) fprintf(stderr, "[AIL_INITDB][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg); +#define _D(fmt, arg...) fprintf(stderr, "[AIL_INITDB][D][%s,%d] "fmt"\n", __FUNCTION__, __LINE__, ##arg) #define SET_DEFAULT_LABEL(x) \ - if(smack_setlabel((x), "*", SMACK_LABEL_ACCESS)) _E("failed chsmack -a \"*\" %s", x) \ - else _D("chsmack -a \"*\" %s", x) + do { \ + if (smack_setlabel((x), "*", SMACK_LABEL_ACCESS)) \ + _E("failed chsmack -a \"*\" %s", x); \ + else \ + _D("chsmack -a \"*\" %s", x); \ + } while (0) static int initdb_count_app(uid_t uid) { @@ -54,20 +60,20 @@ static int initdb_count_app(uid_t uid) int total = 0; ret = ail_filter_new(&filter); - if (ret != AIL_ERROR_OK) { + if (ret != AIL_ERROR_OK) return -1; - } ret = ail_filter_add_bool(filter, AIL_PROP_NODISPLAY_BOOL, false); if (ret != AIL_ERROR_OK) { ail_filter_destroy(filter); return -1; } -//__isadmin - if (uid != GLOBAL_USER) - ret = ail_filter_count_usr_appinfo(filter, &total, uid); + + /* __isadmin */ + if (uid != GLOBAL_USER) + ret = ail_filter_count_usr_appinfo(filter, &total, uid); else - ret = ail_filter_count_appinfo(filter, &total); + ret = ail_filter_count_appinfo(filter, &total); if (ret != AIL_ERROR_OK) { ail_filter_destroy(filter); return -1; @@ -78,11 +84,10 @@ static int initdb_count_app(uid_t uid) return total; } - - -char* _desktop_to_package(const char* desktop) +char *_desktop_to_package(const char* desktop) { - char *package, *tmp; + char *package; + char *tmp; retv_if(!desktop, NULL); @@ -90,7 +95,7 @@ char* _desktop_to_package(const char* desktop) retv_if(!package, NULL); tmp = strrchr(package, '.'); - if(tmp == NULL) { + if (tmp == NULL) { _E("[%s] is not a desktop file", package); free(package); return NULL; @@ -113,12 +118,12 @@ int initdb_load_directory(const char *directory) { DIR *dir; struct dirent entry, *result; - int len, ret; + int ret; char buf[BUFSZE]; int total_cnt = 0; int ok_cnt = 0; - // desktop file + /* desktop file */ dir = opendir(directory); if (!dir) { if (strerror_r(errno, buf, sizeof(buf)) == 0) @@ -126,7 +131,6 @@ int initdb_load_directory(const char *directory) return AIL_ERROR_FAIL; } - len = strlen(directory) + 1; _D("Loading desktop files from %s", directory); for (ret = readdir_r(dir, &entry, &result); @@ -142,11 +146,10 @@ int initdb_load_directory(const char *directory) continue; } - if (ail_desktop_fota(package) != AIL_ERROR_OK) { + if (ail_desktop_fota(package) != AIL_ERROR_OK) _E("Failed to add a package[%s]", package); - } else { + else ok_cnt++; - } free(package); } @@ -199,8 +202,8 @@ static int __is_authorized() uid_t uid = getuid(); uid_t euid = geteuid(); - //euid need to be root to allow smack label changes during initialization - if (((uid_t) GLOBAL_USER == uid) && (euid == OWNER_ROOT) ) + /* euid need to be root to allow smack label changes during initialization */ + if (((uid_t) GLOBAL_USER == uid) && (euid == OWNER_ROOT)) return 1; else return 0; @@ -246,37 +249,31 @@ int main(int argc, char *argv[]) if (!__is_authorized()) { fprintf(stderr, "You are not an authorized user!\n"); _D("You are not root user!\n"); - } - else { - if(remove(APP_INFO_DB_FILE)) - _E(" %s is not removed",APP_INFO_DB_FILE); - if(remove(APP_INFO_DB_FILE_JOURNAL)) - _E(" %s is not removed",APP_INFO_DB_FILE_JOURNAL); + } else { + if (remove(APP_INFO_DB_FILE)) + _E(" %s is not removed", APP_INFO_DB_FILE); + if (remove(APP_INFO_DB_FILE_JOURNAL)) + _E(" %s is not removed", APP_INFO_DB_FILE_JOURNAL); } ret = setenv("AIL_INITDB", "1", 1); _D("AIL_INITDB : %d", ret); ret = initdb_count_app(getuid()); - if (ret > 0) { + if (ret > 0) _D("Some Apps in the App Info DB."); - } ret = initdb_load_directory(USR_DESKTOP_DIRECTORY); - if (ret == AIL_ERROR_FAIL) { + if (ret == AIL_ERROR_FAIL) _E("cannot load usr desktop directory."); - } if (__is_authorized()) { ret = initdb_change_perm(APP_INFO_DB_FILE); - if (ret == AIL_ERROR_FAIL) { + if (ret == AIL_ERROR_FAIL) _E("cannot chown."); - } + SET_DEFAULT_LABEL(APP_INFO_DB_FILE); SET_DEFAULT_LABEL(APP_INFO_DB_FILE_JOURNAL); } + return AIL_ERROR_OK; } - - - -// END