~ubuntu-branches/ubuntu/maverick/rrdtool/maverick

« back to all changes in this revision

Viewing changes to src/rrd_last.c

  • Committer: Bazaar Package Importer
  • Author(s): Clint Byrum
  • Date: 2010-07-22 08:07:01 UTC
  • mfrom: (1.2.8 upstream) (3.1.6 sid)
  • Revision ID: james.westby@ubuntu.com-20100722080701-k46mgdfz6euxwqsm
Tags: 1.4.3-1ubuntu1
* Merge from debian unstable, Remaining changes:
  - debian/control: Don't build against ruby1.9 as we don't want
    it in main.
* require libdbi >= 0.8.3 to prevent aborts when using dbi datasources

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*****************************************************************************
2
 
 * RRDtool 1.3.8  Copyright by Tobi Oetiker, 1997-2009
 
2
 * RRDtool 1.4.3  Copyright by Tobi Oetiker, 1997-2010
3
3
 *****************************************************************************
4
4
 * rrd_last.c
5
5
 *****************************************************************************
7
7
 *****************************************************************************/
8
8
 
9
9
#include "rrd_tool.h"
 
10
#include "rrd_client.h"
10
11
 
11
12
time_t rrd_last(
12
13
    int argc,
13
14
    char **argv)
14
15
{
15
 
    if (argc < 2) {
16
 
        rrd_set_error("please specify an rrd");
 
16
    char *opt_daemon = NULL;
 
17
    int status;
 
18
 
 
19
    optind = 0;
 
20
    opterr = 0;         /* initialize getopt */
 
21
 
 
22
    while (42) {
 
23
        int       opt;
 
24
        int       option_index = 0;
 
25
        static struct option long_options[] = {
 
26
            {"daemon", required_argument, 0, 'd'},
 
27
            {0, 0, 0, 0}
 
28
        };
 
29
 
 
30
        opt = getopt_long(argc, argv, "d:", long_options, &option_index);
 
31
 
 
32
        if (opt == EOF)
 
33
            break;
 
34
 
 
35
        switch (opt) {
 
36
        case 'd':
 
37
            if (opt_daemon != NULL)
 
38
                    free (opt_daemon);
 
39
            opt_daemon = strdup (optarg);
 
40
            if (opt_daemon == NULL)
 
41
            {
 
42
                rrd_set_error ("strdup failed.");
 
43
                return (-1);
 
44
            }
 
45
            break;
 
46
 
 
47
        default:
 
48
            rrd_set_error ("Usage: rrdtool %s [--daemon <addr>] <file>",
 
49
                    argv[0]);
 
50
            return (-1);
 
51
            break;
 
52
        }
 
53
    }                   /* while (42) */
 
54
 
 
55
    if ((argc - optind) != 1) {
 
56
        rrd_set_error ("Usage: rrdtool %s [--daemon <addr>] <file>",
 
57
                argv[0]);
17
58
        return (-1);
18
59
    }
19
60
 
20
 
    return (rrd_last_r(argv[1]));
 
61
    status = rrdc_flush_if_daemon(opt_daemon, argv[optind]);
 
62
    if (opt_daemon) free(opt_daemon);
 
63
    if (status) return (-1);
 
64
 
 
65
    return (rrd_last_r (argv[optind]));
21
66
}
22
67
 
23
 
 
24
68
time_t rrd_last_r(
25
69
    const char *filename)
26
70
{
29
73
 
30
74
    rrd_t     rrd;
31
75
 
 
76
    rrd_init(&rrd);
32
77
    rrd_file = rrd_open(filename, &rrd, RRD_READONLY);
33
78
    if (rrd_file != NULL) {
34
79
        lastup = rrd.live_head->last_up;