summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--plugins/irc.c6
-rw-r--r--ponymap.c28
2 files changed, 16 insertions, 18 deletions
diff --git a/plugins/irc.c b/plugins/irc.c
index 7732b73..c0e967d 100644
--- a/plugins/irc.c
+++ b/plugins/irc.c
@@ -217,8 +217,10 @@ static void *
scan_init (struct unit *u)
{
char nick[IRC_MAX_NICKNAME + 1];
- for (size_t i = 0; i < sizeof nick - 1; i++)
+ size_t i;
+ for (i = 0; i < sizeof nick - 1; i++)
nick[i] = 'a' + rand () % ('z' - 'a' + 1);
+ nick[i] = '\0';
struct str hello;
str_init (&hello);
@@ -267,7 +269,7 @@ on_irc_message (const struct irc_message *msg, const char *raw, void *user_data)
if (code == IRC_RPL_MYINFO && msg->params.len > 0)
{
char *info = xstrdup_printf ("%s: %s",
- "server name", msg->params.vector[0]);
+ "server name", msg->params.vector[1]);
g_data.api->unit_add_info (scan->u, info);
free (info);
diff --git a/ponymap.c b/ponymap.c
index 57aa882..b0fd94a 100644
--- a/ponymap.c
+++ b/ponymap.c
@@ -229,6 +229,7 @@ struct unit
struct poller_timer timeout_event; ///< Timeout event
struct poller_fd fd_event; ///< FD event
+ bool abortion_requested; ///< Abortion requested by service
bool aborted; ///< Scan has been aborted
bool success; ///< Service has been found
struct str_vector info; ///< Info resulting from the scan
@@ -537,9 +538,10 @@ unit_abort (struct unit *u)
if (u->success)
{
// Now we're a part of the target
- LIST_PREPEND (u->target->results, u);
- target_unref (u->target);
+ struct target *target = u->target;
+ LIST_PREPEND (target->results, u);
u->target = NULL;
+ target_unref (target);
}
else
unit_unref (u);
@@ -562,10 +564,6 @@ on_unit_ready (const struct pollfd *pfd, struct unit *u)
struct service *service = u->service;
enum transport_io_result result;
- // We hold a reference so that unit_abort(), which may also be
- // called by handlers within the service, doesn't free the unit.
- unit_ref (u);
-
if ((result = transport->on_readable (u)))
goto exception;
if (u->read_buffer.len)
@@ -574,15 +572,15 @@ on_unit_ready (const struct pollfd *pfd, struct unit *u)
service->on_data (u->service_data, u, buf);
str_remove_slice (buf, 0, buf->len);
- if (u->aborted)
- goto end;
+ if (u->abortion_requested)
+ goto abort;
}
if ((result = transport->on_writeable (u)))
goto exception;
- if (!u->aborted)
- unit_update_poller (u, pfd);
- goto end;
+
+ unit_update_poller (u, pfd);
+ return;
exception:
if (result == TRANSPORT_IO_EOF)
@@ -596,10 +594,8 @@ exception:
service->on_error (u->service_data, u);
}
+abort:
unit_abort (u);
-
-end:
- unit_unref (u);
}
static void
@@ -783,7 +779,7 @@ plugin_api_unit_get_address (struct unit *u)
static ssize_t
plugin_api_unit_write (struct unit *u, const void *buf, size_t len)
{
- if (u->aborted)
+ if (u->abortion_requested || u->aborted)
return -1;
str_append_data (&u->write_buffer, buf, len);
@@ -805,7 +801,7 @@ plugin_api_unit_add_info (struct unit *u, const char *result)
static void
plugin_api_unit_abort (struct unit *u)
{
- unit_abort (u);
+ u->abortion_requested = true;
}
static struct plugin_api g_plugin_vtable =