Blame 0041-dracut-install-make-use-of-_cleanup_-macros.patch

Harald Hoyer e2c90d
From 3ed08d1e4dbb52dc181be01b6e147017327aa6d9 Mon Sep 17 00:00:00 2001
Harald Hoyer e2c90d
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer e2c90d
Date: Mon, 29 Apr 2013 11:35:23 +0200
Harald Hoyer e2c90d
Subject: [PATCH] dracut-install: make use of _cleanup_* macros
Harald Hoyer e2c90d
Harald Hoyer e2c90d
---
Harald Hoyer e2c90d
 install/dracut-install.c | 230 +++++++++++++++++++++++++----------------------
Harald Hoyer e2c90d
 install/macro.h          | 150 +++++++++++++++++++++++++------
Harald Hoyer e2c90d
 install/util.h           |  36 ++++++++
Harald Hoyer e2c90d
 3 files changed, 281 insertions(+), 135 deletions(-)
Harald Hoyer e2c90d
Harald Hoyer e2c90d
diff --git a/install/dracut-install.c b/install/dracut-install.c
Harald Hoyer e2c90d
index 2fad6df..b4bf681 100644
Harald Hoyer e2c90d
--- a/install/dracut-install.c
Harald Hoyer e2c90d
+++ b/install/dracut-install.c
Harald Hoyer e2c90d
@@ -62,6 +62,10 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res
Harald Hoyer e2c90d
 static size_t dir_len(char const *file)
