2 * Copyright (c) 2000 - 2017 Samsung Electronics Co., Ltd. All rights reserved.
4 * Contact: Junghyun Yeon <jungh.yeon@samsung.com>,
5 * Jongmyeong Ko <jongmyeong.ko@samsung.com>, Sangyoon Jang <s89.jang@samsung.com>
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
26 #include <sys/types.h>
29 #include <tzplatform_config.h>
31 #define REGULAR_USER 5000
32 #define MAX_QUERY_LEN 4096
34 #define PKGMGR_PARSER_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db")
35 #define PKGMGR_CERT_DB_FILE tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db")
37 static int __rollback_db(sqlite3 *db, const char *table_name)
39 static const char rollback_query_raw[] =
40 "SELECT COUNT(*) FROM %s WHERE 1=0";
42 sqlite3_stmt *stmt = NULL;
43 char query[MAX_QUERY_LEN] = { '\0' };
45 sqlite3_snprintf(MAX_QUERY_LEN, query, rollback_query_raw, table_name);
46 ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
47 if (ret != SQLITE_OK) {
48 printf("Failed to recover db : %s\n", sqlite3_errmsg(db));
51 sqlite3_finalize(stmt);
55 static int __check_and_rollback_db(const char *db_path, const char *table_name)
60 ret = sqlite3_open_v2(db_path, &db,
61 SQLITE_OPEN_READWRITE, NULL);
62 if (ret != SQLITE_OK) {
63 printf("Failed to open db\n");
67 ret = __rollback_db(db, table_name);
69 printf("Failed to rollback db\n");
75 static void _check_db()
79 ret = __check_and_rollback_db(PKGMGR_PARSER_DB_FILE, "package_info");
81 printf("Failed to check and rollback parser db\n");
83 ret = __check_and_rollback_db(PKGMGR_CERT_DB_FILE, "package_cert_info");
85 printf("Failed to check and rollback cert db\n");
89 int main(int argc, char *argv[])
91 if ((int)getuid() > REGULAR_USER) {
92 printf("This cmd is not allowed for regular user\n");