void dockingportGSP::init()
{
/////////////////// Set process priorities
int prior;
int dummy1;
/// set process priority of ueye usb daemon to highest possible value
char reniceCmd[100];
string processIDofUeyeDeamonStr;
int processIDofUeyeDeamon;
char pidOfCmd[100];
sprintf(pidOfCmd, "pidof ueyeusbd");
processIDofUeyeDeamonStr = this->execAndReturnSystemOutput(pidOfCmd);
processIDofUeyeDeamon = atoi(processIDofUeyeDeamonStr.c_str());
sprintf(reniceCmd, "sudo renice -20 %d", processIDofUeyeDeamon);
dummy1 = system(reniceCmd);
prior = getpriority(PRIO_PROCESS, processIDofUeyeDeamon);
printf("\n ueyeusbd process priority set to: %d\n",prior);
/// set process priority of TestProject process to a value slightly lower than ueye usb daemon
setpriority(PRIO_PROCESS,0,-15);
usleep(10000);
prior = getpriority(PRIO_PROCESS,0);
printf(" TestProject process priority set to: %d\n",prior);
this->useBackgroundTask = false;
prevImageTimeStamp = 0;
/////////////////// Path Initializations
sprintf(this->calibParamDir, "/opt/GogglesOptics/Calib_Params/%s", this->calibParamSetName); //set the parameter directory to be what we enter in command line
///////////////////
/////////////////// Camera Initialization section
GSPretVal = camera.initOneCamera(); // Errors handled within functions
if (GSPretVal != 0)
{
printf("Camera could not be initialized!\n");
return exit(1);
}
// Start camera
GSPretVal = camera.startOneCamera(); // Errors handled within functions
if (GSPretVal != 0)
{
printf("Camera could not be started!\n");
return exit(1);
}
////////////////// UDP PIC INITIALIZATION
if (useUDP_PIC)
this->connectToPIC();
///////////////////
/////////////////// Image Rectification Initialization
GSPretVal = rectifier.calcRectificationMaps(camera.getImageWidth(), camera.getImageHeight(), this->calibParamDir);
if (GSPretVal != 0)
{
cout << "Rectification maps could not be processed!" << endl;
}
///////////////////
/////////////////// Data Storage Initialization
datastorage.initDataStorage(this->dockportName, this->camera_ID, this->runPath, this->camera.getImageWidth(), this->camera.getImageHeight());
if (datastorage.autoImageStorage)
{
// create image-datastorage thread
GSPretVal = pthread_create(&ImageStorageThread, NULL, this->imageStorage_thread_Helper, this);
if (GSPretVal != 0)
{
printf("pthread_create ImageStorageThread failed\n");
return exit(1);
}
}
///////////////////
/////////////////// Initialization of OpenCV Mats with correct Size (depending on the parameter/boolean camera.reduceImageSizeTo320x240)
singleImage.create(camera.getImageHeight(), camera.getImageWidth(), CV_8UC3);
///////////////////
}
//.........这里部分代码省略.........
// Initialize the signal handlers
AuthServerSignalHandler SignalINT, SignalTERM;
// Register authservers's signal handlers
ACE_Sig_Handler Handler;
Handler.register_handler(SIGINT, &SignalINT);
Handler.register_handler(SIGTERM, &SignalTERM);
///- Handle affinity for multiple processors and process priority
uint32 affinity = sConfigMgr->GetIntDefault("UseProcessors", 0);
bool highPriority = sConfigMgr->GetBoolDefault("ProcessPriority", false);
#ifdef _WIN32 // Windows
{
HANDLE hProcess = GetCurrentProcess();
if (affinity > 0)
{
ULONG_PTR appAff;
ULONG_PTR sysAff;
if (GetProcessAffinityMask(hProcess, &appAff, &sysAff))
{
ULONG_PTR currentAffinity = affinity & appAff; // remove non accessible processors
if (!currentAffinity)
TC_LOG_ERROR("server.authserver", "RageFire: Processors marked in UseProcessors bitmask (hex) %x are not accessible for the authserver. Accessible processors bitmask (hex): %x", affinity, appAff);
else if (SetProcessAffinityMask(hProcess, currentAffinity))
TC_LOG_INFO("server.authserver", "RageFire: Using processors (bitmask, hex): %x", currentAffinity);
else
TC_LOG_ERROR("server.authserver", "RageFire: Can't set used processors (hex): %x", currentAffinity);
}
}
if (highPriority)
{
if (SetPriorityClass(hProcess, HIGH_PRIORITY_CLASS))
TC_LOG_INFO("server.authserver", "RageFire: authserver process priority class set to HIGH");
else
TC_LOG_ERROR("server.authserver", "RageFire: Can't set authserver process priority class.");
}
}
#elif __linux__ // Linux
if (affinity > 0)
{
cpu_set_t mask;
CPU_ZERO(&mask);
for (unsigned int i = 0; i < sizeof(affinity) * 8; ++i)
if (affinity & (1 << i))
CPU_SET(i, &mask);
if (sched_setaffinity(0, sizeof(mask), &mask))
TC_LOG_ERROR("server.authserver", "RageFire: Can't set used processors (hex): %x, error: %s", affinity, strerror(errno));
else
{
CPU_ZERO(&mask);
sched_getaffinity(0, sizeof(mask), &mask);
TC_LOG_INFO("server.authserver", "RageFire: Using processors (bitmask, hex): %lx", *(__cpu_mask*)(&mask));
}
}
if (highPriority)
{
if (setpriority(PRIO_PROCESS, 0, PROCESS_HIGH_PRIORITY))
TC_LOG_ERROR("server.authserver", "RageFire: Can't set authserver process priority class, error: %s", strerror(errno));
else
TC_LOG_INFO("server.authserver", "RageFire: authserver process priority class set to %i", getpriority(PRIO_PROCESS, 0));
}
#endif
// maximum counter for next ping
uint32 numLoops = (sConfigMgr->GetIntDefault("MaxPingTime", 30) * (MINUTE * 1000000 / 100000));
uint32 loopCounter = 0;
// Wait for termination signal
while (!stopEvent)
{
// dont move this outside the loop, the reactor will modify it
ACE_Time_Value interval(0, 100000);
if (ACE_Reactor::instance()->run_reactor_event_loop(interval) == -1)
break;
if ((++loopCounter) == numLoops)
{
loopCounter = 0;
TC_LOG_INFO("server.authserver", "RageFire: Ping MySQL to keep connection alive");
LoginDatabase.KeepAlive();
}
}
// Close the Database Pool and library
StopDB();
TC_LOG_INFO("server.authserver", "RageFire: Halting process...");
return 0;
}
开发者ID:SymbolixDEV,项目名称:123,代码行数:101,代码来源:Main.cpp
示例3: main
int main(int argc, char **argv)
{
/* For select(2). */
struct timeval tv;
fd_set in;
/* For parsing arguments. */
char *cp;
/* The key read in. */
char c;
get_options();
/*
* Parse arguments.
*/
argv++;
while (*argv) {
cp = *argv++;
while (*cp) {
switch (*cp) {
case 'd':
if (cp[1]) {
if (sscanf(++cp, "%f", &Sleeptime) != 1) {
fprintf(stderr, PROGNAME ": Bad delay time `%s'\n", cp);
exit(1);
}
goto breakargv;
} else if (*argv) { /* last char in an argv, use next as arg */
if (sscanf(cp = *argv++, "%f", &Sleeptime) != 1) {
fprintf(stderr, PROGNAME ": Bad delay time `%s'\n", cp);
exit(1);
}
goto breakargv;
} else {
fprintf(stderr, "-d requires an argument\n");
exit(1);
}
break;
case 'q':
if (!getuid())
/* set priority to -10 in order to stay above kswapd */
if (setpriority(PRIO_PROCESS, getpid(), -10)) {
/* We check this just for paranoia. It's not
fatal, and shouldn't happen. */
perror(PROGNAME ": setpriority() failed");
}
Sleeptime = 0;
break;
case 'c':
show_cmd = !show_cmd;
break;
case 'S':
Cumulative = 1;
break;
case 'i':
Noidle = 1;
break;
case 's':
Secure = 1;
break;
case '-':
break; /* Just ignore it */
#if defined (SHOWFLAG)
case '/': showall++;
#endif
default:
fprintf(stderr, PROGNAME ": Unknown argument `%c'\n", *cp);
exit(1);
}
cp++;
}
breakargv:
}
/* set to PCPU sorting */
register_sort_function( -1, (cmp_t)pcpu_sort);
/* for correct handling of some fields, we have to do distinguish
* between kernel versions */
set_linux_version();
/* get kernel symbol table, if needed */
if (!CL_wchan_nout) {
if (open_psdb()) {
CL_wchan_nout = 1;
} else {
psdbsucc = 1;
}
}
setup_terminal();
window_size();
/*
* calculate header size, length of cmdline field ...
*/
Numfields = make_header();
/*
* Set up signal handlers.
*/
signal(SIGHUP, (void *) (int) end);
signal(SIGINT, (void *) (int) end);
signal(SIGQUIT, (void *) (int) end);
//.........这里部分代码省略.........
开发者ID:AnthraX1,项目名称:rk,代码行数:101,代码来源:top.c
示例4: client
static void
client (int fd, const char* prio, unsigned int text_size, struct test_st *test)
{
int ret;
char buffer[MAX_BUF + 1];
char text[text_size];
gnutls_certificate_credentials_t x509_cred;
gnutls_session_t session;
struct timespec start, stop;
static unsigned long taken = 0;
static unsigned long measurement;
const char* err;
global_init ();
setpriority(PRIO_PROCESS, getpid(), -15);
memset(text, 0, text_size);
#ifdef DEBUG
gnutls_global_set_log_function (client_log_func);
gnutls_global_set_log_level (6);
#endif
gnutls_certificate_allocate_credentials (&x509_cred);
#ifdef REHANDSHAKE
restart:
#endif
/* Initialize TLS session
*/
gnutls_init (&session, GNUTLS_CLIENT);
gnutls_session_set_ptr(session, test);
cli_session = session;
/* Use default priorities */
if ((ret=gnutls_priority_set_direct (session, prio, &err)) < 0) {
fprintf(stderr, "Error in priority string %s: %s\n", gnutls_strerror(ret), err);
exit(1);
}
/* put the anonymous credentials to the current session
*/
gnutls_credentials_set (session, GNUTLS_CRD_CERTIFICATE, x509_cred);
gnutls_transport_set_ptr (session, (gnutls_transport_ptr_t) fd);
/* Perform the TLS handshake
*/
do
{
ret = gnutls_handshake (session);
}
while (ret < 0 && gnutls_error_is_fatal(ret) == 0);
if (ret < 0)
{
fprintf (stderr, "client: Handshake failed\n");
gnutls_perror (ret);
exit(1);
}
ret = gnutls_protocol_get_version(session);
if (ret < GNUTLS_TLS1_1)
{
fprintf (stderr, "client: Handshake didn't negotiate TLS 1.1 (or later)\n");
exit(1);
}
gnutls_transport_set_push_function (session, push_crippled);
#ifndef REHANDSHAKE
restart:
#endif
do {
ret = gnutls_record_send (session, text, sizeof(text));
} while (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED);
/* measure peer's processing time */
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start);
#define TLS_RECV
#ifdef TLS_RECV
do {
ret = gnutls_record_recv(session, buffer, sizeof(buffer));
} while(ret < 0 && (ret == GNUTLS_E_AGAIN || ret == GNUTLS_E_INTERRUPTED));
#else
do {
ret = recv(fd, buffer, sizeof(buffer), 0);
} while(ret == -1 && errno == EAGAIN);
#endif
if (taken < MAX_MEASUREMENTS(test->npoints) && ret > 0)
{
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &stop);
taken++;
measurement = timespec_sub_ns(&stop, &start);
prev_point_ptr->measurements[prev_point_ptr->midx] = measurement;
/*fprintf(stderr, "(%u,%u): %lu\n", (unsigned) prev_point_ptr->byte1,
(unsigned) prev_point_ptr->byte2, measurements[taken]);*/
//.........这里部分代码省略.........
static void
action_launch_child(svc_action_t *op)
{
int lpc;
/* SIGPIPE is ignored (which is different from signal blocking) by the gnutls library.
* Depending on the libqb version in use, libqb may set SIGPIPE to be ignored as well.
* We do not want this to be inherited by the child process. By resetting this the signal
* to the default behavior, we avoid some potential odd problems that occur during OCF
* scripts when SIGPIPE is ignored by the environment. */
signal(SIGPIPE, SIG_DFL);
#if defined(HAVE_SCHED_SETSCHEDULER)
if (sched_getscheduler(0) != SCHED_OTHER) {
struct sched_param sp;
memset(&sp, 0, sizeof(sp));
sp.sched_priority = 0;
if (sched_setscheduler(0, SCHED_OTHER, &sp) == -1) {
crm_perror(LOG_ERR, "Could not reset scheduling policy to SCHED_OTHER for %s", op->id);
}
}
#endif
if (setpriority(PRIO_PROCESS, 0, 0) == -1) {
crm_perror(LOG_ERR, "Could not reset process priority to 0 for %s", op->id);
}
/* Man: The call setpgrp() is equivalent to setpgid(0,0)
* _and_ compiles on BSD variants too
* need to investigate if it works the same too.
*/
setpgid(0, 0);
/* close all descriptors except stdin/out/err and channels to logd */
for (lpc = getdtablesize() - 1; lpc > STDERR_FILENO; lpc--) {
close(lpc);
}
#if SUPPORT_CIBSECRETS
if (replace_secret_params(op->rsc, op->params) < 0) {
/* replacing secrets failed! */
if (safe_str_eq(op->action,"stop")) {
/* don't fail on stop! */
crm_info("proceeding with the stop operation for %s", op->rsc);
} else {
crm_err("failed to get secrets for %s, "
"considering resource not configured", op->rsc);
_exit(PCMK_OCF_NOT_CONFIGURED);
}
}
#endif
/* Setup environment correctly */
add_OCF_env_vars(op);
/* execute the RA */
execvp(op->opaque->exec, op->opaque->args);
/* Most cases should have been already handled by stat() */
services_handle_exec_error(op, errno);
_exit(op->rc);
}
int main(int argc, char **argv) {
//
// Machine d'état
//
// int state
// -1: erreur
// 0: non initialisé
// 1: initialisé, pret rotation
// 2: rotation, pret décollage
// 3: décollage
// 4: vol normal
// 5: atterissage
//
state = 0;
printf("\n");
printf("\n================================================");
printf("\n===== XMicroDrone - Controlleur V1.1 =====");
printf("\n================================================");
printf("\n");
//
// Récupérons les numéros de devices séries (paramétre optionnel)
//
int premierDevice = 0; // La valeur par défaut, qu'on utilisera s'il n'y a pas d'arguments
if (argc >= 2) {
int arg = atoi(argv[1]);
if (arg >= 0 && arg <= 2) {
premierDevice = arg;
} else {
printf("Argument devices hors de portée.\n");
}
}
//---------------------------------------------------------------------------
//
//
// INITIALISATION DU PROGRAMME
//
//
//---------------------------------------------------------------------------
//
// Rend le fgets sur stdin non bloquant; FONCTIONNE !
//
int flags = fcntl(0, F_GETFL, 0);
flags |= O_NONBLOCK;
fcntl(0, F_SETFL, flags);
printf("Initialisation des différents modules...");
fflush(stdout);
Misc_Initialise(); // Ne dépend de rien d'autre // Pas de blabla
Maths_Initialise(); // Ne dépend de rien d'autre // Pas de blabla
Params_Initialise(); // Après Maths_Initialise(); (peut utiliser des maths) // Pas de blabla
Asservissement_Initialise(); // Après Params_Initialise();
//Pilote_Initialise(); // Après Params, // Pas de blabla
printf(" OK\n");
printf("Fermeture des serveurs port séries...");
fflush(stdout);
//system("pkill -9 xuartctl"); // kill tous les process utilisant xuartctl TS7500
//usleep(100 * 1000);
printf(" OK... - A priori, A voir si on en a besoin - Pour l'instant ne fait rien\n");
// La fonction suivante émet son propre blabla
I2C_Initialise();
Controlleur_Initialise(0); // Aprés Params_Initialise() et I2C_initialise; // Argument: 1 pour allumer les moteurs successivement
//int grnLedOn = 0;
//int redLedOn = 0;
//Misc_SetRedLed(0); //TS7500
//Misc_SetGrnLed(0);
if (0) {
CommWiFi_Initialise(); // Emet son propre blabla
}
// On se donne temporairement la priorité -15 pour que les xuart l'aient
//
// -15 pour les xuartctl (Port séries) et ts7500ctl (I2C)
// -10 pour nous et ts7500ctl
// -5 pour les trucs systemes importants
// 0 pour le reste
// Plage: -20 (haute priorité) é +20 (faible priorité)
int usePrio = 0;
if (usePrio && setpriority(PRIO_PROCESS, getpid(), -15)) {
printf("ERREUR: setpriority\n");
}
Centrale_Initialise(premierDevice); // Argument: le dev par défaut, -1 pour laisser l'utilisateur choisir
Sonar_Initialise(premierDevice + 1); // Argument: le dev par défaut, -1 pour laisser l'utilisateur choisir
// On se replace a -10
if (usePrio && setpriority(PRIO_PROCESS, getpid(), -10)) {
//.........这里部分代码省略.........
开发者ID:Dvad,项目名称:Colibrix,代码行数:101,代码来源:Main.c
示例11: main
int main(int argc, char *argv[])
{
int ret = ERROR_OK;
int err_count = 0;
int rcv_err_count = 0;
bool msg_received = false;
char* device;
/* Para parsear el los mensajes se recorre el arreglo con un puntero
* a enteros de dos bytes.
*/
int16_t *ch_buff;
//char str[128]; // dbg
// check input arguments
if(argc<2)
{
err_log(HOW_TO);
return -1;
}
else device = argv[1];
struct timeval tv_in;
struct timeval tv_end;
struct timeval tv_diff;
#if DEBUG_TIMING_SBUSD
struct timeval tv_last;
#endif //#if DEBUG_TIMING_SBUSD
#if !PC_TEST
fd = open_port(device);
if (fd == -1)
{
return -1;
}
configure_port(fd);
ret = custom_baud(fd);
if (ret < 0)
{
err_log_stderr("custom_baud() failed!");
return ret;
}
#endif
/**
* Inherit priority from main.c for correct IPC.
*/
if(setpriority(PRIO_PROCESS, 0, -18) == -1) //requires being superuser
{
err_log_num("setpriority() failed!",errno);
return -1;
}
// Catch signals
prctl(PR_SET_PDEATHSIG, SIGHUP);
signal(SIGHUP, uquad_sig_handler);
signal(SIGINT, uquad_sig_handler);
signal(SIGQUIT, uquad_sig_handler);
#if PC_TEST
futaba_sbus_begin(); //para tiempo de start
#endif //PC_TEST
// Lleva a cero todos los canales y el mensaje sbus
futaba_sbus_set_channel(ROLL_CHANNEL, 1500); //init roll en cero
futaba_sbus_set_channel(PITCH_CHANNEL, 1500); //init pitch en cero
futaba_sbus_set_channel(YAW_CHANNEL, 1500); //init yaw en cero
futaba_sbus_set_channel(THROTTLE_CHANNEL, 950); //init throttle en minimo
futaba_sbus_set_channel(FLIGHTMODE_CHANNEL, 1500); //inint flight mode 2
futaba_sbus_update_msg();
sleep_ms(500); //Para ponerme a tiro con main
bool main_ready = false;
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
// Loop
// -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
for(;;)
{
gettimeofday(&tv_in,NULL);
//printf("errores: %d\n",err_count);//dbg
#if !PC_TEST
if (err_count > MAX_ERR_SBUSD)
{
err_log("error count exceded");
//err_count = 0;
quit();
}
#endif
ret = uquad_read(&rbuf);
if(ret == ERROR_OK)
{
if(!main_ready) main_ready = true;
//err_log("read ok!");
msg_received = true;
//.........这里部分代码省略.........
int main(int argc, char **argv)
{
int c;
int cnt;
char *childArgv[10];
char *buff;
int childArgc = 0;
int retcode;
char *pwdbuf = NULL;
struct passwd *pwd = NULL, _pwd;
struct login_context cxt = {
.tty_mode = TTY_MODE, /* tty chmod() */
.pid = getpid(), /* PID */
.conv = { misc_conv, NULL } /* PAM conversation function */
};
timeout = (unsigned int)getlogindefs_num("LOGIN_TIMEOUT", LOGIN_TIMEOUT);
signal(SIGALRM, timedout);
siginterrupt(SIGALRM, 1); /* we have to interrupt syscalls like ioclt() */
alarm(timeout);
signal(SIGQUIT, SIG_IGN);
signal(SIGINT, SIG_IGN);
setlocale(LC_ALL, "");
bindtextdomain(PACKAGE, LOCALEDIR);
textdomain(PACKAGE);
setpriority(PRIO_PROCESS, 0, 0);
initproctitle(argc, argv);
/*
* -p is used by getty to tell login not to destroy the environment
* -f is used to skip a second login authentication
* -h is used by other servers to pass the name of the remote
* host to login so that it may be placed in utmp and wtmp
*/
while ((c = getopt(argc, argv, "fHh:pV")) != -1)
switch (c) {
case 'f':
cxt.noauth = 1;
break;
case 'H':
cxt.nohost = 1;
break;
case 'h':
if (getuid()) {
fprintf(stderr,
_("login: -h for super-user only.\n"));
exit(EXIT_FAILURE);
}
init_remote_info(&cxt, optarg);
break;
case 'p':
cxt.keep_env = 1;
break;
case 'V':
printf(UTIL_LINUX_VERSION);
return EXIT_SUCCESS;
case '?':
default:
fprintf(stderr, _("usage: login [ -p ] [ -h host ] [ -H ] [ -f username | username ]\n"));
exit(EXIT_FAILURE);
}
argc -= optind;
argv += optind;
if (*argv) {
char *p = *argv;
cxt.username = xstrdup(p);
/* wipe name - some people mistype their password here */
/* (of course we are too late, but perhaps this helps a little ..) */
while (*p)
*p++ = ' ';
}
for (cnt = get_fd_tabsize() - 1; cnt > 2; cnt--)
close(cnt);
setpgrp(); /* set pgid to pid this means that setsid() will fail */
openlog("login", LOG_ODELAY, LOG_AUTHPRIV);
init_tty(&cxt);
init_loginpam(&cxt);
/* login -f, then the user has already been authenticated */
cxt.noauth = cxt.noauth && getuid() == 0 ? 1 : 0;
if (!cxt.noauth)
loginpam_auth(&cxt);
/*
//.........这里部分代码省略.........
请发表评论