Exemplo n.º 1
0
static void csi_set_callback(SaInvocationT invocation,
							 const SaNameT *comp_name,
							 SaAmfHAStateT ha_state,
							 SaAmfCSIDescriptorT csi_desc)
{
	SaAisErrorT rc, status = SA_AIS_OK;
	SaAmfCSIAttributeT *attr;
	int i;

	if (csi_desc.csiFlags == SA_AMF_CSI_ADD_ONE) {

		syslog(LOG_DEBUG, "CSI Set - add '%s' HAState %s", 
			csi_desc.csiName.value, ha_state_name[ha_state]);

		for (i = 0; i < csi_desc.csiAttr.number; i++) {
			attr = &csi_desc.csiAttr.attr[i];
			syslog(LOG_DEBUG, "   name: %s, value: %s", attr->attrName, attr->attrValue);
			setenv((char*)attr->attrName, (char*)attr->attrValue, 1);
		}

	} else {
		assert(csi_desc.csiFlags == SA_AMF_CSI_TARGET_ALL);
		syslog(LOG_DEBUG, "CSI Set - HAState %s", ha_state_name[ha_state]);
	}

	switch (ha_state) {
	case SA_AMF_HA_ACTIVE:
		status = service_start();
		break;
	case SA_AMF_HA_STANDBY:
		break;
	case SA_AMF_HA_QUIESCED:
		status = service_stop();
		break;
	case SA_AMF_HA_QUIESCING:
		break;
	default:
		syslog(LOG_ERR, "CSI Set: unknown HA state (%u)", ha_state);
		exit(1);
		break;
	}

	my_ha_state = ha_state;

	rc = saAmfResponse(my_amf_hdl, invocation, status);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, "CSI Set: saAmfResponse FAILED (%u)", rc);
		exit(1);
	}

	if (ha_state == SA_AMF_HA_QUIESCING) {
		status = service_stop();
		rc = saAmfCSIQuiescingComplete(my_amf_hdl, invocation, status);
		if (rc != SA_AIS_OK) {
			syslog(LOG_ERR, "CSI Set: saAmfCSIQuiescingComplete FAILED (%u)", rc);
			exit(1);
		}
	}
}
Exemplo n.º 2
0
VOID WINAPI service_ctrl(DWORD ctrl_code)
{   /* Handle the requested control code. */
    if (ctrl_code == SERVICE_CONTROL_STOP || ctrl_code == SERVICE_CONTROL_SHUTDOWN)
        service_stop();
    else
        send_status(ssStatus.dwCurrentState, NO_ERROR, 0, 1040 + ctrl_code);
} /* service_ctrl */
Exemplo n.º 3
0
int do_stop(int nargs, char **args)
{
    struct service *svc;
    svc = service_find_by_name(args[1]);
    if (svc) {
        service_stop(svc);
    }
    return 0;
}
static void msg_stop(const char *name)
{
    struct service *svc = service_find_by_name(name);

    if (svc) {
        service_stop(svc);
    } else {
        ERROR("no such service '%s'\n", name);
    }
}
Exemplo n.º 5
0
/**
 * service_stop_dynamic - Stop disabled/removed dynamic services
 */
void service_stop_dynamic(void)
{
	svc_t *svc;

	_d("Stopping disabled/removed services ...");
	for (svc = svc_dynamic_iterator(1); svc; svc = svc_dynamic_iterator(0)) {
		if (svc_is_changed(svc))
			service_stop(svc);
	}

	_d("All disabled/removed services have been stoppped, calling reconf hooks ...");
	plugin_run_hooks(HOOK_SVC_RECONF); /* Reconfigure HW/VLANs/etc here */
}
Exemplo n.º 6
0
/* stop + start
 *
 * XXX: This should be refactored into a background job AND marked such
 *      so that the service monitor doesn't attempt to restart it!
 */
