Subversion Repositories HomeAutomation

Rev

Rev 997 | Rev 1024 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | SVN | RSS feed

Rev 997 Rev 999
Line 27... Line 27...
27
 
27
 
28
#include "version.h"
28
#include "version.h"
29
#include "Tools/tools.h"
29
#include "Tools/tools.h"
30
#include "SyslogStream/syslogstream.h"
30
#include "SyslogStream/syslogstream.h"
31
#include "Settings/settings.h"
31
#include "Settings/settings.h"
-
 
32
#include "Socket/server.h"
32
#include "CanNet/cannetmanager.h"
33
#include "CanNet/cannetmanager.h"
33
#include "Socket/asyncsocket.h"
34
#include "Socket/asyncsocket.h"
34
#include "VM/virtualmachine.h"
35
#include "VM/virtualmachine.h"
35
#include "CanNet/candebug.h"
36
#include "CanNet/candebug.h"
36
 
37
 
Line 46... Line 47...
46
    signal(SIGPIPE, handler);
47
    signal(SIGPIPE, handler);
47
 
48
 
48
    SyslogStream &slog = SyslogStream::getInstance();
49
    SyslogStream &slog = SyslogStream::getInstance();
49
 
50
 
50
    slog << "Atom " + ftos(VERSION) + " starting...\n";
51
    slog << "Atom " + ftos(VERSION) + " starting...\n";
51
    slog << "Written by Mattias Runge 2008\n\n";
52
    slog << "Written by Mattias Runge 2008-2009\n\n";
52
 
53
 
53
    if (file_exists("/etc/atom.conf"))
54
    if (file_exists("/etc/atom.conf"))
54
    {
55
    {
55
        if (!Settings::read("/etc/atom.conf"))
56
        if (!Settings::read("/etc/atom.conf"))
56
        {
57
        {
Line 66... Line 67...
66
    }
67
    }
67
 
68
 
68
    VirtualMachine &vm = VirtualMachine::getInstance();
69
    VirtualMachine &vm = VirtualMachine::getInstance();
69
    vm.start();
70
    vm.start();
70
 
71
 
-
 
72
    string canDebugPort = Settings::get("CanDebugPort");
-
 
73
    if (canDebugPort != "")
-
 
74
    {
71
    CanDebug &canDebug = CanDebug::getInstance();
75
        CanDebug &canDebug = CanDebug::getInstance();
-
 
76
        canDebug.setSettings(stoi(canDebugPort), "CanDebug");
72
    canDebug.start();
77
        canDebug.start();
-
 
78
    }
-
 
79
    else
-
 
80
    {
-
 
81
        slog << "CanDebugPort is not defined, can not start CanDebug socket\n";
-
 
82
    }
-
 
83
 
-
 
84
    CanNetManager &canMan = CanNetManager::getInstance();
-
 
85
    canMan.start();
73
 
86
 
74
    if (Settings::get("DaemonMode") == "yes")
87
    if (Settings::get("DaemonMode") == "yes")
75
    {
88
    {
76
        slog << "Entering daemon mode...\n";
89
        slog << "Entering daemon mode...\n";
77
        if (daemon(0, 0) == -1)
90
        if (daemon(0, 0) == -1)
78
        {
91
        {
79
            slog << "Could not enter daemon mode. Exiting...\n";
92
            slog << "Could not enter daemon mode. Exiting...\n";
80
            return cleanUp();
93
            return cleanUp();
81
        }
94
        }
82
    }
95
    }
83
 
-
 
84
 
96
 
85
 
-
 
86
    CanNetManager &canMan = CanNetManager::getInstance();
-
 
87
 
-
 
88
    canMan.openChannel();
97
    vm.join();
89
 
98
 
90
    return cleanUp();
99
    return cleanUp();
91
}
100
}
92
 
101
 
93
int cleanUp()
102
int cleanUp()
94
{
103
{
95
    SyslogStream &slog = SyslogStream::getInstance();
104
    SyslogStream &slog = SyslogStream::getInstance();
96
 
105
 
97
    slog << "\n";
106
    slog << "\n";
Line 105... Line 114...
105
    return EXIT_SUCCESS;
114
    return EXIT_SUCCESS;
106
}
115
}
107
 
116
 
108
void handler(int status)
117
void handler(int status)
109
{
118
{
110
    //cout << "In the handler function. Status: " << status << endl;
-
 
111
 
-
 
112
/*
-
 
113
    cout << "SIGTERM: " << SIGTERM << endl;
-
 
114
    cout << "SIGINT: " << SIGINT << endl;
-
 
115
    cout << "SIGQUIT: " << SIGQUIT << endl;
-
 
116
    cout << "SIGABRT: " << SIGABRT << endl;
-
 
117
    cout << "SIGIO: " << SIGIO << endl;
-
 
118
    cout << "SIGPIPE: " << SIGPIPE << endl;
-
 
119
 
-
 
120
*/
-
 
121
    cleanUp();
119
    exit(cleanUp());
122
 
-
 
123
    /*The SIGTERM signal tells a process to exit, so we exit. You can't make a
-
 
124
    process invincible by ignoreing SIGTERM as there are still the
-
 
125
    SIGKILL and SIGSTOP signals which you can't set a handler for (catch) or
-
 
126
    ignore*/
-
 
127
    exit(EXIT_SUCCESS);
-
 
128
}
120
}