Ejemplo n.º 1
0
/**
 * Finalize PC Groups: free DBMaps and config.
 * @public
 */
void do_final_pc_groups(void)
{
	if (pc_group_db != NULL)
		db_destroy(pc_group_db);
	if (pc_groupname_db != NULL )
		db_destroy(pc_groupname_db);
	destroy_config();
}
Ejemplo n.º 2
0
static void set_config(CONFIG **config, char *data, int length, char *filename)
{
   char name[256];
   char val[256];
   CONFIG_ENTRY **prev, *p;
   int pos;

   init_config(FALSE);
   
   GUI_printf("wtf2\n");

   if (*config) {
      destroy_config(*config);
      *config = NULL;
   }

   *config = malloc(sizeof(CONFIG));
   if (!(*config))
      return;

   (*config)->head = NULL;
   (*config)->dirty = FALSE;

   if (filename) {
      (*config)->filename = malloc(strlen(filename)+1);
      if ((*config)->filename)
	 strcpy((*config)->filename, filename); 
   }
   else
      (*config)->filename = NULL;

   prev = &(*config)->head;
   pos = 0;

   while (pos < length) {
      pos += get_line(data+pos, length-pos, name, val);

      p = malloc(sizeof(CONFIG_ENTRY));
      if (!p)
	 return;

      if (name[0]) {
	 p->name = malloc(strlen(name)+1);
	 if (p->name)
	    strcpy(p->name, name);
      }
      else
	 p->name = NULL;

      p->data = malloc(strlen(val)+1);
      if (p->data)
	 strcpy(p->data, val);

      p->next = NULL;
      *prev = p;
      prev = &p->next;
   }
}
Ejemplo n.º 3
0
/* config_cleanup:
 *  Called at shutdown time to free memory being used by the config routines,
 *  and write any changed data out to disk.
 */
void config_cleanup()
{
   CONFIG_HOOK *hook, *nexthook;
   int i;

   for (i=0; i<MAX_CONFIGS; i++) {
      if (config[i]) {
	 destroy_config(config[i]);
	 config[i] = NULL;
      }
   }

   if (config_override) {
      destroy_config(config_override);
      config_override = NULL;
   }

   if (config_language) {
      destroy_config(config_language);
      config_language = NULL;
   }

   if (system_config) {
      destroy_config(system_config);
      system_config = NULL;
   }

   if (config_hook) {
      hook = config_hook;

      while (hook) {
	 if (hook->section)
	    free(hook->section);

	 nexthook = hook->next; 
	 free(hook);
	 hook = nexthook;
      }

      config_hook = NULL;
   }

//   _remove_exit_func(config_cleanup);
   config_installed = FALSE;
}
Ejemplo n.º 4
0
/* config_cleanup:
 *  Called at shutdown time to free memory being used by the config routines,
 *  and write any changed data out to disk.
 */
static void config_cleanup()
{
   int i;

   for (i=0; i<MAX_CONFIGS; i++) {
      if (config[i]) {
	 destroy_config(config[i]);
	 config[i] = NULL;
      }
   }

   if (config_override) {
      destroy_config(config_override);
      config_override = NULL;
   }

/*   _remove_exit_func(config_cleanup);*/
   config_installed = FALSE;
}
Ejemplo n.º 5
0
int
main(int argc, char* argv[])
{
	// Parse command line arguments.
	if (! set_config(argc, argv)) {
		exit(-1);
	}

	// Use default Citrusleaf client logging, but set a filter.
	cf_set_log_level(CF_WARN);

	// Connect to the database server cluster.
	if (! start_cluster_management()) {
		stop_cluster_management();
		destroy_config();
		exit(-1);
	}

	// Set up an array of event bases and thread IDs on the stack.
	base bases[g_config.num_bases];

	// Make these globally available.
	g_bases = bases;

	// Set up an array of record keys on the stack.
	ev2citrusleaf_object keys[g_config.num_keys];

	// Make these globally available.
	g_keys = keys;

	// Start transactions on all the bases.
	start_transactions();

	// Wait for everything to finish, then exit cleanly.
	block_until_transactions_done();
	stop_cluster_management();
	destroy_config();

	LOG("example3 is done");

	return 0;
}
Ejemplo n.º 6
0
/* push_config_state:
 *  Pushes the current config state onto the stack.
 */
void push_config_state()
{
   int i;

   if (config[MAX_CONFIGS-1])
      destroy_config(config[MAX_CONFIGS-1]);

   for (i=MAX_CONFIGS-1; i>0; i--)
      config[i] = config[i-1];

   config[0] = NULL;
}
Ejemplo n.º 7
0
/* pop_config_state:
 *  Pops the current config state off the stack.
 */
