2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
27 #include <sys/types.h>
33 static const char *db_update_arg[] = {
34 "/usr/bin/system_info_init_db",
42 static void show_help(void)
44 printf("system_info_update_db [OPTIONS]\n");
45 printf(" -h --help Show this help\n");
46 printf(" -r --root=ROOT Root path for chroot operation\n");
47 printf(" -k --key=KEY System info key to update\n");
48 printf(" -t --type=TYPE System info type to update (int/bool/double/string)\n");
49 printf(" -g --tag=TAGE System info tag to update (platform/custom)\n");
50 printf(" -v --value=VALUE System info value to update\n");
53 int main(int argc, char *argv[])
59 char root[KEY_MAX] = { 0, };
60 char key[KEY_MAX] = { 0, };
61 char type[KEY_MAX] = { 0, };
62 char tag[KEY_MAX] = { 0, };
63 char value[KEY_MAX] = { 0, };
64 struct option long_options[] = {
65 { "root", required_argument, 0, 0 },
66 { "key", required_argument, 0, 0 },
67 { "type", required_argument, 0, 0 },
68 { "tag", required_argument, 0, 0 },
69 { "value", required_argument, 0, 0 },
70 { "help", no_argument, 0, 0 },
75 opt = getopt_long(argc, argv, "r:k:t:g:v:h",
81 snprintf(root, sizeof(root), "%s", optarg);
84 snprintf(key, sizeof(key), "%s", optarg);
87 snprintf(type, sizeof(type), "%s", optarg);
90 snprintf(tag, sizeof(tag), "%s", optarg);
93 snprintf(value, sizeof(value), "%s", optarg);
103 if (root[0] == '\0') {
104 printf("Invalid Parameter: no root path\n");
107 if (key[0] == '\0') {
108 printf("Invalid Parameter: no key\n");
111 if (type[0] == '\0') {
112 printf("Invalid Parameter: no type\n");
115 if (tag[0] == '\0') {
116 printf("Invalid Parameter: no tag\n");
119 if (value[0] == '\0') {
120 printf("Invalid Parameter: no value\n");
127 printf("Root Path(%s)\n", root);
128 printf("Request to update: key(%s), type(%s), tag(%s), value(%s)\n",
129 key, type, tag, value);
131 db_update_arg[2] = key;
132 db_update_arg[4] = type;
133 db_update_arg[6] = tag;
134 db_update_arg[8] = value;
138 printf("Failed to change root dir (%s, errno:%d)\n", root, errno);
143 printf("Failed to go to root directory : %d", errno);
149 printf("Failed to update db (%d)\n", errno);
151 } else if (pid == 0) {
152 ret = execv(db_update_arg[0], (char **)db_update_arg);
157 ret = waitpid(pid, &status, 0);
159 printf("%d waitpid() failed : %d\n", pid, errno);
163 if (WIFEXITED(status)) {
164 printf("%d terminated by exit(%d)\n", pid, WEXITSTATUS(status));
165 return WEXITSTATUS(status);
168 if (WIFSIGNALED(status))
169 printf("%d terminated by signal %d\n", pid, WTERMSIG(status));
170 else if (WIFSTOPPED(status))
171 printf("%d stopped by signal %d\n", pid, WSTOPSIG(status));