void signal_handler(int sig)
{
		if(sig==SIGUSR1) {
			open_door(1);
		}
		else if(sig==SIGHUP) {
			clear_config();
			read_config();
		}
		else if(sig==SIGINT) {
			printf("Got SIGINT! Exiting...");
			clear_config();
			exit(0);
		}
}
Exemple #2
0
/*
 * This function is called to get the value of the failure_action 
 * tunable stored in /etc/libaudit.conf.  The function returns 1 if
 * the tunable is not found or there is an error. If the tunable is found,
 * 0 is returned the the tunable value is saved in the failmode parameter.
 */
int get_auditfail_action(auditfail_t *failmode)
{
	clear_config();

	if (load_libaudit_config(CONFIG_FILE)) {
		*failmode = config.failure_action;
		return 1;
	}

	*failmode = config.failure_action;
	return 0;
}
void PREFAST_NORETURN
my_exit( int status )
{
	fflush( stdout );
	fflush( stderr );

	if ( ! status ) {
		clear_config();
	}

	exit( status );
}
/*
 * Important: The below generated source_foo.o and deps_foo.o variable
 * assignments are parsed not only by make, but also by the rather simple
 * parser in scripts/mod/sumversion.c.
 */
static void parse_dep_file(void *map, size_t len)
{
	char *m = map;
	char *end = m + len;
	char *p;
	char s[PATH_MAX];
	int first;

	p = strchr(m, ':');
	if (!p) {
		fprintf(stderr, "fixdep: parse error\n");
		exit(1);
	}
	memcpy(s, m, p-m); s[p-m] = 0;
	m = p+1;

	clear_config();

	first = 1;
	while (m < end) {
		while (m < end && (*m == ' ' || *m == '\\' || *m == '\n'))
			m++;
		p = m;
		while (p < end && *p != ' ') p++;
		if (p == end) {
			do p--; while (!isalnum(*p));
			p++;
		}
		memcpy(s, m, p-m); s[p-m] = 0;
		if (strrcmp(s, "include/generated/autoconf.h") &&
		    strrcmp(s, "arch/um/include/uml-config.h") &&
		    strrcmp(s, "include/linux/kconfig.h") &&
		    strrcmp(s, ".ver")) {
			/*
			 * Do not list the source file as dependency, so that
			 * kbuild is not confused if a .c file is rewritten
			 * into .S or vice versa. Storing it in source_* is
			 * needed for modpost to compute srcversions.
			 */
			if (first) {
				printf("source_%s := %s\n\n", target, s);
				printf("deps_%s := \\\n", target);
			} else
				printf("  %s \\\n", s);
			do_config_file(s);
		}
		first = 0;
		m = p + 1;
	}
	printf("\n%s: $(deps_%s)\n\n", target, target);
	printf("$(deps_%s):\n", target);
}
Exemple #5
0
int 
main(int count, char **options) {
        int 		res;
        
        if (strcmp(options[1], "-d") != 0) {
            res = daemon(0, 0);
            printf("return value: %s\n", res);        
        }
        res_init();
        _res.retrans = 4;
        _res.retry = 2;
        int 		running = 1;
        if (parse_config()) {
            printf("error reading configuration!\n");
            return 1;
        }
        if (open_status_socket())
            printf("error opening status socket; no status will be provided\n");
        stat(config_file, &config_last_mod);
        printf("last config modified time: %s\n", ctime(&config_last_mod.st_mtime));
        while (running) {
            struct config_interfaces *cur = config;
            printf("checking if conf file has changed\n");
            if (config_changed()) {
                printf("modifying:\n");
                clear_config(config);
                cur = 0;
                if (parse_config())
                   printf("error reading configuration!\n");
                else
                    cur = config;
            }
            while (cur) {
                if (check_interface(cur)) {
                    printf("media type: %s\n", mediatype(cur->if_name));
                    if (strcmp(mediatype(cur->if_name), "Ethernet") == 0) {
                        if (setup_ethernetinterface(cur))
                            break;
                    } else if (strcmp(mediatype(cur->if_name), "IEEE802.11") == 0) {
                        if (setup_wlaninterface(cur))
                            break;
                    }
                }
                cur = cur->next;
            }
            printf("Sleeping... waiting %d seconds\n", poll_wait);
            sleep(poll_wait);
            printf("restarto\n");
        }
        return 0;
}
Exemple #6
0
/*
 * Generate dependencies for one file.
 */
