File: startup.c

package info (click to toggle)
popa3d 1.0.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 480 kB
  • sloc: ansic: 2,334; sh: 106; makefile: 61
file content (96 lines) | stat: -rw-r--r-- 1,449 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
/*
 * Command line option parsing.
 */

#include "params.h"

#if POP_OPTIONS

#include <sys/socket.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>

/* version.c */
extern char popa3d_version[];
extern char popa3d_date[];

/* standalone.c */
extern int do_standalone(int foreground);

/* pop_root.c */
extern int do_pop_startup(void);
extern int do_pop_session(void);

#ifdef HAVE_PROGNAME
extern char *__progname;
#define progname __progname
#else
static char *progname;
#endif

int af = AF_UNSPEC;
int dual_stack = 0;

static void usage(void)
{
	fprintf(stderr, "Usage: %s [-D] [-F] [-V]\n", progname);
	exit(1);
}

static void version(void)
{
	printf("popa3d version %s (%s)\n", popa3d_version, popa3d_date);
	exit(0);
}

int main(int argc, char **argv)
{
	int c;
	int standalone = 0;
	int foreground = 0;

#ifndef HAVE_PROGNAME
	if (!(progname = argv[0]))
		progname = POP_SERVER;
#endif

	while ((c = getopt(argc, argv, "DFV46")) != -1) {
		switch (c) {
		case 'F':
			foreground++;
			/* fallthrough */
		case 'D':
			standalone++;
			break;
		case '4':
			if (af == AF_INET6)
				dual_stack = 1;
			else
				af = AF_INET;
			break;
		case '6':
			if (af == AF_INET)
				dual_stack = 1;
			af = AF_INET6;
			break;

		case 'V':
			version();

		default:
			usage();
		}
	}

	if (optind != argc)
		usage();

	if (standalone)
		return do_standalone(foreground);

	if (do_pop_startup()) return 1;
	return do_pop_session();
}

#endif