pidgin: 9045ccd8: dns: Check read/write return value to si..
darkrain42 at pidgin.im
darkrain42 at pidgin.im
Sat Oct 31 23:25:27 EDT 2009
-----------------------------------------------------------------
Revision: 9045ccd8ac58880d5eb07820e9fd0172aa0e60f8
Ancestor: bca56d60292040ef7de64e6409cb17f7870ee413
Author: darkrain42 at pidgin.im
Date: 2009-11-01T03:23:03
Branch: im.pidgin.pidgin
URL: http://d.pidgin.im/viewmtn/revision/info/9045ccd8ac58880d5eb07820e9fd0172aa0e60f8
Modified files:
libpurple/dnssrv.c
ChangeLog:
dns: Check read/write return value to silence a bunch of warnings.
-------------- next part --------------
============================================================
--- libpurple/dnssrv.c 10a0c7060220d0a1bb70766f3e79a4471546ba25
+++ libpurple/dnssrv.c 6264d6837b73fbc87e6e4218ccb72280e57ae7c8
@@ -263,7 +263,58 @@ dns_str_is_ascii(const char *name)
#endif
#ifndef _WIN32
+static void
+write_to_parent(int in, int out, gconstpointer data, gsize size)
+{
+ const guchar *buf = data;
+ gssize w;
+ do {
+ w = write(out, buf, size);
+ if (w > 0) {
+ buf += w;
+ size -= w;
+ } else if (w < 0 && errno == EINTR) {
+ /* Let's try some more; */
+ w = 1;
+ }
+ } while (size > 0 && w > 0);
+
+ if (size != 0) {
+ /* An error occurred */
+ close(out);
+ close(in);
+ _exit(0);
+ }
+}
+
+/* Read size bytes to data. Dies if an error occurs. */
+static void
+read_from_parent(int in, int out, gpointer data, gsize size)
+{
+ guchar *buf = data;
+ gssize r;
+
+ do {
+ r = read(in, data, size);
+ if (r > 0) {
+ buf += r;
+ size -= r;
+ } else if (r < 0 && errno == EINTR) {
+ /* Let's try some more; */
+ r = 1;
+ }
+ } while (size > 0 && r > 0);
+
+ if (size != 0) {
+ /* An error occurred */
+ close(out);
+ close(in);
+ _exit(0);
+ }
+}
+
+
G_GNUC_NORETURN static void
resolve(int in, int out)
{
@@ -281,16 +332,12 @@ resolve(int in, int out)
purple_restore_default_signal_handlers();
#endif
- if (read(in, &query, sizeof(query)) <= 0) {
- close(out);
- close(in);
- _exit(0);
- }
+ read_from_parent(in, out, &query, sizeof(query));
size = res_query( query.query, C_IN, query.type, (u_char*)&answer, sizeof( answer));
if (size == -1) {
- write(out, &(query.type), sizeof(query.type));
- write(out, &size, sizeof(int));
+ write_to_parent(in, out, &(query.type), sizeof(query.type));
+ write_to_parent(in, out, &size, sizeof(size));
close(out);
close(in);
_exit(0);
@@ -355,19 +402,17 @@ end:
if (query.type == T_SRV)
ret = purple_srv_sort(ret);
- /* TODO: Check return value */
- write(out, &(query.type), sizeof(query.type));
- write(out, &size, sizeof(size));
+ write_to_parent(in, out, &(query.type), sizeof(query.type));
+ write_to_parent(in, out, &size, sizeof(size));
while (ret != NULL)
{
- /* TODO: Check return value */
if (query.type == T_SRV)
- write(out, ret->data, sizeof(PurpleSrvResponse));
+ write_to_parent(in, out, ret->data, sizeof(PurpleSrvResponse));
if (query.type == T_TXT) {
PurpleTxtResponse *response = ret->data;
gsize l = strlen(response->content) + 1 /* null byte */;
- write(out, &l, sizeof(l));
- write(out, response->content, l);
+ write_to_parent(in, out, &l, sizeof(l));
+ write_to_parent(in, out, response->content, l);
}
g_free(ret->data);
More information about the Commits
mailing list