void pop_config_state()
{
   int i;

   if (config[0])
      destroy_config(config[0]);

   for (i=0; i<MAX_CONFIGS-1; i++)
      config[i] = config[i+1];

   config[MAX_CONFIGS-1] = NULL;
}
Ejemplo n.º 8
0
Archivo: main.c Proyecto: ejrh/snmp
static void run(Options *options)
{
    int socket = open_udp_socket(options->listen_port);

    if (options->verbose)
        fprintf(stderr, "Opened socket on port %d\n", options->listen_port);
    
    if (signal(SIGQUIT, handle_sigquit) == SIG_IGN)
        signal(SIGQUIT, SIG_IGN);
    
    reload_config = 1;
    
    while (1)
    {
        int sleep_time;
        
        if (reload_config)
        {
            if (options->config != NULL)
                destroy_config(options->config);
            
            options->config = load_config(options->config_filename);
            if (!options->config)
            {
                fprintf(stderr, "Warning: Config file cannot be read: %s\n", options->config_filename);
                options->config = create_config();
            }
            initialise_config(options->config);
            
            if (options->verbose)
            {
                fprintf(stderr, "Loaded config from %s\n", options->config_filename);
                print_config(options->config, stderr);
            }
            
            reload_config = 0;
        }
        
        //TODO how long until the next request goes out?
        sleep_time = 1;
        input_timeout(socket, sleep_time);
        check_for_responses(options, socket);
        check_requests(options, socket);
    }
    
    close(socket);
}
Ejemplo n.º 9
0
void destroy_supervisor(supervisor_thread_t *thiz) {
    if(thiz) {
        int w = 0;
        for(w = 0; w < thiz->config->num_workers; w++) {
            destroy_worker(thiz->worker_threads[w]);
        }
        thiz->worker_threads = NULL;
        destroy_rate_limiter(thiz->rate_limiter);
        destroy_queue(thiz->queue);
        destroy_config(thiz->config);
        destroy_worker_array();
        TESR_LOG_FREE(thiz, supervisor_thread_t);
        free(thiz);
        thiz = NULL;
    } else {
        LOG_ERROR("can not free supervisor_thread_t* as it is NULL");
    }
}
Ejemplo n.º 10
0
static int ss7_unload_module(void)
{
  cli_unregister();

#ifdef SCCP
  sccp_cleanup();
#endif
  isup_cleanup();

  cleanup_dump(0, 1, 1);
  if(monitor_running) {
    stop_monitor();
  }
  stop_mtp_thread();
  mtp_cleanup();
  timers_cleanup();


  destroy_config();
  ast_verbose(VERBOSE_PREFIX_3 "SS7 channel unloaded.\n");
  return AST_MODULE_LOAD_SUCCESS;
}
Ejemplo n.º 11
0
/* load_config_file:
 *  Does the work of loading a config file.
 */
