File: dpm-ping.c

package info (click to toggle)
dpm-postgres 1.7.4.7-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 13,788 kB
  • ctags: 10,782
  • sloc: ansic: 146,136; sh: 13,362; perl: 11,142; python: 5,529; cpp: 5,113; sql: 1,790; makefile: 955; fortran: 113
file content (53 lines) | stat: -rw-r--r-- 1,210 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
 * Copyright (C) 2007-2008 by CERN/IT/GD/ITR
 * All rights reserved
 */
 
#ifndef lint
static char sccsid[] = "@(#)$RCSfile: dpm-ping.c,v $ $Revision: 1.2 $ $Date: 2008/01/29 06:49:24 $ CERN IT-GD/ITR Jean-Philippe Baud";
#endif /* not lint */

/*	dpm-ping - check server alive and return version number */
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include "dpm_api.h"
#include "serrno.h"
extern	char	*optarg;
extern	int	optind;
main(argc, argv)
int argc;
char **argv;
{
	int c;
	int errflg = 0;
	char info[256];
	char *server = NULL;

        while ((c = getopt (argc, argv, "h:")) != EOF) {
                switch (c) {
		case 'h':
			server = optarg;
			break;
                case '?':
                        errflg++;
                        break;
                default:
                        break;
                }
        }
        if (optind < argc) {
                errflg++;
        }
        if (errflg) {
                fprintf (stderr, "usage: %s [-h server]\n", argv[0]);
                exit (USERR);
        }

	if (dpm_ping (server, info) < 0) {
		fprintf (stderr, "dpm-ping: %s\n", sstrerror(serrno));
		exit (USERR);
	}
	printf ("%s\n", info);
	exit (0);
}