コード例 #1
0
ファイル: discovery_activator.c プロジェクト: jawi/celix
celix_status_t bundleActivator_start(void * userData, bundle_context_pt context) {
	celix_status_t status = CELIX_SUCCESS;
	struct activator *activator = userData;

	char *uuid = NULL;
	status = bundleContext_getProperty(context, OSGI_FRAMEWORK_FRAMEWORK_UUID, &uuid);
	if (!uuid) {
		printf("DISCOVERY_CONFIGURED: no framework UUID defined?!\n");
		return CELIX_ILLEGAL_STATE;
	}

	size_t len = 11 + strlen(OSGI_FRAMEWORK_OBJECTCLASS) + strlen(OSGI_RSA_ENDPOINT_FRAMEWORK_UUID) + strlen(uuid);
	char *scope = malloc(len);
	if (!scope) {
		return CELIX_ENOMEM;
	}

	sprintf(scope, "(&(%s=*)(%s=%s))", OSGI_FRAMEWORK_OBJECTCLASS, OSGI_RSA_ENDPOINT_FRAMEWORK_UUID, uuid);
	scope[len] = 0;

	printf("DISCOVERY_CONFIGURED: using scope %s.\n", scope);

	endpoint_listener_pt endpointListener = malloc(sizeof(struct endpoint_listener));
	if (!endpointListener) {
		return CELIX_ENOMEM;
	}

	endpointListener->handle = activator->discovery;
	endpointListener->endpointAdded = discovery_endpointAdded;
	endpointListener->endpointRemoved = discovery_endpointRemoved;

	properties_pt props = properties_create();
	properties_set(props, "DISCOVERY", "true");
	properties_set(props, (char *) OSGI_ENDPOINT_LISTENER_SCOPE, scope);

	status = bundleContext_registerService(context, (char *) OSGI_ENDPOINT_LISTENER_SERVICE, endpointListener, props, &activator->endpointListenerService);

	if (status == CELIX_SUCCESS) {
		status = serviceTracker_open(activator->endpointListenerTracker);
	}

	if (status == CELIX_SUCCESS) {
		status = discovery_start(activator->discovery);
	}

	// We can release the scope, as properties_set makes a copy of the key & value...
	free(scope);

	return status;
}
コード例 #2
0
ファイル: main_client.c プロジェクト: eswartz/emul
int tcf_client(void) {
#else
int main(int argc, char ** argv) {
#endif
    int c;
    int ind;
    int keep_alive = 0;
    int mode = 1; /* interactive */
    const char * host_name = "localhost";
    const char * command = NULL;
    const char * log_name = "-";
    const char * script_name = NULL;

    log_mode = 0;

    ini_mdep();
    ini_trace();
    ini_events_queue();
    ini_asyncreq();

#if defined(_WRS_KERNEL)

    progname = "tcf";
    open_log_file("-");

#else

    progname = argv[0];

    /* Parse arguments */
    for (ind = 1; ind < argc; ind++) {
        const char * s = argv[ind];
        if (*s != '-') {
            break;
        }
        s++;
        while ((c = *s++) != '\0') {
            switch (c) {
            case 'd':
                keep_alive = 1;
                break;

            case 'l':
            case 'L':
            case 'S':
            case 'h':
            case 'c':
#if ENABLE_Plugins
            case 'P':
#endif
                if (*s == '\0') {
                    if (++ind >= argc) {
                        fprintf(stderr, "%s: error: no argument given to option '%c'\n", progname, c);
                        exit(1);
                    }
                    s = argv[ind];
                }
                switch (c) {
                case 'l':
                    log_mode = strtol(s, 0, 0);
                    break;

                case 'L':
                    log_name = s;
                    break;

                case 'S':
                    script_name = s;
                    mode = 0;
                    break;

                case 'h':
                    host_name = s;
                    break;

                case 'c':
                    /* TODO: allow multiple -c options */
                    command = s;
                    mode = 2;
                    break;

#if ENABLE_Plugins
                case 'P':
                    plugins_path = s;
                    break;
#endif

                default:
                    fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c);
                    exit(1);
                }
                s = "";
                break;

            default:
                fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c);
                exit(1);
            }
        }
    }

    if (script_name != NULL && command != NULL) {
        fprintf(stderr, "%s: error: illegal option -S and -c are mutually exclusive\n", progname);
        exit(1);
    }

    open_log_file(log_name);

