Send connman mailing list submissions to
        connman@lists.01.org

To subscribe or unsubscribe via the World Wide Web, visit
        https://lists.01.org/mailman/listinfo/connman
or, via email, send a message with subject or body 'help' to
        connman-requ...@lists.01.org

You can reach the person managing the list at
        connman-ow...@lists.01.org

When replying, please edit your Subject line so it is more specific
than "Re: Contents of connman digest..."


Today's Topics:

   1. [PATCH 10/16] util: Reading from /dev/urandom ignores the
      number of bytes read (Peter Meerwald-Stadler)
   2. [PATCH 12/16] shared: Add util_get_random()
      (Peter Meerwald-Stadler)
   3. [PATCH 11/16] shared: Drop unused shared/debugfs.c|.h
      (Peter Meerwald-Stadler)
   4. [PATCH 14/16] gdhcp: Remove dhcp_get_random()
      (Peter Meerwald-Stadler)
   5. [PATCH 13/16] gdhcp: Use util_get_random()
      (Peter Meerwald-Stadler)
   6. [PATCH 15/16] Use util_get_random() (Peter Meerwald-Stadler)
   7. [PATCH 16/16] Remove __connman_util_get_random()
      (Peter Meerwald-Stadler)


----------------------------------------------------------------------

Message: 1
Date: Sat, 17 Sep 2016 13:05:30 +0200
From: Peter Meerwald-Stadler <pme...@pmeerw.net>
To: Patrik Flykt <patrik.fl...@linux.intel.com>
Cc: connman@lists.01.org
Subject: [PATCH 10/16] util: Reading from /dev/urandom ignores the
        number of bytes read
Message-ID: <1474110336-13602-11-git-send-email-pme...@pmeerw.net>

falling back to random()

CID 1352469
---
 src/util.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/util.c b/src/util.c
index d9cb905..e6532c8 100644
--- a/src/util.c
+++ b/src/util.c
@@ -40,15 +40,20 @@ static int f = -1;
 
 int __connman_util_get_random(uint64_t *val)
 {
-       int r = 0;
+       int r;
 
        if (!val)
                return -EINVAL;
 
-       if (read(f, val, sizeof(uint64_t)) < 0) {
+       r = read(f, val, sizeof(uint64_t));
+       if (r < 0) {
                r = -errno;
                connman_warn_once("Could not read from "URANDOM);
                *val = random();
+       } else if (r != sizeof(uint64_t)) {
+               r = -EIO;
+               connman_warn_once("Short read from "URANDOM);
+               *val = random();
        }
 
        return r;
-- 
2.7.4



------------------------------

Message: 2
Date: Sat, 17 Sep 2016 13:05:32 +0200
From: Peter Meerwald-Stadler <pme...@pmeerw.net>
To: Patrik Flykt <patrik.fl...@linux.intel.com>
Cc: connman@lists.01.org
Subject: [PATCH 12/16] shared: Add util_get_random()
Message-ID: <1474110336-13602-13-git-send-email-pme...@pmeerw.net>

---
 src/shared/util.c | 45 +++++++++++++++++++++++++++++++++++++++++++++
 src/shared/util.h |  5 +++++
 2 files changed, 50 insertions(+)

diff --git a/src/shared/util.c b/src/shared/util.c
index df045c5..cd9af68 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -25,9 +25,15 @@
 #include <config.h>
 #endif
 
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <stdlib.h>
 #include <stdio.h>
 #include <ctype.h>
 #include <stdarg.h>
+#include <unistd.h>
+#include <errno.h>
 
 #include "src/shared/util.h"
 
@@ -88,3 +94,42 @@ void util_hexdump(const char dir, const unsigned char *buf, 
size_t len,
                function(str, user_data);
        }
 }
+
+#define URANDOM "/dev/urandom"
+static int f = -1;
+
+int util_get_random(uint64_t *val)
+{
+       int r;
+
+       if (!val)
+               return -EINVAL;
+
+       if (f < 0) {
+               f = open(URANDOM, O_RDONLY);
+               if (f < 0) {
+                       r = -errno;
+                       *val = random();
+                       return r;
+               }
+       }
+
+       r = read(f, val, sizeof(uint64_t));
+       if (r < 0) {
+               r = -errno;
+               *val = random();
+       } else if (r != sizeof(uint64_t)) {
+               r = -EIO;
+               *val = random();
+       }
+
+       return r;
+}
+
+void util_cleanup(void)
+{
+       if (f > 0)
+               close(f);
+
+       f = -1;
+}
diff --git a/src/shared/util.h b/src/shared/util.h
index 293fb3a..067feca 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -21,6 +21,7 @@
  *
  */
 
+#include <stdint.h>
 #include <glib.h>
 
 typedef void (*util_debug_func_t)(const char *str, void *user_data);
@@ -48,3 +49,7 @@ static inline struct cb_data *cb_data_new(void *cb, void 
*user_data)
 
        return ret;
 }