int service_restart(svc_t *svc)
{
	int result = 0;

	if (!svc)
		return 1;

	result += service_stop(svc);
	sleep(1);
	result += service_start(svc);

	return result;
}
Exemplo n.º 7
0
void CL_Service_Unix::service_thread_main(std::vector<CL_String> args)
{
	service_start(args);
	while (true)
	{
		int wakeup_reason = CL_Event::wait(stop_event, reload_event);
		if (wakeup_reason == 1)
			service_reload();
		else
			break;
	}
	service_stop();
}
Exemplo n.º 8
0
Arquivo: service.c Projeto: wkz/finit
/**
 * service_restart - Restart or SIGHUP a process
 *
 * Unfortunately we cannot call service_start() here because we must
 * wait for the svc to actually be collected by the service_monitor()
 * first.  Currently this means that an initctl user will not get
 * correct feedback when restarting a service.  (Prompt may return
 * before we've actually started upp the service again.)
 *
 * XXX: This should be refactored to let initctl check the sighup
 *      flag and then to stop+start or reload.
 */
int service_restart(svc_t *svc)
{
	if (!svc)
		return 1;

	/* Ignore if finit is SIGSTOP'ed */
	if (is_norespawn())
		return 0;

	svc->restart_counter = 0;

	return service_stop(svc, SVC_RESTART_STATE);
}
Exemplo n.º 9
0
/* Singing and dancing ... */
static void svc_dance(svc_t *svc)
{
	svc_cmd_t cmd = service_enabled(svc, 0, NULL);

	if (svc->pid) {
		if (SVC_STOP == cmd)
			service_stop(svc);
		else if (SVC_RELOAD == cmd)
			service_reload(svc);
	} else {
		if (SVC_START == cmd || SVC_RELOAD == cmd)
			service_start(svc);
	}
}
Exemplo n.º 10
0
void Service_Unix::service_thread_main(std::vector<std::string> args)
{
	service_start(args);
	while (true)
	{
		std::unique_lock<std::mutex> lock(mutex);
		event_condition.wait(lock, [&]() { return stop_flag || reload_flag; });

		if (stop_flag)
			break;

		reload_flag = false;
		service_reload();
	}
	service_stop();
}
Exemplo n.º 11
0
BOOL WINAPI
control_handler (DWORD control_type)
{
    switch (control_type)
      {
        /* Use Ctrl+C or Ctrl+Break to simulate SERVICE_CONTROL_STOP in      */
        /* console mode                                                      */
        case CTRL_BREAK_EVENT:
        case CTRL_C_EVENT:
            service_stop ();
            log_printf ("%s: stopping service", application_name);
            control_break = TRUE;
            return (TRUE);

      }
    return (FALSE);
}
Exemplo n.º 12
0
void WINAPI
service_control (DWORD control_code)
{
    /* Handle the requested control code.                                    */
    switch (control_code)
      {
        case SERVICE_CONTROL_STOP:      /*  Stop the service                 */
            service_status.dwCurrentState = SERVICE_STOP_PENDING;
            service_stop ();
            break;

        case SERVICE_CONTROL_INTERROGATE:/* Update the service status        */
            break;
        default:                        /*  Invalid control code             */
            break;
      }
    report_status (service_status.dwCurrentState, NO_ERROR, 0);
}
Exemplo n.º 13
0
int Service_Win32::run_debug(std::vector<std::string> args)
{
	debug_mode = true;
	SetConsoleCtrlHandler(&Service_Win32::control_handler, TRUE);

	service_start(args);
	while (true)
	{
		std::unique_lock<std::mutex> lock(mutex);
		event_condition.wait(lock, [&]() { return stop_flag || reload_flag; });

		if (stop_flag)
			break;

		reload_flag = false;
		service_reload();
	}
	service_stop();
	return 0;
}
Exemplo n.º 14
0
Arquivo: service.c Projeto: wkz/finit
/**
 * service_stop_dynamic - Stop disabled/removed dynamic services
 *
 * We call it "stop", but in reality it could be "skip" as well, if the
 * service supports SIGHUP.  This function is just one step on the road
 * to reload all modified services.
 */
