示例#1
0
ThreadPoolJob::JobStatus EnviIPCRequestJob::runJob()
{
    const ScopedLock sl (jobLock);

    webInputStream = requestURL.withPOSTData(JSON::toString(requestData)).createInputStream (true, &EnviIPCRequestJob::progressCallback, this, "Client: EnviUI", 2000, &responseHeaders);

    if (webInputStream)
    {
        Result res = JSON::parse (webInputStream->readEntireStreamAsString(), responseData);

        if (res.wasOk())
        {
            triggerAsyncUpdate();
            return (ThreadPoolJob::jobHasFinished);
        }
        else
        {
            _ERR("Response from server can't be parsed as JSON ["+res.getErrorMessage()+"]");
            return (ThreadPoolJob::jobNeedsRunningAgain);
        }
    }
    else
    {
        _ERR("Unable to create connection to server");
        return (ThreadPoolJob::jobNeedsRunningAgain);
    }
}
示例#2
0
文件: Main.cpp 项目: shoutrain/ComEgg
int main(int argc, char *argv[])
{
	// Load XML first
	if (1 == argc)
	{
		if (SUCCESS != _ERR(CXMLLoaderManager::Instance()->Load()))
			return -1;
	}
	else if (2 == argc)
	{
		if (SUCCESS != _ERR(CXMLLoaderManager::Instance()->Load(argv[1])))
			return -1;
	}
	else
	{
		printf("Usage: ComEgg [Directory]\n");

		return 0;
	}

	CXMLLoaderManager::Destory();

	// Working...
	if (SUCCESS != _ERR(CNetworkManager::Instance()->Work()))
		return -2;

	return 0;
}
示例#3
0
static int __set_i18n(const char *domain, const char *dir)
{
	char *r;

	if (domain == NULL) {
		errno = EINVAL;
		return -1;
	}

	r = setlocale(LC_ALL, "");
	/* if locale is not set properly, try again to set as language base */
	if (r == NULL) {
		r = setlocale(LC_ALL, vconf_get_str(VCONFKEY_LANGSET));
		_DBG("*****appcore setlocale=%s\n", r);
	}
	if (r == NULL) {
		_ERR("appcore: setlocale() error");
	}
	//_retvm_if(r == NULL, -1, "appcore: setlocale() error");

	r = bindtextdomain(domain, dir);
	if (r == NULL) {
		_ERR("appcore: bindtextdomain() error");
	}
	//_retvm_if(r == NULL, -1, "appcore: bindtextdomain() error");

	r = textdomain(domain);
	if (r == NULL) {
		_ERR("appcore: textdomain() error");
	}
	//_retvm_if(r == NULL, -1, "appcore: textdomain() error");

	return 0;
}
示例#4
0
void EventLoopL::RemoveIO(std::weak_ptr<IO>& wio)
{
	if(std::this_thread::get_id() != Creator_)
	{
		_ERR("You can only remove IO in the thread that creates this event loop!");
 		return;
	}

	std::shared_ptr<IO> io(wio.lock());
	if(!io)
	{
		_ERR("This io is not exist!");
		return;
	}

	if(io->Index() < 0)
	{
		_ERR("This IO has been removed!");
		return;
	}

	event_del(Datas_[io->Index()]->ev);
	event_free(Datas_[io->Index()]->ev);
	Datas_[io->Index()]->ev = NULL;
	IdleIndexs_.push(io->Index());
	io->SetIndex(-1);
}
示例#5
0
EnviApplication::EnviApplication(int argc, char* argv[])
	: enviCLI(nullptr), valid(true)
{
	enviCLI = new EnviCLI (argc, argv);

	EnviLog::getInstance()->setOwner(this);
	if (enviCLI->isSet("log-console"))
	{
		EnviLog::getInstance()->setLogToConsole(true);
	}

	if (enviCLI->isSet("help"))
	{
		enviCLI->printHelp();
		valid = false;
		return;
	}

	if (enviCLI->isSet("log-file"))
	{
		Result res = EnviLog::getInstance()->setLogToFile (getEnviLogFile());

		if (!res.wasOk())
		{
			_ERR("Can't write to specified log file: ["+res.getErrorMessage()+"]");
			valid = false;
			return;
		}
	}

	if (enviCLI->isSet("log-level"))
	{
		EnviLog::getInstance()->setLogLevel (enviCLI->getParameter("log-level").getIntValue());
	}

	if (enviCLI->isSet("disabled-sources"))
	{
		disabledSources = StringArray::fromTokens(enviCLI->getParameter("disabled-sources"), ",", "'\"");
	}

	Result res = findDataSourcesOnDisk();

	if (!res.wasOk())
	{
		_ERR("Can't initialize sources: ["+res.getErrorMessage()+"]");
		valid = false;
		return;
	}

	enviDB		    = new EnviDB(*this);

#ifdef WIRING_PI
	enviWiringPi	= new EnviWiringPi(*this);
#endif
}
示例#6
0
ret_ CProcessor::Unregister(const ch_1 *pszCategory, const ch_1 *pszKey)
{
	_START(PROCESSOR_UNREGISTER);

#ifdef _DEBUG_
	if (!pszCategory)
		_RET(PARAMETER_NULL | PARAMETER_1);

	if (0 == pszCategory[0])
		_RET(PARAMETER_EMPTY | PARAMETER_1);

	if (!pszKey)
		_RET(PARAMETER_NULL | PARAMETER_2);

	if (0 == pszKey[0])
		_RET(PARAMETER_EMPTY | PARAMETER_2);
#endif

	CProcessor *pProcessor = null_v;

	if (SUCCESS == _ERR(CTransactionManager::Instance()->Search(pszCategory,
																pszKey,
																pProcessor)))
	{
#ifdef _DEUB_
		if (!pProcessor)
			_RET(ELEMENT_NULL_IN_CONTAINER);
#endif

		map_register::iterator pos = m_RegisterMap.find(pszCategory);

		if (m_RegisterMap.end() != pos)
		{
			set_register::iterator pos_ = pos->second->find(pszKey);

			if (pos->second->end() != pos_)
			{
				pos->second->erase(pszKey);

				if (0 == pos->second->size())
					m_RegisterMap.erase(pszCategory);
			}
		}

		CTransactionManager::Instance()->Unregister(pszCategory, pszKey);
	}

	ret_ Ret = CRegister::Instance()->Unregister(pszCategory, pszKey);

	if (SUCCESS != _ERR(Ret))
		_RET_BY(Ret);

	_RET(SUCCESS);
}
void _popen_noshell_child_process(
        /* We need the pointer *arg_ptr only to free whatever we reference if exec() fails and we were fork()'ed (thus memory was copied),
         * not clone()'d */
        struct popen_noshell_clone_arg *arg_ptr, /* NULL if we were called by pure fork() (not because of Valgrind) */
        int pipefd_0, int pipefd_1, int read_pipe, int ignore_stderr, const char *file, const char * const *argv) {

        int closed_child_fd;
        int closed_pipe_fd;
        int dupped_child_fd;
        int pipefd[2] = {pipefd_0, pipefd_1};

        if (ignore_stderr) { /* ignore STDERR completely? */
                if (popen_noshell_reopen_fd_to_dev_null(STDERR_FILENO) != 0) _ERR(255, "popen_noshell_reopen_fd_to_dev_null(%d)", STDERR_FILENO);
        }

        if (read_pipe) {
                closed_child_fd = STDIN_FILENO;         /* re-open STDIN to /dev/null */
                closed_pipe_fd = 0;                     /* close read end of pipe */
                dupped_child_fd = STDOUT_FILENO;        /* dup the other pipe end to STDOUT */
        } else {
                closed_child_fd = STDOUT_FILENO;        /* ignore STDOUT completely */
                closed_pipe_fd = 1;                     /* close write end of pipe */
                dupped_child_fd = STDIN_FILENO;         /* dup the other pipe end to STDIN */
        }
        if (popen_noshell_reopen_fd_to_dev_null(closed_child_fd) != 0) {
                _ERR(255, "popen_noshell_reopen_fd_to_dev_null(%d)", closed_child_fd);
        }
        if (_popen_noshell_close_and_dup(pipefd, closed_pipe_fd, dupped_child_fd) != 0) {
                _ERR(255, "_popen_noshell_close_and_dup(%d ,%d)", closed_pipe_fd, dupped_child_fd);
        }

        execvp(file, (char * const *)argv);

        /* if we are here, exec() failed */

        warn("exec(\"%s\") inside the child", file);

#ifdef POPEN_NOSHELL_VALGRIND_DEBUG
        if (arg_ptr) { /* not NULL if we were called by clone() */
                /* but Valgrind does not support clone(), so we were actually called by fork(), thus memory was copied... */
                /* free this copied memory; if it was not Valgrind, this memory would have been shared and would belong to the parent! */
                _pclose_noshell_free_clone_arg_memory(arg_ptr);
        }
#endif

        if (fflush(stdout) != 0) _ERR(255, "fflush(stdout)");
        if (fflush(stderr) != 0) _ERR(255, "fflush(stderr)");
        close(STDIN_FILENO);
        close(STDOUT_FILENO);
        close(STDERR_FILENO);

        _exit(255); // call _exit() and not exit(), or you'll have troubles in C++
}
示例#8
0
文件: appcore.c 项目: pjhwan92/tizen
EXPORT_API int appcore_init(const char *name, const struct ui_ops *ops,
			    int argc, char **argv)
{
	int r;
	char dirname[PATH_MAX];

	if (core.state != 0) {
		_ERR("Already in use");
		errno = EALREADY;
		return -1;
	}

	if (ops == NULL || ops->cb_app == NULL) {
		_ERR("ops or callback function is null");
		errno = EINVAL;
		return -1;
	}

	r = __get_dir_name(dirname);
	r = set_i18n(name, dirname);
	_retv_if(r == -1, -1);

	r = __add_vconf(&core);
	if (r == -1) {
		_ERR("Add vconf callback failed");
		goto err;
	}

	r = aul_launch_init(__aul_handler, &core);
	if (r < 0) {
		_ERR("Aul init failed: %d", r);
		goto err;
	}

	r = aul_launch_argv_handler(argc, argv);
	if (r < 0) {
		_ERR("Aul argv handler failed: %d", r);
		goto err;
	}

	core.ops = ops;
	core.state = 1;		/* TODO: use enum value */

	_pid = getpid();

	return 0;
 err:
	__del_vconf();
	__clear(&core);
	return -1;
}
示例#9
0
文件: fuse.cpp 项目: looncraz/haiku
static int
fuse_mknod(const char* path, mode_t mode, dev_t rdev)
{
	PRINTD("##mknod\n");
	if (S_ISREG(mode)) {
		int fd = _kern_open(-1, path,
			FSSH_O_CREAT | FSSH_O_EXCL | FSSH_O_WRONLY, mode);
		if (fd >= FSSH_B_OK)
			return _ERR(_kern_close(fd));
		return _ERR(fd);
	} else if (S_ISFIFO(mode))
		return _ERR(FSSH_EINVAL);
	else
		return _ERR(FSSH_EINVAL);
}
示例#10
0
文件: exp_client.c 项目: just-hu/zlmb
int
main (int argc, char **argv)
{
    int i;
    char *endpoint = NULL;
    void *context, *socket;

    if (argc <= 2) {
        _usage(argv[0]);
        return -1;
    }

    endpoint = argv[1];

    context = zmq_ctx_new();
    if (!context) {
        _ERR("ZeroMQ context: %s\n", zmq_strerror(errno));
        return -1;
    }

    socket = zmq_socket(context, ZMQ_PUSH);
    if (!socket) {
        _ERR("ZeroMQ socket: %s\n", zmq_strerror(errno));
        zmq_ctx_destroy(context);
        return -1;
    }

    if (zmq_connect(socket, endpoint) == -1) {
        _ERR("ZeroMQ connect: %s: %s\n", endpoint, zmq_strerror(errno));
        zmq_close(socket);
        zmq_ctx_destroy(context);
        return -1;
    }

    for (i = 2; i != (argc - 1); i++) {
        if (zmq_send(socket, argv[i], strlen(argv[i]), ZMQ_SNDMORE) == -1) {
            _ERR("ZeroMQ send: %s\n", zmq_strerror(errno));
        }
    }
    if (zmq_send(socket, argv[i], strlen(argv[i]), 0) == -1) {
        _ERR("ZeroMQ send: %s\n", zmq_strerror(errno));
    }

    zmq_close(socket);
    zmq_ctx_destroy(context);

    return 0;
}
示例#11
0
const bool CtrlrMidiDevice::openDevice()
{
	if (getType() == CtrlrMidiDeviceManager::outputDevice)
	{
		if (outJucePtr != nullptr)
		{
			return (true);
		}

		const ScopedLock sl(deviceLock);

		outJucePtr = MidiOutput::openDevice (getProperty(Ids::midiDevIndex));
		if (outJucePtr == NULL)
		{
			_ERR("CtrlrMidiDevice::openDevice failed to open device \""+getName()+"\"");
			setProperty (Ids::midiDevState, false);
			return (false);
		}
		else
		{
			outJucePtr->startBackgroundThread();
			setProperty (Ids::midiDevState, true);
			return (true);
		}
	}
	else
	{
		if (inJucePtr != nullptr)
		{
			return (true);
		}

		inJucePtr = MidiInput::openDevice (getProperty(Ids::midiDevIndex), this);

		if (inJucePtr == NULL)
		{
			_ERR("CtrlrMidiDevice::openDevice failed to open device \""+getName()+"\"");
			setProperty (Ids::midiDevState, false);
			return (false);
		}
		else
		{
			inJucePtr->start();
			setProperty (Ids::midiDevState, true);
			return (true);
		}
	}
}
void CtrlrModulatorProcessor::setReverseExpression (const String &reverseExpressionString)
{
	if (reverseExpressionString == String::empty || reverseExpressionString == EXP_MODULATOR_REVERSE)
	{
		const ScopedWriteLock sl (processorLock);

		usingReverseProcess = false;
		return;
	}

	{
		const ScopedWriteLock sl (processorLock);

		try
		{
			reverseProcess = Expression(reverseExpressionString);
		}
		catch (Expression::ParseError err)
		{
			_ERR("CtrlrModulatorProcessor::setReverseExpression parse error: " + err.description);
			usingReverseProcess = false;

			return;
		}

		usingReverseProcess = true;
	}
}
示例#13
0
int  SqMod::_runScript(const char* docu,
                        const char* docu_hash,
                        time_t script_time)
{
    _penv->acquire(); //on this thread
    try {
        if(docu) { //compile it in docu_hash
            struct utimbuf  utb = {script_time, script_time};
            MyScript s = _penv->CompileScript(docu);
            s.Run();
            s.WriteCompiledFile(docu_hash);
            utime(docu_hash, &utb);
            return _DONE;
        } else {
            MyScript s = _penv->CompileScript(docu_hash);
            s.Run();
            return _DONE;
        }
    }
    catch(Sqrat::Exception ex)
    {
        swrite(ex.Message().c_str());
        unlink(docu_hash);
    }
    return _ERR(1);
}
void CtrlrModulatorProcessor::setForwardExpression (const String &forwardExpressionString)
{
	if (forwardExpressionString == String::empty || forwardExpressionString == EXP_MODULATOR_FORWARD)
	{
		const ScopedWriteLock sl (processorLock);

		usingForwardProcess = false;
		return;
	}

	{
		const ScopedWriteLock sl (processorLock);

		try
		{
			forwardProcess = Expression(forwardExpressionString);
		}
		catch (Expression::ParseError err)
		{
			_ERR("CtrlrModulatorProcessor::setForwardExpression parse error: " + err.description);
			usingForwardProcess = false;

			return;
		}

		usingForwardProcess = true;
	}
}
示例#15
0
void TcpChannel::handleRead(int cond)
{
    _DBG("begin tcp handle read...");
    struct sockaddr_in addr;
    int error;
    int fd = Socket::Accept(TcpIO_->Fd(), addr, error);
    if(fd < 0)
    {
        _ERR("Accept fail");
        if (error == EMFILE)
        {
            close(IdleFd_);
            IdleFd_ = accept(TcpIO_->Fd(), NULL, NULL);
            close(IdleFd_);
            IdleFd_ = open("/dev/null", O_RDONLY | O_CLOEXEC);
        }
        return;
    }

    if(Callback_)
    {
        InetAddress iAddr;
        iAddr.addr = addr.sin_addr.s_addr;
        iAddr.saddr = inet_ntoa(addr.sin_addr);
        iAddr.port = addr.sin_port;
        Callback_(fd, iAddr);
    }
    else
    {
        close(fd);
    }
}
示例#16
0
文件: fuse.cpp 项目: looncraz/haiku
static int
fuse_write(const char* path, const char* buf, size_t size, off_t offset,
	struct fuse_file_info* fi)
{
	PRINTD("##write\n");
	int fd = _kern_open(-1, path, FSSH_O_WRONLY,
		(FSSH_S_IRWXU | FSSH_S_IRWXG | FSSH_S_IRWXO) & ~sUmask);
	if (fd < FSSH_B_OK)
		return _ERR(fd);