+
+int util_get_random(uint64_t *val);
+void util_cleanup(void);
+
-- 
2.7.4



------------------------------

Message: 3
Date: Sat, 17 Sep 2016 13:05:31 +0200
From: Peter Meerwald-Stadler <pme...@pmeerw.net>
To: Patrik Flykt <patrik.fl...@linux.intel.com>
Cc: connman@lists.01.org
Subject: [PATCH 11/16] shared: Drop unused shared/debugfs.c|.h
Message-ID: <1474110336-13602-12-git-send-email-pme...@pmeerw.net>

---
 src/shared/debugfs.c | 66 ----------------------------------------------------
 src/shared/debugfs.h | 24 -------------------
 2 files changed, 90 deletions(-)
 delete mode 100644 src/shared/debugfs.c
 delete mode 100644 src/shared/debugfs.h

diff --git a/src/shared/debugfs.c b/src/shared/debugfs.c
deleted file mode 100644
index f522c51..0000000
--- a/src/shared/debugfs.c
+++ /dev/null
@@ -1,66 +0,0 @@
-/*
- *
- *  Connection Manager
- *
- *  Copyright (C) 2012  Intel Corporation. All rights reserved.
- *
- *
- *  This library 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.
- *
- *  This library 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 this library; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <stdio.h>
-#include <stdbool.h>
-#include <string.h>
-#include <limits.h>
-
-#include "src/shared/debugfs.h"
-
-#define STRINGIFY(x) STRINGIFY_ARG(x)
-#define STRINGIFY_ARG(x) #x
-
-const char *debugfs_get_path(void)
-{
-       static char path[PATH_MAX + 1];
-       static bool found = false;
-       char type[100];
-       FILE *fp;
-
-       if (found)
-               return path;
-
-       fp = fopen("/proc/mounts", "r");
-       if (!fp)
-               return NULL;
-
-       while (fscanf(fp, "%*s %" STRINGIFY(PATH_MAX) "s %99s %*s %*d %*d\n",
-                                                       path, type) == 2) {
-               if (!strcmp(type, "debugfs")) {
-                       found = true;
-                       break;
-               }
-       }
-
-       fclose(fp);
-
-       if (!found)
-               return NULL;
-
-       return path;
-}
diff --git a/src/shared/debugfs.h b/src/shared/debugfs.h
deleted file mode 100644
index 7f41ca7..0000000
--- a/src/shared/debugfs.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- *
- *  Connection Manager
- *
- *  Copyright (C) 2012  Intel Corporation. All rights reserved.
- *
- *
- *  This library 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.
- *
- *  This library 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 this library; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-const char *debugfs_get_path(void);
-- 
2.7.4



------------------------------

Message: 4
Date: Sat, 17 Sep 2016 13:05:34 +0200
From: Peter Meerwald-Stadler <pme...@pmeerw.net>
To: Patrik Flykt <patrik.fl...@linux.intel.com>
Cc: connman@lists.01.org
Subject: [PATCH 14/16] gdhcp: Remove dhcp_get_random()
Message-ID: <1474110336-13602-15-git-send-email-pme...@pmeerw.net>

---
 gdhcp/common.c | 36 ------------------------------------
 gdhcp/gdhcp.h  |  3 ---
 src/dhcp.c     |  2 --
 3 files changed, 41 deletions(-)

diff --git a/gdhcp/common.c b/gdhcp/common.c
index d88bb7b..cdc39b0 100644
--- a/gdhcp/common.c
+++ b/gdhcp/common.c
@@ -60,42 +60,6 @@ static const DHCPOption client_options[] = {
        { OPTION_UNKNOWN,               0x00 },
 };
 
-#define URANDOM "/dev/urandom"
-static int random_fd = -1;
-
-int dhcp_get_random(uint64_t *val)
-{
-       int r;
-
-       if (random_fd < 0) {
-               random_fd = open(URANDOM, O_RDONLY);
-               if (random_fd < 0) {
-                       r = -errno;
-                       *val = random();
-
-                       return r;
-               }
-       }
-
-       if (read(random_fd, val, sizeof(uint64_t)) < 0) {
-               r = -errno;
-               *val = random();
-
-               return r;
-       }
-
-       return 0;
-}
-
-void dhcp_cleanup_random(void)
-{
-       if (random_fd < 0)
-               return;
-
-       close(random_fd);
-       random_fd = -1;
-}
-
 GDHCPOptionType dhcp_get_code_type(uint8_t code)
 {
        int i;
diff --git a/gdhcp/gdhcp.h b/gdhcp/gdhcp.h
index 3dcb7a5..c5ed434 100644
--- a/gdhcp/gdhcp.h
+++ b/gdhcp/gdhcp.h
@@ -231,9 +231,6 @@ void g_dhcp_server_set_save_lease(GDHCPServer *dhcp_server,
 void g_dhcp_server_set_lease_added_cb(GDHCPServer *dhcp_server,
                                                        GDHCPLeaseAddedCb cb);
 
-int dhcp_get_random(uint64_t *val);
-void dhcp_cleanup_random(void);
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/src/dhcp.c b/src/dhcp.c
index 57e7ac9..ab947f7 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -719,6 +719,4 @@ void __connman_dhcp_cleanup(void)
 
        g_hash_table_destroy(ipconfig_table);
        ipconfig_table = NULL;
-
-       dhcp_cleanup_random();
 }
-- 
2.7.4



------------------------------

Message: 5
Date: Sat, 17 Sep 2016 13:05:33 +0200
From: Peter Meerwald-Stadler <pme...@pmeerw.net>
To: Patrik Flykt <patrik.fl...@linux.intel.com>
Cc: connman@lists.01.org
Subject: [PATCH 13/16] gdhcp: Use util_get_random()
Message-ID: <1474110336-13602-14-git-send-email-pme...@pmeerw.net>

---
 Makefile.am    | 4 ++--
 gdhcp/client.c | 8 ++++----
 gdhcp/common.c | 2 +-
 gdhcp/common.h | 1 +
 gdhcp/ipv4ll.c | 7 +++----
 src/main.c     | 2 ++
 6 files changed, 13 insertions(+), 11 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 96a305d..4632d6d 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -339,10 +339,10 @@ tools_wpad_test_LDADD = @GLIB_LIBS@ -lresolv
 
 tools_stats_tool_LDADD = @GLIB_LIBS@
 
-tools_dhcp_test_SOURCES = $(gdhcp_sources) tools/dhcp-test.c
+tools_dhcp_test_SOURCES = $(gdhcp_sources) $(shared_sources) tools/dhcp-test.c
 tools_dhcp_test_LDADD = @GLIB_LIBS@
 
-tools_dhcp_server_test_SOURCES = $(gdhcp_sources) tools/dhcp-server-test.c
+tools_dhcp_server_test_SOURCES = $(gdhcp_sources) $(shared_sources) 
tools/dhcp-server-test.c
 tools_dhcp_server_test_LDADD = @GLIB_LIBS@
 
 tools_dbus_test_SOURCES = tools/dbus-test.c
diff --git a/gdhcp/client.c b/gdhcp/client.c
index af1b953..305a666 100644
--- a/gdhcp/client.c
+++ b/gdhcp/client.c
@@ -519,7 +519,7 @@ static int send_release(GDHCPClient *dhcp_client,
        debug(dhcp_client, "sending DHCP release request");
 
        init_packet(dhcp_client, &packet, DHCPRELEASE);
-       dhcp_get_random(&rand);
+       util_get_random(&rand);
        packet.xid = rand;
        packet.ciaddr = htonl(ciaddr);
 
@@ -1682,7 +1682,7 @@ static gboolean continue_rebound(gpointer user_data)
        /*recalculate remaining rebind time*/
        dhcp_client->T2 >>= 1;
        if (dhcp_client->T2 > 60) {
-               dhcp_get_random(&rand);
+               util_get_random(&rand);
                dhcp_client->t2_timeout =
                        g_timeout_add_full(G_PRIORITY_HIGH,
                                        dhcp_client->T2 * 1000 + (rand % 2000) 
- 1000,
@@ -1730,7 +1730,7 @@ static gboolean continue_renew (gpointer user_data)
        dhcp_client->T1 >>= 1;
 
        if (dhcp_client->T1 > 60) {
-               dhcp_get_random(&rand);
+               util_get_random(&rand);
                dhcp_client->t1_timeout = g_timeout_add_full(G_PRIORITY_HIGH,
                                dhcp_client->T1 * 1000 + (rand % 2000) - 1000,
                                continue_renew,
@@ -2824,7 +2824,7 @@ int g_dhcp_client_start(GDHCPClient *dhcp_client, const 
char *last_address)
                if (re != 0)
                        return re;
 
-               dhcp_get_random(&rand);
+               util_get_random(&rand);
                dhcp_client->xid = rand;
                dhcp_client->start = time(NULL);
        }
diff --git a/gdhcp/common.c b/gdhcp/common.c
index 3cc6a09..d88bb7b 100644
--- a/gdhcp/common.c
+++ b/gdhcp/common.c
@@ -400,7 +400,7 @@ void dhcpv6_init_header(struct dhcpv6_packet *packet, 
uint8_t type)
 
        packet->message = type;
 
-       dhcp_get_random(&rand);
+       util_get_random(&rand);
        id = rand;
 
        packet->transaction_id[0] = (id >> 16) & 0xff;
diff --git a/gdhcp/common.h b/gdhcp/common.h
index 75abc18..57db3a7 100644
--- a/gdhcp/common.h
+++ b/gdhcp/common.h
@@ -26,6 +26,7 @@
 
 #include "unaligned.h"
 #include "gdhcp.h"
+#include "src/shared/util.h"
 
 #define CLIENT_PORT 68
 #define SERVER_PORT 67
diff --git a/gdhcp/ipv4ll.c b/gdhcp/ipv4ll.c
index c43971f..93db7fb 100644
--- a/gdhcp/ipv4ll.c
+++ b/gdhcp/ipv4ll.c
@@ -45,9 +45,8 @@ uint32_t ipv4ll_random_ip(void)
        uint64_t rand;
 
        do {
-               dhcp_get_random(&rand);
-               tmp = rand;
-               tmp = tmp & IN_CLASSB_HOST;
+               util_get_random(&rand);
+               tmp = rand & IN_CLASSB_HOST;
        } while (tmp > (IN_CLASSB_HOST - 0x0200));
        return ((LINKLOCAL_ADDR + 0x0100) + tmp);
 }
@@ -59,7 +58,7 @@ guint ipv4ll_random_delay_ms(guint secs)
 {
        uint64_t rand;
 
-       dhcp_get_random(&rand);
+       util_get_random(&rand);
        return rand % (secs * 1000);
 }
 
diff --git a/src/main.c b/src/main.c
index fdb4f72..678f288 100644
--- a/src/main.c
+++ b/src/main.c
@@ -37,6 +37,7 @@
 
 #include <gdbus.h>
 
+#include "src/shared/util.h"
 #include "connman.h"
 
 #define DEFAULT_INPUT_REQUEST_TIMEOUT (120 * 1000)
@@ -748,6 +749,7 @@ int main(int argc, char *argv[])
        __connman_dbus_cleanup();
 
        __connman_log_cleanup(option_backtrace);
+       util_cleanup();
 
        dbus_connection_unref(conn);
 
-- 
2.7.4



------------------------------

Message: 6
Date: Sat, 17 Sep 2016 13:05:35 +0200
From: Peter Meerwald-Stadler <pme...@pmeerw.net>
To: Patrik Flykt <patrik.fl...@linux.intel.com>
Cc: connman@lists.01.org
Subject: [PATCH 15/16] Use util_get_random()
Message-ID: <1474110336-13602-16-git-send-email-pme...@pmeerw.net>

---
 src/config.c   | 4 +++-
 src/dhcpv6.c   | 8 +++++---
 src/dnsproxy.c | 4 ++--
 3 files changed, 10 insertions(+), 6 deletions(-)

diff --git a/src/config.c b/src/config.c
index ba10fbb..70f1959 100644
--- a/src/config.c
+++ b/src/config.c
@@ -35,6 +35,8 @@
 
 #include <connman/provision.h>
 #include <connman/ipaddress.h>
+
+#include "src/shared/util.h"
 #include "connman.h"
 
 struct connman_config_service {
@@ -1485,7 +1487,7 @@ static void generate_random_string(char *str, int length)
 
        for (i = 0; i < length-1; i++) {
                do {
-                       __connman_util_get_random(&rand);
+                       util_get_random(&rand);
                        val = (uint8_t)(rand % 122);
                        if (val < 48)
                                val += 48;
diff --git a/src/dhcpv6.c b/src/dhcpv6.c
index 4346817..406a059 100644
--- a/src/dhcpv6.c
+++ b/src/dhcpv6.c
@@ -31,6 +31,8 @@
 #include <connman/ipconfig.h>
 #include <connman/storage.h>
 
+#include "src/shared/util.h"
+
 #include <gdhcp/gdhcp.h>
 
 #include <glib.h>
@@ -109,7 +111,7 @@ static guint compute_random(guint val)
 {
        uint64_t rand;
 
-       __connman_util_get_random(&rand);
+       util_get_random(&rand);
 
        return val - val / 10 +
                ((guint) rand % (2 * 1000)) * val / 10 / 1000;
@@ -1639,7 +1641,7 @@ int __connman_dhcpv6_start_info(struct connman_network 
*network,
        g_hash_table_replace(network_table, network, dhcp);
 
        /* Initial timeout, RFC 3315, 18.1.5 */
-       __connman_util_get_random(&rand);
+       util_get_random(&rand);
        delay = rand % 1000;
 
        dhcp->timeout = g_timeout_add(delay, start_info_req, dhcp);
@@ -1829,7 +1831,7 @@ int __connman_dhcpv6_start(struct connman_network 
*network,
        g_hash_table_replace(network_table, network, dhcp);
 
        /* Initial timeout, RFC 3315, 17.1.2 */
-       __connman_util_get_random(&rand);
+       util_get_random(&rand);
        delay = rand % 1000;
 
        /*
diff --git a/src/dnsproxy.c b/src/dnsproxy.c
index f3ebcf0..f5764b1 100644
--- a/src/dnsproxy.c
+++ b/src/dnsproxy.c
@@ -39,6 +39,7 @@
 
 #include <glib.h>
 
+#include "src/shared/util.h"
 #include "connman.h"
 
 #if __BYTE_ORDER == __LITTLE_ENDIAN
@@ -221,7 +222,7 @@ static guint16 get_id(void)
 {
        uint64_t rand;
 
-       __connman_util_get_random(&rand);
+       util_get_random(&rand);
 
        return rand;
 }
@@ -238,7 +239,6 @@ static int protocol_offset(int protocol)
        default:
                return -EINVAL;
        }
-
 }
 
 /*
-- 
2.7.4



------------------------------

Message: 7
Date: Sat, 17 Sep 2016 13:05:36 +0200
From: Peter Meerwald-Stadler <pme...@pmeerw.net>
To: Patrik Flykt <patrik.fl...@linux.intel.com>
Cc: connman@lists.01.org
Subject: [PATCH 16/16] Remove __connman_util_get_random()
Message-ID: <1474110336-13602-17-git-send-email-pme...@pmeerw.net>

---
 Makefile.am   |  2 +-
 src/connman.h |  3 --
 src/main.c    |  2 --
 src/util.c    | 93 -----------------------------------------------------------
 4 files changed, 1 insertion(+), 99 deletions(-)
 delete mode 100644 src/util.c

diff --git a/Makefile.am b/Makefile.am
index 4632d6d..28f1ade 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -123,7 +123,7 @@ src_connmand_SOURCES = $(gdhcp_sources) $(gweb_sources) 
$(backtrace_sources) \
                        src/stats.c src/dnsproxy.c src/6to4.c \
                        src/ippool.c src/bridge.c src/nat.c src/ipaddress.c \
                        src/inotify.c src/ipv6pd.c src/peer.c \
-                       src/peer_service.c src/machine.c src/util.c
+                       src/peer_service.c src/machine.c
 
 src_connmand_LDADD = gdbus/libgdbus-internal.la $(builtin_libadd) \
                        @GLIB_LIBS@ @DBUS_LIBS@ @GNUTLS_LIBS@ \
diff --git a/src/connman.h b/src/connman.h
index 401e3d7..fe0df3e 100644
--- a/src/connman.h
+++ b/src/connman.h
@@ -1045,6 +1045,3 @@ void __connman_nfacct_cleanup(void);
 int __connman_machine_init(void);
 void __connman_machine_cleanup(void);
 
-int __connman_util_get_random(uint64_t *val);
-int __connman_util_init(void);
-void __connman_util_cleanup(void);
diff --git a/src/main.c b/src/main.c
index 678f288..7b16606 100644
--- a/src/main.c
+++ b/src/main.c
@@ -656,7 +656,6 @@ int main(int argc, char *argv[])
        else
                config_init(option_config);
 
-       __connman_util_init();
        __connman_inotify_init();
        __connman_technology_init();
        __connman_notifier_init();
@@ -745,7 +744,6 @@ int main(int argc, char *argv[])
        __connman_technology_cleanup();
        __connman_inotify_cleanup();
 
-       __connman_util_cleanup();
        __connman_dbus_cleanup();
 
        __connman_log_cleanup(option_backtrace);
diff --git a/src/util.c b/src/util.c
deleted file mode 100644
index e6532c8..0000000
--- a/src/util.c
+++ /dev/null
@@ -1,93 +0,0 @@
-/*
- *
- *  Connection Manager
- *
- *  Copyright (C) 2014  Intel Corporation. All rights reserved.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License version 2 as
- *  published by the Free Software Foundation.
- *
- *  This program 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 General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <inttypes.h>
-#include <stdint.h>
-#include <unistd.h>
-#include <errno.h>
-#include <stdlib.h>
-
-#include "connman.h"
-
-#define URANDOM "/dev/urandom"
-
-static int f = -1;
-
-int __connman_util_get_random(uint64_t *val)
-{
-       int r;
-
-       if (!val)
-               return -EINVAL;
-
-       r = read(f, val, sizeof(uint64_t));
-       if (r < 0) {
-               r = -errno;
-               connman_warn_once("Could not read from "URANDOM);
-               *val = random();
-       } else if (r != sizeof(uint64_t)) {
-               r = -EIO;
-               connman_warn_once("Short read from "URANDOM);
-               *val = random();
-       }
-
-       return r;
-}
-
-int __connman_util_init(void)
-{
-       int r = 0;
-
-       if (f > 0)
-               return 0;
-
-       f = open(URANDOM, O_RDONLY);
-       if (f < 0) {
-               r = -errno;
-               connman_warn("Could not open "URANDOM);
-               srandom(time(NULL));
-       } else {
-               uint64_t val;
-
-               r = __connman_util_get_random(&val);
-               if (r < 0)
-                       srandom(time(NULL));
-               else
-                       srandom(val);
-       }
-
-       return r;
-}
-
-void __connman_util_cleanup(void)
-{
-       if (f > 0)
-               close(f);
-
-       f = -1;
-}
-- 
2.7.4



------------------------------

Subject: Digest Footer

_______________________________________________
connman mailing list
connman@lists.01.org
https://lists.01.org/mailman/listinfo/connman


------------------------------

End of connman Digest, Vol 11, Issue 20
***************************************

Reply via email to