/**
 * Initialize the game 
 * it create a sub repectory (tmp) and extract the TARFile in parameter on it
 * @param TARfile char*
 */
void init(char* TARFile){
    myExec("rm -rf ./tmp");
    if(mkdir("./tmp",777) == -1){
        printf("Sub-Repertory creation has failed !\n");
    }else{
        myExec("chmod 777 tmp");
        if (debug){printf("init(): Sub-Repertory has been created ! \n");}
        char extract[200];
        sprintf(extract,"tar -vxzf %s -C tmp",TARFile);
        myExec(extract);
    }
}
/**
 * Part of init(char* TARFile) function
 * it reads the meta file and set the meta variable
 * deletes the meta file to avoid cheat
 */
int initMeta(){
    int result=1;
    FILE *file;
    printf("Decoding process...\n");
    myExec("chmod 777 ./decoding");
    if(myExec("./decoding")){
        printf("FATAL : Can't process to the decoding of meta file...\n");
        EXIT_FAILURE;
    }
    //system("./decoding");
    if (file = fopen("./tmp/meta", "r")){
        char line [ 256 ];
        strcpy(meta.command[0],"cd");
        strcpy(meta.command[1],"man");
        strcpy(meta.command[2],"exit");
        strcpy(meta.command[3],"pwd");
        strcpy(meta.command[4],"stat");
        strcpy(meta.command[5], "quit");
        strcpy(meta.command[6], "cat");
        int i=7;
        while ( fgets ( line, sizeof line, file ) != NULL ){
            if (line[0]=='$'){
                if(i<MAX_COMMAND){
                    line[strlen(line)-1] = '\0';
                    strcpy(meta.command[i],line+2);
                }else{
                    printf ("Error. Please use debug mode \n");
                    if (debug){printf("initMeta(): Too many commands allowed");}
                    result=0;
                    break;
                }
                i++;
            }else if (line[0]=='>'){
                strcpy(meta.secret,line+2);
                meta.secret[strlen(meta.secret)-1] = '\0';
            }
        }
        meta.nbCommand=i;
        fclose(file);
    }else{
        printf("Meta File not found. The TAR File is corrupted.\n");
        result=0;
    }
    //Delete the meta file
    unlink("./tmp/meta");
    unlink("./tmp/meta~");
    return result;
}
Beispiel #3
0
  int bridgeList(void *magic, char *line)
  {
    EVMod *mod = (EVMod *)magic;
    HSP_mod_OVS *mdata = (HSP_mod_OVS *)mod->data;
    // we're looking for the lines that have "name : <bridge-name>"
    // or specifically the sequence:
    // name
    // <whitespace>
    // :
    // <whitespace>
    // <bridge-name>
    // sscanf with format string "name%*[\t ]:%*[\t ]%s" works, but
    // assumes that the whitespace is not empty.  I don't think we
    // can necessarily assume that (?)
    char bridgeName[SFVS_MAX_LINELEN];
    if(sscanf(line, "name%*[\t ]:%*[\t ]%s", bridgeName) == 1) {
      // copy the bridge name
      char *br = stripQuotes(bridgeName, SFVS_QUOTES);
      myDebug(1, "bridgeList> %s", br);
      if(br && (br[0] != '\0')) {
	setStr(&mdata->bridge, br);
	// now run a command to check (and possible change) the bridge sFlow setting
	char *bridge_get_sflow_cmd[] = { SFVS_OVS_CMD, "get", "bridge", br, "sflow", NULL };
	char line[SFVS_MAX_LINELEN];
	if(myExec(mod, bridge_get_sflow_cmd, bridgeGetSFlow, line, SFVS_MAX_LINELEN, NULL) == NO) return NO;
      }
    }
    return YES;
  }
Beispiel #4
0
  int runningProcesses_prstat(void) {
#define MAX_PS_LINELEN 256
    char line[MAX_PS_LINELEN];
    char *ps_cmd[] = { "/usr/bin/prstat", "-n1", "0", "1", NULL};
    uint32_t proc_run = 0;
    if(myExec(&proc_run, ps_cmd, read_prstat_line, line, MAX_PS_LINELEN)) {
      return (int)proc_run;
    }
    return -1;
  }
