emulator: add "conf" options 62/23062/2
authorSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 17 Jun 2014 01:58:32 +0000 (10:58 +0900)
committerSeokYeon Hwang <syeon.hwang@samsung.com>
Tue, 17 Jun 2014 02:20:46 +0000 (19:20 -0700)
"conf" option with configuration file override profile option.

Change-Id: I6229acff51e8449f668d622dfd7c121f4288f8aa
Signed-off-by: SeokYeon Hwang <syeon.hwang@samsung.com>
tizen/src/emulator.c
tizen/src/emulator_options.c
tizen/src/emulator_options.h

index c7efcc2313b3ddc30bd5a3b328731ad987692bd7..69501089efa772cd41cf08b4c2aadc4e696adbdb 100644 (file)
@@ -66,6 +66,7 @@ MULTI_DEBUG_CHANNEL(tizen, main);
 
 #define SUPPORT_LEGACY_ARGS
 
+#define ARGS_LIMIT  128
 #define LEN_MARU_KERNEL_CMDLINE 512
 char maru_kernel_cmdline[LEN_MARU_KERNEL_CMDLINE];
 
@@ -93,12 +94,15 @@ const char *get_log_path(void)
 
     // if "log_path" is not exist, make it first
     if (!log_path) {
-        char *vm_path = get_variable("vm_path");
-        if (!vm_path) {
-            vm_path = g_strdup("");
+        char *vms_path = get_variable("vms_path");
+        char *vm_name = get_variable("vm_name");
+        if (!vms_path || !vm_name) {
+            log_path = NULL;
+        }
+        else {
+            log_path = g_strdup_printf("%s/%s/logs", vms_path, vm_name);
         }
 
-        log_path = g_strdup_printf("%s/logs", vm_path);
         set_variable("log_path", log_path, false);
     }
 
@@ -311,10 +315,12 @@ static int emulator_main(int argc, char *argv[], char **envp)
 #endif
 
     gchar *profile = NULL;
+    gchar *conf = NULL;
+
     int c = 0;
 
-    _qemu_argv = g_malloc(sizeof(char*) * 256);
-    _skin_argv = g_malloc(sizeof(char*) * 256);
+    _qemu_argv = g_malloc(sizeof(char*) * ARGS_LIMIT);
+    _skin_argv = g_malloc(sizeof(char*) * ARGS_LIMIT);
 
     // parse arguments
     // prevent the error message for undefined options
@@ -322,12 +328,13 @@ static int emulator_main(int argc, char *argv[], char **envp)
 
     while (c != -1) {
         static struct option long_options[] = {
+            {"conf",        required_argument,  0,  'c' },
             {"profile",     required_argument,  0,  'p' },
             {"additional",  required_argument,  0,  'a' },
             {0,             0,                  0,  0   }
         };
 
-        c = getopt_long(argc, argv, "p:v:", long_options, NULL);
+        c = getopt_long(argc, argv, "c:p:a:", long_options, NULL);
 
         if (c == -1)
             break;
@@ -336,6 +343,10 @@ static int emulator_main(int argc, char *argv[], char **envp)
         case '?':
             set_variable(argv[optind - 1], argv[optind], true);
             break;
+        case 'c':
+            set_variable("conf", optarg, true);
+            conf = g_strdup(optarg);
+            break;
         case 'p':
             set_variable("profile", optarg, true);
             profile = g_strdup(optarg);
@@ -350,8 +361,10 @@ static int emulator_main(int argc, char *argv[], char **envp)
         }
     }
 
-    if (!profile) {
-        fprintf(stderr, "Usage: %s {-p|--profile} profile\n", argv[0]);
+    if (!profile && !conf) {
+        fprintf(stderr, "Usage: %s {-c|--conf} conf_file ...\n"
+                        "       %s {-p|--profile} profile ...\n",
+                        basename(argv[0]), basename(argv[0]));
 
         return -1;
     }
@@ -362,7 +375,7 @@ static int emulator_main(int argc, char *argv[], char **envp)
 
     set_bin_path(_qemu_argv[0]);
 
-    if (!load_profile_default(profile)) {
+    if (!load_profile_default(conf, profile)) {
         return -1;
     }
 
index ed6317057b176c7afec46d99579c6575729ada5b..a6f3045b0b27ee6e896e77b9d412aa4c013bbfa3 100644 (file)
@@ -197,14 +197,19 @@ static char *substitute_variables(char *src)
     return str;
 }
 
-bool load_profile_default(const char * const profile)
+bool load_profile_default(const char * const conf, const char * const profile)
 {
     int classification = 0;
     char str[LINE_LIMIT];
     char *filename;
     FILE *file = NULL;
 
-    filename = g_strdup_printf("%s/%s.profile", get_bin_path(), profile);
+    // if "conf" is exist, ignore "profile"
+    if (conf) {
+        filename = g_strdup(conf);
+    } else {
+        filename = g_strdup_printf("%s/%s.conf", get_bin_path(), profile);
+    }
 
     file = fopen(filename, "r");
     if (!file) {
index c4f370c7885b79f12ca906ea8548c19b4b3cb7c6..66022a057c2a04151882f64b180a51beb1fce28d 100644 (file)
@@ -32,7 +32,7 @@
 void set_variable(const char * const arg1, const char * const arg2, bool override);
 char *get_variable(const char * const name);
 void reset_variables(void);
-bool load_profile_default(const char * const profile);
+bool load_profile_default(const char * const conf, const char * const profile);
 bool assemble_profile_args(int *qemu_argc, char **qemu_argv,
         int *skin_argc, char **skin_argv);