* [LTP] [PATCH v2] lib/rmobj: avoid using lstat
@ 2014-08-25 7:18 Jan Stancek
2014-08-25 12:55 ` chrubis
0 siblings, 1 reply; 2+ messages in thread
From: Jan Stancek @ 2014-08-25 7:18 UTC (permalink / raw)
To: ltp-list
rmobj() is failing for _64 version of testcases, which use large
files, where it hits EOVERFLOW in lstat():
open12 0 TWARN : tst_tmpdir.c:206: tst_rmdir: rmobj(/tmp/opexIqjV3) failed:
lstat(/tmp/opexIqjV3/large_file) failed; errno=75:
Value too large for defined data type
Avoid using any *stat functions, instead try to open "obj"
with open(O_DIRECTORY | O_NOFOLLOW,..). If it succeeds,
we know we are dealing with directory, otherwise assume
it's a file or symlink.
Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
lib/rmobj.c | 16 ++++++----------
1 files changed, 6 insertions(+), 10 deletions(-)
diff --git a/lib/rmobj.c b/lib/rmobj.c
index 9b6a643..a9de59c 100644
--- a/lib/rmobj.c
+++ b/lib/rmobj.c
@@ -77,6 +77,7 @@
* NULL) and return -1. Otherwise it will return 0.
*
************************************************************/
+#define _GNU_SOURCE
#include <errno.h> /* for errno */
#include <stdio.h> /* for NULL */
#include <stdlib.h> /* for malloc() */
@@ -84,6 +85,7 @@
#include <limits.h> /* for PATH_MAX */
#include <sys/types.h> /* for opendir(), readdir(), closedir(), stat() */
#include <sys/stat.h> /* for [l]stat() */
+#include <fcntl.h>
#include <dirent.h> /* for opendir(), readdir(), closedir() */
#include <unistd.h> /* for rmdir(), unlink() */
#include "rmobj.h"
@@ -98,19 +100,13 @@ int rmobj(char *obj, char **errmsg)
char dirobj[PATH_MAX]; /* object inside directory to modify */
struct stat statbuf; /* used to hold stat information */
static char err_msg[1024]; /* error message */
+ int fd;
/* Determine the file type */
- if (lstat(obj, &statbuf) < 0) {
- if (errmsg != NULL) {
- sprintf(err_msg, "lstat(%s) failed; errno=%d: %s",
- obj, errno, SYSERR);
- *errmsg = err_msg;
- }
- return -1;
- }
- /* Take appropriate action, depending on the file type */
- if ((statbuf.st_mode & S_IFMT) == S_IFDIR) {
+ fd = open(obj, O_DIRECTORY | O_NOFOLLOW);
+ if (fd != -1) {
+ close(fd);
/* object is a directory */
/* Do NOT perform the request if the directory is "/" */
--
1.7.1
------------------------------------------------------------------------------
Slashdot TV.
Video for Nerds. Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [LTP] [PATCH v2] lib/rmobj: avoid using lstat
2014-08-25 7:18 [LTP] [PATCH v2] lib/rmobj: avoid using lstat Jan Stancek
@ 2014-08-25 12:55 ` chrubis
0 siblings, 0 replies; 2+ messages in thread
From: chrubis @ 2014-08-25 12:55 UTC (permalink / raw)
To: Jan Stancek; +Cc: ltp-list
Hi!
> rmobj() is failing for _64 version of testcases, which use large
> files, where it hits EOVERFLOW in lstat():
>
> open12 0 TWARN : tst_tmpdir.c:206: tst_rmdir: rmobj(/tmp/opexIqjV3) failed:
> lstat(/tmp/opexIqjV3/large_file) failed; errno=75:
> Value too large for defined data type
>
> Avoid using any *stat functions, instead try to open "obj"
> with open(O_DIRECTORY | O_NOFOLLOW,..). If it succeeds,
> we know we are dealing with directory, otherwise assume
> it's a file or symlink.
>
> Signed-off-by: Jan Stancek <jstancek@redhat.com>
This builds fine back to the SLES9 and works also fine. Acked.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
Slashdot TV.
Video for Nerds. Stuff that matters.
http://tv.slashdot.org/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2014-08-25 12:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-25 7:18 [LTP] [PATCH v2] lib/rmobj: avoid using lstat Jan Stancek
2014-08-25 12:55 ` chrubis
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.