change documentation for badge
[platform/core/appfw/badge.git] / src / badge_init.c
1 /*
2  * Copyright (c) 2016 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */
17
18 #define _GNU_SOURCE
19
20 #include <string.h>
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <dirent.h>
24 #include <unistd.h>
25 #include <sys/stat.h>
26 #include <sys/types.h>
27 #include <sys/wait.h>
28 #include <errno.h>
29
30 #include <badge_setting.h>
31 #include <badge_setting_service.h>
32 #include <badge_error.h>
33
34 #define OWNER_ROOT 0
35
36 #ifdef _E
37 #undef _E
38 #endif
39 #define _E(fmt, arg...) fprintf(stderr, "[BADGE_INIT][E][%s,%d] "fmt"\n", \
40                                 __func__, __LINE__, ##arg)
41
42 static int __is_authorized(void)
43 {
44         uid_t uid = getuid();
45
46         if ((uid_t)OWNER_ROOT == uid)
47                 return 1;
48         else
49                 return 0;
50 }
51
52 int main(int argc, char *argv[])
53 {
54         int ret;
55         uid_t uid = OWNER_ROOT;
56
57         if (!__is_authorized()) {
58                 _E("You are not an authorized user!");
59                 return -1;
60         }
61
62         if (argc > 2)
63                 uid = (uid_t)atoi(argv[2]);
64
65         ret = badge_setting_refresh_setting_table(uid);
66         if (ret != BADGE_ERROR_NONE)
67                 _E("badge setting table refresh fail.");
68
69         return ret;
70 }