mirror of
https://codeberg.org/libreboot/lbmk.git
synced 2026-07-17 08:40:14 +02:00
lbutils: don't set USE_OPENAT and USE_URANDOM
these can be set explicitly in the compiler flags, e.g. make CC="cc -DUSE_OPENAT=1 -DUSE_URANDOM=1" these options, if set to 1, will cause you to use the code as if it were running on non-linux systems such as openbsd. of course, some differences will still exist, but this is useful for portability testing when compiling on linux. Signed-off-by: Leah Rowe <leah@libreboot.org>
This commit is contained in:
@@ -7,6 +7,7 @@
|
|||||||
|
|
||||||
CC = cc
|
CC = cc
|
||||||
HELLCC = clang
|
HELLCC = clang
|
||||||
|
OLDCC = $(CC) -DUSE_URANDOM=1 -DUSE_OPENAT
|
||||||
|
|
||||||
CFLAGS = -Os -Wall -Wextra -std=c99 -pedantic -Werror
|
CFLAGS = -Os -Wall -Wextra -std=c99 -pedantic -Werror
|
||||||
LDFLAGS =
|
LDFLAGS =
|
||||||
|
|||||||
@@ -34,13 +34,6 @@
|
|||||||
|
|
||||||
#define items(x) (sizeof((x)) / sizeof((x)[0]))
|
#define items(x) (sizeof((x)) / sizeof((x)[0]))
|
||||||
|
|
||||||
/* system prototypes
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef USE_URANDOM
|
|
||||||
#define USE_URANDOM 0
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define MKHTEMP_RETRY_MAX 512
|
#define MKHTEMP_RETRY_MAX 512
|
||||||
#define MKHTEMP_SPIN_THRESHOLD 32
|
#define MKHTEMP_SPIN_THRESHOLD 32
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,15 @@ long max = pathconf("/", _PC_PATH_MAX);
|
|||||||
|
|
||||||
/* for openat2: */
|
/* for openat2: */
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
#if !defined(USE_OPENAT) || \
|
||||||
|
((USE_OPENAT) < 1) /* if 1: use openat, not openat2 */
|
||||||
#ifndef _GNU_SOURCE
|
#ifndef _GNU_SOURCE
|
||||||
#define _GNU_SOURCE 1
|
#define _GNU_SOURCE 1
|
||||||
#endif
|
#endif
|
||||||
#include <linux/openat2.h>
|
#include <linux/openat2.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -612,7 +615,8 @@ open_file_on_eintr(const char *path,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifdef __linux__ /* we use openat2 on linux */
|
#if defined(__linux__) && \
|
||||||
|
((USE_OPENAT) < 1) /* we use openat2 on linux */
|
||||||
int
|
int
|
||||||
openat_on_eintr(int dirfd, const char *path,
|
openat_on_eintr(int dirfd, const char *path,
|
||||||
int flags, mode_t mode)
|
int flags, mode_t mode)
|
||||||
|
|||||||
@@ -10,6 +10,8 @@
|
|||||||
|
|
||||||
/* for openat2 / fast path: */
|
/* for openat2 / fast path: */
|
||||||
#ifdef __linux__
|
#ifdef __linux__
|
||||||
|
#if !defined(USE_OPENAT) || \
|
||||||
|
((USE_OPENAT) < 1) /* if 1: use openat, not openat2 */
|
||||||
#ifndef _GNU_SOURCE
|
#ifndef _GNU_SOURCE
|
||||||
#define _GNU_SOURCE 1
|
#define _GNU_SOURCE 1
|
||||||
#endif
|
#endif
|
||||||
@@ -22,6 +24,7 @@
|
|||||||
#define AT_EMPTY_PATH 0x1000
|
#define AT_EMPTY_PATH 0x1000
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -543,7 +546,8 @@ mkhtemp_try_create(int dirfd,
|
|||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
if (type == MKHTEMP_FILE) {
|
if (type == MKHTEMP_FILE) {
|
||||||
#ifdef __linux__
|
#if defined(__linux__) && \
|
||||||
|
(!defined(USE_OPENAT) || ((USE_OPENAT) < 1))
|
||||||
/* try O_TMPFILE fast path */
|
/* try O_TMPFILE fast path */
|
||||||
if (mkhtemp_tmpfile_linux(dirfd,
|
if (mkhtemp_tmpfile_linux(dirfd,
|
||||||
st_dir_first, fname_copy,
|
st_dir_first, fname_copy,
|
||||||
@@ -652,7 +656,8 @@ err:
|
|||||||
we still use openat() on bsd, which is
|
we still use openat() on bsd, which is
|
||||||
still ok with our other mitigations
|
still ok with our other mitigations
|
||||||
*/
|
*/
|
||||||
#ifdef __linux__
|
#if defined(__linux__) && \
|
||||||
|
(!defined(USE_OPENAT) || ((USE_OPENAT) < 1))
|
||||||
int
|
int
|
||||||
mkhtemp_tmpfile_linux(int dirfd,
|
mkhtemp_tmpfile_linux(int dirfd,
|
||||||
struct stat *st_dir_first,
|
struct stat *st_dir_first,
|
||||||
|
|||||||
@@ -154,7 +154,7 @@ retry_rand: {
|
|||||||
|
|
||||||
while (rw_retry(saved_errno,
|
while (rw_retry(saved_errno,
|
||||||
rc = read_on_eintr(fd,
|
rc = read_on_eintr(fd,
|
||||||
(unsigned char *)buf + off, n - off, 0)));
|
(unsigned char *)buf + off, n - off)));
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
long rc;
|
long rc;
|
||||||
while (sys_retry(saved_errno,
|
while (sys_retry(saved_errno,
|
||||||
@@ -183,10 +183,6 @@ retry_rand: {
|
|||||||
reset_caller_errno(0);
|
reset_caller_errno(0);
|
||||||
return;
|
return;
|
||||||
err:
|
err:
|
||||||
#if defined(USE_URANDOM) && \
|
|
||||||
((USE_URANDOM) > 0)
|
|
||||||
close_on_eintr(&fd);
|
|
||||||
#endif
|
|
||||||
(void) with_fallback_errno(ECANCELED);
|
(void) with_fallback_errno(ECANCELED);
|
||||||
exitf("Randomisierungsfehler");
|
exitf("Randomisierungsfehler");
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|||||||
Reference in New Issue
Block a user