00001 // ----------------------------------------------------------------------^ 00002 // Copyright (C) 2004, 2005, 2006, 2007, 2008 Giorgio Calderone 00003 // (mailto: <gcalderone@ifc.inaf.it>) 00004 // 00005 // This file is part of MCS. 00006 // 00007 // MCS is free software; you can redistribute it and/or modify 00008 // it under the terms of the GNU General Public License as published by 00009 // the Free Software Foundation; either version 2 of the License, or 00010 // (at your option) any later version. 00011 // 00012 // MCS is distributed in the hope that it will be useful, 00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 // GNU General Public License for more details. 00016 // 00017 // You should have received a copy of the GNU General Public License 00018 // along with MCS; if not, write to the Free Software 00019 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00020 // 00021 // ----------------------------------------------------------------------$ 00022 00023 00024 #include <mcs.hh> 00025 using namespace mcs; 00026 00027 void usage() 00028 { 00029 cout << "killmcs: kills a MCS server" << endl; 00030 cout << "Giorgio Calderone <gcalderone@ifc.inaf.it>" << endl; 00031 cout << endl; 00032 cout << "Usage: killmcs [-h] appname [inipath]" << endl; 00033 } 00034 00035 00036 int main(int argc, char* argv[]) 00037 { 00038 Env* env = NULL; 00039 CommandParser cp; 00040 string s; 00041 00042 try { 00043 cp.parseCmd(argc, argv); 00044 00045 if (argc == 1 || //Invocation without any option or argument 00046 cp.givenOpt("h") || //Option -h has been given 00047 cp.argc() == 0 ){ //No argument has been given 00048 usage(); 00049 exit(0); 00050 } 00051 00052 //At least one argument has been given 00053 string appname = cp.arg(0).sval(); 00054 00055 //Eventually get the second argument 00056 string inipath = (cp.argc() >= 2 ? cp.arg(1).sval() : ""); 00057 00058 if (inipath.empty()) 00059 env = new Env(appname); 00060 else 00061 env = new Env(appname, inipath); 00062 env-> server = NULL; 00063 00064 if (chdir(env->path.c_str()) != 0) 00065 throw MCS_ERROR(MSG_DIRECTORY_NOT_FOUND, env->path); 00066 00067 s = env->path + "/mcs.pid"; 00068 ifstream pidfile("mcs.pid"); 00069 00070 if (pidfile.fail()) 00071 throw MCS_ERROR(MSG_CANT_OPEN_FILE, s.c_str()); 00072 00073 pidfile >> s; 00074 pidfile.close(); 00075 unlink("mcs.pid"); 00076 00077 s = "kill " + s; 00078 cout << s << endl; 00079 00080 exit(system(s.c_str())); 00081 } 00082 catch (Event& e) { 00083 cerr << e.msg() << endl; 00084 exit(3); 00085 } 00086 00087 00088 if (env) delete env; 00089 }
![]() |
MCS (My Customizable Server) ver. 0.3.3-alpha3
|