void do_depend(const char * filename, const char * command)
{
	int mapsize;
	int pagesizem1 = getpagesize()-1;
	int fd;
	struct stat st;
	char * map;

	fd = open(filename, O_RDONLY);
	if (fd < 0) {
		perror(filename);
		return;
	}

	fstat(fd, &st);
	if (st.st_size == 0) {
		fprintf(stderr,"%s is empty\n",filename);
		close(fd);
		return;
	}

	mapsize = st.st_size;
	mapsize = (mapsize+pagesizem1) & ~pagesizem1;
	map = mmap(NULL, mapsize, PROT_READ, MAP_PRIVATE, fd, 0);
	if ((long) map == -1) {
		perror("mkdep: mmap");
		close(fd);
		return;
	}
	if ((unsigned long) map % sizeof(unsigned long) != 0)
	{
		fprintf(stderr, "do_depend: map not aligned\n");
		exit(1);
	}

	hasdep = 0;
	clear_config();
	state_machine(map, map+st.st_size);
	if (hasdep) {
		puts(command);
		if (*command)
			define_precious(filename);
	}

	munmap(map, mapsize);
	close(fd);
}
Exemple #7
0
//******************************************************************
// configuration
//******************************************************************
int cliNoRouterOspfCmd(CliMode mode, int argc, char **argv) {
	struct tms tm;
	uint32_t tic1 = times(&tm);

	char *data = (char *) pktout + sizeof(RcpPkt);
	*data = '\0';
	
	// clear all configuration
	clear_config();
	
	// clear areas
	clear_areas();
	
	// remove areas
	remove_areas();
	
	// clear routes
	clear_routes();
	
	// remove summary addresses
	memset(shm->config.ospf_sum_addr, 0, sizeof(RcpOspfSummaryAddr) * RCP_OSPF_SUMMARY_ADDR_LIMIT);
	shm->config.ospf_discard_external = 1;
	
	// range
	memset(shm->config.ospf_range, 0, sizeof(RcpOspfRange) * RCP_OSPF_RANGE_LIMIT);
	shm->config.ospf_discard_internal = 1;
	
	// remove all external lsa
	clear_external();
	

	uint32_t tic2 = times(&tm);
	uint32_t delta;
	if (tic2 > tic1)
		delta = tic2 - tic1;
	else
		delta = tic1 - tic2;
	
	if (delta > systic_delta_operation) {
		systic_delta_operation = delta;
		rcpDebug("operation timeout delta %u\n", systic_delta_operation);
	}
		
	return 0;
}
Exemple #8
0
void parse_dep_file(void *map, size_t len)
{
	char *m = map;
	char *end = m + len;
	char *p;
	char s[PATH_MAX];

	p = strchr(m, ':');
	if (!p) {
		fprintf(stderr, "fixdep: parse error\n");
		exit(1);
	}
	memcpy(s, m, p-m); s[p-m] = 0;
	printf("deps_%s := \\\n", target);
	m = p+1;

	clear_config();

	while (m < end) {
		while (m < end && (*m == ' ' || *m == '\\' || *m == '\n'))
			m++;
		p = m;
		while (p < end && *p != ' ') p++;
		if (p == end) {
			do p--; while (!isalnum(*p));
			p++;
		}
		memcpy(s, m, p-m); s[p-m] = 0;
		if (strrcmp(s, "include/linux/autoconf.h") &&
		    strrcmp(s, "arch/um/include/uml-config.h") &&
		    strrcmp(s, ".ver")) {
			printf("  %s \\\n", s);
			do_config_file(s);
		}
		m = p + 1;
	}
	printf("\n%s: $(deps_%s)\n\n", target, target);
	printf("$(deps_%s):\n", target);
}
Exemple #9
0
int cec_init(int init_video)
{
  int res;

  /* Set the CEC configuration */
  clear_config(&cec_config);
  snprintf(cec_config.strDeviceName, 13, "pidvbip");
  cec_config.clientVersion       = CEC_CONFIG_VERSION;
  cec_config.bActivateSource     = 0;

  /* Say we are a recording/tuner/playback device */
  cec_config.deviceTypes.types[0] = CEC_DEVICE_TYPE_RECORDING_DEVICE;

  /* Set the callbacks */
  clear_callbacks(&cec_callbacks);
  cec_callbacks.CBCecLogMessage  = &CecLogMessage;
  cec_callbacks.CBCecKeyPress    = &CecKeyPress;
  cec_callbacks.CBCecCommand     = &CecCommand;
  cec_callbacks.CBCecAlert       = &CecAlert;
  cec_callbacks.CBCecSourceActivated= &CecSourceActivated;

  cec_config.callbacks           = &cec_callbacks;

  /* Initialise the library */
  if (!cec_initialise(&cec_config)) {
    fprintf(stderr,"Error initialising libcec, aborting\n");
    return 1;
  }

  if (init_video) {
    /* init video on targets that need this */
    cec_init_video_standalone();
  }

  /* Locate CEC device */
  cec_adapter devices[10];
  int nadapters = cec_find_adapters(devices, 10, NULL);

  if (nadapters <= 0) {
    fprintf(stderr,"Error, no CEC adapters found.\n");
    cec_destroy();
    return 2;
  }

  if (nadapters > 1) {
    fprintf(stderr,"WARNING: %d adapters found, using first.\n",nadapters);
  }

  fprintf(stderr,"Using CEC adapter \"%s\", path=\"%s\"\n",devices[0].comm,devices[0].path);

  /* Open device with a 10000ms (10s) timeout */
  if (!cec_open(devices[0].comm, CEC_DEFAULT_CONNECT_TIMEOUT)) {
    fprintf(stderr,"Error, cannot open device %s\n",devices[0].comm);
    cec_destroy();
    return 3;
  }

  /* Enable callbacks, first parameter is the callback data passed to every callback */
  cec_enable_callbacks(NULL, &cec_callbacks);

  /* Get the menu language of the TV */
  cec_menu_language language;
  cec_get_device_menu_language(CEC_DEFAULT_BASE_DEVICE, &language);
  fprintf(stderr,"TV menu language: \"%c%c%c\"\n",language.language[0],language.language[1],language.language[2]);

  /* Get the power status of the TV */
  cec_power_status power_status = cec_get_device_power_status(CEC_DEFAULT_BASE_DEVICE);
  fprintf(stderr,"TV Power Status:  %d\n",power_status);

  /* Select ourselves as the source - this will also power-on the TV if needed */
  fprintf(stderr,"Setting ourselves as the source\n");
  cec_set_active_source(CEC_DEVICE_TYPE_RECORDING_DEVICE);

  /* Clear the keypress queue */
  key_queue.numkeys = 0;
  pthread_mutex_init(&key_queue.mutex,NULL);

  return 0;
}
Exemple #10
0
/*
 * Important: The below generated source_foo.o and deps_foo.o variable
 * assignments are parsed not only by make, but also by the rather simple
 * parser in scripts/mod/sumversion.c.
 */
