Skip to content

Commit

Permalink
Merge pull request #1310 from brauner/2016-11-22/tree_wide_replace_re…
Browse files Browse the repository at this point in the history
…addir_r

tree-wide: replace readdir_r() with readdir()
  • Loading branch information
stgraber committed Nov 22, 2016
2 parents edb1098 + 78c284c commit 4e57e9d
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 36 deletions.
4 changes: 2 additions & 2 deletions src/lxc/bdev.c
Expand Up @@ -1897,7 +1897,7 @@ static int loop_detect(const char *path)

static int find_free_loopdev_no_control(int *retfd, char *namep)
{
struct dirent dirent, *direntp;
struct dirent *direntp;
struct loop_info64 lo;
DIR *dir;
int fd = -1;
Expand All @@ -1907,8 +1907,8 @@ static int find_free_loopdev_no_control(int *retfd, char *namep)
SYSERROR("Error opening /dev");
return -1;
}
while (!readdir_r(dir, &dirent, &direntp)) {

while ((direntp = readdir(dir))) {
if (!direntp)
break;
if (strncmp(direntp->d_name, "loop", 4) != 0)
Expand Down
23 changes: 4 additions & 19 deletions src/lxc/cgfs.c
Expand Up @@ -155,7 +155,7 @@ static struct cgroup_ops cgfs_ops;

static int cgroup_rmdir(char *dirname)
{
struct dirent dirent, *direntp;
struct dirent *direntp;
int saved_errno = 0;
DIR *dir;
int ret, failed=0;
Expand All @@ -167,7 +167,7 @@ static int cgroup_rmdir(char *dirname)
return -1;
}

while (!readdir_r(dir, &dirent, &direntp)) {
while ((direntp = readdir(dir))) {
struct stat mystat;
int rc;

Expand Down Expand Up @@ -2068,26 +2068,14 @@ static bool cgroup_devices_has_allow_or_deny(struct cgfs_data *d,
static int cgroup_recursive_task_count(const char *cgroup_path)
{
DIR *d;
struct dirent *dent_buf;
struct dirent *dent;
ssize_t name_max;
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);
if (!d) {
free(dent_buf);
if (!d)
return 0;
}

while (readdir_r(d, dent_buf, &dent) == 0 && dent) {
while ((dent = readdir(d))) {
const char *parts[3] = {
cgroup_path,
dent->d_name,
Expand All @@ -2101,13 +2089,11 @@ static int cgroup_recursive_task_count(const char *cgroup_path)
sub_path = lxc_string_join("/", parts, false);
if (!sub_path) {
closedir(d);
free(dent_buf);
return -1;
}
r = stat(sub_path, &st);
if (r < 0) {
closedir(d);
free(dent_buf);
free(sub_path);
return -1;
}
Expand All @@ -2123,7 +2109,6 @@ static int cgroup_recursive_task_count(const char *cgroup_path)
free(sub_path);
}
closedir(d);
free(dent_buf);

return n;
}
Expand Down
7 changes: 3 additions & 4 deletions src/lxc/conf.c
Expand Up @@ -590,7 +590,7 @@ static int setup_lodev(const char *rootfs, int fd, struct loop_info64 *loinfo)
static int mount_rootfs_file(const char *rootfs, const char *target,
const char *options)
{
struct dirent dirent, *direntp;
struct dirent *direntp;
struct loop_info64 loinfo;
int ret = -1, fd = -1, rc;
DIR *dir;
Expand All @@ -602,8 +602,7 @@ static int mount_rootfs_file(const char *rootfs, const char *target,
return -1;
}

while (!readdir_r(dir, &dirent, &direntp)) {

while ((direntp = readdir(dir))) {
if (!direntp)
break;

Expand Down Expand Up @@ -2938,7 +2937,7 @@ void lxc_restore_phys_nics_to_netns(int netnsfd, struct lxc_conf *conf)
{
int i, ret, oldfd;
char path[MAXPATHLEN];
char ifname[IFNAMSIZ];
char ifname[IFNAMSIZ];

if (netnsfd < 0 || conf->num_savednics == 0)
return;
Expand Down
2 changes: 1 addition & 1 deletion src/lxc/confile.c
Expand Up @@ -1007,7 +1007,7 @@ static int config_hook(const char *key, const char *value,
struct lxc_conf *lxc_conf)
{
char *copy;

if (!value || strlen(value) == 0)
return lxc_clear_hooks(lxc_conf, key);

Expand Down
12 changes: 6 additions & 6 deletions src/lxc/lxccontainer.c
Expand Up @@ -509,7 +509,7 @@ static bool wait_on_daemonized_start(struct lxc_container *c, int pid)

static bool am_single_threaded(void)
{
struct dirent dirent, *direntp;
struct dirent *direntp;
DIR *dir;
int count=0;

Expand All @@ -519,7 +519,7 @@ static bool am_single_threaded(void)
return false;
}

while (!readdir_r(dir, &dirent, &direntp)) {
while ((direntp = readdir(dir))) {
if (!direntp)
break;

Expand Down Expand Up @@ -2988,7 +2988,7 @@ static int lxcapi_snapshot_list(struct lxc_container *c, struct lxc_snapshot **r
{
char snappath[MAXPATHLEN], path2[MAXPATHLEN];
int dirlen, count = 0, ret;
struct dirent dirent, *direntp;
struct dirent *direntp;
struct lxc_snapshot *snaps =NULL, *nsnaps;
DIR *dir;

Expand All @@ -3007,7 +3007,7 @@ static int lxcapi_snapshot_list(struct lxc_container *c, struct lxc_snapshot **r
return 0;
}

while (!readdir_r(dir, &dirent, &direntp)) {
while ((direntp = readdir(dir))) {
if (!direntp)
break;

Expand Down Expand Up @@ -3439,7 +3439,7 @@ int list_defined_containers(const char *lxcpath, char ***names, struct lxc_conta
{
DIR *dir;
int i, cfound = 0, nfound = 0;
struct dirent dirent, *direntp;
struct dirent *direntp;
struct lxc_container *c;

if (!lxcpath)
Expand All @@ -3456,7 +3456,7 @@ int list_defined_containers(const char *lxcpath, char ***names, struct lxc_conta
if (names)
*names = NULL;

while (!readdir_r(dir, &dirent, &direntp)) {
while ((direntp = readdir(dir))) {
if (!direntp)
break;

Expand Down
4 changes: 2 additions & 2 deletions src/lxc/start.c
Expand Up @@ -188,7 +188,7 @@ static int match_fd(int fd)

int lxc_check_inherited(struct lxc_conf *conf, int fd_to_ignore)
{
struct dirent dirent, *direntp;
struct dirent *direntp;
int fd, fddir;
DIR *dir;

Expand All @@ -201,7 +201,7 @@ int lxc_check_inherited(struct lxc_conf *conf, int fd_to_ignore)

fddir = dirfd(dir);

while (!readdir_r(dir, &dirent, &direntp)) {
while ((direntp = readdir(dir))) {
if (!direntp)
break;

Expand Down
4 changes: 2 additions & 2 deletions src/lxc/utils.c
Expand Up @@ -62,7 +62,7 @@ extern bool btrfs_try_remove_subvol(const char *path);

static int _recursive_rmdir(char *dirname, dev_t pdev, bool onedev)
{
struct dirent dirent, *direntp;
struct dirent *direntp;
DIR *dir;
int ret, failed=0;
char pathname[MAXPATHLEN];
Expand All @@ -73,7 +73,7 @@ static int _recursive_rmdir(char *dirname, dev_t pdev, bool onedev)
return -1;
}

while (!readdir_r(dir, &dirent, &direntp)) {
while ((direntp = readdir(dir))) {
struct stat mystat;
int rc;

Expand Down

0 comments on commit 4e57e9d

Please sign in to comment.