/* exit: * Shuts down the driver, freeing allocated resources, etc. All channels * will already have been destroyed by the `destroy_channel' function, so * normally all this needs to do is tidy up anything `init' left untidy. * Return zero if successful, non-zero otherwise. */ static int local_exit(void) { MUTEX_LOCK(port_list); while (port_list) destroy_port(port_list); MUTEX_UNLOCK(port_list); MUTEX_DESTROY(port_list); return 0; }
static struct snobj *handle_reset_ports(struct snobj *q) { struct port *p; while (list_ports((const struct port **)&p, 1, 0)) destroy_port(p); printf("*** All ports have been destroyed ***\n"); return NULL; }
/* destroy_channel: * Called when a channel is being closed. This should tidy up anything * that init_channel or subsequent functions have left messy, for example * it should free any data block that has been allocated. Return zero if * successful, non-zero otherwise. */ static int local_destroy_channel(NET_CHANNEL *chan) { channel_data_t *data = chan->data; MUTEX_LOCK(port_list); destroy_port(data->port); MUTEX_UNLOCK (port_list); free(data); return 0; }
static struct snobj *handle_reset_ports(struct snobj *q) { struct port *p; while (list_ports((const struct port **)&p, 1, 0)) { int ret = destroy_port(p); if (ret) return snobj_errno(-ret); } printf("*** All ports have been destroyed ***\n"); return NULL; }
static struct snobj *handle_destroy_port(struct snobj *arg) { const char *port_name; struct port *port; int ret; port_name = snobj_str_get(arg); if (!port_name) return snobj_err(EINVAL, "Argument must be a name in str"); port = find_port(port_name); if (!port) return snobj_err(ENOENT, "No port `%s' found", port_name); ret = destroy_port(port); if (ret) return snobj_errno(-ret); return NULL; }