File: yshutdown.c

package info (click to toggle)
yiff 2.06-3
  • links: PTS
  • area: main
  • in suites: potato
  • size: 3,464 kB
  • ctags: 3,028
  • sloc: ansic: 47,463; makefile: 218; sh: 77
file content (117 lines) | stat: -rw-r--r-- 1,598 bytes parent folder | download
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
#include <string.h>

#include <Y2/Y.h>
#include <Y2/Ylib.h>

#include "../include/string.h"


#ifndef DEF_CON_ARG
# define DEF_CON_ARG	"127.0.0.1:9433"
#endif


/*
 *	Print help.
 */
void PrintUsage()
{
	printf("\
Usage: yshutdown [options]\n\
\n\
    [options] can be any of the following:\n\
\n\
        --recorder <address:port>    Specify which YIFF server to connect to.\n\
\n"
	);


	return;
}


int main(int argc, char *argv[])
{
	int i;

	char *con_arg = NULL;

	YConnection *con = NULL;



	/* Parse arguments. */
	for(i = 1; i < argc; i++)
	{
	    if(argv[i] == NULL)
		continue;

	    /* Help. */
	    if(strcasepfx(argv[i], "--h") ||
               strcasepfx(argv[i], "-h") ||
               !strcmp(argv[i], "?")
	    )
	    {
		PrintUsage();
		return(0);
	    }



	    /* Connect address. */
	    else if(strcasepfx(argv[i], "--rec") ||
                    strcasepfx(argv[i], "-rec")
	    )
	    {
		i++;
		if(i < argc)
		{
		    free(con_arg);
		    con_arg = StringCopyAlloc(argv[i]);
		}
		else
		{
		    fprintf(stderr,
			"%s: Requires argument.\n",
			argv[i - 1]
		    );
		}
	    }
	}


	/*
	 *	Connect to YIFF server.
	 */
	con = YOpenConnection(
	    NULL,		/* No start argument. */
	    con_arg
	);
	if(con == NULL)
	{
	    printf("%s: Cannot connect to YIFF server.\n",
		(con_arg == NULL) ? DEF_CON_ARG : con_arg
	    );

            free(con_arg);
            con_arg = NULL;

	    return(-1);
	}


	/*
	 *	Shut down the server.
	 */
	YShutdownServer(con);


	free(con_arg);
	con_arg = NULL;


	return(0);
}