summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPekka Paalanen <pekka.paalanen@collabora.co.uk>2015-02-12 13:11:25 +0200
committerPekka Paalanen <pekka.paalanen@collabora.co.uk>2015-02-25 14:47:59 +0200
commit23a07005ed9fc2eec1e0540d882d256cd48f20ab (patch)
treef6a6ece0cd31964536e13836051e8cb705008be3
parent899b50b126e7d87f1e4f1da51d7ad725393c9103 (diff)
timeline: use file_create_dated() helper
Use shared code for this kind of stuff. Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.co.uk> Tested-by: Nobuhiko Tanibata <NOBUHIKO_TANIBATA@xddp.denso.co.jp> Reviewed-by: Daniel Stone <daniels@collabora.com>
-rw-r--r--src/timeline.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/src/timeline.c b/src/timeline.c
index bf69ba6c..c60213ea 100644
--- a/src/timeline.c
+++ b/src/timeline.c
@@ -31,6 +31,7 @@
#include "timeline.h"
#include "compositor.h"
+#include "file-util.h"
struct timeline_log {
clock_t clk_id;
@@ -45,31 +46,25 @@ static struct timeline_log timeline_ = { CLOCK_MONOTONIC, NULL, 0 };
static int
weston_timeline_do_open(void)
{
- time_t t;
- struct tm *tmp;
+ const char *prefix = "weston-timeline-";
+ const char *suffix = ".log";
char fname[1000];
- int ret;
- t = time(NULL);
- tmp = localtime(&t);
- if (!tmp) {
- weston_log("Conversion to local time failed, "
- "cannot open timeline log file.\n");
- return -1;
- }
+ timeline_.file = file_create_dated(prefix, suffix,
+ fname, sizeof(fname));
+ if (!timeline_.file) {
+ const char *msg;
- ret = strftime(fname, sizeof(fname),
- "weston-timeline-%F_%H-%M-%S.log", tmp);
- if (ret == 0) {
- weston_log("Time formatting failed, "
- "cannot open timeline log file.\n");
- return -1;
- }
+ switch (errno) {
+ case ETIME:
+ msg = "failure in datetime formatting";
+ break;
+ default:
+ msg = strerror(errno);
+ }
- timeline_.file = fopen(fname, "w");
- if (!timeline_.file) {
- weston_log("Cannot open '%s' for writing: %s\n",
- fname, strerror(errno));
+ weston_log("Cannot open '%s*%s' for writing: %s\n",
+ prefix, suffix, msg);
return -1;
}