chiark
/
gitweb
/
~ianmdlvl
/
elogind.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
journald/server: replace readdir_r with readdir
[elogind.git]
/
src
/
shared
/
util.c
diff --git
a/src/shared/util.c
b/src/shared/util.c
index cdc58e394f1e77fbe9ed329dc2054ae299d03c77..481c17245ddc1978cf4f52fb80fd6261a0484f3e 100644
(file)
--- a/
src/shared/util.c
+++ b/
src/shared/util.c
@@
-86,7
+86,7
@@
static volatile unsigned cached_columns = 0;
static volatile unsigned cached_lines = 0;
size_t page_size(void) {
static volatile unsigned cached_lines = 0;
size_t page_size(void) {
- static
__thread
size_t pgsz = 0;
+ static
thread_local
size_t pgsz = 0;
long r;
if (_likely_(pgsz > 0))
long r;
if (_likely_(pgsz > 0))
@@
-2306,7
+2306,6
@@
bool is_device_path(const char *path) {
int dir_is_empty(const char *path) {
_cleanup_closedir_ DIR *d;
int dir_is_empty(const char *path) {
_cleanup_closedir_ DIR *d;
- int r;
d = opendir(path);
if (!d)
d = opendir(path);
if (!d)
@@
-2314,11
+2313,11
@@
int dir_is_empty(const char *path) {
for (;;) {
struct dirent *de;
for (;;) {
struct dirent *de;
- union dirent_storage buf;
- r = readdir_r(d, &buf.de, &de);
- if (r > 0)
- return -r;
+ errno = 0;
+ de = readdir(d);
+ if (!de && errno != 0)
+ return -errno;
if (!de)
return 1;
if (!de)
return 1;
@@
-2660,14
+2659,15
@@
int rm_rf_children_dangerous(int fd, bool only_dirs, bool honour_sticky, struct
for (;;) {
struct dirent *de;
for (;;) {
struct dirent *de;
- union dirent_storage buf;
bool is_dir, keep_around;
struct stat st;
int r;
bool is_dir, keep_around;
struct stat st;
int r;
- r = readdir_r(d, &buf.de, &de);
- if (r != 0 && ret == 0) {
- ret = -r;
+ errno = 0;
+ de = readdir(d);
+ if (!de && errno != 0) {
+ if (ret == 0)
+ ret = -errno;
break;
}
break;
}
@@
-2737,9
+2737,9
@@
int rm_rf_children_dangerous(int fd, bool only_dirs, bool honour_sticky, struct
_pure_ static int is_temporary_fs(struct statfs *s) {
assert(s);
_pure_ static int is_temporary_fs(struct statfs *s) {
assert(s);
- return
-
F_TYPE_EQUAL(s->f_type, TMPFS_MAGIC) ||
-
F_TYPE_EQUAL(s->f_type, RAMFS_MAGIC);
+
+
return
F_TYPE_EQUAL(s->f_type, TMPFS_MAGIC) ||
+ F_TYPE_EQUAL(s->f_type, RAMFS_MAGIC);
}
int rm_rf_children(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev) {
}
int rm_rf_children(int fd, bool only_dirs, bool honour_sticky, struct stat *root_dev) {
@@
-3469,7
+3469,7
@@
int wait_for_terminate_and_warn(const char *name, pid_t pid) {
return -EPROTO;
}
return -EPROTO;
}
-
_noreturn_
void freeze(void) {
+
noreturn
void freeze(void) {
/* Make sure nobody waits for us on a socket anymore */
close_all_fds(NULL, 0);
/* Make sure nobody waits for us on a socket anymore */
close_all_fds(NULL, 0);
@@
-4485,13
+4485,11
@@
int get_files_in_directory(const char *path, char ***list) {
for (;;) {
struct dirent *de;
for (;;) {
struct dirent *de;
- union dirent_storage buf;
- int k;
-
k = readdir_r(d, &buf.de, &de)
;
-
assert(k >= 0
);
- if (
k >
0)
- return -
k
;
+
errno = 0
;
+
de = readdir(d
);
+ if (
!de && errno !=
0)
+ return -
errno
;
if (!de)
break;
if (!de)
break;
@@
-4580,7
+4578,7
@@
char *strjoin(const char *x, ...) {
}
bool is_main_thread(void) {
}
bool is_main_thread(void) {
- static
__thread
int cached = 0;
+ static
thread_local
int cached = 0;
if (_unlikely_(cached == 0))
cached = getpid() == gettid() ? 1 : -1;
if (_unlikely_(cached == 0))
cached = getpid() == gettid() ? 1 : -1;
@@
-4798,7
+4796,7
@@
static const char *const __signal_table[] = {
DEFINE_PRIVATE_STRING_TABLE_LOOKUP(__signal, int);
const char *signal_to_string(int signo) {
DEFINE_PRIVATE_STRING_TABLE_LOOKUP(__signal, int);
const char *signal_to_string(int signo) {
- static
__thread
char buf[sizeof("RTMIN+")-1 + DECIMAL_STR_MAX(int) + 1];
+ static
thread_local
char buf[sizeof("RTMIN+")-1 + DECIMAL_STR_MAX(int) + 1];
const char *name;
name = __signal_to_string(signo);
const char *name;
name = __signal_to_string(signo);
@@
-5154,7
+5152,7
@@
bool is_valid_documentation_url(const char *url) {
}
bool in_initrd(void) {
}
bool in_initrd(void) {
- static
__thread
int saved = -1;
+ static int saved = -1;
struct statfs s;
if (saved >= 0)
struct statfs s;
if (saved >= 0)
@@
-5617,15
+5615,14
@@
int on_ac_power(void) {
for (;;) {
struct dirent *de;
for (;;) {
struct dirent *de;
- union dirent_storage buf;
_cleanup_close_ int fd = -1, device = -1;
char contents[6];
ssize_t n;
_cleanup_close_ int fd = -1, device = -1;
char contents[6];
ssize_t n;
- int k;
- k = readdir_r(d, &buf.de, &de);
- if (k != 0)
- return -k;
+ errno = 0;
+ de = readdir(d);
+ if (!de && errno != 0)
+ return -errno;
if (!de)
break;
if (!de)
break;
@@
-6088,3
+6085,13
@@
int namespace_enter(int pidns_fd, int mntns_fd, int root_fd) {
return 0;
}
return 0;
}
+
+bool pid_valid(pid_t pid) {
+ if (pid <= 0)
+ return false;
+
+ if (kill(pid, 0) >= 0)
+ return true;
+
+ return errno != ESRCH;
+}