Exemplo n.º 1
0
Arquivo: tchmgr.c Projeto: kadoma/fms
/* parse arguments of list command */
static int runlist(int argc, char **argv){
  char *path = NULL;
  int omode = 0;
  bool pv = false;
  bool px = false;
  for(int i = 2; i < argc; i++){
    if(argv[i][0] == '-'){
      if(!strcmp(argv[i], "-nl")){
        omode |= HDBONOLCK;
      } else if(!strcmp(argv[i], "-nb")){
        omode |= HDBOLCKNB;
      } else if(!strcmp(argv[i], "-pv")){
        pv = true;
      } else if(!strcmp(argv[i], "-px")){
        px = true;
      } else {
        usage();
      }
    } else if(!path){
      path = argv[i];
    } else {
      usage();
    }
  }
  if(!path) usage();
  int rv = proclist(path, omode, pv, px);
  return rv;
}
Exemplo n.º 2
0
/* parse arguments of list command */
static int32_t runlist(int argc, char** argv) {
    int32_t argbrk = FALSE;
    const char* rstr;
    int32_t rnd, etc, i;
    int64_t rnum;
    rstr = NULL;
    rnd = FALSE;
    etc = FALSE;
    for (i = 2; i < argc; i++) {
        if (!argbrk && argv[i][0] == '-') {
            if (!strcmp(argv[i], "--")) {
                argbrk = TRUE;
            } else if (!strcmp(argv[i], "-rnd")) {
                rnd = TRUE;
            } else if (!strcmp(argv[i], "-etc")) {
                etc = TRUE;
            } else {
                usage();
            }
        } else if (!rstr) {
            argbrk = TRUE;
            rstr = argv[i];
        } else {
            usage();
        }
    }
    if (!rstr) usage();
    rnum = kcatoix(rstr);
    if (rnum < 1) usage();
    return proclist(rnum, rnd, etc);
}
Exemplo n.º 3
0
bool DirectorCore::buildProcessMap(void) noexcept
{
  // search existing processes for those we should be managing (not 100% foolproof)
  process_state_t state;
  std::set<pid_t> pidlist;
  const pid_t thispid = posix::getpid();
  if(proclist(pidlist) == posix::success_response)
  {
    for(pid_t pid : pidlist)
    {
      posix::memset(reinterpret_cast<void*>(&state), 0, sizeof(state));
      if(procstat(pid, state) && // if get process state works AND
         (!state.parent_process_id || state.parent_process_id == thispid)) // process has unknown parent process OR director is the parent process
        for(const std::string& config : getConfigList()) // try each config
          if(getConfigValue(config, "/Process/Executable") == state.executable) // if the executable matches
          {
            m_process_map[config]->add(thispid, pid); // claim this as a managed process
            posix::memset(reinterpret_cast<void*>(&state), 0, sizeof(state)); // wipe process state for safety
            for(pid_t childpid : pidlist)
              if(procstat(childpid, state) && // if get process state works AND
                 state.parent_process_id == pid) // process is a child of this parent pid
                m_process_map[config]->add(pid, childpid); // claim this as a managed process
          }
    }
    return true;
  }
  return false;
}
Exemplo n.º 4
0
/* Returns whether DIRECTORY is acceptable for download, wrt the
   include/exclude lists.

   If FLAGS is ALLABS, the leading `/' is ignored in paths; relative
   and absolute paths may be freely intermixed.  */