Harald Hoyer e2c90d
 {
Harald Hoyer e2c90d
         size_t length;
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+        if(!file)
Harald Hoyer e2c90d
+                return 0;
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
         /* Strip the basename and any redundant slashes before it.  */
Harald Hoyer e2c90d
         for (length = strlen(file)-1; 0 < length; length--)
Harald Hoyer e2c90d
                 if (file[length] == '/' && file[length-1] != '/')
Harald Hoyer e2c90d
@@ -73,20 +77,22 @@ static char *convert_abs_rel(const char *from, const char *target)
Harald Hoyer e2c90d
 {
Harald Hoyer e2c90d
         /* we use the 4*MAXPATHLEN, which should not overrun */
Harald Hoyer e2c90d
         char relative_from[MAXPATHLEN * 4];
Harald Hoyer e2c90d
-        char *realtarget = NULL;
Harald Hoyer e2c90d
-        char *p, *q;
Harald Hoyer e2c90d
+        _cleanup_free_ char *realtarget = NULL;
Harald Hoyer e2c90d
+        _cleanup_free_ char *target_dir_p = NULL, *realpath_p = NULL;
Harald Hoyer e2c90d
         const char *realfrom = from;
Harald Hoyer e2c90d
         int level = 0, fromlevel = 0, targetlevel = 0;
Harald Hoyer e2c90d
         int l, i, rl;
Harald Hoyer e2c90d
         int dirlen;
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
-        p = strdup(target);
Harald Hoyer e2c90d
-        dirlen = dir_len(p);
Harald Hoyer e2c90d
-        p[dirlen] = '\0';
Harald Hoyer e2c90d
-        q = realpath(p, NULL);
Harald Hoyer e2c90d
+        target_dir_p = strdup(target);
Harald Hoyer e2c90d
+        if (!target_dir_p)
Harald Hoyer e2c90d
+                return strdup(from);
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+        dirlen = dir_len(target_dir_p);
Harald Hoyer e2c90d
+        target_dir_p[dirlen] = '\0';
Harald Hoyer e2c90d
+        realpath_p = realpath(target_dir_p, NULL);
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
-        if (q == NULL) {
Harald Hoyer e2c90d
-                free(p);
Harald Hoyer e2c90d
+        if (realpath_p == NULL) {
Harald Hoyer e2c90d
                 log_warning("convert_abs_rel(): target '%s' directory has no realpath.", target);
Harald Hoyer e2c90d
                 return strdup(from);
Harald Hoyer e2c90d
         }
Harald Hoyer e2c90d
@@ -95,11 +101,9 @@ static char *convert_abs_rel(const char *from, const char *target)
Harald Hoyer e2c90d
          * character - need to skip all leading /'s */
Harald Hoyer e2c90d
         rl = strlen(target);
Harald Hoyer e2c90d
         for (i = dirlen+1; i < rl; ++i)
Harald Hoyer e2c90d
-            if (p[i] != '/')
Harald Hoyer e2c90d
+            if (target_dir_p[i] != '/')
Harald Hoyer e2c90d
                 break;
Harald Hoyer e2c90d
-        asprintf(&realtarget, "%s/%s", q, &p[i]);
Harald Hoyer e2c90d
-        free(p);
Harald Hoyer e2c90d
-        free(q);
Harald Hoyer e2c90d
+        asprintf(&realtarget, "%s/%s", realpath_p, &target_dir_p[i]);
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         /* now calculate the relative path from <from> to <target> and
Harald Hoyer e2c90d
            store it in <relative_from>
Harald Hoyer e2c90d
@@ -122,8 +126,6 @@ static char *convert_abs_rel(const char *from, const char *target)
Harald Hoyer e2c90d
                 if (realtarget[i] == '/')
Harald Hoyer e2c90d
                         level++;
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
-        free(realtarget);
Harald Hoyer e2c90d
-
Harald Hoyer e2c90d
         /* add "../" to the relative_from path, until the common pathname is
Harald Hoyer e2c90d
            reached */
Harald Hoyer e2c90d
         for (i = level; i < targetlevel; i++) {
Harald Hoyer e2c90d
@@ -155,18 +157,16 @@ static char *convert_abs_rel(const char *from, const char *target)
Harald Hoyer e2c90d
 static int ln_r(const char *src, const char *dst)
Harald Hoyer e2c90d
 {
Harald Hoyer e2c90d
         int ret;
Harald Hoyer e2c90d
-        const char *points_to = convert_abs_rel(src, dst);
Harald Hoyer e2c90d
+        _cleanup_free_ const char *points_to = convert_abs_rel(src, dst);
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
         log_info("ln -s '%s' '%s'", points_to, dst);
Harald Hoyer e2c90d
         ret = symlink(points_to, dst);
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         if (ret != 0) {
Harald Hoyer e2c90d
                 log_error("ERROR: ln -s '%s' '%s': %m", points_to, dst);
Harald Hoyer e2c90d
-                free((char *)points_to);
Harald Hoyer e2c90d
                 return 1;
Harald Hoyer e2c90d
         }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
-        free((char *)points_to);
Harald Hoyer e2c90d
-
Harald Hoyer e2c90d
         return 0;
Harald Hoyer e2c90d
 }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
@@ -186,11 +186,11 @@ static bool use_clone = true;
Harald Hoyer e2c90d
 static int cp(const char *src, const char *dst)
Harald Hoyer e2c90d
 {
Harald Hoyer e2c90d
         int pid;
Harald Hoyer e2c90d
-        int ret;
Harald Hoyer e2c90d
+        int ret = 0;
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         if (use_clone) {
Harald Hoyer e2c90d
                 struct stat sb;
Harald Hoyer e2c90d
-                int dest_desc, source_desc;
Harald Hoyer e2c90d
+                _cleanup_close_ int dest_desc = -1, source_desc = -1;
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
                 if (lstat(src, &sb) != 0)
Harald Hoyer e2c90d
                         goto normal_copy;
Harald Hoyer e2c90d
@@ -207,12 +207,11 @@ static int cp(const char *src, const char *dst)
Harald Hoyer e2c90d
                          (sb.st_mode) & (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO));
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
                 if (dest_desc < 0) {
Harald Hoyer e2c90d
-                        close(source_desc);
Harald Hoyer e2c90d
                         goto normal_copy;
Harald Hoyer e2c90d
                 }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
                 ret = clone_file(dest_desc, source_desc);
Harald Hoyer e2c90d
-                close(source_desc);
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
                 if (ret == 0) {
Harald Hoyer e2c90d
                         struct timeval tv[2];
Harald Hoyer e2c90d
                         if (fchown(dest_desc, sb.st_uid, sb.st_gid) != 0)
Harald Hoyer e2c90d
@@ -222,11 +221,10 @@ static int cp(const char *src, const char *dst)
Harald Hoyer e2c90d
                         tv[1].tv_sec = sb.st_mtime;
Harald Hoyer e2c90d
                         tv[1].tv_usec = 0;
Harald Hoyer e2c90d
                         futimes(dest_desc, tv);
Harald Hoyer e2c90d
-                        close(dest_desc);
Harald Hoyer e2c90d
                         return ret;
Harald Hoyer e2c90d
                 }
Harald Hoyer e2c90d
                 close(dest_desc);
Harald Hoyer e2c90d
-
Harald Hoyer e2c90d
+                dest_desc = -1;
Harald Hoyer e2c90d
                 /* clone did not work, remove the file */
Harald Hoyer e2c90d
                 unlink(dst);
Harald Hoyer e2c90d
                 /* do not try clone again */
Harald Hoyer e2c90d
@@ -243,10 +241,11 @@ static int cp(const char *src, const char *dst)
Harald Hoyer e2c90d
         while (waitpid(pid, &ret, 0) < 0) {
Harald Hoyer e2c90d
                 if (errno != EINTR) {
Harald Hoyer e2c90d
                         ret = -1;
Harald Hoyer e2c90d
+                        log_error("Failed: cp --reflink=auto --sparse=auto --preserve=mode,timestamps -fL %s %s", src, dst);
Harald Hoyer e2c90d
                         break;
Harald Hoyer e2c90d
                 }
Harald Hoyer e2c90d
         }
Harald Hoyer e2c90d
-
Harald Hoyer e2c90d
+        log_debug("cp ret = %d", ret);
Harald Hoyer e2c90d
         return ret;
Harald Hoyer e2c90d
 }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
@@ -256,15 +255,17 @@ static int resolve_deps(const char *src)
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         char *buf = malloc(LINE_MAX);
Harald Hoyer e2c90d
         size_t linesize = LINE_MAX;
Harald Hoyer e2c90d
-        FILE *fptr;
Harald Hoyer e2c90d
-        char *cmd;
Harald Hoyer e2c90d
+        _cleanup_pclose_ FILE *fptr = NULL;
Harald Hoyer e2c90d
+        _cleanup_free_ char *cmd = NULL;
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         if (strstr(src, ".so") == 0) {
Harald Hoyer e2c90d
-                int fd;
Harald Hoyer e2c90d
+                _cleanup_close_ int fd = -1;
Harald Hoyer e2c90d
                 fd = open(src, O_RDONLY | O_CLOEXEC);
Harald Hoyer e2c90d
+                if (fd < 0)
Harald Hoyer e2c90d
+                        return -errno;
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
                 read(fd, buf, LINE_MAX);
Harald Hoyer e2c90d
                 buf[LINE_MAX - 1] = '\0';
Harald Hoyer e2c90d
-                close(fd);
Harald Hoyer e2c90d
                 if (buf[0] == '#' && buf[1] == '!') {
Harald Hoyer e2c90d
                         /* we have a shebang */
Harald Hoyer e2c90d
                         char *p, *q;
Harald Hoyer e2c90d
@@ -280,7 +281,11 @@ static int resolve_deps(const char *src)
Harald Hoyer e2c90d
         }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         /* run ldd */
Harald Hoyer e2c90d
-        asprintf(&cmd, "ldd %s 2>&1", src);
Harald Hoyer e2c90d
+        ret = asprintf(&cmd, "ldd %s 2>&1", src);
Harald Hoyer e2c90d
+        if (ret < 0)
Harald Hoyer e2c90d
+                return ret;
Harald Hoyer e2c90d
+        ret = 0;
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
         fptr = popen(cmd, "r");
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         while (!feof(fptr)) {
Harald Hoyer e2c90d
@@ -336,7 +341,6 @@ static int resolve_deps(const char *src)
Harald Hoyer e2c90d
                         }
Harald Hoyer e2c90d
                 }
Harald Hoyer e2c90d
         }
Harald Hoyer e2c90d
-        pclose(fptr);
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         return ret;
Harald Hoyer e2c90d
 }
Harald Hoyer e2c90d
@@ -344,10 +348,14 @@ static int resolve_deps(const char *src)
Harald Hoyer e2c90d
 /* Install ".<filename>.hmac" file for FIPS self-checks */
Harald Hoyer e2c90d
 static int hmac_install(const char *src, const char *dst, const char *hmacpath)
Harald Hoyer e2c90d
 {
Harald Hoyer e2c90d
-        char *srcpath = strdup(src);
Harald Hoyer e2c90d
-        char *dstpath = strdup(dst);
Harald Hoyer e2c90d
-        char *srchmacname = NULL;
Harald Hoyer e2c90d
-        char *dsthmacname = NULL;
Harald Hoyer e2c90d
+        _cleanup_free_ char *srcpath = strdup(src);
Harald Hoyer e2c90d
+        _cleanup_free_ char *dstpath = strdup(dst);
Harald Hoyer e2c90d
+        _cleanup_free_ char *srchmacname = NULL;
Harald Hoyer e2c90d
+        _cleanup_free_ char *dsthmacname = NULL;
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+        if (!(srcpath && dstpath))
Harald Hoyer e2c90d
+                return -ENOMEM;
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
         size_t dlen = dir_len(src);
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         if (endswith(src, ".hmac"))
Harald Hoyer e2c90d
@@ -371,22 +379,18 @@ static int hmac_install(const char *src, const char *dst, const char *hmacpath)
Harald Hoyer e2c90d
         }
Harald Hoyer e2c90d
         log_debug("hmac cp '%s' '%s')", srchmacname, dsthmacname);
Harald Hoyer e2c90d
         dracut_install(srchmacname, dsthmacname, false, false, true);
Harald Hoyer e2c90d
-        free(dsthmacname);
Harald Hoyer e2c90d
-        free(srchmacname);
Harald Hoyer e2c90d
-        free(srcpath);
Harald Hoyer e2c90d
-        free(dstpath);
Harald Hoyer e2c90d
         return 0;
Harald Hoyer e2c90d
 }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
 static int dracut_install(const char *src, const char *dst, bool isdir, bool resolvedeps, bool hashdst)
Harald Hoyer e2c90d
 {
Harald Hoyer e2c90d
         struct stat sb, db;
Harald Hoyer e2c90d
-        char *dname = NULL;
Harald Hoyer e2c90d
-        char *fulldstpath = NULL;
Harald Hoyer e2c90d
-        char *fulldstdir = NULL;
Harald Hoyer e2c90d
+        _cleanup_free_ char *fulldstpath = NULL;
Harald Hoyer e2c90d
+        _cleanup_free_ char *fulldstdir = NULL;
Harald Hoyer e2c90d
         int ret;
Harald Hoyer e2c90d
         bool src_exists = true;
Harald Hoyer e2c90d
-        char *i, *existing;
Harald Hoyer e2c90d
+        char *i = NULL;
Harald Hoyer e2c90d
+        char *existing;
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         log_debug("dracut_install('%s', '%s')", src, dst);
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
@@ -419,6 +423,9 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res
Harald Hoyer e2c90d
         }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         i = strdup(dst);
Harald Hoyer e2c90d
+        if (!i)
Harald Hoyer e2c90d
+                return -ENOMEM;
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
         hashmap_put(items, i, i);
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         asprintf(&fulldstpath, "%s%s", destrootdir, dst);
Harald Hoyer e2c90d
@@ -437,7 +444,6 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res
Harald Hoyer e2c90d
                 } else
