[ekg2-commit] r4091 - in trunk: ekg plugins/gg plugins/polchat plugins/rc: trunk/ekg/commands.c trunk/ekg/ekg.c trunk/ekg/plugins.c trunk/ekg/plugins.h trunk/ekg/sessions.c trunk/plugins/gg/commands.c trunk/plugins/polchat/polchat.c trunk/plugins/rc/main.c
SVN commit
svn w toxygen.net
Czw, 10 Lip 2008, 12:59:54 CEST
Author: darkjames
Date: 2008-07-10 12:59:54 +0200 (Thu, 10 Jul 2008)
New Revision: 4091
Modified:
trunk/ekg/commands.c
trunk/ekg/ekg.c
trunk/ekg/plugins.c
trunk/ekg/plugins.h
trunk/ekg/sessions.c
trunk/plugins/gg/commands.c
trunk/plugins/polchat/polchat.c
trunk/plugins/rc/main.c
Log:
restore old watches abi.
unfortunetly it segvs when we do smth like:
watch_t *w1, *w2
(where w2->next == w1)
w2 is running, and in w2 handler we do:
watch_free(w1);
/* watch_free(w2); */
Modified: trunk/ekg/commands.c
===================================================================
--- trunk/ekg/commands.c 2008-07-10 10:07:29 UTC (rev 4090)
+++ trunk/ekg/commands.c 2008-07-10 10:59:54 UTC (rev 4091)
@@ -1897,16 +1897,18 @@
static COMMAND(cmd_debug_watches)
{
- watch_t *w;
char buf[256];
+ list_t l;
printq("generic_bold", ("fd wa plugin pers tout started rm"));
- for (w = watches; w; w = w->next) {
+ for (l = watches; l; l = l->next) {
+ char *plugin;
char wa[4];
- char *plugin;
+ watch_t *w = l->data;
- if (!w) continue;
+ if (!w)
+ continue;
xstrcpy(wa, "");
Modified: trunk/ekg/ekg.c
===================================================================
--- trunk/ekg/ekg.c 2008-07-10 10:07:29 UTC (rev 4090)
+++ trunk/ekg/ekg.c 2008-07-10 10:59:54 UTC (rev 4091)
@@ -192,20 +192,15 @@
}
{ /* removed 'w->removed' watches, timeout checking moved below select() */
- watch_t *w;
+ list_t l;
- for (w = watches; w;) {
- watch_t *next = w->next;
+ for (l = watches; l; l = l->next) {
+ watch_t *w = l->data;
- if (w->removed == 1) {
- watch_t *tmp;
-
+ if (w && w->removed == 1) {
w->removed = 0;
- if ((tmp = watch_free(w))) /* if watch was really deleted, we shall jump */
- next = tmp;
+ watch_free(w);
}
-
- w = next;
}
}
@@ -258,9 +253,10 @@
FD_ZERO(&wd);
{
- watch_t *w;
+ list_t l;
- for (maxfd = 0, w = watches; w; w = w->next) {
+ for (maxfd = 0, l = watches; l; l = l->next) {
+ watch_t *w = l->data;
if (!w)
continue;
@@ -328,20 +324,16 @@
* ekg mogło działać dalej, sprawdźmy który to i go
* usuńmy z listy. */
if (errno == EBADF) {
- watch_t *w;
+ list_t l;
- for (w = watches; w;) {
+ for (l = watches; l; l = l->next) {
+ watch_t *w = l->data;
struct stat st;
- watch_t *next = w->next;
if (w && fstat(w->fd, &st)) {
- watch_t *tmp;
debug("select(): bad file descriptor: fd=%d, type=%d, plugin=%s\n", w->fd, w->type, (w->plugin) ? w->plugin->name : ("none"));
- if ((tmp = watch_free(w)))
- next = tmp;
+ watch_free(w);
}
-
- w = next;
}
} else if (errno != EINTR)
debug("select() failed: %s\n", strerror(errno));
@@ -368,14 +360,15 @@
}
{ /* przejrzyj deskryptory */
- watch_t *w, *next;
+ list_t l;
- for (w = watches; w; w = next) {
- next = w->next;
+ for (l = watches; l; l = l->next) {
+ watch_t *w = l->data;
- if (!FD_ISSET(w->fd, &rd) && !FD_ISSET(w->fd, &wd)) { /* timeout checking */
- watch_t *tmp;
+ if (!w)
+ continue;
+ if (!FD_ISSET(w->fd, &rd) && !FD_ISSET(w->fd, &wd)) { /* timeout checking */
if (w->timeout < 1 || (tv.tv_sec - w->started) < w->timeout)
continue;
w->removed = -1;
@@ -383,16 +376,14 @@
int (*handler)(int, int, char*, void*) = w->handler;
if (handler(2, w->fd, NULL, w->data) == -1 || w->removed == 1) {
w->removed = 0;
- if ((tmp = watch_free(w)))
- next = tmp;
+ watch_free(w);
continue;
}
} else {
int (*handler)(int, int, int, void*) = w->handler;
if (handler(2, w->fd, w->type, w->data) == -1 || w->removed == 1) {
w->removed = 0;
- if ((tmp = watch_free(w)))
- next = tmp;
+ watch_free(w);
continue;
}
}
@@ -427,7 +418,7 @@
if (ekg_watches_removed > 0) {
debug("ekg_loop() Removed %d watches this loop, let's cleanup calling: list_cleanup() ...\n", ekg_watches_removed);
- //list_cleanup(&watches); /* not needed anymore, left for historical reasons ( ; */
+ list_cleanup(&watches);
ekg_watches_removed = 0;
}
}
@@ -1089,16 +1080,12 @@
}
{
- watch_t *w;
+ list_t l;
- for (w = watches; w;) {
- watch_t *tmp;
- watch_t *next = w->next;
+ for (l = watches; l; l = l->next) {
+ watch_t *w = l->data;
- if ((tmp = watch_free(w)))
- next = tmp;
-
- w = next;
+ watch_free(w);
}
}
@@ -1116,7 +1103,7 @@
// if (p->dl) ekg2_dlclose(p->dl);
}
}
- LIST_DESTROY2(watches, NULL); watches = NULL;
+ list_destroy(watches, 0); watches = NULL;
if (config_changed && !config_speech_app && config_save_quit == 1) {
char line[80];
Modified: trunk/ekg/plugins.c
===================================================================
--- trunk/ekg/plugins.c 2008-07-10 10:07:29 UTC (rev 4090)
+++ trunk/ekg/plugins.c 2008-07-10 10:59:54 UTC (rev 4091)
@@ -59,9 +59,7 @@
static __DYNSTUFF_LIST_ADD_SORTED, /* plugins_add() */
__DYNSTUFF_LIST_UNLINK) /* plugins_unlink() */
-watch_t *watches = NULL;
-__DYNSTUFF_LIST_ADD_BEGINNING(watches, watch_t, NULL); /* watches_add() */
-
+list_t watches = NULL;
idle_t *idles = NULL;
query_t *queries[QUERY_EXTERNAL+1];
@@ -394,11 +392,11 @@
int plugin_unload(plugin_t *p)
{
char *name;
+ list_t l;
if (!p)
return -1;
-
if (config_expert_mode == 0 && p->pclass == PLUGIN_UI) {
plugin_t *plug;
@@ -413,14 +411,12 @@
}
}
- {
- watch_t *w;
+ for (l = watches; l; l = l->next) {
+ watch_t *w = l->data;
- for (w = watches; w; w = w->next) {
- if (w && w->plugin == p && (w->removed == 1 || w->removed == -1)) {
- print("generic_error", "XXX cannot remove this plugin when there some watches active");
- return -1;
- }
+ if (w && w->plugin == p && (w->removed == 1 || w->removed == -1)) {
+ print("generic_error", "XXX cannot remove this plugin when there some watches active");
+ return -1;
}
}
/* XXX, to samo dla timerow */
@@ -443,8 +439,6 @@
return 0;
}
-
-
/*
* plugin_register()
*
@@ -500,26 +494,24 @@
* ekg2 do SEGV.
*/
- watch_t *w;
struct timer *t;
idle_t *i;
session_t *s;
query_t **ll;
variable_t *v;
command_t *c;
+ list_t l;
if (!p)
return -1;
/* XXX think about sequence of unloading....: currently: watches, timers, sessions, queries, variables, commands */
- for (w = watches; w;) {
- watch_t *next = w->next;
+ for (l = watches; l; l = l->next) {
+ watch_t *w = l->data;
- if (w->plugin == p)
+ if (w && w->plugin == p)
watch_free(w);
-
- w = next;
}
for (t = timers; t; t = t->next) {
@@ -855,11 +847,12 @@
*
* zwraca obiekt watch_t o podanych parametrach.
*/
-watch_t *watch_find(plugin_t *plugin, int fd, watch_type_t type)
-{
- watch_t *w;
+watch_t *watch_find(plugin_t *plugin, int fd, watch_type_t type) {
+ list_t l;
- for (w = watches; w; w = w->next) {
+ for (l = watches; l; l = l->next) {
+ watch_t *w = l->data;
+
/* XXX: added simple plugin ignoring, make something nicer? */
if (w && ((plugin == (void*) -1) || w->plugin == plugin) && w->fd == fd && (w->type & type) && !(w->removed > 0))
return w;
@@ -891,30 +884,28 @@
* zwraca wskaźnik do następnego obiektu do iterowania
* albo NULL, jak nie można skasować.
*/
-watch_t *watch_free(watch_t *w) {
- void *next;
-
+void watch_free(watch_t *w) {
if (!w)
- return NULL;
+ return;
if (w->removed == 2)
- return NULL;
+ return;
if (w->removed == -1 || w->removed == 1) { /* watch is running.. we cannot remove it */
w->removed = 1;
- return NULL;
+ return;
}
if (w->type == WATCH_WRITE && w->buf && !w->handler) {
debug_error("[INTERNAL_DEBUG] WATCH_LINE_WRITE must be removed by plugin, manually (settype to WATCH_NONE and than call watch_free()\n");
- return NULL;
+ return;
}
- next = LIST_REMOVE2(&watches, w, watch_free_data);
+ watch_free_data(w);
+ list_remove_safe(&watches, w, 1);
+
ekg_watches_removed++;
debug("watch_free() REMOVED WATCH, watches removed this loop: %d oldwatch: 0x%x\n", ekg_watches_removed, w);
-
- return next;
}
/*
@@ -1149,8 +1140,7 @@
w->handler = handler;
w->data = data;
- watches_add(w);
-
+ list_add_beginning(&watches, w);
return w;
}
Modified: trunk/ekg/plugins.h
===================================================================
--- trunk/ekg/plugins.h 2008-07-10 10:07:29 UTC (rev 4090)
+++ trunk/ekg/plugins.h 2008-07-10 10:59:54 UTC (rev 4091)
@@ -26,7 +26,7 @@
#include "dynstuff.h"
#include "sessions.h"
-#define EKG_ABI_VER 4055
+#define EKG_ABI_VER 4090
#define EXPORT __attribute__ ((visibility("default")))
@@ -157,8 +157,6 @@
typedef WATCHER_SESSION(watcher_session_handler_func_t);
typedef struct watch {
- struct watch *next;
-
int fd; /* obserwowany deskryptor */
watch_type_t type; /* co sprawdzamy */
plugin_t *plugin; /* wtyczka obsługująca deskryptor */
@@ -189,7 +187,7 @@
#endif
watch_t *watch_find(plugin_t *plugin, int fd, watch_type_t type);
-watch_t *watch_free(watch_t *w);
+void watch_free(watch_t *w);
typedef void *watch_handler_func_t;
@@ -233,7 +231,7 @@
#ifndef EKG2_WIN32_NOFUNCTION
extern plugin_t *plugins;
-extern watch_t *watches;
+extern list_t watches;
extern idle_t *idles;
extern query_t *queries[];
#endif
Modified: trunk/ekg/sessions.c
===================================================================
--- trunk/ekg/sessions.c 2008-07-10 10:07:29 UTC (rev 4090)
+++ trunk/ekg/sessions.c 2008-07-10 10:59:54 UTC (rev 4091)
@@ -271,6 +271,7 @@
window_t *w;
char *tmp;
int count;
+ list_t l;
if (!(s = session_find(uid)))
return -1;
@@ -297,21 +298,13 @@
}
#endif
- { /* remove session watches */
- watch_t *w;
+/* remove session watches */
+ for (l = watches; l; l = l->next) {
+ watch_t *w = l->data;
- for (w = watches; w;) {
- watch_t *next = w->next;
+ if (w && w->is_session && w->data == s)
+ watch_free(w);
- if (w && w->is_session && w->data == s) {
- watch_t *tmp;
-
- if ((tmp = watch_free(w)))
- next = tmp;
- }
-
- w = next;
- }
}
{
@@ -1445,21 +1438,18 @@
session_t *s;
struct timer *t;
- watch_t *w;
window_t *wl;
+ list_t l;
if (!sessions)
return;
/* remove _ALL_ session watches */
- for (w = watches; w;) {
- watch_t *next = w->next;
- watch_t *tmp;
+ for (l = watches; l; l = l->next) {
+ watch_t *w = l->data;
- if (w->is_session && ((tmp = watch_free(w))))
- next = tmp;
-
- w = next;
+ if (w && w->is_session)
+ watch_free(w);
}
for (t = timers; t; t = t->next) {
Modified: trunk/plugins/gg/commands.c
===================================================================
--- trunk/plugins/gg/commands.c 2008-07-10 10:07:29 UTC (rev 4090)
+++ trunk/plugins/gg/commands.c 2008-07-10 10:59:54 UTC (rev 4091)
@@ -1456,9 +1456,11 @@
/* if we free token... we must search for it in all watches, and point data to NULL */
/* XXX, hack... let's copy token data to all watch ? */
- watch_t *w;
+ list_t l;
- for (w = watches; w; w = w->next) {
+ for (l = watches; l; l = l->next) {
+ watch_t *w = l->data;
+
if (w && w->data == h) {
w->data = NULL;
/* maybe we call remove here ? */
Modified: trunk/plugins/polchat/polchat.c
===================================================================
--- trunk/plugins/polchat/polchat.c 2008-07-10 10:07:29 UTC (rev 4090)
+++ trunk/plugins/polchat/polchat.c 2008-07-10 10:59:54 UTC (rev 4091)
@@ -116,11 +116,13 @@
if (len == fulllen) { /* we sent all data, ok.. */
watch_t *next_watch = NULL;
- watch_t *w;
+ list_t l;
/* turn on next watch */
- for (w = watches; w; w = w->next) { /* watche sa od najnowszego po najstarszy.. dlatego musimy znalezc ostatni... */
+ for (l = watches; l; l = l->next) { /* watche sa od najnowszego po najstarszy.. dlatego musimy znalezc ostatni... */
+ watch_t *w = l->data;
+
if (w && w->fd == fd && w->type == WATCH_NONE)
next_watch = w;
}
@@ -131,9 +133,11 @@
errno = 0;
} else if (len > 0) {
- watch_t *w;
+ list_t l;
- for (w = watches; w; w = w->next) {
+ for (l = watches; l; l = l->next) {
+ watch_t *w = l->data;
+
if (w && w->fd == fd && w->type == WATCH_WRITE_LINE && w->data == data) { /* this watch */
w->data = (void *) fulllen - len;
break;
@@ -310,17 +314,13 @@
}
if (j->fd != -1) {
- watch_t *w;
+ list_t l;
- for (w = watches; w;) {
- watch_t *tmp;
+ for (l = watches; l; l = l->next) {
+ watch_t *w = l->data;
- if (w && w->fd == j->fd &&
- (1 /* || w->type == WATCH_NONE || w->type == WATCH_WRITE_LINE */)
- && ((tmp = watch_free(w))))
- w = tmp;
- else
- w = w->next;
+ if (w && w->fd == j->fd && (1 /* || w->type == WATCH_NONE || w->type == WATCH_WRITE_LINE */))
+ watch_free(w);
}
close(j->fd);
Modified: trunk/plugins/rc/main.c
===================================================================
--- trunk/plugins/rc/main.c 2008-07-10 10:07:29 UTC (rev 4090)
+++ trunk/plugins/rc/main.c 2008-07-10 10:59:54 UTC (rev 4091)
@@ -125,9 +125,11 @@
}
static watch_t *rc_watch_find(int fd) {
- watch_t *w;
+ list_t l;
- for (w = watches; w; w = w->next) {
+ for (l = watches; l; l = l->next) {
+ watch_t *w = l->data;
+
if (w && w->plugin == &rc_plugin && w->fd == fd)
return w;
}
Więcej informacji o liście dyskusyjnej ekg2-commit