Merge pull request #13077 from poettering/activate-n-fds

activate: move array allocation to heap
This commit is contained in:
Frantisek Sumsal 2019-07-16 18:46:30 +00:00 committed by GitHub
commit 64c3b40c25
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View file

@ -49,8 +49,7 @@ static int add_epoll(int epoll_fd, int fd) {
static int open_sockets(int *epoll_fd, bool accept) { static int open_sockets(int *epoll_fd, bool accept) {
char **address; char **address;
int n, fd, r; int n, fd, r, count = 0;
int count = 0;
n = sd_listen_fds(true); n = sd_listen_fds(true);
if (n < 0) if (n < 0)
@ -69,13 +68,18 @@ static int open_sockets(int *epoll_fd, bool accept) {
/* Close logging and all other descriptors */ /* Close logging and all other descriptors */
if (arg_listen) { if (arg_listen) {
int except[3 + n]; _cleanup_free_ int *except = NULL;
int i;
for (fd = 0; fd < SD_LISTEN_FDS_START + n; fd++) except = new(int, n);
except[fd] = fd; if (!except)
return log_oom();
for (i = 0; i < n; i++)
except[i] = SD_LISTEN_FDS_START + i;
log_close(); log_close();
r = close_all_fds(except, 3 + n); r = close_all_fds(except, n);
if (r < 0) if (r < 0)
return log_error_errno(r, "Failed to close all file descriptors: %m"); return log_error_errno(r, "Failed to close all file descriptors: %m");
} }

View file

@ -26,6 +26,7 @@
#include "sparse-endian.h" #include "sparse-endian.h"
#include "string-table.h" #include "string-table.h"
#include "string-util.h" #include "string-util.h"
#include "unaligned.h"
#include "util.h" #include "util.h"
#if HAVE_LZ4 #if HAVE_LZ4
@ -101,7 +102,7 @@ int compress_blob_lz4(const void *src, uint64_t src_size,
if (r <= 0) if (r <= 0)
return -ENOBUFS; return -ENOBUFS;
*(le64_t*) dst = htole64(src_size); unaligned_write_le64(dst, src_size);
*dst_size = r + 8; *dst_size = r + 8;
return 0; return 0;
@ -187,8 +188,8 @@ int decompress_blob_lz4(const void *src, uint64_t src_size,
if (src_size <= 8) if (src_size <= 8)
return -EBADMSG; return -EBADMSG;
size = le64toh( *(le64_t*)src ); size = unaligned_read_le64(src);
if (size < 0 || (unsigned) size != le64toh(*(le64_t*)src)) if (size < 0 || (unsigned) size != unaligned_read_le64(src))
return -EFBIG; return -EFBIG;
if ((size_t) size > *dst_alloc_size) { if ((size_t) size > *dst_alloc_size) {
out = realloc(*dst, size); out = realloc(*dst, size);