本文整理汇总了C++中Daemon类的典型用法代码示例。如果您正苦于以下问题:C++ Daemon类的具体用法?C++ Daemon怎么用?C++ Daemon使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Daemon类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
/**
*
* @param argc
* @param argv
* @return
*/
int main(int argc, char** argv) {
bool foreground = false;
// TODO: Check for foreground flag
// TODO: Add other flags
// Check startup flags
try {
po::options_description desc("Allowed options");
desc.add_options()
("help,h", "Display this message")
("version,v", "Display version information")
("foreground,f", "Run in foreground, logging errors to console")
;
po::variables_map vm;
po::store(po::parse_command_line(argc, argv, desc), vm);
po::notify(vm);
// Display help message
if (vm.count("help")) {
cout << desc << "\n";
return 0;
}
// Display version information
if (vm.count("version")) {
printf("[%s] - Version %s\n", argv[0], VERSION);
return 0;
}
if (vm.count("fg")) {
foreground = true;
}
} catch (exception &e) {
printf("[%s] Exception caught getting options: %s\n", argv[0], e.what());
return 1;
}
// Fork to background, if we weren't told not to do it
if (!foreground) {
fork();
}
// Setup logging
openlog("tievox", LOG_PERROR | LOG_PID | LOG_CONS, LOG_DAEMON);
// Setup wiringPi, using physical pin numbers.
wiringPiSetupPhys();
// Run daemon
Daemon *daemon = new Daemon();
int result = daemon->Run();
// Cleanup after ourselves
closelog();
return result;
}
示例2: main
int main() {
Daemon d;
if(d.isUnique()) {
daemon(0, 0);
d.run();
}
return 0;
}
示例3: dprintf
void *daemon_launch_thread_(void *arg) {
Daemon *d = (Daemon *)arg;
dprintf(DBG_MINOR, "Dummy::Sensor: Launching dummy simulator thread\n");
d->running = true;
d->run();
d->running = false;
pthread_exit(NULL);
return NULL;
}
示例4: get_local_fqdn
int
CollectorList::resortLocal( const char *preferred_collector )
{
// Find the collector in the list that is best suited for
// this host. This is determined either by
// a) preferred_collector passed in
// b) the collector that has the same hostname as this negotiator
char * tmp_preferred_collector = NULL;
if ( !preferred_collector ) {
// figure out our hostname for plan b) above
MyString _hostname_str = get_local_fqdn();
const char * _hostname = _hostname_str.Value();
if (!(*_hostname)) {
// Can't get our hostname??? fuck off
return -1;
}
tmp_preferred_collector = strdup(_hostname);
preferred_collector = tmp_preferred_collector; // So we know to free later
}
// First, pick out collector(s) that is on this host
Daemon *daemon;
SimpleList<Daemon*> prefer_list;
this->list.Rewind();
while ( this->list.Next(daemon) ) {
if ( same_host (preferred_collector, daemon->fullHostname()) ) {
this->list.DeleteCurrent();
prefer_list.Prepend( daemon );
}
}
// Walk through the list of preferred collectors,
// stuff 'em in the main "list"
this->list.Rewind();
prefer_list.Rewind();
while ( prefer_list.Next(daemon) ) {
this->list.Prepend( daemon );
}
free(tmp_preferred_collector); // Warning, preferred_collector (may have) just became invalid, so do this just before returning.
return 0;
}
示例5: main
int main(int argc, char *argv[]) {
QApplication a(argc, argv);
//listenStatus = 1;
//if (localPortIsOpen(QHostAddress::LocalHost,9250) || localPortIsOpen(QHostAddress::LocalHost,9251)) torStatus = -1;
//if (localPortIsOpen(QHostAddress::Any, 445)) listenStatus = 0;
//Database::db = new QSqlDatabase(QSqlDatabase::addDatabase("QSQLITE"));
//Database::db->setDatabaseName("db.sqlite");
//Database::setDB();
QThread *thread = new QThread;
Daemon *Tor = new Daemon;
Tor->moveToThread(thread);
QObject::connect(thread, SIGNAL(started()), Tor, SLOT(startTor()));
QObject::connect(Tor, SIGNAL(finished()), thread, SLOT(quit()), Qt::DirectConnection);
QObject::connect(thread, SIGNAL(finished()), Tor, SLOT(deleteLater()));
QObject::connect(thread, SIGNAL(finished()), thread, SLOT(deleteLater()));
thread->start();
QThread *thread2 = new QThread;
Daemon *daemon = new Daemon;
daemon->moveToThread(thread2);
QObject::connect(thread2, SIGNAL(started()), daemon, SLOT(startListener()));
QObject::connect(daemon, SIGNAL(ListenerStarted()), daemon, SLOT(init()));
QObject::connect(daemon, SIGNAL(finished()), thread2, SLOT(quit()), Qt::DirectConnection);
QObject::connect(thread2, SIGNAL(finished()), daemon, SLOT(deleteLater()));
QObject::connect(thread2, SIGNAL(finished()), thread2, SLOT(deleteLater()));
thread2->start();
QThread *thread3 = new QThread;
JobsManager *jobsmanager = new JobsManager;
QObject::connect(thread3, SIGNAL(started()), jobsmanager, SLOT(worker()));
jobsmanager->moveToThread(thread3);
thread3->start();
Dialog *dialog = new Dialog();
dialog->show();
QTimer::singleShot(4000, dialog, SLOT(hide()));
Systray *systray = new Systray();
QObject::connect(systray, SIGNAL(exit()), &a, SLOT(quit()));
QObject::connect(jobsmanager, SIGNAL(update()), systray, SLOT(update()));
return a.exec();
}
示例6: entry
void* Daemon::entry(void* data){
struct sync* td = (struct sync*)data;
Daemon* daemon = td->daemon;
/* setup self-pipe */
if ( pipe2(daemon->pipe, O_NONBLOCK) != 0 ){
int saved = errno;
Log::fatal("main", "pipe2() returned %d: %s\n", saved, strerror(saved));
td->value = saved;
sem_post(&td->semaphore);
return NULL;
}
td->value = daemon->init();
sem_post(&td->semaphore);
if ( td->value != 0 ){
return NULL;
}
if ( td->barrier ){
pthread_barrier_wait(td->barrier);
}
daemon->run();
daemon->cleanup();
/* close pipe */
close(daemon->pipe[0]);
close(daemon->pipe[1]);
/* free resources */
sem_destroy(&td->semaphore);
free(td);
return 0;
}
示例7: main
int main(int argc, char **argv) {
#ifdef DAEMON
/* отделяемся от родительского процесса */
int pid = fork();
switch (pid) {
case 0: // child
{
umask(0); //777
setsid(); // Создание нового SID для дочернего процесса
/*Закрываем стандартные файловые дескрипторы*/
close (STDIN_FILENO);
close (STDOUT_FILENO);
close (STDERR_FILENO);
signal(SIGHUP, signal_handler);
signal(SIGTERM, signal_handler);
openlog("daemon", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);
#endif
// CODE
dmn = Daemon();
dmn.start();
exit(0);
#ifdef DAEMON
break;
}
case -1: // error!
exit(EXIT_FAILURE);
/*Если с PID ’ ом в с е получилось , то родительский процесс можно завершить .*/
default:// parent
return 0;
}
#endif
}
示例8: main
int main( int argc, char *argv[] )
{
char *machine_name = 0;
char *log_name = 0;
char *pool=0;
int i;
daemon_t type = DT_MASTER;
myDistro->Init( argc, argv );
config();
for( i=1; i<argc; i++ ) {
if(!strcmp(argv[i],"-help")) {
usage(argv[0]);
exit(0);
} else if(!strcmp(argv[i],"-pool")) {
i++;
if(!argv[i]) {
fprintf(stderr,"-pool requires an argument.\n\n");
usage(argv[0]);
exit(1);
}
pool = argv[i];
} else if(!strcmp(argv[i],"-version")) {
version();
exit(0);
} else if(!strcmp(argv[i],"-debug")) {
dprintf_set_tool_debug("TOOL", 0);
} else if(argv[i][0]=='-') {
type = stringToDaemonType(&argv[i][1]);
if( type == DT_NONE || type == DT_DAGMAN) {
usage(argv[0]);
exit(1);
}
} else if(argv[i][0]!='-') {
if(!machine_name) {
machine_name = argv[i];
} else if(!log_name) {
log_name = argv[i];
} else {
fprintf(stderr,"Extra argument: %s\n\n",argv[i]);
usage(argv[0]);
exit(1);
}
} else {
usage(argv[0]);
exit(1);
}
}
if( !machine_name || !log_name ) {
usage(argv[0]);
exit(1);
}
Daemon *daemon;
ReliSock *sock;
if (pool) {
DCCollector col( pool );
if( ! col.addr() ) {
fprintf( stderr, "Error: %s\n", col.error() );
exit(1);
}
daemon = new Daemon( type, machine_name, col.addr() );
} else {
daemon = new Daemon( type, machine_name );
}
dprintf(D_FULLDEBUG,"Locating daemon process on %s...\n",machine_name);
if(!daemon->locate()) {
fprintf(stderr,"Couldn't locate daemon on %s: %s\n",machine_name,daemon->error());
exit(1);
}
dprintf(D_FULLDEBUG,"Daemon %s is %s\n",daemon->hostname(),daemon->addr());
sock = (ReliSock*)daemon->startCommand( DC_FETCH_LOG, Sock::reli_sock);
if(!sock) {
fprintf(stderr,"couldn't connect to daemon %s at %s\n",daemon->hostname(),daemon->addr());
return 1;
}
int commandType = DC_FETCH_LOG_TYPE_PLAIN;
if ((strcmp(log_name, "HISTORY") == 0) || (strcmp(log_name, "STARTD_HISTORY") == 0)) {
commandType = DC_FETCH_LOG_TYPE_HISTORY;
}
if ((strcmp(log_name, "STARTD.PER_JOB_HISTORY_DIR") == 0) || (strcmp(log_name, "STARTD.PER_JOB_HISTORY_DIR") == 0)) {
commandType = DC_FETCH_LOG_TYPE_HISTORY_DIR;
}
sock->put( commandType );
sock->put( log_name );
sock->end_of_message();
//.........这里部分代码省略.........
示例9: main
//.........这里部分代码省略.........
dashAttributes.rewind();
while ((s = dashAttributes.next())) {
projList.AppendArg(s);
}
}
}
if( projList.Count() > 0 ) {
char **attr_list = projList.GetStringArray();
query->setDesiredAttrs(attr_list);
deleteStringArray(attr_list);
}
// if diagnose was requested, just print the query ad
if (diagnose) {
ClassAd queryAd;
// print diagnostic information about inferred internal state
setMode ((Mode) 0, 0, NULL);
setType (NULL, 0, NULL);
setPPstyle ((ppOption) 0, 0, DEFAULT);
printf ("----------\n");
q = query->getQueryAd (queryAd);
fPrintAd (stdout, queryAd);
printf ("----------\n");
fprintf (stderr, "Result of making query ad was: %d\n", q);
exit (1);
}
// Address (host:port) is taken from requested pool, if given.
char* addr = (NULL != pool) ? pool->addr() : NULL;
Daemon* requested_daemon = pool;
// If we're in "direct" mode, then we attempt to locate the daemon
// associated with the requested subsystem (here encoded by value of mode)
// In this case the host:port of pool (if given) denotes which
// pool is being consulted
if( direct ) {
Daemon *d = NULL;
switch( mode ) {
case MODE_MASTER_NORMAL:
d = new Daemon( DT_MASTER, direct, addr );
break;
case MODE_STARTD_NORMAL:
case MODE_STARTD_AVAIL:
case MODE_STARTD_RUN:
case MODE_STARTD_COD:
d = new Daemon( DT_STARTD, direct, addr );
break;
#ifdef HAVE_EXT_POSTGRESQL
case MODE_QUILL_NORMAL:
d = new Daemon( DT_QUILL, direct, addr );
break;
#endif /* HAVE_EXT_POSTGRESQL */
case MODE_SCHEDD_NORMAL:
case MODE_SCHEDD_SUBMITTORS:
d = new Daemon( DT_SCHEDD, direct, addr );
break;
case MODE_NEGOTIATOR_NORMAL:
d = new Daemon( DT_NEGOTIATOR, direct, addr );
break;
case MODE_CKPT_SRVR_NORMAL:
示例10: name
int
Globals::run(int argc, char * * argv)
{
Daemon daemon;
char * cp;
char * sockarg;
name(FilePath(argv[0]).filename());
// Parse arguments.
config = FilePath("/etc") + name();
for (;;) {
cp = *++argv;
if (!--argc || *cp != '-' || !cp[1])
break;
while (*++cp)
switch (*cp) {
case 'c': // Configuration file.
if (!--argc)
usage();
config = *++argv;
break;
case 'd': // Increase debug level.
debuglvl++;
break;
case 'e': // Log to stderr only.
stderrOnly = true;
break;
case 'g': // Group.
if (!--argc)
usage();
group = *++argv;
break;
case 'j': // Jail.
if (!--argc)
usage();
jail = *++argv;
break;
case 'l': // Log to stderr too.
logstd = true;
break;
case 'n': // Do not detach.
nodaemon = true;
break;
case 'u': // User.
if (!--argc)
usage();
user = *++argv;
break;
default:
usage();
}
}
if (!cp)
usage();
else if (--argc)
usage();
sockarg = cp;
// Daemonize.
// Do not change user and/or group now, since we need full
// permissions for sockets.
try {
daemon.program(name());
daemon.lock_file(FilePath(LOCKDIR) + daemon.program());
daemon.pid_file(FilePath(RUNDIR) + (daemon.program() + ".pid"));
daemon.user(user);
daemon.group(group);
daemon.log_to_stderr(logstd);
daemon.jail(jail);
daemon.block_signals();
daemon.ignore_signals();
if (!nodaemon)
daemon.detach();
daemon.close_all(!stderrOnly);
daemon.open_log(LOG_PID | LOG_NDELAY, LOG_MAIL);
//.........这里部分代码省略.........
示例11: main
int main( int argc, char *argv[] )
{
char *pool=0;
char *name=0;
char *address=0;
char *optional_config=0;
int output_mode = -1;
daemon_t dtype = DT_NONE;
int i;
ExtArray<MyString> worklist_name;
ExtArray<int> worklist_number;
int worklist_count = 0;
Daemon * daemon = NULL;
myDistro->Init( argc, argv );
config();
for( i=1; i<argc; i++ ) {
if(!strncmp(argv[i],"-help",strlen(argv[i]))) {
usage(argv[0]);
exit(0);
} else if(!strncmp(argv[i],"-quiet",strlen(argv[i]))) {
if(output_mode == -1) {
output_mode = 0;
} else {
fprintf(stderr,"ERROR: only one output mode may be specified.\n\n");
usage(argv[0]);
exit(1);
}
} else if(!strncmp(argv[i],"-table",strlen(argv[i]))) {
if(output_mode == -1) {
output_mode = 10;
} else {
fprintf(stderr,"ERROR: only one output mode may be specified.\n\n");
usage(argv[0]);
exit(1);
}
} else if(!strncmp(argv[i],"-verbose",strlen(argv[i]))) {
if(output_mode == -1) {
output_mode = 2;
} else {
fprintf(stderr,"ERROR: only one output mode may be specified.\n\n");
usage(argv[0]);
exit(1);
}
} else if(!strncmp(argv[i],"-config",strlen(argv[i]))) {
i++;
if(!argv[i]) {
fprintf(stderr,"ERROR: -config requires an argument.\n\n");
usage(argv[0]);
exit(1);
}
optional_config = argv[i];
} else if(!strncmp(argv[i],"-pool",strlen(argv[i]))) {
i++;
if(!argv[i]) {
fprintf(stderr,"ERROR: -pool requires an argument.\n\n");
usage(argv[0]);
exit(1);
}
if(address) {
fprintf(stderr,"ERROR: -address cannot be used with -pool or -name.\n\n");
usage(argv[0]);
exit(1);
}
pool = argv[i];
} else if(!strncmp(argv[i],"-name",strlen(argv[i]))) {
i++;
if(!argv[i]) {
fprintf(stderr,"ERROR: -name requires an argument.\n\n");
usage(argv[0]);
exit(1);
}
if(address) {
fprintf(stderr,"ERROR: -address cannot be used with -pool or -name.\n\n");
usage(argv[0]);
exit(1);
}
name = argv[i];
} else if(!strncmp(argv[i],"-type",strlen(argv[i]))) {
i++;
if(!argv[i]) {
fprintf(stderr,"ERROR: -type requires an argument.\n\n");
usage(argv[0]);
exit(1);
}
dtype = stringToDaemonType(argv[i]);
if( dtype == DT_NONE) {
fprintf(stderr,"ERROR: unrecognized daemon type: %s\n\n", argv[i]);
usage(argv[0]);
exit(1);
}
} else if(!strncmp(argv[i],"-address",strlen(argv[i]))) {
i++;
if(!argv[i]) {
fprintf(stderr,"ERROR: -address requires an argument.\n\n");
usage(argv[0]);
exit(1);
}
//.........这里部分代码省略.........
示例12: main
int main(int argc, char **argv) {
openni::Device &device = __device;
openni::VideoStream &depth = __depth, &color = __color;
openni::Status rc;
char *prefix = strrchr(argv[0], '/')+1;
char *cfgfile = new char[prefix-argv[0]+strlen(rgbdsend::config_file_name)+1];
strncpy(cfgfile, argv[0], prefix-argv[0]+1);
strcpy(cfgfile+(prefix-argv[0]), rgbdsend::config_file_name);
Config conf;
if(conf.read(cfgfile) != 1) {
printf("Config: Falling back to builtin presets.\n");
conf.setDefaults();
}
delete[] cfgfile;
CURL *curl = init_curl();
Daemon daemon;
daemon.init(conf.daemon_port, conf.daemon_timeout);
atexit(atexit_handler);
init_openni(&device, &depth, &color, conf);
int dw, dh, cw, ch;
int tmp1, tmp2;
if(!depth.getCropping(&tmp1, &tmp2, &dw, &dh)) {
dw = depth.getVideoMode().getResolutionX();
dh = depth.getVideoMode().getResolutionY();
}
if(!color.getCropping(&tmp1, &tmp2, &cw, &ch)) {
cw = color.getVideoMode().getResolutionX();
ch = color.getVideoMode().getResolutionY();
}
printf("Resolution:\nDepth: %dx%d @ %d fps\nColor: %dx%d @ %d fps\n",
dw, dh, depth.getVideoMode().getFps(),
cw, ch, color.getVideoMode().getFps());
std::queue<char *> onilist;
Command cmd;
while(1) {
timeval t;
t.tv_sec = conf.daemon_timeout;
t.tv_usec = 0;
fd_set fds;
FD_ZERO(&fds);
FD_SET(daemon.sock, &fds);
FD_SET(daemon.csock, &fds);
int in = select((daemon.csock > daemon.sock ? daemon.csock : daemon.sock)+1, &fds, 0, 0, &t);
if(FD_ISSET(daemon.sock, &fds))
daemon.acceptConnection();
if(FD_ISSET(daemon.csock, &fds)) {
char b[5];
int r = daemon.receiveCommand(&cmd);
if(r == 0) {
printf("Daemon Error: Could not receive command.\n");
daemon.closeConnection();
continue;
}
if(r == 2) // keep alive
continue;
if(strncmp(cmd.header, "capt", 4) == 0) {
printf("Received capture command.\n");
char *newfile = new char[rgbdsend::filename_bufsize];
if(record_oni(newfile, rgbdsend::filename_bufsize, depth, color, conf) == true) {
onilist.push(newfile);
} else {
delete[] newfile;
}
daemon.sendCommand("okay", 0, 0);
} else if(strncmp(cmd.header, "thmb", 4) == 0) {
printf("Received thumbnail command.\n");
unsigned char *thumbbuf = NULL;
long unsigned int size = 0;
capture_thumbnail(&thumbbuf, &size, color);
printf("Captured thumbnail. %ld bytes\n", size);
daemon.sendCommand("stmb", thumbbuf, size);
// delete[] thumbbuf; seems like libjpeg handles this. but I'm not sure.
} else if(strncmp(cmd.header, "quit", 4) == 0) {
daemon.closeConnection();
} else {
//.........这里部分代码省略.........
示例13: main
int main(int argc, char *argv[])
{
Daemon *app = new Daemon(argc, argv);
return app->run();
}
示例14: signal_handler
void signal_handler(int sig) {
switch (sig) {
case SIGHUP:
dmn.reup();
break;
case SIGTERM:
dmn.die();
break;
}
}
示例15: signal_handler
void signal_handler(int sig) {
switch (sig) {
case SIGHUP:
syslog(LOG_INFO, "Reload conf file\n");
break;
case SIGTERM:
syslog(LOG_INFO, "Close daemon...\n");
dmn.die();
break;
}
}