OSDN Git Service

Move create_uuid() to lib and xpoll() to lib/net.c.
authorRob Landley <rob@landley.net>
Sat, 16 Jan 2016 22:59:47 +0000 (16:59 -0600)
committerRob Landley <rob@landley.net>
Sat, 16 Jan 2016 22:59:47 +0000 (16:59 -0600)
lib/lib.c
lib/lib.h
lib/net.c
toys/pending/mke2fs.c

index 3e41c63..871eda7 100644 (file)
--- a/lib/lib.c
+++ b/lib/lib.c
@@ -964,14 +964,27 @@ int qstrcmp(const void *a, const void *b)
   return strcmp(*(char **)a, *(char **)b);
 }
 
-int xpoll(struct pollfd *fds, int nfds, int timeout)
+// According to http://www.opengroup.org/onlinepubs/9629399/apdxa.htm
+// we should generate a uuid structure by reading a clock with 100 nanosecond
+// precision, normalizing it to the start of the gregorian calendar in 1582,
+// and looking up our eth0 mac address.
+//
+// On the other hand, we have 128 bits to come up with a unique identifier, of
+// which 6 have a defined value.  /dev/urandom it is.
+
+void create_uuid(char *uuid)
 {
-  int i;
+  // Read 128 random bits
+  int fd = xopen("/dev/urandom", O_RDONLY);
+  xreadall(fd, uuid, 16);
+  close(fd);
 
-  for (;;) {
-    if (0>(i = poll(fds, nfds, timeout))) {
-      if (errno != EINTR && errno != ENOMEM) perror_exit("xpoll");
-      else if (timeout>0) timeout--;
-    } else return i;
-  }
+  // Claim to be a DCE format UUID.
+  uuid[6] = (uuid[6] & 0x0F) | 0x40;
+  uuid[8] = (uuid[8] & 0x3F) | 0x80;
+
+  // rfc2518 section 6.4.1 suggests if we're not using a macaddr, we should
+  // set bit 1 of the node ID, which is the mac multicast bit.  This means we
+  // should never collide with anybody actually using a macaddr.
+  uuid[11] |= 128;
 }
index a6998a8..0c6d379 100644 (file)
--- a/lib/lib.h
+++ b/lib/lib.h
@@ -194,7 +194,7 @@ void crc_init(unsigned int *crc_table, int little_endian);
 void base64_init(char *p);
 int yesno(int def);
 int qstrcmp(const void *a, const void *b);
-int xpoll(struct pollfd *fds, int nfds, int timeout);
+void create_uuid(char *uuid);
 
 #define HR_SPACE 1 // Space between number and units
 #define HR_B     2 // Use "B" for single byte units
@@ -236,6 +236,7 @@ int xsocket(int domain, int type, int protocol);
 void xsetsockopt(int fd, int level, int opt, void *val, socklen_t len);
 int xconnect(char *host, char *port, int family, int socktype, int protocol,
   int flags);
+int xpoll(struct pollfd *fds, int nfds, int timeout);
 
 // password.c
 int get_salt(char *salt, char * algo);
index 48d0a5f..facb096 100644 (file)
--- a/lib/net.c
+++ b/lib/net.c
@@ -42,3 +42,15 @@ int xconnect(char *host, char *port, int family, int socktype, int protocol,
 
   return fd;
 }
+
+int xpoll(struct pollfd *fds, int nfds, int timeout)
+{
+  int i;
+
+  for (;;) {
+    if (0>(i = poll(fds, nfds, timeout))) {
+      if (errno != EINTR && errno != ENOMEM) perror_exit("xpoll");
+      else if (timeout>0) timeout--;
+    } else return i;
+  }
+}
index a2c1529..b4c841a 100644 (file)
@@ -219,31 +219,6 @@ static void check_treelinks(struct dirtree *tree)
   }
 }
 
-// According to http://www.opengroup.org/onlinepubs/9629399/apdxa.htm
-// we should generate a uuid structure by reading a clock with 100 nanosecond
-// precision, normalizing it to the start of the gregorian calendar in 1582,
-// and looking up our eth0 mac address.
-//
-// On the other hand, we have 128 bits to come up with a unique identifier, of
-// which 6 have a defined value.  /dev/urandom it is.
-
-static void create_uuid(char *uuid)
-{
-  // Read 128 random bits
-  int fd = xopen("/dev/urandom", O_RDONLY);
-  xreadall(fd, uuid, 16);
-  close(fd);
-
-  // Claim to be a DCE format UUID.
-  uuid[6] = (uuid[6] & 0x0F) | 0x40;
-  uuid[8] = (uuid[8] & 0x3F) | 0x80;
-
-  // rfc2518 section 6.4.1 suggests if we're not using a macaddr, we should
-  // set bit 1 of the node ID, which is the mac multicast bit.  This means we
-  // should never collide with anybody actually using a macaddr.
-  uuid[11] = uuid[11] | 128;
-}
-
 // Calculate inodes per group from total inodes.
 static uint32_t get_inodespg(uint32_t inodes)
 {