Beispiel #5
0
void DispatchThread::run()
{
  if (qtEventLoop_)
    dispatchObject_ = new DispatchObject(this);

  signalDone();

  if (qtEventLoop_)
    exec();
  else
    myExec();

  delete dispatchObject_;

  signalDone();
}
void DispatchThread::run()
{
    // app_->createQt();
    // qDebug() << "--- DispatchThread run: Thr=" << QThread::currentThread();

    if (_qtEventLoop)
        _dispatchObject = new DispatchObject(this);

    signalDone();

    if (_qtEventLoop)
        exec();
    else
        myExec();

    delete _dispatchObject;

    // app_->destroyQt();

    signalDone();
}
Beispiel #7
0
static int
openImgdisplay()
{
    Imgdisplay_pid = open_pipe_rw(&Imgdisplay_rf, &Imgdisplay_wf);
    if (Imgdisplay_pid < 0)
	goto err0;
    if (Imgdisplay_pid == 0) {
	/* child */
	char *cmd;
	setup_child(FALSE, 2, -1);
	if (!strchr(Imgdisplay, '/'))
	    cmd = Strnew_m_charp(w3m_auxbin_dir(), "/", Imgdisplay, NULL)->ptr;
	else
	    cmd = Imgdisplay;
	myExec(cmd);
	/* XXX: ifdef __EMX__, use start /f ? */
    }
    activeImage = TRUE;
    return TRUE;
  err0:
    Imgdisplay_pid = 0;
    activeImage = FALSE;
    return FALSE;
}
Beispiel #8
0
  static int syncOVS(EVMod *mod)
  {
    HSP_mod_OVS *mdata = (HSP_mod_OVS *)mod->data;
    resetCmd(mod);
    resetExtras(mod);
    char line[SFVS_MAX_LINELEN];

    myDebug(1, "==== ovs-vsctl version ====");
    char *version_cmd[] = { SFVS_OVS_CMD, "--version", NULL};
    // don't abort if this fails: readVersion returns NO as an easy way
    // to only see the first line. (Line number should really be supplied to
    // callback from myExec)
    mdata->ovs10 = NO; // assume newer version
    mdata->usingAtVar = NO;
    myExec((void *)mod, version_cmd, readVersion, line, SFVS_MAX_LINELEN, NULL);
    // adapt if OVS is upgraded under our feet
    if(mdata->ovs10 == NO) mdata->useAtVar = YES;
    if(mdata->config.error
       || mdata->config.num_collectors == 0
       || (mdata->config.sampling_n == 0 && mdata->config.polling_secs == 0)) {
      // no config or no targets or no sampling/polling - clear everything
      myDebug(1, "no config found: clearing all OVS sFlow config");
      setStr(&mdata->sflowUUID, "[]");
      setState(mod, SFVSSTATE_SYNC_DESTROY);
    }
    else {
      // got config - assume here that we're going to create a new
      // sflow object, but if we find one we'll adopt it
      setStr(&mdata->sflowUUID, SFVS_NEW_SFLOW_ID);
      setState(mod, SFVSSTATE_SYNC_SEARCH);
    }
    myDebug(1, "==== list sflow ====");
    char *list_sflow_cmd[] = { SFVS_OVS_CMD, "list", "sflow", NULL };
    if(myExec((void *)mod, list_sflow_cmd, sFlowList, line, SFVS_MAX_LINELEN, NULL) == NO) return NO;

    if(mdata->useAtVar) {
      // we can add the create at the end
    }
    else {
      // create new sFlow object if there were none found (i.e. if
      // the sflowUUID has not changed from the initial setting we
      // gave it.
      if(strcmp(SFVS_NEW_SFLOW_ID, mdata->sflowUUID) == 0) {
	addCreateSFlow(mod);
	logCmd(mod);
	strArrayAdd(mdata->cmd, NULL); // for execve(2)
	if(myExec((void *)mod, strArray(mdata->cmd), submitCreate, line, SFVS_MAX_LINELEN, NULL) == NO) return NO;
	resetCmd(mod);
      }
    }

    // make sure every bridge is using this sFlow entry
    myDebug(1, "==== list bridge ====");
    char *list_bridge_cmd[] = { SFVS_OVS_CMD, "list", "bridge", NULL};
    if(myExec((void *)mod, list_bridge_cmd, bridgeList, line, SFVS_MAX_LINELEN, NULL) == NO) return NO;

    // now it's safe to delete any extras that we found
    for(int ex = strArrayN(mdata->extras); --ex >= 0; ) {
      addDestroySFlow(mod, strArrayAt(mdata->extras, ex));
    }

    if(mdata->useAtVar) {
      // create new sFlow object if there were none found (i.e. if
      // the sflowUUID has not changed from the initial setting we
      // gave it.
      if(strcmp(SFVS_NEW_SFLOW_ID, mdata->sflowUUID) == 0) {
	addCreateSFlow(mod);
      }
    }

    // if we decided to make any changes, submit them now
    mdata->cmdFailed = NO;
    if(strArrayN(mdata->cmd) > 1) {
      logCmd(mod);
      strArrayAdd(mdata->cmd, NULL); // for execve(2)
      if(myExec((void *)mod, strArray(mdata->cmd), submitChanges, line, SFVS_MAX_LINELEN, NULL) == NO) return NO;
      if(mdata->usingAtVar && mdata->cmdFailed == NO) {
        // remember that it worked at least once
        mdata->usedAtVarOK = YES;
      }
    }
    return mdata->cmdFailed ? NO : YES;
  }