Subversion Repositories heating

Rev

Rev 5 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 andreas 1
/*
2
 * Copyright (C) 2015 by Andreas Theofilu. All rights reserved!
3
 *
4
 * All rights reserved. No warranty, explicit or implicit, provided.
5
 *
6
 * NOTICE:  All information contained herein is, and remains
7
 * the property of Andreas Theofilu and his suppliers, if any.
8
 * The intellectual and technical concepts contained
9
 * herein are proprietary to Andreas Theofilu and its suppliers and
10
 * may be covered by European and Foreign Patents, patents in process,
11
 * and are protected by trade secret or copyright law.
12
 * Dissemination of this information or reproduction of this material
13
 * is strictly forbidden unless prior written permission is obtained
14
 * from Andreas Theofilu.
15
 * 
16
 * Author: Andreas Theofilu <andreas@theosys.at>
17
 */
18
#include <iostream>
19
#include <fstream>
20
#include <string>
21
#include <cstdio>
22
#include <cstring>
23
#include <ctime>
24
#include <cstdlib>
25
#include <csignal>
26
#include <syslog.h>
27
#include <cerrno>
28
#include <unistd.h>
29
#include <pthread.h>
30
#include <sys/stat.h>
31
#include <sys/types.h>
32
#include <sys/socket.h>
33
#include <fcntl.h>
34
#include <netdb.h>
35
#include <arpa/inet.h>
36
#include <netinet/in.h>
37
#include <sys/ioctl.h>
38
#include <sys/param.h>
39
#include <pwd.h>
40
#include <grp.h>
41
#include "config.h"
42
 
43
struct SOCKETS
44
{
45
	int sockfd;
46
	int newfd;
47
	char ip[256];
48
};
49
 
50
void daemon_start (int ignsigcld);
51
void sig_handler(int sig);
52
void changeToUser(const char *usr, const char *grp);
53
void sig_child ();
54
 
55
void *pthr_parser(void *pV_data);
56
void *pthr_Probe(void * pV_data);
57
void *processCommands(void *pV_data);
58
int parseCommand(int s1, char *buf);
59
 
60
struct SOCKETS soc;				// The network sockets to be passed to a thread
61
 
62
int main(int argc, char **argv) 
63
{
64
	// First read config file and check if it was ok
65
	config *cfg = new config();
66
 
67
	if (!cfg->is_initialized())
68
	{
69
		std::cerr << "Error reading config file! Make sure there is one and that it is readable by root!" << std::endl;
70
		exit (0);
71
	}
72
 
73
	CONFIGURE configs = cfg->getConfig();
74
	// Daemonize and run in background
75
	daemon_start(0);
76
	changeToUser(configs.user, configs.group);
77
	// We no longer need the configuration data here, so we remove them.
78
	delete (cfg);
79
	// Now start our Thread
80
	if (pthread_create(&pthr_pars, NULL, pthr_parser, (void *)0) != 0)
81
	{
82
		syslog (LOG_DAEMON,"Create of thread \"pthr_parser\" failed!");
83
		return 1;
84
	}
85
 
86
	while (1)
87
		sleep(3600);
88
 
89
	return 0;
90
}