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