-
-
Save MagnusTiberius/ecf1b8e3a3410ba52f629a5a33fc3ca1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <string.h> | |
#include <fcntl.h> | |
#include <unistd.h> | |
#include <getopt.h> | |
#include <sys/queue.h> | |
#include <sys/types.h> | |
#include <sys/socket.h> | |
#include <sys/file.h> | |
#include <sys/stat.h> | |
#include <regex.h> | |
#include <errno.h> | |
#include <syslog.h> | |
#include <time.h> | |
#ifdef SUPPORT_RUN_AS | |
#include <pwd.h> | |
#endif | |
#include <netdb.h> | |
#include <arpa/inet.h> | |
#include <signal.h> | |
#include <linux/limits.h> | |
#include <ctype.h> | |
#include <algorithm> | |
#include <cstdlib> | |
#include <memory> | |
#include <string> | |
#include <vector> | |
#include <utility> | |
#include "jansson.h" | |
#include "json.h" | |
#include "timestamp.h" | |
#include "eipeventd.h" | |
using std::string; | |
using std::vector; | |
using std::unique_ptr; | |
/* | |
* Main function. Process the command line arguments. | |
*/ | |
int main(int argc, char *argv[]) | |
{ | |
EipEventD eipeventd; | |
int c; | |
int port_optind = -1; | |
if ((eipeventd.prog_name = strrchr(argv[0], '/')) != NULL) | |
++eipeventd.prog_name; | |
else | |
eipeventd.prog_name = argv[0]; | |
while (1) { | |
static struct option long_options[] = | |
{ | |
{"port", required_argument, 0, 'p'}, | |
{"help", no_argument, &eipeventd.help_flag, 1}, | |
{"version", no_argument, &eipeventd.version_flag, 1}, | |
{0, 0, 0, 0} | |
}; | |
/* getopt_long stores the option index here. */ | |
int option_index = 0; | |
c = getopt_long(argc, argv, "p:", | |
long_options, &option_index); | |
/* Detect the end of the options. */ | |
if (c == -1) | |
break; | |
switch (c) { | |
case 0: | |
break; | |
case 'p': | |
port_optind = optind - 1; | |
break; | |
case '?': | |
{ | |
printf("? failure\n"); | |
/* getopt_long already printed an error message. */ | |
exit(EXIT_FAILURE); | |
} | |
default: | |
{ | |
printf("abort\n"); | |
abort(); | |
} | |
} | |
} | |
if (eipeventd.help_flag == 1) { | |
eipeventd.print_usage(); | |
exit(EXIT_SUCCESS); | |
} | |
if (eipeventd.version_flag == 1) { | |
eipeventd.print_version(); | |
exit(EXIT_SUCCESS); | |
} | |
eipeventd.daemonize(); | |
eipeventd.run(port_optind != -1 ? argv[port_optind] : DEFAULT_SERVER_PORT); | |
printf("9.0\n"); | |
EipEventD::destroy_pidfile(); | |
closelog(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment