コード例 #1
0
ファイル: ebusd.c プロジェクト: hannesgredler/ebusd
int
main(int argc, char *argv[])
{
	int tmp;
	
	/* set progname */
	progname = (const char *)strrchr(argv[0], '/');
	progname = progname ? (progname + 1) : argv[0];

	/* read command line  */
	cmdline(&argc, &argv);
	
	/* set default cfgfile */
	if (*cfgfile == '\0')
		strncpy(cfgfile , DAEMON_CFGFILE, strlen(DAEMON_CFGFILE));

	/* read config file */
	if (cfg_file_read(cfgfile, cfg, cfglen) == -1)
		fprintf(stderr, "can't open cfgfile: %s ==> " \
				"build in settings will be used\n", cfgfile);	

	/* set unset configuration */
	set_unset();

	/* print configuration */
	if (settings == YES)
		cfg_print(cfg, cfglen);

	
	/* set ebus configuration */
	eb_set_nodevicecheck(nodevicecheck);
	eb_set_rawdump(rawdump);
	eb_set_showraw(showraw);

	tmp = (eb_htoi(&address[0])) * 16 + (eb_htoi(&address[1]));
	eb_set_qq((unsigned char) tmp);

	eb_set_get_retry(get_retry);
	eb_set_skip_ack(skip_ack);
	eb_set_max_wait(max_wait);
	eb_set_send_retry(send_retry);
	eb_set_print_size(print_size);

	/* open log */
	log_level(loglevel);
	log_open(logfile, foreground);	

	/* to be daemon */
	if (foreground == NO) {
		log_print(L_ALL, DAEMON_NAME " " DAEMON_VERSION " started");
		syslog(LOG_INFO, DAEMON_NAME " " DAEMON_VERSION " started");
		daemonize();
	}

	/* read ebus command configuration files */
	if (eb_cmd_dir_read(cfgdir, extension) == -1)
		log_print(L_WAR, "error during read command file");

	/* open raw file */
	if (rawdump == YES) {
		if (eb_raw_file_open(rawfile) == -1) {
			log_print(L_ALL, "can't open rawfile: %s", rawfile);
			cleanup(EXIT_FAILURE);
		} else {
			log_print(L_INF, "%s opened", rawfile);
		}

	}

	/* open serial device */
	if (eb_serial_open(device, &serialfd) == -1) {
		log_print(L_ALL, "can't open device: %s", device);
		cleanup(EXIT_FAILURE);
	} else {
		log_print(L_INF, "%s opened", device);
	}


	/* open listing tcp socket */
	if (sock_open(&socketfd, port, localhost) == -1) {
		log_print(L_ALL, "can't open port: %d", port);
		cleanup(EXIT_FAILURE);
	} else {
		log_print(L_INF, "port %d opened", port);
	}

	/* init msg queue */
	if (msg_queue_init() == -1) {
		log_print(L_ALL, "can't initialize msg queue");
		cleanup(EXIT_FAILURE);
	} else {
		msg_queue_on = YES;
		log_print(L_INF, "msg queue initialized");
	}

	/* enter main loop */
	main_loop();

	cleanup(EXIT_SUCCESS);

	return 0;
}
コード例 #2
0
ファイル: cfgreader.c プロジェクト: tal-nino/gnokii
/* DEPRECATED */
static gn_error cfg_file_or_memory_read(const char *file, const char **lines)
{
	char *val;
	gn_error error;

	error = gn_lib_init();
	if (error != GN_ERR_NONE) {
		fprintf(stderr, _("Failed to initialize libgnokii.\n"));
		return error;
	}

	if (file == NULL && lines == NULL) {
		fprintf(stderr, _("Couldn't open a config file or memory.\n"));
		return GN_ERR_NOCONFIG;
	}

	/* I know that it doesn't belong here but currently there is now generic
	 * application init function anywhere.
	 */
	setvbuf(stdout, NULL, _IONBF, 0);
	setvbuf(stderr, NULL, _IONBF, 0);

	/*
	 * Try opening a given config file
	 */
	if (file != NULL)
		gn_cfg_info = cfg_file_read(file);
	else
		gn_cfg_info = cfg_memory_read(lines);

	if (gn_cfg_info == NULL) {
		/* this is bad, but the previous was much worse - bozo */
		return GN_ERR_NOCONFIG;
	}
	gn_config_default.model[0] = 0;
	gn_config_default.port_device[0] = 0;
	gn_config_default.connection_type = GN_CT_Serial;
	gn_config_default.init_length = 0;
	gn_config_default.serial_baudrate = 19200;
	gn_config_default.serial_write_usleep = -1;
	gn_config_default.hardware_handshake = false;
	gn_config_default.require_dcd = false;
	gn_config_default.set_dtr_rts = true;
	gn_config_default.smsc_timeout = -1;
	gn_config_default.irda_string[0] = 0;
	gn_config_default.connect_script[0] = 0;
	gn_config_default.disconnect_script[0] = 0;
	gn_config_default.rfcomm_cn = 0;
	gn_config_default.sm_retry = 0;
	gn_config_default.use_locking = 0;
	gn_config_default.auth_type = GN_AUTH_TYPE_NONE;
	gn_config_default.auth_file[0] = 0;

	if ((error = cfg_psection_load(&gn_config_global, "global", &gn_config_default)) != GN_ERR_NONE)
		return error;

	/* hack to support [sms] / smsc_timeout parameter */
	if (gn_config_global.smsc_timeout < 0) {
		if (!(val = gn_cfg_get(gn_cfg_info, "sms", "timeout")))
			gn_config_global.smsc_timeout = 100;
		else
			gn_config_global.smsc_timeout = 10 * atoi(val);
	}

	if (!cfg_get_log_target(&gn_log_debug_mask, "debug") ||
	    !cfg_get_log_target(&gn_log_rlpdebug_mask, "rlpdebug") ||
	    !cfg_get_log_target(&gn_log_xdebug_mask, "xdebug"))
		return GN_ERR_NOLOG;

	gn_log_debug("LOG: debug mask is 0x%x\n", gn_log_debug_mask);
	gn_log_rlpdebug("LOG: rlpdebug mask is 0x%x\n", gn_log_rlpdebug_mask);
	gn_log_xdebug("LOG: xdebug mask is 0x%x\n", gn_log_xdebug_mask);
	if (file)
		dprintf("Config read from file %s.\n", file);
	return GN_ERR_NONE;
}