本文整理汇总了C++中setlogmask函数的典型用法代码示例。如果您正苦于以下问题:C++ setlogmask函数的具体用法?C++ setlogmask怎么用?C++ setlogmask使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了setlogmask函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: options
//.........这里部分代码省略.........
{ "listen-ng", 'n', 0, G_OPTION_ARG_STRING, &listenngs, "UDP port to listen on, NG protocol", "[IP46:]PORT" },
{ "tos", 'T', 0, G_OPTION_ARG_INT, &tos, "Default TOS value to set on streams", "INT" },
{ "timeout", 'o', 0, G_OPTION_ARG_INT, &timeout, "RTP timeout", "SECS" },
{ "silent-timeout",'s',0,G_OPTION_ARG_INT, &silent_timeout,"RTP timeout for muted", "SECS" },
{ "pidfile", 'p', 0, G_OPTION_ARG_STRING, &pidfile, "Write PID to file", "FILE" },
{ "foreground", 'f', 0, G_OPTION_ARG_NONE, &foreground, "Don't fork to background", NULL },
{ "port-min", 'm', 0, G_OPTION_ARG_INT, &port_min, "Lowest port to use for RTP", "INT" },
{ "port-max", 'M', 0, G_OPTION_ARG_INT, &port_max, "Highest port to use for RTP", "INT" },
{ "redis", 'r', 0, G_OPTION_ARG_STRING, &redisps, "Connect to Redis database", "IP:PORT" },
{ "redis-db", 'R', 0, G_OPTION_ARG_INT, &redis_db, "Which Redis DB to use", "INT" },
{ "b2b-url", 'b', 0, G_OPTION_ARG_STRING, &b2b_url, "XMLRPC URL of B2B UA" , "STRING" },
{ "log-level", 'L', 0, G_OPTION_ARG_INT, (void *)&log_level, "Mask log priorities above this level", "INT" },
{ "log-facility", 0, 0, G_OPTION_ARG_STRING, &log_facility_s, "Syslog facility to use for logging", "daemon|local0|...|local7"},
{ "log-stderr", 'E', 0, G_OPTION_ARG_NONE, &_log_stderr, "Log on stderr instead of syslog", NULL },
{ "xmlrpc-format", 'x', 0, G_OPTION_ARG_INT, &xmlrpc_fmt, "XMLRPC timeout request format to use. 0: SEMS DI, 1: call-id only", "INT" },
{ NULL, }
};
GOptionContext *c;
GError *er = NULL;
c = g_option_context_new(" - next-generation media proxy");
g_option_context_add_main_entries(c, e, NULL);
if (!g_option_context_parse(c, argc, argv, &er))
die("Bad command line: %s\n", er->message);
if (version)
die("%s\n", RTPENGINE_VERSION);
if (!ipv4s)
die("Missing option --ip\n");
if (!listenps && !listenudps && !listenngs)
die("Missing option --listen-tcp, --listen-udp or --listen-ng\n");
ipv4 = inet_addr(ipv4s);
if (ipv4 == -1)
die("Invalid IPv4 address (--ip)\n");
if (adv_ipv4s) {
adv_ipv4 = inet_addr(adv_ipv4s);
if (adv_ipv4 == -1)
die("Invalid IPv4 address (--advertised-ip)\n");
}
if (ipv6s) {
if (smart_pton(AF_INET6, ipv6s, &ipv6) != 1)
die("Invalid IPv6 address (--ip6)\n");
}
if (adv_ipv6s) {
if (smart_pton(AF_INET6, adv_ipv6s, &adv_ipv6) != 1)
die("Invalid IPv6 address (--advertised-ip6)\n");
}
if (listenps) {
if (parse_ip_port(&listenp, &listenport, listenps))
die("Invalid IP or port (--listen-tcp)\n");
}
if (listenudps) {
if (parse_ip6_port(&udp_listenp, &udp_listenport, listenudps))
die("Invalid IP or port (--listen-udp)\n");
}
if (listenngs) {
if (parse_ip6_port(&ng_listenp, &ng_listenport, listenngs))
die("Invalid IP or port (--listen-ng)\n");
}
if (tos < 0 || tos > 255)
die("Invalid TOS value\n");
if (timeout <= 0)
timeout = 60;
if (silent_timeout <= 0)
silent_timeout = 3600;
if (redisps) {
if (parse_ip_port(&redis_ip, &redis_port, redisps) || !redis_ip)
die("Invalid IP or port (--redis)\n");
if (redis_db < 0)
die("Must specify Redis DB number (--redis-db) when using Redis\n");
}
if (xmlrpc_fmt < 0 || xmlrpc_fmt > 1) {
die("Invalid XMLRPC format\n");
}
if ((log_level < LOG_EMERG) || (log_level > LOG_DEBUG))
die("Invalid log level (--log_level)\n");
setlogmask(LOG_UPTO(log_level));
if (log_facility_s) {
if (!parse_log_facility(log_facility_s, &_log_facility)) {
print_available_log_facilities();
die ("Invalid log facility '%s' (--log-facility)\n", log_facility_s);
}
}
if (_log_stderr) {
write_log = log_to_stderr;
}
}
开发者ID:rockxcn,项目名称:rtpengine,代码行数:101,代码来源:main.c
示例2: main
int main (int argc, char *argv[]) {
char *cmd;
struct sigaction sa;
int fifofd;
long int pidslave[3];
// char fifoslave[512];
struct harvester *sh;
pthread_t *ht;
pthread_attr_t ha;
GError *error = NULL;
GOptionContext *context;
static int use_daemonize = 1;
static GOptionEntry entries[] = {
{"disable-daemonize", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &use_daemonize, "do not daemonize", NULL},
{NULL}
};
context = g_option_context_new ("launch seed harvester");
g_option_context_add_main_entries (context, entries, NULL);
g_option_context_set_summary(context, "xmimsim-harvester: a daemon that gathers seeds from /dev/random...");
if (!g_option_context_parse (context, &argc, &argv, &error)) {
g_print ("option parsing failed: %s\n", error->message);
exit (1);
}
if ((cmd = strrchr(argv[0], '/')) == NULL)
cmd = argv[0];
else
cmd++;
if (use_daemonize)
daemonize(cmd);
else {
openlog(cmd, LOG_CONS | LOG_PID, LOG_DAEMON);
setlogmask(LOG_UPTO(LOG_DEBUG));
}
if (already_running()) {
syslog(LOG_ERR, "daemon already running");
exit(1);
}
sa.sa_handler = sigterm;
sigfillset(&sa.sa_mask);
//sigaddset(&sa.sa_mask, SIGTERM);
sa.sa_flags=0;
if (sigaction(SIGTERM, &sa, NULL) < 0) {
syslog(LOG_ERR, "can't catch SIGTERM: %s", strerror(errno));
exit(1);
}
if (sigaction(SIGSEGV, &sa, NULL) < 0) {
syslog(LOG_ERR, "can't catch SIGSEGV: %s", strerror(errno));
exit(1);
}
if (sigaction(SIGBUS, &sa, NULL) < 0) {
syslog(LOG_ERR, "can't catch SIGBUS: %s", strerror(errno));
exit(1);
}
if (sigaction(SIGILL, &sa, NULL) < 0) {
syslog(LOG_ERR, "can't catch SIGILL: %s", strerror(errno));
exit(1);
}
if (sigaction(SIGQUIT, &sa, NULL) < 0) {
syslog(LOG_ERR, "can't catch SIGQUIT: %s", strerror(errno));
exit(1);
}
sa.sa_handler = sighup;
sigemptyset(&sa.sa_mask);
sigaddset(&sa.sa_mask, SIGHUP);
sa.sa_flags=0;
if (sigaction(SIGHUP, &sa, NULL) < 0) {
syslog(LOG_ERR, "can't catch SIGHUP: %s", strerror(errno));
exit(1);
}
if (xmi_start_random_acquisition_dev() != 1) {
syslog(LOG_ERR,"xmi_start_random_acquisition_dev error");
exit(1);
}
syslog(LOG_INFO,"daemon running succesfully");
pthread_attr_init(&ha);
pthread_attr_setdetachstate(&ha,PTHREAD_CREATE_DETACHED);
while (1) {
//create fifo
if (mkfifo(FIFOMASTER, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) == -1) {
syslog(LOG_ERR,"Could not create named link" FIFOMASTER ": %s",strerror(errno));
exit(1);
}
if ((fifofd = open(FIFOMASTER,O_RDONLY)) == -1) {
syslog(LOG_ERR,"Could not open named link" FIFOMASTER ": %s",strerror(errno));
exit(1);
}
//.........这里部分代码省略.........
开发者ID:tschoonj,项目名称:xmimsim,代码行数:101,代码来源:xmimsim-harvester.c
示例3: main
/*
* chat [-esSvV] [-f chat-file] [-r report-file] [-t timeout]
* [-T phone-number] [-U phone-number2] [chat-script]
* where chat-script has the form:
* [...[[expect[-send[-expect...]] send expect[-send[-expect]] ...]]]
*
* Perform a UUCP-dialer-like chat script on stdin and stdout.
*/
int
main(int argc, char *argv[])
{
int option;
tzset();
while ((option = getopt(argc, argv, "ef:r:sSt:T:U:vV")) != -1) {
switch (option) {
case 'e':
++echo;
break;
case 'f':
if (chat_file != NULL)
free(chat_file);
chat_file = copy_of(optarg);
break;
case 'r':
if (report_fp != NULL)
fclose(report_fp);
if (report_file != NULL)
free(report_file);
report_file = copy_of(optarg);
report_fp = fopen(report_file, "a");
if (report_fp != NULL) {
if (verbose)
fprintf(report_fp, "Opening \"%s\"...\n", report_file);
} else
fatal(2, "cannot open \"%s\" for appending", report_file);
break;
case 's':
++to_stderr;
break;
case 'S':
to_log = 0;
break;
case 't':
timeout = atoi(optarg);
break;
case 'T':
if (phone_num != NULL)
free(phone_num);
phone_num = copy_of(optarg);
break;
case 'U':
if (phone_num2 != NULL)
free(phone_num2);
phone_num2 = copy_of(optarg);
break;
case 'v':
++verbose;
break;
case 'V':
++Verbose;
break;
default:
usage();
break;
}
}
argc -= optind;
argv += optind;
/*
* Default the report file to the stderr location
*/
if (report_fp == NULL)
report_fp = stderr;
if (to_log) {
openlog("chat", LOG_PID | LOG_NDELAY, LOG_LOCAL2);
if (verbose)
setlogmask(LOG_UPTO(LOG_INFO));
else
setlogmask(LOG_UPTO(LOG_WARNING));
}
if (chat_file != NULL) {
if (*argv != NULL)
usage();
//.........这里部分代码省略.........
开发者ID:2asoft,项目名称:freebsd,代码行数:101,代码来源:chat.c
示例4: vconsoleLogger
void vconsoleLogger(int priority, const char *format, va_list optional_arguments) {
/*int n = 0;*/
const int saved_errno = errno;
const int LogMask = setlogmask(0);
/* no cancellation point is currently used in this function
* (according to Advanced Programming in the Unix Environment 2nd ed p411)
* so there is no thread cancellation clean-up handlers defined
*/
/* Check for invalid bits. */
if (unlikely(priority & ~(LOG_PRIMASK | LOG_FACMASK))) {
/*syslog(INTERNALLOG,
"syslog: unknown facility/priority: %x", pri);*/
WARNING_MSG("unknown facility/priority: %x", priority);
priority &= LOG_PRIMASK | LOG_FACMASK;
}
/* Check priority against setlogmask values. */
if ((LOG_MASK (LOG_PRI (priority)) & LogMask) != 0) {
char *buf = 0;
size_t bufsize = 1024;
/*char logFormat[1024];
char *cursor = logFormat;*/
FILE *f = open_memstream(&buf, &bufsize);
if (f != NULL) {
struct tm now_tm;
time_t now;
(void) time(&now);
/*cursor += strftime(cursor,sizeof(logFormat),"%h %e %T ",localtime_r(&now, &now_tm));*/
f->_IO_write_ptr += strftime(f->_IO_write_ptr,f->_IO_write_end - f->_IO_write_ptr,"%h %e %T ",localtime_r(&now, &now_tm));
if (LogTag) {
//cursor += sprintf (cursor,"%s: ",LogTag);
fprintf(f,"%s: ",LogTag);
}
if (LogStat & LOG_PID) {
if (LogStat & LOG_TID) {
const pid_t tid = gettid();
/*cursor += sprintf (cursor, "[%d:%d]", (int) getpid (),(int) tid);*/
fprintf(f,"[%d:%d]", (int) getpid (),(int) tid);
} else {
/*cursor += sprintf (cursor, "[%d]", (int) getpid ());*/
fprintf(f,"[%d]", (int) getpid ());
}
}
if (LogStat & LOG_RDTSC) {
const unsigned long long int t = rdtsc();
/*cursor += sprintf (cursor, "(%llu)",t);*/
fprintf(f,"(%llu)",t);
} /* (LogStat & LOG_RDTSC) */
if (LogStat & LOG_CLOCK) {
#if HAVE_CLOCK_GETTIME
struct timespec timeStamp;
if (clock_gettime(CLOCK_MONOTONIC,&timeStamp) == 0) {
/*cursor += sprintf (cursor, "(%lu.%.9d)",timeStamp.tv_sec,timeStamp.tv_nsec);*/
fprintf(f,"(%lu.%.9d)",timeStamp.tv_sec,timeStamp.tv_nsec);
} else {
const int error = errno;
ERROR_MSG("clock_gettime CLOCK_MONOTONIC error %d (%m)",error);
}
#else
static unsigned int alreadyPrinted = 0; /* to avoid to print this error msg on each call */
if (unlikely(0 == alreadyPrinted)) {
ERROR_MSG("clock_gettime not available on this system");
alreadyPrinted = 1;
}
#endif
} /* (LogStat & LOG_CLOCK) */
if (LogStat & LOG_LEVEL) {
switch(LOG_PRI(priority)) {
case LOG_EMERG:
/*cursor += snprintf(cursor,sizeof(logFormat) - (cursor - logFormat),"* Emergency * %s",format);*/
fprintf(f,"[EMERG] %s",format);
break;
case LOG_ALERT:
/*cursor += snprintf(cursor,sizeof(logFormat) - (cursor - logFormat),"* Alert * %s",format);*/
fprintf(f,"[ALERT] %s",format);
break;
case LOG_CRIT:
/*cursor += snprintf(cursor,sizeof(logFormat) - (cursor - logFormat),"* Critical * %s",format);*/
fprintf(f,"[CRIT] %s",format);
break;
case LOG_ERR:
/*cursor += snprintf(cursor,sizeof(logFormat) - (cursor - logFormat),"* Error * %s",format);*/
fprintf(f,"[ERROR] %s",format);
break;
case LOG_WARNING:
/*cursor += snprintf(cursor,sizeof(logFormat) - (cursor - logFormat),"* Warning * %s",format);*/
fprintf(f,"[WARNING] %s",format);
break;
case LOG_NOTICE:
/*cursor += snprintf(cursor,sizeof(logFormat) - (cursor - logFormat),"* Notice * %s",format); */
fprintf(f,"[NOTICE] %s",format);
break;
//.........这里部分代码省略.........
开发者ID:Oliviers-OSS,项目名称:dbgflags,代码行数:101,代码来源:consoleLogger.c
示例5: main
int main(int argc, char *argv[]) {
/* variables used on multiple locations are set at the top of the function */
int status = 0;
int daemon = 0;
char *customConfigLocation = NULL;
setlogmask(LOG_UPTO(LOG_NOTICE));
int option = 0;
opterr = 0;
while((option = getopt(argc, argv, "v:Vhdi:")) != -1)
switch(option) {
case 'v':
if(strcmp(optarg, "0") == 0)
setlogmask(LOG_UPTO(LOG_ERR));
else if(strcmp(optarg, "1") == 0)
setlogmask(LOG_UPTO(LOG_INFO));
else if(strcmp(optarg, "2") == 0)
setlogmask(LOG_UPTO(LOG_DEBUG));
break;
case 'V':
fprintf(stdout, "%s %s\n\n%s\n", PROGRAM_NAME, PROGRAM_VERSION, PROGRAM_LEGAL);
exit(EXIT_SUCCESS);
case 'h':
fprintf(stdout, "Usage: %s %s", argv[0], TEXT_USAGE);
exit(EXIT_SUCCESS);
case 'd':
daemon = 1;
break;
case 'i':
customConfigLocation = optarg;
break;
case '?':
if(optopt == 'i')
fprintf(stderr, "You forgot to include a path with option '-%c'.\n", optopt);
else if(optopt == 'v')
setlogmask(LOG_UPTO(LOG_INFO));
else if(isprint(optopt))
fprintf(stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf(stderr, "Unknown option character `\\x%x'.\n", optopt);
exit(EXIT_FAILURE);
default:
exit(EXIT_FAILURE);
}
/* All files created without revoked permissions (thus result: 0666) */
umask(0);
if(daemon) {
if((status = daemonize()) == EXIT_FAILURE)
exit(EXIT_FAILURE);
}
else {
/* Setup syslog, print also to stderr, and give notice of execution */
openlog(PROGRAM_NAME, LOG_NDELAY | LOG_PID | LOG_PERROR, LOG_DAEMON);
syslog(LOG_NOTICE, "Program started by User %d", getuid());
}
/* Lock process and print pid to lock file */
if((lock_file = open(LOCKFILE, O_RDWR|O_CREAT|O_CLOEXEC, LOCKMODE)) < 0) {
syslog(LOG_ERR, "Failed to open lock file: %s", strerror(errno));
closelog();
exit(EXIT_FAILURE);
}
if(lockf(lock_file, F_TLOCK, 0) < 0) {
syslog(LOG_WARNING, "Exiting: only one instance of this application can run: %s", strerror(errno));
closelog();
exit(EXIT_SUCCESS);
}
ftruncate(lock_file, 0);
dprintf(lock_file, "%d\n", getpid());
/* Get main thread id and make it the default value for all other threads.
* If a thread has been initialized, it changes the default value and the
* termination handler knows whether to cancel it or not. */
mainThread = statusQueryThread = watchMixerThread = interfaceListenThread = pthread_self();
common_data.process = NULL;
common_data.interface = NULL;
common_data.volume = NULL;
struct sigaction signal_action;
signal_action.sa_handler = terminate;
sigfillset(&signal_action.sa_mask);
signal_action.sa_flags = 0;
if(sigaction(SIGINT, &signal_action, NULL) < 0 || sigaction(SIGTERM, &signal_action, NULL) < 0) {
syslog(LOG_ERR, "Failed to ignore signals: %s", strerror(errno));
closelog();
exit(EXIT_FAILURE);
}
/* Execute synchronatord function, if all goes well, it will never return */
status = synchronatord(customConfigLocation);
syslog(LOG_ERR, "Exiting: %i", status);
closelog();
exit(status);
} /* end main */
开发者ID:muelmatt,项目名称:synchronator,代码行数:98,代码来源:synchronator.c
示例6: benchmark
/**
* @brief benchmark
* cbenchmark的入口
* 通过读取参数中的信息
* 开始执行
*
* @param param
* cbenchmark全局信息
*/
void benchmark(void* param)
{
struct bench * bp = bm_init(param);
struct timeval tvStart,tvEnd;
float dif = 0;
float tps = 0;
if(bp->mode & BM_MODE_SHARE && (bp->libs != NULL)){
init_mw(bp);
}
//参数文件初始化
if(bp->infile != NULL){
init_proc_param(bp);
}
//日志初始化
openlog(bp->log.name, LOG_PID|LOG_CONS, LOG_USER);
setlogmask(LOG_UPTO(bp->log.level));
/*
* 为cbenchmark主进程注册信号处理函数
* 之后会对每个子进程也注册类似函数
* 这些信号处理统一由cb_trap管理
*/
/*
* SIGINT信号处理当用户通过Ctrl+C发送中断信息给主进程后
* 主进程将让子进程停止工作
* 同时自己也逐渐结束
*/
if(signal(SIGINT,cb_trap) == SIG_ERR){
fprintf(stderr,"Register signal trap faile.");
};
//起始时间
gettimeofday(&tvStart,NULL);
dispatch(bp);
//如果以定时器模式执行
//则启动定时器
//并设置回掉函数
//让其对子进程发送SIGUSR1信号
if(bp->mode & BM_MODE_TIMER){
timer(&bp->time,cb_kill_children_break,NULL);
}
//等待所有进程终止
waitall((void *)bp);
//终止时间
gettimeofday(&tvEnd,NULL);
dif = (tvEnd.tv_sec-tvStart.tv_sec) + (tvEnd.tv_usec-tvStart.tv_usec)/1000000.0;
analyse((void *)bp,dif);
//关闭日志
closelog();
//关闭动态库
if(bp->mode & BM_MODE_SHARE && (bp->libs != NULL)){
destroy_mw(bp);
}
}
开发者ID:charlescui,项目名称:CBenchmark,代码行数:74,代码来源:cbenchmark.c
示例7: main
/* Application Launcher Daemon entrypoint */
int main(int argc, char **argv)
{
/* return code */
int l_ret;
/* logging mechanism */
int log = LOG_MASK (LOG_ERR) | LOG_MASK (LOG_INFO);
#ifdef DEBUG
log = log | LOG_MASK(LOG_DEBUG);
#endif
openlog ("AL-DAEMON", 0x0, LOG_USER);
setlogmask(log);
/* handle signals */
signal(SIGTERM, AlSignalHandler);
signal(SIGKILL, AlSignalHandler);
/* parse cli options */
AlParseCLIOptions(argc, argv);
if (g_stop) {
AlDaemonShutdown();
return 0;
}
if (g_start) {
/* daemonize the application launcher */
AlDaemonize();
log_message("Daemon process was started !\n", 0);
#ifdef USE_LAST_USER_MODE
/* initialise the last user mode */
if(!(l_ret=InitializeLastUserMode())){
log_error_message("Last user mode initialization failed !\n", 0);
}
else { log_message("Last user mode initialized. Listening for method calls ....\n", 0);
}
#endif
/* initialize SRM Daemon */
if(!initialize_al_dbus()){
log_error_message("Failed to initialize AL Daemon!\n Stopping daemon ...", 0);
terminate_al_dbus();
return 1;
}
/* start the signal dispatching thread */
al_dbus_signal_dispatcher();
/* main loop */
GMainLoop *l_loop = NULL;
if(!(l_loop = g_main_loop_new(NULL, FALSE))){
log_error_message("Error creating main loop !\n", 0);
exit(1);
}
/* run the main loop */
g_main_loop_run(l_loop);
}
log_message("Daemon exited !\n", 0);
/* close logging mechanism */
closelog ();
/* free res */
terminate_al_dbus();
return 0;
}
开发者ID:Life-Cycle-Management,项目名称:si-applauncher,代码行数:69,代码来源:al-daemon.c
示例8: syslog_setlogmask
static int
syslog_setlogmask(lua_State *L)
{
lua_pushinteger(L, setlogmask(luaL_checkint(L, 1)));
return 1;
}
开发者ID:Hooman3,项目名称:minix,代码行数:6,代码来源:syslog.c
示例9: init_logging
/*
* Initialize the logging
*
* Called once per process, including forked children.
*/
void
init_logging(
const char * name,
u_int32 def_syslogmask,
int is_daemon
)
{
static int was_daemon;
const char * cp;
const char * pname;
/*
* ntpd defaults to only logging sync-category events, when
* NLOG() is used to conditionalize. Other libntp clients
* leave it alone so that all NLOG() conditionals will fire.
* This presumes all bits lit in ntp_syslogmask can't be
* configured via logconfig and all lit is thereby a sentinel
* that ntp_syslogmask is still at its default from libntp,
* keeping in mind this function is called in forked children
* where it has already been called in the parent earlier.
* Forked children pass 0 for def_syslogmask.
*/
if (INIT_NTP_SYSLOGMASK == ntp_syslogmask &&
0 != def_syslogmask)
ntp_syslogmask = def_syslogmask; /* set more via logconfig */
/*
* Logging. This may actually work on the gizmo board. Find a name
* to log with by using the basename
*/
cp = strrchr(name, DIR_SEP);
if (NULL == cp)
pname = name;
else
pname = 1 + cp; /* skip DIR_SEP */
progname = estrdup(pname);
#ifdef SYS_WINNT /* strip ".exe" */
cp = strrchr(progname, '.');
if (NULL != cp && !strcasecmp(cp, ".exe"))
progname[cp - progname] = '\0';
#endif
#if !defined(VMS)
if (is_daemon)
was_daemon = TRUE;
# ifndef LOG_DAEMON
openlog(progname, LOG_PID);
# else /* LOG_DAEMON */
# ifndef LOG_NTP
# define LOG_NTP LOG_DAEMON
# endif
openlog(progname, LOG_PID | LOG_NDELAY, (was_daemon)
? LOG_NTP
: 0);
# ifdef DEBUG
if (debug)
setlogmask(LOG_UPTO(LOG_DEBUG));
else
# endif /* DEBUG */
setlogmask(LOG_UPTO(LOG_DEBUG)); /* @@@ was INFO */
# endif /* LOG_DAEMON */
#endif /* !VMS */
}
开发者ID:enukane,项目名称:netbsd-src,代码行数:70,代码来源:msyslog.c
示例10: main
//.........这里部分代码省略.........
}
gLogLevel=intarg;
break;
case 'V':
// version
break;
case '?':
case 'h':
usage(0);
break;
default:
usage(1);
break;
}
}
/* install handlers */
signal( SIGPIPE, SIG_IGN );
signal(SIGCHLD,sigchld_handler); /* ignore child */
signal(SIGHUP,kill_handler); /* catch hangup signal */
signal(SIGTERM,kill_handler); /* catch kill signal */
/*
Initialize Windows sockets (no-op on other platforms)
*/
WSAStartup(MAKEWORD(1,1), &wsaData);
if(!nosysl) {
openlog("matrixtunnel", LOG_PID, LOG_DAEMON);
setlogmask(LOG_UPTO(gLogLevel));
}
/*
Initialize the MatrixSSL Library, and read in the public key (certificate)
and private key.
*/
if (matrixSslOpen() < 0) {
ELOG("matrixSslOpen failed, exiting...");
exit(1);
}
/*
Standard PEM files
*/
if (matrixSslReadKeys(&keys, certfile, keyfile, NULL, NULL) < 0) {
ELOG("Error reading or parsing %s or %s, exiting...",
certfile, keyfile);
exit(1);
}
// go to background
if(!nofork) {
daemonize();
}
/*
Create the listen socket
*/
if ((srv_fd = socketListen(srv_port, &status)) == INVALID_SOCKET) {
ELOG("Cannot listen on port %d, exiting...", srv_port);
exit(1);
}
开发者ID:cmtsij,项目名称:Vizio_XWR100_GPL,代码行数:67,代码来源:matrixtunnel.c
示例11: main
int
main(int argc, char *argv[])
{
int s, rtsock, maxfd, ch;
int once = 0;
struct timeval *timeout;
struct fd_set fdset;
char *argv0;
const char *opts;
/*
* Initialization
*/
argv0 = argv[0];
/* get option */
if (argv0 && argv0[strlen(argv0) - 1] != 'd') {
fflag = 1;
once = 1;
opts = "adD";
} else
opts = "adDfm1";
while ((ch = getopt(argc, argv, opts)) != -1) {
switch (ch) {
case 'a':
aflag = 1;
break;
case 'd':
dflag = 1;
break;
case 'D':
dflag = 2;
break;
case 'f':
fflag = 1;
break;
case 'm':
mobile_node = 1;
break;
case '1':
once = 1;
break;
default:
usage(argv0);
/*NOTREACHED*/
}
}
argc -= optind;
argv += optind;
if (aflag) {
int i;
if (argc != 0) {
usage(argv0);
/*NOTREACHED*/
}
argv = autoifprobe();
if (!argv) {
errx(1, "could not autoprobe interface");
/*NOTREACHED*/
}
for (i = 0; argv[i]; i++)
;
argc = i;
}
if (argc == 0) {
usage(argv0);
/*NOTREACHED*/
}
/* set log level */
if (dflag == 0)
log_upto = LOG_NOTICE;
if (!fflag) {
char *ident;
ident = strrchr(argv0, '/');
if (!ident)
ident = argv0;
else
ident++;
openlog(ident, LOG_NDELAY|LOG_PID, LOG_DAEMON);
if (log_upto >= 0)
setlogmask(LOG_UPTO(log_upto));
}
#ifndef HAVE_ARC4RANDOM
/* random value initilization */
srandom((u_long)time(NULL));
#endif
/* warn if accept_rtadv is down */
if (!getinet6sysctl(IPV6CTL_ACCEPT_RTADV))
warnx("kernel is configured not to accept RAs");
/* warn if forwarding is up */
if (getinet6sysctl(IPV6CTL_FORWARDING))
warnx("kernel is configured as a router, not a host");
//.........这里部分代码省略.........
开发者ID:kusumi,项目名称:DragonFlyBSD,代码行数:101,代码来源:rtsold.c
示例12: main
int main(int argc, char **argv)
{
char cert_path[1024];
char key_path[1024];
int n = 0;
int use_ssl = 0;
int opts = 0;
char interface_name[128] = "";
const char *iface = NULL;
#ifndef WIN32
int syslog_options = LOG_PID | LOG_PERROR;
#endif
unsigned int ms, oldms = 0;
struct lws_context_creation_info info;
int debug_level = 7;
#ifndef LWS_NO_DAEMONIZE
int daemonize = 0;
#endif
memset(&info, 0, sizeof info);
info.port = 7681;
while (n >= 0) {
n = getopt_long(argc, argv, "eci:hsap:d:Dr:", options, NULL);
if (n < 0)
continue;
switch (n) {
case 'e':
opts |= LWS_SERVER_OPTION_LIBEV;
break;
#ifndef LWS_NO_DAEMONIZE
case 'D':
daemonize = 1;
#ifndef WIN32
syslog_options &= ~LOG_PERROR;
#endif
break;
#endif
case 'd':
debug_level = atoi(optarg);
break;
case 's':
use_ssl = 1;
break;
case 'a':
opts |= LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT;
break;
case 'p':
info.port = atoi(optarg);
break;
case 'i':
strncpy(interface_name, optarg, sizeof interface_name);
interface_name[(sizeof interface_name) - 1] = '\0';
iface = interface_name;
break;
case 'c':
close_testing = 1;
fprintf(stderr, " Close testing mode -- closes on "
"client after 50 dumb increments"
"and suppresses lws_mirror spam\n");
break;
case 'r':
resource_path = optarg;
printf("Setting resource path to \"%s\"\n", resource_path);
break;
case 'h':
fprintf(stderr, "Usage: test-server "
"[--port=<p>] [--ssl] "
"[-d <log bitfield>] "
"[--resource_path <path>]\n");
exit(1);
}
}
#if !defined(LWS_NO_DAEMONIZE) && !defined(WIN32)
/*
* normally lock path would be /var/lock/lwsts or similar, to
* simplify getting started without having to take care about
* permissions or running as root, set to /tmp/.lwsts-lock
*/
if (daemonize && lws_daemonize("/tmp/.lwsts-lock")) {
fprintf(stderr, "Failed to daemonize\n");
return 1;
}
#endif
signal(SIGINT, sighandler);
#ifndef WIN32
/* we will only try to log things according to our debug_level */
setlogmask(LOG_UPTO (LOG_DEBUG));
openlog("lwsts", syslog_options, LOG_DAEMON);
#endif
/* tell the library what debug level to emit and to send it to syslog */
lws_set_log_level(debug_level, lwsl_emit_syslog);
lwsl_notice("libwebsockets test server - "
"(C) Copyright 2010-2014 Andy Green <[email protected]> - "
//.........这里部分代码省略.........
开发者ID:BTCDDev,项目名称:supernet,代码行数:101,代码来源:test-server.c
示例13: main
int main(int argc, char **argv)
{
int i;
struct sigaction sa, osa;
FILE *pf;
int r;
prog_name= strrchr(argv[0], '/');
if (prog_name == nil) prog_name= argv[0]; else prog_name++;
i= 1;
while (i < argc && argv[i][0] == '-') {
char *opt= argv[i++] + 1;
if (opt[0] == '-' && opt[1] == 0) break; /* -- */
while (*opt != 0) switch (*opt++) {
case 'd':
if (*opt == 0) {
debug= 1;
} else {
debug= strtoul(opt, &opt, 10);
if (*opt != 0) usage();
}
break;
default:
usage();
}
}
if (i != argc) usage();
selectlog(SYSLOG);
openlog(prog_name, LOG_PID, LOG_DAEMON);
setlogmask(LOG_UPTO(LOG_INFO));
/* Save process id. */
if ((pf= fopen(PIDFILE, "w")) == NULL) {
fprintf(stderr, "%s: %s\n", PIDFILE, strerror(errno));
exit(1);
}
fprintf(pf, "%d\n", getpid());
if (ferror(pf) || fclose(pf) == EOF) {
fprintf(stderr, "%s: %s\n", PIDFILE, strerror(errno));
exit(1);
}
sigemptyset(&sa.sa_mask);
sa.sa_flags= 0;
sa.sa_handler= handler;
/* Hangup: Reload crontab files. */
sigaction(SIGHUP, &sa, nil);
/* User signal 1 & 2: Raise or reset debug level. */
sigaction(SIGUSR1, &sa, nil);
sigaction(SIGUSR2, &sa, nil);
/* Interrupt and Terminate: Cleanup and exit. */
if (sigaction(SIGINT, nil, &osa) == 0 && osa.sa_handler != SIG_IGN) {
sigaction(SIGINT, &sa, nil);
}
if (sigaction(SIGTERM, nil, &osa) == 0 && osa.sa_handler != SIG_IGN) {
sigaction(SIGTERM, &sa, nil);
}
/* Alarm: Wake up and run a job. */
sigaction(SIGALRM, &sa, nil);
/* Initialize current time and time next to do something. */
time(&now);
next= NEVER;
/* Table load required first time. */
need_reload= 1;
do {
if (need_reload) {
need_reload= 0;
load_crontabs();
busy= 1;
}
/* Run jobs whose time has come. */
if (next <= now) {
cronjob_t *job;
if ((job= tab_nextjob()) != nil) run_job(job);
busy= 1;
}
if (busy) {
/* Did a job finish? */
r= waitpid(-1, nil, WNOHANG);
busy= 0;
} else {
/* Sleep until the next job must be started. */
if (next == NEVER) {
alarm(0);
} else {
#if __minix_vmd
//.........这里部分代码省略.........
开发者ID:Stichting-MINIX-Research-Foundation,项目名称:minix,代码行数:101,代码来源:cron.c
示例14: cyg_pppd_main
externC void
cyg_pppd_main(CYG_ADDRWORD arg)
{
int i;
struct timeval timo;
struct protent *protp;
int connect_attempts = 0;
phase = PHASE_INITIALIZE;
cyg_ppp_options_install( ((struct tty *)arg)->options );
for (i = 0; (protp = protocols[i]) != NULL; ++i)
(*protp->init)(0);
if (!ppp_available()) {
option_error(no_ppp_msg);
exit(1);
}
/*
* Initialize system-dependent stuff and magic number package.
*/
sys_init();
magic_init();
if (debug)
setlogmask(LOG_UPTO(LOG_DEBUG));
for (;;) {
need_holdoff = 1;
{
Cyg_ErrNo err;
while ((err = cyg_io_lookup(devnam, &tty_handle)) < 0) {
if (err != 0)
syslog(LOG_ERR, "Failed to open %s: %d", devnam,err);
}
#ifdef CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS
if( modem )
{
cyg_uint32 len = sizeof(ppp_tty.serial_callbacks);
ppp_tty.serial_callbacks.fn = cyg_ppp_serial_callback;
ppp_tty.serial_callbacks.priv = (CYG_ADDRWORD)&ppp_tty;
err = cyg_io_set_config( tty_handle,
CYG_IO_SET_CONFIG_SERIAL_STATUS_CALLBACK,
&ppp_tty.serial_callbacks,
&len);
if( err != 0 ) {
syslog(LOG_ERR, "cyg_io_set_config(serial callbacks): %d",err);
die(1);
}
}
#endif
}
hungup = 0;
kill_link = 0;
/* set line speed, flow control, etc.; clear CLOCAL if modem option */
set_up_tty(tty_handle, 0);
#ifdef CYGPKG_PPP_CHAT
if( script != NULL )
{
if( !cyg_ppp_chat( devnam, script ) )
{
connect_attempts++;
goto fail;
}
}
#endif
#ifdef CYGOPT_IO_SERIAL_SUPPORT_LINE_STATUS
if( modem )
{
while( !ppp_tty.carrier_detected )
cyg_thread_delay(100);
}
#endif
connect_attempts = 0; /* we made it through ok */
/* set up the serial device as a ppp interface */
establish_ppp(tty_handle);
syslog(LOG_INFO, "Using interface ppp%d", ifunit);
(void) sprintf(ifname, "ppp%d", ifunit);
/*
* Start opening the connection and wait for
* incoming events (reply, timeout, etc.).
*/
syslog(LOG_NOTICE, "Connect: %s <--> %s", ifname, devnam);
//.........这里部分代码省略.........
开发者ID:Palantir555,项目名称:ecos-mars-zx3,代码行数:101,代码来源:pppd.c
示例15: main
int main(int argc, char **argv)
{
struct libwebsocket_context *context;
int opts = 0;
char interface_name[128] = "";
const char *interface = NULL;
int syslog_options = LOG_PID | LOG_PERROR;
int listen_port = 7681;
struct lws_context_creation_info info;
int debug_level = 7;
int daemonize = 0;
memset(&info, 0, sizeof info);
char c;
int opt_index = 0;
while ((c = getopt_long(argc, argv, "hd:k:p:i:DK:", long_opts,
&opt_index)) != -1) {
switch (c) {
case 'D':
daemonize = 1;
syslog_options &= ~LOG_PERROR;
break;
case 'd':
debug_level = atoi(optarg);
break;
case 'p':
listen_port = atoi(optarg);
break;
case 'k':
strncpy(keyfile,optarg,sizeof(keyfile));
keyfile[sizeof(keyfile)-1] = 0;
break;
case 'K':
strncpy(knownhostfile,optarg,sizeof(knownhostfile));
knownhostfile[sizeof(knownhostfile)-1] = 0;
break;
case 'i':
strncpy(interface_name, optarg, sizeof interface_name);
interface_name[(sizeof interface_name) - 1] = '\0';
interface = interface_name;
break;
case '?':
case 'h':
fprintf(stderr,
"Usage: %s [OPTIONS]...\n"
"Websocket-speaking daemon to acquire authentication tokens\n"
"from compatible websites.\n\n"
" -p,--port NUM listen on port NUM. (default:%i)\n"
" -d,--debug NUM set debug level to NUM.\n"
" -k,--keyfile FILE specify IdentityFile for ssh.\n"
" -K,--knownhosts FILE specify special ssh known_hosts file\n"
" to store host keys acquired by authd\n"
" (defaults to %s)\n"
" -D,--daemonize run in background.\n"
" --help show this message and exit.\n",
argv[0],listen_port,knownhostfile);
exit(1);
}
}
/*
* normally lock path would be /var/lock/lwsts or similar, to
* simplify getting started without having to take care about
* permissions or running as root, set to /tmp/.lwsts-lock
*/
if (daemonize && lws_daemonize("/tmp/.lwstecho-lock")) {
fprintf(stderr, "Failed to daemonize\n");
return 1;
}
/* we will only try to log things according to our debug_level */
setlogmask(LOG_UPTO (LOG_DEBUG));
openlog("lwsts", syslog_options, LOG_DAEMON);
/* tell the library what debug level to emit and to send it to syslog */
lws_set_log_level(debug_level, lwsl_emit_syslog);
info.port = listen_port;
info.iface = interface;
info.protocols = protocols;
#ifndef LWS_NO_EXTENSIONS
info.extensions = libwebsocket_get_internal_extensions();
#endif
info.gid = -1;
info.uid = -1;
info.options = opts;
context = libwebsocket_create_context(&info);
if (context == NULL) {
lwsl_err("libwebsocket init failed\n");
return -1;
}
signal(SIGINT, sighandler);
/* setup temp file: */
int fd = mkstemp(tfname);
if (fd == -1) {
//.........这里部分代码省略.........
开发者ID:wes1138,项目名称:webauth-via-ssh,代码行数:101,代码来源:authd.c
示例16: flow_init
/**
* Initialize flow-control context and process command-line arguments
*
* Sets fc->r to zero upon success, a non-zero errno code, otherwise.
*
* @param fc The flow control context
* @param argc The number of command-line arguments
* @param argv The command-line arguments
* @return Upon success, zero. A non-zero errno code, otherwise.
*/
static void flow_init( struct flow_context *fc ) {
int r;
int i;
struct sockaddr_in sa;
socklen_t sa_len;
sighandler_t old_sh;
// determine the service name
if ( NULL == fc->ident ) {
memcpy(
flow_progname,
fc->argv[ 0 ],
MIN(
strlen( fc->argv[ 0 ] ),
sizeof( flow_progname - 1 )
)
);
fc->ident = basename( flow_progname );
}
// use getopt(3), create a usage(), etc
// options could include verbosity
#ifdef HAVE_SYSLOG
// enable logging
openlog( fc->ident, 0, LOG_DAEMON );
setlogmask( LOG_UPTO( LOG_INFO ) );
// could be conditional, e.g. if command-line argument exists to enable / disable debug
setlogmask( setlogmask( 0 ) | LOG_MASK( LOG_DEBUG ) );
#endif
// set the global variable for signal handlers
_fc = fc;
I( "installing signal handlers.." );
for( i = 0; i < ARRAY_SIZE( signals_to_catch ); i++ ) {
old_sh = signal( signals_to_catch[ i ], sighandler );
if ( SIG_ERR == old_sh ) {
r = errno;
E( "signal(2) failed" );
goto out;
}
}
I( "opening signal pipe.." );
r = pipe( fc->signal_fd );
if ( EXIT_SUCCESS != r ) {
r = errno;
E( "pipe(2) failed" );
goto out;
}
D( "opened signal pipe as fd's %d, %d", fc->signal_fd[ 0 ], fc->signal_fd[ 1 ] );
cas( & fc->highest_fd, fc->signal_fd[ 0 ] );
I( "opening server socket.." );
r = socket( AF_INET, SOCK_DGRAM, 0 );
if ( -1 == r ) {
r = errno;
E( "socket(2) failed" );
goto out;
}
fc->server_socket = r;
D( "opened server socket as fd %d", fc->server_socket );
I( "binding server socket.." );
sa.sin_family = AF_INET;
sa.sin_port = htons( fc->server_port );
sa.sin_addr.s_addr = htonl( INADDR_ANY );
sa_len = sizeof( sa );
r = bind( fc->server_socket, (struct sockaddr *) & sa, sa_len );
if ( -1 == r ) {
r = errno;
E( "bind(2) failed" );
goto out;
}
D( "bound server socket to port %d", fc->server_port );
cas( & fc->highest_fd, fc->server_socket );
out:
fc->r = r;
}
开发者ID:Syanna,项目名称:firmware,代码行数:96,代码来源:flow.c
示例17: main
int main(int argc, char **argv){
running = true;
pthread_mutex_init(&runlock, NULL);
pthread_cond_init(&runcond, NULL);
const char *www_root = "/www";
const char *listen_socket = "ws://127.0.0.1:5303";
const char *plugin_dir = "/usr/lib/orange/api/";
const char *pw_file = "/etc/orange/shadow";
const char *acl_dir = "";
int num_workers = 10;
printf("Orange RPCD v%s\n",VERSION);
printf("Lua/JSONRPC server\n");
printf("Copyright (c) 2016 Martin Schröder <[email protected]>\n");
setlogmask(LOG_UPTO(LOG_INFO));
openlog("orangerpcd", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
int c = 0;
while((c = getopt(argc, argv, "d:l:p:vx:a:w:")) != -1){
switch(c){
case 'd':
www_root = optarg;
break;
case 'a':
acl_dir = optarg;
break;
case 'l':
listen_socket = optarg;
break;
case 'p':
plugin_dir = optarg;
break;
case 'v':
orange_debug_level++;
break;
case 'x':
pw_file = optarg;
break;
case 'w':
num_workers = abs(atoi(optarg));
if(num_workers > 100)
printf("WARNING: using more than 100 workers may not make sense!\n");
break;
default: break;
}
}
#if !defined(CONFIG_THREADS)
num_workers = 0;
printf("Note: threading is disabled!\n");
#else
printf("Threading is enabled! Running with %d workers.\n", num_workers);
#endif
orange_server_t server = orange_ws_server_new(www_root);
if(orange_server_listen(server, listen_socket) < 0){
fprintf(stderr, "server could not listen on specified socket!\n");
return -1;
}
signal(SIGINT, handle_sigint);
signal(SIGUSR1, handle_sigint);
struct orange *app = orange_new(plugin_dir, pw_file, acl_dir);
struct orange_rpc rpc;
orange_rpc_init(&rpc, server, ap
|
请发表评论