home
/
code
/
khatus.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Move config defaults from global into main
[khatus.git]
/
x5
/
khatus_sensor_time.c
diff --git
a/x5/khatus_sensor_time.c
b/x5/khatus_sensor_time.c
index
ad170ef
..
01483b9
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>
@@
-21,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",
@@
-70,10
+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
}
int
@@
-85,44
+78,19
@@
main(int argc, char **argv)
struct timespec ti;
char buf[MAX_LEN];
struct timespec ti;
char buf[MAX_LEN];
- int fd = -1;
-
- int n = 0; /* written */
- int r = 0; /* remaining */
- int i = 0; /* buffer position */
-
opt_parse(argc, argv);
opt_parse(argc, argv);
-
- signal(SIGPIPE, SIG_IGN); /* Handling manually */
-
- memset(buf, '\0', MAX_LEN);
ti = timespec_of_float(opt_interval);
ti = timespec_of_float(opt_interval);
+ debug("opt_fmt: \"%s\"\n", opt_fmt);
+ debug("opt_interval: %f\n", opt_interval);
+ debug("ti: {tv_sec = %ld, tv_nsec = %ld}\n", ti.tv_sec, ti.tv_nsec);
+ memset(buf, '\0', MAX_LEN);
+ signal(SIGPIPE, SIG_IGN);
+
for (;;) {
for (;;) {
- debug("openning \"%s\"\n", fifo_name);
- fd = open(fifo_name, O_WRONLY);
- if (fd < 0)
- fatal("Failed to open FIFO file: \"%s\". Error: %s\n",
- fifo_name,
- strerror(errno));
- debug("openned. fd: %d\n", fd);
t = time(NULL);
strftime(buf, MAX_LEN, opt_fmt, localtime(&t));
t = time(NULL);
strftime(buf, MAX_LEN, opt_fmt, localtime(&t));
- r = strlen(buf);
- buf[r] = END_OF_MESSAGE;
- for (i = 0; (n = write(fd, buf + i++, 1)) && r; r--)
- ;
- if (n < 0)
- fatal("Failed to write to %s. Err num: %d, Err msg: %s\n",
- fifo_name,
- errno,
- strerror(errno));
- if (close(fd) < 0)
- fatal("Failed to close %s. Err num: %d, Err msg: %s\n",
- fifo_name,
- errno,
- strerror(errno));
- fd = -1;
- debug("closed. fd: %d\n", fd);
+ puts(buf);
+ fflush(stdout);
snooze(&ti);
}
return EXIT_SUCCESS;
snooze(&ti);
}
return EXIT_SUCCESS;
This page took
0.03539 seconds
and
4
git commands to generate.