void service_stop_dynamic(void)
{
	svc_t *svc;

	_d("Stopping disabled/removed services ...");
	for (svc = svc_dynamic_iterator(1); svc; svc = svc_dynamic_iterator(0)) {
		if (svc_is_changed(svc) && svc->pid) {
			svc_state_t new_state = SVC_RELOAD_STATE;

			if (svc_is_removed(svc))
				new_state = SVC_HALTED_STATE;

			if (!svc_has_sighup(svc))
				dyn_stop_cnt++;

			_d("Marking service %s as state %d", svc->cmd, new_state);
			service_stop(svc, new_state);
		}
	}

	/* Check if we need to collect any services before calling user HOOK */
	service_stop_done(NULL);
}
Exemplo n.º 15
0
static void csi_remove_callback(SaInvocationT invocation,
								const SaNameT *comp_name,
								const SaNameT *csi_name,
								SaAmfCSIFlagsT csi_flags)
{
	SaAisErrorT rc, status = SA_AIS_OK;

	syslog(LOG_DEBUG, "CSI Remove callback");

	assert(csi_flags == SA_AMF_CSI_TARGET_ALL);

	if (my_ha_state == SA_AMF_HA_ACTIVE)
		status = service_stop();

	/* Reset HA state */
	my_ha_state = 0;

	rc = saAmfResponse(my_amf_hdl, invocation, status);
	if (rc != SA_AIS_OK) {
		syslog(LOG_ERR, "CSI remove callback: saAmfResponse FAILED (%u)", rc);
		exit(1);
	}
}
Exemplo n.º 16
0
int handle_one_request(ServiceHandler h, char *buf, int buf_size)
{

    debug;
    char Buf[MAX_BUF_LEN] = "\0";
    int BufSize = MAX_BUF_LEN;
    char Data1[MAX_BUF_LEN] = "\0";
    char Data2[MAX_BUF_LEN] = "\0";

    mDataFormat data = (mDataFormat) malloc(sizeof(struct DataFormat));
    data->value1 = Data1;
    data->value2 = Data2;

    memset(Data1, 0, MAX_BUF_LEN);
    memset(Data2, 0, MAX_BUF_LEN);
    data->value1 = Data1;
    data->value2 = Data2;

    /*if(receive_data(h,Buf,&BufSize) == 0)
      {
          fprintf(stderr,"Connection Error,%s:%d\n",__FILE__,__LINE__);
          return -1;            
      }*/
    if(BufSize == 0)
    {
        free(data);
        return -1;
    }
    int ret = parse_data(buf,data);

    // print the received data
    // printRec(data);

    if(ret == -1)
    {
        error_response(h,"Data Format Error!\n");
        printf("server parse_data error!\n");
        free(data);
        return -1;
    }
    if(data->cmd == OPEN_CMD)
    {
        debug;
        Database db = createNewDB(data->value1);
        debug_argv("open db:%p\n",db);
        match_sockfd_mdb(h, db);
        BufSize = MAX_BUF_LEN;
        data->value_num = 0;
        BufSize = format_data(Buf,data);
        assert(BufSize > 0);
        send_data(h,Buf,BufSize);
    }
    else if(data->cmd == CLOSE_CMD)
    {
        debug_argv("close db\n");
        Database db = NULL;
        get_mdb(h, &db);
        closeDB(db);
        BufSize = MAX_BUF_LEN;
        data->value_num = 0;
        BufSize = format_data(Buf,data);
        send_data(h,Buf,BufSize);
        detach_sockfd_mdb(h);
        service_stop(h);
        free(data);
        return 0;
    }
    else if(data->cmd == GET_CMD)
    {
        Database db = NULL;
        get_mdb(h, &db);

        //debug_argv("get db:%p\n",db);
        int key = *(int *)data->value1;
        Data value;

        char tem[MAX_BUF_LEN] = "\0";
        value.value = tem;
        ret = getValueByKey(db, key, &value);
       // printf("server getdata value => %s\n", value.value);
        if(ret == -1)
        {
            error_response(h,"The key NOT FOUND!\n");
            free(data);
            return -1;              
        }
        BufSize = MAX_BUF_LEN;
        data->value_num = 1;
        data->len_value1 = strlen(value.value);
        data->value1 = value.value;
        BufSize = format_data(Buf,data);
        send_data(h,Buf,BufSize);

    }
    else if(data->cmd == SET_CMD)
    {
        int key = *(int *)data->value1;
        Data value;
        value.value = data->value2;
        value.length = data->len_value2;
        Database db = NULL;
        get_mdb(h, &db);
        debug_argv("set: db:%p\n",db);
        ret = putKeyValue(db,key,&value);
        if (ret == -1)
        {
            error_response(h,"Save key & value error!\n");
            printf("set error : %d, %s\n", key, value.value);
            free(data);
            return -1;
        }
        BufSize = MAX_BUF_LEN;
        data->value_num = 0;
        BufSize = format_data(Buf,data);
        send_data(h,Buf,BufSize);    

    }
    else if(data->cmd == DEL_CMD)
    {
        int key = *(int *)data->value1;;           
        Database db = NULL;
        get_mdb(h, &db);
        debug_argv("delete: db:%p\n",db);
        ret = deleteValueByKey(db,key);
        if(ret == -1)
        {
            error_response(h,"The key NOT FOUND!\n");
            free(data);
            return -1;
        }            
        BufSize = MAX_BUF_LEN;
        data->value_num = 0;
        BufSize = format_data(Buf,data);
        send_data(h,Buf,BufSize);             
    }
    else
    {
        printf("Unknow Request!\n");
        error_response(h, "Unknow Request!\n");
    }                                   
    free(data);
    return 0;
}
Exemplo n.º 17
0
int
main(int argc, char *argv[])
{
    char *unixctl_path = NULL;
    struct unixctl_server *unixctl;
    char *remote;
    bool exiting;
    int retval;

    set_program_name(argv[0]);
    retval = dpdk_init(argc,argv);
    argc -= retval;
    argv += retval;

    ovs_cmdl_proctitle_init(argc, argv);
    service_start(&argc, &argv);
    remote = parse_options(argc, argv, &unixctl_path);
    fatal_ignore_sigpipe();
    ovsrec_init();

    daemonize_start();

    if (want_mlockall) {
#ifdef HAVE_MLOCKALL
        if (mlockall(MCL_CURRENT | MCL_FUTURE)) {
            VLOG_ERR("mlockall failed: %s", ovs_strerror(errno));
        }
#else
        VLOG_ERR("mlockall not supported on this system");
#endif
    }

    retval = unixctl_server_create(unixctl_path, &unixctl);
    if (retval) {
        exit(EXIT_FAILURE);
    }
    unixctl_command_register("exit", "", 0, 0, ovs_vswitchd_exit, &exiting);

    bridge_init(remote);
    free(remote);

    exiting = false;
    while (!exiting) {
        memory_run();
        if (memory_should_report()) {
            struct simap usage;

            simap_init(&usage);
            bridge_get_memory_usage(&usage);
            memory_report(&usage);
            simap_destroy(&usage);
        }
        bridge_run();
        unixctl_server_run(unixctl);
        netdev_run();

        memory_wait();
        bridge_wait();
        unixctl_server_wait(unixctl);
        netdev_wait();
        if (exiting) {
            poll_immediate_wake();
        }
        poll_block();
        if (should_service_stop()) {
            exiting = true;
        }
    }
    bridge_exit();
    unixctl_server_destroy(unixctl);
    service_stop();

    return 0;
}
Exemplo n.º 18
0
int WINAPI WinMain(HINSTANCE this_instance, HINSTANCE prev_instance,
#ifdef _WIN32_WCE
        LPWSTR lpCmdLine,
#else
        LPSTR lpCmdLine,
#endif
        int nCmdShow) {
    TCHAR stunnel_exe_path[MAX_PATH];
    LPTSTR c;
#ifndef _WIN32_WCE
    LPTSTR errmsg;
#endif

    (void)prev_instance; /* squash the unused parameter warning */
    (void)lpCmdLine; /* squash the unused parameter warning */
    (void)nCmdShow; /* squash the unused parameter warning */

    tls_init(); /* initialize thread-local storage */
    ghInst=this_instance;
    gui_cmdline(); /* setup global cmdline structure */
    GetModuleFileName(0, stunnel_exe_path, MAX_PATH);

#ifndef _WIN32_WCE
    /* find previous instances of the same executable */
    if(!cmdline.service && !cmdline.install && !cmdline.uninstall &&
            !cmdline.reload && !cmdline.reopen &&
            !cmdline.start && !cmdline.stop) {
        EnumWindows(enum_windows, (LPARAM)stunnel_exe_path);
        if(cmdline.exit)
            return 1; /* in case EnumWindows didn't find a previous instance */
    }
#endif

    /* set current working directory and engine path */
    c=_tcsrchr(stunnel_exe_path, TEXT('\\')); /* last backslash */
    if(c) { /* found */
        *c=TEXT('\0'); /* truncate the program name */
        c=_tcsrchr(stunnel_exe_path, TEXT('\\')); /* previous backslash */
        if(c && !_tcscmp(c+1, TEXT("bin")))
            *c=TEXT('\0'); /* truncate "bin" */
    }
#ifndef _WIN32_WCE
    if(!SetCurrentDirectory(stunnel_exe_path)) {
        errmsg=str_tprintf(TEXT("Cannot set directory to %s"),
            stunnel_exe_path);
        message_box(errmsg, MB_ICONERROR);
        str_free(errmsg);
        return 1;
    }
    /* try to enter the "config" subdirectory, ignore the result */
    SetCurrentDirectory(TEXT("config"));
#endif
    _tputenv(str_tprintf(TEXT("OPENSSL_ENGINES=%s\\engines"),
        stunnel_exe_path));

    if(initialize_winsock())
        return 1;

#ifndef _WIN32_WCE
    if(cmdline.service) /* "-service" must be processed before "-install" */
        return service_initialize();
    if(cmdline.install)
        return service_install();
    if(cmdline.uninstall)
        return service_uninstall();
    if(cmdline.start)
        return service_start();
    if(cmdline.stop)
        return service_stop();
    if(cmdline.reload)
        return service_user(SIGNAL_RELOAD_CONFIG);
    if(cmdline.reopen)
        return service_user(SIGNAL_REOPEN_LOG);
#endif
    return gui_loop();
}
Exemplo n.º 19
0
Arquivo: gui.c Projeto: djs55/stunnel
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,
#ifdef _WIN32_WCE
    LPWSTR lpCmdLine,
