home
/
code
/
khatus.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Shift X2 status from legacy to archived
[khatus.git]
/
x5
/
khatus_sensor_time.c
diff --git
a/x5/khatus_sensor_time.c
b/x5/khatus_sensor_time.c
index
84e747a
..
7e16aac
100644
(file)
--- a/
x5/khatus_sensor_time.c
+++ b/
x5/khatus_sensor_time.c
@@
-1,7
+1,6
@@
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
-#include <fcntl.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@@
-9,9
+8,8
@@
#include <time.h>
#include <unistd.h>
#include <time.h>
#include <unistd.h>
-#include "khatus_lib_log.h"
-#include "khatus_lib_sensor.h"
-#include "khatus_lib_time.h"
+#include "khlib_log.h"
+#include "khlib_time.h"
#define usage(...) {print_usage(); fprintf(stderr, "Error:\n " __VA_ARGS__); exit(EXIT_FAILURE);}
#define usage(...) {print_usage(); fprintf(stderr, "Error:\n " __VA_ARGS__); exit(EXIT_FAILURE);}
@@
-22,15
+20,13
@@
char *argv0 = NULL;
double opt_interval = 1.0;
char *opt_fmt = "%a %b %d %H:%M:%S";
double opt_interval = 1.0;
char *opt_fmt = "%a %b %d %H:%M:%S";
-char *fifo_name = NULL;
void
print_usage()
{
printf(
void
print_usage()
{
printf(
- "%s: [OPT ...]
FIFO
\n"
+ "%s: [OPT ...]\n"
"\n"
"\n"
- "FIFO = string # path to fifo file\n"
"OPT = -i int # interval\n"
" | -f string # format string\n"
" | -h # help message (i.e. what you're reading now :) )\n",
"OPT = -i int # interval\n"
" | -f string # format string\n"
" | -h # help message (i.e. what you're reading now :) )\n",
@@
-71,20
+67,6
@@
opt_parse(int argc, char **argv)
default:
assert(0);
}
default:
assert(0);
}
- fifo_name = argv[optind];
- debug("fifo_name: %s\n", fifo_name);
- if (!fifo_name)
- usage("No filename was provided\n");
-}
-
-int
-read_time(char *buf)
-{
- time_t t;
-
- t = time(NULL);
- strftime(buf, MAX_LEN, opt_fmt, localtime(&t));
- return strlen(buf);
}
int
}
int
@@
-92,15
+74,24
@@
main(int argc, char **argv)
{
argv0 = argv[0];
{
argv0 = argv[0];
+ time_t t;
struct timespec ti;
char buf[MAX_LEN];
opt_parse(argc, argv);
struct timespec ti;
char buf[MAX_LEN];
opt_parse(argc, argv);
-
- signal(SIGPIPE, SIG_IGN); /* Handled in loop */
-
+ ti = khlib_timespec_of_float(opt_interval);
+ khlib_debug("opt_fmt: \"%s\"\n", opt_fmt);
+ khlib_debug("opt_interval: %f\n", opt_interval);
+ khlib_debug("ti: {tv_sec = %ld, tv_nsec = %ld}\n",ti.tv_sec,ti.tv_nsec);
memset(buf, '\0', MAX_LEN);
memset(buf, '\0', MAX_LEN);
- ti = timespec_of_float(opt_interval);
- loop(&ti, fifo_name, buf, read_time);
+ signal(SIGPIPE, SIG_IGN);
+
+ for (;;) {
+ t = time(NULL);
+ strftime(buf, MAX_LEN, opt_fmt, localtime(&t));
+ puts(buf);
+ fflush(stdout);
+ khlib_sleep(&ti);
+ }
return EXIT_SUCCESS;
}
return EXIT_SUCCESS;
}
This page took
0.02178 seconds
and
4
git commands to generate.