Beispiel #1
0
/* {{{ proto int exec(string command [, array output [, int return_value]])
   Execute an external program */
void php3_exec(INTERNAL_FUNCTION_PARAMETERS)
{
	pval *arg1, *arg2, *arg3;
	int arg_count = ARG_COUNT(ht);
	int ret;

	if (arg_count > 3 || getParameters(ht, arg_count, &arg1, &arg2, &arg3) == FAILURE) {
		WRONG_PARAM_COUNT;
	}
	switch (arg_count) {
		case 1:
			ret = _Exec(0, arg1->value.str.val, NULL, return_value);
			break;
		case 2:
			if (!ParameterPassedByReference(ht,2)) {
				php3_error(E_WARNING,"Array argument to exec() not passed by reference");
			}
			ret = _Exec(2, arg1->value.str.val, arg2, return_value);
			break;
		case 3:
			if (!ParameterPassedByReference(ht,2)) {
				php3_error(E_WARNING,"Array argument to exec() not passed by reference");
			}
			if (!ParameterPassedByReference(ht,3)) {
				php3_error(E_WARNING,"return_status argument to exec() not passed by reference");
			}
			ret = _Exec(2, arg1->value.str.val, arg2, return_value);
			arg3->type = IS_LONG;
			arg3->value.lval=ret;
			break;
	}
}
void FvLodTickNode::Exec(const float fDeltaTime)
{
	const float fDeltaTimeMod = FvMathTool::Max(fDeltaTime, m_fSpan);
	m_fAccumulateTime += fDeltaTime;
	//FvLogBus::CritOk("FvLodTickNode::Exec m_fAccumulateTime(%f)", m_fAccumulateTime);
	if(m_fAccumulateTime >= fDeltaTimeMod)
	{
		m_fAccumulateTime -= fDeltaTimeMod;
		_Exec(fDeltaTimeMod);
	}
}
Beispiel #3
0
int Shell::Exec(const std::string& buf, Client* client, Server* server){
	CommandLine cmd;
	if(cmd.Parse(buf, command_num) < 0) return -1;
	return _Exec(cmd, client, server);
}
Beispiel #4
0
int PreExec_Exec(
    PreExec* self,
    const char* programPath,
    uid_t uid,
    uid_t gid)
{
    char path[PAL_MAX_PATH_SIZE];
    char key[PAL_MAX_PATH_SIZE];
    char uidBuf[11];
    const char* uidStr;
    char gidBuf[11];
    const char* gidStr;

    /* If no pre-exec program, nothing to do */
    if (programPath == NULL)
        return 0;

    /* Form the UID string */
    {
        size_t dummy;
        uidStr = Uint32ToStr(uidBuf, (PAL_Uint32)uid, &dummy);
    }

    /* Form the GID string */
    {
        size_t dummy;
        gidStr = Uint32ToStr(gidBuf, (PAL_Uint32)gid, &dummy);
    }

    /* Form a hash key from PREEXEC+UID+GID */
    {
        key[0] = '\0';
        Strlcat(key, programPath, PAL_MAX_PATH_SIZE);
        Strlcat(key, "+", PAL_MAX_PATH_SIZE);
        Strlcat(key, uidStr, PAL_MAX_PATH_SIZE);
        Strlcat(key, "+", PAL_MAX_PATH_SIZE);
        Strlcat(key, gidStr, PAL_MAX_PATH_SIZE);
    }

    /* If key already in cache, then return without doing anything */
    {
        static pthread_mutex_t s_mutex = PTHREAD_MUTEX_INITIALIZER;

        pthread_mutex_lock(&s_mutex);

        if (_Contains(&self->cache, key))
        {
            pthread_mutex_unlock(&s_mutex);
            return 0;
        }

        /* Add key to cache */
        _Insert(&self->cache, key);
        pthread_mutex_unlock(&s_mutex);
    }

    /* Form the full path of the pre-exec program */
    {
        const char* bindir = OMI_GetPath(ID_BINDIR);

        path[0] = '\0';

        if (bindir)
        {
            Strlcat(path, bindir, PAL_MAX_PATH_SIZE);
            Strlcat(path, "/", PAL_MAX_PATH_SIZE);
        }

        Strlcat(path, programPath, PAL_MAX_PATH_SIZE);
    }

    /* Execute and wait on the pre-exec program to exit */
    _BlockSIGCHLD();
    {
        pid_t pid = _Exec(path, uidStr, gidStr);

        if (pid == -1)
        {
            _UnblockSIGCHLD();
            trace_PreExecFailed(path);
            return -1;
        }

        {
            pid_t r;
            int status;

            r = waitpid(pid, &status, 0);

            if (r != pid || WEXITSTATUS(status) != 0)
            {
                _UnblockSIGCHLD();
                trace_PreExecFailed(path);
                return -1;
            }
        }
    }
    _UnblockSIGCHLD();

    trace_PreExecOk(path);
    return 0;
}