Exemplo n.º 1
0
void server_dump(dbase_server *root, int level)
{
  int i;
  if ((!root) && (!level)) root = servers;
  if (root)
  {
    for (i = 0; i < level; i++) debug_out("| ");
    debug_out("%s (%s) - %s\n", root->name, root->numeric, root->desc);
    for (i = 0; i < root->children_count; i++)
      server_dump(root->children[i], level+1);
  }
}
Exemplo n.º 2
0
/* dump servers */
static void m_dump_server(char *arg)
{
  struct server *sptr = NULL;

  if(arg)
  {
    if(chars_isdigit(*arg))
      sptr = server_find_id(atoi(arg));
    else
      sptr = server_find_name(arg);
  }

  server_dump(sptr);
}
Exemplo n.º 3
0
void dump_internal_state(void)
{
   int dump_fd ;
   const char *dump_file = DUMP_FILE ;
   time_t current_time ;
   int fd ;
   unsigned u ;
   const char *func = "dump_internal_state" ;

   if ( debug.on )
      msg( LOG_DEBUG, func, "Dumping State" ) ;

   dump_fd = open( dump_file, O_WRONLY | O_CREAT | O_APPEND, DUMP_FILE_MODE);
   if ( dump_fd == -1 )
   {
      msg( LOG_ERR, func, "failed to open %s: %m", dump_file ) ;
      return ;
   }
   
   if (Sbuftype( dump_fd, SIO_LINEBUF ) == SIO_ERR )
   {
       /*
	* If the above function failed, Sprint will most likely
	* fail, too. Output a message for troubleshooting and quit.
	*/
       msg( LOG_ERR, func, "failed setting up sio buffering: %m" ) ;
       return;
   }

   /*
    * Print the program name, version, and timestamp.
    * Note that the program_version variable contains the program name.
    */
   (void) time( &current_time ) ;
   Sprint( dump_fd, "INTERNAL STATE DUMP: %s\n", program_version ) ;
   Sprint( dump_fd, "Current time: %s\n", ctime( &current_time ) ) ;

   dump_services( dump_fd ) ;

   /*
    * Dump the server table
    */
   Sprint( dump_fd, "Server table dump:\n" ) ;
   for ( u = 0 ; u < pset_count( SERVERS( ps ) ) ; u++ )
      server_dump( SERP( pset_pointer( SERVERS( ps ), u ) ), dump_fd ) ;
   Sputchar( dump_fd, '\n' ) ;

   /*
    * Dump the retry_table
    */
   Sprint( dump_fd, "Retry table dump:\n" ) ;
   for ( u = 0 ; u < pset_count( RETRIES( ps ) ) ; u++ )
      server_dump( SERP( pset_pointer( RETRIES( ps ), u ) ), dump_fd ) ;
   Sputchar( dump_fd, '\n' ) ;

   /*
    * Dump the socket mask
    */
   Sprint( dump_fd, "Socket mask:" ) ;
   for ( fd = 0 ; fd < ps.ros.max_descriptors ; fd++ )
      if ( FD_ISSET( fd, &ps.rws.socket_mask ) )
         Sprint( dump_fd, " %d", fd ) ;
   Sputchar( dump_fd, '\n' ) ;
   Sprint( dump_fd, "mask_max = %d\n", ps.rws.mask_max ) ;

   /*
    * Dump the descriptors that are open and are *not* in the socket mask
    */
   Sprint( dump_fd, "Open descriptors (not in socket mask):" ) ;
   for ( fd = 0 ; fd < ps.ros.max_descriptors ; fd++ )
   {
      struct stat st ;

      if ( FD_ISSET( fd, &ps.rws.socket_mask ) )
         continue ;
      if ( fstat( fd, &st ) == -1 )
         continue ;
      Sprint( dump_fd, " %d", fd ) ;
   }
   Sputchar( dump_fd, '\n' ) ;
   Sputchar( dump_fd, '\n' ) ;

   Sprint( dump_fd, "active_services = %d\n", ps.rws.active_services ) ;
   Sprint( dump_fd, "available_services = %d\n", ps.rws.available_services ) ;
   Sprint( dump_fd, "descriptors_free = %d\n", ps.rws.descriptors_free ) ;
   Sprint( dump_fd, "running_servers = %d\n", pset_count( SERVERS( ps ) ) ) ;
   Sprint( dump_fd, "Logging service = %s\n",
            LOG_SERVICE( ps ) != NULL ? "enabled" : "not enabled" ) ;
   Sputchar( dump_fd, '\n' ) ;

   Sprint( dump_fd, "max_descriptors = %d\n", (int)ps.ros.max_descriptors ) ;
   Sprint( dump_fd, "process_limit = %d\n", (int)ps.ros.process_limit ) ;
   Sprint( dump_fd, "config_file = %s\n", ps.ros.config_file ) ;
   if ( debug.on )
      Sprint( dump_fd, "debug_fd = %d\n", debug.fd ) ;
   Sputchar( dump_fd, '\n' ) ;

   Sprint( dump_fd, "END OF DUMP\n\n" ) ;
   Sclose( dump_fd );

   msg( LOG_INFO, func, "generated state dump in file %s", dump_file ) ;
}
Exemplo n.º 4
0
static int signal_hello(LassiConnection *lc, DBusMessage *m) {
    const char *id, *address;
    DBusError e;
    GList *i;
    dbus_bool_t b;
    DBusMessage *n;
    gint32 active_generation, order_generation, clipboard_generation;

    dbus_error_init(&e);

    if (lc->id) {
        g_debug("Received duplicate HelloNode.");
        return -1;
    }

    if (!(dbus_message_get_args(
                m, &e,
                DBUS_TYPE_STRING, &id,
                DBUS_TYPE_STRING, &address,
                DBUS_TYPE_INT32, &active_generation,
                DBUS_TYPE_INT32, &order_generation,
                DBUS_TYPE_INT32, &clipboard_generation,
                DBUS_TYPE_INVALID))) {
        g_warning("Received invalid message: %s", e.message);
        dbus_error_free(&e);
        return -1;
    }

    if (strcmp(id, lc->server->id) == 0) {
        g_debug("Dropping looped back connection.");
        return -1;
    }

    if (g_hash_table_lookup(lc->server->connections_by_id, id)) {
        g_debug("Dropping duplicate connection.");
        return -1;
    }

    lc->server->active_generation = MAX(lc->server->active_generation, active_generation);
    lc->server->order_generation = MAX(lc->server->order_generation, order_generation);
    lc->server->clipboard_generation = MAX(lc->server->clipboard_generation, clipboard_generation);

    g_debug("Got welcome from %s (%s)", id, address);

    lc->id = g_strdup(id);
    lc->address = g_strdup(address);
    g_hash_table_insert(lc->server->connections_by_id, lc->id, lc);
    server_position_connection(lc->server, lc);

    /* Notify all old nodes of the new one */
    n = dbus_message_new_signal("/", LASSI_INTERFACE, "NodeAdded");
    g_assert(n);

    b = dbus_message_append_args(n, DBUS_TYPE_STRING, &id, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID);
    g_assert(b);

    server_broadcast(lc->server, n, lc);
    dbus_message_unref(n);

    /* Notify new node about old nodes */
    for (i = lc->server->connections; i; i = i->next) {
        LassiConnection *k = i->data;

        if (k == lc || !k->id)
            continue;

        n = dbus_message_new_signal("/", LASSI_INTERFACE, "NodeAdded");
        g_assert(n);

        b = dbus_message_append_args(n, DBUS_TYPE_STRING, &id, DBUS_TYPE_STRING, &address, DBUS_TYPE_INVALID);
        g_assert(b);

        b = dbus_connection_send(lc->dbus_connection, n, NULL);
        g_assert(b);

        dbus_message_unref(n);
    }

    if (lc->we_are_client) {
        server_send_update_grab(lc->server, -1);
        lassi_server_send_update_order(lc->server, NULL);

        lc->delayed_welcome = FALSE;
        show_welcome(lc, TRUE);
    } else
        lc->delayed_welcome = TRUE;

    server_layout_changed(lc->server, -1);
    lassi_prefs_update(&lc->server->prefs_info);

    server_dump(lc->server);

    return 0;
}
Exemplo n.º 5
0
static void connection_unlink(LassiConnection *lc, gboolean remove_from_order) {
    LassiServer *ls;
    g_assert(lc);

    g_debug("Unlinking %s (%s)", lc->id, lc->address);

    ls = lc->server;

    if (lc->id) {
        DBusMessage *n;
        dbus_bool_t b;

        /* Tell everyone */
        n = dbus_message_new_signal("/", LASSI_INTERFACE, "NodeRemoved");
        g_assert(n);

        b = dbus_message_append_args(n,
                                     DBUS_TYPE_STRING, &lc->id,
                                     DBUS_TYPE_STRING, &lc->address,
                                     DBUS_TYPE_BOOLEAN, &remove_from_order,
                                     DBUS_TYPE_INVALID);
        g_assert(b);

        server_broadcast(ls, n, NULL);
        dbus_message_unref(n);
    }

    ls->connections = g_list_remove(ls->connections, lc);
    ls->n_connections --;

    if (lc->id) {
        show_welcome(lc, FALSE);

        g_hash_table_remove(ls->connections_by_id, lc->id);
        ls->connections_left = g_list_remove(ls->connections_left, lc);
        ls->connections_right = g_list_remove(ls->connections_right, lc);

        if (ls->active_connection == lc)
            server_pick_active_connection(ls);

        if (ls->clipboard_connection == lc) {
            ls->clipboard_connection = NULL;
            ls->clipboard_empty = TRUE;
            lassi_clipboard_clear(&lc->server->clipboard_info, FALSE);
        }

        if (ls->primary_connection == lc) {
            ls->primary_connection = NULL;
            ls->primary_empty = TRUE;
            lassi_clipboard_clear(&lc->server->clipboard_info, TRUE);
        }

        if (remove_from_order) {
            GList *i = g_list_find_custom(ls->order, lc->id, (GCompareFunc) strcmp);

            if (i)
                ls->order = g_list_delete_link(ls->order, i);
        }

        server_layout_changed(ls, -1);
        lassi_prefs_update(&ls->prefs_info);
        server_dump(ls);
    }

    lassi_tray_update(&ls->tray_info, ls->n_connections);

    connection_destroy(lc);
}