~ken-vandine/ubuntu/natty/nfs-utils/1.2.2-4ubuntu1

« back to all changes in this revision

Viewing changes to tests/statdb_dump.c

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar, Anibal Monsalve Salazar, Ben Hutchings
  • Date: 2010-04-06 16:11:22 UTC
  • mfrom: (1.2.18 upstream)
  • Revision ID: james.westby@ubuntu.com-20100406161122-x7erw0q8xiitoyp6
Tags: 1:1.2.2-1
[ Anibal Monsalve Salazar ]
* New upstream release 
  Build depend on libcap-dev
  Set configure option --enable-nfsv41
* X-ref nfsd({7,8})
  02-524255-manpages.patch by Cyril Brulebois
  Closes: 524255

[ Ben Hutchings ]
* Change maintainer to Debian kernel team; move Aníbal to uploaders and
  add myself to uploaders
* Check for nfsd in /proc/filesystems rather than looking for signs of it in
  /proc/kallsyms (Closes: #563104, #572736)
* Document the -n option to svcgssd, thanks to Alberto Gonzalez Iniesta
  (Closes: #451402, #550270)
* Replace upstream reference in package descriptions with Homepage fields,
  and do not refer to the obsolete CVS repository
* Update policy version to 3.8.4; no changes required
* Override lintian error 'init.d-script-missing-dependency-on-remote_fs';
  the init script does work without /usr mounted

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * statdb_dump.c -- dump contents of statd's monitor DB
 
3
 *
 
4
 * Copyright (C) 2010  Red Hat, Jeff Layton <jlayton@redhat.com>
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or
 
7
 * modify it under the terms of the GNU General Public License
 
8
 * as published by the Free Software Foundation; either version 2
 
9
 * of the License, or (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
19
 * Boston, MA 02110-1301, USA.
 
20
 */
 
21
 
 
22
#ifdef HAVE_CONFIG_H
 
23
#include "config.h"
 
24
#endif
 
25
 
 
26
#include <stdio.h>
 
27
#include <errno.h>
 
28
#include <arpa/inet.h>
 
29
 
 
30
#include "nsm.h"
 
31
#include "xlog.h"
 
32
 
 
33
static char cookiebuf[(SM_PRIV_SIZE * 2) + 1];
 
34
static char addrbuf[INET6_ADDRSTRLEN + 1];
 
35
 
 
36
static unsigned int
 
37
dump_host(const char *hostname, const struct sockaddr *sa, const struct mon *m,
 
38
          const time_t timestamp)
 
39
{
 
40
        int ret;
 
41
        const char *addr;
 
42
        const struct sockaddr_in *sin;
 
43
        const struct sockaddr_in6 *sin6;
 
44
 
 
45
        ret = nsm_priv_to_hex(m->priv, cookiebuf, sizeof(cookiebuf));
 
46
        if (!ret) {
 
47
                xlog(L_ERROR, "Unable to convert cookie to hex string.\n");
 
48
                return ret;
 
49
        }
 
50
 
 
51
        switch (sa->sa_family) {
 
52
        case AF_INET:
 
53
                sin = (struct sockaddr_in *)(char *)sa;
 
54
                addr = inet_ntop(sa->sa_family, &sin->sin_addr.s_addr, addrbuf,
 
55
                                 (socklen_t)sizeof(addrbuf));
 
56
                break;
 
57
        case AF_INET6:
 
58
                sin6 = (struct sockaddr_in6 *)(char *)sa;
 
59
                addr = inet_ntop(sa->sa_family, &sin6->sin6_addr, addrbuf,
 
60
                                 (socklen_t)sizeof(addrbuf));
 
61
                break;
 
62
        default:
 
63
                xlog(L_ERROR, "Unrecognized address family: %hu\n",
 
64
                        sa->sa_family);
 
65
                return 0;
 
66
        }
 
67
 
 
68
        if (addr == NULL) {
 
69
                xlog(L_ERROR, "Unable to convert sockaddr to string: %s\n",
 
70
                                strerror(errno));
 
71
                return 0;
 
72
        }
 
73
 
 
74
        /*
 
75
         * Callers of this program should assume that in the future, extra
 
76
         * fields may be added to the output. Anyone adding extra fields to
 
77
         * the output should add them to the end of the line.
 
78
         */
 
79
        printf("%s %s %s %s %s %d %d %d\n",
 
80
                        hostname, addr, cookiebuf,
 
81
                        m->mon_id.mon_name,
 
82
                        m->mon_id.my_id.my_name,
 
83
                        m->mon_id.my_id.my_prog,
 
84
                        m->mon_id.my_id.my_vers,
 
85
                        m->mon_id.my_id.my_proc); 
 
86
 
 
87
        return 1;
 
88
}
 
89
 
 
90
int
 
91
main(int argc, char **argv)
 
92
{
 
93
        xlog_syslog(0);
 
94
        xlog_stderr(1);
 
95
        xlog_open(argv[0]);
 
96
        
 
97
        nsm_load_monitor_list(dump_host);
 
98
        return 0;
 
99
}