From 03850d103d5f4e454a5aab01aacd3ea2f401ba3b Mon Sep 17 00:00:00 2001 From: David Anderson Date: Wed, 21 May 2014 09:20:33 -0700 Subject: [PATCH] create_work: error out if bad ID arg in "--target_host ID" etc. Actually we just check that the arg is nonzero. We could look up the DB record (e.g. the host record) but that would slow down mass job creation. --- tools/create_work.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tools/create_work.cpp b/tools/create_work.cpp index fc3a127883..ad7a286432 100644 --- a/tools/create_work.cpp +++ b/tools/create_work.cpp @@ -158,6 +158,15 @@ void JOB_DESC::parse_cmdline(int argc, char** argv) { } } +void check_assign_id(int x) { + if (x == 0) { + fprintf(stderr, + "you must specify a nonzero database ID for assigning jobs to users, teams, or hosts.\n" + ); + exit(1); + } +} + int main(int argc, char** argv) { DB_APP app; int retval; @@ -235,23 +244,28 @@ int main(int argc, char** argv) { jd.assign_type = ASSIGN_USER; jd.assign_multi = true; jd.assign_id = atoi(argv[++i]); + check_assign_id(jd.assign_id); } else if (arg(argv, i, "broadcast_team")) { jd.assign_flag = true; jd.assign_type = ASSIGN_TEAM; jd.assign_multi = true; jd.assign_id = atoi(argv[++i]); + check_assign_id(jd.assign_id); } else if (arg(argv, i, "target_host")) { jd.assign_flag = true; jd.assign_type = ASSIGN_HOST; jd.assign_id = atoi(argv[++i]); + check_assign_id(jd.assign_id); } else if (arg(argv, i, "target_user")) { jd.assign_flag = true; jd.assign_type = ASSIGN_USER; jd.assign_id = atoi(argv[++i]); + check_assign_id(jd.assign_id); } else if (arg(argv, i, "target_team")) { jd.assign_flag = true; jd.assign_type = ASSIGN_TEAM; jd.assign_id = atoi(argv[++i]); + check_assign_id(jd.assign_id); } else if (arg(argv, i, "help")) { usage(); exit(0);