Harald Hoyer e2c90d
                         log_debug("'%s' already exists", fulldstpath);
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
-                free(fulldstpath);
Harald Hoyer e2c90d
                 /* dst does already exist */
Harald Hoyer e2c90d
                 return ret;
Harald Hoyer e2c90d
         }
Harald Hoyer e2c90d
@@ -449,6 +455,8 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res
Harald Hoyer e2c90d
         ret = stat(fulldstdir, &db);
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         if (ret < 0) {
Harald Hoyer e2c90d
+                _cleanup_free_ char *dname = NULL;
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
                 if (errno != ENOENT) {
Harald Hoyer e2c90d
                         log_error("ERROR: stat '%s': %m", fulldstdir);
Harald Hoyer e2c90d
                         return 1;
Harald Hoyer e2c90d
@@ -456,35 +464,34 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res
Harald Hoyer e2c90d
                 /* create destination directory */
Harald Hoyer e2c90d
                 log_debug("dest dir '%s' does not exist", fulldstdir);
Harald Hoyer e2c90d
                 dname = strdup(dst);
Harald Hoyer e2c90d
+                if (!dname)
Harald Hoyer e2c90d
+                        return 1;
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
                 dname[dir_len(dname)] = '\0';
Harald Hoyer e2c90d
                 ret = dracut_install(dname, dname, true, false, true);
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
-                free(dname);
Harald Hoyer e2c90d
-
Harald Hoyer e2c90d
                 if (ret != 0) {
Harald Hoyer e2c90d
                         log_error("ERROR: failed to create directory '%s'", fulldstdir);
Harald Hoyer e2c90d
-                        free(fulldstdir);
Harald Hoyer e2c90d
                         return 1;
Harald Hoyer e2c90d
                 }
Harald Hoyer e2c90d
         }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
-        free(fulldstdir);
Harald Hoyer e2c90d
-
Harald Hoyer e2c90d
         if (isdir && !src_exists) {
Harald Hoyer e2c90d
                 log_info("mkdir '%s'", fulldstpath);
Harald Hoyer e2c90d
-                return mkdir(fulldstpath, 0755);
Harald Hoyer e2c90d
+                ret = mkdir(fulldstpath, 0755);
Harald Hoyer e2c90d
+                return ret;
Harald Hoyer e2c90d
         }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         /* ready to install src */
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         if (S_ISDIR(sb.st_mode)) {
Harald Hoyer e2c90d
                 log_info("mkdir '%s'", fulldstpath);
Harald Hoyer e2c90d
-                return mkdir(fulldstpath, sb.st_mode | S_IWUSR);
Harald Hoyer e2c90d
+                ret = mkdir(fulldstpath, sb.st_mode | S_IWUSR);
Harald Hoyer e2c90d
+                return ret;
Harald Hoyer e2c90d
         }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         if (S_ISLNK(sb.st_mode)) {
Harald Hoyer e2c90d
-                char *abspath;
Harald Hoyer e2c90d
-                char *absdestpath = NULL;
Harald Hoyer e2c90d
+                _cleanup_free_ char *abspath = NULL;
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
                 abspath = realpath(src, NULL);
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
@@ -502,15 +509,13 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res
Harald Hoyer e2c90d
                 }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
                 if (lstat(fulldstpath, &sb) != 0) {
Harald Hoyer e2c90d
+                        _cleanup_free_ char *absdestpath = NULL;
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
                         asprintf(&absdestpath, "%s%s", destrootdir, abspath);
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
                         ln_r(absdestpath, fulldstpath);
Harald Hoyer e2c90d
-
Harald Hoyer e2c90d
-                        free(absdestpath);
Harald Hoyer e2c90d
                 }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
-                free(abspath);
Harald Hoyer e2c90d
                 if (arg_hmac) {
Harald Hoyer e2c90d
                         /* copy .hmac files also */
Harald Hoyer e2c90d
                         hmac_install(src, dst, NULL);
Harald Hoyer e2c90d
@@ -528,8 +533,12 @@ static int dracut_install(const char *src, const char *dst, bool isdir, bool res
Harald Hoyer e2c90d
                 }
Harald Hoyer e2c90d
         }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
+        log_debug("dracut_install ret = %d", ret);
Harald Hoyer e2c90d
         log_info("cp '%s' '%s'", src, fulldstpath);
Harald Hoyer e2c90d
         ret += cp(src, fulldstpath);
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+        log_debug("dracut_install ret = %d", ret);
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
         return ret;
Harald Hoyer e2c90d
 }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
