#include <unistd.h>
#include <sys/types.h>
#include <sys/smack.h>
+#include <glib.h>
#include <sqlite3.h>
#include <tzplatform_config.h>
#include <system_info.h>
int main(int argc, char **argv)
{
int ret;
+ GOptionContext *context;
+ GError *error = NULL;
+ gpointer opt_force = NULL;
+ GOptionEntry entries[] = {
+ {"force", 'f', 0, G_OPTION_ARG_NONE, &opt_force, "Remove an existing db file and initialize it", NULL},
+ {NULL}
+ };
if (getuid() != ROOT_UID) {
printf("This binary should be run as root user\n");
return -1;
}
- ret = __unlink_db();
- if (ret < 0)
+ context = g_option_context_new(NULL);
+ g_option_context_add_main_entries(context, entries, NULL);
+ if (!g_option_context_parse(context, &argc, &argv, &error)) {
+ printf("%s: %s\n", argv[0], error->message);
+ g_option_context_free(context);
+ g_clear_error(&error);
return -1;
+ }
+ g_option_context_free(context);
+
+ if (opt_force) {
+ ret = __unlink_db();
+ if (ret < 0)
+ return -1;
+ } else {
+ ret = access(PATH_DB, F_OK);
+ if (ret == 0) {
+ printf("The db(%s) file already exists.\n", PATH_DB);
+ return 0;
+ }
+ }
return __init_db();
}