1 /****************************************************************************
2 * Copyright (C) 2006-2010 by Jason Ansel, Kapil Arya, and Gene Cooperman *
3 * jansel@csail.mit.edu, kapil@ccs.neu.edu, gene@ccs.neu.edu *
4 * *
5 * This file is part of the dmtcp/src module of DMTCP (DMTCP:dmtcp/src). *
6 * *
7 * DMTCP:dmtcp/src is free software: you can redistribute it and/or *
8 * modify it under the terms of the GNU Lesser General Public License as *
9 * published by the Free Software Foundation, either version 3 of the *
10 * License, or (at your option) any later version. *
11 * *
12 * DMTCP:dmtcp/src is distributed in the hope that it will be useful, *
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
15 * GNU Lesser General Public License for more details. *
16 * *
17 * You should have received a copy of the GNU Lesser General Public *
18 * License along with DMTCP:dmtcp/src. If not, see *
19 * <http://www.gnu.org/licenses/>. *
20 ****************************************************************************/
21
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25
26 #include "dmtcpcoordinatorapi.h"
27 #include "dmtcp_coordinator.h"
28 #include "dmtcpmessagetypes.h"
29 #include "mtcpinterface.h"
30
31 using namespace dmtcp;
32
33 // gcc-4.3.4 -Wformat=2 issues false positives for warnings unless the format
34 // string has atleast one format specifier with corresponding format argument.
35 // Ubuntu 9.01 uses -Wformat=2 by default.
36 static const char* theUsage =
37 "%sPURPOSE:\n"
38 " Send a command to the dmtcp_coordinator remotely.\n\n"
39 "USAGE:\n"
40 " dmtcp_command [OPTIONS] COMMAND [COMMAND...]\n\n"
41 "OPTIONS:\n"
42 " --host, -h, (environment variable DMTCP_HOST):\n"
43 " Hostname where dmtcp_coordinator is run (default: localhost)\n"
44 " --port, -p, (environment variable DMTCP_PORT):\n"
45 " Port where dmtcp_coordinator is run (default: 7779)\n"
46 " --quiet:\n"
47 " Skip copyright notice\n\n"
48 "COMMANDS:\n"
49 " s, -s, --status : Print status message\n"
50 " i, -i, --interval <val> : Update checkpoint interval to <val> seconds\n"
51 " c, -c, --checkpoint : Checkpoint all nodes\n"
52 " bc, -bc, --bcheckpoint : Checkpoint all nodes, blocking until done\n"
53 " f, -f, --force : Force restart even with missing nodes (for debugging)\n"
54 " k, -k, --kill : Kill all nodes\n"
55 " q, -q, --quit : Kill all nodes and quit\n\n"
56 "See http://dmtcp.sf.net/ for more information.\n"
57 ;
58
59
60 //shift args
61 #define shift argc--,argv++
62
63 int main ( int argc, char** argv )
64 {
65 bool quiet = false;
66
67 //process args
68 shift;
|
At conditional (1): "true": Taking true branch.
|
69 while(true){
|
At conditional (2): "argc > 0": Taking true branch.
|
70 dmtcp::string s = argc>0 ? argv[0] : "--help";
|
At conditional (3): "std::operator ==<char, std::char_traits<char>, dmtcp::DmtcpAlloc<char> >(s, "--help")": Taking false branch.
|
|
At conditional (4): "std::operator ==<char, std::char_traits<char>, dmtcp::DmtcpAlloc<char> >(s, "-h")": Taking true branch.
|
|
At conditional (5): "argc == 1": Taking false branch.
|
71 if(s=="--help" || s=="-h" && argc==1){
72 fprintf(stderr, theUsage, "");
73 return 1;
|
At conditional (6): "argc > 1": Taking true branch.
|
|
At conditional (7): "std::operator ==<char, std::char_traits<char>, dmtcp::DmtcpAlloc<char> >(s, "-h")": Taking true branch.
|
74 }else if(argc>1 && (s == "-h" || s == "--host")){
|
Event tainted_string: |
Passing tainted string "argv[1]" to a function that cannot accept tainted data. |
| Also see events: |
[tainted_string][tainted_string] |
75 setenv(ENV_VAR_NAME_ADDR, argv[1], 1);
76 shift; shift;
77 }else if(argc>1 && (s == "-p" || s == "--port")){
|
Event tainted_string: |
Passing tainted string "argv[1]" to a function that cannot accept tainted data. |
| Also see events: |
[tainted_string][tainted_string] |
78 setenv(ENV_VAR_NAME_PORT, argv[1], 1);
79 shift; shift;
80 }else if(s == "--quiet"){
81 quiet = true;
82 shift;
83 }else{
84 break;
85 }
86 }
87
88 if (! quiet)
89 printf("DMTCP/MTCP Copyright (C) 2006-2010 Jason Ansel, Michael Rieker,\n"
90 " Kapil Arya, and Gene Cooperman\n"
91 "This program comes with ABSOLUTELY NO WARRANTY.\n"
92 "This is free software, and you are welcome to redistribute it\n"
93 "under certain conditions; see COPYING file for details.\n"
94 "(Use flag \"--quiet\" to hide this message.)\n\n");
95
96 for( ; argc>0; shift){
97 char* cmd = argv[0];
98 //ignore leading dashes
99 while(*cmd == '-') cmd++;
100
101 dmtcp::string s = cmd;
102
103 if(*cmd == 'b' && *(cmd+1) != 'c')
104 *cmd = 'h'; // If blocking ckpt, next letter must be 'c'; else print usage
105
106 if(*cmd == 'h' || *cmd == '\0' || *cmd == '?'){
107 fprintf(stderr, theUsage, "");
108 return 1;
109 }
110
111 int result[DMTCPMESSAGE_NUM_PARAMS];
112 DmtcpCoordinatorAPI coordinatorAPI;
113 if (s == "i" || s == "interval") {
|
Event tainted_string: |
Passing tainted string "argv[1]" to a function that cannot accept tainted data. |
| Also see events: |
[tainted_string][tainted_string] |
114 setenv(ENV_VAR_CKPT_INTR, argv[1], 1);
115 cmd = (char *)s.c_str();
116 coordinatorAPI.connectAndSendUserCommand(*cmd, result);
117 shift;
118 } else if (*cmd == 'b') {
119 // blocking prefix
120 coordinatorAPI.connectAndSendUserCommand(*cmd, result);
121 // actual command
122 coordinatorAPI.connectAndSendUserCommand(*(cmd+1), result);
123 } else {
124 coordinatorAPI.connectAndSendUserCommand(*cmd, result);
125 }
126
127 //check for error
128 if(result[0]<0){
129 switch(result[0]){
130 case DmtcpCoordinator::ERROR_COORDINATOR_NOT_FOUND:
131 fprintf(stderr,
132 "Coordinator not found. Try specifying port with \'--port\'.\n" );
133 break;
134 case DmtcpCoordinator::ERROR_INVALID_COMMAND:
135 fprintf(stderr,
136 "Unknown command: %c, try 'dmtcp_command --help'\n", *cmd);
137 break;
138 case DmtcpCoordinator::ERROR_NOT_RUNNING_STATE:
139 fprintf(stderr, "Error, computation not in running state."
140 " Either a checkpoint is\n"
141 " currently happening or there are no connected processes.\n");
142 break;
143 default:
144 fprintf(stderr, "Unknown error\n");
145 break;
146 }
147 return 2;
148 }
149
150 if(*cmd == 's'){
151 printf("Status...\n");
152 printf("NUM_PEERS=%d\n", result[0]);
153 printf("RUNNING=%s\n", (result[1]?"yes":"no"));
154 }
155
156 }
157
158 return 0;
159 }
160