Project

General

Profile

Revision 0ed3db9d

ID0ed3db9d1611ed04fe99a6b0493ebe82ca81c9b7
Parent 3411817b
Child 2f795968

Added by Thomas Mullins about 10 years ago

Removed pid file necessity

Still uses it if running as root, but otherwise doesn't bother. Should
be a bit easier for local testing.

View differences:

mainbox/main.c
128 128
"          clear   signals a running tooltron to clear its cache\n";
129 129

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

  
......
174 174

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

  
177
    if (create_pid_file())
178
      /* pid file already exists, error */
179
      return 1;
177
    /* if we're not root, don't bother with the pid file */
178
    if (geteuid() == 0) {
179
      as_root = 1;
180
      if (create_pid_file())
181
        /* pid file already exists, error */
182
        return 1;
183
    } else {
184
      as_root = 0;
185
      log_print("Warning: not root. Running without a PID file");
186
    }
180 187

  
181 188
    status = tooltron_main(device, server);
182 189

  
183
    remove_pid_file();
190
    if (as_root)
191
      remove_pid_file();
184 192
    return status;
185 193

  
186 194
  }

Also available in: Unified diff