Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / apps / log-exists.c @ master

History | View | Annotate | Download (2.61 KB)

1
/* vim: set ai sw=4 sts=4 ts=4 : */
2

    
3
/*
4
**  LOG-EXISTS --- check to see if a log exists.
5
**
6
**                This does absolutely nothing other than check to make sure
7
**                that a log actually exists.  It is for use in scripts.
8
**
9
**        ----- BEGIN LICENSE BLOCK -----
10
**        Applications for the Global Data Plane
11
**        From the Ubiquitous Swarm Lab, 490 Cory Hall, U.C. Berkeley.
12
**
13
**        Copyright (c) 2015-2019, Regents of the University of California.
14
**        All rights reserved.
15
**
16
**        Permission is hereby granted, without written agreement and without
17
**        license or royalty fees, to use, copy, modify, and distribute this
18
**        software and its documentation for any purpose, provided that the above
19
**        copyright notice and the following two paragraphs appear in all copies
20
**        of this software.
21
**
22
**        IN NO EVENT SHALL REGENTS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT,
23
**        SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST
24
**        PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION,
25
**        EVEN IF REGENTS HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
**
27
**        REGENTS SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, BUT NOT
28
**        LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
29
**        FOR A PARTICULAR PURPOSE. THE SOFTWARE AND ACCOMPANYING DOCUMENTATION,
30
**        IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS IS". REGENTS HAS NO
31
**        OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS,
32
**        OR MODIFICATIONS.
33
**        ----- END LICENSE BLOCK -----
34
*/
35

    
36
#include <gdp/gdp.h>
37

    
38
#include <ep/ep_app.h>
39
#include <ep/ep_dbg.h>
40

    
41
#include <sysexits.h>
42

    
43
void
44
usage(void)
45
{
46
        fprintf(stderr,
47
                        "Usage: %s [-D dbg_spec] [-G router_addr] log-name\n"
48
                        "    -D  set debugging flags\n"
49
                        "    -G  IP host to contact for gdp_router\n",
50
                        ep_app_getprogname());
51
        exit(EX_USAGE);
52
}
53

    
54

    
55
int
56
main(int argc, char **argv)
57
{
58
        int opt;
59
        bool show_usage = false;
60
        EP_STAT estat;
61
        gdp_gin_t *gin;
62
        char *gdpd_addr = NULL;
63
        gdp_name_t gdpiname;
64

    
65
        while ((opt = getopt(argc, argv, "D:G:")) > 0)
66
        {
67
                switch (opt)
68
                {
69
                 case 'D':
70
                        ep_dbg_set(optarg);
71
                        break;
72

    
73
                 case 'G':
74
                        gdpd_addr = optarg;
75
                        break;
76

    
77
                 default:
78
                        show_usage = true;
79
                        break;
80
                }
81
        }
82
        argc -= optind;
83
        argv += optind;
84

    
85
        if (show_usage || argc != 1)
86
                usage();
87

    
88
        // initialize GDP library
89
        estat = gdp_init(gdpd_addr);
90
        if (!EP_STAT_ISOK(estat))
91
        {
92
                ep_app_error("GDP Initialization failed");
93
                exit(EX_UNAVAILABLE);
94
        }
95

    
96
        // allow thread to settle to avoid interspersed debug output
97
        ep_time_nanosleep(INT64_C(100000000));
98

    
99
        // open GCL to be tested
100
        gdp_parse_name(argv[0], gdpiname);
101
        estat = gdp_gin_open(gdpiname, GDP_MODE_RO, NULL, &gin);
102
        if (EP_STAT_ISOK(estat))
103
                exit(EX_OK);
104
        else
105
                exit(EX_NOINPUT);
106
}