1 // This file is part of BOINC.
2 // http://boinc.berkeley.edu
3 // Copyright (C) 2011 University of California
4 //
5 // BOINC is free software; you can redistribute it and/or modify it
6 // under the terms of the GNU Lesser General Public License
7 // as published by the Free Software Foundation,
8 // either version 3 of the License, or (at your option) any later version.
9 //
10 // BOINC is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 // See the GNU Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public License
16 // along with BOINC.  If not, see <http://www.gnu.org/licenses/>.
17 
18 // cancel_jobs min-ID max-ID
19 //    cancel jobs from min-ID to max-ID inclusive
20 // cancel_jobs --name wuname
21 //    cancel the job with the given name
22 
23 #include <stdio.h>
24 
25 #include "backend_lib.h"
26 #include "sched_config.h"
27 
usage()28 void usage() {
29     fprintf(stderr, "Usage: cancel_jobs min-ID max-ID\n");
30     fprintf(stderr, "or cancel_jobs --name wuname\n");
31     exit(1);
32 }
33 
main(int argc,char ** argv)34 int main(int argc, char** argv) {
35     if (argc != 3) usage();
36 
37     int retval = config.parse_file();
38     if (retval) exit(1);
39 
40     retval = boinc_db.open(
41         config.db_name, config.db_host, config.db_user, config.db_passwd
42     );
43     if (retval) {
44         printf("boinc_db.open: %s\n", boincerror(retval));
45         exit(1);
46     }
47     if (!strcmp(argv[1], "--name")) {
48         DB_WORKUNIT wu;
49         char buf[256];
50         snprintf(buf, sizeof(buf), "where name='%s'", argv[2]);
51         retval = wu.lookup(buf);
52         if (retval) {
53             fprintf(stderr, "No workunit named '%s'\n", argv[2]);
54             exit(1);
55         }
56         retval = cancel_job(wu);
57     } else {
58         int min_id = atoi(argv[1]);
59         int max_id = atoi(argv[2]);
60         if (!min_id || !max_id) usage();
61         retval = cancel_jobs(min_id, max_id);
62     }
63     if (retval) {
64         fprintf(stderr, "cancel job failed: %s\n", boincerror(retval));
65         exit(retval);
66     }
67 }
68