int
accdir (const char *directory, enum accd flags)
{
  /* Remove starting '/'.  */
  if (flags & ALLABS && *directory == '/')
    ++directory;
  if (opt.includes)
    {
      if (!proclist (opt.includes, directory, flags))
	return 0;
    }
  if (opt.excludes)
    {
      if (proclist (opt.excludes, directory, flags))
	return 0;
    }
  return 1;
}
Exemplo n.º 5
0
/* parse arguments of list command */
static int runlist(int argc, char **argv) {
    char *path = NULL;
    TCCMP cmp = NULL;
    int omode = 0;
    int max = -1;
    bool pv = false;
    bool px = false;
    bool bk = false;
    char *jstr = NULL;
    char *bstr = NULL;
    char *estr = NULL;
    char *fmstr = NULL;
    for (int i = 2; i < argc; i++) {
        if (!path && argv[i][0] == '-') {
            if (!strcmp(argv[i], "-cd")) {
                cmp = tccmpdecimal;
            } else if (!strcmp(argv[i], "-ci")) {
                cmp = tccmpint32;
            } else if (!strcmp(argv[i], "-cj")) {
                cmp = tccmpint64;
            } else if (!strcmp(argv[i], "-nl")) {
                omode |= BDBONOLCK;
            } else if (!strcmp(argv[i], "-nb")) {
                omode |= BDBOLCKNB;
            } else if (!strcmp(argv[i], "-m")) {
                if (++i >= argc) usage();
                max = tcatoix(argv[i]);
            } else if (!strcmp(argv[i], "-bk")) {
                bk = true;
            } else if (!strcmp(argv[i], "-pv")) {
                pv = true;
            } else if (!strcmp(argv[i], "-px")) {
                px = true;
            } else if (!strcmp(argv[i], "-j")) {
                if (++i >= argc) usage();
                jstr = argv[i];
            } else if (!strcmp(argv[i], "-rb")) {
                if (++i >= argc) usage();
                bstr = argv[i];
                if (++i >= argc) usage();
                estr = argv[i];
            } else if (!strcmp(argv[i], "-fm")) {
                if (++i >= argc) usage();
                fmstr = argv[i];
            } else {
                usage();
            }
        } else if (!path) {
            path = argv[i];
        } else {
            usage();
        }
    }
    if (!path) usage();
    int rv = proclist(path, cmp, omode, max, pv, px, bk, jstr, bstr, estr, fmstr);
    return rv;
}
Exemplo n.º 6
0
/* parse arguments of list command */
static int runlist(int argc, char **argv){
  char *path = NULL;
  int omode = 0;
  int max = -1;
  bool pv = false;
  bool px = false;
  char *rlstr = NULL;
  char *rustr = NULL;
  char *ristr = NULL;
  for(int i = 2; i < argc; i++){
    if(!path && argv[i][0] == '-'){
      if(!strcmp(argv[i], "-nl")){
        omode |= FDBONOLCK;
      } else if(!strcmp(argv[i], "-nb")){
        omode |= FDBOLCKNB;
      } else if(!strcmp(argv[i], "-m")){
        if(++i >= argc) usage();
        max = tcatoix(argv[i]);
      } else if(!strcmp(argv[i], "-pv")){
        pv = true;
      } else if(!strcmp(argv[i], "-px")){
        px = true;
      } else if(!strcmp(argv[i], "-rb")){
        if(++i >= argc) usage();
        rlstr = argv[i];
        if(++i >= argc) usage();
        rustr = argv[i];
      } else if(!strcmp(argv[i], "-ri")){
        if(++i >= argc) usage();
        ristr = argv[i];
      } else {
        usage();
      }
    } else if(!path){
      path = argv[i];
    } else {
      usage();
    }
  }
  if(!path) usage();
  int rv = proclist(path, omode, max, pv, px, rlstr, rustr, ristr);
  return rv;
}
Exemplo n.º 7
0
/* parse arguments of list command */
static int runlist(int argc, char **argv){
  char *name = NULL;
  int sep = -1;
  int max = -1;
  bool pv = false;
  bool px = false;
  char *fmstr = NULL;
  for(int i = 2; i < argc; i++){
    if(!name && argv[i][0] == '-'){
      if(!strcmp(argv[i], "-sep")){
        if(++i >= argc) usage();
        sep = sepstrtochr(argv[i]);
      } else if(!strcmp(argv[i], "-m")){
        if(++i >= argc) usage();
        max = tcatoix(argv[i]);
      } else if(!strcmp(argv[i], "-pv")){
        pv = true;
      } else if(!strcmp(argv[i], "-px")){
        px = true;
      } else if(!strcmp(argv[i], "-fm")){
        if(++i >= argc) usage();
        fmstr = argv[i];
      } else {
        usage();
      }
    } else if(!name){
      name = argv[i];
    } else {
      usage();
    }
  }
  if(!name) usage();
  name = tcsprintf("%s#mode=r", name);
  int rv = proclist(name, sep, max, pv, px, fmstr);
  tcfree(name);
  return rv;
}