#endif

    discovery_start();

    proto = protocol_alloc();

#if ENABLE_Cmdline
    if (script_name != NULL) open_script_file(script_name);
    if (command != NULL) set_single_command(keep_alive, host_name, command);
    ini_cmdline_handler(mode, proto);
#else
    if (script_name != NULL) fprintf(stderr, "Warning: This version does not support script file as input.\n");
#endif

#if ENABLE_Plugins
    plugins_load(proto, NULL);
#endif

    /* Process events - must run on the initial thread since ptrace()
     * returns ECHILD otherwise, thinking we are not the owner. */
    run_event_loop();
    return 0;
}
コード例 #3
0
ファイル: main_lua.c プロジェクト: eswartz/emul
int tcf_lua(void) {
#else
int main(int argc, char ** argv) {
#endif
    int c;
    int ind;
    int error;
    const char * log_name = "-";
    const char * script_name = NULL;
    char * engine_name;
    lua_State *L;

    log_mode = 0;

#ifndef WIN32
    signal(SIGPIPE, SIG_IGN);
#endif
    ini_mdep();
    ini_trace();
    ini_events_queue();
    ini_asyncreq();

#if defined(_WRS_KERNEL)

    progname = "tcf";
    open_log_file("-");

#else

    progname = argv[0];

    /* Parse arguments */
    for (ind = 1; ind < argc; ind++) {
        const char * s = argv[ind];
        if (*s != '-') {
            break;
        }
        s++;
        while ((c = *s++) != '\0') {
            switch (c) {
            case 'l':
            case 'L':
            case 'S':
                if (*s == '\0') {
                    if (++ind >= argc) {
                        fprintf(stderr, "%s: error: no argument given to option '%c'\n", progname, c);
                        exit(1);
                    }
                    s = argv[ind];
                }
                switch (c) {
                case 'l':
                    log_mode = strtol(s, 0, 0);
                    break;

                case 'L':
                    log_name = s;
                    break;

                case 'S':
                    script_name = s;
                    break;

                default:
                    fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c);
                    exit(1);
                }
                s = "";
                break;

            default:
                fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c);
                exit(1);
            }
        }
    }
    if (ind >= argc) {
        fprintf(stderr, "%s: error: no Lua script specified\n", progname);
        exit(1);
    }
    engine_name = argv[ind++];
    if (ind < argc) {
        fprintf(stderr, "%s: error: too many arguments\n", progname);
        exit(1);
    }

    open_log_file(log_name);

