Esempio n. 1
0
void
init_messages(void)
{
    char	*cmd;
    MESG *	md;

    (void) signal(SIGPIPE, SIG_IGN);

    calculate_nopen ();

    Message = (char *)Malloc(MSGMAX);

    (void) Chmod(Lp_Tmp, 0711);
    
    if ((md = mcreate(Lp_FIFO)) == NULL)
	fail ("Can't create public message device (%s).\n", PERROR);
    mon_discon(md, conn_shutdown);
    
    if (mlisteninit(md) != 0)
	if (errno == ENOMEM)
	    mallocfail();
	else
	    fail ("Unexpected streams error (%s).\n" , PERROR);

    (void) Chmod(Lp_FIFO, 0666);
    return;
}
Esempio n. 2
0
void
shutdown_messages(void)
{
    MESG	*md;
    
    (void) Chmod(Lp_Tmp, 0700);
    (void) Chmod(Lp_FIFO, 0600);
    md = mlistenreset();
    mdestroy(md);
}
Esempio n. 3
0
int CFileZillaEngine::Execute(const CCommand &command)
{
	if (command.GetId() != Command::cancel && IsBusy())
		return FZ_REPLY_BUSY;

	m_bIsInCommand = true;

	int res = FZ_REPLY_INTERNALERROR;
	switch (command.GetId())
	{
	case Command::connect:
		res = Connect(reinterpret_cast<const CConnectCommand &>(command));
		break;
	case Command::disconnect:
		res = Disconnect(reinterpret_cast<const CDisconnectCommand &>(command));
		break;
	case Command::cancel:
		res = Cancel(reinterpret_cast<const CCancelCommand &>(command));
		break;
	case Command::list:
		res = List(reinterpret_cast<const CListCommand &>(command));
		break;
	case Command::transfer:
		res = FileTransfer(reinterpret_cast<const CFileTransferCommand &>(command));
		break;
	case Command::raw:
		res = RawCommand(reinterpret_cast<const CRawCommand&>(command));
		break;
	case Command::del:
		res = Delete(reinterpret_cast<const CDeleteCommand&>(command));
		break;
	case Command::removedir:
		res = RemoveDir(reinterpret_cast<const CRemoveDirCommand&>(command));
		break;
	case Command::mkdir:
		res = Mkdir(reinterpret_cast<const CMkdirCommand&>(command));
		break;
	case Command::rename:
		res = Rename(reinterpret_cast<const CRenameCommand&>(command));
		break;
	case Command::chmod:
		res = Chmod(reinterpret_cast<const CChmodCommand&>(command));
		break;
	default:
		return FZ_REPLY_SYNTAXERROR;
	}

	if (res != FZ_REPLY_WOULDBLOCK)
		ResetOperation(res);

	m_bIsInCommand = false;

	if (command.GetId() != Command::disconnect)
		res |= m_nControlSocketError;
	else if (res & FZ_REPLY_DISCONNECTED)
		res = FZ_REPLY_OK;
	m_nControlSocketError = 0;

	return res;
}
Esempio n. 4
0
/* applies to fd all options belonging to phase */
int applyopts_named(const char *filename, struct opt *opts, unsigned int phase) {
   struct opt *opt;

   if (!opts)  return 0;

   opt = opts; while (opt->desc != ODESC_END) {
      if (opt->desc == ODESC_DONE ||
	  opt->desc->phase != phase && phase != PH_ALL ||
	  !(opt->desc->group & GROUP_NAMED)) {
	 ++opt; continue; }
      switch (opt->desc->optcode) {
      case OPT_GROUP_EARLY:
      case OPT_GROUP:
	 if (Chown(filename, -1, opt->value.u_gidt) < 0) {
	    Error3("chown(\"%s\", -1, "F_gid"): %s", filename,
		   opt->value.u_gidt, strerror(errno));
	 }
	 break;
      case OPT_USER_EARLY:
      case OPT_USER:
	 if (Chown(filename, opt->value.u_uidt, -1) < 0) {
	    Error3("chown(\"%s\", "F_uid", -1): %s", filename,
		   opt->value.u_uidt, strerror(errno));
	 }
	 break;
      case OPT_PERM_EARLY:
      case OPT_PERM:
	 if (Chmod(filename, opt->value.u_modet) < 0) {
	    Error3("chmod(\"%s\", "F_mode"): %s",
		   filename, opt->value.u_modet, strerror(errno));
	 }
	 break;
      case OPT_UNLINK_EARLY:
      case OPT_UNLINK:
      case OPT_UNLINK_LATE:
	 if (Unlink(filename) < 0) {
	    if (errno == ENOENT) {
	       Warn2("unlink(\"%s\"): %s", filename, strerror(errno));
	    } else {
	       Error2("unlink(\"%s\"): %s", filename, strerror(errno));
	    }
	 }
	 break;
      case OPT_UMASK:
	 if (Umask(opt->value.u_modet) < 0) {
	    /* linux docu says it always succeeds, but who believes it? */
	    Error2("umask("F_mode"): %s", opt->value.u_modet, strerror(errno));
	 }
	 break;
      default: Error1("applyopts_named(): option \"%s\" not implemented",
		      opt->desc->defname);
	 break;
      }
      opt->desc = ODESC_DONE;
      ++opt;
   }
   return 0;
}
Esempio n. 5
0
int CFileZillaApi::Command(t_command *pCommand)
{
	//Check if call allowed
	if (!m_bInitialized)
		return FZ_REPLY_NOTINITIALIZED;

	//Dispatch command to command specific functions
	switch(pCommand->id)
	{
	case FZ_COMMAND_LIST:
		if (pCommand->param1!=_MPT(""))
			return List(pCommand->path,pCommand->param1,pCommand->param4);
		else if (!pCommand->path.IsEmpty())
			return List(pCommand->path,pCommand->param4);
		else
			return List(pCommand->param4);
		break;
	case FZ_COMMAND_CONNECT:
		return Connect(pCommand->server);
		break;
	case FZ_COMMAND_DISCONNECT:
		return Disconnect();
		break;
	case FZ_COMMAND_FILETRANSFER:
		return FileTransfer(pCommand->transferfile);
		break;
	case FZ_COMMAND_DELETE:
		return Delete(pCommand->param1, pCommand->path);
		break;
	case FZ_COMMAND_REMOVEDIR:
		return RemoveDir(pCommand->param1, pCommand->path);
		break;
	case FZ_COMMAND_MAKEDIR:
		return MakeDir(pCommand->path);
		break;
	case FZ_COMMAND_RENAME:
		return Rename(pCommand->param1, pCommand->param2, pCommand->path, pCommand->newPath);
		break;
	case FZ_COMMAND_CUSTOMCOMMAND:
		return CustomCommand(pCommand->param1);
		break;
	case FZ_COMMAND_CHMOD:
		return Chmod(pCommand->param4, pCommand->param1, pCommand->path);
		break;
	}
	return FZ_REPLY_INVALIDPARAM;
}
Esempio n. 6
0
bool NoFile::Copy(const NoString& sOldFileName, const NoString& sNewFileName, bool bOverwrite)
{
    if ((!bOverwrite) && (NoFile::Exists(sNewFileName))) {
        errno = EEXIST;
        return false;
    }

    NoFile OldFile(sOldFileName);
    NoFile NewFile(sNewFileName);

    if (!OldFile.Open()) {
        return false;
    }

    if (!NewFile.Open(O_WRONLY | O_CREAT | O_TRUNC)) {
        return false;
    }

    char szBuf[8192];
    ssize_t len = 0;

    while ((len = OldFile.Read(szBuf, 8192))) {
        if (len < 0) {
            NO_DEBUG("NoFile::Copy() failed: " << strerror(errno));
            OldFile.Close();

            // That file is only a partial copy, get rid of it
            NewFile.Close();
            NewFile.Delete();

            return false;
        }
        NewFile.Write(szBuf, len);
    }

    OldFile.Close();
    NewFile.Close();

    struct stat st;
    GetInfo(sOldFileName, st);
    Chmod(sNewFileName, st.st_mode);

    return true;
}
Esempio n. 7
0
/**
 * Open: HDFS does not support certain modes of operation.  For example,
 * you can read or write, but not both.  So O_RDONLY or O_WRONLY.   Some
 * versions of HDFS support O_WRONLY|O_APPEND, but rumor has it that it is
 * flaky.
 *
 * @param bpath the path we are creating
 * @param flags read/write mode
 * @param mode desired permissions
 * @param ret_hand return class pointer to IOSHandle for the new file or null on error
 * @return PLFS_SUCCESS or PLFS_E* on error
 */
