示例#1
0
文件: file.c 项目: KISSMonX/monit
/**
 * Search the system for the monit control file. Try first ~/.monitrc,
 * if that fails try /etc/monitrc, then SYSCONFDIR/monitrc (default:
 * /usr/local/etc/monitrc) and finally ./monitrc.
 * Exit the application if the control file was not found.
 * @return The location of monits control file (monitrc)
 */
char *File_findControlFile() {

  char *rcfile= xcalloc(sizeof(char), STRLEN + 1);
  
  snprintf(rcfile, STRLEN, "%s/.%s", Run.Env.home, MONITRC);
  if(File_exist(rcfile)) {
    return (rcfile);
  }
  memset(rcfile, 0, STRLEN);
  snprintf(rcfile, STRLEN, "/etc/%s", MONITRC);
  if(File_exist(rcfile)) {
    return (rcfile);
  }
  memset(rcfile, 0, STRLEN);
  snprintf(rcfile, STRLEN, "%s/%s", SYSCONFDIR, MONITRC);
  if(File_exist(rcfile)) {
    return (rcfile);
  }
  memset(rcfile, 0, STRLEN);
  snprintf(rcfile, STRLEN, "/usr/local/etc/%s", MONITRC);
  if(File_exist(rcfile)) {
    return (rcfile);
  }
  if(File_exist(MONITRC)) {
    memset(rcfile, 0, STRLEN);
    snprintf(rcfile, STRLEN, "%s/%s", Run.Env.cwd, MONITRC);
    return (rcfile);
  }
  LogError("%s: Cannot find the control file at "
      "~/.%s, /etc/%s, %s/%s, /usr/local/etc/%s or at ./%s \n",
      prog, MONITRC, MONITRC, SYSCONFDIR, MONITRC, MONITRC, MONITRC);
  exit(1);
  
}
示例#2
0
文件: file.c 项目: Nejuf/monit
char *file_findControlFile() {

        char *rcfile = CALLOC(sizeof(char), STRLEN + 1);

        snprintf(rcfile, STRLEN, "%s/.%s", Run.Env.home, MONITRC);
        if (File_exist(rcfile)) {
                return rcfile;
        }
        snprintf(rcfile, STRLEN, "/etc/%s", MONITRC);
        if (File_exist(rcfile)) {
                return rcfile;
        }
        snprintf(rcfile, STRLEN, "%s/%s", SYSCONFDIR, MONITRC);
        if (File_exist(rcfile)) {
                return rcfile;
        }
        snprintf(rcfile, STRLEN, "/usr/local/etc/%s", MONITRC);
        if (File_exist(rcfile)) {
                return rcfile;
        }
        if (File_exist(MONITRC)) {
                snprintf(rcfile, STRLEN, "%s/%s", Run.Env.cwd, MONITRC);
                return rcfile;
        }
        LogError("Cannot find the control file at ~/.%s, /etc/%s, %s/%s, /usr/local/etc/%s or at ./%s \n", MONITRC, MONITRC, SYSCONFDIR, MONITRC, MONITRC, MONITRC);
        exit(1);

}
示例#3
0
文件: state.c 项目: KISSMonX/monit
/**
 * Check if we should update current services with persistent state
 * information. The logic is as follows: Iff a state file is present
 * *and* older than the running monit daemon's lock file we have had a
 * crash and should update data from the state file.
 * @return TRUE if the state should be updated otherwise FALSE
 */
int State_shouldUpdate() {
  
  if(File_exist(Run.statefile) && File_exist(Run.pidfile)) {
    return (File_getTimestamp(Run.pidfile, S_IFREG) >
	    File_getTimestamp(Run.statefile, S_IFREG));
  }
  
  return FALSE;
  
}
示例#4
0
文件: file.c 项目: KISSMonX/monit
/**
 * Finalize and remove temporary files and make sure Monit id file exist
 */
void File_finalize() {
  unlink(Run.pidfile);
  // Make sure that Monit id file exist
  if (! File_exist(Run.idfile)) {
    FILE *f =  fopen(Run.idfile,"w");
    if (! f) {
      LogError("%s: Error opening Monit id file '%s' for writing -- %s\n", prog, Run.idfile, STRERROR);
    } else {
      fprintf(f, "%s\n", Run.id);
      fclose(f);
    }
  }
}
示例#5
0
T Command_new(const char *path, const char *arg0, ...) {
        T C;
        if (! File_exist(path))
                THROW(AssertException, "File '%s' does not exist", path ? path : "null");
        NEW(C);
        C->env = List_new();
        C->args = List_new();
        List_append(C->env, Str_dup(Command_Path));
        va_list ap;
        va_start(ap, arg0);
        buildArgs(C, path, arg0, ap);
        va_end(ap);
        return C;
}
示例#6
0
T Command_new(const char *path, const char *arg0, ...) {
        T C;
        assert(path);
        if (! File_exist(path))
                THROW(AssertException, "File '%s' does not exist", path);
        NEW(C);
        C->env = List_new();
        C->args = List_new();
        va_list ap;
        va_start(ap, arg0);
        buildArgs(C, path, arg0, ap);
        va_end(ap);
        // Copy this process's environment for transit to sub-processes
        extern char **environ;
        for (char **e = environ; *e; e++) {
                List_append(C->env, Str_dup(*e));
        }
        return C;
}