static void load_config_file(CONFIG **config, char *filename, char *savefile)
{
	int length;
	GUI_printf("wtf\n");

	if (*config)
	{
		destroy_config(*config);
		*config = NULL;
	}

	length = file_size(filename);
	GUI_printf("wtf3\n");

	if (length > 0)
	{
		FS_lock();
		FILE *f = fopen(filename, "rb");
		if (f)
		{
			char *tmp = malloc(length);
			if (tmp)
			{
				fread(tmp, 1, length, f);
				set_config(config, tmp, length, savefile);
				free(tmp);
			}
			else
				set_config(config, NULL, 0, savefile);
			fclose(f);
		}
		else
			set_config(config, NULL, 0, savefile);
		FS_unlock();
	}
	else
		set_config(config, NULL, 0, savefile);
}
Ejemplo n.º 12
0
int main(int argc, char *argv[])
{
	char *user = NULL;
	char *input = NULL;
	char *output = NULL;
	int input_location = 0;
	bool multiple_input = false;
	bool one_passed = false;
	bool output_is_dir = false;
	struct config cfg;
	int c;

	while((c=getopt(argc, argv, "hdu:")) != -1)	{
		switch(c)	{
			case 'u':
				user = optarg;
				break;
			case 'h':
				usage(argv[0]);
				exit(NO_ERROR);
			case 'd':
				_debug = 1;
				break;
			case '?':
				if(strchr("u", optopt) == NULL)
					fprintf(stderr,
						"Unknown option -%c encountered\n", optopt);
				else
					fprintf(stderr,
						"Option -%c requires an argument\n", optopt);
				exit(USAGE_ERROR);
			default:
				abort();
		}
	}
	debug("optind: %d, argc: %d", optind, argc);
	if(optind + 2 == argc)	{
		input = argv[optind];
		output = argv[optind + 1];
		multiple_input = false;
	} else if (optind + 2 < argc)	{
		input_location = optind;
		output = argv[argc - 1];
		multiple_input = true;
	} else  {
		fprintf(stderr, "Invalid number of arguments\n");
		usage(argv[0]);
		exit(USAGE_ERROR);
	}

	if(user == NULL)	{
		fprintf(stderr,
				"Error, user must be supplied with -u <user> argument\n"
				"\tRerun with -h to see usage-details\n");
		exit(USAGE_ERROR);
	}

	/* All of these functions exit the program unless everything is A-OK */
	read_config(CONFIG_PATH, &cfg);

	/* If the user running the program doesn't match the config-file, exit */
	die_unless_user(cfg.required_user);

	/* Try to become target user iff. they are a member of the right group */
	if_valid_become(user, cfg.required_group);

	/* Append a '/' if the output is a dir and it doesn't have one */
	output = dirify_output(output, &output_is_dir);
	debug("output now: %s (%d)", output, output_is_dir);

	/* If the output path isn't in the list of allowed outputs, exit */
	validate_output(output, cfg.allowed_paths);

	destroy_config(&cfg);

	/* Do the actual copy, failing on any error condition */
	if(!multiple_input)	{
		copy_file(input, output);
	} else {
		struct stat sb;
		char *p;
		int i;

		if(!output_is_dir)
			log_exit(USAGE_ERROR, "Error: destination %s must be a directory", output);

		debug("Multiple inputs, %d files to %s", argc - input_location - 1,
			  output);
		for(i = input_location; i < argc - 1; i++)	{
			p = argv[i];

			if(stat(p, &sb) < 0)
				log_exit_perror(FILEPERM_ERROR, "stat input: %s", p);

			switch(sb.st_mode & S_IFMT)	{
				case S_IFREG:
					debug("**************  Copy file %d  ****************",
						  i - input_location + 1);
					copy_file(p, output);
					one_passed = true;
					break;
				case S_IFDIR:
					log_msg("%s is a directory, skipping", p);	break;
				default:
					log_msg("%s is not a regular file, skip", p);	break;
			}
		}
	}

	/* changed by dirify() above */
	free(output);

	if(multiple_input && !one_passed)	{
		debug("No files copied, exit NO_ACTION_ERROR");
		return NO_ACTION_ERROR;
	} else {
		debug("Finished, exit OK");
		return NO_ERROR;
	}
}
Ejemplo n.º 13
0
static void set_config(CONFIG **config, char *data, int length, char *filename)
{
   char name[256];
   char val[256];
   CONFIG_SECTION **prev, *p;
   CONFIG_ENTRY	**prev_e, *p_e;
   int pos;
   int	in_section = 0;

   init_config(FALSE);

   if (*config) {
      destroy_config(*config);
      *config = NULL;
   }

   *config = malloc(sizeof(CONFIG));
   if (!(*config))
      return;

   (*config)->head = NULL;
   (*config)->dirty = FALSE;

   if (filename) {
      (*config)->filename = malloc(strlen(filename)+1);
      if ((*config)->filename)
	 strcpy((*config)->filename, filename); 
   }
   else
      (*config)->filename = NULL;

   prev = &(*config)->head;
   pos = 0;

   while (pos < length) {
      pos += get_line(data+pos, length-pos, name, val);

      if (in_section && name[0] == '[')
	  {
	      in_section = 0;
	  }

      if (in_section)
      {
	  p_e = malloc(sizeof(CONFIG_ENTRY));
          if (!p_e)
    	    return;

          if (name[0]) {
	     p_e->name = malloc(strlen(name)+1);
	     if (p_e->name)
		strcpy(p_e->name, name);
	  }
	  else
	     p_e->name = NULL;

	  p_e->data = malloc(strlen(val)+1);
	  if (p_e->data)
	     strcpy(p_e->data, val);

	  p_e->next = NULL;
	  *prev_e = p_e;
	  prev_e = &p_e->next;

	  continue;
      }	

      p = malloc(sizeof(CONFIG_SECTION));
      if (!p)
	 return;

      p->key = NULL;

      if (name[0]) {
	 p->name = malloc(strlen(name)+1);
	 if (p->name)
	    strcpy(p->name, name);
      }
      else
	 p->name = NULL;

      p->data = malloc(strlen(val)+1);
      if (p->data)
	 strcpy(p->data, val);

      p->next = NULL;
      *prev = p;
      prev = &p->next;

      // FIXME
      if (name[0] == '[')
      {
	  prev_e = &p->head;
	  in_section = 1;
      }
   }
}
Ejemplo n.º 14
0
static DBusMessage *create_proxy_config(DBusConnection *conn,
					DBusMessage *msg, void *user_data)
{
	DBusMessage *reply;
	DBusMessageIter iter, array;
	struct proxy_config *config;
	const char *sender, *method = NULL, *interface = NULL;
	const char *url = NULL, *script = NULL;
	char **servers = NULL, **excludes = NULL;
	char **domains = NULL, **nameservers = NULL;

	sender = dbus_message_get_sender(msg);

	dbus_message_iter_init(msg, &iter);
	dbus_message_iter_recurse(&iter, &array);

	while (dbus_message_iter_get_arg_type(&array) == DBUS_TYPE_DICT_ENTRY) {
		DBusMessageIter entry, value, list;
		const char *key;

		dbus_message_iter_recurse(&array, &entry);
		dbus_message_iter_get_basic(&entry, &key);

		dbus_message_iter_next(&entry);
		dbus_message_iter_recurse(&entry, &value);

		switch (dbus_message_iter_get_arg_type(&value)) {
		case DBUS_TYPE_STRING:
			if (g_str_equal(key, "Method")) {
				dbus_message_iter_get_basic(&value, &method);
				if (strlen(method) == 0)
					method = NULL;
			} else if (g_str_equal(key, "URL")) {
				dbus_message_iter_get_basic(&value, &url);
				if (strlen(url) == 0)
					url = NULL;
			} else if (g_str_equal(key, "Script")) {
				dbus_message_iter_get_basic(&value, &script);
				if (strlen(script) == 0)
					script = NULL;
			} else if (g_str_equal(key, "Interface")) {
				dbus_message_iter_get_basic(&value, &interface);
				if (strlen(interface) == 0)
					interface = NULL;
			}
			break;
		case DBUS_TYPE_ARRAY:
			dbus_message_iter_recurse(&value, &list);

			if (dbus_message_iter_get_arg_type(&list) ==
							DBUS_TYPE_INVALID)
				break;

			if (g_str_equal(key, "Servers")) {
				g_strfreev(servers);
				servers = extract_string_array(&list);
			} else if (g_str_equal(key, "Excludes")) {
				g_strfreev(excludes);
				excludes = extract_string_array(&list);
			} else if (g_str_equal(key, "Domains")) {
				g_strfreev(domains);
				domains = extract_string_array(&list);
			} else if (g_str_equal(key, "Nameservers")) {
				g_strfreev(nameservers);
				nameservers = extract_string_array(&list);
			}
			break;
		}

		dbus_message_iter_next(&array);
	}

	DBG("sender %s method %s interface %s", sender, method, interface);
	DBG("url %s script %p", url, script);

	if (!method) {
		reply = g_dbus_create_error(msg,
					PACRUNNER_ERROR_INTERFACE ".Failed",
					"No proxy method specified");
		goto done;
	}

	config = create_config(conn, sender, interface);
	if (!config) {
		reply = g_dbus_create_error(msg,
					PACRUNNER_ERROR_INTERFACE ".Failed",
					"Memory allocation failed");
		goto done;
	}

	config->domains = domains;
	config->nameservers = nameservers;

	domains = NULL;
	nameservers = NULL;

	if (g_str_equal(method, "direct")) {
		if (pacrunner_proxy_set_direct(config->proxy) < 0)
			pacrunner_error("Failed to set direct proxy");
	} else if (g_str_equal(method, "manual")) {
		if (pacrunner_proxy_set_manual(config->proxy,
						servers, excludes) < 0)
			pacrunner_error("Failed to set proxy servers");
	} else if (g_str_equal(method, "auto")) {
		if (pacrunner_proxy_set_auto(config->proxy, url, script) < 0)
			pacrunner_error("Failed to set auto proxy");
	} else {
		destroy_config(config);
		reply = g_dbus_create_error(msg,
					PACRUNNER_ERROR_INTERFACE ".Failed",
					"Invalid proxy method specified");
		goto done;
	}

	g_hash_table_insert(config_list, config->path, config);


	reply = g_dbus_create_reply(msg, DBUS_TYPE_OBJECT_PATH, &config->path,
							DBUS_TYPE_INVALID);

done:
	g_strfreev(servers);
	g_strfreev(excludes);

	g_strfreev(domains);
	g_strfreev(nameservers);

	return reply;
}
Ejemplo n.º 15
0
extern int fini ( void )
{
	destroy_config();
	return SLURM_SUCCESS;
}
Ejemplo n.º 16
0
int reload_config(void)
{
	destroy_config();
	return load_config();
}
Ejemplo n.º 17
0
struct config* parse_config(FILE *input) {
	struct config *config = malloc(sizeof(struct config));
	if (config == NULL) {
		stats_error_log("malloc() error");
		return NULL;
	}

