1- #include " control_tools.h"
2- #include " pclsync_lib.h"
3- #include " overlay_client.h"
4-
51#include < iostream>
62
73#include < sys/types.h>
1612#include < map>
1713#include < string>
1814
15+ #include " control_tools.h"
16+ #include " pclsync_lib.h"
17+ #include " overlay_client.h"
18+
1919namespace control_tools {
2020
2121static const int STOP = 0 ;
@@ -28,44 +28,49 @@ enum command_ids_ {
2828 ADDSYNC ,
2929 STOPSYNC
3030};
31-
3231
33- int start_crypto (const char * pass) {
32+ int start_crypto (const char * pass){
3433 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;
3837 else
3938 std::cout << " Crypto started. " << std::endl;
40- free (errm);
39+ if (errm)
40+ free (errm);
4141}
42+
4243int stop_crypto (){
4344 int ret;
44- char * errm;
45+ char * errm= NULL ;
4546 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;
4748 else
4849 std::cout << " Crypto Stopped. " << std::endl;
49- free (errm);
50+ if (errm)
51+ free (errm);
5052}
53+
5154int finalize (){
5255 int ret;
53- char * errm;
56+ char * errm= NULL ;
5457 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;
5659 else
5760 std::cout << " Exiting ..." << std::endl;
58-
59- free (errm);
61+ if (errm)
62+ free (errm);
6063}
64+
6165void process_commands ()
6266{
6367 std::cout<< " Supported commands are:" << std::endl << " startcrypto <crypto pass>, stopcrypto, finalize, q, quit" << std::endl;
6468 std::cout<< " > " ;
6569 for (std::string line; std::getline (std::cin, line);) {
66- if (!line.compare (" finalize" )) {
70+ if (!line.compare (" finalize" )){
6771 finalize ();
68- break ;}
72+ break ;
73+ }
6974 else if (!line.compare (" stopcrypto" ))
7075 stop_crypto ();
7176 else if (!line.compare (0 ,11 ," startcrypto" ,0 ,11 ) && (line.length () > 12 ))
@@ -81,11 +86,11 @@ int daemonize(bool do_commands) {
8186 pid_t pid, sid;
8287
8388 pid = fork ();
84- if (pid < 0 )
89+ if (pid< 0 )
8590 exit (EXIT_FAILURE );
86- if (pid > 0 ) {
91+ if (pid> 0 ) {
8792 std::cout << " Daemon process created. Process id is: " << pid << std::endl;
88- if (do_commands) {
93+ if (do_commands){
8994 process_commands ();
9095 }
9196 else
@@ -94,10 +99,9 @@ int daemonize(bool do_commands) {
9499 }
95100 umask (0 );
96101 /* Open any logs here */
97- sid = setsid ();
102+ sid= setsid ();
98103 if (sid < 0 )
99104 exit (EXIT_FAILURE );
100-
101105 if ((chdir (" /" )) < 0 )
102106 exit (EXIT_FAILURE );
103107 close (STDIN_FILENO );
@@ -106,10 +110,9 @@ int daemonize(bool do_commands) {
106110
107111 if (console_client::clibrary::pclsync_lib::get_lib ().init ())
108112 exit (EXIT_FAILURE );
109- while (1 ) {
113+ while (1 ){
110114 sleep (10 );
111115 }
112-
113116}
114117
115- }
118+ }
0 commit comments