#endif

    if (script_name != NULL) {
        if((lua_read_command_state.req.u.fio.fd = open(script_name, O_RDONLY, 0)) < 0) {
            fprintf(stderr, "%s: error: cannot open script: %s\n", progname, script_name);
            exit(1);
        }
    } else {
        lua_read_command_state.req.u.fio.fd = fileno(stdin);
    }

    discovery_start();

    if((luastate = L = luaL_newstate()) == NULL) {
        fprintf(stderr, "error from luaL_newstate\n");
        exit(1);
    }
    luaL_openlibs(L);

    luaL_register(L, "tcf", tcffuncs);
    lua_pop(L, 1);

    /* Peer metatable */
    luaL_newmetatable(L, "tcf_peer");
    luaL_register(L, NULL, peerfuncs);
    lua_pushvalue(L, -1);
    lua_setfield(L, -1, "__index");     /* m.__index = m */
    lua_pushvalue(L, -1);
    lua_setfield(L, -1, "__metatable"); /* m.__metatable = m */
    lua_pop(L, 1);

    /* Protocol metatable */
    luaL_newmetatable(L, "tcf_protocol");
    luaL_register(L, NULL, protocolfuncs);
    lua_pushvalue(L, -1);
    lua_setfield(L, -1, "__index");     /* m.__index = m */
    lua_pushvalue(L, -1);
    lua_setfield(L, -1, "__metatable"); /* m.__metatable = m */
    lua_pop(L, 1);

    /* Channel metatable */
    luaL_newmetatable(L, "tcf_channel");
    luaL_register(L, NULL, channelfuncs);
    lua_pushvalue(L, -1);
    lua_setfield(L, -1, "__index");     /* m.__index = m */
    lua_pushvalue(L, -1);
    lua_setfield(L, -1, "__metatable"); /* m.__metatable = m */
    lua_pop(L, 1);

    /* Post event metatable */
    luaL_newmetatable(L, "tcf_post_event");
    luaL_register(L, NULL, posteventfuncs);
    lua_pushvalue(L, -1);
    lua_setfield(L, -1, "__index");     /* m.__index = m */
    lua_pushvalue(L, -1);
    lua_setfield(L, -1, "__metatable"); /* m.__metatable = m */
    lua_pop(L, 1);

    lua_newtable(L);                    /* peers = {} */
    lua_newtable(L);                    /* m = {} */
    lua_pushstring(L, "v");             /* Values are weak */
    lua_setfield(L, -2, "__mode");      /* m.__mode = "v" */
    lua_setmetatable(L, -2);            /* setmetatable(peer, m) */
    peers_refp = luaref_new(L, NULL);
    peer_server_add_listener(peer_server_changes, L);

    if((error = luaL_loadfile(L, engine_name)) != 0) {
        fprintf(stderr, "%s\n", lua_tostring(L,1));
        exit(1);
    }

    if((error = lua_pcall(L, 0, LUA_MULTRET, 0)) != 0) {
        fprintf(stderr, "%s\n", lua_tostring(L,1));
        exit(1);
    }

    /* Process events - must run on the initial thread since ptrace()
     * returns ECHILD otherwise, thinking we are not the owner. */
    run_event_loop();

    lua_close(L);
    return 0;
}
コード例 #4
0
ファイル: main_log.c プロジェクト: tom3333/tcf.agent
int tcf_log(void) {
#else
int main(int argc, char ** argv) {
    int c;
    int ind;
    const char * log_name = "-";
#endif
    const char * url = "TCP:";
    PeerServer * ps;
    ChannelServer * serv;
    int print_server_properties = 0;

    ini_mdep();
    ini_trace();
    ini_events_queue();
    ini_asyncreq();

    log_mode = LOG_TCFLOG;

#if defined(_WRS_KERNEL)

    progname = "tcf";
    open_log_file("-");

#else

    progname = argv[0];

    /* Parse arguments */
    for (ind = 1; ind < argc; ind++) {
        char * s = argv[ind];
        if (*s++ != '-') break;
        while (s && (c = *s++) != '\0') {
            switch (c) {
            case 'h':
                show_help();
                exit(0);

            case 'n':
                auto_redirect = 0;
                break;

            case 'S':
                print_server_properties = 1;
                break;

#if ENABLE_Trace
            case 'l':
#endif
            case 'L':
            case 's':
            case 'f':
                if (*s == '\0') {
                    if (++ind >= argc) {
                        fprintf(stderr, "%s: error: no argument given to option '%c'\n", progname, c);
                        exit(1);
                    }
                    s = argv[ind];
                }
                switch (c) {
#if ENABLE_Trace
                case 'l':
                    if (parse_trace_mode(s, &log_mode) != 0) {
                        fprintf(stderr, "Cannot parse log level: %s\n", s);
                        exit(1);
                    }
                    break;
#endif

                case 'L':
                    log_name = s;
                    break;

                case 's':
                    url = s;
                    break;

                case 'f':
                    if (filter_add_message_filter(s) != 0) {
                        fprintf(stderr, "Cannot parse filter level: %s\n", s);
                        exit(1);
                    }
                    break;

                default:
                    fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c);
                    show_help();
                    exit(1);
                }
                s = NULL;
                break;

            default:
                ILLEGAL_OPTION_HOOK;
                fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c);
                show_help();
                exit(1);
            }
        }
    }
    open_log_file(log_name);

    if (ind < argc) {
        dest_url = argv[ind++];
        if (!auto_redirect) {
            fprintf(stderr, "Automatic redirect disabled: argument '%s' ignored\n", dest_url);
            dest_url = NULL;
        }
    }