	int res = _kern_write(fd, offset, buf, size);
	_kern_close(fd);
	if (res < FSSH_B_OK)
		res = _ERR(res);
	return res;
}
示例#17
0
文件: appcore.c 项目: pjhwan92/tizen
EXPORT_API int appcore_flush_memory(void)
{
	int (*flush_fn) (int);
	int size = 0;

	struct appcore *ac = &core;

	if (!core.state) {
		_ERR("Appcore not initialized");
		return -1;
	}

	_DBG("[APP %d] Flushing memory ...", _pid);

	if (ac->ops->cb_app) {
		ac->ops->cb_app(AE_MEM_FLUSH, ac->ops->data, NULL);
	}

	flush_fn = dlsym(RTLD_DEFAULT, "sqlite3_release_memory");
	if (flush_fn) {
		size = flush_fn(SQLITE_FLUSH_MAX);
	}

	malloc_trim(0);
	/*
	*Disabled - the impact of stack_trim() is unclear
	*stack_trim();
	*/

	_DBG("[APP %d] Flushing memory DONE", _pid);

	return 0;
}
示例#18
0
文件: appcore.c 项目: pjhwan92/tizen
EXPORT_API int appcore_set_event_callback(enum appcore_event event,
					  int (*cb) (void *), void *data)
{
	struct appcore *ac = &core;
	struct sys_op *op;
	enum sys_event se;

	for (se = SE_UNKNOWN; se < SE_MAX; se++) {
		if (event == to_ae[se])
			break;
	}

	if (se == SE_UNKNOWN || se >= SE_MAX) {
		_ERR("Unregistered event");
		errno = EINVAL;
		return -1;
	}

	op = &ac->sops[se];

	op->func = cb;
	op->data = data;

	return 0;
}
示例#19
0
文件: fuse.cpp 项目: looncraz/haiku
static int
fuse_symlink(const char* from, const char* to)
{
	PRINTD("##symlink\n");
	return _ERR(_kern_create_symlink(-1, to, from,
		FSSH_S_IRWXU | FSSH_S_IRWXG | FSSH_S_IRWXO));
}
示例#20
0
文件: fuse.cpp 项目: looncraz/haiku
static int
fuse_readdir(const char* path, void* buf, fuse_fill_dir_t filler,
	off_t offset, struct fuse_file_info* fi)
{
	PRINTD("##readdir\n");
	int dfp = _kern_open_dir(-1, path);
	if (dfp < FSSH_B_OK)
		return _ERR(dfp);

	fssh_ssize_t entriesRead = 0;
	struct fssh_stat f_st;
	struct stat st;
	char buffer[sizeof(fssh_dirent) + FSSH_B_FILE_NAME_LENGTH];
	fssh_dirent* dirEntry = (fssh_dirent*)buffer;
	while ((entriesRead = _kern_read_dir(dfp, dirEntry,
			sizeof(buffer), 1)) == 1) {
		fssh_memset(&st, 0, sizeof(st));
		fssh_memset(&f_st, 0, sizeof(f_st));
		fssh_status_t status = _kern_read_stat(dfp, dirEntry->d_name,
			false, &f_st, sizeof(f_st));
		if (status >= FSSH_B_OK) {
			fromFsshStatToStat(&f_st, &st);
			if (filler(buf, dirEntry->d_name, &st, 0))
				break;
		}
	}
	_kern_close(dfp);
	//TODO: check _kern_close
	return 0;
}
示例#21
0
ret_ CProcessor::Stop()
{
	_START(STOP);

	map_handle::iterator pos;

	for (pos = m_HandleInMap.begin(); pos != m_HandleInMap.end(); pos++)
	{
#ifdef _DEBUG_
		if (!pos->second)
			_RET(ELEMENT_NULL_IN_CONTAINER);
#endif
		_DEL(pos->second);
	}

	for (pos = m_HandleOutMap.begin(); pos != m_HandleOutMap.end(); pos++)
	{
#ifdef _DEBUG_
		if (!pos->second)
			_RET(ELEMENT_NULL_IN_CONTAINER);
#endif
		_DEL(pos->second);
	}

	m_HandleInMap.clear();
	m_HandleOutMap.clear();

	for (map_register::iterator pos_ = m_RegisterMap.begin();
		 pos_ != m_RegisterMap.end(); pos_++)
	{
#ifdef _DEBUG_
		if (!pos_->second)
			_RET(ELEMENT_NULL_IN_CONTAINER);
#endif

		for (set_register::iterator pos_1 = pos_->second->begin();
			 pos_1 != pos_->second->end(); pos_1++)
		{
			ch_1 *sCategory	= (ch_1 *)pos_->first.data();
			ch_1 *pszKey		= (ch_1 *)pos_1->data();
			ret_ Ret		=
				CRegister::Instance()->Unregister(sCategory, pszKey);

#ifdef _DEBUG_
			if (SUCCESS != _ERR(Ret))
				_RET_BY(Ret);
#endif

			CTransactionManager::Instance()->Unregister(sCategory, pszKey);
		}

		pos_->second->clear();
		_DEL(pos_->second);
	}

	m_RegisterMap.clear();

	_RET(SUCCESS);
}
示例#22
0
ret_ CProcessor::Send(const CPDUInfo *pPDUInfo,
					  const ub_1 *pMsg,
					  size_ nSize,
					  const TMsgInfo *pMsgInfo)
{
	_START(SEND);

#ifdef _DEBUG_
	if (!m_pHandle)
		_RET(FAILURE);

	if (!pPDUInfo)
		_RET(PARAMETER_NULL | PARAMETER_1);

	if (!pMsg)
		_RET(PARAMETER_NULL | PARAMETER_2);

	if (0 >= nSize)
		_RET(PARAMETER_ERROR | PARAMETER_3);

	if (!pMsgInfo)
		_RET(PARAMETER_NULL | PARAMETER_4);
#endif

	ret_ Ret = m_pHandle->CheckSend(pPDUInfo, pMsg, nSize);

	if (SUCCESS != _ERR(Ret))
		_RET_BY(Ret);

	TMsgInfo MsgInfo;

	memcpy(&MsgInfo, pMsgInfo, sizeof(TMsgInfo));
	memcpy(MsgInfo.sLocalIP, m_pHandle->GetLocalIP(), IP_MAX_LENGTH);
	MsgInfo.nLocalPort = m_pHandle->GetLocalPort();

	Ret = ExecMsgHandle(pPDUInfo, pMsg, nSize, &MsgInfo, DIRECTION_OUT);

	if (SUCCESS != _ERR(Ret))
		_RET(Ret);

	_RET_BY(m_pHandle->Send(pMsg,
							nSize,
							MsgInfo.sRemoteIP,
							MsgInfo.nRemotePort));
}
示例#23
0
文件: fuse.cpp 项目: looncraz/haiku
static int
fuse_chmod(const char* path, mode_t mode)
{
	PRINTD("##chmod\n");
	fssh_struct_stat st;
	st.fssh_st_mode = mode;
	return _ERR(_kern_write_stat(-1, path, false, &st, sizeof(st),
			FSSH_B_STAT_MODE));
}
示例#24
0
文件: fuse.cpp 项目: looncraz/haiku
static int
fuse_chown(const char* path, uid_t uid, gid_t gid)
{
	PRINTD("##chown\n");
	fssh_struct_stat st;
	st.fssh_st_uid = uid;
	st.fssh_st_gid = gid;
	return _ERR(_kern_write_stat(-1, path, false, &st, sizeof(st),
			FSSH_B_STAT_UID|FSSH_B_STAT_GID));
}
示例#25
0
文件: fuse.cpp 项目: looncraz/haiku
static int
fuse_readlink(const char* path, char* buffer, size_t size)
{
	PRINTD("##readlink\n");
	fssh_size_t n_size = size - 1;
	fssh_status_t st = _kern_read_link(-1, path, buffer, &n_size);
	if (st >= FSSH_B_OK)
		buffer[n_size] = '\0';
	return _ERR(st);
}
示例#26
0
static void popen_noshell_child_process(
	int pipefd_0, int pipefd_1,
	int read_pipe, int ignore_stderr,
	const char *file, const char * const *argv) {
	int closed_child_fd;
	int closed_pipe_fd;
	int dupped_child_fd;
	int pipefd[2] = {pipefd_0, pipefd_1};

	if (ignore_stderr) { /* ignore STDERR completely? */
		if (popen_noshell_reopen_fd_to_dev_null(STDERR_FILENO) != 0) _ERR(255, "popen_noshell_reopen_fd_to_dev_null(%d)", STDERR_FILENO);
	}

	if (read_pipe) {
		closed_child_fd = STDIN_FILENO;		/* re-open STDIN to /dev/null */
		closed_pipe_fd = 0;			/* close read end of pipe */
		dupped_child_fd = STDOUT_FILENO;	/* dup the other pipe end to STDOUT */
	} else {
		closed_child_fd = STDOUT_FILENO;	/* ignore STDOUT completely */
		closed_pipe_fd = 1;			/* close write end of pipe */
		dupped_child_fd = STDIN_FILENO;		/* dup the other pipe end to STDIN */
	}
	if (popen_noshell_reopen_fd_to_dev_null(closed_child_fd) != 0) {
		_ERR(255, "popen_noshell_reopen_fd_to_dev_null(%d)", closed_child_fd);
	}
	if (popen_noshell_close_and_dup(pipefd, closed_pipe_fd, dupped_child_fd) != 0) {
		_ERR(255, "popen_noshell_close_and_dup(%d ,%d)", closed_pipe_fd, dupped_child_fd);
	}

	execvp(file, (char * const *)argv);

	/* if we are here, exec() failed */

	warn("exec(\"%s\") inside the child", file);

	if (fflush(stdout) != 0) _ERR(255, "fflush(stdout)");
	if (fflush(stderr) != 0) _ERR(255, "fflush(stderr)");
	close(STDIN_FILENO);
	close(STDOUT_FILENO);
	close(STDERR_FILENO);

	_exit(255); // call _exit() and not exit(), or you'll have troubles in C++
}
示例#27
0
文件: fuse.cpp 项目: looncraz/haiku
int
fuse_getattr(const char* path, struct stat* stbuf)
{
	PRINTD("##getattr\n");
	struct fssh_stat f_stbuf;
	fssh_status_t status = _kern_read_stat(-1, path, false, &f_stbuf,
			sizeof(f_stbuf));
	fromFsshStatToStat(&f_stbuf, stbuf);
	if (gIsDebug)
		printf("GETATTR returned: %d\n", status);
	return _ERR(status);
}
示例#28
0
bool TcpChannel::Create()
{
    int error;
    int fd = Socket::Create(error);
    if(fd < 0)
    {
        _ERR("Create Socket fail!");
        return false;
    }

    if(!Socket::Bind(fd, Port_, error))
    {
        _ERR("Bind socket %d fail", fd);
        return false;
    }

    TcpIO_.reset(new IO(fd, EV_READ | EV_PERSIST));
    TcpIO_->SetCallback(std::bind(&TcpChannel::handleRead, this, std::placeholders::_1));

    return true;
}
示例#29
0
int  SqMod::work(CtxMod* pctx, CAN_RW rw)
{
    char   docu[512];
    char   docu_hash[512];
    struct stat forig;

    size_t chars = sprintf(docu,"%s%s%s", pctx->_dir_home,
                                          pctx->_url_path,
                                          pctx->_url_doc);

    _pctx = pctx;
    if(stat(docu, &forig)!=0) { //no file
        _pctx->socket_write(HTTP_ERR(docu), nHTTP_ERR);
        return _ERR(1);
    }

    int64_t  docu_hname = simple_hash(docu);
    sprintf(docu_hash,"%ssbin/_%020lld.pnut", _pctx->_dir_cache, docu_hname);
    struct stat fcahced={0};
    stat(docu_hash, &fcahced);
    if(forig.st_mtime != fcahced.st_mtime)
    {
        char   composed[FILENAME_MAX];

        sprintf(composed,"%stmp/_%08X%08X%s", _pctx->_dir_cache,
                                this, pthread_self(), _pctx->_url_doc);
        FILE* pf = fopen(composed,"wb");
        if(pf){
            int err = _include(docu, pf, forig.st_size);
            fclose(pf);
            if(0==err)
                return _runScript(composed, docu_hash, forig.st_mtime);
            unlink(composed);
        }
        _pctx->socket_write(HTTP_ERR(composed), nHTTP_ERR);
        return _ERR(1);

    }
    return _runScript(0, docu_hash, forig.st_mtime);
}
示例#30
0
文件: app_worker.c 项目: just-hu/zlmb
static char *
_str_printf(const char *format, ...)
{
    size_t length, size = BUFSIZ;
    char *str;
    va_list arg, ap;
    void *tmp = NULL;

    str = (char *)malloc(sizeof(char *) * (size + 1));
    if (!str) {
        _ERR("Memory allocate string.\n");
        return NULL;
    }

    memset(str, '\0', size + 1);

    va_start(arg, format);
    va_copy(ap, arg);

    length = vsnprintf(str, size, format, arg);
    if (length >= size) {
        size = length + 1;
        tmp = realloc(str, size);
        if (!tmp) {
            free(str);
            va_end(arg);
            va_end(ap);
            _ERR("Memory allocate string.\n");
            return NULL;
        }
        str = (char *)tmp;
        vsnprintf(str, size, format, ap);
    }

    va_end(arg);
    va_end(ap);

    return str;
}