	init_proto_config(&config->carbon_config);
	if (config->carbon_config.ring == NULL) {
		stats_error_log("failed to allocate ring");
		free(config);
		return NULL;
	}
	config->carbon_config.bind = strdup("127.0.0.1:2003");

	init_proto_config(&config->statsd_config);
	config->statsd_config.bind = strdup("127.0.0.1:8125");

	yaml_parser_t parser;
	yaml_event_t event;

	if (!yaml_parser_initialize(&parser)) {
		stats_log("failed to initialize yaml parser");
		goto parse_err;
	}
	yaml_parser_set_input_file(&parser, input);

	struct proto_config *protoc = NULL;
	char *strval;
	long numval;
	int shard_count = -1;
	int map_nesting = 0;
	bool in_document = false;
	bool keep_going = true;
	bool is_key = false;
	bool update_bind = false;
	bool update_send_queue = false;
	bool update_validate = false;
	bool update_tcp_cork = false;
	bool always_resolve_dns = false;
	bool expect_shard_map = false;
	while (keep_going) {
		if (!yaml_parser_parse(&parser, &event)) {
			goto parse_err;
		}

		switch(event.type) {
		case YAML_NO_EVENT:
		case YAML_STREAM_START_EVENT:
			break;  // nothing to do
		case YAML_STREAM_END_EVENT:
			keep_going = false;
			break;
		case YAML_DOCUMENT_START_EVENT:
			if (in_document) {
				stats_error_log("config should not have nested documents");
				goto parse_err;
			}
			in_document = true;
			break;
		case YAML_DOCUMENT_END_EVENT:
			in_document = false;
			break;
		case YAML_SEQUENCE_START_EVENT:
		case YAML_SEQUENCE_END_EVENT:
			stats_error_log("unexpectedly got sequence");
			goto parse_err;
			break;
		case YAML_MAPPING_START_EVENT:
			is_key = true;
			map_nesting++;
			break;
		case YAML_MAPPING_END_EVENT:
			map_nesting--;
			break;
		case YAML_ALIAS_EVENT:
			stats_error_log("don't know how to handle yaml aliases");
			goto parse_err;
			break;
		case YAML_SCALAR_EVENT:
			strval = (char *) event.data.scalar.value;
			switch (map_nesting) {
			case 0:
				stats_error_log("unexpectedly got scalar outside of a map");
				goto parse_err;
				break;
			case 1:
				if (strcmp(strval, "carbon") == 0) {
					protoc = &config->carbon_config;
					config->carbon_config.initialized = true;
				} else if (strcmp(strval, "statsd") == 0) {
					protoc = &config->statsd_config;
					config->statsd_config.initialized = true;
				} else {
					stats_error_log("unexpectedly got map value: \"%s\"", strval);
					goto parse_err;
				}
				break;
			case 2:
				if (is_key) {
					if (strcmp(strval, "bind") == 0) {
						update_bind = true;
					} else if (strcmp(strval, "max_send_queue") == 0) {
						update_send_queue = true;
					} else if (strcmp(strval, "shard_map") == 0) {
						shard_count = -1;
						expect_shard_map = true;
					} else if (strcmp(strval, "validate") == 0) {
						update_validate = true;
					} else if (strcmp(strval, "tcp_cork") == 0) {
						update_tcp_cork = true;
					} else if (strcmp(strval, "always_resolve_dns") == 0) {
						always_resolve_dns = true;
					}
				} else {
					if (update_bind) {
						free(protoc->bind);
						protoc->bind = strdup(strval);
						update_bind = false;
					} else if (update_send_queue) {
						if (!convert_number(strval, &numval)) {
							stats_error_log("max_send_queue was not a number: %s", strval);
						}
						protoc->max_send_queue = numval;
						update_send_queue = false;
					} else if (update_validate) {
						if (!set_boolean(strval, &protoc->enable_validation)) {
							goto parse_err;
						}
						update_validate = false;
					} else if (update_tcp_cork) {
						if (!set_boolean(strval, &protoc->enable_tcp_cork)) {
							goto parse_err;
						}
						update_tcp_cork = false;
					} else if (always_resolve_dns) {
						if (!set_boolean(strval, &protoc->always_resolve_dns)) {
							goto parse_err;
						}
					}
				}
				break;
			case 3:
				if (!expect_shard_map) {
					stats_error_log("was not expecting shard map");
					goto parse_err;
				} else if (is_key) {
					if (!convert_number(strval, &numval)) {
						stats_error_log("shard key was not a number: \"%s\"", strval);
						goto parse_err;

					}
					shard_count++;
					if (numval != shard_count) {
						stats_error_log("expected to see shard key %d, instead saw %d",
							  shard_count, numval);
						goto parse_err;
					}
				} else {
					if (statsrelay_list_expand(protoc->ring) == NULL) {
						stats_error_log("unable to expand list");
						goto parse_err;
					}
					if ((protoc->ring->data[protoc->ring->size - 1]  = strdup(strval)) == NULL) {
						stats_error_log("failed to copy string");
						goto parse_err;
					}
				}
			}
			is_key = !is_key;
			break;
		default:
			stats_error_log("unhandled yaml event");
			goto parse_err;
		}
		yaml_event_delete(&event);
	}

