mirror of
https://git.proxmox.com/git/mirror_lxc
synced 2025-08-16 01:52:34 +00:00
tree-wide: replace readdir_r() with readdir()
Signed-off-by: Christian Brauner <cbrauner@suse.de>
This commit is contained in:
parent
1e7990d77c
commit
74f9697663
@ -269,7 +269,7 @@ static int do_loop_create(const char *path, uint64_t size, const char *fstype)
|
|||||||
|
|
||||||
static int find_free_loopdev_no_control(int *retfd, char *namep)
|
static int find_free_loopdev_no_control(int *retfd, char *namep)
|
||||||
{
|
{
|
||||||
struct dirent dirent, *direntp;
|
struct dirent *direntp;
|
||||||
struct loop_info64 lo;
|
struct loop_info64 lo;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
int fd = -1;
|
int fd = -1;
|
||||||
@ -279,7 +279,7 @@ static int find_free_loopdev_no_control(int *retfd, char *namep)
|
|||||||
SYSERROR("Error opening /dev");
|
SYSERROR("Error opening /dev");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
while (!readdir_r(dir, &dirent, &direntp)) {
|
while ((direntp = readdir(dir))) {
|
||||||
|
|
||||||
if (!direntp)
|
if (!direntp)
|
||||||
break;
|
break;
|
||||||
|
@ -157,7 +157,7 @@ static struct cgroup_ops cgfs_ops;
|
|||||||
|
|
||||||
static int cgroup_rmdir(char *dirname)
|
static int cgroup_rmdir(char *dirname)
|
||||||
{
|
{
|
||||||
struct dirent dirent, *direntp;
|
struct dirent *direntp;
|
||||||
int saved_errno = 0;
|
int saved_errno = 0;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
int ret, failed=0;
|
int ret, failed=0;
|
||||||
@ -169,7 +169,7 @@ static int cgroup_rmdir(char *dirname)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!readdir_r(dir, &dirent, &direntp)) {
|
while ((direntp = readdir(dir))) {
|
||||||
struct stat mystat;
|
struct stat mystat;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@ -2067,26 +2067,14 @@ out:
|
|||||||
static int cgroup_recursive_task_count(const char *cgroup_path)
|
static int cgroup_recursive_task_count(const char *cgroup_path)
|
||||||
{
|
{
|
||||||
DIR *d;
|
DIR *d;
|
||||||
struct dirent *dent_buf;
|
|
||||||
struct dirent *dent;
|
struct dirent *dent;
|
||||||
ssize_t name_max;
|
|
||||||
int n = 0, r;
|
int n = 0, r;
|
||||||
|
|
||||||
/* see man readdir_r(3) */
|
|
||||||
name_max = pathconf(cgroup_path, _PC_NAME_MAX);
|
|
||||||
if (name_max <= 0)
|
|
||||||
name_max = 255;
|
|
||||||
dent_buf = malloc(offsetof(struct dirent, d_name) + name_max + 1);
|
|
||||||
if (!dent_buf)
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
d = opendir(cgroup_path);
|
d = opendir(cgroup_path);
|
||||||
if (!d) {
|
if (!d)
|
||||||
free(dent_buf);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
|
||||||
|
|
||||||
while (readdir_r(d, dent_buf, &dent) == 0 && dent) {
|
while ((dent = readdir(d))) {
|
||||||
const char *parts[3] = {
|
const char *parts[3] = {
|
||||||
cgroup_path,
|
cgroup_path,
|
||||||
dent->d_name,
|
dent->d_name,
|
||||||
@ -2100,13 +2088,11 @@ static int cgroup_recursive_task_count(const char *cgroup_path)
|
|||||||
sub_path = lxc_string_join("/", parts, false);
|
sub_path = lxc_string_join("/", parts, false);
|
||||||
if (!sub_path) {
|
if (!sub_path) {
|
||||||
closedir(d);
|
closedir(d);
|
||||||
free(dent_buf);
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
r = stat(sub_path, &st);
|
r = stat(sub_path, &st);
|
||||||
if (r < 0) {
|
if (r < 0) {
|
||||||
closedir(d);
|
closedir(d);
|
||||||
free(dent_buf);
|
|
||||||
free(sub_path);
|
free(sub_path);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -2122,7 +2108,6 @@ static int cgroup_recursive_task_count(const char *cgroup_path)
|
|||||||
free(sub_path);
|
free(sub_path);
|
||||||
}
|
}
|
||||||
closedir(d);
|
closedir(d);
|
||||||
free(dent_buf);
|
|
||||||
|
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
@ -907,7 +907,7 @@ static char *must_make_path(const char *first, ...)
|
|||||||
|
|
||||||
static int cgroup_rmdir(char *dirname)
|
static int cgroup_rmdir(char *dirname)
|
||||||
{
|
{
|
||||||
struct dirent dirent, *direntp;
|
struct dirent *direntp;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
int r = 0;
|
int r = 0;
|
||||||
|
|
||||||
@ -915,7 +915,7 @@ static int cgroup_rmdir(char *dirname)
|
|||||||
if (!dir)
|
if (!dir)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
while (!readdir_r(dir, &dirent, &direntp)) {
|
while ((direntp = readdir(dir))) {
|
||||||
struct stat mystat;
|
struct stat mystat;
|
||||||
char *pathname;
|
char *pathname;
|
||||||
|
|
||||||
@ -1367,7 +1367,7 @@ bad:
|
|||||||
|
|
||||||
static int recursive_count_nrtasks(char *dirname)
|
static int recursive_count_nrtasks(char *dirname)
|
||||||
{
|
{
|
||||||
struct dirent dirent, *direntp;
|
struct dirent *direntp;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
int count = 0, ret;
|
int count = 0, ret;
|
||||||
char *path;
|
char *path;
|
||||||
@ -1376,7 +1376,7 @@ static int recursive_count_nrtasks(char *dirname)
|
|||||||
if (!dir)
|
if (!dir)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
while (!readdir_r(dir, &dirent, &direntp)) {
|
while ((direntp = readdir(dir))) {
|
||||||
struct stat mystat;
|
struct stat mystat;
|
||||||
|
|
||||||
if (!direntp)
|
if (!direntp)
|
||||||
|
@ -510,7 +510,7 @@ out:
|
|||||||
static int mount_rootfs_file(const char *rootfs, const char *target,
|
static int mount_rootfs_file(const char *rootfs, const char *target,
|
||||||
const char *options)
|
const char *options)
|
||||||
{
|
{
|
||||||
struct dirent dirent, *direntp;
|
struct dirent *direntp;
|
||||||
struct loop_info64 loinfo;
|
struct loop_info64 loinfo;
|
||||||
int ret = -1, fd = -1, rc;
|
int ret = -1, fd = -1, rc;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
@ -522,7 +522,7 @@ static int mount_rootfs_file(const char *rootfs, const char *target,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!readdir_r(dir, &dirent, &direntp)) {
|
while ((direntp = readdir(dir))) {
|
||||||
|
|
||||||
if (!direntp)
|
if (!direntp)
|
||||||
break;
|
break;
|
||||||
|
@ -1805,7 +1805,7 @@ int append_unexp_config_line(const char *line, struct lxc_conf *conf)
|
|||||||
|
|
||||||
static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf)
|
static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf)
|
||||||
{
|
{
|
||||||
struct dirent dirent, *direntp;
|
struct dirent *direntp;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
char path[MAXPATHLEN];
|
char path[MAXPATHLEN];
|
||||||
int ret = -1, len;
|
int ret = -1, len;
|
||||||
@ -1816,7 +1816,7 @@ static int do_includedir(const char *dirp, struct lxc_conf *lxc_conf)
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!readdir_r(dir, &dirent, &direntp)) {
|
while ((direntp = readdir(dir))) {
|
||||||
const char *fnam;
|
const char *fnam;
|
||||||
if (!direntp)
|
if (!direntp)
|
||||||
break;
|
break;
|
||||||
|
@ -623,7 +623,7 @@ WRAP_API_1(bool, wait_on_daemonized_start, int)
|
|||||||
|
|
||||||
static bool am_single_threaded(void)
|
static bool am_single_threaded(void)
|
||||||
{
|
{
|
||||||
struct dirent dirent, *direntp;
|
struct dirent *direntp;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
int count=0;
|
int count=0;
|
||||||
|
|
||||||
@ -633,7 +633,7 @@ static bool am_single_threaded(void)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!readdir_r(dir, &dirent, &direntp)) {
|
while ((direntp = readdir(dir))) {
|
||||||
if (!direntp)
|
if (!direntp)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -2284,7 +2284,7 @@ out:
|
|||||||
static bool has_snapshots(struct lxc_container *c)
|
static bool has_snapshots(struct lxc_container *c)
|
||||||
{
|
{
|
||||||
char path[MAXPATHLEN];
|
char path[MAXPATHLEN];
|
||||||
struct dirent dirent, *direntp;
|
struct dirent *direntp;
|
||||||
int count=0;
|
int count=0;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
|
|
||||||
@ -2293,7 +2293,7 @@ static bool has_snapshots(struct lxc_container *c)
|
|||||||
dir = opendir(path);
|
dir = opendir(path);
|
||||||
if (!dir)
|
if (!dir)
|
||||||
return false;
|
return false;
|
||||||
while (!readdir_r(dir, &dirent, &direntp)) {
|
while ((direntp = readdir(dir))) {
|
||||||
if (!direntp)
|
if (!direntp)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -3503,7 +3503,7 @@ static int do_lxcapi_snapshot_list(struct lxc_container *c, struct lxc_snapshot
|
|||||||
{
|
{
|
||||||
char snappath[MAXPATHLEN], path2[MAXPATHLEN];
|
char snappath[MAXPATHLEN], path2[MAXPATHLEN];
|
||||||
int count = 0, ret;
|
int count = 0, ret;
|
||||||
struct dirent dirent, *direntp;
|
struct dirent *direntp;
|
||||||
struct lxc_snapshot *snaps =NULL, *nsnaps;
|
struct lxc_snapshot *snaps =NULL, *nsnaps;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
|
|
||||||
@ -3520,7 +3520,7 @@ static int do_lxcapi_snapshot_list(struct lxc_container *c, struct lxc_snapshot
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!readdir_r(dir, &dirent, &direntp)) {
|
while ((direntp = readdir(dir))) {
|
||||||
if (!direntp)
|
if (!direntp)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -3666,7 +3666,7 @@ err:
|
|||||||
static bool remove_all_snapshots(const char *path)
|
static bool remove_all_snapshots(const char *path)
|
||||||
{
|
{
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
struct dirent dirent, *direntp;
|
struct dirent *direntp;
|
||||||
bool bret = true;
|
bool bret = true;
|
||||||
|
|
||||||
dir = opendir(path);
|
dir = opendir(path);
|
||||||
@ -3674,7 +3674,7 @@ static bool remove_all_snapshots(const char *path)
|
|||||||
SYSERROR("opendir on snapshot path %s", path);
|
SYSERROR("opendir on snapshot path %s", path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
while (!readdir_r(dir, &dirent, &direntp)) {
|
while ((direntp = readdir(dir))) {
|
||||||
if (!direntp)
|
if (!direntp)
|
||||||
break;
|
break;
|
||||||
if (!strcmp(direntp->d_name, "."))
|
if (!strcmp(direntp->d_name, "."))
|
||||||
@ -4191,7 +4191,7 @@ int list_defined_containers(const char *lxcpath, char ***names, struct lxc_conta
|
|||||||
{
|
{
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
int i, cfound = 0, nfound = 0;
|
int i, cfound = 0, nfound = 0;
|
||||||
struct dirent dirent, *direntp;
|
struct dirent *direntp;
|
||||||
struct lxc_container *c;
|
struct lxc_container *c;
|
||||||
|
|
||||||
if (!lxcpath)
|
if (!lxcpath)
|
||||||
@ -4208,7 +4208,7 @@ int list_defined_containers(const char *lxcpath, char ***names, struct lxc_conta
|
|||||||
if (names)
|
if (names)
|
||||||
*names = NULL;
|
*names = NULL;
|
||||||
|
|
||||||
while (!readdir_r(dir, &dirent, &direntp)) {
|
while ((direntp = readdir(dir))) {
|
||||||
if (!direntp)
|
if (!direntp)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ static int match_fd(int fd)
|
|||||||
*/
|
*/
|
||||||
int lxc_check_inherited(struct lxc_conf *conf, bool closeall, int fd_to_ignore)
|
int lxc_check_inherited(struct lxc_conf *conf, bool closeall, int fd_to_ignore)
|
||||||
{
|
{
|
||||||
struct dirent dirent, *direntp;
|
struct dirent *direntp;
|
||||||
int fd, fddir;
|
int fd, fddir;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
|
|
||||||
@ -225,7 +225,7 @@ restart:
|
|||||||
|
|
||||||
fddir = dirfd(dir);
|
fddir = dirfd(dir);
|
||||||
|
|
||||||
while (!readdir_r(dir, &dirent, &direntp)) {
|
while ((direntp = readdir(dir))) {
|
||||||
if (!direntp)
|
if (!direntp)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -90,7 +90,7 @@ extern bool btrfs_try_remove_subvol(const char *path);
|
|||||||
static int _recursive_rmdir(char *dirname, dev_t pdev,
|
static int _recursive_rmdir(char *dirname, dev_t pdev,
|
||||||
const char *exclude, int level, bool onedev)
|
const char *exclude, int level, bool onedev)
|
||||||
{
|
{
|
||||||
struct dirent dirent, *direntp;
|
struct dirent *direntp;
|
||||||
DIR *dir;
|
DIR *dir;
|
||||||
int ret, failed=0;
|
int ret, failed=0;
|
||||||
char pathname[MAXPATHLEN];
|
char pathname[MAXPATHLEN];
|
||||||
@ -102,7 +102,7 @@ static int _recursive_rmdir(char *dirname, dev_t pdev,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (!readdir_r(dir, &dirent, &direntp)) {
|
while ((direntp = readdir(dir))) {
|
||||||
struct stat mystat;
|
struct stat mystat;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user