#endif

    bcg = broadcast_group_alloc();

    /* Default filters (use "-fi" to disable). */
    filter_add_message_filter("o,E,Locator,peerHeartBeat");
    filter_add_message_filter("o,E,Locator,peerAdded");
    filter_add_message_filter("o,E,Locator,peerRemoved");
    filter_add_message_filter("o,E,Locator,peerChanged");
    filter_add_message_filter("o,C,Locator,getPeers");
    filter_add_message_filter("tr10,C,FileSystem,read");
    filter_add_message_filter("t10,C,FileSystem,write");

    set_proxy_log_filter_listener2(filter_is_log_filtered);

    ps = channel_peer_from_url(url);
    if (ps == NULL) {
        fprintf(stderr, "%s: invalid server URL (-s option value): %s\n", progname, url);
        exit(1);
    }
    peer_server_addprop(ps, loc_strdup("Name"), loc_strdup("TCF Protocol Logger"));
    peer_server_addprop(ps, loc_strdup("Proxy"), loc_strdup(""));
    SERVER_ADDPROP_HOOK;
    serv = channel_server(ps);
    if (serv == NULL) {
        fprintf(stderr, "%s: cannot create TCF server: %s\n", progname, errno_to_str(errno));
        exit(1);
    }
    serv->new_conn = channel_new_connection;

    discovery_start();

    if (print_server_properties) {
        ChannelServer * s;
        char * server_properties;
        assert(!list_is_empty(&channel_server_root));
        s = servlink2channelserverp(channel_server_root.next);
        server_properties = channel_peer_to_json(s->ps);
        printf("Server-Properties: %s\n", server_properties);
        fflush(stdout);
        trace(LOG_ALWAYS, "Server-Properties: %s", server_properties);
        loc_free(server_properties);
    }

    /* Process events - must run on the initial thread since ptrace()
     * returns ECHILD otherwise, thinking we are not the owner. */
    run_event_loop();
    return 0;
}
コード例 #5
0
ファイル: main.c プロジェクト: wind-river-cdt/tcf.agent
int tcf(void) {
#else
int main(int argc, char ** argv) {
    int c;
    int ind;
    int daemon = 0;
    const char * log_name = NULL;
    const char * log_level = NULL;
#endif
    int interactive = 0;
    int print_server_properties = 0;
    const char * url = DEFAULT_SERVER_URL;
    Protocol * proto;
    TCFBroadcastGroup * bcg;

    ini_mdep();
    ini_trace();
    ini_events_queue();
    ini_asyncreq();

#if defined(_WRS_KERNEL)

    progname = "tcf";
    open_log_file("-");
    log_mode = 0;

#else

    progname = argv[0];

    /* Parse arguments */
    for (ind = 1; ind < argc; ind++) {
        const char * s = argv[ind];
        if (*s != '-') {
            break;
        }
        s++;
        while ((c = *s++) != '\0') {
            switch (c) {
            case 'i':
                interactive = 1;
                break;

            case 't':
#if ENABLE_RCBP_TEST
                test_proc();
#endif
                exit(0);
                break;

            case 'd':
                daemon = 1;
                break;

            case 'c':
                generate_ssl_certificate();
                exit(0);
                break;

            case 'S':
                print_server_properties = 1;
                break;

            case 'h':
                show_help();
                exit(0);

            case 'I':
            case 'l':
            case 'L':
            case 's':
#if ENABLE_Plugins
            case 'P':
#endif
                if (*s == '\0') {
                    if (++ind >= argc) {
                        fprintf(stderr, "%s: error: no argument given to option '%c'\n", progname, c);
                        exit(1);
                    }
                    s = argv[ind];
                }
                switch (c) {
                case 'I':
                    idle_timeout = strtol(s, 0, 0);
                    break;

                case 'l':
                    log_level = s;
                    parse_trace_mode(log_level, &log_mode);
                    break;

                case 'L':
                    log_name = s;
                    break;

                case 's':
                    url = s;
                    break;

#if ENABLE_Plugins
                case 'P':
                    plugins_path = s;
                    break;
#endif
                }
                s = "";
                break;

            default:
                fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c);
                show_help();
                exit(1);
            }
        }
    }

    if (daemon && log_name != NULL && strcmp (log_name, LOG_NAME_STDERR) != 0) {
        fprintf(stderr, "%s: error: can only log to stderr when in daemon "
                "mode.\n", progname);
        exit (1);
    }

    if (daemon) become_daemon();
    open_log_file(log_name);

#endif

    bcg = broadcast_group_alloc();
    proto = protocol_alloc();

    /* The static services must be initialised before the plugins */
#if ENABLE_Cmdline
    if (interactive) ini_cmdline_handler(interactive, proto);
#else
    if (interactive) fprintf(stderr, "Warning: This version does not support interactive mode.\n");
#endif

    ini_services(proto, bcg);

#if !defined(_WRS_KERNEL)
    /* Reparse log level in case initialization cause additional
     * levels to be registered */
    if (log_level != NULL && parse_trace_mode(log_level, &log_mode) != 0) {
        fprintf(stderr, "Cannot parse log level: %s\n", log_level);
        exit(1);
    }
#endif

    if (ini_server(url, proto, bcg) < 0) {
        fprintf(stderr, "Cannot create TCF server: %s\n", errno_to_str(errno));
        exit(1);
    }
    discovery_start();

    if (print_server_properties) {
        ChannelServer * s;
        char * server_properties;
        assert(!list_is_empty(&channel_server_root));
        s = servlink2channelserverp(channel_server_root.next);
        server_properties = channel_peer_to_json(s->ps);
        printf("Server-Properties: %s\n", server_properties);
        fflush(stdout);
        trace(LOG_ALWAYS, "Server-Properties: %s", server_properties);
        loc_free(server_properties);
    }

#if ENABLE_SignalHandlers
    signal(SIGABRT, signal_handler);
    signal(SIGILL, signal_handler);
    signal(SIGINT, signal_handler);
    signal(SIGTERM, signal_handler);
#if defined(_WIN32)
    SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE);
    AddVectoredExceptionHandler(1, VectoredExceptionHandler);