plfs_error_t
HDFSIOStore::Open(const char *bpath, int flags, mode_t mode, IOSHandle **ret_hand) {
    plfs_error_t rv;
    int new_flags;
    hdfsFile openFile;
    HDFSIOSHandle *hand;

    do_hdfs_check_alt(this,*ret_hand);
    rv = PLFS_SUCCESS;

    if (flags == O_RDONLY) {
        new_flags = O_RDONLY;
    } else if (flags & O_WRONLY)  {
        new_flags = O_WRONLY;
    } else if (flags & O_RDWR) {
        if (!hdfsExists_wrap(this->hfs, bpath)) {
            /* If the file exists, open Read Only! */
            new_flags = O_RDONLY;
        } else {
            new_flags = O_WRONLY;
        }
    } else {
        *ret_hand = NULL;
        return PLFS_ENOTSUP;
    }

    openFile = hdfsOpenFile_retry(this->hfs, bpath, new_flags, 0, 0, 0);
    if (!openFile) {
        *ret_hand = NULL;
        return get_err(-1);
    }

    hand = new HDFSIOSHandle(this, this->hfs, openFile, bpath);
    if (hand == NULL) {
        rv = PLFS_ENOMEM;
        hdfsCloseFile_wrap(this->hfs, openFile);
    }

    Chmod(bpath, mode);  /* ignoring errors.... */
    
    *ret_hand = hand;
    return rv;
}
Esempio n. 8
0
void test35c()
{
  gid_t gid, gid2;
  uid_t uid, uid2;
  struct utimbuf ub;
  int fd, does_truncate, stat_loc;

  subtest = 3;

  /* Access problems. */
  Mkdir("bar");
  Creat("bar/tryme");
  if (superuser) {
	Chmod("bar", 0000);	/* No search permisson at all. */
	if (utime("bar/tryme", NULL) != 0) e(1);
  }
  if (!superuser) {
	Chmod("bar", 0677);	/* No search permisson. */
	if (utime("bar/tryme", NULL) != -1) e(2);
	if (errno != EACCES) e(3);
  }
  Chmod("bar", 0777);

  if (I_can_chown) {
	switch (fork()) {
	    case -1:	printf("Can't fork\n");	break;
	    case 0:
		alarm(20);

		/* Get two differend non root uids. */
		if (superuser) {
			getids(&uid, &gid);
			if (uid == 0) getids(&uid, &gid);
			if (uid == 0) e(4);
		}
		if (!superuser) {
			uid = geteuid();
			gid = getegid();
		}
		getids(&uid2, &gid);
		if (uid == uid2) getids(&uid2, &gid2);
		if (uid == uid2) e(5);

		/* Creat a number of files for root, user and user2. */
		Creat("rootfile");	/* Owned by root. */
		Chmod("rootfile", 0600);
		Chown("rootfile", 0, 0);
		Creat("user2file");	/* Owned by user 2, writeable. */
		Chmod("user2file", 0020);
		Chown("user2file", uid2, gid);
		Creat("user2private");	/* Owned by user 2, privately. */
		Chmod("user2private", 0600);
		Chown("user2private", uid2, gid);

		if (superuser) {
			setgid(gid);
			setuid(uid);
		}

		/* We now are user ``uid'' from group ``gid''. */
		ub.actime = (time_t) 12345L;
		ub.modtime = (time_t) 12345L;

		if (utime("rootfile", NULL) != -1) e(6);
		if (errno != EACCES) e(7);
		if (utime("rootfile", &ub) != -1) e(8);
		if (errno != EPERM) e(9);

		if (utime("user2file", NULL) != 0) e(10);
		if (utime("user2file", &ub) != -1) e(11);
		if (errno != EPERM) e(12);

		if (utime("user2private", NULL) != -1) e(13);
		if (errno != EACCES) e(14);
		if (utime("user2private", &ub) != -1) e(15);
		if (errno != EPERM) e(16);

		exit(errct ? 1 : 0);
	    default:
		wait(&stat_loc);
		if (stat_loc != 0) e(17);	/* Alarm? */
	}
  }

  /* Test names that are too long. */
  does_truncate = does_fs_truncate();
  fd = creat(NameTooLong, 0777);
  if (does_truncate) {
	if (utime(NameTooLong, NULL) != 0) e(18);
  } else {
	if (utime(NameTooLong, NULL) != -1) e(19);
	if (errno != ENAMETOOLONG) e(20);
  }
  (void) close(fd);

  /* Make PathTooLong contain ././.../a */
  PathTooLong[strlen(PathTooLong) - 2] = '/';
  PathTooLong[strlen(PathTooLong) - 1] = 'a';
  Creat("a");
  if (utime(PathTooLong, NULL) != -1) e(21);
  if (errno != ENAMETOOLONG) e(22);

  /* Non existing file name. */
  if (utime("nonexist", NULL) != -1) e(23);
  if (errno != ENOENT) e(24);

  /* Empty file name. */
  if (utime("", NULL) != -1) e(25);
  if (errno != ENOENT) e(26);

  System("rm -rf ../DIR_35/*");
}
Esempio n. 9
0
void test33c()
{				/* Test errors returned. */
  int i, fd, does_truncate;

  subtest = 3;
  System("rm -rf ../DIR_33/*");

  /* Test what access() does with non existing files. */
  System("rm -rf nonexist");
  if (access("noexist", F_OK) != -1) e(1);
  if (errno != ENOENT) e(2);
  if (access("noexist", R_OK) != -1) e(3);
  if (errno != ENOENT) e(4);
  if (access("noexist", W_OK) != -1) e(5);
  if (errno != ENOENT) e(6);
  if (access("noexist", X_OK) != -1) e(7);
  if (errno != ENOENT) e(8);
  if (access("noexist", R_OK | W_OK) != -1) e(9);
  if (errno != ENOENT) e(10);
  if (access("noexist", R_OK | X_OK) != -1) e(11);
  if (errno != ENOENT) e(12);
  if (access("noexist", W_OK | X_OK) != -1) e(13);
  if (errno != ENOENT) e(14);
  if (access("noexist", R_OK | W_OK | X_OK) != -1) e(15);
  if (errno != ENOENT) e(16);

  /* Test access on a nonsearchable path. */
  if (mkdir("nosearch", 0777) != 0) e(1000);
  if ( (i = creat("nosearch/file", 0666)) < 0) e(1001);
  if (close(i) < 0) e(1002);
  if ( (i = creat("file", 0666) < 0)) e(1003);
  if (close(i) < 0) e(1004);
  if (chmod("nosearch/file", 05777) < 0) e(1005);
  if (chmod("file", 05777) < 0) e(1006);
  if (chmod("nosearch", 0677) != 0) e(1007);
  if (access("nosearch/file", F_OK) != 0) e(17);

  /* Test ToLongName and ToLongPath */
  does_truncate = does_fs_truncate();
  if (does_truncate) {
  	if ((fd = creat(ToLongName, 0777)) != 0) e(18);
  	if (close(fd) != 0) e(19);
	if (access(ToLongName, F_OK) != 0) e(20);
  } else {
  	if ((fd = creat(ToLongName, 0777)) != -1) e(21);
	if (errno != ENAMETOOLONG) e(22);
  	(void) close(fd);	/* Just in case */
	if (access(ToLongName, F_OK) != -1) e(23);
	if (errno != ENAMETOOLONG) e(24);
  }

  ToLongPath[PATH_MAX - 2] = '/';
  ToLongPath[PATH_MAX - 1] = 'a';
  if (access(ToLongPath, F_OK) != -1) e(27);
  if (errno != ENAMETOOLONG) e(28);
  ToLongPath[PATH_MAX - 1] = '/';

  /* Test empty strings. */
  if (access("", F_OK) != -1) e(29);
  if (errno != ENOENT) e(30);
  System("rm -rf idonotexist");
  if (access("idonotexist", F_OK) != -1) e(31);
  if (errno != ENOENT) e(32);

  /* Test non directorys in prefix of path. */
  if (access("/etc/passwd/dir/foo", F_OK) != -1) e(33);
  if (errno != ENOTDIR) e(34);
  System("rm -rf nodir; > nodir");
  if (access("nodir/foo", F_OK) != -1) e(35);
  if (errno != ENOTDIR) e(36);

  /* Test if invalid amode arguments are signaled. */
  System("> allmod");
  Chmod("allmod", 05777);
  for (i = -1025; i < 1025; i++) {
	if ((mode_t) i != F_OK && ((mode_t) i & ~(R_OK | W_OK | X_OK)) != 0) {
		if (access("allmod", (mode_t) i) != -1) e(37);
		if (errno != EINVAL) e(38);
	} else 
		if (access("allmod", (mode_t) i) != 0) e(39);
  }
}
Esempio n. 10
0
void test33b()
{
  int stat_loc;			/* For the wait(&stat_loc) call. */

  subtest = 2;
  System("rm -rf ../DIR_33/*");

  switch (fork()) {
      case -1:	printf("Can't fork\n");	break;
      case 0:
	alarm(20);

	/* (Re)set the effective ids to the real ids. */
	setuid(getuid());
	setgid(getgid());
	System("> ______rwx; chmod 007 ______rwx");
	System("> ________x; chmod 001 ________x");
	System("> _________; chmod 000 _________");
	exit(0);

      default:
	wait(&stat_loc);
	if (stat_loc != 0) e(1);/* Alarm? */
  }

  /* If we are superuser, we have access to all. */
  /* Well, almost, execution access might need at least one X bit. */
  if (superuser) {
	if (access("_________", R_OK) != 0) e(2);
	if (access("_________", W_OK) != 0) e(3);
	if (access("________x", R_OK) != 0) e(4);
	if (access("________x", W_OK) != 0) e(5);
	if (access("________x", X_OK) != 0) e(6);
	if (access("______rwx", R_OK) != 0) e(7);
	if (access("______rwx", W_OK) != 0) e(8);
	if (access("______rwx", X_OK) != 0) e(9);
  }
  if (!superuser) {
	if (access("_________", R_OK) != -1) e(10);
	if (errno != EACCES) e(11);
	if (access("_________", W_OK) != -1) e(12);
	if (errno != EACCES) e(13);
	if (access("_________", X_OK) != -1) e(14);
	if (errno != EACCES) e(15);
	if (access("________x", R_OK) != -1) e(16);
	if (errno != EACCES) e(17);
	if (access("________x", W_OK) != -1) e(18);
	if (errno != EACCES) e(19);
	if (access("________x", X_OK) != -1) e(20);
	if (errno != EACCES) e(21);
	if (access("______rwx", R_OK) != -1) e(22);
	if (errno != EACCES) e(23);
	if (access("______rwx", W_OK) != -1) e(24);
	if (errno != EACCES) e(25);
	if (access("______rwx", X_OK) != -1) e(26);
	if (errno != EACCES) e(27);
  }

  /* If the real uid != effective uid. */
  if (!superuser) {
	System("rm -rf [_r][_w][_x]");
	System("> rwx");
	Chmod("rwx", 0700);
	System("> rw_");
	Chmod("rw_", 0600);
	System("> r_x");
	Chmod("r_x", 0500);
	System("> r__");
	Chmod("r__", 0400);
	System("> _wx");
	Chmod("_wx", 0300);
	System("> _w_");
	Chmod("_w_", 0200);
	System("> __x");
	Chmod("__x", 0100);
	System("> ___");
	Chmod("___", 0000);

	if (access("rwx", F_OK) != 0) e(28);
	if (access("rwx", R_OK) != -1) e(29);
	if (errno != EACCES) e(30);
	if (access("rwx", W_OK) != -1) e(31);
	if (errno != EACCES) e(32);
	if (access("rwx", X_OK) != -1) e(33);
	if (errno != EACCES) e(34);

	if (access("rw_", F_OK) != 0) e(35);
	if (access("rw_", R_OK) != -1) e(36);
	if (errno != EACCES) e(37);
	if (access("rw_", W_OK) != -1) e(38);
	if (errno != EACCES) e(39);
	if (access("rw_", X_OK) != -1) e(40);
	if (errno != EACCES) e(41);

	if (access("r_x", F_OK) != 0) e(42);
	if (access("r_x", R_OK) != -1) e(43);
	if (errno != EACCES) e(44);
	if (access("r_x", W_OK) != -1) e(45);
	if (errno != EACCES) e(46);
	if (access("r_x", X_OK) != -1) e(47);
	if (errno != EACCES) e(48);

	if (access("r__", F_OK) != 0) e(49);
	if (access("r__", R_OK) != -1) e(50);
	if (errno != EACCES) e(51);
	if (access("r__", W_OK) != -1) e(52);
	if (errno != EACCES) e(53);
	if (access("r__", X_OK) != -1) e(54);
	if (errno != EACCES) e(55);

	if (access("_wx", F_OK) != 0) e(56);
	if (access("_wx", R_OK) != -1) e(57);
	if (errno != EACCES) e(58);
	if (access("_wx", W_OK) != -1) e(59);
	if (errno != EACCES) e(60);
	if (access("_wx", X_OK) != -1) e(61);
	if (errno != EACCES) e(62);

	if (access("_w_", F_OK) != 0) e(63);
	if (access("_w_", R_OK) != -1) e(64);
	if (errno != EACCES) e(65);
	if (access("_w_", W_OK) != -1) e(66);
	if (errno != EACCES) e(67);
	if (access("_w_", X_OK) != -1) e(68);
	if (errno != EACCES) e(69);

	if (access("__x", F_OK) != 0) e(70);
	if (access("__x", R_OK) != -1) e(71);
	if (errno != EACCES) e(72);
	if (access("__x", W_OK) != -1) e(73);
	if (errno != EACCES) e(74);
	if (access("__x", X_OK) != -1) e(75);
	if (errno != EACCES) e(76);

	if (access("___", F_OK) != 0) e(77);
	if (access("___", R_OK) != -1) e(78);
	if (errno != EACCES) e(79);
	if (access("___", W_OK) != -1) e(80);
	if (errno != EACCES) e(81);
	if (access("___", X_OK) != -1) e(82);
	if (errno != EACCES) e(83);

	System("rm -rf [_r][_w][_x]");
  }
}
Esempio n. 11
0
TVerdict CTestSyscalls::doTestStepL()
	{
	int err;
	if(TestStepName() == KCreat)
   		{
   		INFO_PRINTF1(_L("Creat():"));
   		err = Creat();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kopen1)
		{
		INFO_PRINTF1(_L("open1():"));
		err = open1();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
   	   	
	else if(TestStepName() == Kopen2)
		{
		INFO_PRINTF1(_L("open2():"));
		err = open2();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopen3)
		{
		INFO_PRINTF1(_L("open3():"));
		err = open3();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopen4)
		{
		INFO_PRINTF1(_L("open4():"));
		err = open4();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopen5)
		{
		INFO_PRINTF1(_L("open5():"));
		err = open5();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopen6)
		{
		INFO_PRINTF1(_L("open6():"));
		err = open6();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KOpenTruncate1)
		{
		INFO_PRINTF1(_L("OpenTruncate1:"));
		err = OpenTruncate1();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KOpenTruncate2)
		{
		INFO_PRINTF1(_L("OpenTruncate2:"));
		err = OpenTruncate2();
		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopen7)
   		{
   		INFO_PRINTF1(_L("open7():"));
   		err = open7();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KOpenInAppendMode)
   		{
   		INFO_PRINTF1(_L("OpenInAppendMode():"));
   		err = OpenInAppendMode();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kwrite1)
		{
   		INFO_PRINTF1(_L("write1():"));
		err = write1();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kwrite2)
   		{
   		INFO_PRINTF1(_L("write2():"));
   		err = write2();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kwrite3)
   		{
   		INFO_PRINTF1(_L("write3():"));
   		err = write3();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kwrite5)
		{
   		INFO_PRINTF1(_L("write5():"));
   		err = write5();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kread1)
   		{
   		INFO_PRINTF1(_L("read1():"));
   		err = read1();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kread2)
   		{
		INFO_PRINTF1(_L("read2():"));
   		err = read2();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kread3)
   		{
		INFO_PRINTF1(_L("read3():"));
   		err = read3();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == Kread4)
		{
		INFO_PRINTF1(_L("read4():"));
		err = read4();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
	else if(TestStepName() == KOpendir)
   		{
   	   	INFO_PRINTF1(_L("Opendir():"));
   	   	err = Opendir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KClosedir)
   		{
   	   	INFO_PRINTF1(_L("Closedir():"));
   	   	err = Closedir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KReaddir)
   		{
   	   	INFO_PRINTF1(_L("Readdir():"));
   	   	err = Readdir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KLseek)
   		{
   	   	INFO_PRINTF1(_L("Lseek():"));
   	   	err = Lseek();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KLseek1)
   		{
   	   	INFO_PRINTF1(_L("Lseek1():"));
   	   	err = Lseek1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
    else if(TestStepName() == KAccess)
   		{
   	   	INFO_PRINTF1(_L("Access():"));
   	   	err = Access();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KAccess1)
   		{
   	   	INFO_PRINTF1(_L("Access1():"));
   	   	err = Access1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KDup)
   		{
   	   	INFO_PRINTF1(_L("Dup():"));
   	   	err = Dup();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KDup2)
   		{
   	   	INFO_PRINTF1(_L("Dup2():"));
   	   	err = Dup2();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRename)
   		{
   	   	INFO_PRINTF1(_L("Rename():"));
   	   	err = Rename();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRename1)
   		{
   	   	INFO_PRINTF1(_L("Rename1():"));
   	   	err = Rename1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KChmod)
   		{
   	   	INFO_PRINTF1(_L("Chmod():"));
   	   	err = Chmod();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KChmod1)
   		{
   	   	INFO_PRINTF1(_L("Chmod1():"));
   	   	err = Chmod1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
    else if(TestStepName() == KChmod_dir)
   		{
   	   	INFO_PRINTF1(_L("Chmod_dir():"));
   	   	err = Chmod_dir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KFChmod)
   		{
   	   	INFO_PRINTF1(_L("FChmod():"));
   	   	err = FChmod();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KFChmod_dir)
   		{
   	   	INFO_PRINTF1(_L("FChmod_dir():"));
   	   	err = FChmod_dir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KExit)
   		{
   	   	INFO_PRINTF1(_L("Exit():"));
   	   	err = Exit();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KClose)
   		{
   	   	INFO_PRINTF1(_L("Close():"));
   	   	err = Close();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KMkdir)
   		{
   	   	INFO_PRINTF1(_L("Mkdir():"));
   	   	err = Mkdir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KMk_dir)
   		{
   	   	INFO_PRINTF1(_L("Mk_dir():"));
   	   	err = Mk_dir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KRmdir)
   		{
   	   	INFO_PRINTF1(_L("Rmdir():"));
   	   	err = Rmdir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KRm_dir)
   		{
   	   	INFO_PRINTF1(_L("Rm_dir():"));
   	   	err = Rm_dir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
    else if(TestStepName() == KRmdir1)
   		{
   	   	INFO_PRINTF1(_L("Rmdir1():"));
   	   	err = Rmdir1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRmdir_Chdir)
   		{
   	   	INFO_PRINTF1(_L("Rmdir_Chdir():"));
   	   	err = Rmdir_Chdir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KFsync)
   		{
   	   	INFO_PRINTF1(_L("Fsync():"));
   	   	err = Fsync();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KUtimes)
   		{
   	   	INFO_PRINTF1(_L("Utimes():"));
   	   	err = Utimes();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
   	else if(TestStepName() == KUtime)
   		{
   	   	INFO_PRINTF1(_L("Utime():"));
   	   	err = Utime();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KChdir)
   		{
   	   	INFO_PRINTF1(_L("Chdir():"));
   	   	err = Chdir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KFcntl)
   		{
   	   	INFO_PRINTF1(_L("Fcntl():"));
   	   	err = Fcntl();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KIoctl)
   		{
   	   	INFO_PRINTF1(_L("Ioctl():"));
   	   	err = Ioctl();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KFstat)
   		{
   	   	INFO_PRINTF1(_L("Fstat():"));
   	   	err = Fstat();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KStat)
   		{
   	   	INFO_PRINTF1(_L("Stat():"));
   	   	err = Stat();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KStat1)
   		{
   	   	INFO_PRINTF1(_L("Stat1():"));
   	   	err = Stat1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KStat2)
   		{
   	   	INFO_PRINTF1(_L("Stat2():"));
   	   	err = Stat2();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KStat3)
   		{
   	   	INFO_PRINTF1(_L("Stat3():"));
   	   	err = Stat3();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KGetpid)
   		{
   	   	INFO_PRINTF1(_L("Getpid():"));
   	   	err = Getpid();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KClock)
   		{
   	   	INFO_PRINTF1(_L("Clock():"));
   	   	err = Clock();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KTime)
   		{
   	   	INFO_PRINTF1(_L("Time():"));
   	   	err = Time();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KWaitPid)
   		{
   	   	INFO_PRINTF1(_L("WaitPid():"));
   	   	err = WaitPid();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KReadV)
   		{
   	   	INFO_PRINTF1(_L("ReadV():"));
   	   	err = ReadV();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KWriteV)
   		{
   	   	INFO_PRINTF1(_L("WriteV():"));
   	   	err = WriteV();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KSleep)
   		{
   	   	INFO_PRINTF1(_L("Sleep():"));
   	   	err = Sleep();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KSeekDir)
   		{
   	   	INFO_PRINTF1(_L("SeekDir():"));
   	   	err = SeekDir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRewindDir)
   		{
   	   	INFO_PRINTF1(_L("RewindDir():"));
   	   	err = RewindDir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KTelldir)
   		{
   	   	INFO_PRINTF1(_L("Telldir():"));
   	   	err = Telldir();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KTestClock)
   		{
   	   	INFO_PRINTF1(_L("TestClock():"));
   	   	err = TestClock();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KCreat2)
   		{
   		INFO_PRINTF1(_L("Creat2():"));
   		err = Creat2();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
   	else if(TestStepName() == Kopen8)
   		{
   		INFO_PRINTF1(_L("open8():"));
   		err = open8();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
   	else if(TestStepName() == KTestStat)
   		{
   		INFO_PRINTF1(_L("KTestStat():"));
   		err = TestStat();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KLseekttytest1)
   		{
   		INFO_PRINTF1(_L("Lseekttytest1():"));
   		err = Lseekttytest1();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KLseekttytest2)
   		{
   		INFO_PRINTF1(_L("Lseekttytest2():"));
   		err = Lseekttytest2();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KWaitPidtest)
   		{
   		INFO_PRINTF1(_L("WaitPidtest():"));
   		err = WaitPidtest();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KWaittest)
   		{
   		INFO_PRINTF1(_L("Waittest():"));
   		err = Waittest();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KOpen_FileDes_Test)
   		{
   		INFO_PRINTF1(_L("Open_FileDes_Test():"));
   		err = Open_FileDes_Test();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Kopenuid)
   		{
   		INFO_PRINTF1(_L("openuid():"));
   		err = openuid();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KMkdir1)
   		{
   	   	INFO_PRINTF1(_L("Mkdir1():"));
   	   	err = Mkdir1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KMkdir2)
   		{
   	   	INFO_PRINTF1(_L("Mkdir2():"));
   	   	err = Mkdir2();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KRename2)
   		{
   	   	INFO_PRINTF1(_L("Rename2():"));
   	   	err = Rename2();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == Ktestfsync)
   		{
   		INFO_PRINTF1(_L("testfsync():"));
   		err = testfsync();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Ktestrename)
   		{
   		INFO_PRINTF1(_L("testrename():"));
   		err = testrename();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Ktestopenvalidate)
   		{
   		INFO_PRINTF1(_L("testopenvalidate():"));
   		err = testopenvalidate();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == Ksync_safe)
   		{
   		INFO_PRINTF1(_L("sync_safe():"));
   		err = sync_safe();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
   	else if(TestStepName() == KFstat1)
   		{
   	   	INFO_PRINTF1(_L("Fstat1():"));
   	   	err = Fstat1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KUtimes1)
   		{
   	   	INFO_PRINTF1(_L("Utimes1():"));
   	   	err = Utimes1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
		}
	else if(TestStepName() == KMkdir_test1)
   		{
   	   	INFO_PRINTF1(_L("Mkdir_test1():"));
   	   	err = Mkdir_test1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KChmod_test)
   		{
   	   	INFO_PRINTF1(_L("Chmod_test():"));
   	   	err = Chmod_test();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
	else if(TestStepName() == KChdir1)
   		{
   	   	INFO_PRINTF1(_L("Chdir1():"));
   	   	err = Chdir1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}   
   	else if(TestStepName() == KRmdir2)
   		{
   	   	INFO_PRINTF1(_L("Rmdir2():"));
   	   	err = Rmdir2();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRename_test)
   		{
   	   	INFO_PRINTF1(_L("Rename_test():"));
   	   	err = Rename_test();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KRename3)
   		{
   	   	INFO_PRINTF1(_L("Rename3():"));
   	   	err = Rename3();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
   	else if(TestStepName() == KCreat1)
   		{
   		INFO_PRINTF1(_L("Creat1():"));
   		err = Creat1();
   		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   		}
   	else if(TestStepName() == KReadV1)
   		{
   	   	INFO_PRINTF1(_L("ReadV1():"));
   	   	err = ReadV1();
   	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
   	   	}
 	else if(TestStepName() == KUtimes2)
    		{
    	   	INFO_PRINTF1(_L("Utimes2():"));
    	   	err = Utimes2();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
 		}
 	else if(TestStepName() == KStat_test)
    		{
    	   	INFO_PRINTF1(_L("Stat_test():"));
    	   	err = Stat_test();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}
    	else if(TestStepName() == KMkdir_test2)
    		{
    	   	INFO_PRINTF1(_L("Mkdir_test2():"));
    	   	err = Mkdir_test2();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}
    	else if(TestStepName() == KChmod2)
    		{
    	   	INFO_PRINTF1(_L("Chmod2():"));
    	   	err = Chmod2();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}
    	else if(TestStepName() == KChdir2)
    		{
    	   	INFO_PRINTF1(_L("Chdir2():"));
    	   	err = Chdir2();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	} 
    	else if(TestStepName() == KRename4)
    		{
    	   	INFO_PRINTF1(_L("Rename4():"));
    	   	err = Rename4();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}
 	else if(TestStepName() == KRename5)
    		{
    	   	INFO_PRINTF1(_L("Rename5():"));
    	   	err = Rename5();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}  
 	else if(TestStepName() == KRmdir3)
    		{
    	   	INFO_PRINTF1(_L("Rmdir3():"));
    	   	err = Rmdir3();
    	   	SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    	   	}  
    	else if(TestStepName() == Kread5)
 		{
 		INFO_PRINTF1(_L("read5():"));
 		err = read5();
    		SetTestStepResult(err ? static_cast<TVerdict>(err) : EPass);
    		} 	   	 
	return TestStepResult(); 
	}
Esempio n. 12
0
static void Test(Properties &prop) {
    FileSystemState *tablefs_data;
    tablefs_data = new tablefs::FileSystemState(prop.getPropertyInt("threshold"),
                                          prop.getProperty("metadir").c_str(),
                                          prop.getProperty("datadir").c_str(),
                                          prop.getProperty("logfile").c_str(),
                                          prop.getPropertyInt("sync.time.limit",-1));

    SetState(tablefs_data);

    Init(NULL);

    int mem_lock_size = 400;
    mem_lock_size = prop.getPropertyInt("mem.lock.size", 400);
    TraceLoader loader(mem_lock_size);
    loader.LoadTrace(prop.getProperty("tracefile").c_str());

    Monitor mon = Monitor(prop.getProperty("mon.partition"), 
                          prop.getProperty("mon.filesystem"));
    Monitor tmon = Monitor(prop.getProperty("mon.partition"), 
                           prop.getProperty("mon.filesystem"));
    mon.DoMonitor();
    tmon.DoMonitor();

    sync();

    srand(100);
    time_t time1 = time(NULL);
    int cnt = 0;
    for (int i = 0; i < loader.getNumPaths(); ++i) {
    	char filetype;
    	char* path = loader.getPath(i, filetype);
        Stat(path);
        if (filetype == 'f') {
            Mknode(path);
        } else
        if (filetype == 'd') {
            Mkdir(path);
        }
        Stat(path);
        cnt ++;
        if (cnt >= 1000) {
          tmon.DoMonitor();
          cnt = 0;
        }
    }

    time_t time2 = time(NULL);
    mon.DoMonitor();
    tmon.DoMonitor();
    printf("create directory tree , %d\n", (int) (time2 - time1));
    int nquery = prop.getPropertyInt("num.query");
    int npath = loader.getNumPaths();
    printf("nquery %d npath %d\n", nquery, npath);
    cnt = 0;
    for (int i = 0; i < nquery; ++i) {
      int pi = rand() % npath;
      char* path = loader.getPath(pi);
      if ((i & 3) == 0) {
        Chmod(path, 777);
      } else 
      if ((i & 3) == 1) {
        struct timespec tv[2];
        tv[0].tv_sec = time(NULL);
        tv[1].tv_sec = time(NULL);
        UpdateTimens(path, tv);
      } else {
        Stat(path);
      }
      cnt++;
      if (cnt >= 1000) {
        tmon.DoMonitor();
        cnt = 0;
      }
    }

    time_t time3 = time(NULL);
    mon.DoMonitor();
    tmon.DoMonitor();
    printf("update and query , %d\n", (int) (time3 - time2));

    char tpath[256];
    sprintf(tpath, "%s/test.txt", prop.getProperty("metadir").c_str()); 
    int fd = open(tpath, O_WRONLY); 
    fsync(fd);
    close(fd);
    sync();
    
    for (int i = 0; i < 20; ++i) {
      sleep(1);
      tmon.DoMonitor();
    }

    time_t time4 = time(NULL);
    mon.DoMonitor();
    tmon.DoMonitor();
    printf("sync , %d\n", (int) (time4 - time3));

    mon.Report();
    tmon.Report();

    Destroy(tablefs_data);
}
Esempio n. 13
0
static int xioopen_pty(int argc, const char *argv[], struct opt *opts, int xioflags, xiofile_t *xfd, unsigned groups, int dummy1, int dummy2, int dummy3) {
   /* we expect the form: filename */
   int ptyfd = -1, ttyfd = -1;
#if defined(HAVE_DEV_PTMX) || defined(HAVE_DEV_PTC)
   bool useptmx = false;	/* use /dev/ptmx or equivalent */
#endif
#if HAVE_OPENPTY
   bool useopenpty = false;	/* try only openpty */
#endif	/* HAVE_OPENPTY */
   char ptyname[MAXPTYNAMELEN];
   char *tn = NULL;
   char *linkname = NULL;
   bool opt_unlink_close = true;	/* remove symlink afterwards */
   bool wait_slave = false;	/* true would be better for many platforms, but
				   some OSes cannot handle this, and for common
				   default behaviour as well as backward 
				   compatibility we choose "no" as default */
   struct timespec pollintv = { PTY_INTERVALL };

   if (argc != 1) {
      Error2("%s: wrong number of parameters (%d instead of 0)", argv[0], argc-1);
   }

   xfd->stream.howtoend = END_CLOSE;

   if (applyopts_single(&xfd->stream, opts, PH_INIT) < 0)  return -1;
   applyopts(-1, opts, PH_INIT);

   retropt_bool(opts, OPT_UNLINK_CLOSE, &opt_unlink_close);

   /* trying to set user-early, perm-early etc. here might be useless because
      file system entry is eventually available only past pty creation */
   /* name not yet known; umask should not be handled with this function! */
   /* umask does not affect resulting mode, on Linux 2.4 */
   applyopts_named("", opts, PH_EARLY);	/* umask! */

#if defined(HAVE_DEV_PTMX) || defined(HAVE_DEV_PTC)
   retropt_bool(opts, OPT_PTMX, &useptmx);
#endif
#if HAVE_OPENPTY
   retropt_bool(opts, OPT_OPENPTY, &useopenpty);
#endif

#if (defined(HAVE_DEV_PTMX) || defined(HAVE_DEV_PTC))
#  if  HAVE_OPENPTY
   useopenpty = !useptmx;
#  else /* !HAVE_OPENPTY */
   useptmx = true;
#  endif /* !HAVE_OPENPTY */
#else
# if HAVE_OPENPTY
   useopenpty = true;
# endif /* HAVE_OPENPTY */
#endif /* ! (defined(HAVE_DEV_PTMX) || defined(HAVE_DEV_PTC)) */

#if HAVE_POLL
   retropt_bool(opts, OPT_PTY_WAIT_SLAVE, &wait_slave);
   retropt_timespec(opts, OPT_PTY_INTERVALL, &pollintv);
#endif /* HAVE_POLL */

   if (applyopts_single(&xfd->stream, opts, PH_INIT) < 0)  return -1;
   applyopts2(-1, opts, PH_INIT, PH_EARLY);

   applyopts(-1, opts, PH_PREBIGEN);

#if defined(HAVE_DEV_PTMX)
#  define PTMX "/dev/ptmx"	/* Linux */
#elif HAVE_DEV_PTC
#  define PTMX "/dev/ptc"	/* AIX 4.3.3 */
#endif
#if HAVE_DEV_PTMX || HAVE_DEV_PTC
   if (useptmx) {
      if ((ptyfd = Open(PTMX, O_RDWR|O_NOCTTY, 0620)) < 0) {
	 Warn1("open(\""PTMX"\", O_RDWR|O_NOCTTY, 0620): %s",
	       strerror(errno));
	 /*!*/
      } else {
	 ;/*0 Info1("open(\""PTMX"\", O_RDWR|O_NOCTTY, 0620) -> %d", ptyfd);*/
      }
      if (ptyfd >= 0 && ttyfd < 0) {
	 /* we used PTMX before forking */
	 /*0 extern char *ptsname(int);*/
#if HAVE_GRANTPT	/* AIX, not Linux */
	 if (Grantpt(ptyfd)/*!*/ < 0) {
	    Warn2("grantpt(%d): %s", ptyfd, strerror(errno));
	 }
#endif /* HAVE_GRANTPT */
#if HAVE_UNLOCKPT
	 if (Unlockpt(ptyfd)/*!*/ < 0) {
	    Warn2("unlockpt(%d): %s", ptyfd, strerror(errno));
	 }
#endif /* HAVE_UNLOCKPT */
#if HAVE_PROTOTYPE_LIB_ptsname	/* AIX, not Linux */
	 if ((tn = Ptsname(ptyfd)) == NULL) {
	    Warn2("ptsname(%d): %s", ptyfd, strerror(errno));
	 } else {
	    Notice1("PTY is %s", tn);
	 }
#endif /* HAVE_PROTOTYPE_LIB_ptsname */
	 if (tn == NULL) {
	    if ((tn = Ttyname(ptyfd)) == NULL) {
	       Warn2("ttyname(%d): %s", ptyfd, strerror(errno));
	    }
	 }
	 ptyname[0] = '\0'; strncat(ptyname, tn, MAXPTYNAMELEN-1);
      }
   }
#endif /* HAVE_DEV_PTMX || HAVE_DEV_PTC */
#if HAVE_OPENPTY
   if (ptyfd < 0) {
      int result;
      if ((result = Openpty(&ptyfd, &ttyfd, ptyname, NULL, NULL)) < 0) {
	 Error4("openpty(%p, %p, %p, NULL, NULL): %s",
		&ptyfd, &ttyfd, ptyname, strerror(errno));
	 return -1;
      }
      Notice1("PTY is %s", ptyname);
   }
#endif /* HAVE_OPENPTY */

   if (!retropt_string(opts, OPT_SYMBOLIC_LINK, &linkname)) {
      if (Unlink(linkname) < 0 && errno != ENOENT) {
	 Error2("unlink(\"%s\"): %s", linkname, strerror(errno));
      }
      if (Symlink(ptyname, linkname) < 0) {
	 Error3("symlink(\"%s\", \"%s\"): %s",
		ptyname, linkname, strerror(errno));
      }
      if (opt_unlink_close) {
	 if ((xfd->stream.unlink_close = strdup(linkname)) == NULL) {
	    Error1("strdup(\"%s\"): out of memory", linkname);
	 }
	 xfd->stream.opt_unlink_close = true;
      }
   }

   applyopts_named(ptyname, opts, PH_PASTOPEN);
   applyopts_named(ptyname, opts, PH_FD);

   applyopts_cloexec(ptyfd, opts);/*!*/
   xfd->stream.dtype    = XIODATA_PTY;

   applyopts(ptyfd, opts, PH_FD);

   {
      /* special handling of user-late etc.; with standard behaviour (up to
	 1.7.1.1) they affected /dev/ptmx instead of /dev/pts/N */
      uid_t uid = -1, gid = -1;
      mode_t perm;

      bool dont;
      dont = retropt_uid(opts, OPT_USER_LATE, &uid);
      dont &= retropt_gid(opts, OPT_GROUP_LATE, &gid);

      if (!dont) {
	 if (Chown(ptyname, uid, gid) < 0) {
	    Error4("chown(\"%s\", %d, %d): %s",
		   ptyname, uid, gid, strerror(errno));
	 }
      }

      if (retropt_mode(opts, OPT_PERM_LATE, &perm) == 0) {
	 if (Chmod(ptyname, perm) < 0) {
	    Error3("chmod(\"%s\", %03o): %s",
		   ptyname, perm, strerror(errno));
	 }
      }

   }

   xfd->stream.fd = ptyfd;
   applyopts(ptyfd, opts, PH_LATE);
   if (applyopts_single(&xfd->stream, opts, PH_LATE) < 0)  return -1;

#if HAVE_POLL
   /* if you can and wish: */
   if (wait_slave) {
      /* try to wait until someone opens the slave side of the pty */
      /* we want to get a HUP (hangup) condition on the pty */
#if HAVE_DEV_PTMX || HAVE_DEV_PTC
      if (useptmx) {
	 ttyfd = Open(tn, O_RDWR|O_NOCTTY, 0620);
	 Close(ttyfd);
      }
#endif
#if HAVE_OPENPTY
      if (useopenpty) {
	 Close(ttyfd);
      }
#endif /* HAVE_OPENPTY */

      /* now we poll until the HUP vanishes - this indicates a slave conn. */
      while (true) {
	 struct pollfd ufd;
	 ufd.fd = ptyfd;
	 ufd.events = (POLLHUP);
	 if (Poll(&ufd, 1, 0) < 0) {
	    Error3("poll({%d, 0x%04hu,}, 1, 0): %s",
		   ufd.fd, ufd.events, strerror(errno));
	    /*! close something */
	    return -1;
	 }
	 if (!(ufd.revents & POLLHUP)) {
	    break;
	 }
	 Nanosleep(&pollintv, NULL);
	 continue;
      }
   }
#endif /* HAVE_POLL */

   return STAT_OK;
}
Esempio n. 14
0
int CFileZillaEngine::Command(const CCommand &command)
{
    if (command.GetId() != cmd_cancel && IsBusy())
        return FZ_REPLY_BUSY;

    m_bIsInCommand = true;

    int res = FZ_REPLY_INTERNALERROR;

    printf("command id: %d\n", command.GetId());
    switch (command.GetId())
    {
    case cmd_connect:
        res = Connect(reinterpret_cast<const CConnectCommand &>(command));
        break;
    case cmd_disconnect:
        res = Disconnect(reinterpret_cast<const CDisconnectCommand &>(command));
        break;
    case cmd_cancel:
        res = Cancel(reinterpret_cast<const CCancelCommand &>(command));
        break;
    case cmd_list:
        res = List(reinterpret_cast<const CListCommand &>(command));
        break;
    case cmd_transfer:
        res = FileTransfer(reinterpret_cast<const CFileTransferCommand &>(command));
        break;
    case cmd_raw:
        res = RawCommand(reinterpret_cast<const CRawCommand&>(command));
        break;
    case cmd_delete:
        res = Delete(reinterpret_cast<const CDeleteCommand&>(command));
        break;
    case cmd_removedir:
        res = RemoveDir(reinterpret_cast<const CRemoveDirCommand&>(command));
        break;
    case cmd_mkdir:
        res = Mkdir(reinterpret_cast<const CMkdirCommand&>(command));
        break;
    case cmd_rename:
        res = Rename(reinterpret_cast<const CRenameCommand&>(command));
        break;
    case cmd_chmod:
        res = Chmod(reinterpret_cast<const CChmodCommand&>(command));
        break;
    case cmd_checksum:
        printf("recognized the checksum command\n");
        res = Checksum(reinterpret_cast<const CChecksumCommand&>(command));
        break;
    default:
        return FZ_REPLY_SYNTAXERROR;
    }

    if (res != FZ_REPLY_WOULDBLOCK)
        ResetOperation(res);

    m_bIsInCommand = false;

    if (command.GetId() != cmd_disconnect)
        res |= m_nControlSocketError;
    else if (res & FZ_REPLY_DISCONNECTED)
        res = FZ_REPLY_OK;
    m_nControlSocketError = 0;

    return res;
}