# include <ohana.h>

int main (int argc, char **argv) {

  char *filename;
  double timeout;
  int holdtime, state, type, fd;

  if (argc != 4) {
    fprintf (stderr, "USAGE: glock (filename) (type) (holdtime)\n");
    exit (1);
  }

  filename = argv[1];
  timeout = 120.0;

  holdtime = atoi (argv[3]);

  type = 0;
  if (!strcasecmp (argv[2], "hard")) {
    type = LCK_HARD;
  }
  if (!strcasecmp (argv[2], "soft")) {
    type = LCK_SOFT;
  }
  if (!strcasecmp (argv[2], "xcld")) {
    type = LCK_XCLD;
  }

  fd = setlockfile2 (filename, timeout, type, &state);
  if (fd == -1) {
    fprintf (stderr, "ERROR: can't lock file %s\n", filename);
    exit (1);
  }

  sleep (holdtime);
  
  clearlockfile2 (filename, fd, type, &state);

  exit (0);
}
