Skip to content

Commit

Permalink
Merge pull request #2 from tedjp/master
Browse files Browse the repository at this point in the history
entwatch style, error message & variable cleanups
  • Loading branch information
mikemol committed Mar 29, 2012
2 parents 609cd5b + 253d297 commit 9737970
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
2 changes: 1 addition & 1 deletion configure.ac
@@ -1,4 +1,4 @@
AC_PREREQ([2.68])
AC_PREREQ([2.67])
AC_INIT([enttools], [1.0], [mikemol@gmail.com])
AM_INIT_AUTOMAKE([1.11 silent-rules foreign subdir-objects])
AC_CONFIG_SRCDIR([src/entwatch.c])
Expand Down
22 changes: 10 additions & 12 deletions src/entwatch.c
Expand Up @@ -15,39 +15,37 @@ int looping = 1;
int main(int argc, char* argv[])
{
int rfd = 0;
int entcnt = 0;
int r;
int waittime = 30;
char timebuf[512];
time_t now;
struct tm *tmp;

if(argc == 2) {
waittime = atoi(argv[1]);
if(waittime < 1) {
fprintf(stderr, "specified wait time cannot be less than 1\n");
return -1;
return 1;
}
}

rfd = open("/dev/random", O_RDONLY);

if(-1 == rfd) {
fprintf(stderr, "error opening /dev/random\n");
return -1;
fprintf(stderr, "error opening /dev/random: %s\n", strerror(errno));
return 1;
}

// loop here, calling ioctl(rfd, RNDGETENTCNT) and printing the result
do {
int entcnt = 0;
char timebuf[512];
time_t now;
int r;

now = time(NULL);
r = ioctl(rfd, RNDGETENTCNT, &entcnt);
if(0 > r) {
int e = errno;
fprintf(stderr, "Error with ioctl call: %s\n", strerror(e));
fprintf(stderr, "Error with ioctl call: %s\n", strerror(errno));
break;
}
tmp = localtime(&now);
strftime(timebuf, 512, "%F %T", tmp);
strftime(timebuf, sizeof(timebuf), "%F %T", localtime(&now));
printf("[%s] %d\n", timebuf, entcnt);
sleep(waittime);
} while(looping);
Expand Down

0 comments on commit 9737970

Please sign in to comment.