Subversion Repositories heating

Rev

Rev 48 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 48 Rev 54
Line 37... Line 37...
37
#include <netinet/in.h>
37
#include <netinet/in.h>
38
#include <sys/ioctl.h>
38
#include <sys/ioctl.h>
39
#include <sys/param.h>
39
#include <sys/param.h>
40
#include <pwd.h>
40
#include <pwd.h>
41
#include <grp.h>
41
#include <grp.h>
-
 
42
#include <bcm2835.h>
42
#include <sys/resource.h>
43
#include <sys/resource.h>
43
#include "config.h"
44
#include "config.h"
44
#include "heating.h"
45
#include "heating.h"
45
 
46
 
46
struct SOCKETS
47
struct SOCKETS
Line 69... Line 70...
69
int main(int argc, char **argv) 
70
int main(int argc, char **argv) 
70
{
71
{
71
struct rlimit core_limits;
72
struct rlimit core_limits;
72
 
73
 
73
	heat = nullptr;
74
	heat = nullptr;
-
 
75
	bcmInitialized = false;
-
 
76
 
74
	// First read config file and check if it was ok
77
	// First read config file and check if it was ok
75
	config *cfg = new config();
78
	config *cfg = new config();
76
	
79
	
77
	if (!cfg->is_initialized())
80
	if (!cfg->is_initialized())
78
	{
81
	{
Line 80... Line 83...
80
		delete (cfg);
83
		delete (cfg);
81
		return 1;
84
		return 1;
82
	}
85
	}
83
	
86
	
84
	CONFIGURE configs = cfg->getConfig();
87
	CONFIGURE configs = cfg->getConfig();
-
 
88
	// We must initialize the BCM2835 library here, as long as we are root!
-
 
89
	if (!bcm2835_init())
-
 
90
		syslog(LOG_WARNING, "Error initializing the BCM2835 library! The GPIO ports will not function.");
-
 
91
	else
-
 
92
		bcmInitialized = true;
-
 
93
 
85
	// Daemonize and run in background
94
	// Daemonize and run in background
86
	daemon_start(0);
95
	daemon_start(0);
87
	changeToUser(configs.user, configs.group);
96
	changeToUser(configs.user, configs.group);
88
	// core dumps may be disallowed by parent of this process; change that
97
	// core dumps may be disallowed by parent of this process; change that
89
	if (Configure.debug)
98
	if (Configure.debug)
Line 195... Line 204...
195
		{
204
		{
196
			heat->stopRun();
205
			heat->stopRun();
197
			sleep(2);
206
			sleep(2);
198
		}
207
		}
199
 
208
 
-
 
209
		if (bcmInitialized)
-
 
210
			bcm2835_close();
-
 
211
 
200
		exit(0);
212
		exit(0);
201
	}
213
	}
202
}
214
}
203
 
215
 
204
void changeToUser(const char *usr, const char *grp)
216
void changeToUser(const char *usr, const char *grp)