int main(int argc, char *argv[]) { struct filesystem *f; char path[1024]; char *image = getsetting("imagefile"); if (!image) { printf("Have you run ulogin?\n"); return 10; } char *cwd = getsetting("cwd"); if (argc == 2) { if (argv[1][0] == '/') { sprintf(path, "%s", argv[1]); } else { sprintf(path, "%s/%s", cwd, argv[1]); } } else { sprintf(path, "%s", cwd); } free(cwd); f = fsopen(image); if (!f) { printf("Unable to open %s\n", image); } else { if (!uls(f, path)) { printf("%s not found\n", path); } } fsclose(f); free(image); return 0; }
/*! \fn static int getboolsetting(MYSQL *psql, const char *setting, int dflt) * \brief Obtains a boolean option from the database. * * Given the parameters for fetching a setting from the database, * do so for a *Boolean* value. We parse the usual set of words * meaning true/false, and if we don't get a value, or if we don't * understand what we fetched, we use the default value provided. * * \return boolean TRUE or FALSE based upon database setting or the DEFAULT if not found */ static int getboolsetting(MYSQL *psql, const char *setting, int dflt) { const char *rc; assert(psql != 0); assert(setting != 0); rc = getsetting(psql, setting); if (rc == 0) return dflt; if (STRIMATCH(rc, "on" ) || STRIMATCH(rc, "yes" ) || STRIMATCH(rc, "true") || STRIMATCH(rc, "1" ) ) { return TRUE; } if (STRIMATCH(rc, "off" ) || STRIMATCH(rc, "no" ) || STRIMATCH(rc, "false") || STRIMATCH(rc, "0" ) ) { return FALSE; } /* doesn't really match one of our keywords: what to do? */ return dflt; }
int main(int argc, char *argv[]) { struct filesystem *f; int i; int mode; char temp[1024]; char *cwd; char *fsname = getsetting("imagefile");; if (!fsname) { printf("Have you run ulogin?\n"); return 10; } if (argc < 3) { printf("Usage: %s <uid> <file> ...\n", argv[0]); return 10; } sscanf(argv[1], "%o", &mode); f = fsopen(fsname); if (!f) { printf("Unable to open %s\n", fsname); return 10; } cwd = getsetting("cwd"); for (i = 2; i < argc; i++) { if (argv[i][0] == '/') { uchown(f, argv[i], mode); } else { if (!cwd) { sprintf(temp, "/%s", argv[i]); } else { sprintf(temp, "%s/%s", cwd, argv[i]); } compresspath(temp); uchown(f, temp, mode); } } fsclose(f); if (cwd) free(cwd); free(fsname); return 0; }
int8_t RogueSD::sync(void) { // procedure: // 1. sync (send ESC, clear prompt) // 2. get version ("v"), and module type // 3. change settings as needed // 4. check status // 5. close files (if needed - E08, or other error, not needed) // 0. empty any data in the serial buffer _comm_flush(); // 1. sync _comm_write(0x1b); // send ESC to clear buffer on uMMC _read_blocked(); // consume prompt // 2. get version (ignore prompt - just drop it) _get_version(); // 3. change settings as needed // OLD: write timeout setting = 10 ms timeout // NEW: listing style = old style (0) if ((_moduletype == uMMC && _fwversion < UMMC_MIN_FW_VERSION_FOR_NEW_COMMANDS) || (_moduletype == uMP3 && _fwversion < UMP3_MIN_FW_VERSION_FOR_NEW_COMMANDS)) { // we need to set the write timeout to allow us to control when a line is finished // in writeln. changesetting('1', 1); // 10 ms timeout } else { // we're using the new version // Let's make sure the Listing Style setting is set to the old style if (getsetting('L') != 0) { changesetting('L', 0); } // get the prompt char print('S'); if (_moduletype != uMMC) { print('T'); }; print('P'); print('\r'); // get our prompt (if possible) _promptchar = _getnumber(10); _read_blocked(); // consume prompt } // 4. check status if (_moduletype != uMMC) { print("FC"); }; print('Z'); print('\r'); // Get status if (_get_response()) return -1; else { // good _read_blocked(); // consume prompt // 5. close all files closeall(); // ensure all handles are closed return 0; } }
/*! \fn void read_config_options(void) * \brief Reads the default Spine runtime parameters from the database and set's the global array * * load default values from the database for poller processing * */ void read_config_options() { MYSQL mysql; MYSQL_RES *result; int num_rows; char web_root[BUFSIZE]; char sqlbuf[SMALL_BUFSIZE], *sqlp = sqlbuf; const char *res; db_connect(set.dbdb, &mysql); /* get the mysql server version */ set.dbversion = 0; if ((res = getglobalvariable(&mysql, "version")) != 0 ) { set.dbversion = atoi(res); } /* get logging level from database - overrides spine.conf */ if ((res = getsetting(&mysql, "log_verbosity")) != 0 ) { const int n = atoi(res); if (n != 0) set.log_level = n; } /* determine script server path operation and default log file processing */ if ((res = getsetting(&mysql, "path_webroot")) != 0 ) { snprintf(set.path_php_server, SMALL_BUFSIZE, "%s/script_server.php", res); snprintf(web_root, BUFSIZE, "%s", res); } /* determine logfile path */ if ((res = getsetting(&mysql, "path_cactilog")) != 0 ) { if (strlen(res) != 0) { snprintf(set.path_logfile, SMALL_BUFSIZE, "%s", res); }else{ if (strlen(web_root) != 0) { snprintf(set.path_logfile, SMALL_BUFSIZE, "%s/log/cacti.log", web_root); }else{ set.path_logfile[0] ='\0'; } } }else{ snprintf(set.path_logfile, SMALL_BUFSIZE, "%s/log/cacti.log", web_root); } /* log the path_webroot variable */ SPINE_LOG_DEBUG(("DEBUG: The path_php_server variable is %s", set.path_php_server)); /* log the path_cactilog variable */ SPINE_LOG_DEBUG(("DEBUG: The path_cactilog variable is %s", set.path_logfile)); /* determine log file, syslog or both, default is 1 or log file only */ if ((res = getsetting(&mysql, "log_destination")) != 0 ) { set.log_destination = parse_logdest(res, LOGDEST_FILE); }else{ set.log_destination = LOGDEST_FILE; } /* log the log_destination variable */ SPINE_LOG_DEBUG(("DEBUG: The log_destination variable is %i (%s)", set.log_destination, printable_logdest(set.log_destination))); set.logfile_processed = TRUE; /* get PHP Path Information for Scripting */ if ((res = getsetting(&mysql, "path_php_binary")) != 0 ) { STRNCOPY(set.path_php, res); } /* log the path_php variable */ SPINE_LOG_DEBUG(("DEBUG: The path_php variable is %s", set.path_php)); /* set availability_method */ if ((res = getsetting(&mysql, "availability_method")) != 0 ) { set.availability_method = atoi(res); } /* log the availability_method variable */ SPINE_LOG_DEBUG(("DEBUG: The availability_method variable is %i", set.availability_method)); /* set ping_recovery_count */ if ((res = getsetting(&mysql, "ping_recovery_count")) != 0 ) { set.ping_recovery_count = atoi(res); } /* log the ping_recovery_count variable */ SPINE_LOG_DEBUG(("DEBUG: The ping_recovery_count variable is %i", set.ping_recovery_count)); /* set ping_failure_count */ if ((res = getsetting(&mysql, "ping_failure_count")) != 0) { set.ping_failure_count = atoi(res); } /* log the ping_failure_count variable */ SPINE_LOG_DEBUG(("DEBUG: The ping_failure_count variable is %i", set.ping_failure_count)); /* set ping_method */ if ((res = getsetting(&mysql, "ping_method")) != 0 ) { set.ping_method = atoi(res); } /* log the ping_method variable */ SPINE_LOG_DEBUG(("DEBUG: The ping_method variable is %i", set.ping_method)); /* set ping_retries */ if ((res = getsetting(&mysql, "ping_retries")) != 0 ) { set.ping_retries = atoi(res); } /* log the ping_retries variable */ SPINE_LOG_DEBUG(("DEBUG: The ping_retries variable is %i", set.ping_retries)); /* set ping_timeout */ if ( (res = getsetting(&mysql, "ping_timeout")) != 0 ) { set.ping_timeout = atoi(res); } /* log the ping_timeout variable */ SPINE_LOG_DEBUG(("DEBUG: The ping_timeout variable is %i", set.ping_timeout)); /* set snmp_retries */ if ( (res = getsetting(&mysql, "snmp_retries")) != 0 ) { set.snmp_retries = atoi(res); } /* log the snmp_retries variable */ SPINE_LOG_DEBUG(("DEBUG: The snmp_retries variable is %i", set.snmp_retries)); /* set logging option for errors */ set.log_perror = getboolsetting(&mysql, "log_perror", FALSE); /* log the log_perror variable */ SPINE_LOG_DEBUG(("DEBUG: The log_perror variable is %i", set.log_perror)); /* set logging option for errors */ set.log_pwarn = getboolsetting(&mysql, "log_pwarn", FALSE); /* log the log_pwarn variable */ SPINE_LOG_DEBUG(("DEBUG: The log_pwarn variable is %i", set.log_pwarn)); /* set logging option for errors */ set.boost_redirect = getboolsetting(&mysql, "boost_redirect", FALSE); /* log the log_pwarn variable */ SPINE_LOG_DEBUG(("DEBUG: The boost_redirect variable is %i", set.boost_redirect)); /* set logging option for statistics */ set.log_pstats = getboolsetting(&mysql, "log_pstats", FALSE); /* log the log_pstats variable */ SPINE_LOG_DEBUG(("DEBUG: The log_pstats variable is %i", set.log_pstats)); /* get Cacti defined max threads override spine.conf */ if ((res = getsetting(&mysql, "max_threads")) != 0 ) { set.threads = atoi(res); if (set.threads > MAX_THREADS) { set.threads = MAX_THREADS; } } /* log the threads variable */ SPINE_LOG_DEBUG(("DEBUG: The threads variable is %i", set.threads)); /* get the poller_interval for those who have elected to go with a 1 minute polling interval */ if ((res = getsetting(&mysql, "poller_interval")) != 0 ) { set.poller_interval = atoi(res); }else{ set.poller_interval = 0; } /* log the poller_interval variable */ if (set.poller_interval == 0) { SPINE_LOG_DEBUG(("DEBUG: The polling interval is the system default")); }else{ SPINE_LOG_DEBUG(("DEBUG: The polling interval is %i seconds", set.poller_interval)); } /* get the concurrent_processes variable to determine thread sleep values */ if ((res = getsetting(&mysql, "concurrent_processes")) != 0 ) { set.num_parent_processes = atoi(res); }else{ set.num_parent_processes = 1; } /* log the concurrent processes variable */ SPINE_LOG_DEBUG(("DEBUG: The number of concurrent processes is %i", set.num_parent_processes)); /* get the script timeout to establish timeouts */ if ((res = getsetting(&mysql, "script_timeout")) != 0 ) { set.script_timeout = atoi(res); if (set.script_timeout < 5) { set.script_timeout = 5; } }else{ set.script_timeout = 25; } /* log the script timeout value */ SPINE_LOG_DEBUG(("DEBUG: The script timeout is %i", set.script_timeout)); /* get the number of script server processes to run */ if ((res = getsetting(&mysql, "php_servers")) != 0 ) { set.php_servers = atoi(res); if (set.php_servers > MAX_PHP_SERVERS) { set.php_servers = MAX_PHP_SERVERS; } if (set.php_servers <= 0) { set.php_servers = 1; } }else{ set.php_servers = 2; } /* log the script timeout value */ SPINE_LOG_DEBUG(("DEBUG: The number of php script servers to run is %i", set.php_servers)); /*---------------------------------------------------------------- * determine if the php script server is required by searching for * all the host records for an action of POLLER_ACTION_PHP_SCRIPT_SERVER. * If we get even one, it means we have to deal with the PHP script * server. * */ set.php_required = FALSE; /* assume no */ /* log the requirement for the script server */ if (!strlen(set.host_id_list)) { sqlp = sqlbuf; sqlp += sprintf(sqlp, "SELECT action FROM poller_item"); sqlp += sprintf(sqlp, " WHERE action=%d", POLLER_ACTION_PHP_SCRIPT_SERVER); sqlp += append_hostrange(sqlp, "host_id"); if (set.poller_id_exists) { sqlp += sprintf(sqlp, " AND poller_id=%i", set.poller_id); } sqlp += sprintf(sqlp, " LIMIT 1"); result = db_query(&mysql, sqlbuf); num_rows = mysql_num_rows(result); if (num_rows > 0) set.php_required = TRUE; SPINE_LOG_DEBUG(("DEBUG: StartHost='%i', EndHost='%i', TotalPHPScripts='%i'", set.start_host_id, set.end_host_id, num_rows)); }else{ sqlp = sqlbuf; sqlp += sprintf(sqlp, "SELECT action FROM poller_item"); sqlp += sprintf(sqlp, " WHERE action=%d", POLLER_ACTION_PHP_SCRIPT_SERVER); sqlp += sprintf(sqlp, " AND host_id IN(%s)", set.host_id_list); if (set.poller_id_exists) { sqlp += sprintf(sqlp, " AND poller_id=%i", set.poller_id); } sqlp += sprintf(sqlp, " LIMIT 1"); result = db_query(&mysql, sqlbuf); num_rows = mysql_num_rows(result); if (num_rows > 0) set.php_required = TRUE; SPINE_LOG_DEBUG(("DEBUG: Host List to be polled='%s', TotalPHPScripts='%i'", set.host_id_list, num_rows)); } SPINE_LOG_DEBUG(("DEBUG: The PHP Script Server is %sRequired", set.php_required ? "" : "Not ")); /* determine the maximum oid's to obtain in a single get request */ if ((res = getsetting(&mysql, "max_get_size")) != 0 ) { set.snmp_max_get_size = atoi(res); if (set.snmp_max_get_size > 128) { set.snmp_max_get_size = 128; } }else{ set.snmp_max_get_size = 25; } /* log the snmp_max_get_size variable */ SPINE_LOG_DEBUG(("DEBUG: The Maximum SNMP OID Get Size is %i", set.snmp_max_get_size)); mysql_free_result(result); db_disconnect(&mysql); }