Commit 998e6993 authored by Niels Möller's avatar Niels Möller
Browse files

* src/resource.h (REMEMBER_RESOURCE): Deleted method, use an

ordinary fucntion remember_Resource instead. Updated all callers.

* src/resource.c (concrete_resource_list): Deleted class, put all
information directly in the resource_lsit class.
(remember_resource): New public function.

Rev: src/channel.c:1.109
Rev: src/channel_forward.c:1.6
Rev: src/client_pty.c:1.22
Rev: src/client_session.c:1.16
Rev: src/client_x11.c:1.18
Rev: src/connection.c:1.71
Rev: src/connection_commands.c:1.41
Rev: src/gateway_commands.c:1.15
Rev: src/gc.c:1.30
Rev: src/io_commands.c:1.50
Rev: src/keyexchange.c:1.85
Rev: src/resource.c:1.25
Rev: src/resource.h:1.14
Rev: src/server_session.c:1.79
parent c620d9e1
......@@ -393,7 +393,7 @@ register_channel(UINT32 local_channel_number,
if (take_into_use)
use_channel(channel->connection, local_channel_number);
REMEMBER_RESOURCE(channel->connection->resources,
remember_resource(channel->connection->resources,
&channel->resources->super);
}
......
......@@ -59,7 +59,7 @@ init_channel_forward(struct channel_forward *self,
self->socket = socket;
REMEMBER_RESOURCE(self->super.resources, &socket->super);
remember_resource(self->super.resources, &socket->super);
}
struct channel_forward *
......
......@@ -146,11 +146,11 @@ do_pty_continuation(struct command_continuation *s,
"Setting the attributes of the local terminal failed.\n");
}
REMEMBER_RESOURCE(channel->resources,
remember_resource(channel->resources,
make_client_tty_resource(self->req->tty,
self->req->attr));
REMEMBER_RESOURCE(channel->resources,
remember_resource(channel->resources,
INTERACT_WINDOW_SUBSCRIBE
(self->req->tty,
make_client_winch_handler(channel)));
......
......@@ -168,9 +168,9 @@ do_client_io(struct command *s UNUSED,
= make_channel_read_close_callback(channel);
/* Make sure stdio is closed properly if the channel or connection dies */
REMEMBER_RESOURCE(channel->resources, &session->in->super);
REMEMBER_RESOURCE(channel->resources, &session->out->super);
REMEMBER_RESOURCE(channel->resources, &session->err->super);
remember_resource(channel->resources, &session->in->super);
remember_resource(channel->resources, &session->out->super);
remember_resource(channel->resources, &session->err->super);
ALIST_SET(channel->request_types, ATOM_EXIT_STATUS,
&make_handle_exit_status(session->exit_status)->super);
......@@ -220,9 +220,9 @@ make_client_session_channel(struct lsh_fd *in,
self->err = err;
self->escape = escape;
REMEMBER_RESOURCE(self->super.resources, &in->super);
REMEMBER_RESOURCE(self->super.resources, &out->super);
REMEMBER_RESOURCE(self->super.resources, &err->super);
remember_resource(self->super.resources, &in->super);
remember_resource(self->super.resources, &out->super);
remember_resource(self->super.resources, &err->super);
/* Flow control */
out->write_buffer->report = &self->super.super;
......
......@@ -455,7 +455,7 @@ DEFINE_CHANNEL_OPEN(channel_open_x11)
make_exc_x11_connect_handler(e, HANDLER_CONTEXT));
if (fd)
REMEMBER_RESOURCE(connection->resources, &fd->super);
remember_resource(connection->resources, &fd->super);
else
EXCEPTION_RAISE(e,
make_channel_open_exception(SSH_OPEN_CONNECT_FAILED,
......@@ -670,7 +670,7 @@ do_request_x11_continuation(struct command_continuation *s,
self->connection->table->x11_display = self->display;
REMEMBER_RESOURCE(channel->resources,
remember_resource(channel->resources,
make_client_x11_display_resource(self->connection,
self->display));
......
......@@ -597,5 +597,5 @@ connection_set_timeout(struct ssh_connection *connection,
connection->timer = io_callout(&timeout->super,
seconds);
REMEMBER_RESOURCE(connection->resources, connection->timer);
remember_resource(connection->resources, connection->timer);
}
......@@ -47,7 +47,7 @@ DEFINE_COMMAND2(connection_remember)
CAST_SUBTYPE(resource, resource, a2);
if (resource)
REMEMBER_RESOURCE(connection->resources, resource);
remember_resource(connection->resources, resource);
COMMAND_RETURN(c, resource);
}
......
......@@ -166,7 +166,7 @@ DEFINE_COMMAND2(gateway_accept)
struct ssh_connection *gateway = gateway_make_connection(lv, e);
/* Kill gateway connection if the main connection goes down. */
REMEMBER_RESOURCE(connection->resources, &lv->fd->super);
remember_resource(connection->resources, &lv->fd->super);
gateway->chain = connection;
......
......@@ -232,7 +232,7 @@ gc_global(struct resource *o)
assert(root_set->super.alive);
REMEMBER_RESOURCE(root_set, o);
remember_resource(root_set, o);
}
void gc(void)
......
......@@ -212,7 +212,7 @@ do_connect(struct address_info *a,
}
if (resources)
REMEMBER_RESOURCE(resources,
remember_resource(resources,
&fd->super);
}
......
......@@ -602,7 +602,7 @@ set_reexchange_timeout(struct ssh_connection *connection,
connection->key_expire = io_callout(&timeout->super,
seconds);
REMEMBER_RESOURCE(connection->resources, connection->key_expire);
remember_resource(connection->resources, connection->key_expire);
}
/* GABA:
......
......@@ -33,24 +33,17 @@
#include <assert.h>
/* Prototypes */
void dont_free_live_resource(int alive);
#define GABA_DEFINE
#include "resource.h.x"
#undef GABA_DEFINE
/* Forward declarations */
struct resource_node;
void dont_free_live_resource(int alive);
void do_mark_resources(struct resource_node **q,
void (*mark)(struct lsh_object *o));
void do_free_resources(struct resource_node **q);
#include "resource.c.x"
#define GABA_DEFINE
#include "resource.h.x"
#undef GABA_DEFINE
/* Sanity check */
......@@ -87,16 +80,6 @@ struct resource_node
struct resource *resource;
};
/* Works as a weak list of resources. */
/* GABA:
(class
(name concrete_resource_list)
(super resource_list)
(vars
(q indirect-special "struct resource_node *"
do_mark_resources do_free_resources)))
*/
/* Loop over the resources, mark the living and unlink the dead. */
void
do_mark_resources(struct resource_node **q,
......@@ -134,16 +117,15 @@ do_free_resources(struct resource_node **q)
}
static void
do_remember_resource(struct resource_list *s,
struct resource *resource)
void
remember_resource(struct resource_list *self,
struct resource *resource)
{
CAST(concrete_resource_list, self, s);
struct resource_node *n;
assert(resource);
if (!self->super.super.alive)
if (!self->super.alive)
{
werror("do_remember_resource: resource list is already dead.\n");
KILL_RESOURCE(resource);
......@@ -160,35 +142,39 @@ do_remember_resource(struct resource_list *s,
static void
do_kill_all(struct resource *s)
{
CAST(concrete_resource_list, self, s);
struct resource_node *n;
CAST(resource_list, self, s);
trace("do_kill_all: resource_list %xi\n", self);
for (n = self->q; n; )
{
CAST_SUBTYPE(resource, r, n->resource);
struct resource_node *old = n;
KILL_RESOURCE(r);
n = n->next;
if (self->super.alive)
{
struct resource_node *n;
self->super.alive = 0;
lsh_space_free(old);
for (n = self->q; n; )
{
CAST_SUBTYPE(resource, r, n->resource);
struct resource_node *old = n;
KILL_RESOURCE(r);
n = n->next;
lsh_space_free(old);
}
self->q = NULL;
}
self->q = NULL;
self->super.super.alive = 0;
}
struct resource_list *
make_resource_list(void)
{
NEW(concrete_resource_list, self);
init_resource(&self->super.super, do_kill_all);
NEW(resource_list, self);
init_resource(&self->super, do_kill_all);
trace("make_resource_list: created %xi\n", self);
self->super.remember = do_remember_resource;
self->q = NULL;
return &self->super;
return self;
}
......@@ -30,6 +30,9 @@
#include "lsh.h"
/* Forward declarations */
struct resource_node;
#define GABA_DECLARE
#include "resource.h.x"
#undef GABA_DECLARE
......@@ -51,19 +54,22 @@ void
init_resource(struct resource *self,
void (*k)(struct resource *));
/* For the resource list. */
/* Works as a weak list of resources. */
/* GABA:
(class
(name resource_list)
(super resource)
(vars
(remember method void "struct resource *r")))
(q indirect-special "struct resource_node *"
do_mark_resources do_free_resources)))
*/
#define REMEMBER_RESOURCE(l, r) ((l)->remember((l), (r)))
#define KILL_RESOURCE_LIST(l) KILL_RESOURCE(&(l)->super)
void remember_resource(struct resource_list *self,
struct resource *resource);
/* Allocates an empty list. */
struct resource_list *make_resource_list(void);
......
......@@ -531,17 +531,17 @@ spawn_process(struct server_session *session,
/* Make sure that the process and it's stdio is
* cleaned up if the channel or connection dies. */
REMEMBER_RESOURCE
remember_resource
(channel->resources, &child->super);
/* FIXME: How to do this properly if in and out may use the
* same fd? */
REMEMBER_RESOURCE
remember_resource
(channel->resources, &session->in->super);
REMEMBER_RESOURCE
remember_resource
(channel->resources, &session->out->super);
if (session->err)
REMEMBER_RESOURCE
remember_resource
(channel->resources, &session->err->super);
/* Don't close channel immediately at EOF, as we want to
......@@ -984,7 +984,7 @@ do_alloc_pty(struct channel_request *c UNUSED,
* on the master pty? */
session->term = term;
session->pty = pty;
REMEMBER_RESOURCE(channel->resources, &pty->super);
remember_resource(channel->resources, &pty->super);
verbose(" granted.\n");
COMMAND_RETURN(s, NULL);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment