#include "cli.h"
+static vector keys;
+static vector handlers;
+
static struct key *
alloc_key (void)
{
}
void
-free_handlers (vector vec)
+free_handlers (void)
{
int i;
struct handler * h;
- vector_foreach_slot (vec, h, i)
+ vector_foreach_slot (handlers, h, i)
FREE(h);
- vector_free(vec);
+ vector_free(handlers);
+ handlers = NULL;
}
int
return 0;
}
+void cli_exit(void)
+{
+ free_handlers();
+ free_keys(keys);
+ keys = NULL;
+}
+
static int
key_match_fingerprint (struct key * kw, int fp)
{
int (*fn)(void *, char **, int *, void *);
};
-vector keys;
-vector handlers;
-
int alloc_handlers (void);
int add_handler (int fp, int (*fn)(void *, char **, int *, void *));
int set_handler_callback (int fp, int (*fn)(void *, char **, int *, void *));
int load_keys (void);
char * get_keyparam (vector v, int code);
void free_keys (vector vec);
-void free_handlers (vector vec);
+void free_handlers (void);
int cli_init (void);
+void cli_exit(void);
char * key_generator (const char * str, int state);
vector_foreach_slot(vecs->mpvec, mpp, i)
dm_queue_if_no_path(mpp->alias, 0);
remove_maps_and_stop_waiters(vecs);
- free_pathvec(vecs->pathvec, FREE_PATHS);
+ unlock(vecs->lock);
pthread_cancel(check_thr);
pthread_cancel(uevent_thr);
sysfs_cleanup();
- free_keys(keys);
- keys = NULL;
- free_handlers(handlers);
- handlers = NULL;
- free_polls();
-
+ lock(vecs->lock);
+ free_pathvec(vecs->pathvec, FREE_PATHS);
+ vecs->pathvec = NULL;
unlock(vecs->lock);
/* Now all the waitevent threads will start rushing in. */
while (vecs->lock.depth > 0) {
#include <uxsock.h>
#include <defaults.h>
+#include "cli.h"
#include "uxlsnr.h"
#define SLEEP_TIME 5000
static struct client *clients;
static unsigned num_clients;
+struct pollfd *polls;
/*
* handle a new client joining
void free_polls (void)
{
- FREE(polls);
+ if (polls)
+ FREE(polls);
+}
+
+void uxsock_cleanup(void *arg)
+{
+ cli_exit();
+ free_polls();
}
/*
exit(1);
}
+ pthread_cleanup_push(uxsock_cleanup, NULL);
+
polls = (struct pollfd *)MALLOC(0);
while (1) {
/* something went badly wrong! */
condlog(0, "poll");
- exit(1);
+ pthread_exit(NULL);
}
if (poll_count == 0)
}
}
+ pthread_cleanup_pop(1);
close(ux_sock);
return NULL;
}
-struct pollfd *polls;
+#ifndef _UXLSNR_H
+#define _UXLSNR_H
-void free_polls(void);
void * uxsock_listen(int (*uxsock_trigger)
(char *, char **, int *, void *),
void * trigger_data);
+#endif