1
- #include " control_tools.h"
2
- #include " pclsync_lib.h"
3
- #include " overlay_client.h"
4
-
5
1
#include < iostream>
6
2
7
3
#include < sys/types.h>
16
12
#include < map>
17
13
#include < string>
18
14
15
+ #include " control_tools.h"
16
+ #include " pclsync_lib.h"
17
+ #include " overlay_client.h"
18
+
19
19
namespace control_tools {
20
20
21
21
static const int STOP = 0 ;
@@ -28,44 +28,49 @@ enum command_ids_ {
28
28
ADDSYNC,
29
29
STOPSYNC
30
30
};
31
-
32
31
33
- int start_crypto (const char * pass) {
32
+ int start_crypto (const char * pass){
34
33
int ret;
35
- char * errm;
36
- if (SendCall (STARTCRYPTO, pass, &ret, &errm))
37
- std::cout << " Start Crypto failed. return is " << ret<< " and message is " <<errm << std::endl;
34
+ char * errm= NULL ;
35
+ if (SendCall (STARTCRYPTO, pass, &ret, &errm))
36
+ std::cout << " Start Crypto failed. return is " << ret << " and message is " <<errm << std::endl;
38
37
else
39
38
std::cout << " Crypto started. " << std::endl;
40
- free (errm);
39
+ if (errm)
40
+ free (errm);
41
41
}
42
+
42
43
int stop_crypto (){
43
44
int ret;
44
- char * errm;
45
+ char * errm= NULL ;
45
46
if (SendCall (STOPCRYPTO, " " , &ret, &errm))
46
- std::cout << " Stop Crypto failed. return is " << ret<< " and message is " <<errm << std::endl;
47
+ std::cout << " Stop Crypto failed. return is " << ret << " and message is " << errm << std::endl;
47
48
else
48
49
std::cout << " Crypto Stopped. " << std::endl;
49
- free (errm);
50
+ if (errm)
51
+ free (errm);
50
52
}
53
+
51
54
int finalize (){
52
55
int ret;
53
- char * errm;
56
+ char * errm= NULL ;
54
57
if (SendCall (FINALIZE, " " , &ret, &errm))
55
- std::cout << " Finalize failed. return is " << ret<< " and message is " <<errm << std::endl;
58
+ std::cout << " Finalize failed. return is " << ret<< " and message is " << errm << std::endl;
56
59
else
57
60
std::cout << " Exiting ..." << std::endl;
58
-
59
- free (errm);
61
+ if (errm)
62
+ free (errm);
60
63
}
64
+
61
65
void process_commands ()
62
66
{
63
67
std::cout<< " Supported commands are:" << std::endl << " startcrypto <crypto pass>, stopcrypto, finalize, q, quit" << std::endl;
64
68
std::cout<< " > " ;
65
69
for (std::string line; std::getline (std::cin, line);) {
66
- if (!line.compare (" finalize" )) {
70
+ if (!line.compare (" finalize" )){
67
71
finalize ();
68
- break ;}
72
+ break ;
73
+ }
69
74
else if (!line.compare (" stopcrypto" ))
70
75
stop_crypto ();
71
76
else if (!line.compare (0 ,11 ," startcrypto" ,0 ,11 ) && (line.length () > 12 ))
@@ -81,11 +86,11 @@ int daemonize(bool do_commands) {
81
86
pid_t pid, sid;
82
87
83
88
pid = fork ();
84
- if (pid < 0 )
89
+ if (pid< 0 )
85
90
exit (EXIT_FAILURE);
86
- if (pid > 0 ) {
91
+ if (pid> 0 ) {
87
92
std::cout << " Daemon process created. Process id is: " << pid << std::endl;
88
- if (do_commands) {
93
+ if (do_commands){
89
94
process_commands ();
90
95
}
91
96
else
@@ -94,10 +99,9 @@ int daemonize(bool do_commands) {
94
99
}
95
100
umask (0 );
96
101
/* Open any logs here */
97
- sid = setsid ();
102
+ sid= setsid ();
98
103
if (sid < 0 )
99
104
exit (EXIT_FAILURE);
100
-
101
105
if ((chdir (" /" )) < 0 )
102
106
exit (EXIT_FAILURE);
103
107
close (STDIN_FILENO);
@@ -106,10 +110,9 @@ int daemonize(bool do_commands) {
106
110
107
111
if (console_client::clibrary::pclsync_lib::get_lib ().init ())
108
112
exit (EXIT_FAILURE);
109
- while (1 ) {
113
+ while (1 ){
110
114
sleep (10 );
111
115
}
112
-
113
116
}
114
117
115
- }
118
+ }
0 commit comments