Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

gdp / apps / gdp-delete.c @ master

History | View | Annotate | Download (3.05 KB)

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

    
3
/*
4
**  GDP-DELETE --- delete a GCL
5
**
6
**                This is only for debugging.  The gdp_gin_delete call is intended
7
**                for use by an expiration service.
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] target_log\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
        const char *lname;
64
        gdp_name_t gdpiname;
65
        const char *phase;
66
        int exitstat = EX_OK;
67

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

    
76
                 case 'G':
77
                        gdpd_addr = optarg;
78
                        break;
79

    
80
                 default:
81
                        show_usage = true;
82
                        break;
83
                }
84
        }
85
        argc -= optind;
86
        argv += optind;
87

    
88
        if (show_usage || argc != 1)
89
                usage();
90

    
91
        // initialize GDP library
92
        estat = gdp_init(gdpd_addr);
93
        if (!EP_STAT_ISOK(estat))
94
        {
95
                exitstat = EX_UNAVAILABLE;
96
                ep_app_error("GDP Initialization failed");
97
                goto fail0;
98
        }
99

    
100
        // allow thread to settle to avoid interspersed debug output
101
        ep_time_nanosleep(INT64_C(100000000));
102

    
103
        // open target GCL (must already exist)
104
        lname = argv[0];
105
        gdp_parse_name(lname, gdpiname);
106
        phase = "open";
107
        estat = gdp_gin_open(gdpiname, GDP_MODE_AO, NULL, &gin);
108
        if (!EP_STAT_ISOK(estat))
109
        {
110
                exitstat = EX_NOINPUT;
111
                goto fail1;
112
        }
113

    
114
        // delete and close log
115
        phase = "delete";
116
        estat = gdp_gin_delete(gin);
117

    
118
        if (!EP_STAT_ISOK(estat))
119
        {
120
                exitstat = EX_NOPERM;
121
fail1:
122
                ep_app_error("could not %s %s", phase, lname);
123
        }
124

    
125
fail0:
126
        ep_app_message(estat, "exiting with status");
127
        if (exitstat == EX_OK && !EP_STAT_ISOK(estat))
128
                exitstat = EX_UNAVAILABLE;
129
        return exitstat;
130
}