From: chrubis@suse.cz
To: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
Cc: vasily.isaenko@oracle.com, ltp-list@lists.sourceforge.net
Subject: Re: [LTP] [PATCH V3 3/3] safe_touch: use utimes(2) if utimensat(2) is not defined
Date: Fri, 6 Dec 2013 16:42:29 +0100 [thread overview]
Message-ID: <20131206154229.GA3426@rei> (raw)
In-Reply-To: <1386159388-23713-3-git-send-email-stanislav.kholmanskikh@oracle.com>
Hi!
> If utimensat(2) is not defined on the platform we switch
> to using utimes(2).
>
> Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
> ---
> include/safe_file_ops.h | 1 +
> lib/safe_file_ops.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-
> 2 files changed, 52 insertions(+), 2 deletions(-)
>
> diff --git a/include/safe_file_ops.h b/include/safe_file_ops.h
> index 77ad594..1815984 100644
> --- a/include/safe_file_ops.h
> +++ b/include/safe_file_ops.h
> @@ -36,6 +36,7 @@
>
> #include <sys/stat.h>
>
> +#include "lapi/utime.h"
> #include "test.h"
>
> /*
> diff --git a/lib/safe_file_ops.c b/lib/safe_file_ops.c
> index 8cfd264..f9c316d 100644
> --- a/lib/safe_file_ops.c
> +++ b/lib/safe_file_ops.c
> @@ -21,11 +21,15 @@
> * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
> */
>
> +#include "config.h"
> #include <stdarg.h>
> #include <stdio.h>
> +#include <sys/time.h>
> #include <sys/types.h>
> #include <sys/stat.h>
> #include <fcntl.h>
> +#include <unistd.h>
> +#include <utime.h>
>
> #include "safe_file_ops.h"
>
> @@ -69,6 +73,22 @@ static int count_scanf_conversions(const char *fmt)
> return cnt;
> }
>
> +static void set_time(struct timeval *res, struct timespec *src,
> + long cur_tv_sec, long cur_tv_usec)
> +{
> + switch (src->tv_nsec) {
> + case UTIME_NOW:
> + break;
> + case UTIME_OMIT:
> + res->tv_sec = cur_tv_sec;
> + res->tv_usec = cur_tv_usec;
> + break;
> + default:
> + res->tv_sec = src->tv_sec;
> + res->tv_usec = src->tv_nsec / 1000;
> + }
> +}
I've added an #ifndef HAVE_UTIMENSAT around this block, because
otherwise we will get unused function warning when HAVE_UTIMENSAT is
defined.
> void safe_file_scanf(const char *file, const int lineno,
> void (*cleanup_fn) (void),
> const char *path, const char *fmt, ...)
> @@ -186,10 +206,39 @@ void safe_touch(const char *file, const int lineno,
> pathname, file, lineno);
> }
>
> +
> +#if HAVE_UTIMENSAT
> ret = utimensat(AT_FDCWD, pathname, times, 0);
> +#else
> + if (times == NULL) {
> + ret = utimes(pathname, NULL);
> + } else {
> + struct stat sb;
> + struct timeval cotimes[2];
> +
> + ret = stat(pathname, &sb);
> + if (ret == -1)
> + tst_brkm(TBROK | TERRNO, cleanup_fn,
> + "Failed to stat file '%s' at %s:%d",
> + pathname, file, lineno);
> +
> + ret = gettimeofday(cotimes, NULL);
> + if (ret == -1)
> + tst_brkm(TBROK | TERRNO, cleanup_fn,
> + "Failed to gettimeofday() at %s:%d",
> + file, lineno);
> + cotimes[1] = cotimes[0];
> +
> + set_time(cotimes, times,
> + sb.st_atime, sb.st_atim.tv_nsec / 1000);
> + set_time(cotimes + 1, times + 1,
> + sb.st_mtime, sb.st_mtim.tv_nsec / 1000);
> +
> + ret = utimes(pathname, cotimes);
> + }
> +#endif
> if (ret == -1)
> tst_brkm(TBROK | TERRNO, cleanup_fn,
> - "Failed to do utimensat() on file '%s' at %s:%d",
> + "Failed to update the access/modification times on file '%s' at %s:%d",
And I've also fixed this line to fit into 80 chars.
Pushed, thanks.
--
Cyril Hrubis
chrubis@suse.cz
------------------------------------------------------------------------------
Sponsored by Intel(R) XDK
Develop, test and display web and hybrid apps with a single code base.
Download it for free now!
http://pubads.g.doubleclick.net/gampad/clk?id=111408631&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list
prev parent reply other threads:[~2013-12-06 15:43 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <529D7CFE.9090104@oracle.com>
2013-12-04 12:16 ` [LTP] [PATCH V3 1/3] autoconf check for utimensat(2) Stanislav Kholmanskikh
2013-12-04 12:16 ` [LTP] [PATCH V3 2/3] created lapi/utime.h Stanislav Kholmanskikh
2013-12-04 12:16 ` [LTP] [PATCH V3 3/3] safe_touch: use utimes(2) if utimensat(2) is not defined Stanislav Kholmanskikh
2013-12-06 15:42 ` chrubis [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20131206154229.GA3426@rei \
--to=chrubis@suse.cz \
--cc=ltp-list@lists.sourceforge.net \
--cc=stanislav.kholmanskikh@oracle.com \
--cc=vasily.isaenko@oracle.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox