Skip to content

Commit

Permalink
Merge pull request #32 from deweerdt/master
Browse files Browse the repository at this point in the history
Issue #28
  • Loading branch information
tj committed Dec 1, 2013
2 parents d8774d3 + d2b9437 commit d3e1942
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/mon.c
Expand Up @@ -13,6 +13,7 @@
#include <fcntl.h>
#include <signal.h>
#include <stdint.h>
#include <stdbool.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/wait.h>
Expand Down Expand Up @@ -48,6 +49,7 @@ typedef struct {
int sleepsec;
int max_attempts;
int attempts;
bool show_status;
} monitor_t;

/*
Expand Down Expand Up @@ -444,9 +446,7 @@ on_mon_pidfile(command_t *self) {
static void
on_status(command_t *self) {
monitor_t *monitor = (monitor_t *) self->data;
if (!monitor->pidfile) error("--pidfile required");
show_status_of(monitor->pidfile);
exit(0);
monitor->show_status = true;
}

/*
Expand Down Expand Up @@ -505,6 +505,7 @@ main(int argc, char **argv){
monitor.attempts = 0;
monitor.last_restart_at = 0;
monitor.clock = 60000;
monitor.show_status = false;

command_t program;
command_init(&program, "mon", VERSION);
Expand All @@ -522,6 +523,12 @@ main(int argc, char **argv){
command_option(&program, "-E", "--on-error <cmd>", "execute <cmd> on error", on_error);
command_parse(&program, argc, argv);

if (monitor.show_status) {
if (!monitor.pidfile) error("--pidfile required");
show_status_of(monitor.pidfile);
exit(0);
}

// command required
if (!program.argc) error("<cmd> required");
const char *cmd = program.argv[0];
Expand Down

0 comments on commit d3e1942

Please sign in to comment.