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