	yaml_parser_delete(&parser);
	return config;

parse_err:
	destroy_config(config);
	yaml_event_delete(&event);
	yaml_parser_delete(&parser);
	return NULL;
}
Ejemplo n.º 18
0
//------------------------------------------------
// Parse command line options.
//
static bool
set_config(int argc, char* argv[])
{
	g_config.p_host = DEFAULT_HOST;
	g_config.port = DEFAULT_PORT;
	g_config.p_namespace = DEFAULT_NAMESPACE;
	g_config.p_set = DEFAULT_SET;
	g_config.trigger_usec = DEFAULT_TRIGGER_USEC;
	g_config.timeout_msec = DEFAULT_TIMEOUT_MSEC;
	g_config.num_bases = DEFAULT_NUM_BASES;
	g_config.num_keys = DEFAULT_NUM_KEYS;

	int c;

	while ((c = getopt(argc, argv, "h:p:n:s:u:m:b:k:")) != -1) {
		switch (c) {
		case 'h':
			g_config.p_host = strdup(optarg);
			break;

		case 'p':
			g_config.port = atoi(optarg);
			break;

		case 'n':
			g_config.p_namespace = strdup(optarg);
			break;

		case 's':
			g_config.p_set = strdup(optarg);
			break;

		case 'u':
			g_config.trigger_usec = atoi(optarg);
			break;

		case 'm':
			g_config.timeout_msec = atoi(optarg);
			break;

		case 'b':
			g_config.num_bases = atoi(optarg);
			break;

		case 'k':
			g_config.num_keys = atoi(optarg);
			break;

		default:
			destroy_config();
			usage();
			return false;
		}
	}

	LOG("host:                %s", g_config.p_host);
	LOG("port:                %d", g_config.port);
	LOG("namespace:           %s", g_config.p_namespace);
	LOG("set name:            %s", g_config.p_set);
	LOG("transaction trigger: every %d usec", g_config.trigger_usec);
	LOG("transaction timeout: %d msec", g_config.timeout_msec);
	LOG("number of bases:     %d", g_config.num_bases);
	LOG("number of keys:      %d", g_config.num_keys);

	return true;
}
Ejemplo n.º 19
0
int
main (int argc, char **argv)
{
#ifdef G_OS_WIN32
	extern void link_shutdown (void);
#endif

	GConfClient *client;
#if DEVELOPMENT
	gboolean skip_warning_dialog;
#endif
	GnomeProgram *program;
	GnomeClient *master_client;
	GOptionContext *context;
	char *filename;

	/* Make ElectricFence work.  */
	free (malloc (10));

	bindtextdomain (GETTEXT_PACKAGE, EVOLUTION_LOCALEDIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);

	context = g_option_context_new (_("- The Evolution PIM and Email Client"));

	g_option_context_add_main_entries (context, options, GETTEXT_PACKAGE);

	g_option_context_set_translation_domain(context, GETTEXT_PACKAGE);

#ifdef G_OS_WIN32
	set_paths ();
#endif

	program = gnome_program_init (PACKAGE, VERSION, LIBGNOMEUI_MODULE, argc, argv,
				      GNOME_PROGRAM_STANDARD_PROPERTIES,
				      GNOME_PARAM_GOPTION_CONTEXT, context,
				      GNOME_PARAM_HUMAN_READABLE_NAME, _("Evolution"),
				      NULL);

#ifdef G_OS_WIN32
	if (strcmp (_(""), "") == 0) {
		/* No message catalog installed for the current locale language,
		 * so don't bother with the localisations provided by other things then
		 * either. Reset thread locale to "en-US" and C library locale to "C".
		 */
		SetThreadLocale (MAKELCID (MAKELANGID (LANG_ENGLISH, SUBLANG_ENGLISH_US),
					   SORT_DEFAULT));
		setlocale (LC_ALL, "C");
	}
#endif
	if (start_online && start_offline) {
		fprintf (stderr, _("%s: --online and --offline cannot be used together.\n  Use %s --help for more information.\n"),
			 argv[0], argv[0]);
		exit (1);
	}

	if (killev) {
		filename = g_build_filename (EVOLUTION_TOOLSDIR,
					     "killev",
					     NULL);
		execl (filename, "killev", NULL);
		/* Not reached */
		exit (0);
	}

	client = gconf_client_get_default ();

#if DEVELOPMENT
	
	if (force_migrate) {
		destroy_config (client);
	}
#endif
	if (disable_preview) {
		gconf_client_set_bool (client, "/apps/evolution/mail/display/show_preview", FALSE, NULL);
		gconf_client_set_bool (client, "/apps/evolution/mail/display/safe_list", TRUE, NULL);
		gconf_client_set_bool (client, "/apps/evolution/addressbook/display/show_preview", FALSE, NULL);
		gconf_client_set_bool (client, "/apps/evolution/calendar/display/show_task_preview", FALSE, NULL);
	}

	setup_segv_redirect ();

	if (evolution_debug_log) {
		int fd;

		fd = g_open (evolution_debug_log, O_WRONLY | O_CREAT | O_TRUNC, 0600);
		if (fd != -1) {
			dup2 (fd, STDOUT_FILENO);
			dup2 (fd, STDERR_FILENO);
			close (fd);
		} else
			g_warning ("Could not set up debugging output file.");
	}

	master_client = gnome_master_client ();

	g_signal_connect (G_OBJECT (master_client), "save_yourself", G_CALLBACK (gnome_master_client_save_yourself_cb), NULL);
	g_signal_connect (G_OBJECT (master_client), "die", G_CALLBACK (gnome_master_client_die_cb), NULL);

	glade_init ();
	e_cursors_init ();
	e_icon_factory_init ();
	e_passwords_init();

	gtk_window_set_default_icon_name ("evolution");

	if (setup_only)
		exit (0);

	gnome_sound_init ("localhost");

	if (!disable_eplugin) {
		e_plugin_register_type(e_plugin_lib_get_type());
		e_plugin_hook_register_type(es_menu_hook_get_type());
		e_plugin_hook_register_type(es_event_hook_get_type());
#ifdef ENABLE_PROFILING
		e_plugin_hook_register_type(e_profile_event_hook_get_type());
#endif
		e_plugin_hook_register_type(e_plugin_type_hook_get_type());
		e_plugin_hook_register_type(e_import_hook_get_type());
		e_plugin_hook_register_type(E_TYPE_PLUGIN_UI_HOOK);
		e_plugin_load_plugins();
	}

#if DEVELOPMENT
	skip_warning_dialog = gconf_client_get_bool (
		client, SKIP_WARNING_DIALOG_KEY, NULL);

	if (!skip_warning_dialog && !getenv ("EVOLVE_ME_HARDER"))
		gconf_client_set_bool (
			client, SKIP_WARNING_DIALOG_KEY,
			show_development_warning (), NULL);
	else
		g_idle_add ((GSourceFunc) idle_cb, remaining_args);

#else
	g_idle_add ((GSourceFunc) idle_cb, remaining_args);
#endif
	g_object_unref (client);

	bonobo_main ();

	e_icon_factory_shutdown ();
	g_object_unref (program);
	gnome_sound_shutdown ();
	e_cursors_shutdown ();
#ifdef G_OS_WIN32
	link_shutdown ();
#endif
	return 0;
}
Ejemplo n.º 20
0
int main(int argc, char **argv) {
	char *config_name = (char *) default_config;
	int8_t c = 0;
	while (c != -1) {
		c = (int8_t)getopt_long(argc, argv, "c:h", long_options, NULL);
		switch (c) {
		case -1:
			break;
		case 0:
		case 'h':
			print_help(argv[0]);
			return 0;
		case 'c':
			config_name = optarg;
			break;
		default:
			printf("%s: Unknown argument %c\n", argv[0], c);
			return 1;
		}
	}
	if (optind != 1 && optind != 3) {
		printf("%s: unexpected command optoins\n", argv[0]);
		return 1;
	}

	FILE *config_file = fopen(config_name, "r");
	if (config_file == NULL) {
		fprintf(stderr, "failed to open %s\n", config_name);
		return 1;
	}
	struct config *app_cfg = parse_config(config_file);

	fclose(config_file);
	if (app_cfg == NULL) {
		fprintf(stderr, "failed to parse config %s\n", config_name);
		return 1;
	}

	hashring_t carbon_ring = NULL, statsd_ring = NULL;

	if (app_cfg->carbon_config.initialized) {
		carbon_ring = hashring_load_from_config(
			&app_cfg->carbon_config, NULL, my_strdup, free);
	}
	if (app_cfg->statsd_config.initialized) {
		statsd_ring = hashring_load_from_config(
			&app_cfg->statsd_config, NULL, my_strdup, free);
	}
	destroy_config(app_cfg);

	uint32_t shard;
	char *choice = NULL;
	char *line = NULL;
	size_t len;
	ssize_t bytes_read;
	while ((bytes_read = getline(&line, &len, stdin)) != -1) {
		// trim whitespace
		for (ssize_t i = 0; i < bytes_read; i++) {
			if (isspace(line[i])) {
				line[i] = '\0';
				break;
			}
		}
		printf("key=%s", line);
		if (carbon_ring != NULL) {
			choice = hashring_choose(carbon_ring, line, &shard);
			if (choice != NULL) {
				printf(" carbon=%s carbon_shard=%d", choice, shard);
			}
		}
		if (statsd_ring != NULL) {
			choice = hashring_choose(statsd_ring, line, &shard);
			if (choice != NULL) {
				printf(" statsd=%s statsd_shard=%d", choice, shard);
			}
		}
		putchar('\n');
		fflush(stdout);
	}
	free(line);
	hashring_dealloc(carbon_ring);
	hashring_dealloc(statsd_ring);
	return 0;
}
Ejemplo n.º 21
0
Archivo: main.c Proyecto: asdr/PCA
int main ( int argc, char** argv ) {
  FILE* pipe;
  SHAREDBUFFER* shared_buffer;
  CONFIG* config;
  char main_process_lifetime[15];
  int producer_count = 0;
  char producer_lifetime[15];
  int consumer_count = 0;
  int child_exit_status = 0;
  int child_exit_pid;
  int child_pid;
  int i = 0;
  int logfd;
  char message[150];
  char dir[255];
  int available_process_count = 10000;

  strncpy(dir, argv[0], last_index_of(argv[0], '/'));
  chdir(dir);

  logfd = log_open_file( NULL );
  if ( !logfd )
    {
      printf("Unable to open log file.\n");
      return EXIT_FAILURE;
    }

  log_event( "--------------------------------" );
  log_event( "Main process started." );

  // first of all load configuration file
  config = load_config_file();

  if ( !config )
    {
      log_event( "Unable to access configuration." );
      return EXIT_FAILURE;
    }

  // read values from configuration
  producer_count = atoi(read_configuration(config, "producer_count", "5"));
  consumer_count = atoi(read_configuration(config, "consumer_count", "2"));
  strcpy(producer_lifetime, read_configuration(config, "producer_lifetime", "10"));
  strcpy(main_process_lifetime, read_configuration(config, "main_process_lifetime", "40"));

  destroy_config( config );

  log_event( "Fetching available process count of system." );
  pipe = popen(PROCESS_COUNT_SCRIPT, "r");
  if ( pipe )
    {
      fgets(message, 100, pipe);
      pclose(pipe);
      available_process_count = atoi(message);
    }

  if ( producer_count + consumer_count + 1 > available_process_count )
    {
      log_event( "Requested total process count is more than available process count of system." );
      goto SAFE_EXIT;
    }

  //initialize shared buffer
  shared_buffer = create_shared_buffer();

  if ( !shared_buffer )
    {
      log_event( "Unable to initialize shared buffer." );
      destroy_config( config );
      return EXIT_FAILURE;
    }

  // create and start producer processes
  // producer processes run for a specified lifetime ( in seconds )
  // which is read from configuration
  for ( i=0; i<producer_count; ++i)
    {
      child_pid = vfork();
      if ( child_pid == 0 ) // producer process
        {
          execl("producer", "producer", producer_lifetime, NULL);
          exit(0);
        }
    }

  // start consumer processes
  // consumer processes run until a SIGKILL signal
  // there is no specific entry in the requirements that
  // when a consumer process should end.
  for ( i=0; i<consumer_count; ++i)
    {
      child_pid = vfork();
      if ( child_pid == 0 ) // consumer process
        {
          execl("consumer", "consumer", NULL);
          exit(0);
        }
    }

  // start controller process
  // controller process checks elapsed time
  // once in every 5 seconds
  // if total execution time is above a specified time (in seconds)
  // signals all child processes except itself, to force exit
  child_pid = vfork();
  if ( child_pid == 0 ) //controller process
    {
      execl("controller", "controller", main_process_lifetime, NULL);
      exit(0);
    }

  // in order to catch all child processes exits
  // we need a common wait for all them
  // here exitting processes is cought with pid and exit status
  // wait childs to exit
  while( (child_exit_pid = wait(&child_exit_status)) > 0 )
    {
      sprintf( message, "Process [PID:%d] exitid with status: %d", child_exit_pid, child_exit_status );
      log_event( message );
    }

 SAFE_EXIT:
  log_event( "Main process is being closed." );

  // relase allocated data structures to OS
  destroy_shared_buffer( shared_buffer );

  log_close_file(  );

  return EXIT_SUCCESS;
}