~wb-munzinger/+junk/wdmd

« back to all changes in this revision

Viewing changes to wdmd_client.c

  • Committer: David Weber
  • Date: 2012-01-18 10:06:17 UTC
  • Revision ID: wb@munzinger.de-20120118100617-m1dyfbytxc3i451v
Import

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2011 Red Hat, Inc.
3
 
 *
4
 
 * This copyrighted material is made available to anyone wishing to use,
5
 
 * modify, copy, or redistribute it subject to the terms and conditions
6
 
 * of the GNU General Public License v2 or (at your option) any later version.
7
 
 */
8
 
 
9
 
#include <inttypes.h>
10
 
#include <unistd.h>
11
 
#include <stdio.h>
12
 
#include <stdlib.h>
13
 
#include <stdint.h>
14
 
#include <stddef.h>
15
 
#include <fcntl.h>
16
 
#include <string.h>
17
 
#include <errno.h>
18
 
#include <time.h>
19
 
 
20
 
#include "wdmd.h"
21
 
 
22
 
int main(int argc, char *argv[])
23
 
{
24
 
        char name[WDMD_NAME_SIZE];
25
 
        uint64_t t, last_keepalive;
26
 
        int test_interval, fire_timeout;
27
 
        int con, rv;
28
 
        int i = 0;
29
 
        int iter = 10;
30
 
 
31
 
        if (argc > 1)
32
 
                iter = atoi(argv[1]);
33
 
 
34
 
        memset(name, 0, sizeof(name));
35
 
        sprintf(name, "%s", "wdmd_client");
36
 
 
37
 
        con = wdmd_connect();
38
 
        printf("wdmd_connect %d\n", con);
39
 
        if (con < 0)
40
 
                return con;
41
 
 
42
 
        rv = wdmd_register(con, name);
43
 
        printf("wdmd_register %d\n", rv);
44
 
        if (rv < 0)
45
 
                return rv;
46
 
 
47
 
        rv = wdmd_status(con, &test_interval, &fire_timeout, &last_keepalive);
48
 
        printf("wdmd_status %d test_interval %d fire_timeout %d last_keepalive %llu\n",
49
 
               rv, test_interval, fire_timeout,
50
 
               (unsigned long long)last_keepalive);
51
 
        if (rv < 0)
52
 
                return rv;
53
 
 
54
 
        while (1) {
55
 
                sleep(10);
56
 
 
57
 
                t = time(NULL);
58
 
 
59
 
                rv = wdmd_test_live(con, t, t + 40);
60
 
                printf("wdmd_test_live %d %llu %llu\n", rv,
61
 
                       (unsigned long long)t,
62
 
                       (unsigned long long)(t + 40));
63
 
 
64
 
                if (i++ > iter)
65
 
                        break;
66
 
        }
67
 
 
68
 
        rv = wdmd_test_live(con, t, 0);
69
 
        printf("wdmd_test_live 0 %d\n", rv);
70
 
 
71
 
        return 0;
72
 
}
73