#else
    LPSTR lpCmdLine,
#endif
    int nCmdShow) {

    LPSTR command_line;

#ifdef _WIN32_WCE
    command_line=tstr2str(lpCmdLine);
#else
    command_line=lpCmdLine;
#endif

    ghInst=hInstance;

    parse_cmdline(command_line); /* setup global cmdline structure */
#ifndef _WIN32_WCE
    if(set_cwd()) /* set current working directory */
        return 1;
#endif

    /* setup the windo caption before reading the configuration file
     * options.win32_service is not available here and may not be used */
#ifdef _WIN32_WCE
    _tcscpy(win32_name, TEXT("stunnel ") TEXT(VERSION)
        TEXT(" on Windows CE (not configured)"));
#else
    _tcscpy(win32_name, TEXT("stunnel ") TEXT(VERSION)
        TEXT(" on Win32 (not configured)"));
#endif

    if(initialize_winsock())
        return 1;

    if(!setjmp(jump_buf)) { /* TRY */
        main_initialize(
            cmdline.config_file[0] ? cmdline.config_file : NULL, NULL);
#ifdef _WIN32_WCE
        _tcscpy(win32_name, TEXT("stunnel ") TEXT(VERSION)
            TEXT(" on Windows CE"));
#else
        _snprintf(win32_name, STRLEN, "stunnel %s on Win32 (%s)",
            VERSION, options.win32_service); /* update the information */
        if(!cmdline.service) {
            if(cmdline.install)
                return service_install(command_line);
            if(cmdline.uninstall)
                return service_uninstall();
            if(cmdline.start)
                return service_start();
            if(cmdline.stop)
                return service_stop();
        }
#endif
    }

    /* CATCH */
#ifndef _WIN32_WCE
    if(cmdline.service)
        return service_initialize();
    else
#endif
        return win_main(hInstance, hPrevInstance, command_line, nCmdShow);
}
Exemplo n.º 20
0
/**
 * service_runlevel - Change to a new runlevel
 * @newlevel: New runlevel to activate
 *
 * Stops all services not in @newlevel and starts, or lets continue to run,
 * those in @newlevel.  Also updates @prevlevel and active @runlevel.
 */