static void parse_dep_file(void *map, size_t len)
{
	char *m = map;
	char *end = m + len;
	char *p;
	char s[PATH_MAX];
	int is_target;
	int saw_any_target = 0;
	int is_first_dep = 0;

	clear_config();

	while (m < end) {
		/* Skip any "white space" */
		while (m < end && (*m == ' ' || *m == '\\' || *m == '\n'))
			m++;
		/* Find next "white space" */
		p = m;
		while (p < end && *p != ' ' && *p != '\\' && *p != '\n')
			p++;
		/* Is the token we found a target name? */
		is_target = (*(p-1) == ':');
		/* Don't write any target names into the dependency file */
		if (is_target) {
			/* The /next/ file is the first dependency */
			is_first_dep = 1;
		} else {
			/* Save this token/filename */
			memcpy(s, m, p-m);
			s[p - m] = 0;

			/* Ignore certain dependencies */
			if (strrcmp(s, "include/generated/autoconf.h") &&
			    strrcmp(s, "arch/um/include/uml-config.h") &&
			    strrcmp(s, "include/linux/kconfig.h") &&
			    strrcmp(s, ".ver")) {
				/*
				 * Do not list the source file as dependency,
				 * so that kbuild is not confused if a .c file
				 * is rewritten into .S or vice versa. Storing
				 * it in source_* is needed for modpost to
				 * compute srcversions.
				 */
				if (is_first_dep) {
					/*
					 * If processing the concatenation of
					 * multiple dependency files, only
					 * process the first target name, which
					 * will be the original source name,
					 * and ignore any other target names,
					 * which will be intermediate temporary
					 * files.
					 */
					if (!saw_any_target) {
						saw_any_target = 1;
						printf("source_%s := %s\n\n",
							target, s);
						printf("deps_%s := \\\n",
							target);
					}
					is_first_dep = 0;
				} else
					printf("  %s \\\n", s);
				do_config_file(s);
			}
		}
		/*
		 * Start searching for next token immediately after the first
		 * "whitespace" character that follows this token.
		 */
		m = p + 1;
	}

	if (!saw_any_target) {
		fprintf(stderr, "fixdep: parse error; no targets found\n");
		exit(1);
	}

	printf("\n%s: $(deps_%s)\n\n", target, target);
	printf("$(deps_%s):\n", target);
}
Exemple #11
0
static int process_logs(void)
{
	struct daemon_conf config;
	char *filename;
	int len, num = 0;

	if (user_file && userfile_is_dir) {
		char dirname[MAXPATHLEN];
		clear_config (&config);

		strcpy(dirname, user_file);
		if (dirname[strlen(dirname)-1] != '/')
			strcat(dirname, "/");
		strcat (dirname, "audit.log");
		free((void *)config.log_file);
		config.log_file=strdup(dirname);
		fprintf(stderr, "NOTE - using logs in %s\n", config.log_file);
	} else {
		/* Load config so we know where logs are */
       		if (load_config(&config, TEST_SEARCH))
			fprintf(stderr, "NOTE - using built-in logs: %s\n",
				config.log_file);
	}

	/* for each file */
	len = strlen(config.log_file) + 16;
	filename = malloc(len);
	if (!filename) {
		fprintf(stderr, "No memory\n");
		free_config(&config);
		return 1;
	}
	/* Find oldest log file */
	snprintf(filename, len, "%s", config.log_file);
	do {
		if (access(filename, R_OK) != 0)
			break;
// FIXME: do a time check and put them on linked list for later
		num++;
		snprintf(filename, len, "%s.%d", config.log_file, num);
	} while (1);
	num--;
	/*
	 * We note how many files we need to process
	 */
	files_to_process = num;

	/* Got it, now process logs from last to first */
	if (num > 0)
		snprintf(filename, len, "%s.%d", config.log_file, num);
	else
		snprintf(filename, len, "%s", config.log_file);
	do {
		int ret;
		if ((ret = process_file(filename))) {
			free(filename);
			free_config(&config);
			return ret;
		}

		/* Get next log file */
		files_to_process--;     /* one less file to process */
		num--;
		if (num > 0)
			snprintf(filename, len, "%s.%d", config.log_file, num);
		else if (num == 0)
			snprintf(filename, len, "%s", config.log_file);
		else
			break;
	} while (1);
	free(filename);
	free_config(&config);
	return 0;
}
Exemple #12
0
int do_reload_config (int create_conn) {
  int res;
  need_reload_config = 0;

  fd[0] = open (config_filename, O_RDONLY);
  if (fd[0] < 0) {
    fprintf (stderr, "cannot re-read config file %s: %m\n", config_filename);
    return -1;
  }

  res = kdb_load_hosts ();
  if (res > 0 && verbosity > 0) {
    fprintf (stderr, "/etc/hosts changed, reloaded\n");
  }

  res = parse_config (NextConf, CurConf, 0);

  close (fd[0]);

  //  clear_config (NextConf);
  
  if (res < 0) {
    vkprintf (0, "error while re-reading config file %s, new configuration NOT applied\n", config_filename);
    return res;
  }

  res = try_open_new_listening_sockets (NextConf);
  if (res < 0) {
    vkprintf (0, "error while re-reading config file %s, new configuration NOT applied: cannot open listening ports\n", config_filename);
    return res;
  }

  res = parse_config (NextConf, CurConf, 1);

  if (res < 0) {
    clear_config (NextConf, 0);
    vkprintf (0, "fatal error while re-reading config file %s\n", config_filename);
    exit (-res);
  }

  if (create_conn) {
    transfer_listening_sockets (NextConf, CurConf);
  }

  struct mc_config *tmp = CurConf;
  CurConf = NextConf;
  NextConf = tmp;

  clear_config (NextConf, 1);

  if (create_conn) {
    create_all_outbound_connections ();
  }

  CurConf->config_loaded_at = now ? now : time (0);
  CurConf->config_bytes = config_bytes;
  CurConf->config_md5_hex = zmalloc (33);
  md5_hex (config_buff, config_bytes, CurConf->config_md5_hex);
  CurConf->config_md5_hex[32] = 0;

  vkprintf (0, "configuration file %s re-read successfully, new configuration active\n", config_filename);

  return 0;
}
Exemple #13
0
int load_config(remote_conf_t *config, const char *file)
{
	int fd, rc, mode, lineno = 1;
	struct stat st;
	FILE *f;
	char buf[128];

	clear_config(config);

	/* open the file */
	mode = O_RDONLY;
	rc = open(file, mode);
	if (rc < 0) {
		if (errno != ENOENT) {
			syslog(LOG_ERR, "Error opening %s (%s)", file,
				strerror(errno));
			return 1;
		}
		syslog(LOG_WARNING,
			"Config file %s doesn't exist, skipping", file);
		return 0;
	}
	fd = rc;

	/* check the file's permissions: owned by root, not world writable,
	 * not symlink.
	 */
	if (fstat(fd, &st) < 0) {
		syslog(LOG_ERR, "Error fstat'ing config file (%s)", 
			strerror(errno));
		close(fd);
		return 1;
	}
	if (st.st_uid != 0) {
		syslog(LOG_ERR, "Error - %s isn't owned by root", 
			file);
		close(fd);
		return 1;
	}
	if ((st.st_mode & S_IWOTH) == S_IWOTH) {
		syslog(LOG_ERR, "Error - %s is world writable", 
			file);
		close(fd);
		return 1;
	}
	if (!S_ISREG(st.st_mode)) {
		syslog(LOG_ERR, "Error - %s is not a regular file", 
			file);
		close(fd);
		return 1;
	}

	/* it's ok, read line by line */
	f = fdopen(fd, "r");
	if (f == NULL) {
		syslog(LOG_ERR, "Error - fdopen failed (%s)", 
			strerror(errno));
		close(fd);
		return 1;
	}

	while (get_line(f, buf)) {
		// convert line into name-value pair
		const struct kw_pair *kw;
		struct nv_pair nv;
		rc = nv_split(buf, &nv);
		switch (rc) {
			case 0: // fine
				break;
			case 1: // not the right number of tokens.
				syslog(LOG_ERR, 
				"Wrong number of arguments for line %d in %s", 
					lineno, file);
				break;
			case 2: // no '=' sign
				syslog(LOG_ERR, 
					"Missing equal sign for line %d in %s", 
					lineno, file);
				break;
			default: // something else went wrong... 
				syslog(LOG_ERR, 
					"Unknown error for line %d in %s", 
					lineno, file);
				break;
		}
		if (nv.name == NULL) {
			lineno++;
			continue;
		}
		if (nv.value == NULL) {
			fclose(f);
			return 1;
		}

		/* identify keyword or error */
		kw = kw_lookup(nv.name);
		if (kw->name == NULL) {
			syslog(LOG_ERR, 
				"Unknown keyword \"%s\" in line %d of %s", 
				nv.name, lineno, file);
			fclose(f);
			return 1;
		}

		/* Check number of options */
		if (kw->max_options == 0 && nv.option != NULL) {
			syslog(LOG_ERR, 
				"Keyword \"%s\" has invalid option "
				"\"%s\" in line %d of %s", 
				nv.name, nv.option, lineno, file);
			fclose(f);
			return 1;
		}

		/* dispatch to keyword's local parser */
		rc = kw->parser(&nv, lineno, config);
		if (rc != 0) {
			fclose(f);
			return 1; // local parser puts message out
		}

		lineno++;
	}

	fclose(f);
	if (lineno > 1)
		return sanity_check(config, file);
	return 0;
}