diff options
author | Harsh Prateek Bora <harsh@linux.vnet.ibm.com> | 2011-05-18 17:23:00 +0530 |
---|---|---|
committer | Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com> | 2011-08-22 09:44:52 +0530 |
commit | 5f524c1ebcc5e0dec0de8940d34f9adb3c7887a1 (patch) | |
tree | 05be96a33cb9e8cde3b4c39ab69217adfa627ba2 /hw/9pfs/virtio-9p.c | |
parent | d208a0e00598d19abab7cb6dc97cf21d7bf0eede (diff) |
use readdir_r instead of readdir for reentrancy
Signed-off-by: Harsh Prateek Bora <harsh@linux.vnet.ibm.com>
Signed-off-by: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Diffstat (limited to 'hw/9pfs/virtio-9p.c')
-rw-r--r-- | hw/9pfs/virtio-9p.c | 22 |
1 files changed, 16 insertions, 6 deletions
diff --git a/hw/9pfs/virtio-9p.c b/hw/9pfs/virtio-9p.c index 4abf2f9ef8..ad70768dce 100644 --- a/hw/9pfs/virtio-9p.c +++ b/hw/9pfs/virtio-9p.c @@ -1495,17 +1495,20 @@ static int v9fs_do_readdir_with_stat(V9fsState *s, V9fsPDU *pdu, int32_t count = 0; struct stat stbuf; off_t saved_dir_pos; - struct dirent *dent; + struct dirent *dent, *result; /* save the directory position */ saved_dir_pos = v9fs_co_telldir(s, fidp); if (saved_dir_pos < 0) { return saved_dir_pos; } + + dent = g_malloc(sizeof(struct dirent)); + while (1) { v9fs_string_init(&name); - err = v9fs_co_readdir(s, fidp, &dent); - if (err || !dent) { + err = v9fs_co_readdir_r(s, fidp, dent, &result); + if (err || !result) { break; } v9fs_string_sprintf(&name, "%s/%s", fidp->path.data, dent->d_name); @@ -1524,6 +1527,7 @@ static int v9fs_do_readdir_with_stat(V9fsState *s, V9fsPDU *pdu, v9fs_co_seekdir(s, fidp, saved_dir_pos); v9fs_stat_free(&v9stat); v9fs_string_free(&name); + g_free(dent); return count; } count += len; @@ -1532,6 +1536,7 @@ static int v9fs_do_readdir_with_stat(V9fsState *s, V9fsPDU *pdu, saved_dir_pos = dent->d_off; } out: + g_free(dent); v9fs_string_free(&name); if (err < 0) { return err; @@ -1628,16 +1633,19 @@ static int v9fs_do_readdir(V9fsState *s, V9fsPDU *pdu, int len, err = 0; int32_t count = 0; off_t saved_dir_pos; - struct dirent *dent; + struct dirent *dent, *result; /* save the directory position */ saved_dir_pos = v9fs_co_telldir(s, fidp); if (saved_dir_pos < 0) { return saved_dir_pos; } + + dent = g_malloc(sizeof(struct dirent)); + while (1) { - err = v9fs_co_readdir(s, fidp, &dent); - if (err || !dent) { + err = v9fs_co_readdir_r(s, fidp, dent, &result); + if (err || !result) { break; } v9fs_string_init(&name); @@ -1646,6 +1654,7 @@ static int v9fs_do_readdir(V9fsState *s, V9fsPDU *pdu, /* Ran out of buffer. Set dir back to old position and return */ v9fs_co_seekdir(s, fidp, saved_dir_pos); v9fs_string_free(&name); + g_free(dent); return count; } /* @@ -1667,6 +1676,7 @@ static int v9fs_do_readdir(V9fsState *s, V9fsPDU *pdu, v9fs_string_free(&name); saved_dir_pos = dent->d_off; } + g_free(dent); if (err < 0) { return err; } |