]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/shared/machine-pool.c
tree-wide: drop license boilerplate
[thirdparty/systemd.git] / src / shared / machine-pool.c
index fb8a6e2fd7908de0f4c4f4ab106693c1a49d472a..e4713b9f4e01df5d1903d81653a5a3d358310807 100644 (file)
@@ -3,19 +3,6 @@
   This file is part of systemd.
 
   Copyright 2015 Lennart Poettering
-
-  systemd 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.
-
-  systemd 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 systemd; If not, see <http://www.gnu.org/licenses/>.
 ***/
 
 #include <errno.h>
@@ -79,7 +66,6 @@ static int setup_machine_raw(uint64_t size, sd_bus_error *error) {
         _cleanup_close_ int fd = -1;
         struct statvfs ss;
         pid_t pid = 0;
-        siginfo_t si;
         int r;
 
         /* We want to be able to make use of btrfs-specific file
@@ -90,11 +76,8 @@ static int setup_machine_raw(uint64_t size, sd_bus_error *error) {
          * /var/lib/machines. */
 
         fd = open("/var/lib/machines.raw", O_RDWR|O_CLOEXEC|O_NONBLOCK|O_NOCTTY);
-        if (fd >= 0) {
-                r = fd;
-                fd = -1;
-                return r;
-        }
+        if (fd >= 0)
+                return TAKE_FD(fd);
 
         if (errno != ENOENT)
                 return sd_bus_error_set_errnof(error, errno, "Failed to open /var/lib/machines.raw: %m");
@@ -141,24 +124,19 @@ static int setup_machine_raw(uint64_t size, sd_bus_error *error) {
                 _exit(EXIT_FAILURE);
         }
 
-        r = wait_for_terminate(pid, &si);
-        if (r < 0) {
-                sd_bus_error_set_errnof(error, r, "Failed to wait for mkfs.btrfs: %m");
-                goto fail;
-        }
-
+        r = wait_for_terminate_and_check("mkfs", pid, 0);
         pid = 0;
 
-        if (si.si_code != CLD_EXITED) {
-                r = sd_bus_error_setf(error, SD_BUS_ERROR_FAILED, "mkfs.btrfs died abnormally.");
+        if (r < 0) {
+                sd_bus_error_set_errnof(error, r, "Failed to wait for mkfs.btrfs: %m");
                 goto fail;
         }
-        if (si.si_status == 99) {
+        if (r == 99) {
                 r = sd_bus_error_set_errnof(error, ENOENT, "Cannot set up /var/lib/machines, mkfs.btrfs is missing");
                 goto fail;
         }
-        if (si.si_status != 0) {
-                r = sd_bus_error_setf(error, SD_BUS_ERROR_FAILED, "mkfs.btrfs failed with error code %i", si.si_status);
+        if (r != EXIT_SUCCESS) {
+                r = sd_bus_error_setf(error, SD_BUS_ERROR_FAILED, "mkfs.btrfs failed with error code %i", r);
                 goto fail;
         }
 
@@ -168,10 +146,7 @@ static int setup_machine_raw(uint64_t size, sd_bus_error *error) {
                 goto fail;
         }
 
-        r = fd;
-        fd = -1;
-
-        return r;
+        return TAKE_FD(fd);
 
 fail:
         unlink_noerrno(tmp);