void service_runlevel(int newlevel)
{
	svc_t *svc;

	if (runlevel == newlevel)
		return;

	if (newlevel < 0 || newlevel > 9)
		return;

	prevlevel = runlevel;
	runlevel  = newlevel;

	_d("Setting new runlevel --> %d <-- previous %d", runlevel, prevlevel);
	runlevel_set(prevlevel, newlevel);

	/* Make sure to (re)load all *.conf in /etc/finit.d/ */
	conf_reload_dynamic();

	_d("Stopping services services not allowed in new runlevel ...");
	for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
		if (!svc_in_runlevel(svc, runlevel)) {
#ifndef INETD_DISABLED
			if (svc_is_inetd(svc))
				inetd_stop(&svc->inetd);
			else
#endif
				service_stop(svc);
		}

		/* ... or disabled/removed services from /etc/finit.d/ */
		if (svc_is_dynamic(svc) && svc_is_changed(svc))
			service_stop(svc);
	}

	/* Prev runlevel services stopped, call hooks before starting new runlevel ... */
	_d("All services have been stoppped, calling runlevel change hooks ...");
	plugin_run_hooks(HOOK_RUNLEVEL_CHANGE);  /* Reconfigure HW/VLANs/etc here */

	_d("Starting services services new to this runlevel ...");
	for (svc = svc_iterator(1); svc; svc = svc_iterator(0)) {
#ifndef INETD_DISABLED
		/* Inetd services have slightly different semantics */
		if (svc_is_inetd(svc)) {
			if (svc_in_runlevel(svc, runlevel))
				inetd_start(&svc->inetd);

			continue;
		}
#endif

		/* All other services consult their callback here */
		svc_dance(svc);
	}

	/* Cleanup stale services */
	svc_clean_dynamic(service_unregister);

	if (0 == runlevel) {
		do_shutdown(SIGUSR2);
		return;
	}
	if (6 == runlevel) {
		do_shutdown(SIGUSR1);
		return;
	}

	if (runlevel == 1)
		touch("/etc/nologin");	/* Disable login in single-user mode */
	else
		erase("/etc/nologin");

	if (0 != prevlevel)
		tty_runlevel(runlevel);
}
Exemplo n.º 21
0
int service_engine(char *addr, int port)
{
    int i;
    if(MAX_TASK_NUM > 0)
    {
        for (i = 0; i < MAX_TASK_NUM; i++)
        {
            sem_init(&event[i], 0, 0);
            int temp = i;
           if (pthread_create(&thread_id[i], NULL, (void *)handle_requests, (void *)temp) != 0)
            {
                printf("pthread_create error, %s:%d\n",__FILE__, __LINE__);
                exit(-1);
            }

        }
    }
    /* 
     * command line console
     */

    init_mdb();

    ServiceHandler h = -1;
    initialize_service(addr,port);
    while(1)
    {
        h = service_start();
        //        handle_request(h);  
        task_node_t *tnode = (task_node_t *)malloc( sizeof(task_node_t));
        tnode->buf_size = MAX_BUF_LEN;
        if (receive_data (h, tnode->buf, &(tnode->buf_size)) == 0)
        {
            service_stop(h);
            continue;
        }

        if (MAX_TASK_NUM > 0)
        {
            tnode->req = h;
            int i = random_int(MAX_TASK_NUM);
            /* put tnode into task_list */
            if (task_list[i] == NULL)
            {
                task_list[i] = tnode;
                tnode->next = NULL;
                tnode->last = tnode;
            }
            else
            {
                task_node_t *p = task_list[i];
                p->last->next = tnode;
                p->last = tnode;
                tnode->next = NULL;
            }
            sem_post(&event[i]);

            //        service_stop(h); 
        }
        else 
        {
            handle_one_request(h, tnode->buf, tnode->buf_size);
            free(tnode);
        }
    }
    shutdown_service();
    close_mdb();
    if (MAX_TASK_NUM > 0 )
    {
        for (i = 0; i< MAX_TASK_NUM; i++)
        {
            task_node_t *p = task_list[i];
            task_node_t *q;
            while (p)
            {
                q = p->next;
                free(p);
                p = q;
            }
        }
    }
    return 0;
}
Exemplo n.º 22
0
int WINAPI WinMain(HINSTANCE this_instance, HINSTANCE prev_instance,
#ifdef _WIN32_WCE
        LPWSTR lpCmdLine,
#else
        LPSTR lpCmdLine,
#endif
        int nCmdShow) {
    LPSTR command_line;
    char *c, stunnel_exe_path[MAX_PATH];
#ifndef _WIN32_WCE
    char *errmsg;
#endif

    (void)prev_instance; /* skip warning about unused parameter */
    (void)nCmdShow; /* skip warning about unused parameter */

    str_init(); /* initialize per-thread string management */
    ghInst=this_instance;
#ifdef _WIN32_WCE
    command_line=tstr2str(lpCmdLine);
#else
    command_line=lpCmdLine;
#endif

    parse_cmdline(command_line); /* setup global cmdline structure */

    GetModuleFileName(0, stunnel_exe_path, MAX_PATH);

#ifndef _WIN32_WCE
    /* find previous instances of the same executable */
    if(!cmdline.service && !cmdline.install && !cmdline.uninstall &&
            !cmdline.start && !cmdline.stop) {
        EnumWindows(enum_windows, (LPARAM)stunnel_exe_path);
        if(cmdline.exit)
            return 0; /* in case EnumWindows didn't find a previous instance */
    }
#endif

    /* set current working directory and engine path */
    c=strrchr(stunnel_exe_path, '\\'); /* last backslash */
    if(c) /* found */
        c[1]='\0'; /* truncate program name */
#ifndef _WIN32_WCE
    if(!SetCurrentDirectory(stunnel_exe_path)) {
        errmsg=str_printf("Cannot set directory to %s", stunnel_exe_path);
        message_box(errmsg, MB_ICONERROR);
        str_free(errmsg);
        return 1;
    }
#endif
    _putenv_s("OPENSSL_ENGINES", stunnel_exe_path);

    if(initialize_winsock())
        return 1;

#ifndef _WIN32_WCE
    if(cmdline.service) /* "-service" must be processed before "-install" */
        return service_initialize();
    if(cmdline.install)
        return service_install(command_line);
    if(cmdline.uninstall)
        return service_uninstall();
    if(cmdline.start)
        return service_start();
    if(cmdline.stop)
        return service_stop();
#endif
    return gui_loop();
}
Exemplo n.º 23
0
void service_unregister(svc_t *svc)
{
	service_stop(svc);
	svc_del(svc);
}