Esempio n. 1
0
int
smtoper_init (void)
{
    AGENT   *agent;                     /*  Handle for our agent             */
    THREAD  *thread;                    /*  Handle for initial thread        */

#   include "smtoper.i"                 /*  Include dialog interpreter       */

    /*  We give this agent a high priority, so that we get to see messages   */
    /*  and errors as soon as possible.                                      */
    agent-> priority = SMT_PRIORITY_HIGH;

    /*  Shutdown event comes from Kernel, normal priority so we can show     */
    /*  incoming messages before we shut down.                               */
    declare_smtlib_shutdown   (shutdown_event, 0);

    /*  Public methods supported by this agent                               */
    declare_smtoper_set_log (log_event,     0);
    declare_smtoper_error   (error_event,   0);
    declare_smtoper_warning (warning_event, 0);
    declare_smtoper_info    (info_event,    0);
    declare_smtoper_disable (disable_event, 0);
    declare_smtoper_enable  (enable_event,  0);


    /*  Create initial, unnamed thread                                       */
    thread = thread_create (AGENT_NAME, "");
    smt_set_console (&thread-> queue-> qid);

    /*  Tell sflcons.c that we want date/time prefix on output               */
    console_set_mode (CONSOLE_DATETIME);

    /*  Signal okay to caller that we initialised okay                       */
    return (0);
}
Esempio n. 2
0
MODULE set_debug_mode (THREAD *thread)
{
    tcb = thread-> tcb;                 /*  Point to thread's context        */
    dns_debug_mode = TRUE;
    console_set_mode (CONSOLE_TIME);
    console_capture  (".\\nshost.log", 'a');
    coprintf ("Debug mode ON, console output logged to file 'nshost.log'");
}
Esempio n. 3
0
void console_init(void)
{
    console_set_mode(CONSOLE_MODE_LINE);
}
Esempio n. 4
0
/*  ---------------------------------------------------------------------[<]-
    Function: service_begin

    Synopsis: depending on arguments (from the command line):
      -i: install service               (windows)
      -u: remove  service               (windows)
      -d: runs service in console mode  (windows)
      -h: basic help information        (windows)
      -d: runs service in background    (UNIX / Linux)

      if no arguments, the service is actually started.

    NOTE: with Windows, the working directory is set to the one where the
    binary program stands.

    Returns: 0 is everything is OK, negative error code otherwise
    ---------------------------------------------------------------------[>]-*/
int
service_begin (
    int                   argc, 
    char                **argv,
    SMT_AGENTS_INIT_FCT  *init_fct, 
    SMT_AGENTS_TERM_FCT  *term_fct,
    const char           *appl_version)
{  
    int
        action;
    int
        rc = 0;

#if (defined(WIN32)) 
    static char
        buffer [LINE_MAX];
    char
        *p_char;

    SERVICE_TABLE_ENTRY 
        dispatch_table [] = {
        { NULL, (LPSERVICE_MAIN_FUNCTION) service_main },
        { NULL, NULL }
    };

    /*  Change to the correct working directory, where config file stands    */
    GetModuleFileName (NULL, buffer, LINE_MAX);
    if ((p_char = strrchr (buffer, '\\')) != NULL)
        *p_char = '\0';
    SetCurrentDirectory (buffer);
#endif

    rc = init_resources (argv[0], appl_version, init_fct, term_fct);
    if (rc != 0)
        return (1);

    ASSERT (application_config);        /* init_resources post condition     */
    if (load_service_config (application_config) != 0)
      {
        free_resources ();
        return (1);
      }

    ASSERT (service_trace_file);        /* load_service_config postcondition */
    console_set_mode (CONSOLE_DATETIME);
    console_capture (service_trace_file, 'a');

#if (defined(WIN32)) 
    dispatch_table [0].lpServiceName = service_name;
    win_version = get_windows_version ();
#endif

    action = parse_command_line (argc, argv);

    if (action == ACTION_HELP)
      {
        puts (USAGE);
      }
#if (defined(WIN32)) 
    else
    if (action == ACTION_INSTALL)
      {
        if (win_version == WINDOWS_95)
            set_win95_service (TRUE);
        else
            install_service ();
      }
    else 
    if (action == ACTION_UNINSTALL)
      {
        if (win_version == WINDOWS_95)
            set_win95_service (FALSE);
        else
            remove_service ();
      }
    else
    if (action == ACTION_CONSOLE)
      {
        console_mode  = TRUE;
        console_service (argc, argv);
      }
    else
    if (action == ACTION_NOARG)
      {
        console_send (NULL, FALSE);

        if (win_version == WINDOWS_95)
          {
            hide_window ();
            console_mode = TRUE;
            console_service (argc, argv);
          }
        else
        if (win_version == WINDOWS_NT_3X
        ||  win_version == WINDOWS_NT_4
        ||  win_version == WINDOWS_2000)
          {
            log_printf ("%s: initialising service ...", application_name);
            if (!StartServiceCtrlDispatcher (dispatch_table))
                add_to_message_log ("StartServiceCtrlDispatcher failed");
          }
      }
#elif (defined(__UNIX__))
    else
    if (action == ACTION_BACKGROUND)
      {
        const char
           *background_args [] = { "-s", NULL };

        log_printf ("Moving into the background");
        if (process_server (NULL, NULL, argc, argv, background_args) != 0)
          {
            log_printf ("Backgrounding failed.  Giving up.");
            rc = -1;
          }
        else
          action = ACTION_NOARG;
      }
    if (action == ACTION_NOARG)
      {
        rc = smt_init ();
        if (!rc && (init_fct != NULL))
            rc = (*init_fct)(application_config);
        if (!rc)
            smt_exec_full ();
        if (term_fct != NULL)
            (*term_fct)();
        smt_term ();
      }
#endif
    else
    if (action == ACTION_ERROR)
        puts (USAGE);
    
    free_resources ();
    return rc;
}