/* SPDX-License-Identifier: LGPL-2.1+ */
-#ifndef _GNU_SOURCE
-#define _GNU_SOURCE 1
-#endif
+#include "config.h"
+
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-#include "config.h"
#include "file_utils.h"
#include "macro.h"
#include "memory_utils.h"
-#include "raw_syscalls.h"
+#include "process_utils.h"
+#include "rexec.h"
#include "string_utils.h"
#include "syscall_wrappers.h"
-#if IS_BIONIC
-#include "../include/fexecve.h"
+#if IS_BIONIC && !HAVE_FEXECVE
+#include "fexecve.h"
#endif
#define LXC_MEMFD_REXEC_SEALS \
if (memfd < 0) {
char template[PATH_MAX];
- ret = snprintf(template, sizeof(template),
- P_tmpdir "/.%s_XXXXXX", memfd_name);
- if (ret < 0 || (size_t)ret >= sizeof(template))
+ ret = strnprintf(template, sizeof(template),
+ P_tmpdir "/.%s_XXXXXX", memfd_name);
+ if (ret < 0)
return;
tmpfd = lxc_make_tmpfile(template, true);
sent = lxc_sendfile_nointr(memfd >= 0 ? memfd : tmpfd, fd, NULL,
st.st_size - bytes_sent);
if (sent < 0) {
- /* Fallback to shoveling data between kernel- and
+ /*
+ * Fallback to shoveling data between kernel- and
* userspace.
*/
- lseek(fd, 0, SEEK_SET);
+ if (lseek(fd, 0, SEEK_SET) == (off_t) -1)
+ fprintf(stderr, "Failed to seek to beginning of file");
+
if (fd_to_fd(fd, memfd >= 0 ? memfd : tmpfd))
break;
} else {
char procfd[LXC_PROC_PID_FD_LEN];
- ret = snprintf(procfd, sizeof(procfd), "/proc/self/fd/%d", tmpfd);
- if (ret < 0 || (size_t)ret >= sizeof(procfd))
+ ret = strnprintf(procfd, sizeof(procfd), "/proc/self/fd/%d", tmpfd);
+ if (ret < 0)
return;
execfd = open(procfd, O_PATH | O_CLOEXEC);