int main(int argc,char **argv) { int fd; const char *fnok; if (!argv[1]) strerr_die1x(100,"svok: usage: svok dir"); if (chdir(argv[1]) == -1) strerr_die3sys(111,FATAL,"unable to chdir to ",argv[1]); if (!svpath_init()) strerr_die3sys(111,FATAL,"unable to setup control path for ",argv[1]); if ((fnok = svpath_make("/ok")) == 0) strerr_die2sys(111,FATAL,"unable to allocate memory"); fd = open_write(fnok); if (fd == -1) { if (errno == error_noent) _exit(100); if (errno == error_nodevice) _exit(100); strerr_die3sys(111,FATAL,"unable to open ",fnok); } _exit(0); }
void doit(char *dir) { struct stat st; int r; int fd; const char *x; const char *fntemp; char status[40]; buffer_puts(&b,dir); buffer_puts(&b,": "); if (chdir(dir) == -1) { x = error_str(errno); buffer_puts(&b,"unable to chdir: "); buffer_puts(&b,x); return; } if (!svpath_init()) { strerr_warn4(WARNING,"unable to set up control path for ",dir,": ",&strerr_sys); return; } normallyup = 0; if (stat("down",&st) == -1) { if (errno != error_noent) { x = error_str(errno); buffer_puts(&b,"unable to stat down: "); buffer_puts(&b,x); return; } normallyup = 1; } if ((fntemp = svpath_make("/ok")) == 0) die_nomem(); fd = open_write(fntemp); if (fd == -1) { if (errno == error_nodevice) { buffer_puts(&b,"supervise not running"); return; } x = error_str(errno); buffer_puts(&b,"unable to open "); buffer_puts(&b,fntemp); buffer_puts(&b,": "); buffer_puts(&b,x); return; } close(fd); if ((fntemp = svpath_make("/status")) == 0) die_nomem(); fd = open_read(fntemp); if (fd == -1) { x = error_str(errno); buffer_puts(&b,"unable to open "); buffer_puts(&b,fntemp); buffer_puts(&b,": "); buffer_puts(&b,x); return; } r = buffer_unixread(fd,status,sizeof status); close(fd); if (r < 18) { if (r == -1) x = error_str(errno); else x = "bad format"; buffer_puts(&b,"unable to read "); buffer_puts(&b,fntemp); buffer_puts(&b,": "); buffer_puts(&b,x); return; } showstatus(status,r); if (r >= 20+18) { buffer_puts(&b,"\n"); buffer_puts(&b,dir); buffer_puts(&b," log: "); showstatus(status+20,r-20); } }
int main(int argc,const char *const *argv) { int fd; const char *fn; char status[40]; int rd; int opt; int check_log = -1; while ((opt = getopt(argc,argv,"lL")) != opteof) { switch (opt) { case 'L': check_log = 1; break; case 'l': check_log = 0; break; default: die_usage(); } } argv += optind; if (!argv[0]) die_usage(); if (chdir(argv[0]) == -1) strerr_die3sys(111,FATAL,"unable to chdir to ",argv[1]); if (!svpath_init()) strerr_die3sys(111,FATAL,"unable to setup control path for ",argv[1]); if ((fn = svpath_make("/ok")) == 0) strerr_die2sys(111,FATAL,"unable to allocate memory"); fd = open_write(fn); if (fd == -1) { if (errno == error_noent) _exit(100); if (errno == error_nodevice) _exit(100); strerr_die3sys(111,FATAL,"unable to open ",fn); } close(fd); if ((fn = svpath_make("/status")) == 0) strerr_die2sys(111,FATAL,"unable to allocate memory"); fd = open_read(fn); if (fd == -1) { if (errno == error_noent) _exit(100); strerr_die3sys(111,FATAL,"unable to open ",fn); } if ((rd = read(fd,status,sizeof status)) == -1) strerr_die3sys(111,FATAL,"unable to read ",fn); if (rd < 18) strerr_die4(111,FATAL,"bad data in ",fn,": truncated file",0); if (check_log <= 0) if (!checkstatus(status,rd)) _exit(100); if (check_log != 0) { if (rd < 20+18) { if (check_log > 0) _exit(100); } else if (!checkstatus(status+20,rd-20)) _exit(100); } _exit(0); }