revert web-viewer: added init and shutdown logic of nodejs and websocket
authorsungmin ha <sungmin82.ha@samsung.com>
Wed, 11 Mar 2015 05:53:03 +0000 (14:53 +0900)
committersung min Ha <sungmin82.ha@samsung.com>
Wed, 11 Mar 2015 06:16:03 +0000 (15:16 +0900)
Change-Id: Ie8ee508182dca7e4023054b111242050015b27c7
Signed-off-by: sungmin ha <sungmin82.ha@samsung.com>
tizen/src/emul_state.c
tizen/src/emul_state.h
tizen/src/emulator.c
tizen/src/util/osutil-linux.c
tizen/src/util/osutil.h
vl.c

index e178296980d0792838bd92619acf6366195ab09e..d56a5196a1499e93f5d302ba674253a0806307ba 100644 (file)
@@ -50,17 +50,11 @@ static EmulatorConfigInfo _emul_info = {0,};
 static EmulatorConfigState _emul_state;
 
 /* misc */
-char remote_bin_path[PATH_MAX] = { 0, };
 #ifdef SUPPORT_LEGACY_ARGS
 // for compatibility
 char log_path[PATH_MAX] = { 0, };
 #endif
 
-const char *get_remote_bin_path(void)
-{
-    return remote_bin_path;
-}
-
 const char *get_bin_path(void)
 {
     const char *bin_path = get_variable(KEYWORD_BIN_PATH);
@@ -226,12 +220,6 @@ void set_emul_vm_base_port(int port)
     _emul_info.ecs_port = port + 3;
     _emul_info.serial_port = port + 4;
     _emul_info.spice_port = port + 5;
-    _emul_info.websocket_port = port + 6;
-}
-
-int get_emul_websocket_port(void)
-{
-    return _emul_info.websocket_port;
 }
 
 int get_emul_spice_port(void)
index 4d4ef108320104f7ea74de50201486fc8717836d..b2146bc74243c318a8078af138c13ea807238dfd 100644 (file)
@@ -101,7 +101,6 @@ typedef  struct EmulatorConfigInfo {
     char guest_ip[16];
 
     int spice_port;
-    int websocket_port;
     char *vm_name;
     char *skin_path;
     bool gpu_accel_enable;
@@ -130,12 +129,10 @@ typedef struct EmulatorConfigState {
 } EmulatorConfigState;
 
 /* misc */
-extern char remote_bin_path[];
 #ifdef SUPPORT_LEGACY_ARGS
 extern char log_path[];
 #endif
 
-char const *get_remote_bin_path(void);
 char const *get_bin_path(void);
 char const *get_log_path(void);
 
@@ -184,7 +181,6 @@ int get_emul_ecs_port(void);
 int get_emul_serial_port(void);
 char* get_emul_vm_name(void);
 int get_emul_spice_port(void);
-int get_emul_websocket_port(void);
 char* get_emul_skin_path(void);
 bool get_emul_gpu_accel(void);
 bool get_emul_cpu_accel(void);
index 5b6ff90a86b8288f9f0c28f03995d2325b55f7d8..bd4ef2e6304d7a28963010cb4e6f204f99ffc014 100644 (file)
@@ -179,10 +179,6 @@ static void prepare_basic_features(gchar * const kernel_cmdline)
 
     set_base_port();
 
-#if defined(CONFIG_SPICE) && defined(CONFIG_LINUX)
-    clean_websocket_port(SIGKILL);
-#endif
-
     make_vm_lock_os();
 
     maru_device_hotplug_init();
index f5e7cda24e6de7cd2f677b022e737d476b4bdd6f..3e754fca7bf44c507b1289713ee6219c3180afff 100644 (file)
@@ -54,9 +54,6 @@
 #include <linux/version.h>
 #include <sys/utsname.h>
 #include <sys/sysinfo.h>
-#ifdef CONFIG_SPICE
-#include <dirent.h>
-#endif
 
 MULTI_DEBUG_CHANNEL(emulator, osutil);
 
@@ -167,11 +164,6 @@ void set_bin_path_os(char const *const exec_argv)
     g_strlcat(bin_path, "/", PATH_MAX);
 
     set_variable(KEYWORD_BIN_PATH, bin_path, true);
-
-#ifdef CONFIG_SPICE
-    g_strlcpy(remote_bin_path, link_path, strlen(link_path) - strlen(file_name) - 2);
-    g_strlcat(remote_bin_path, "remote/bin/", PATH_MAX);
-#endif
 }
 
 int get_number_of_processors(void)
@@ -248,212 +240,6 @@ void print_system_info_os(void)
     g_free(buffer);
 }
 
