Exemple #1
0
/* Set up an RPC for procedure PROCNUM for talking to the portmapper.
   Allocate storage with malloc and point *BUF at it; caller must free
   this when done.  Return the address where the args for the
   procedure should be placed. */
static int *
pmap_initialize_rpc (int procnum, void **buf)
{
  return initialize_rpc (PMAPPROG, PMAPVERS, procnum, 0, buf, 0, 0, -1);
}
Exemple #2
0
/* Set up an RPC for procedure PROCNUM for talking to the mount
   server.  Allocate storage with malloc and point *BUF at it; caller
   must free this when done.  Return the address where the args for
   the procedure should be placed.  */
static int *
mount_initialize_rpc (int procnum, void **buf)
{
  return initialize_rpc (MOUNTPROG, MOUNTVERS, procnum, 0, buf, 0, 0, -1);
}
Exemple #3
0
int
main (int argc, const char **argv)
{
    GMainLoop *main_loop;
    struct sigaction sig_action;
    const char *config_file;
    char *python_path;

    g_thread_init (NULL);
    g_type_init ();

    rcd_executable_name = g_strdup (argv[0]);

    rcd_options_parse (argc, argv);

    if (rcd_options_get_show_version ()) {
        g_print ("%s\n", rcd_about_name ());
        g_print ("%s\n\n", rcd_about_copyright ());
        exit (0);
    }

    config_file = rcd_options_get_config_file ();
    if (config_file && !g_file_test (config_file, G_FILE_TEST_EXISTS)) {
        g_printerr ("Unable to find config file '%s'\n", config_file);
        g_printerr ("rcd aborting\n");

        exit (-1);
    }

    root_check ();
    if (!rcd_options_get_late_background ())
        daemonize ();

    /* Set up SIGTERM and SIGQUIT handlers */
    sig_action.sa_handler = signal_handler;
    sigemptyset (&sig_action.sa_mask);
    sig_action.sa_flags = 0;
    sigaction (SIGINT,  &sig_action, NULL);
    sigaction (SIGTERM, &sig_action, NULL);
    sigaction (SIGQUIT, &sig_action, NULL);

    /* Set up SIGHUP handler. */
    sig_action.sa_handler = sighup_handler;
    sigemptyset (&sig_action.sa_mask);
    sig_action.sa_flags = 0;
    sigaction (SIGHUP, &sig_action, NULL);
    
    /* If it looks like rcd-buddy is in the right place, set up
       handlers for crashes */
    python_path = g_find_program_in_path ("python");
    if (python_path != NULL
        && g_file_test (SHAREDIR "/rcd-buddy", G_FILE_TEST_EXISTS)) {
        sig_action.sa_handler = crash_handler;
        sigaction (SIGSEGV, &sig_action, NULL);
        sigaction (SIGFPE,  &sig_action, NULL);
        sigaction (SIGBUS,  &sig_action, NULL);
        sigaction (SIGABRT, &sig_action, NULL);
    }
    g_free (python_path);

    rcd_privileges_init ();

    initialize_logging ();

    /* Check to see if the password file is secure.
       If it isn't, a big warning will go out to the log file. */
    rcd_identity_password_file_is_secure ();

    /* Set the GPG keyring for package verification */
    rc_verification_set_keyring (SHAREDIR "/rcd.gpg");

    /* Create mid and secret */
    if (!g_file_test (SYSCONFDIR "/mcookie", G_FILE_TEST_EXISTS))
        rcd_create_uuid (SYSCONFDIR "/mcookie");

    if (!g_file_test (SYSCONFDIR "/partnernet", G_FILE_TEST_EXISTS))
        rcd_create_uuid (SYSCONFDIR "/partnernet");

    /* Add memory usage watcher */
    rcd_heartbeat_register_func (heartbeat_memory_monitor, NULL);

    initialize_rc_packman ();
    initialize_rc_services ();
    initialize_rc_world ();
    initialize_rpc ();

    if (!rcd_options_get_no_modules_flag ())
        rcd_module_init ();

    /* We can't daemonize any later than this, so hopefully module
       initialization won't be slow. */
    if (rcd_options_get_late_background ()) {
        
        rc_debug (RC_DEBUG_LEVEL_ALWAYS, "Running daemon in background.");
        daemonize ();

        /* We need to reinit logging, since the file descriptor gets closed
           when we daemonize. */
        rcd_log_reinit ();

        /* Say hello again, so it gets stored in the log file. */
        hello ();
    }

    rcd_rpc_local_server_start ();

    if (rcd_prefs_get_remote_server_enabled ()) {
        if (!rcd_rpc_remote_server_start ())
            exit (-1);
    }

    initialize_data ();
    
    /* No heartbeat if we have initialized from a dump file. */
    if (rcd_options_get_dump_file () == NULL)
        rcd_heartbeat_start ();

    main_loop = g_main_loop_new (NULL, TRUE);
    g_main_loop_run (main_loop);

    /*
     * We'll never reach here, because we'll exit() out in
     * rcd-shutdown.c.
     */
    g_assert_not_reached ();

    return 0;
} /* main */