@@ -28,49 +28,44 @@ enum command_ids_ {
2828 ADDSYNC ,
2929 STOPSYNC
3030};
31+
3132
32- int start_crypto (const char * pass){
33+ int start_crypto (const char * pass) {
3334 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;
3738 else
3839 std::cout << " Crypto started. " << std::endl;
39- if (errm)
40- free (errm);
40+ free (errm);
4141}
42-
4342int stop_crypto (){
4443 int ret;
45- char * errm= NULL ;
44+ char * errm;
4645 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;
4847 else
4948 std::cout << " Crypto Stopped. " << std::endl;
50- if (errm)
51- free (errm);
49+ free (errm);
5250}
53-
5451int finalize (){
5552 int ret;
56- char * errm= NULL ;
53+ char * errm;
5754 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;
5956 else
6057 std::cout << " Exiting ..." << std::endl;
61- if (errm)
62- free (errm);
58+
59+ free (errm);
6360}
64-
6561void process_commands ()
6662{
6763 std::cout<< " Supported commands are:" << std::endl << " startcrypto <crypto pass>, stopcrypto, finalize, q, quit" << std::endl;
6864 std::cout<< " > " ;
6965 for (std::string line; std::getline (std::cin, line);) {
70- if (!line.compare (" finalize" )){
66+ if (!line.compare (" finalize" )) {
7167 finalize ();
72- break ;
73- }
68+ break ;}
7469 else if (!line.compare (" stopcrypto" ))
7570 stop_crypto ();
7671 else if (!line.compare (0 ,11 ," startcrypto" ,0 ,11 ) && (line.length () > 12 ))
@@ -86,11 +81,11 @@ int daemonize(bool do_commands) {
8681 pid_t pid, sid;
8782
8883 pid = fork ();
89- if (pid< 0 )
84+ if (pid < 0 )
9085 exit (EXIT_FAILURE );
91- if (pid> 0 ) {
86+ if (pid > 0 ) {
9287 std::cout << " Daemon process created. Process id is: " << pid << std::endl;
93- if (do_commands){
88+ if (do_commands) {
9489 process_commands ();
9590 }
9691 else
@@ -99,9 +94,10 @@ int daemonize(bool do_commands) {
9994 }
10095 umask (0 );
10196 /* Open any logs here */
102- sid= setsid ();
97+ sid = setsid ();
10398 if (sid < 0 )
10499 exit (EXIT_FAILURE );
100+
105101 if ((chdir (" /" )) < 0 )
106102 exit (EXIT_FAILURE );
107103 close (STDIN_FILENO );
@@ -110,9 +106,10 @@ int daemonize(bool do_commands) {
110106
111107 if (console_client::clibrary::pclsync_lib::get_lib ().init ())
112108 exit (EXIT_FAILURE );
113- while (1 ){
109+ while (1 ) {
114110 sleep (10 );
115111 }
112+
116113}
117114
118115}
0 commit comments