Project

General

Profile

Revision 13fd9e7e

ID13fd9e7efe3c7d7ae6631d672e5a391535e59c95
Parent 4f824e14
Child ddd50354

Added by Thomas Mullins over 5 years ago

Added stop command and fixed pid file deletion

View differences:

mainbox/main.c
98 98
    usleep(SLEEP_MS * (useconds_t)1000);
99 99
    i = (i+1) % N_TOOLS;
100 100
  }
101
  log_print("Recieved SIGINT or SIGTERM, shutting down");
101 102

  
102 103
  log_print("Disabling tools");
103 104
  for (i = 0; i < N_TOOLS; i++) {
......
122 123
"          defaults to roboticsclub.org\n"
123 124
"       <cmd> can be any of the following:\n"
124 125
"          run     runs tooltron if it is not already running\n"
125
"          refresh signals an already running tooltron to refresh its cache\n"
126
"          clear   signals an already running tooltron to clear its cache\n";
126
"          stop    signals a running tooltron to shut down\n"
127
"          refresh signals a running tooltron to refresh its cache\n"
128
"          clear   signals a running tooltron to clear its cache\n";
127 129

  
128 130
int main(int argc, char **argv) {
129
  int opt;
131
  int opt, status;
130 132
  const char *device = "/dev/ttyUSB0";
131 133
  const char *server = "roboticsclub.org";
132 134

  
......
156 158
  }
157 159

  
158 160
  if (strcmp(argv[optind], "refresh") == 0) {
161

  
159 162
    send_signal(SIGUSR1);
160 163
    return 0;
164

  
161 165
  } else if (strcmp(argv[optind], "clear") == 0) {
166

  
162 167
    send_signal(SIGUSR2);
163 168
    return 0;
164
  } else if (strcmp(argv[optind], "run") != 0) {
165
    /* <cmd> is not "refresh", "clear", or "run", error */
166
    printf(usage, argv[0]);
167
    return 1;
168
  }
169 169

  
170
  if (create_pid_file())
171
    /* pid file already exists, error */
172
    return 1;
170
  } else if (strcmp(argv[optind], "stop") == 0) {
171

  
172
    send_signal(SIGTERM);
173
    return 0;
174

  
175
  } else if (strcmp(argv[optind], "run") == 0) {
176

  
177
    if (create_pid_file())
178
      /* pid file already exists, error */
179
      return 1;
180

  
181
    status = tooltron_main(device, server);
182

  
183
    remove_pid_file();
184
    return status;
185

  
186
  }
173 187

  
174
  return tooltron_main(device, server);
188
  printf("Unknown command \"%s\"\n", argv[optind]);
189
  printf(usage, argv[0]);
190
  return 1;
175 191
}

Also available in: Unified diff