#endif
#endif /* ENABLE_SignalHandlers */

    if (idle_timeout != 0) {
        add_channel_close_listener(channel_closed);
        check_idle_timeout(NULL);
    }

    /* Process events - must run on the initial thread since ptrace()
     * returns ECHILD otherwise, thinking we are not the owner. */
    run_event_loop();

#if ENABLE_Plugins
    plugins_destroy();
#endif /* ENABLE_Plugins */

    return 0;
}
コード例 #6
0
ファイル: main.c プロジェクト: tom3333/tcf.agent
int tcf(void) {
#else
int main(int argc, char ** argv) {
    int c;
    int ind;
    int daemon = 0;
    const char * log_name = NULL;
    const char * log_level = NULL;
#endif
    int interactive = 0;
    int print_server_properties = 0;
    const char * url = DEFAULT_SERVER_URL;
    Protocol * proto;
    TCFBroadcastGroup * bcg;

    PRE_INIT_HOOK;
    ini_mdep();
    ini_trace();
    ini_events_queue();
    ini_asyncreq();
    PRE_THREADING_HOOK;

#if defined(_WRS_KERNEL)

    progname = "tcf";
    open_log_file("-");
    log_mode = 0;

#else

    progname = argv[0];

    /* Parse arguments */
    for (ind = 1; ind < argc; ind++) {
        char * s = argv[ind];
        if (*s++ != '-') break;
        while (s && (c = *s++) != '\0') {
            switch (c) {
            case 'i':
                interactive = 1;
                break;

            case 't':
#if ENABLE_RCBP_TEST
                test_proc();
#endif
                exit(0);
                break;

            case 'd':
#if defined(_WIN32) || defined(__CYGWIN__)
                /* For Windows the only way to detach a process is to
                 * create a new process, so we patch the -d option to
                 * -D for the second time we get invoked so we don't
                 * keep on creating new processes forever. */
                s[-1] = 'D';
                daemon = 2;
                break;

            case 'D':
#endif
                daemon = 1;
                break;

            case 'c':
                generate_ssl_certificate();
                exit(0);
                break;

            case 'S':
                print_server_properties = 1;
                break;

            case 'h':
                show_help();
                exit(0);

            case 'I':
#if ENABLE_Trace
            case 'l':
#endif
            case 'L':
            case 's':
            case 'g':
#if ENABLE_Plugins
            case 'P':
#endif
                if (*s == '\0') {
                    if (++ind >= argc) {
                        fprintf(stderr, "%s: error: no argument given to option '%c'\n", progname, c);
                        exit(1);
                    }
                    s = argv[ind];
                }
                switch (c) {
                case 'I':
                    idle_timeout = strtol(s, 0, 0);
                    break;

#if ENABLE_Trace
                case 'l':
                    log_level = s;
                    parse_trace_mode(log_level, &log_mode);
                    break;
#endif

                case 'L':
                    log_name = s;
                    break;

                case 's':
                    url = s;
                    break;

#if ENABLE_DebugContext
                case 'g':
                    if (ini_gdb_rsp(s) < 0) {
                        fprintf(stderr, "Cannot create GDB server: %s\n", errno_to_str(errno));
                        exit(1);
                    }
                    break;
#endif

#if ENABLE_Plugins
                case 'P':
                    plugins_path = s;
                    break;
#endif
                }
                s = NULL;
                break;

            default:
                ILLEGAL_OPTION_HOOK;
                fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c);
                show_help();
                exit(1);
            }
        }
    }

    POST_OPTION_HOOK;
    if (daemon) {
#if defined(_WIN32) || defined(__CYGWIN__)
        become_daemon(daemon > 1 ? argv : NULL);
#else
        become_daemon();
#endif
    }
    open_log_file(log_name);

#endif

    bcg = broadcast_group_alloc();
    proto = protocol_alloc();

    /* The static services must be initialised before the plugins */
#if ENABLE_Cmdline
    if (interactive) ini_cmdline_handler(interactive, proto);
#else
    if (interactive) fprintf(stderr, "Warning: This version does not support interactive mode.\n");
#endif

    ini_services(proto, bcg);

#if !defined(_WRS_KERNEL)
    /* Reparse log level in case initialization cause additional
     * levels to be registered */
    if (log_level != NULL && parse_trace_mode(log_level, &log_mode) != 0) {
        fprintf(stderr, "Cannot parse log level: %s\n", log_level);
        exit(1);
    }
#endif

    if (ini_server(url, proto, bcg) < 0) {
        fprintf(stderr, "Cannot create TCF server: %s\n", errno_to_str(errno));
        exit(1);
    }
    discovery_start();

    if (print_server_properties) {
        ChannelServer * s;
        char * server_properties;
        assert(!list_is_empty(&channel_server_root));
        s = servlink2channelserverp(channel_server_root.next);
        server_properties = channel_peer_to_json(s->ps);
        printf("Server-Properties: %s\n", server_properties);
        fflush(stdout);
        trace(LOG_ALWAYS, "Server-Properties: %s", server_properties);
        loc_free(server_properties);
    }

    PRE_DAEMON_HOOK;
#if !defined(_WRS_KERNEL)
    if (daemon)
        close_out_and_err();
#endif

#if ENABLE_SignalHandlers
    signal(SIGABRT, signal_handler);
    signal(SIGILL, signal_handler);
    signal(SIGINT, signal_handler);
    signal(SIGTERM, signal_handler);
#if defined(_WIN32) || defined(__CYGWIN__)
    SetConsoleCtrlHandler((PHANDLER_ROUTINE)CtrlHandler, TRUE);
    AddVectoredExceptionHandler(1, VectoredExceptionHandler);
#endif
#endif /* ENABLE_SignalHandlers */

    if (idle_timeout != 0) {
        add_channel_close_listener(channel_closed);
        check_idle_timeout(NULL);
    }

    /* Process events - must run on the initial thread since ptrace()
     * returns ECHILD otherwise, thinking we are not the owner. */
    run_event_loop();

#if ENABLE_Plugins
    plugins_destroy();
#endif /* ENABLE_Plugins */

    return 0;
}
コード例 #7
0
ファイル: main_log.c プロジェクト: wind-river-cdt/tcf.agent
int tcf_log(void) {
#else
int main(int argc, char ** argv) {
    int c;
    int ind;
    const char * log_name = "-";
#endif
    const char * url = "TCP:";
    PeerServer * ps;
    ChannelServer * serv;

    ini_mdep();
    ini_trace();
    ini_events_queue();
    ini_asyncreq();

    log_mode = LOG_TCFLOG;

#if defined(_WRS_KERNEL)

    progname = "tcf";
    open_log_file("-");

#else

    progname = argv[0];

    /* Parse arguments */
    for (ind = 1; ind < argc; ind++) {
        const char * s = argv[ind];
        if (*s != '-') {
            break;
        }
        s++;
        while ((c = *s++) != '\0') {
            switch (c) {
            case 'h':
                show_help();
                exit (0);

            case 'l':
            case 'L':
            case 's':
                if (*s == '\0') {
                    if (++ind >= argc) {
                        fprintf(stderr, "%s: error: no argument given to option '%c'\n", progname, c);
                        exit(1);
                    }
                    s = argv[ind];
                }
                switch (c) {
                case 'l':
                    if (parse_trace_mode(s, &log_mode) != 0) {
                        fprintf(stderr, "Cannot parse log level: %s\n", s);
                        exit(1);
                    }
                    break;

                case 'L':
                    log_name = s;
                    break;

                case 's':
                    url = s;
                    break;

                default:
                    fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c);
                    show_help();
                    exit(1);
                }
                s = "";
                break;

            default:
                fprintf(stderr, "%s: error: illegal option '%c'\n", progname, c);
                show_help();
                exit(1);
            }
        }
    }
    open_log_file(log_name);
    if (ind < argc) {
        dest_url = argv[ind++];
    }

#endif

    ps = channel_peer_from_url(url);
    if (ps == NULL) {
        fprintf(stderr, "%s: invalid server URL (-s option value): %s\n", progname, url);
        exit(1);
    }
    peer_server_addprop(ps, loc_strdup("Name"), loc_strdup("TCF Protocol Logger"));
    peer_server_addprop(ps, loc_strdup("Proxy"), loc_strdup(""));
    serv = channel_server(ps);
    if (serv == NULL) {
        fprintf(stderr, "%s: cannot create TCF server: %s\n", progname, errno_to_str(errno));
        exit(1);
    }
    serv->new_conn = channel_new_connection;

    discovery_start();

    /* Process events - must run on the initial thread since ptrace()
     * returns ECHILD otherwise, thinking we are not the owner. */
    run_event_loop();
    return 0;
}