本文整理汇总了C++中LS_ERROR函数的典型用法代码示例。如果您正苦于以下问题:C++ LS_ERROR函数的具体用法?C++ LS_ERROR怎么用?C++ LS_ERROR使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了LS_ERROR函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: get_first_addr
static bool
get_first_addr(const char* hostname,
const char* servname,
const struct addrinfo* hints,
struct sockaddr* addr,
size_t addr_len,
ls_err* err)
{
int status;
struct addrinfo* res, * p, * found;
bool ret = false;
if ( ( status = getaddrinfo(hostname, servname, hints, &res) ) != 0 )
{
if (err != NULL)
{
/* HACK. GAI errors on linux are negative, positive on OSX */
err->code = ls_err_gai(status);
err->message = gai_strerror(status);
err->function = __func__;
err->file = __FILE__;
err->line = __LINE__;
}
return false;
}
/* Take the first v6 address, otherwise take the first v4 address */
found = NULL;
for (p = res; p != NULL; p = p->ai_next)
{
if (p->ai_family == AF_INET6)
{
found = p;
break;
}
else if ( !found && (p->ai_family == AF_INET) )
{
found = p;
}
}
if (found)
{
if (addr_len < found->ai_addrlen)
{
LS_ERROR(err, LS_ERR_OVERFLOW);
}
else
{
memcpy(addr, found->ai_addr, found->ai_addrlen);
ret = true;
}
}
else
{
LS_ERROR(err, LS_ERR_NOT_FOUND);
}
freeaddrinfo(res);
return ret;
}
示例2: _logger
Server::Server(std::shared_ptr<Logger> logger)
: _logger(logger), _listenSock(-1), _epollFd(-1), _eventFd(-1),
_maxKeepAliveDrops(0),
_lameConnectionTimeoutSeconds(DefaultLameConnectionTimeoutSeconds),
_nextDeadConnectionCheck(0), _threadId(0), _terminate(false),
_expectedTerminate(false) {
_epollFd = epoll_create(10);
if (_epollFd == -1) {
LS_ERROR(_logger, "Unable to create epoll: " << getLastError());
return;
}
_eventFd = eventfd(0, EFD_NONBLOCK | EFD_CLOEXEC);
if (_eventFd == -1) {
LS_ERROR(_logger, "Unable to create event FD: " << getLastError());
return;
}
epoll_event eventWake = { EPOLLIN, { &_eventFd } };
if (epoll_ctl(_epollFd, EPOLL_CTL_ADD, _eventFd, &eventWake) == -1) {
LS_ERROR(_logger, "Unable to add wake socket to epoll: " << getLastError());
return;
}
}
示例3: sizeof
void Server::handleAccept() {
sockaddr_in address;
socklen_t addrLen = sizeof(address);
int fd = ::accept(_listenSock,
reinterpret_cast<sockaddr*>(&address),
&addrLen);
if (fd == -1) {
LS_ERROR(_logger, "Unable to accept: " << getLastError());
return;
}
if (!configureSocket(fd)) {
::close(fd);
return;
}
LS_INFO(_logger, formatAddress(address) << " : Accepted on descriptor " << fd);
Connection* newConnection = new Connection(_logger, *this, fd, address);
epoll_event event = { EPOLLIN, { newConnection } };
if (epoll_ctl(_epollFd, EPOLL_CTL_ADD, fd, &event) == -1) {
LS_ERROR(_logger, "Unable to add socket to epoll: " << getLastError());
delete newConnection;
::close(fd);
return;
}
_connections.insert(std::make_pair(newConnection, time(nullptr)));
}
示例4: LS_DBG_L
void LshttpdMain::gracefulRestart()
{
LS_DBG_L("Graceful Restart... ");
close(m_fdAdmin);
broadcastSig(SIGTERM, 1);
s_iRunning = 0;
m_pidFile.closePidFile();
m_pServer->passListeners();
int pid = fork();
if (!pid)
{
char achCmd[1024];
int fd = StdErrLogger::getInstance().getStdErr();
if (fd != 2)
close(fd);
int len = getFullPath("bin/litespeed", achCmd, 1024);
achCmd[len - 10] = 0;
chdir(achCmd);
achCmd[len - 10] = '/';
if (execl(achCmd, "litespeed", NULL))
LS_ERROR("Failed to start new instance of LiteSpeed Web server!");
exit(0);
}
if (pid == -1)
LS_ERROR("Failed to restart the server!");
}
示例5: LS_ERROR
XmlNode *ConfigCtx::parseFile(const char *configFilePath,
const char *rootTag)
{
char achError[4096];
XmlTreeBuilder tb;
XmlNode *pRoot = tb.parse(configFilePath, achError, 4095);
if (pRoot == NULL)
{
LS_ERROR(this, "%s", achError);
return NULL;
}
// basic validation
if (strcmp(pRoot->getName(), rootTag) != 0)
{
LS_ERROR(this, "%s: root tag expected: <%s>, real root tag : <%s>!\n",
configFilePath, rootTag, pRoot->getName());
delete pRoot;
return NULL;
}
#ifdef TEST_OUTPUT_PLAIN_CONF
char sPlainFile[512] = {0};
strcpy(sPlainFile, configFilePath);
strcat(sPlainFile, ".txt");
// plainconf::testOutputConfigFile( pRoot, sPlainFile );
#endif
return pRoot;
}
示例6: LS_ERROR
bool Server::configureSocket(int fd) const {
if (!makeNonBlocking(fd)) {
return false;
}
const int yesPlease = 1;
if (setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &yesPlease, sizeof(yesPlease)) == -1) {
LS_ERROR(_logger, "Unable to set reuse socket option: " << getLastError());
return false;
}
if (_maxKeepAliveDrops > 0) {
if (setsockopt(fd, SOL_SOCKET, SO_KEEPALIVE, &yesPlease, sizeof(yesPlease)) == -1) {
LS_ERROR(_logger, "Unable to enable keepalive: " << getLastError());
return false;
}
const int oneSecond = 1;
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPIDLE, &oneSecond, sizeof(oneSecond)) == -1) {
LS_ERROR(_logger, "Unable to set idle probe: " << getLastError());
return false;
}
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPINTVL, &oneSecond, sizeof(oneSecond)) == -1) {
LS_ERROR(_logger, "Unable to set idle interval: " << getLastError());
return false;
}
if (setsockopt(fd, IPPROTO_TCP, TCP_KEEPCNT, &_maxKeepAliveDrops, sizeof(_maxKeepAliveDrops)) == -1) {
LS_ERROR(_logger, "Unable to set keep alive count: " << getLastError());
return false;
}
}
return true;
}
示例7: copyFile
static int copyFile(const char *pSrc, const char *pDest)
{
int fd = open(pSrc, O_RDONLY);
if (fd == -1)
{
LS_ERROR("Can not open Awstats model configuration file[%s]: %s",
pSrc, strerror(errno));
return LS_FAIL;
}
int fdDest = open(pDest, O_RDWR | O_CREAT | O_TRUNC, 0644);
if (fdDest == -1)
{
LS_ERROR("Can not create file [%s], %s", pDest, strerror(errno));
close(fd);
return LS_FAIL;
}
int ret = 0;
int len;
char achBuf[8192];
while ((len = read(fd, achBuf, 8192)) > 0)
{
if (write(fdDest, achBuf, len) != len)
{
LS_ERROR("Can not write to file [%s], disk full?", pDest);
unlink(pDest);
ret = -1;
break;
}
}
close(fd);
close(fdDest);
return ret;
}
示例8: renameLogFile
int renameLogFile(const char *pLogPath, const char *pSrcSuffix,
const char *pDestSuffix)
{
struct stat st;
char achDest[1024];
char achSrc[1024];
ls_snprintf(achDest, sizeof(achDest), "%s%s", pLogPath, pDestSuffix);
if (ls_fio_stat(achDest, &st) == 0)
{
LS_ERROR("File already exists: [%s], Awstats updating"
" might be in progress.", achDest);
return LS_FAIL;
}
ls_snprintf(achSrc, sizeof(achSrc), "%s%s", pLogPath, pSrcSuffix);
if (ls_fio_stat(achSrc, &st) == -1)
{
LS_ERROR("Log file does not exist: [%s], cannot update"
" Awstats statistics", achSrc);
return LS_FAIL;
}
if (st.st_size == 0)
return LS_FAIL;
if (rename(achSrc, achDest) == -1)
{
LS_ERROR("Cannot rename file from [%s] to [%s]: %s",
achSrc, achDest, strerror(errno));
return LS_FAIL;
}
return 0;
}
示例9: sprintf
/***
* We try to make log available even if errorlog is not setup.
* So, at the beginning, we put the logs to StringList plainconf::errorLogList by call logToMem()
* once flushErrorLog() is called, it means errorlog is setup, and this function will save all
* the buffered logs to errorlog file.
* Then if logToMem still be called, it should not access the stringlist anymore,
* but just access the errorlog directly.
*/
void plainconf::logToMem(char errorLevel, const char *format, ...)
{
char buf[512];
sprintf(buf, "%c[PlainConf] ", errorLevel);
int len = strlen(buf);
if (gModuleList.size() > 0)
{
XmlNode *pCurNode = (XmlNode *)gModuleList.back();
sprintf(buf + len, "[%s:%s] ", pCurNode->getName(),
((pCurNode->getValue() == NULL) ? "" : pCurNode->getValue()));
}
len = strlen(buf);
va_list ap;
va_start(ap, format);
int ret = vsnprintf(buf + len, 512 - len, format, ap);
va_end(ap);
if (!bErrorLogSetup)
errorLogList.add(buf, ret + len);
else
{
if (errorLevel == LOG_LEVEL_ERR)
LS_ERROR(buf + 1);
else
LS_INFO(buf + 1);
}
}
示例10: snprintf
int SslContext::setMultiKeyCertFile(const char *pKeyFile, int iKeyType,
const char *pCertFile, int iCertType,
int chained)
{
int i, iCertLen, iKeyLen, iLoaded = 0;
char achCert[max_path_len], achKey[max_path_len];
const char *apExt[max_certs] = {"", ".rsa", ".dsa", ".ecc"};
char *pCertCur, *pKeyCur;
iCertLen = snprintf(achCert, max_path_len, "%s", pCertFile);
pCertCur = achCert + iCertLen;
iKeyLen = snprintf(achKey, max_path_len, "%s", pKeyFile);
pKeyCur = achKey + iKeyLen;
for (i = 0; i < max_certs; ++i)
{
snprintf(pCertCur, max_path_len - iCertLen, "%s", apExt[i]);
snprintf(pKeyCur, max_path_len - iKeyLen, "%s", apExt[i]);
if ((access(achCert, F_OK) == 0) && (access(achKey, F_OK) == 0))
{
if (setKeyCertificateFile(achKey, iKeyType, achCert, iCertType,
chained) == false)
{
LS_ERROR("Failed to load key file %s and cert file %s",
achKey, achCert);
return false;
}
iLoaded = 1;
}
}
return (iLoaded == 1);
}
示例11: tube_data
LS_API bool tube_data(tube *t, uint8_t *data, size_t len, ls_err *err)
{
// max size for CBOR preamble 19 bytes:
// 1(map|27) 8(length) 1(key:0) 1(bstr|27) 8(length)
//uint8_t preamble[19];
cn_cbor *map;
cn_cbor *cdata;
bool ret = false;
cn_cbor_context ctx;
assert(t);
if (len == 0) {
return tube_send(t, SPUD_DATA, false, false, NULL, 0, 0, err);
}
if (!_map_create(&ctx, &map, err)) {
return false;
}
// TODO: the whole point of the iov system is so that we don't have to copy
// the data here. Which we just did. Please fix.
if (!(cdata = cn_cbor_data_create(data, len, &ctx, NULL)) ||
!cn_cbor_mapput_int(map, 0, cdata, &ctx, NULL))
{
LS_ERROR(err, LS_ERR_NO_MEMORY);
goto cleanup;
}
ret = tube_send_cbor(t, SPUD_DATA, false, false, map, err);
cleanup:
ls_pool_destroy((ls_pool*)ctx.context);
return ret;
}
示例12: get_rand_buf
static bool
get_rand_buf(void* buf,
size_t sz,
ls_err* err)
{
#ifdef HAVE_ARC4RANDOM
UNUSED_PARAM(err);
arc4random_buf(buf, sz);
return true;
#elif defined(HAVE__DEV_URANDOM)
/* TODO: think about pre-reading entropy to avoid blocking I/O here. */
/* *certainly* don't open/close the file every time. */
/* Also, read these: */
/*
* http://insanecoding.blogspot.com/2014/05/a-good-idea-with-bad-usage-devurandom.html
* */
/* http://www.2uo.de/myths-about-urandom/ */
/* --- Yes. Move to openSSL or someting? */
FILE* rfile = fopen("/dev/urandom", "r");
size_t nread;
if (!rfile)
{
LS_ERROR(err, -errno);
return false;
}
nread = fread(buf, 1, sz, rfile);
fclose(rfile);
/* Only true if size is 1. (did not understand man page) */
/* If this is untrue, something horrible has happened, and we should just */
/* stop. */
return (nread == sz);
#else
#error New random source needed
#endif
}
示例13: LS_NOTICE
void LocalWorkerConfig::configExtAppUserGroup(const XmlNode *pNode,
int iType)
{
const char *pUser = pNode->getChildValue("extUser");
const char *pGroup = pNode->getChildValue("extGroup");
gid_t gid = -1;
struct passwd *pw = Daemonize::configUserGroup(pUser, pGroup, gid);
if (pw)
{
if ((int) gid == -1)
gid = pw->pw_gid;
if ((iType != EA_LOGGER)
&& ((pw->pw_uid < ServerProcessConfig::getInstance().getUidMin())
|| (gid < ServerProcessConfig::getInstance().getGidMin())))
{
LS_NOTICE(ConfigCtx::getCurConfigCtx(), "ExtApp suExec access denied,"
" UID or GID of VHost document root is smaller "
"than minimum UID, GID configured. ");
}
else
setUGid(pw->pw_uid, gid);
}
LS_ERROR(ConfigCtx::getCurConfigCtx(), "Invalid User Name(%s) or Group "
"Name(%s)!", pUser, pGroup);
}
示例14: while
int LshttpdMain::processAdminBuffer(char *p, char *pEnd)
{
while ((pEnd > p) && isspace(pEnd[-1]))
--pEnd;
if (pEnd - p < 14)
return LS_FAIL;
if (strncasecmp(pEnd - 14, "end of actions", 14) != 0)
{
LS_ERROR("[ADMIN] failed to read command, command buf len=%d",
(int)(pEnd - p));
return LS_FAIL;
}
pEnd -= 14;
int apply;
char *pLineEnd;
while (p < pEnd)
{
pLineEnd = (char *)memchr(p, '\n', pEnd - p);
if (pLineEnd == NULL)
pLineEnd = pEnd;
char *pTemp = pLineEnd;
while ((pLineEnd > p) && isspace(pLineEnd[-1]))
--pLineEnd;
*pLineEnd = 0;
if (processAdminCmd(p, pLineEnd, apply))
break;
p = pTemp + 1;
}
m_pBuilder->releaseConfigXmlTree();
if (s_iRunning > 0)
m_pServer->generateStatusReport();
if (apply)
applyChanges();
return 0;
}
示例15: while
int HttpMime::processOneLine(const char *pFilePath, char *pLine,
int lineNo)
{
pLine = StringTool::strTrim(pLine);
if (strlen(pLine) == 0)
return 0;
char *pType = pLine ;
char *pDesc ;
const char *reason;
while (1)
{
if ((pDesc = strchr(pLine, '=')) == NULL)
{
reason = "missing '='";
break;
}
*pDesc = '\0';
++ pDesc;
if (!addUpdateMIME(pType, pDesc, reason, 0))
break;
else
return 0;
}
LS_ERROR("[MIME] File %s line %d: (%s) - \"%s\"",
pFilePath, lineNo, reason, pLine);
return LS_FAIL;
}