~ubuntu-branches/ubuntu/trusty/rstatd/trusty

« back to all changes in this revision

Viewing changes to rstat_main.c

  • Committer: Bazaar Package Importer
  • Author(s): Anibal Monsalve Salazar
  • Date: 2005-02-10 20:19:28 UTC
  • mfrom: (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050210201928-jy94wvrfs75kgt6i
Tags: 3.07-4
New maintainer's email address.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * $Id: rstat_main.c,v 1.2 2002/01/14 12:24:48 andik Exp $
 
3
 *
 
4
 *  rpc.rstatd version 3.07 rpc remote statistics daemon. 
 
5
 *  Copyright (C) 1995  Adam Migus, Memorial University of Newfoundland
 
6
 *       (MUN)
 
7
 *  Copyright (C) 2001 Andreas Klingler, University of Erlangen-Nuernberg
 
8
 *
 
9
 *  This program is free software; you can redistribute it and/or modify
 
10
 *  it under the terms of the GNU General Public License as published by
 
11
 *  the Free Software Foundation; either version 1, or (at your option)
 
12
 *  any later version.
 
13
 *
 
14
 *  This program is distributed in the hope that it will be useful,
 
15
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
16
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
17
 *  GNU General Public License for more details.
 
18
 *
 
19
 *  You should have received a copy of the GNU General Public License
 
20
 *  along with this program; if not, write to the Free Software
 
21
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
22
 *
 
23
 *  If you make modifications to the source, I would be happy to have
 
24
 *  them to include in future releases.  Feel free to send them to:
 
25
 *      Adam Migus                                      
 
26
 *              amigus@cs.mun.ca 
 
27
 *      amigus@ucs.mun.ca   
 
28
 *
 
29
 *              Modified by Adam Migus (amigus@cs.mun.ca)
 
30
 *              Modified by Andreas Klingler (andreas.klingler@cyber-wizard.com)
 
31
 *
 
32
 * Original Author:
 
33
 * Copyright (c) 1993, John Brezak
 
34
 * All rights reserved.
 
35
 *
 
36
 **************************************************************************/
 
37
 
 
38
#include <stdio.h>
 
39
#include <rpc/rpc.h>
 
40
#include <signal.h>
 
41
#include <syslog.h>
 
42
#include "rstat.h"
 
43
 
 
44
static char * id = "@(#) $Id: rstat_main.c,v 1.2 2002/01/14 12:24:48 andik Exp $ $Revision: 1.2 $";
 
45
 
 
46
extern void rstat_service();
 
47
extern void test_connect();
 
48
 
 
49
int inetd_connect = 1;
 
50
 
 
51
void background()
 
52
{
 
53
        int pid;
 
54
        
 
55
        pid = fork();
 
56
        switch(pid) {
 
57
                case 0:
 
58
                        break;
 
59
                case -1: 
 
60
                        perror("fork");
 
61
                        break;
 
62
                default:
 
63
                        exit(0);
 
64
        }
 
65
        setsid();
 
66
}
 
67
void cleanup()
 
68
{
 
69
        (void) pmap_unset(RSTATPROG, RSTATVERS_USERS);
 
70
        (void) pmap_unset(RSTATPROG, RSTATVERS_TIME);
 
71
        (void) pmap_unset(RSTATPROG, RSTATVERS_SWTCH);
 
72
        (void) pmap_unset(RSTATPROG, RSTATVERS_ORIG);
 
73
        exit(0);
 
74
}
 
75
 
 
76
int ninterfaces;
 
77
char **interfaces;
 
78
 
 
79
void main(argc, argv)
 
80
     int argc;
 
81
     char **argv;
 
82
{
 
83
        SVCXPRT *transp;
 
84
        int fromlen, sock = 0, proto = 0;
 
85
        struct sockaddr_in from;
 
86
        int debug = 0;
 
87
        int count = 1;
 
88
 
 
89
        if (argc > 1)
 
90
          {
 
91
            if (strcmp("-d", argv[count]) == 0)
 
92
              {
 
93
                debug = 1;
 
94
                count++;
 
95
              }
 
96
            ninterfaces = argc - count; /* everything on the commandline besides -d */
 
97
            interfaces = &argv[count];  /* is interpreted as interface names */
 
98
          }
 
99
        
 
100
        if (getsockname(sock,(struct sockaddr *)&from, &fromlen) < 0) {
 
101
                inetd_connect = 0;
 
102
                sock = RPC_ANYSOCK;
 
103
                proto = IPPROTO_UDP;
 
104
        }
 
105
 
 
106
        if (!(inetd_connect)) {
 
107
                (void)pmap_unset(RSTATPROG, RSTATVERS_USERS);
 
108
                (void)pmap_unset(RSTATPROG, RSTATVERS_TIME);
 
109
                (void)pmap_unset(RSTATPROG, RSTATVERS_SWTCH);
 
110
                (void)pmap_unset(RSTATPROG, RSTATVERS_ORIG);
 
111
                (void) signal(SIGINT, cleanup);
 
112
                (void) signal(SIGTERM, cleanup);
 
113
                (void) signal(SIGHUP, cleanup);
 
114
                openlog("rpc.rstatd", LOG_CONS|LOG_PID, LOG_DAEMON);
 
115
                if (!debug) background();
 
116
        }
 
117
        (void)signal(SIGALRM, test_connect);
 
118
 
 
119
        transp = svcudp_create(sock);
 
120
        if (transp == NULL) {
 
121
                syslog(LOG_ERR, "cannot create udp service.");
 
122
                exit(1);
 
123
        }
 
124
        if (!svc_register(transp, RSTATPROG, RSTATVERS_USERS, rstat_service, proto)) {
 
125
                syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_USERS, udp).");
 
126
                exit(1);
 
127
        }
 
128
        if (!svc_register(transp, RSTATPROG, RSTATVERS_TIME, rstat_service, proto)) {
 
129
                syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_TIME, udp).");
 
130
                exit(1);
 
131
        }
 
132
        if (!svc_register(transp, RSTATPROG, RSTATVERS_SWTCH, rstat_service, proto)) {
 
133
                syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_SWTCH, udp).");
 
134
                exit(1);
 
135
        }
 
136
        if (!svc_register(transp, RSTATPROG, RSTATVERS_ORIG, rstat_service, proto)) {
 
137
                syslog(LOG_ERR, "unable to register (RSTATPROG, RSTATVERS_ORIG, udp).");
 
138
                exit(1);
 
139
        }
 
140
 
 
141
        svc_run();
 
142
        syslog(LOG_ERR, "svc_run returned");
 
143
        exit(1);
 
144
}