-#ifdef CONFIG_SPICE
-#define PID_MAX_COUNT 256
-const char *execution_file_websocket = "websockify.py";
-const char *execution_file_node = "node";
-const char *node_proc_name = "emulator-x86-web";
-
-void get_process_id(char const *process_name, char *first_param, int *pid, int *pscount)
-{
-    char cmdline[2048], dir_name[255];
-    int total_len = 0, current_len = 0;
-    struct dirent *dir_entry_p;
-    DIR *dir_p;
-    FILE *fp;
-    char *mptr;
-
-    dir_p = opendir("/proc/");
-    while (NULL != (dir_entry_p = readdir(dir_p))) {
-        /* Checking for numbered directories */
-        if (strspn(dir_entry_p->d_name, "0123456789") == strlen(dir_entry_p->d_name)) {
-            strcpy(dir_name, "/proc/");
-            strcat(dir_name, dir_entry_p->d_name);
-            strcat(dir_name, "/cmdline");
-
-            fp = fopen(dir_name, "rb");
-            if (fp == NULL) {
-                continue;
-            }
-
-            total_len = 0;
-            memset(cmdline, 0, sizeof(cmdline));
-            while (!feof(fp)) {
-                cmdline[total_len++] = fgetc(fp);
-            }
-
-            fclose(fp);
-            current_len = strlen(cmdline);
-            mptr = cmdline;
-            do {
-                if (strstr(mptr, process_name) != NULL) {
-                    if (!first_param || strstr(&cmdline[current_len + 1], first_param) != NULL) {
-                        if (sizeof(pid) < *pscount + 1) {
-                            WARN("PID array size is not enough.\n");
-                            return;
-                        }
-                        pid[*pscount] = atoi(dir_entry_p->d_name);
-                        INFO("get_process_id(%s %s) :Found. id = %d\n", process_name, first_param, pid[*pscount]);
-                        (*pscount)++;
-                    }
-                    break;
-                }
-
-                mptr = &cmdline[current_len + 1];
-                current_len += strlen(mptr) + 1;
-            } while (current_len < total_len);
-        }
-    }
-
-    closedir(dir_p);
-    if (*pscount == 0) {
-        INFO("get_process_id(%s %s) : id = 0 (could not find process)\n", process_name, first_param);
-    }
-}
-
-void execute_websocket(int port)
-{
-    char const *remote_bin_dir = get_remote_bin_path();
-    char const *relative_path = "../websocket/";
-    char websocket_path[strlen(remote_bin_dir) + strlen(execution_file_websocket) + strlen(relative_path) + 1];
-    int ret = -1;
-    char local_port[32];
-    char websocket_port[16];
-
-    memset(websocket_port, 0, sizeof(websocket_port));
-    sprintf(websocket_port, "%d", port);
-
-    memset(local_port, 0, sizeof(local_port));
-    sprintf(local_port, "localhost:%d", get_emul_spice_port());
-
-    memset(websocket_path, 0, sizeof(websocket_path));
-    sprintf(websocket_path, "%s%s%s", remote_bin_dir, relative_path, execution_file_websocket);
-
-    INFO("Exec [%s %s %s]\n", websocket_path, websocket_port, local_port);
-
-    ret = execl(websocket_path, execution_file_websocket, websocket_port, local_port, (char *)0);
-    if (ret == 127) {
-        WARN("Can't execute websocket.\n");
-    } else if (ret == -1) {
-        WARN("Fork error!\n");
-    }
-}
-
-void execute_nodejs(void)
-{
-    char const *remote_bin_dir = get_remote_bin_path();
-    char const *relative_path = "../web-viewer/bin/tty.js";
-    char webviewer_script[strlen(remote_bin_dir) + strlen(relative_path) + 1];
-    char nodejs_path[strlen(remote_bin_dir) + strlen(execution_file_node) + 1];
-    int ret = -1;
-
-    memset(webviewer_script, 0, sizeof(webviewer_script));
-    sprintf(webviewer_script, "%s%s", remote_bin_dir, relative_path);
-
-    memset(nodejs_path, 0, sizeof(nodejs_path));
-    sprintf(nodejs_path, "%s%s", remote_bin_dir, execution_file_node);
-
-    INFO("Exec [%s %s]\n", nodejs_path, webviewer_script);
-
-    ret = execl(nodejs_path, execution_file_node, webviewer_script, (char *)0);
-    if (ret == 127) {
-        WARN("Can't execute node server.\n");
-    } else if (ret == -1) {
-        WARN("Fork error!\n");
-    }
-}
-
-void clean_websocket_port(int signal)
-{
-    char websocket_port[16];
-    memset(websocket_port, 0, sizeof(websocket_port));
-    sprintf(websocket_port, "%d", get_emul_websocket_port());
-
-    int pscount = 0, i = 0;
-    int pid[PID_MAX_COUNT];
-
-    memset(pid, 0, PID_MAX_COUNT);
-    get_process_id(execution_file_websocket, websocket_port, pid, &pscount);
-    if (pscount > 0) {
-        for (i = 0; i < pscount; i++) {
-            INFO("Will be killed PID: %d\n", pid[i]);
-            kill(pid[i], signal);
-        }
-    }
-}
-
-static void websocket_notify_exit(Notifier *notifier, void *data)
-{
-    clean_websocket_port(SIGTERM);
-}
-
-static void nodejs_notify_exit(Notifier *notifier, void *data)
-{
-    int pscount = 0, i = 0;
-    int pid[PID_MAX_COUNT];
-
-    memset(pid, 0, sizeof(pid));
-    get_process_id("spicevmc", NULL, pid, &pscount);
-    if (pscount == 1) {
-        INFO("Detected the last spice emulator.\n");
-        pid[0] = 0;
-        pscount = 0;
-        get_process_id(node_proc_name, NULL, pid, &pscount);
-        for (i = 0; i < pscount; i++) {
-            INFO("Will be killed %s, PID: %d\n", node_proc_name, pid[i]);
-            kill(pid[i], SIGTERM);
-        }
-    }
-}
-
-static Notifier websocket_exit = { .notify = websocket_notify_exit };
-static Notifier nodejs_exit = { .notify = nodejs_notify_exit };
-
-void websocket_init(void)
-{
-    int pscount = 0;
-    char websocket_port[16];
-    int pid[PID_MAX_COUNT];
-
-    memset(websocket_port, 0, sizeof(websocket_port));
-    sprintf(websocket_port, "%d", get_emul_websocket_port());
-
-    memset(pid, 0, sizeof(pid));
-    get_process_id(execution_file_websocket, websocket_port, pid, &pscount);
-    emulator_add_exit_notifier(&websocket_exit);
-
-    if (pscount == 0) {
-        int pid = fork();
-        if (pid == 0) {
-            setsid();
-            execute_websocket(get_emul_websocket_port());
-        }
-    } else {
-       INFO("Aleady running websokify %s localhost:%d\n", websocket_port, get_emul_spice_port());
-    }
-}
-
-void nodejs_init(void)
-{
-    int pscount = 0;
-    int pid[PID_MAX_COUNT];
-
-    memset(pid, 0, sizeof(pid));
-    get_process_id(node_proc_name, NULL, pid, &pscount);
-    emulator_add_exit_notifier(&nodejs_exit);
-
-    if (pscount == 0) {
-        int pid = fork();
-        if (pid == 0) {
-            setsid();
-            execute_nodejs();
-        }
-    } else {
-       INFO("Aleady running node server.\n");
-    }
-}
-#endif
-
 bool make_sdcard_lock_os(char *sdcard)
 {
     return make_sdcard_lock_posix(sdcard);
index 7e0201e45b0f17fceac6adcf68ad83d762d7dcdd..ee52510e225d3a6715d2286feabf8f2e2165d39f 100644 (file)
@@ -65,15 +65,6 @@ int remove_sdcard_lock_posix(char *sdcard);
 
 void print_system_info_os(void);
 
-#if defined(CONFIG_SPICE) && defined(CONFIG_LINUX)
-void get_process_id(char const *process_name, char *first_param, int *pid, int *pscount);
-void execute_websocket(int port);
-void execute_nodejs(void);
-void clean_websocket_port(int signal);
-void nodejs_init(void);
-void websocket_init(void);
-#endif
-
 static inline int get_timeofday(char *buf, size_t size)
 {
     qemu_timeval tv;
diff --git a/vl.c b/vl.c
index 6e3500879b9698e6da181e5952ec4acd91af56b9..4e025ce5068bbfb06d0fbcb8fdfdae6d101bc701 100644 (file)
--- a/vl.c
+++ b/vl.c
@@ -163,10 +163,6 @@ static char *vigs_backend = NULL;
 #ifdef CONFIG_MARU
 int skin_disabled = 0;
 extern int enable_spice;
-#if defined(CONFIG_SPICE) && defined(CONFIG_LINUX)
-extern void websocket_init(void);
-extern void nodejs_init(void);
-#endif
 #endif
 
 static const char *data_dir[16];
@@ -4332,10 +4328,6 @@ int main(int argc, char **argv, char **envp)
     qemu_mutex_lock_iothread();
 
 #ifdef CONFIG_SPICE
-#if defined(CONFIG_MARU) && defined(CONFIG_LINUX)
-    nodejs_init();
-#endif
-
     /* spice needs the timers to be initialized by this point */
     qemu_spice_init();
 #endif
@@ -4583,9 +4575,6 @@ int main(int argc, char **argv, char **envp)
 #ifdef CONFIG_SPICE
     if (using_spice) {
         qemu_spice_display_init();
-#if defined(CONFIG_MARU) && defined(CONFIG_LINUX)
-        websocket_init();
-#endif
     }
 #endif