Re: [systemd-devel] [PATCH] initial sd-dns commit

2014-01-11 Thread Tom Gundersen
Hi Daniel,

On Mon, Jan 6, 2014 at 12:41 PM, Daniel Buch  wrote:
> Im hopeing we can continue in-tree since its easier from here, and im unable 
> to get the time i want at the moment.
> But i will ofcourse continue to help where i can when time permits.
>
> I think the file nameing and locations are right?

I made a few modifications before pushing, please have a look to see I
didn't mess anything up :)

We should still update stuff like type/function names to use the
sd_dns prefix, but this is a good start. Thanks for your work!

Cheers,

Tom
___
systemd-devel mailing list
systemd-devel@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/systemd-devel


[systemd-devel] [PATCH] initial sd-dns commit

2014-01-06 Thread Daniel Buch
Hi again,

Im hopeing we can continue in-tree since its easier from here, and im unable to 
get the time i want at the moment.
But i will ofcourse continue to help where i can when time permits.

I think the file nameing and locations are right?

Anyway heres what i got so far

---
 Makefile.am   |   29 +
 src/libsystemd-dns/asyncns-util.h |8 +
 src/libsystemd-dns/asyncns.c  | 1158 +
 src/libsystemd-dns/test-asyncns.c |  164 ++
 src/systemd/sd-dns.h  |  156 +
 5 files changed, 1515 insertions(+)
 create mode 100644 src/libsystemd-dns/asyncns-util.h
 create mode 100644 src/libsystemd-dns/asyncns.c
 create mode 100644 src/libsystemd-dns/test-asyncns.c
 create mode 100644 src/systemd/sd-dns.h

diff --git a/Makefile.am b/Makefile.am
index 069583c..9ae123a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -662,6 +662,35 @@ tests += \
 
 # 
--
 noinst_LTLIBRARIES += \
+   libsystemd-dns.la
+
+libsystemd_dns_la_SOURCES = \
+   src/systemd/sd-asyncns.h \
+   src/libsystemd-dns/asyncns.c \
+   src/libsystemd-dns/asyncns-util.h
+
+libsystemd_dns_la_LIBADD = \
+   libsystemd-shared.la
+
+libsystemd_dns_la_CFLAGS = \
+   -pthread
+
+test_dns_SOURCES = \
+   src/libsystemd-dns/test-asyncns.c \
+   src/systemd/sd-dns.h
+
+test_dns_LDADD = \
+   libsystemd-dns.la
+
+test_dns_LDFLAGS = \
+   -lresolv \
+   -pthread
+
+tests += \
+test-dns
+
+# 
--
+noinst_LTLIBRARIES += \
libsystemd-shared.la
 
 libsystemd_shared_la_SOURCES = \
diff --git a/src/libsystemd-dns/asyncns-util.h 
b/src/libsystemd-dns/asyncns-util.h
new file mode 100644
index 000..31d19bd
--- /dev/null
+++ b/src/libsystemd-dns/asyncns-util.h
@@ -0,0 +1,8 @@
+#pragma once
+
+DEFINE_TRIVIAL_CLEANUP_FUNC(asyncns_t*, asyncns_free);
+DEFINE_TRIVIAL_CLEANUP_FUNC(unsigned char *, asyncns_freeanswer);
+DEFINE_TRIVIAL_CLEANUP_FUNC(struct addrinfo*, asyncns_freeaddrinfo);
+#define _cleanup_asyncns_free_ _cleanup_(asyncns_freep)
+#define _cleanup_asyncns_answer_free_ _cleanup_(asyncns_freeanswerp)
+#define _cleanup_asyncns_addrinfo_free_ _cleanup_(asyncns_freeaddrinfop)
diff --git a/src/libsystemd-dns/asyncns.c b/src/libsystemd-dns/asyncns.c
new file mode 100644
index 000..508f6b0
--- /dev/null
+++ b/src/libsystemd-dns/asyncns.c
@@ -0,0 +1,1158 @@
+/***
+  This file is part of libasyncns.
+
+  Copyright 2005-2008 Lennart Poettering
+
+  libasyncns is free software; you can redistribute it and/or modify
+  it under the terms of the GNU Lesser General Public License as
+  published by the Free Software Foundation, either version 2.1 of the
+  License, or (at your option) any later version.
+
+  libasyncns is distributed in the hope that it will be useful, but
+  WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with libasyncns. If not, see
+  .
+ ***/
+
+#ifdef HAVE_CONFIG_H
+#include 
+#endif
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#ifdef HAVE_SYS_PRCTL_H
+#include 
+#endif
+
+#include "sd-dns.h"
+#include "util.h"
+
+#define MAX_WORKERS 16
+#define MAX_QUERIES 256
+#define BUFSIZE (10240)
+
+typedef enum {
+REQUEST_ADDRINFO,
+RESPONSE_ADDRINFO,
+REQUEST_NAMEINFO,
+RESPONSE_NAMEINFO,
+REQUEST_RES_QUERY,
+REQUEST_RES_SEARCH,
+RESPONSE_RES,
+REQUEST_TERMINATE,
+RESPONSE_DIED
+} query_type_t;
+
+enum {
+REQUEST_RECV_FD = 0,
+REQUEST_SEND_FD = 1,
+RESPONSE_RECV_FD = 2,
+RESPONSE_SEND_FD = 3,
+MESSAGE_FD_MAX = 4
+};
+
+struct asyncns {
+int fds[MESSAGE_FD_MAX];
+
+pthread_t workers[MAX_WORKERS];
+unsigned valid_workers;
+
+unsigned current_id, current_index;
+asyncns_query_t* queries[MAX_QUERIES];
+
+asyncns_query_t *done_head, *done_tail;
+
+int n_queries;
+int dead;
+};
+
+struct asyncns_query {
+asyncns_t *asyncns;
+int done;
+unsigned id;
+query_type_t type;
+asyncns_query_t *done_next, *done_prev;
+int ret;
+int _errno;
+int _h_errno;
+struct addrinfo *addrinfo;
+char *serv, *host;
+void *userdata;
+};
+
+typedef struct rheader {
+query_type_t type;
+unsigned id;
+size_t length;
+} rheader_t;
+
+typedef struct addrinfo_request {
+struct rheader header;
+int h