@@ -540,49 +549,49 @@ static void item_free(char *i)
Harald Hoyer e2c90d
 }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
 static void usage(int status)
Harald Hoyer e2c90d
-{
Harald Hoyer e2c90d
-        /*                                                                     */
Harald Hoyer e2c90d
-        printf("\
Harald Hoyer e2c90d
-Usage: %s -D DESTROOTDIR [OPTION]... -a SOURCE...\n\
Harald Hoyer e2c90d
-   or: %s -D DESTROOTDIR [OPTION]... SOURCE DEST\n\
Harald Hoyer e2c90d
-\n\
Harald Hoyer e2c90d
-Install SOURCE to DEST in DESTROOTDIR with all needed dependencies.\n\
Harald Hoyer e2c90d
-\n\
Harald Hoyer e2c90d
-  -D --destrootdir    Install all files to DESTROOTDIR as the root\n\
Harald Hoyer e2c90d
-  -a --all            Install all SOURCE arguments to DESTROOTDIR\n\
Harald Hoyer e2c90d
-  -o --optional       If SOURCE does not exist, do not fail\n\
Harald Hoyer e2c90d
-  -d --dir            SOURCE is a directory\n\
Harald Hoyer e2c90d
-  -l --ldd            Also install shebang executables and libraries\n\
Harald Hoyer e2c90d
-  -R --resolvelazy    Only install shebang executables and libraries for all SOURCE files\n\
Harald Hoyer e2c90d
-  -H --fips           Also install all '.SOURCE.hmac' files\n\
Harald Hoyer e2c90d
-  -v --verbose        Show more output\n\
Harald Hoyer e2c90d
-     --debug          Show debug output\n\
Harald Hoyer e2c90d
-     --version        Show package version\n\
Harald Hoyer e2c90d
-  -h --help           Show this help\n\
Harald Hoyer e2c90d
-\n\
Harald Hoyer e2c90d
-Example:\n\
Harald Hoyer e2c90d
-# mkdir -p /var/tmp/test-root\n\
Harald Hoyer e2c90d
-# %s -D /var/tmp/test-root --ldd -a sh tr\n\
Harald Hoyer e2c90d
-# tree /var/tmp/test-root\n\
Harald Hoyer e2c90d
-/var/tmp/test-root\n\
Harald Hoyer e2c90d
-|-- lib64 -> usr/lib64\n\
Harald Hoyer e2c90d
-`-- usr\n\
Harald Hoyer e2c90d
-    |-- bin\n\
Harald Hoyer e2c90d
-    |   |-- bash\n\
Harald Hoyer e2c90d
-    |   |-- sh -> bash\n\
Harald Hoyer e2c90d
-    |   `-- tr\n\
Harald Hoyer e2c90d
-    `-- lib64\n\
Harald Hoyer e2c90d
-        |-- ld-2.15.90.so\n\
Harald Hoyer e2c90d
-        |-- ld-linux-x86-64.so.2 -> ld-2.15.90.so\n\
Harald Hoyer e2c90d
-        |-- libc-2.15.90.so\n\
Harald Hoyer e2c90d
-        |-- libc.so\n\
Harald Hoyer e2c90d
-        |-- libc.so.6 -> libc-2.15.90.so\n\
Harald Hoyer e2c90d
-        |-- libdl-2.15.90.so\n\
Harald Hoyer e2c90d
-        |-- libdl.so -> libdl-2.15.90.so\n\
Harald Hoyer e2c90d
-        |-- libdl.so.2 -> libdl-2.15.90.so\n\
Harald Hoyer e2c90d
-        |-- libtinfo.so.5 -> libtinfo.so.5.9\n\
Harald Hoyer e2c90d
-        `-- libtinfo.so.5.9\n\
Harald Hoyer e2c90d
-", program_invocation_short_name, program_invocation_short_name, program_invocation_short_name);
Harald Hoyer e2c90d
+{        
Harald Hoyer e2c90d
+             /*                                                                     */
Harald Hoyer e2c90d
+        printf("Usage: %s -D DESTROOTDIR [OPTION]... -a SOURCE...\n"
Harald Hoyer e2c90d
+               "or: %s -D DESTROOTDIR [OPTION]... SOURCE DEST\n"
Harald Hoyer e2c90d
+               "\n"
Harald Hoyer e2c90d
+               "Install SOURCE to DEST in DESTROOTDIR with all needed dependencies.\n"
Harald Hoyer e2c90d
+               "\n"
Harald Hoyer e2c90d
+               "  -D --destrootdir    Install all files to DESTROOTDIR as the root\n"
Harald Hoyer e2c90d
+               "  -a --all            Install all SOURCE arguments to DESTROOTDIR\n"
Harald Hoyer e2c90d
+               "  -o --optional       If SOURCE does not exist, do not fail\n"
Harald Hoyer e2c90d
+               "  -d --dir            SOURCE is a directory\n"
Harald Hoyer e2c90d
+               "  -l --ldd            Also install shebang executables and libraries\n"
Harald Hoyer e2c90d
+               "  -R --resolvelazy    Only install shebang executables and libraries\n"
Harald Hoyer e2c90d
+               "                      for all SOURCE files\n"
Harald Hoyer e2c90d
+               "  -H --fips           Also install all '.SOURCE.hmac' files\n"
Harald Hoyer e2c90d
+               "  -v --verbose        Show more output\n"
Harald Hoyer e2c90d
+               "     --debug          Show debug output\n"
Harald Hoyer e2c90d
+               "     --version        Show package version\n"
Harald Hoyer e2c90d
+               "  -h --help           Show this help\n"
Harald Hoyer e2c90d
+               "\n"
Harald Hoyer e2c90d
+               "Example:\n"
Harald Hoyer e2c90d
+               "# mkdir -p /var/tmp/test-root\n"
Harald Hoyer e2c90d
+               "# %s -D /var/tmp/test-root --ldd -a sh tr\n"
Harald Hoyer e2c90d
+               "# tree /var/tmp/test-root\n"
Harald Hoyer e2c90d
+               "/var/tmp/test-root\n"
Harald Hoyer e2c90d
+               "|-- lib64 -> usr/lib64\n"
Harald Hoyer e2c90d
+               "`-- usr\n"
Harald Hoyer e2c90d
+               "    |-- bin\n"
Harald Hoyer e2c90d
+               "    |   |-- bash\n"
Harald Hoyer e2c90d
+               "    |   |-- sh -> bash\n"
Harald Hoyer e2c90d
+               "    |   `-- tr\n"
Harald Hoyer e2c90d
+               "    `-- lib64\n"
Harald Hoyer e2c90d
+               "        |-- ld-2.15.90.so\n"
Harald Hoyer e2c90d
+               "        |-- ld-linux-x86-64.so.2 -> ld-2.15.90.so\n"
Harald Hoyer e2c90d
+               "        |-- libc-2.15.90.so\n"
Harald Hoyer e2c90d
+               "        |-- libc.so\n"
Harald Hoyer e2c90d
+               "        |-- libc.so.6 -> libc-2.15.90.so\n"
Harald Hoyer e2c90d
+               "        |-- libdl-2.15.90.so\n"
Harald Hoyer e2c90d
+               "        |-- libdl.so -> libdl-2.15.90.so\n"
Harald Hoyer e2c90d
+               "        |-- libdl.so.2 -> libdl-2.15.90.so\n"
Harald Hoyer e2c90d
+               "        |-- libtinfo.so.5 -> libtinfo.so.5.9\n"
Harald Hoyer e2c90d
+               "        `-- libtinfo.so.5.9\n"
Harald Hoyer e2c90d
+               , program_invocation_short_name, program_invocation_short_name, program_invocation_short_name);
Harald Hoyer e2c90d
         exit(status);
Harald Hoyer e2c90d
 }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
@@ -595,7 +604,7 @@ static int parse_argv(int argc, char *argv[])
Harald Hoyer e2c90d
                 ARG_DEBUG
Harald Hoyer e2c90d
         };
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
-        static const struct option const options[] = {
Harald Hoyer e2c90d
+        static struct option const options[] = {
Harald Hoyer e2c90d
                 {"help", no_argument, NULL, 'h'},
Harald Hoyer e2c90d
                 {"version", no_argument, NULL, ARG_VERSION},
Harald Hoyer e2c90d
                 {"dir", no_argument, NULL, 'd'},
Harald Hoyer e2c90d
@@ -691,7 +700,7 @@ static int resolve_lazy(int argc, char **argv)
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
 static char *find_binary(const char *src)
Harald Hoyer e2c90d
 {
Harald Hoyer e2c90d
-        char *path;
Harald Hoyer e2c90d
+        _cleanup_free_ char *path = NULL;
Harald Hoyer e2c90d
         char *p, *q;
Harald Hoyer e2c90d
         bool end = false;
Harald Hoyer e2c90d
         char *newsrc = NULL;
Harald Hoyer e2c90d
@@ -703,6 +712,12 @@ static char *find_binary(const char *src)
Harald Hoyer e2c90d
         }
Harald Hoyer e2c90d
         path = strdup(path);
Harald Hoyer e2c90d
         p = path;
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+        if (path == NULL) {
Harald Hoyer e2c90d
+                log_error("Out of memory!");
Harald Hoyer e2c90d
+                exit(EXIT_FAILURE);
Harald Hoyer e2c90d
+        }
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
         log_debug("PATH=%s", path);
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         do {
Harald Hoyer e2c90d
@@ -716,6 +731,11 @@ static char *find_binary(const char *src)
Harald Hoyer e2c90d
                         *q = '\0';
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
                 asprintf(&newsrc, "%s/%s", p, src);
Harald Hoyer e2c90d
+                if (newsrc == NULL) {
Harald Hoyer e2c90d
+                        log_error("Out of memory!");
Harald Hoyer e2c90d
+                        exit(EXIT_FAILURE);
Harald Hoyer e2c90d
+                }
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
                 p = q + 1;
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
                 if (stat(newsrc, &sb) != 0) {
Harald Hoyer e2c90d
@@ -729,9 +749,9 @@ static char *find_binary(const char *src)
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
         } while (!end);
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
-        free(path);
Harald Hoyer e2c90d
         if (newsrc)
Harald Hoyer e2c90d
                 log_debug("find_binary(%s) == %s", src, newsrc);
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
         return newsrc;
Harald Hoyer e2c90d
 }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
@@ -773,22 +793,20 @@ static int install_all(int argc, char **argv)
Harald Hoyer e2c90d
                 log_debug("Handle '%s'", argv[i]);
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
                 if (strchr(argv[i], '/') == NULL) {
Harald Hoyer e2c90d
-                        char *newsrc = find_binary(argv[i]);
Harald Hoyer e2c90d
+                        _cleanup_free_ char *newsrc = find_binary(argv[i]);
Harald Hoyer e2c90d
                         if (newsrc) {
Harald Hoyer e2c90d
                                 log_debug("dracut_install '%s'", newsrc);
Harald Hoyer e2c90d
                                 ret = dracut_install(newsrc, newsrc, arg_createdir, arg_resolvedeps, true);
Harald Hoyer e2c90d
                                 if (ret == 0) {
Harald Hoyer e2c90d
                                         log_debug("dracut_install '%s' OK", newsrc);
Harald Hoyer e2c90d
                                 }
Harald Hoyer e2c90d
-                                free(newsrc);
Harald Hoyer e2c90d
                         } else {
Harald Hoyer e2c90d
                                 ret = -1;
Harald Hoyer e2c90d
                         }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
                 } else {
Harald Hoyer e2c90d
-                        char *dest = strdup(argv[i]);
Harald Hoyer e2c90d
+                        _cleanup_free_ char *dest = strdup(argv[i]);
Harald Hoyer e2c90d
                         ret = dracut_install(argv[i], dest, arg_createdir, arg_resolvedeps, true);
Harald Hoyer e2c90d
-                        free(dest);
Harald Hoyer e2c90d
                 }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
                 if ((ret != 0) && (!arg_optional)) {
Harald Hoyer e2c90d
diff --git a/install/macro.h b/install/macro.h
Harald Hoyer e2c90d
index 1c0aa91..ac61b49 100644
Harald Hoyer e2c90d
--- a/install/macro.h
Harald Hoyer e2c90d
+++ b/install/macro.h
Harald Hoyer e2c90d
@@ -1,7 +1,6 @@
Harald Hoyer e2c90d
 /*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
-#ifndef foomacrohfoo
Harald Hoyer e2c90d
-#define foomacrohfoo
Harald Hoyer e2c90d
+#pragma once
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
 /***
Harald Hoyer e2c90d
   This file is part of systemd.
Harald Hoyer e2c90d
@@ -45,16 +44,38 @@
Harald Hoyer e2c90d
 #define _hidden_ __attribute__ ((visibility("hidden")))
Harald Hoyer e2c90d
 #define _weakref_(x) __attribute__((weakref(#x)))
Harald Hoyer e2c90d
 #define _introspect_(x) __attribute__((section("introspect." x)))
Harald Hoyer e2c90d
+#define _alignas_(x) __attribute__((aligned(__alignof(x))))
Harald Hoyer e2c90d
+#define _cleanup_(x) __attribute__((cleanup(x)))
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+/* automake test harness */
Harald Hoyer e2c90d
+#define EXIT_TEST_SKIP 77
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
 #define XSTRINGIFY(x) #x
Harald Hoyer e2c90d
 #define STRINGIFY(x) XSTRINGIFY(x)
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
 /* Rounds up */
Harald Hoyer e2c90d
-#define ALIGN(l) ALIGN_TO((l), sizeof(void*))
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+#define ALIGN4(l) (((l) + 3) & ~3)
Harald Hoyer e2c90d
+#define ALIGN8(l) (((l) + 7) & ~7)
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+#if __SIZEOF_POINTER__ == 8
Harald Hoyer e2c90d
+#define ALIGN(l) ALIGN8(l)
Harald Hoyer e2c90d
+#elif __SIZEOF_POINTER__ == 4
Harald Hoyer e2c90d
+#define ALIGN(l) ALIGN4(l)
Harald Hoyer e2c90d
+#else
Harald Hoyer e2c90d
+#error "Wut? Pointers are neither 4 nor 8 bytes long?"
Harald Hoyer e2c90d
+#endif
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+#define ALIGN_PTR(p) ((void*) ALIGN((unsigned long) p))
Harald Hoyer e2c90d
+#define ALIGN4_PTR(p) ((void*) ALIGN4((unsigned long) p))
Harald Hoyer e2c90d
+#define ALIGN8_PTR(p) ((void*) ALIGN8((unsigned long) p))
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
 static inline size_t ALIGN_TO(size_t l, size_t ali) {
Harald Hoyer e2c90d
         return ((l + ali - 1) & ~(ali - 1));
Harald Hoyer e2c90d
 }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
+#define ALIGN_TO_PTR(p, ali) ((void*) ALIGN_TO((unsigned long) p))
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
 #define ELEMENTSOF(x) (sizeof(x)/sizeof((x)[0]))
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
 /*
Harald Hoyer e2c90d
@@ -64,34 +85,35 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
Harald Hoyer e2c90d
  * @member: the name of the member within the struct.
Harald Hoyer e2c90d
  *
Harald Hoyer e2c90d
  */
Harald Hoyer e2c90d
-#define container_of(ptr, type, member) ({ \
Harald Hoyer e2c90d
-        const typeof( ((type *)0)->member ) *__mptr = (ptr); \
Harald Hoyer e2c90d
-        (type *)( (char *)__mptr - offsetof(type,member) );})
Harald Hoyer e2c90d
+#define container_of(ptr, type, member)                                 \
Harald Hoyer e2c90d
+        __extension__ ({                                                \
Harald Hoyer e2c90d
+                        const typeof( ((type *)0)->member ) *__mptr = (ptr); \
Harald Hoyer e2c90d
+                        (type *)( (char *)__mptr - offsetof(type,member) ); \
Harald Hoyer e2c90d
+                })
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
-#ifndef MAX
Harald Hoyer e2c90d
-#define MAX(a,b)                                \
Harald Hoyer e2c90d
-        __extension__ ({                        \
Harald Hoyer e2c90d
-                        typeof(a) _a = (a);     \
Harald Hoyer e2c90d
-                        typeof(b) _b = (b);     \
Harald Hoyer e2c90d
-                        _a > _b ? _a : _b;      \
Harald Hoyer e2c90d
+#undef MAX
Harald Hoyer e2c90d
+#define MAX(a,b)                                 \
Harald Hoyer e2c90d
+        __extension__ ({                         \
Harald Hoyer e2c90d
+                        typeof(a) _a = (a);      \
Harald Hoyer e2c90d
+                        typeof(b) _b = (b);      \
Harald Hoyer e2c90d
+                        _a > _b ? _a : _b;       \
Harald Hoyer e2c90d
                 })
Harald Hoyer e2c90d
-#endif
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
-#define MAX3(a,b,c)                             \
Harald Hoyer e2c90d
-        MAX(MAX(a,b),c)
Harald Hoyer e2c90d
+#define MAX3(x,y,z)                              \
Harald Hoyer e2c90d
+        __extension__ ({                         \
Harald Hoyer e2c90d
+                        typeof(x) _c = MAX(x,y); \
Harald Hoyer e2c90d
+                        MAX(_c, z);              \
Harald Hoyer e2c90d
+                })
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
-#ifndef MIN
Harald Hoyer e2c90d
+#undef MIN
Harald Hoyer e2c90d
 #define MIN(a,b)                                \
Harald Hoyer e2c90d
         __extension__ ({                        \
Harald Hoyer e2c90d
                         typeof(a) _a = (a);     \
Harald Hoyer e2c90d
                         typeof(b) _b = (b);     \
Harald Hoyer e2c90d
                         _a < _b ? _a : _b;      \
Harald Hoyer e2c90d
                 })
Harald Hoyer e2c90d
-#endif
Harald Hoyer e2c90d
-
Harald Hoyer e2c90d
-#define MIN3(a,b,c)                             \
Harald Hoyer e2c90d
-        MIN(MIN(a,b),c)
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
+#ifndef CLAMP
Harald Hoyer e2c90d
 #define CLAMP(x, low, high)                                             \
Harald Hoyer e2c90d
         __extension__ ({                                                \
Harald Hoyer e2c90d
                         typeof(x) _x = (x);                             \
Harald Hoyer e2c90d
@@ -99,6 +121,7 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
Harald Hoyer e2c90d
                         typeof(high) _high = (high);                    \
Harald Hoyer e2c90d
                         ((_x > _high) ? _high : ((_x < _low) ? _low : _x)); \
Harald Hoyer e2c90d
                 })
Harald Hoyer e2c90d
+#endif
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
 #define assert_se(expr)                                                 \
Harald Hoyer e2c90d
         do {                                                            \
Harald Hoyer e2c90d
@@ -119,14 +142,21 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
Harald Hoyer e2c90d
                 log_assert_failed_unreachable(t, __FILE__, __LINE__, __PRETTY_FUNCTION__); \
Harald Hoyer e2c90d
         } while (false)
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
-#define assert_cc(expr)                            \
Harald Hoyer e2c90d
-        do {                                       \
Harald Hoyer e2c90d
-                switch (0) {                       \
Harald Hoyer e2c90d
-                        case 0:                    \
Harald Hoyer e2c90d
-                        case !!(expr):             \
Harald Hoyer e2c90d
-                                ;                  \
Harald Hoyer e2c90d
-                }                                  \
Harald Hoyer e2c90d
+#if defined(static_assert)
Harald Hoyer e2c90d
+#define assert_cc(expr)                         \
Harald Hoyer e2c90d
+        do {                                    \
Harald Hoyer e2c90d
+                static_assert(expr, #expr);     \
Harald Hoyer e2c90d
+        } while (false)
Harald Hoyer e2c90d
+#else
Harald Hoyer e2c90d
+#define assert_cc(expr)                         \
Harald Hoyer e2c90d
+        do {                                    \
Harald Hoyer e2c90d
+                switch (0) {                    \
Harald Hoyer e2c90d
+                case 0:                         \
Harald Hoyer e2c90d
+                case !!(expr):                  \
Harald Hoyer e2c90d
+                        ;                       \
Harald Hoyer e2c90d
+                }                               \
Harald Hoyer e2c90d
         } while (false)
Harald Hoyer e2c90d
+#endif
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
 #define PTR_TO_UINT(p) ((unsigned int) ((uintptr_t) (p)))
Harald Hoyer e2c90d
 #define UINT_TO_PTR(u) ((void*) ((uintptr_t) (u)))
Harald Hoyer e2c90d
@@ -149,6 +179,8 @@ static inline size_t ALIGN_TO(size_t l, size_t ali) {
Harald Hoyer e2c90d
 #define memzero(x,l) (memset((x), 0, (l)))
Harald Hoyer e2c90d
 #define zero(x) (memzero(&(x), sizeof(x)))
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
+#define CHAR_TO_STR(x) ((char[2]) { x, 0 })
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
 #define char_array_0(x) x[sizeof(x)-1] = 0;
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
 #define IOVEC_SET_STRING(i, s)                  \
Harald Hoyer e2c90d
@@ -187,6 +219,66 @@ static inline size_t IOVEC_INCREMENT(struct iovec *i, unsigned n, size_t k) {
Harald Hoyer e2c90d
         return k;
Harald Hoyer e2c90d
 }
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
-#include "log.h"
Harald Hoyer e2c90d
+#define VA_FORMAT_ADVANCE(format, ap)                                   \
Harald Hoyer e2c90d
+do {                                                                    \
Harald Hoyer e2c90d
+        int _argtypes[128];                                             \
Harald Hoyer e2c90d
+        size_t _i, _k;                                                  \
Harald Hoyer e2c90d
+        _k = parse_printf_format((format), ELEMENTSOF(_argtypes), _argtypes); \
Harald Hoyer e2c90d
+        assert(_k < ELEMENTSOF(_argtypes));                             \
Harald Hoyer e2c90d
+        for (_i = 0; _i < _k; _i++) {                                   \
Harald Hoyer e2c90d
+                if (_argtypes[_i] & PA_FLAG_PTR)  {                     \
Harald Hoyer e2c90d
+                        (void) va_arg(ap, void*);                       \
Harald Hoyer e2c90d
+                        continue;                                       \
Harald Hoyer e2c90d
+                }                                                       \
Harald Hoyer e2c90d
+                                                                        \
Harald Hoyer e2c90d
+                switch (_argtypes[_i]) {                                \
Harald Hoyer e2c90d
+                case PA_INT:                                            \
Harald Hoyer e2c90d
+                case PA_INT|PA_FLAG_SHORT:                              \
Harald Hoyer e2c90d
+                case PA_CHAR:                                           \
Harald Hoyer e2c90d
+                        (void) va_arg(ap, int);                         \
Harald Hoyer e2c90d
+                        break;                                          \
Harald Hoyer e2c90d
+                case PA_INT|PA_FLAG_LONG:                               \
Harald Hoyer e2c90d
+                        (void) va_arg(ap, long int);                    \
Harald Hoyer e2c90d
+                        break;                                          \
Harald Hoyer e2c90d
+                case PA_INT|PA_FLAG_LONG_LONG:                          \
Harald Hoyer e2c90d
+                        (void) va_arg(ap, long long int);               \
Harald Hoyer e2c90d
+                        break;                                          \
Harald Hoyer e2c90d
+                case PA_WCHAR:                                          \
Harald Hoyer e2c90d
+                        (void) va_arg(ap, wchar_t);                     \
Harald Hoyer e2c90d
+                        break;                                          \
Harald Hoyer e2c90d
+                case PA_WSTRING:                                        \
Harald Hoyer e2c90d
+                case PA_STRING:                                         \
Harald Hoyer e2c90d
+                case PA_POINTER:                                        \
Harald Hoyer e2c90d
+                        (void) va_arg(ap, void*);                       \
Harald Hoyer e2c90d
+                        break;                                          \
Harald Hoyer e2c90d
+                case PA_FLOAT:                                          \
Harald Hoyer e2c90d
+                case PA_DOUBLE:                                         \
Harald Hoyer e2c90d
+                        (void) va_arg(ap, double);                      \
Harald Hoyer e2c90d
+                        break;                                          \
Harald Hoyer e2c90d
+                case PA_DOUBLE|PA_FLAG_LONG_DOUBLE:                     \
Harald Hoyer e2c90d
+                        (void) va_arg(ap, long double);                 \
Harald Hoyer e2c90d
+                        break;                                          \
Harald Hoyer e2c90d
+                default:                                                \
Harald Hoyer e2c90d
+                        assert_not_reached("Unknown format string argument."); \
Harald Hoyer e2c90d
+                }                                                       \
Harald Hoyer e2c90d
+        }                                                               \
Harald Hoyer e2c90d
+} while(false)
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+ /* Because statfs.t_type can be int on some architecures, we have to cast
Harald Hoyer e2c90d
+  * the const magic to the type, otherwise the compiler warns about
Harald Hoyer e2c90d
+  * signed/unsigned comparison, because the magic can be 32 bit unsigned.
Harald Hoyer e2c90d
+ */
Harald Hoyer e2c90d
+#define F_TYPE_CMP(a, b) (a == (typeof(a)) b)
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
-#endif
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+/* Returns the number of chars needed to format variables of the
Harald Hoyer e2c90d
+ * specified type as a decimal string. Adds in extra space for a
Harald Hoyer e2c90d
+ * negative '-' prefix. */
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+#define DECIMAL_STR_MAX(type)                                           \
Harald Hoyer e2c90d
+        (1+(sizeof(type) <= 1 ? 3 :                                     \
Harald Hoyer e2c90d
+            sizeof(type) <= 2 ? 5 :                                     \
Harald Hoyer e2c90d
+            sizeof(type) <= 4 ? 10 :                                    \
Harald Hoyer e2c90d
+            sizeof(type) <= 8 ? 20 : sizeof(int[-2*(sizeof(type) > 8)])))
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+#include "log.h"
Harald Hoyer e2c90d
diff --git a/install/util.h b/install/util.h
Harald Hoyer e2c90d
index 9085935..e86b2f2 100644
Harald Hoyer e2c90d
--- a/install/util.h
Harald Hoyer e2c90d
+++ b/install/util.h
Harald Hoyer e2c90d
@@ -507,6 +507,42 @@ void* memdup(const void *p, size_t l);
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
 int is_kernel_thread(pid_t pid);
Harald Hoyer e2c90d
 
Harald Hoyer e2c90d
+static inline void freep(void *p) {
Harald Hoyer e2c90d
+        free(*(void**) p);
Harald Hoyer e2c90d
+}
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+static inline void fclosep(FILE **f) {
Harald Hoyer e2c90d
+        if (*f)
Harald Hoyer e2c90d
+                fclose(*f);
Harald Hoyer e2c90d
+}
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+static inline void pclosep(FILE **f) {
Harald Hoyer e2c90d
+        if (*f)
Harald Hoyer e2c90d
+                pclose(*f);
Harald Hoyer e2c90d
+}
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+static inline void closep(int *fd) {
Harald Hoyer e2c90d
+        if (*fd >= 0)
Harald Hoyer e2c90d
+                close_nointr_nofail(*fd);
Harald Hoyer e2c90d
+}
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+static inline void closedirp(DIR **d) {
Harald Hoyer e2c90d
+        if (*d)
Harald Hoyer e2c90d
+                closedir(*d);
Harald Hoyer e2c90d
+}
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+static inline void umaskp(mode_t *u) {
Harald Hoyer e2c90d
+        umask(*u);
Harald Hoyer e2c90d
+}
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
+#define _cleanup_free_ _cleanup_(freep)
Harald Hoyer e2c90d
+#define _cleanup_fclose_ _cleanup_(fclosep)
Harald Hoyer e2c90d
+#define _cleanup_pclose_ _cleanup_(pclosep)
Harald Hoyer e2c90d
+#define _cleanup_close_ _cleanup_(closep)
Harald Hoyer e2c90d
+#define _cleanup_closedir_ _cleanup_(closedirp)
Harald Hoyer e2c90d
+#define _cleanup_umask_ _cleanup_(umaskp)
Harald Hoyer e2c90d
+#define _cleanup_globfree_ _cleanup_(globfree)
Harald Hoyer e2c90d
+
Harald Hoyer e2c90d
 int fd_inc_sndbuf(int fd, size_t n);
Harald Hoyer e2c90d
 int fd_inc_rcvbuf(int fd, size_t n);
Harald Hoyer e2c90d