]> git.ipfire.org Git - people/stevee/pakfire.git/commitdiff
jail: Fix signal handling
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 2 Aug 2022 16:37:41 +0000 (16:37 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 2 Aug 2022 16:37:41 +0000 (16:37 +0000)
We need to stricly send uint64_t.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/libpakfire/jail.c

index c72d1a6fb528806af6f3decc7792a5a9af022b7d..2f41728fe5e34fc008996e90107dc4b6fc9b0a74 100644 (file)
@@ -508,25 +508,40 @@ ERROR:
 }
 
 static int pakfire_jail_send_signal(struct pakfire_jail* jail, int fd) {
-       const int val = 1;
+       const uint64_t val = 1;
+       int r = 0;
 
        DEBUG(jail->pakfire, "Sending signal...\n");
 
-       write(fd, &val, sizeof(val));
+       // Write to the file descriptor
+       ssize_t bytes_written = write(fd, &val, sizeof(val));
+       if (bytes_written < 0 || (size_t)bytes_written < sizeof(val)) {
+               ERROR(jail->pakfire, "Could not send signal: %m\n");
+               r = 1;
+       }
+
+       // Close the file descriptor
        close(fd);
 
-       return 0;
+       return r;
 }
 
 static int pakfire_jail_wait_for_signal(struct pakfire_jail* jail, int fd) {
-       int val = 0;
+       uint64_t val = 0;
+       int r = 0;
 
        DEBUG(jail->pakfire, "Waiting for signal...\n");
 
-       read(fd, &val, sizeof(val));
+       ssize_t bytes_read = read(fd, &val, sizeof(val));
+       if (bytes_read < 0 || (size_t)bytes_read < sizeof(val)) {
+               ERROR(jail->pakfire, "Error waiting for signal: %m\n");
+               r = 1;
+       }
+
+       // Close the file descriptor
        close(fd);
 
-       return 0;
+       return r;
 }
 
 /*