⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 jk_nt_service.c

📁 Tomcat 4.1与WebServer集成组件的源代码包.
💻 C
📖 第 1 页 / 共 4 页
字号:
                    }                }                                                                } else {                char b[] = {(char)254, (char)15};                rc = send(sd, b, 2, 0);                if(2 == rc) {                    rc = JK_TRUE;                }            }            jk_close_socket(sd);            if(JK_TRUE == rc) {                if(WAIT_OBJECT_0 == WaitForSingleObject(hTomcat, 30*1000)) {                    return;                }            }                    }    }    TerminateProcess(hTomcat, 0);    }static int exec_cmd(const char *name, HANDLE *hTomcat, char *cmdLine){    char  tag[1024];    HKEY  hk;    strcpy(tag, BASE_REGISTRY_LOCATION);    strcat(tag, name);    strcat(tag, "\\");    strcat(tag, PARAMS_LOCATION);    if(ERROR_SUCCESS == RegOpenKeyEx(HKEY_LOCAL_MACHINE,                                     tag,                                     (DWORD)0,                                              KEY_READ,                                     &hk)) {        char prp_file[2048];        if(get_registry_config_parameter(hk,                                         PRP_LOCATION,                                          prp_file,                                         sizeof(prp_file))) {            jk_map_t *init_map;                        if(map_alloc(&init_map)) {                if(map_read_properties(init_map, prp_file)) {                    jk_tomcat_startup_data_t data;                    jk_pool_t p;                    jk_pool_atom_t buf[HUGE_POOL_SIZE];                    jk_open_pool(&p, buf, sizeof(buf));                                if(read_startup_data(init_map, &data, &p)) {                        STARTUPINFO startupInfo;                        PROCESS_INFORMATION processInformation;                        SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), NULL, TRUE };                        if(data.extra_path) {                            jk_append_libpath(&p, data.extra_path);                        }                        memset(&startupInfo, 0, sizeof(startupInfo));                        startupInfo.cb = sizeof(startupInfo);                        startupInfo.lpTitle = "Jakarta Tomcat";                        startupInfo.dwFlags = STARTF_USESTDHANDLES;                        startupInfo.hStdInput = NULL;                        startupInfo.hStdOutput = CreateFile(data.stdout_file,                                                            GENERIC_WRITE,                                                            FILE_SHARE_READ,                                                            &sa,                                                            OPEN_ALWAYS,                                                            FILE_ATTRIBUTE_NORMAL,                                                            NULL);                        SetFilePointer(startupInfo.hStdOutput,                                       0,                                       NULL,                                       FILE_END);                        startupInfo.hStdError = CreateFile(data.stderr_file,                                                           GENERIC_WRITE,                                                           FILE_SHARE_READ,                                                           &sa,                                                           OPEN_ALWAYS,                                                           FILE_ATTRIBUTE_NORMAL,                                                           NULL);                        SetFilePointer(startupInfo.hStdError,                                       0,                                       NULL,                                       FILE_END);                        memset(&processInformation, 0, sizeof(processInformation));                        						if( cmdLine==NULL ) 							cmdLine=data.cmd_line;                        printf(cmdLine);                        if(CreateProcess(data.java_bin,                                        cmdLine,                                        NULL,                                        NULL,                                        TRUE,                                        CREATE_NEW_CONSOLE,                                        NULL,                                        data.tomcat_home,                                        &startupInfo,                                        &processInformation)){                            *hTomcat = processInformation.hProcess;                            CloseHandle(processInformation.hThread);                            CloseHandle(startupInfo.hStdOutput);                            CloseHandle(startupInfo.hStdError);                            shutdown_port = data.shutdown_port;                            shutdown_secret = data.shutdown_secret;                            shutdown_protocol = strdup(data.shutdown_protocol);							shutdown_cmd = strdup(data.stop_cmd);                            return JK_TRUE;                        } else {                            printf("Error: Can not create new process - %s\n",                                     GetLastErrorText(szErr, sizeof(szErr)));                                        }                    }                                    }            }            map_free(&init_map);        }        RegCloseKey(hk);    }     return JK_FALSE;}static int start_tomcat(const char *name, HANDLE *hTomcat){    return exec_cmd( name, hTomcat, NULL );}static int create_registry_key(const char *tag,                               HKEY *key){    LONG  lrc = RegCreateKeyEx(HKEY_LOCAL_MACHINE,                               tag,                               0,                               NULL,                               REG_OPTION_NON_VOLATILE,                               KEY_WRITE,                               NULL,                               key,                               NULL);    if(ERROR_SUCCESS != lrc) {        return JK_FALSE;            }    return JK_TRUE;}static int set_registry_config_parameter(HKEY hkey,                                         const char *tag,                                          char *value){           LONG  lrc;    lrc = RegSetValueEx(hkey,                         tag,                                    0,                                      REG_SZ,                          value,                         strlen(value));    if(ERROR_SUCCESS != lrc) {        return JK_FALSE;            }    return JK_TRUE;     }static int get_registry_config_parameter(HKEY hkey,                                         const char *tag,                                          char *b,                                         DWORD sz){       DWORD type = 0;    LONG  lrc;    lrc = RegQueryValueEx(hkey,                               tag,                                (LPDWORD)0,                          &type,                              (LPBYTE)b,                          &sz);     if(ERROR_SUCCESS != lrc) {        return JK_FALSE;            }        b[sz] = '\0';    return JK_TRUE;     }static int read_startup_data(jk_map_t *init_map,                              jk_tomcat_startup_data_t *data,                              jk_pool_t *p){        data->classpath = NULL;    data->tomcat_home = NULL;    data->stdout_file = NULL;    data->stderr_file = NULL;    data->java_bin = NULL;    data->extra_path = NULL;    data->tomcat_class = NULL;    data->server_file = NULL;    /* All this is wrong - you just need to configure cmd_line */    /* Optional - you may have cmd_line defined */    data->server_file = map_get_string(init_map,                                        "wrapper.server_xml",                                        NULL);    data->classpath = map_get_string(init_map,                                      "wrapper.class_path",                                        NULL);    data->tomcat_home = map_get_string(init_map,                                        "wrapper.tomcat_home",                                        NULL);    data->java_bin = map_get_string(init_map,                                     "wrapper.javabin",                                     NULL);    data->tomcat_class = map_get_string(init_map,                                        "wrapper.startup_class",                                        "org.apache.tomcat.startup.Tomcat");    data->cmd_line = map_get_string(init_map,                                    "wrapper.cmd_line",                                    NULL);    data->stop_cmd = map_get_string(init_map,                                    "wrapper.stop_cmd",                                    NULL);    if(NULL == data->cmd_line &&       ( (NULL == data->tomcat_class) ||         (NULL == data->server_file) ||         (NULL == data->tomcat_home) ||         (NULL == data->java_bin) )) {       return JK_FALSE;    }    if(NULL == data->cmd_line) {        data->cmd_line = (char *)jk_pool_alloc(p, (20 +                                                    strlen(data->java_bin) +                                                   strlen(" -classpath ") +                                                   strlen(data->classpath) +                                                   strlen(data->tomcat_class) +                                                   strlen(" -home ") +                                                   strlen(data->tomcat_home) +                                                   strlen(" -config ") +                                                   strlen(data->server_file)                                                   ) * sizeof(char));        if(NULL == data->cmd_line) {            return JK_FALSE;        }        strcpy(data->cmd_line, data->java_bin);        strcat(data->cmd_line, " -classpath ");        strcat(data->cmd_line, data->classpath);        strcat(data->cmd_line, " ");        strcat(data->cmd_line, data->tomcat_class);        strcat(data->cmd_line, " -home ");        strcat(data->cmd_line, data->tomcat_home);        strcat(data->cmd_line, " -config ");        strcat(data->cmd_line, data->server_file);    }    data->shutdown_port = map_get_int(init_map,                                      "wrapper.shutdown_port",                                      8007);    data->shutdown_secret = map_get_string(init_map,                                           "wrapper.shutdown_secret", NULL );        data->shutdown_protocol = map_get_string(init_map,                                             "wrapper.shutdown_protocol",                                             AJP12_TAG);    data->extra_path = map_get_string(init_map,                                      "wrapper.ld_path",                                      NULL);    data->stdout_file = map_get_string(init_map,                                       "wrapper.stdout",                                       NULL);    if(NULL == data->stdout_file && NULL == data->tomcat_home ) {        return JK_FALSE;    }        if(NULL == data->stdout_file) {        data->stdout_file = jk_pool_alloc(p, strlen(data->tomcat_home) + 2 + strlen("\\stdout.log"));        strcpy(data->stdout_file, data->tomcat_home);        strcat(data->stdout_file, "\\stdout.log");            }    data->stderr_file = map_get_string(init_map,                                       "wrapper.stderr",                                       NULL);    if(NULL == data->stderr_file) {        data->stderr_file = jk_pool_alloc(p, strlen(data->tomcat_home) + 2 + strlen("\\stderr.log"));        strcpy(data->stderr_file, data->tomcat_home);        strcat(data->stderr_file, "\\stderr.log");            }    return JK_TRUE;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -