tasty! apache remover is working
[feisty_meow.git] / nucleus / tools / simple_utilities / zap_process.cpp
1 /*****************************************************************************\
2 *                                                                             *
3 *  Name   : zap_process                                                       *
4 *  Author : Chris Koeritz                                                     *
5 *                                                                             *
6 *  Purpose:                                                                   *
7 *                                                                             *
8 *    Whacks a process named on the command line, if possible.                 *
9 *                                                                             *
10 *******************************************************************************
11 * Copyright (c) 2000-$now By Author.  This program is free software; you can  *
12 * redistribute it and/or modify it under the terms of the GNU General Public  *
13 * License as published by the Free Software Foundation; either version 2 of   *
14 * the License or (at your option) any later version.  This is online at:      *
15 *     http://www.fsf.org/copyleft/gpl.html                                    *
16 * Please send any updates to: fred@gruntose.com                               *
17 \*****************************************************************************/
18
19 #include <application/command_line.h>
20 #include <application/windoze_helper.h>
21 #include <basis/astring.h>
22 #include <basis/guards.h>
23 #include <filesystem/filename.h>
24 #include <loggers/console_logger.h>
25 #include <loggers/critical_events.h>
26 #include <processes/process_control.h>
27 #include <processes/process_entry.h>
28 #include <structures/static_memory_gremlin.h>
29
30 //HOOPLE_STARTUP_CODE;
31 //hmmm: missing
32
33 using namespace application;
34 using namespace basis;
35 using namespace filesystem;
36 using namespace loggers;
37 using namespace processes;
38 using namespace structures;
39
40 int main(int argc, char *argv[])
41 {
42   console_logger out;
43   command_line cmds(argc, argv);
44   if ( (cmds.entries() < 1)
45       || (cmds.get(0).type() != command_parameter::VALUE) ) {
46     out.log(cmds.program_name().basename().raw() + " usage:\n"
47         "this takes a single parameter, which is the name of a program\n"
48         "to hunt down and eradicate.  this will zap the program without\n"
49         "any warning or any chance for it to save its state.", ALWAYS_PRINT);
50     return 1;
51   }
52   astring program_name = cmds.get(0).text();
53   program_name.to_lower();
54   process_entry_array processes;
55   process_control proc_con;
56   if (!proc_con.query_processes(processes))
57     non_continuable_error("procto", "main", "failed to query processes!");
58   bool found = false;
59   bool success = true;
60   for (int i = 0; i < processes.length(); i++) {
61     filename path = processes[i].path();
62 //    out.log(astring("got process path: ") + path.raw(), ALWAYS_PRINT);
63     astring base = path.basename().raw().lower();
64     if (base == program_name) {
65       found = true;
66 //      out.log("would whack this entry:");
67 //      out.log(processes[i].text_form());
68       bool ret = proc_con.zap_process(processes[i]._process_id);
69       if (ret)
70         out.log(a_sprintf("Killed process %d [", processes[i]._process_id)
71             + program_name + astring("]"), ALWAYS_PRINT);
72       else {
73         out.log(astring(astring::SPRINTF, "Failed to zap process %d [",
74             processes[i]._process_id) + program_name + astring("]"), ALWAYS_PRINT);
75         success = false;
76       }
77     }
78   }
79   if (!found)
80     out.log(astring("Could not find the program named ") + program_name, ALWAYS_PRINT);
81   if (!success) return 123;
82   else return 0;
83 }
84
85 #ifdef __BUILD_STATIC_APPLICATION__
86   // static dependencies found by buildor_gen_deps.sh:
87   #include <application/application_shell.cpp>
88   #include <application/command_line.cpp>
89   #include <application/windoze_helper.cpp>
90   #include <basis/astring.cpp>
91   #include <basis/common_outcomes.cpp>
92   #include <basis/environment.cpp>
93   #include <basis/guards.cpp>
94   #include <basis/mutex.cpp>
95   #include <basis/utf_conversion.cpp>
96   #include <configuration/application_configuration.cpp>
97   #include <configuration/configurator.cpp>
98   #include <configuration/ini_configurator.cpp>
99   #include <configuration/ini_parser.cpp>
100   #include <configuration/table_configurator.cpp>
101   #include <configuration/variable_tokenizer.cpp>
102   #include <filesystem/byte_filer.cpp>
103   #include <filesystem/directory.cpp>
104   #include <filesystem/filename.cpp>
105   #include <loggers/combo_logger.cpp>
106   #include <loggers/console_logger.cpp>
107   #include <loggers/critical_events.cpp>
108   #include <loggers/file_logger.cpp>
109   #include <loggers/program_wide_logger.cpp>
110   #include <processes/process_control.cpp>
111   #include <processes/process_entry.cpp>
112   #include <structures/bit_vector.cpp>
113   #include <structures/checksums.cpp>
114   #include <structures/object_packers.cpp>
115   #include <structures/static_memory_gremlin.cpp>
116   #include <structures/string_hasher.cpp>
117   #include <structures/string_table.cpp>
118   #include <structures/version_record.cpp>
119   #include <textual/byte_formatter.cpp>
120   #include <textual/parser_bits.cpp>
121   #include <textual/string_manipulation.cpp>
122   #include <timely/earth_time.cpp>
123   #include <timely/time_stamp.cpp>
124 #endif // __BUILD_STATIC_APPLICATION__
125