dhcp: merge branch 'systemd-dhcp' into master
authorThomas Haller <thaller@redhat.com>
Mon, 23 Mar 2015 20:00:10 +0000 (21:00 +0100)
committerThomas Haller <thaller@redhat.com>
Mon, 23 Mar 2015 20:12:31 +0000 (21:12 +0100)
Conflicts:
src/dhcp-manager/systemd-dhcp/src/shared/util.c

1  2 
src/dhcp-manager/systemd-dhcp/src/libsystemd-network/sd-dhcp-client.c
src/dhcp-manager/systemd-dhcp/src/libsystemd/sd-id128/sd-id128.c
src/dhcp-manager/systemd-dhcp/src/shared/log.h
src/dhcp-manager/systemd-dhcp/src/shared/path-util.c
src/dhcp-manager/systemd-dhcp/src/shared/path-util.h
src/dhcp-manager/systemd-dhcp/src/shared/socket-util.h
src/dhcp-manager/systemd-dhcp/src/shared/strv.c
src/dhcp-manager/systemd-dhcp/src/shared/strv.h
src/dhcp-manager/systemd-dhcp/src/shared/util.c
src/dhcp-manager/systemd-dhcp/src/shared/util.h
src/dhcp-manager/systemd-dhcp/src/systemd/sd-event.h

    along with systemd; If not, see <http://www.gnu.org/licenses/>.
  ***/
  
 +#include "nm-sd-adapt.h"
 +
  #include <stdbool.h>
  #include <stdarg.h>
+ #include <stdlib.h>
  #include <syslog.h>
  #include <sys/signalfd.h>
  #include <errno.h>
  #include "virt.h"
  #include "def.h"
  #include "sparse-endian.h"
 +#endif /* NM_IGNORED */
  
+ /* Put this test here for a lack of better place */
+ assert_cc(EAGAIN == EWOULDBLOCK);
 +#if 0 /* NM_IGNORED */
  int saved_argc = 0;
  char **saved_argv = NULL;
  
@@@ -2350,7 -2329,17 +2353,18 @@@ ssize_t loop_read(int fd, void *buf, si
          return n;
  }
  
+ int loop_read_exact(int fd, void *buf, size_t nbytes, bool do_poll) {
+         ssize_t n;
+         n = loop_read(fd, buf, nbytes, do_poll);
+         if (n < 0)
+                 return n;
+         if ((size_t) n != nbytes)
+                 return -EIO;
+         return 0;
+ }
 +#if 0 /* NM_IGNORED */
  int loop_write(int fd, const void *buf, size_t nbytes, bool do_poll) {
          const uint8_t *p = buf;
  
@@@ -2602,13 -2591,12 +2616,14 @@@ char* dirname_malloc(const char *path) 
  
          return dir;
  }
 +#endif /* NM_IGNORED */
  
  int dev_urandom(void *p, size_t n) {
 +#if 0 /* NM_IGNORED */
          static int have_syscall = -1;
-         int r, fd;
-         ssize_t k;
+         _cleanup_close_ int fd = -1;
+         int r;
  
          /* Gathers some randomness from the kernel. This call will
           * never block, and will always return some data from the
                                  return -errno;
                  } else
                          /* too short read? */
-                         return -EIO;
+                         return -ENODATA;
          }
-         int fd;
-         ssize_t k;
 +#else /* NM IGNORED */
++        _cleanup_close_ int fd = -1;
 +#endif /* NM_IGNORED */
  
          fd = open("/dev/urandom", O_RDONLY|O_CLOEXEC|O_NOCTTY);
          if (fd < 0)
@@@ -8172,4 -8145,44 +8198,45 @@@ void cmsg_close_all(struct msghdr *mh) 
                  if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SCM_RIGHTS)
                          close_many((int*) CMSG_DATA(cmsg), (cmsg->cmsg_len - CMSG_LEN(0)) / sizeof(int));
  }
+ int rename_noreplace(int olddirfd, const char *oldpath, int newdirfd, const char *newpath) {
+         struct stat buf;
+         int ret;
+         ret = renameat2(olddirfd, oldpath, newdirfd, newpath, RENAME_NOREPLACE);
+         if (ret >= 0)
+                 return 0;
+         /* Even though renameat2() exists since Linux 3.15, btrfs added
+          * support for it later. If it is not implemented, fallback to another
+          * method. */
+         if (errno != EINVAL)
+                 return -errno;
+         /* The link()/unlink() fallback does not work on directories. But
+          * renameat() without RENAME_NOREPLACE gives the same semantics on
+          * directories, except when newpath is an *empty* directory. This is
+          * good enough. */
+         ret = fstatat(olddirfd, oldpath, &buf, AT_SYMLINK_NOFOLLOW);
+         if (ret >= 0 && S_ISDIR(buf.st_mode)) {
+                 ret = renameat(olddirfd, oldpath, newdirfd, newpath);
+                 return ret >= 0 ? 0 : -errno;
+         }
+         /* If it is not a directory, use the link()/unlink() fallback. */
+         ret = linkat(olddirfd, oldpath, newdirfd, newpath, 0);
+         if (ret < 0)
+                 return -errno;
+         ret = unlinkat(olddirfd, oldpath, 0);
+         if (ret < 0) {
+                 /* backup errno before the following unlinkat() alters it */
+                 ret = errno;
+                 (void) unlinkat(newdirfd, newpath, 0);
+                 errno = ret;
+                 return -errno;
+         }
+         return 0;
+ }
 +#endif /* NM_IGNORED */