static void matecomponent_activation_existing_set (const MateComponentActivationBaseService *base_service, struct SysServer *ss, CORBA_Object obj, CORBA_Environment *ev) { GSList *link; struct SysServerInstance *ssi; ssi = NULL; for (link = ss->instances; link; link = link->next) { ssi = link->data; if ( (!ssi->username || STRMATCH (ssi->username, base_service->username)) && (!ssi->hostname || STRMATCH (ssi->hostname, base_service->hostname))) break; } if (link == NULL) { ssi = g_new0 (struct SysServerInstance, 1); ssi->already_running = obj; ssi->username = g_strdup (base_service->username); ssi->hostname = g_strdup (base_service->hostname); ss->instances = g_slist_prepend (ss->instances, ssi); } else {
int GPTLevent_name_to_code (const char *name, int *code) { int ret; /* return code */ int n; /* loop over derived entries */ /* ** First check derived events */ for (n = 0; n < nderivedentries; ++n) { if (STRMATCH (name, derivedtable[n].namestr)) { *code = derivedtable[n].counter; return 0; } } /* ** Next check PAPI events--note that PAPI must be initialized before the ** name_to_code function can be invoked. */ if ((ret = GPTL_PAPIlibraryinit ()) < 0) return GPTLerror ("GPTL_event_name_to_code: GPTL_PAPIlibraryinit failure\n"); if ((PAPI_event_name_to_code ((char *) name, code)) != PAPI_OK) return GPTLerror ("GPTL_event_name_to_code: PAPI_event_name_to_code failure\n"); return 0; }
int GPTL_PAPIget_eventvalue (const char *eventname, const Papistats *aux, double *value) { int n; /* loop index through enabled events */ int numidx; /* numerator index into papicounters */ int denomidx; /* denominator index into papicounters */ for (n = 0; n < nevents; ++n) { if (STRMATCH (eventname, pr_event[n].event.namestr)) { numidx = pr_event[n].numidx; if (pr_event[n].denomidx > -1) { /* derived event */ denomidx = pr_event[n].denomidx; if (aux->accum[denomidx] > 0) /* protect against divide by zero */ *value = (double) aux->accum[numidx] / (double) aux->accum[denomidx]; else *value = 0.; } else { /* Raw PAPI event */ *value = (double) aux->accum[numidx]; } break; } } if (n == nevents) return GPTLerror ("GPTL_PAPIget_eventvalue: event %s not enabled\n", eventname); return 0; }
static CORBA_Object existing_check (const MateComponentActivationBaseService *base_service, struct SysServer *ss) { GSList *link; for (link = ss->instances; link; link = link->next) { struct SysServerInstance *ssi; ssi = link->data; if ( (!ssi->username || STRMATCH (ssi->username, base_service->username)) && (!ssi->hostname || STRMATCH (ssi->hostname, base_service->hostname))) return ssi->already_running; } return CORBA_OBJECT_NIL; }
/*! \fn void snmp_spine_init() * \brief wrapper function for init_snmp * * Initializes snmp for the given application ID * */ void snmp_spine_init(void) { #ifdef USE_NET_SNMP /* Only do numeric output */ #ifdef NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_NUMERIC_ENUM, 1); #endif /* Prevent update of the snmpapp.conf file */ #ifdef NETSNMP_DS_LIB_DONT_PERSIST_STATE netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PERSIST_STATE, 1); #endif /* Prevent update of the snmpapp.conf file */ #ifdef NETSNMP_DS_LIB_DISABLE_PERSISTENT_LOAD netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DISABLE_PERSISTENT_LOAD, 1); #endif #ifdef NETSNMP_DS_LIB_DONT_PRINT_UNITS netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_DONT_PRINT_UNITS, 1); #endif netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICK_PRINT, 1); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_QUICKE_PRINT, 1); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_PRINT_BARE_VALUE, 1); netsnmp_ds_set_boolean(NETSNMP_DS_LIBRARY_ID, NETSNMP_DS_LIB_NUMERIC_TIMETICKS, 1); #ifdef PACKAGE_VERSION /* check that the headers we compiled with match the library we linked with - apparently not defined in UCD-SNMP... */ SPINE_LOG_DEBUG(("DEBUG: SNMP Header Version is %s\n", PACKAGE_VERSION)); SPINE_LOG_DEBUG(("DEBUG: SNMP Library Version is %s\n", netsnmp_get_version())); if(STRMATCH(PACKAGE_VERSION,netsnmp_get_version())) { init_snmp("spine"); }else{ /* report the error and quit spine */ die("ERROR: SNMP Library Version Mismatch (%s vs %s)",PACKAGE_VERSION,netsnmp_get_version()); } #else SPINE_LOG_DEBUG(("DEBUG: Issues with SNMP Header Version information, assuming old version of Net-SNMP.\n")); init_snmp("spine"); #endif #else ds_set_boolean(DS_LIBRARY_ID, DS_LIB_QUICK_PRINT, 1); ds_set_boolean(DS_LIBRARY_ID, DS_LIB_PRINT_BARE_VALUE, 1); ds_set_boolean(DS_LIBRARY_ID, DS_LIB_NUMERIC_TIMETICKS, 1); init_snmp("spine"); #endif }
int main(int argc, char **argv) { char *Argv0 = *argv; int rc; int lfd; pid_t childpid; time_t starttime; int attempts = 0; UNUSED_PARAMETER(argc); time(&starttime); for ( argv++ ; *argv ; argv++ ) { char *arg = *argv; char *opt = strchr(arg, '='); /* the -- token marks the end of the list */ if ( strcmp(*argv, "--") == 0 ) { argv++; break; } if (opt) *opt++ = '\0'; /* pick off the =VALUE part */ if ( STRMATCH(arg, "--version") ) { puts(Version); exit(EXIT_SUCCESS); } else if ( STRMATCH(arg, "--help")) { show_help(helptext); exit(EXIT_SUCCESS); } else if ( STRMATCH(arg, "-L") || STRMATCH(arg, "--lockfile")) { lockfile = getarg(opt, &argv); } else if ( STRMATCH(arg, "-W") || STRMATCH(arg, "--wait")) { wait_for_lock = TRUE; } else if ( STRMATCH(arg, "-S") || STRMATCH(arg, "--sleep")) { sleeptime = atoi(getarg(opt, &argv)); } else if ( STRMATCH(arg, "-R") || STRMATCH(arg, "--retries")) { retries = atoi(getarg(opt, &argv)); } else if ( STRMATCH(arg, "-T") || STRMATCH(arg, "--maxtime")) { Maxtime = atoi(getarg(opt, &argv)); } else if ( STRMATCH(arg, "-V") || STRMATCH(arg, "--verbose")) { Verbose++; } else if ( STRMATCH(arg, "-Q") || STRMATCH(arg, "-q") || STRMATCH(arg, "--quiet") || STRMATCH(arg, "-I") || STRMATCH(arg, "--idempotent")) { Quiet = TRUE; } else { die("ERROR: \"%s\" is an invalid cmdline param", arg); } } /*---------------------------------------------------------------- * SANITY CHECKING * * Make sure that we have all the parameters we require */ if (*argv == 0) die("ERROR: missing command to %s (must follow \"--\" marker) ", Argv0); if (lockfile == 0) die("ERROR: missing --lockfile=F parameter"); /*---------------------------------------------------------------- * Open or create the lockfile, then try to acquire the lock. If * the lock is acquired immediately (==0), then we're done, but * if the lock is not available, we have to wait for it. * * We can either loop trying for the lock (for --wait), or exit * with error. */ if ( (lfd = open(lockfile, O_RDWR|O_CREAT, openmode)) < 0) die("ERROR: cannot open(%s) [err=%s]", lockfile, strerror(errno)); while ( WAIT_AND_LOCK(lfd) != 0 ) { attempts++; if ( ! wait_for_lock ) { if ( Quiet) exit(EXIT_SUCCESS); else die("ERROR: cannot launch %s - run is locked", argv[0]); } if ( retries > 0 && attempts >= retries ) { die("ERROR: cannot launch %s - run is locked (after %d attempts)", argv[0], attempts); } /* waiting */ if ( Verbose ) printf("(locked: sleeping %d secs, after attempt #%d)\n", sleeptime, attempts); sleep(sleeptime); } fflush(stdout); /* run the child */ if ( (childpid = fork()) == 0 ) { /* IN THE CHILD */ close(lfd); /* don't need the lock file */ /* Make ourselves a process group leader so that this and all * child processes can be sent a signal as a group. This may * be used someday to support a --kill option, though this is * is still tricky. * * PORTING NOTE: if "setsid" is undefined on your platform, * just comment it out and send me an email with info about * the build environment. */ (void) setsid(); /* Set rc to the result of execvp. This lets the parent know we failed. */ rc = execvp(argv[0], argv); } else if ( childpid > 0 ) { /* IN THE PARENT */ time_t endtime; pid_t pid; int status; if ( Verbose ) printf("Waiting for process %ld\n", (long) childpid); pid = waitpid(childpid, &status, 0); rc = WEXITSTATUS(status); time(&endtime); endtime -= starttime; if ( Verbose || (Maxtime > 0 && endtime > Maxtime) ) printf("pid %d exited with status %d, exit code: %d (time=%ld sec)\n", pid, status, rc, endtime); } else { die("ERROR: cannot fork [%s]", strerror(errno)); } exit(rc); }
int main(int argc, char **argv) { char *Argv0 = *argv; int rc; int lfd; pid_t childpid; time_t starttime; UNUSED_PARAMETER(argc); time(&starttime); for ( argv++ ; *argv ; argv++ ) { char *arg = *argv; char *opt = strchr(arg, '='); /* the -- token marks the end of the list */ if ( strcmp(*argv, "--") == 0 ) { argv++; break; } if (opt) *opt++ = '\0'; /* pick off the =VALUE part */ if ( STRMATCH(arg, "-L") || STRMATCH(arg, "--lockfile")) { lockfile = getarg(opt, &argv); } else if ( STRMATCH(arg, "-W") || STRMATCH(arg, "--wait")) { wait_for_lock = TRUE; } else if ( STRMATCH(arg, "-S") || STRMATCH(arg, "--sleep")) { sleeptime = atoi(getarg(opt, &argv)); } else if ( STRMATCH(arg, "-T") || STRMATCH(arg, "--maxtime")) { Maxtime = atoi(getarg(opt, &argv)); } else if ( STRMATCH(arg, "-V") || STRMATCH(arg, "--verbose")) { Verbose++; } else { die("ERROR: \"%s\" is an invalid cmdline param", arg); } } /*---------------------------------------------------------------- * SANITY CHECKING * * Make sure that we have all the parameters we require */ if (*argv == 0) die("ERROR: missing command to %s (must follow \"--\" marker) ", Argv0); if (lockfile == 0) die("ERROR: missing --lockfile=F parameter"); /*---------------------------------------------------------------- * Open or create the lockfile, then try to acquire the lock. If * the lock is acquired immediately (==0), then we're done, but * if the lock is not available, we have to wait for it. * * We can either loop trying for the lock (for --wait), or exit * with error. */ if ( (lfd = open(lockfile, O_RDWR|O_CREAT, openmode)) < 0) die("ERROR: cannot open(%s) [err=%s]", lockfile, strerror(errno)); while ( WAIT_AND_LOCK(lfd) != 0 ) { if ( ! wait_for_lock ) { die("ERROR: cannot launch %s - run is locked", argv[0]); } /* waiting */ if ( Verbose ) printf("(locked: sleeping %d secs)\n", sleeptime); sleep(sleeptime); } fflush(stdout); /* run the child */ if ( (childpid = fork()) == 0 ) { close(lfd); // don't need the lock file execvp(argv[0], argv); } else if ( childpid > 0 ) { time_t endtime; pid_t pid; if ( Verbose ) printf("Waiting for process %ld\n", (long) childpid); pid = waitpid(childpid, &rc, 0); time(&endtime); endtime -= starttime; if ( Verbose || (Maxtime > 0 && endtime > Maxtime) ) printf("pid %d exited with status %d (time=%ld sec)\n", pid, rc, endtime); } else { die("ERROR: cannot fork [%s]", strerror(errno)); } exit(rc); }
/* Note that AC power sources also include a laptop battery it is charging. */ static void checkps(CFDictionaryRef dict, SDL_bool * have_ac, SDL_bool * have_battery, SDL_bool * charging, int *seconds, int *percent) { CFStringRef strval; /* don't CFRelease() this. */ CFBooleanRef bval; CFNumberRef numval; SDL_bool charge = SDL_FALSE; SDL_bool choose = SDL_FALSE; SDL_bool is_ac = SDL_FALSE; int secs = -1; int maxpct = -1; int pct = -1; if ((GETVAL(kIOPSIsPresentKey, &bval)) && (bval == kCFBooleanFalse)) { return; /* nothing to see here. */ } if (!GETVAL(kIOPSPowerSourceStateKey, &strval)) { return; } if (STRMATCH(strval, CFSTR(kIOPSACPowerValue))) { is_ac = *have_ac = SDL_TRUE; } else if (!STRMATCH(strval, CFSTR(kIOPSBatteryPowerValue))) { return; /* not a battery? */ } if ((GETVAL(kIOPSIsChargingKey, &bval)) && (bval == kCFBooleanTrue)) { charge = SDL_TRUE; } if (GETVAL(kIOPSMaxCapacityKey, &numval)) { SInt32 val = -1; CFNumberGetValue(numval, kCFNumberSInt32Type, &val); if (val > 0) { *have_battery = SDL_TRUE; maxpct = (int) val; } } if (GETVAL(kIOPSMaxCapacityKey, &numval)) { SInt32 val = -1; CFNumberGetValue(numval, kCFNumberSInt32Type, &val); if (val > 0) { *have_battery = SDL_TRUE; maxpct = (int) val; } } if (GETVAL(kIOPSTimeToEmptyKey, &numval)) { SInt32 val = -1; CFNumberGetValue(numval, kCFNumberSInt32Type, &val); /* Mac OS X reports 0 minutes until empty if you're plugged in. :( */ if ((val == 0) && (is_ac)) { val = -1; /* !!! FIXME: calc from timeToFull and capacity? */ } secs = (int) val; if (secs > 0) { secs *= 60; /* value is in minutes, so convert to seconds. */ } } if (GETVAL(kIOPSCurrentCapacityKey, &numval)) { SInt32 val = -1; CFNumberGetValue(numval, kCFNumberSInt32Type, &val); pct = (int) val; } if ((pct > 0) && (maxpct > 0)) { pct = (int) ((((double) pct) / ((double) maxpct)) * 100.0); } if (pct > 100) { pct = 100; } /* * We pick the battery that claims to have the most minutes left. * (failing a report of minutes, we'll take the highest percent.) */ if ((secs < 0) && (*seconds < 0)) { if ((pct < 0) && (*percent < 0)) { choose = SDL_TRUE; /* at least we know there's a battery. */ } if (pct > *percent) { choose = SDL_TRUE; } } else if (secs > *seconds) { choose = SDL_TRUE; } if (choose) { *seconds = secs; *percent = pct; *charging = charge; } }