summaryrefslogtreecommitdiff
path: root/src/shared
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2012-09-19 22:21:09 +0200
committerLennart Poettering <lennart@poettering.net>2012-09-19 22:21:09 +0200
commit7d5e9c0f60cddf01ec803012cbdc02d2f55b78c1 (patch)
treeecb5dc336ce9e0ecf6d5e3b6757b0a10f7f1e692 /src/shared
parent57f3067825d9361d7487f272bfaff3b36c684c62 (diff)
util: define union dirent_storage and make use of it everywhere
Make sure to allocate enough space for readdir_r(). https://bugzilla.redhat.com/show_bug.cgi?id=858754
Diffstat (limited to 'src/shared')
-rw-r--r--src/shared/conf-files.c5
-rw-r--r--src/shared/hwclock.c5
-rw-r--r--src/shared/install.c15
-rw-r--r--src/shared/util.c15
-rw-r--r--src/shared/util.h7
5 files changed, 31 insertions, 16 deletions
diff --git a/src/shared/conf-files.c b/src/shared/conf-files.c
index 83e4cce156..34b86293d3 100644
--- a/src/shared/conf-files.c
+++ b/src/shared/conf-files.c
@@ -39,7 +39,6 @@
static int files_add(Hashmap *h, const char *path, const char *suffix) {
DIR *dir;
- struct dirent buffer, *de;
int r = 0;
dir = opendir(path);
@@ -50,10 +49,12 @@ static int files_add(Hashmap *h, const char *path, const char *suffix) {
}
for (;;) {
+ struct dirent *de;
+ union dirent_storage buf;
int k;
char *p;
- k = readdir_r(dir, &buffer, &de);
+ k = readdir_r(dir, &buf.de, &de);
if (k != 0) {
r = -k;
goto finish;
diff --git a/src/shared/hwclock.c b/src/shared/hwclock.c
index 67eb2eff8b..b93855d957 100644
--- a/src/shared/hwclock.c
+++ b/src/shared/hwclock.c
@@ -61,10 +61,11 @@ static int rtc_open(int flags) {
for (;;) {
char *p, *v;
- struct dirent buf, *de;
+ struct dirent *de;
+ union dirent_storage buf;
int r;
- r = readdir_r(d, &buf, &de);
+ r = readdir_r(d, &buf.de, &de);
if (r != 0)
goto fallback;
diff --git a/src/shared/install.c b/src/shared/install.c
index f30bf8317b..a99c757ea8 100644
--- a/src/shared/install.c
+++ b/src/shared/install.c
@@ -201,7 +201,6 @@ static int remove_marked_symlinks_fd(
int r = 0;
DIR *d;
- struct dirent buffer, *de;
assert(remove_symlinks_to);
assert(fd >= 0);
@@ -218,9 +217,11 @@ static int remove_marked_symlinks_fd(
rewinddir(d);
for (;;) {
+ struct dirent *de;
+ union dirent_storage buf;
int k;
- k = readdir_r(d, &buffer, &de);
+ k = readdir_r(d, &buf.de, &de);
if (k != 0) {
r = -errno;
break;
@@ -375,7 +376,6 @@ static int find_symlinks_fd(
int r = 0;
DIR *d;
- struct dirent buffer, *de;
assert(name);
assert(fd >= 0);
@@ -391,8 +391,10 @@ static int find_symlinks_fd(
for (;;) {
int k;
+ struct dirent *de;
+ union dirent_storage buf;
- k = readdir_r(d, &buffer, &de);
+ k = readdir_r(d, &buf.de, &de);
if (k != 0) {
r = -errno;
break;
@@ -1906,7 +1908,6 @@ int unit_file_get_list(
return r;
STRV_FOREACH(i, paths.unit_path) {
- struct dirent buffer, *de;
const char *units_dir;
free(buf);
@@ -1934,9 +1935,11 @@ int unit_file_get_list(
}
for (;;) {
+ struct dirent *de;
+ union dirent_storage buffer;
UnitFileList *f;
- r = readdir_r(d, &buffer, &de);
+ r = readdir_r(d, &buffer.de, &de);
if (r != 0) {
r = -r;
goto finish;
diff --git a/src/shared/util.c b/src/shared/util.c
index 69c9437db8..b48bad4c46 100644
--- a/src/shared/util.c
+++ b/src/shared/util.c
@@ -2956,9 +2956,10 @@ int dir_is_empty(const char *path) {
return -errno;
for (;;) {
- struct dirent buf, *de;
+ struct dirent *de;
+ union dirent_storage buf;
- r = readdir_r(d, &buf, &de);
+ r = readdir_r(d, &buf.de, &de);
if (r > 0)
return -r;
@@ -3260,12 +3261,13 @@ int rm_rf_children_dangerous(int fd, bool only_dirs, bool honour_sticky, struct
}
for (;;) {
- struct dirent buf, *de;
+ struct dirent *de;
+ union dirent_storage buf;
bool is_dir, keep_around;
struct stat st;
int r;
- r = readdir_r(d, &buf, &de);
+ r = readdir_r(d, &buf.de, &de);
if (r != 0 && ret == 0) {
ret = -r;
break;
@@ -4942,10 +4944,11 @@ int get_files_in_directory(const char *path, char ***list) {
return -errno;
for (;;) {
- struct dirent buffer, *de;
+ struct dirent *de;
+ union dirent_storage buf;
int k;
- k = readdir_r(d, &buffer, &de);
+ k = readdir_r(d, &buf.de, &de);
if (k != 0) {
r = -k;
goto finish;
diff --git a/src/shared/util.h b/src/shared/util.h
index 2429339f5b..e5728bd87e 100644
--- a/src/shared/util.h
+++ b/src/shared/util.h
@@ -35,6 +35,7 @@
#include <sys/stat.h>
#include <dirent.h>
#include <sys/resource.h>
+#include <stddef.h>
#include "macro.h"
@@ -46,6 +47,12 @@ typedef struct dual_timestamp {
usec_t monotonic;
} dual_timestamp;
+union dirent_storage {
+ struct dirent de;
+ uint8_t storage[offsetof(struct dirent, d_name) +
+ ((NAME_MAX + 1 + sizeof(long)) & ~(sizeof(long) - 1))];
+};
+
#define MSEC_PER_SEC 1000ULL
#define USEC_PER_SEC 1000000ULL
#define USEC_PER_MSEC 1000ULL