Allow disk paths of (almost) any length in both gkrellm and gkrellmd.
monitor.c: serve_disk_data() now uses a dynamic buffer for to-be-sent disk-lines instead of relying on a very short static array. client.c: read_server_setup() now uses a static read buffer that is as big/small as the global server_buf. client_disk_line_from_server() now uses a dynamic string for disk names.
This commit is contained in:
parent
3450feee97
commit
6bd26e8401
|
@ -571,7 +571,7 @@ serve_disk_data(GkrellmdMonitor *mon, gboolean first_serve)
|
||||||
{
|
{
|
||||||
DiskData *disk;
|
DiskData *disk;
|
||||||
GList *list;
|
GList *list;
|
||||||
gchar buf[128];
|
gchar *buf = NULL;
|
||||||
|
|
||||||
gkrellmd_set_serve_name(mon, "disk");
|
gkrellmd_set_serve_name(mon, "disk");
|
||||||
for (list = disk_list; list; list = list->next)
|
for (list = disk_list; list; list = list->next)
|
||||||
|
@ -582,18 +582,20 @@ serve_disk_data(GkrellmdMonitor *mon, gboolean first_serve)
|
||||||
if (!disk->subdisk_parent)
|
if (!disk->subdisk_parent)
|
||||||
{
|
{
|
||||||
if (gkrellmd_check_client_version(mon, 2, 2, 7) && disk->virtual)
|
if (gkrellmd_check_client_version(mon, 2, 2, 7) && disk->virtual)
|
||||||
snprintf(buf, sizeof(buf), "%s virtual %" PRIu64 " %" PRIu64 "\n",
|
buf = g_strdup_printf("%s virtual %" PRIu64 " %" PRIu64 "\n",
|
||||||
disk->name, disk->rb, disk->wb);
|
disk->name, disk->rb, disk->wb);
|
||||||
else
|
else
|
||||||
snprintf(buf, sizeof(buf), "%s %" PRIu64 " %" PRIu64 "\n",
|
buf = g_strdup_printf("%s %" PRIu64 " %" PRIu64 "\n",
|
||||||
disk->name, disk->rb, disk->wb);
|
disk->name, disk->rb, disk->wb);
|
||||||
}
|
}
|
||||||
else if (mon->privat->client->feature_subdisk)
|
else if (mon->privat->client->feature_subdisk)
|
||||||
snprintf(buf, sizeof(buf), "%s %s %" PRIu64 " %" PRIu64 "\n",
|
buf = g_strdup_printf("%s %s %" PRIu64 " %" PRIu64 "\n",
|
||||||
disk->name, disk->subdisk_parent, disk->rb, disk->wb);
|
disk->name, disk->subdisk_parent, disk->rb, disk->wb);
|
||||||
else
|
else
|
||||||
continue;
|
continue;
|
||||||
gkrellmd_serve_data(mon, buf);
|
gkrellmd_serve_data(mon, buf);
|
||||||
|
g_free(buf);
|
||||||
|
buf = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
26
src/client.c
26
src/client.c
|
@ -102,7 +102,7 @@ static gint client_input_id,
|
||||||
client_fd;
|
client_fd;
|
||||||
static gboolean server_alive;
|
static gboolean server_alive;
|
||||||
|
|
||||||
static gchar server_buf[4097];
|
static gchar server_buf[4097]; /* TODO: Use dynamic receive buffer */
|
||||||
static gint buf_index;
|
static gint buf_index;
|
||||||
|
|
||||||
static gchar locale_decimal_point;
|
static gchar locale_decimal_point;
|
||||||
|
@ -303,13 +303,17 @@ client_disk_line_from_server(gchar *line)
|
||||||
{
|
{
|
||||||
DiskData *disk = NULL;
|
DiskData *disk = NULL;
|
||||||
GList *list;
|
GList *list;
|
||||||
gchar name[16], s1[32], s2[32], s3[32];
|
gchar *name;
|
||||||
|
gchar s1[32], s2[32], s3[32];
|
||||||
guint64 rblk, wblk;
|
guint64 rblk, wblk;
|
||||||
gint n;
|
gint n;
|
||||||
gboolean virtual = FALSE;
|
gboolean virtual = FALSE;
|
||||||
|
|
||||||
// FIXME: Extend client and server to support disks with both name and label
|
g_assert(line != NULL);
|
||||||
n = sscanf(line, "%15s %31s %31s %31s", name, s1, s2, s3);
|
name = g_malloc(strlen(line) * sizeof(gchar));
|
||||||
|
|
||||||
|
/* FIXME: Extend client and server to support disks with both name and label */
|
||||||
|
n = sscanf(line, "%s %31s %31s %31s", name, s1, s2, s3);
|
||||||
if (n == 4)
|
if (n == 4)
|
||||||
{
|
{
|
||||||
if ( gkrellm_client_check_server_version(2, 2, 7)
|
if ( gkrellm_client_check_server_version(2, 2, 7)
|
||||||
|
@ -329,15 +333,22 @@ client_disk_line_from_server(gchar *line)
|
||||||
s1[0] = '\0';
|
s1[0] = '\0';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
g_warning("Invalid disk line received from server: \"%s\"", line);
|
||||||
|
g_free(name);
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
for (list = disk_list; list; list = list->next)
|
for (list = disk_list; list; list = list->next)
|
||||||
{
|
{
|
||||||
|
/* Search disk in list */
|
||||||
disk = (DiskData *) list->data;
|
disk = (DiskData *) list->data;
|
||||||
if (!strcmp(disk->name, name))
|
if (!strcmp(disk->name, name))
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!list)
|
if (!list)
|
||||||
{
|
{
|
||||||
|
/* Disk wasn't found, create new disk and add to list */
|
||||||
disk = g_new0(DiskData, 1);
|
disk = g_new0(DiskData, 1);
|
||||||
disk->name = g_strdup(name);
|
disk->name = g_strdup(name);
|
||||||
if (s1[0]) /* I expect server to send in order */
|
if (s1[0]) /* I expect server to send in order */
|
||||||
|
@ -346,10 +357,12 @@ client_disk_line_from_server(gchar *line)
|
||||||
}
|
}
|
||||||
if (disk)
|
if (disk)
|
||||||
{
|
{
|
||||||
|
/* Assign parsed data to disk */
|
||||||
disk->rblk = rblk;
|
disk->rblk = rblk;
|
||||||
disk->wblk = wblk;
|
disk->wblk = wblk;
|
||||||
disk->virtual = virtual;
|
disk->virtual = virtual;
|
||||||
}
|
}
|
||||||
|
g_free(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -1620,6 +1633,7 @@ KeyTable update_table[] =
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* TODO: Port to GInputStream */
|
||||||
static gint
|
static gint
|
||||||
gkrellm_getline(gint fd, gchar *buf, gint len)
|
gkrellm_getline(gint fd, gchar *buf, gint len)
|
||||||
{
|
{
|
||||||
|
@ -1649,7 +1663,7 @@ gkrellm_getline(gint fd, gchar *buf, gint len)
|
||||||
}
|
}
|
||||||
if (nread < 0 && errno != EINTR)
|
if (nread < 0 && errno != EINTR)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Broken server connection\n");
|
g_warning("Broken server connection\n");
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
gkrellm_debug(DEBUG_CLIENT, "%s\n", buf);
|
gkrellm_debug(DEBUG_CLIENT, "%s\n", buf);
|
||||||
|
@ -1698,7 +1712,7 @@ process_server_line(KeyTable *table, gint table_size, gchar *line)
|
||||||
static gboolean
|
static gboolean
|
||||||
read_server_setup(gint fd)
|
read_server_setup(gint fd)
|
||||||
{
|
{
|
||||||
gchar buf[256];
|
gchar buf[4097]; /* TODO: Use dynamic receive buffer */
|
||||||
gint table_size;
|
gint table_size;
|
||||||
|
|
||||||
gkrellm_debug(DEBUG_CLIENT, "read_server_setup()\n");
|
gkrellm_debug(DEBUG_CLIENT, "read_server_setup()\n");
|
||||||
|
|
Loading…
Reference in New Issue