tree-wide: use -EBADF for fd initialization
-1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
This commit is contained in:
@@ -75,7 +75,7 @@ static void fallback_random_bytes(void *p, size_t n) {
|
||||
|
||||
void random_bytes(void *p, size_t n) {
|
||||
static bool have_getrandom = true, have_grndinsecure = true;
|
||||
_cleanup_close_ int fd = -1;
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
|
||||
if (n == 0)
|
||||
return;
|
||||
@@ -117,7 +117,7 @@ void random_bytes(void *p, size_t n) {
|
||||
|
||||
int crypto_random_bytes(void *p, size_t n) {
|
||||
static bool have_getrandom = true, seen_initialized = false;
|
||||
_cleanup_close_ int fd = -1;
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
|
||||
if (n == 0)
|
||||
return 0;
|
||||
@@ -145,7 +145,7 @@ int crypto_random_bytes(void *p, size_t n) {
|
||||
}
|
||||
|
||||
if (!seen_initialized) {
|
||||
_cleanup_close_ int ready_fd = -1;
|
||||
_cleanup_close_ int ready_fd = -EBADF;
|
||||
int r;
|
||||
|
||||
ready_fd = open("/dev/random", O_RDONLY|O_CLOEXEC|O_NOCTTY);
|
||||
@@ -187,7 +187,7 @@ size_t random_pool_size(void) {
|
||||
}
|
||||
|
||||
int random_write_entropy(int fd, const void *seed, size_t size, bool credit) {
|
||||
_cleanup_close_ int opened_fd = -1;
|
||||
_cleanup_close_ int opened_fd = -EBADF;
|
||||
int r;
|
||||
|
||||
assert(seed || size == 0);
|
||||
|
||||
Reference in New Issue
Block a user