コード例 #1
0
ファイル: seahorse-daemon.c プロジェクト: GNOME/libcryptui
/**
 * main:
 * @argc: default arguments
 * @argv: default arguments
 *
 * Parses the options, daemonizes, starts HKP, DBus and Avahi
 *
 * Returns: 0 on success
 */
int main(int argc, char* argv[])
{
    GOptionContext *octx = NULL;
    GError *error = NULL;

    seahorse_secure_memory_init ();
    
    octx = g_option_context_new ("");
    g_option_context_add_main_entries (octx, options, GETTEXT_PACKAGE);
    g_option_context_add_group (octx, egg_sm_client_get_option_group ());

    if (!gtk_init_with_args (&argc, &argv, _("Encryption Daemon (Seahorse)"), 
                             (GOptionEntry *)options, GETTEXT_PACKAGE, &error)) {
	    g_printerr ("seahorse-daemon: %s\n", error->message);
	    g_error_free (error);
	    exit (1);
    }
     	 
	g_signal_connect (egg_sm_client_get (), "quit", G_CALLBACK (smclient_quit), NULL);

    /*
     * All functions after this point have to print messages
     * nicely and not just called exit()
     */
    daemonize ();

    /* Handle some signals */
    seahorse_unix_signal_register (SIGINT, unix_signal);
    seahorse_unix_signal_register (SIGTERM, unix_signal);

    /* We log to the syslog */
    prepare_logging ();

    /* Insert Icons into Stock */
    seahorse_gtkstock_init ();
   
    /* Make the default SeahorseContext */
    seahorse_context_new (SEAHORSE_CONTEXT_APP | SEAHORSE_CONTEXT_DAEMON);

    /* Load the various components */
    seahorse_pgp_module_init ();

    seahorse_context_refresh_auto (NULL);

    /* Initialize the various daemon components */
    seahorse_dbus_server_init ();

    /* Sometimes we've already gotten a quit signal */
    if(!daemon_quit) {
        daemon_running = TRUE;
        gtk_main ();
        g_message ("left gtk_main\n");
    }

    seahorse_dbus_server_cleanup ();

    g_option_context_free (octx);
    seahorse_context_destroy (SCTX_APP ());

    return 0;
}
コード例 #2
0
ファイル: gkd-main.c プロジェクト: Distrotech/gnome-keyring
int
main (int argc, char *argv[])
{
	/*
	 * The gnome-keyring startup is not as simple as I wish it could be.
	 *
	 * It's often started in the primordial stages of a session, where
	 * there's no DBus, and no proper X display. This is the strange world
	 * of PAM.
	 *
	 * When started with the --login option, we do as little initialization
	 * as possible. We expect a login password on the stdin, and unlock
	 * or create the login keyring.
	 *
	 * Then later we expect gnome-keyring-dameon to be run again with the
	 * --start option. This second gnome-keyring-daemon will hook the
	 * original daemon up with environment variables necessary to initialize
	 * itself and bring it into the session. This second daemon usually exits.
	 *
	 * Without either of these options, we follow a more boring and
	 * predictable startup.
	 */

	/*
	 * Before we do ANYTHING, we drop privileges so we don't become
	 * a security issue ourselves.
	 */
	gkd_capability_obtain_capability_and_drop_privileges ();

#ifdef WITH_STRICT
	g_setenv ("DBUS_FATAL_WARNINGS", "1", FALSE);
	if (!g_getenv ("G_DEBUG"))
		g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
#endif

#if !GLIB_CHECK_VERSION(2,35,0)
	g_type_init ();
#endif

#ifdef HAVE_LOCALE_H
	/* internationalisation */
	setlocale (LC_ALL, "");
#endif

#ifdef HAVE_GETTEXT
	bindtextdomain (GETTEXT_PACKAGE, GNOMELOCALEDIR);
	textdomain (GETTEXT_PACKAGE);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
#endif

	egg_libgcrypt_initialize ();

	/* Send all warning or error messages to syslog */
	prepare_logging ();

	parse_arguments (&argc, &argv);

	/* The --version option. This is machine parseable output */
	if (run_version) {
		g_print ("gnome-keyring-daemon: %s\n", VERSION);
		g_print ("testing: %s\n",
#ifdef WITH_DEBUG
		         "enabled");
#else
		         "disabled");
#endif
		exit (0);
	}

	/* The --start option */
	if (run_for_start) {
		if (discover_other_daemon (initialize_daemon_at, TRUE)) {
			/*
			 * Another daemon was initialized, print out environment
			 * for any callers, and quit or go comatose.
			 */
			print_environment ();
			if (run_foreground)
				while (sleep(0x08000000) == 0);
			cleanup_and_exit (0);
		}

	/* The --replace option */
	} else if (run_for_replace) {
		discover_other_daemon (replace_daemon_at, FALSE);
		if (control_directory)
			g_message ("Replacing daemon, using directory: %s", control_directory);
		else
			g_message ("Could not find daemon to replace, staring normally");
	}

	/* Initialize the main directory */
	gkd_util_init_master_directory (control_directory);

	/* Initialize our daemon main loop and threading */
	loop = g_main_loop_new (NULL, FALSE);

	/* Initialize our control socket */
	if (!gkd_control_listen ())
		return FALSE;

	if (perform_unlock) {
		login_password = read_login_password (STDIN);
		atexit (clear_login_password);
	}

	/* The --login option. Delayed initialization */
	if (run_for_login) {
		timeout_id = g_timeout_add_seconds (LOGIN_TIMEOUT, (GSourceFunc) on_login_timeout, NULL);

	/* Not a login daemon. Startup stuff now.*/
	} else {
		/* These are things that can run before forking */
		if (!gkr_daemon_startup_steps (run_components))
			cleanup_and_exit (1);
	}

	signal (SIGPIPE, SIG_IGN);

	/* The whole forking and daemonizing dance starts here. */
	fork_and_print_environment();

	g_unix_signal_add (SIGTERM, on_signal_term, loop);
	g_unix_signal_add (SIGHUP, on_signal_term, loop);
	g_unix_signal_add (SIGUSR1, on_signal_usr1, loop);

	/* Prepare logging a second time, since we may be in a different process */
	prepare_logging();

	/* Remainder initialization after forking, if initialization not delayed */
	if (!run_for_login) {
		gkr_daemon_initialize_steps (run_components);

		/*
		 * Close stdout and so that the caller knows that we're
		 * all initialized, (when run in foreground mode).
		 *
		 * However since some logging goes to stdout, redirect that
		 * to stderr. We don't want the caller confusing that with
		 * valid output anyway.
		 */
		if (dup2 (2, 1) < 1)
			g_warning ("couldn't redirect stdout to stderr");

		g_debug ("initialization complete");
	}

	g_main_loop_run (loop);

	/* This wraps everything up in order */
	egg_cleanup_perform ();

	g_free (control_directory);

	g_debug ("exiting cleanly");
	return 0;
}
コード例 #3
0
/**
 * main:
 * @argc:
 * @argv[]: Sent to gtk_init
 *
 * Prompt for GnuPG and SSH. Communicates using stdin/stdout. Communication data
 * is in ini-file structures
 *
 * Returns: 0
 */
int
main (int argc, char *argv[])
{
	GError *err = NULL;
	gchar *data;
	gboolean ret;
	gsize length;

	/* Exit on HUP signal */
	signal(SIGINT,  hup_handler);

	prepare_logging ();

	egg_libgcrypt_initialize ();

	input_data = g_key_file_new ();
	output_data = g_key_file_new ();

	gtk_init (&argc, &argv);

#ifdef HAVE_LOCALE_H
	/* internationalisation */
	setlocale (LC_ALL, "");
#endif

#ifdef HAVE_GETTEXT
	bindtextdomain (GETTEXT_PACKAGE, MATELOCALEDIR);
	textdomain (GETTEXT_PACKAGE);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
#endif

	data = read_all_input ();
	g_assert (data);

	if (!data[0])
		fatal ("no auth dialog instructions", NULL);

	ret = g_key_file_load_from_data (input_data, data, strlen (data), G_KEY_FILE_NONE, &err);
	g_free (data);

	if (!ret)
		fatal ("couldn't parse auth dialog instructions", egg_error_message (err));

	run_dialog ();

	/* Cleanup after any key */
	if (the_key) {
		egg_secure_clear (the_key, n_the_key);
		egg_secure_free (the_key);
		the_key = NULL;
		n_the_key = 0;
	}

	g_key_file_free (input_data);
	data = g_key_file_to_data (output_data, &length, &err);
	g_key_file_free (output_data);

	if (!data)
		fatal ("couldn't format auth dialog response: %s", egg_error_message (err));

	write_all_output (data, length);
	g_free (data);

	return 0;
}
コード例 #4
0
ファイル: tmon.c プロジェクト: 908626950/linux
int main(int argc, char **argv)
{
	int err = 0;
	int id2 = 0, c;
	double yk = 0.0; /* controller output */
	int target_tz_index;

	if (geteuid() != 0) {
		printf("TMON needs to be run as root\n");
		exit(EXIT_FAILURE);
	}

	while ((c = getopt_long(argc, argv, "c:dlht:vgz:", opts, &id2)) != -1) {
		switch (c) {
		case 'c':
			no_control = 0;
			strncpy(ctrl_cdev, optarg, CDEV_NAME_SIZE);
			break;
		case 'd':
			start_daemon_mode();
			printf("Run TMON in daemon mode\n");
			break;
		case 't':
			ticktime = strtod(optarg, NULL);
			if (ticktime < 1)
				ticktime = 1;
			break;
		case 'l':
			printf("Logging data to /var/tmp/tmon.log\n");
			logging = 1;
			break;
		case 'h':
			usage();
			break;
		case 'v':
			version();
			break;
		case 'g':
			debug_on = 1;
			break;
		case 'z':
			target_thermal_zone = strtod(optarg, NULL);
			break;
		default:
			break;
		}
	}
	if (pthread_mutex_init(&input_lock, NULL) != 0) {
		fprintf(stderr, "\n mutex init failed, exit\n");
		return 1;
	}
	start_syslog();
	if (signal(SIGINT, tmon_sig_handler) == SIG_ERR)
		syslog(LOG_DEBUG, "Cannot handle SIGINT\n");
	if (signal(SIGTERM, tmon_sig_handler) == SIG_ERR)
		syslog(LOG_DEBUG, "Cannot handle SIGINT\n");

	if (probe_thermal_sysfs()) {
		pthread_mutex_destroy(&input_lock);
		closelog();
		return -1;
	}
	initialize_curses();
	setup_windows();
	signal(SIGWINCH, resize_handler);
	show_title_bar();
	show_sensors_w();
	show_cooling_device();
	update_thermal_data();
	show_data_w();
	prepare_logging();
	init_thermal_controller();

	nodelay(stdscr, TRUE);
	err = pthread_create(&event_tid, NULL, &handle_tui_events, NULL);
	if (err != 0) {
		printf("\ncan't create thread :[%s]", strerror(err));
		tmon_cleanup();
		exit(EXIT_FAILURE);
	}

	/* validate range of user selected target zone, default to the first
	 * instance if out of range
	 */
	target_tz_index = zone_instance_to_index(target_thermal_zone);
	if (target_tz_index < 0) {
		target_thermal_zone = ptdata.tzi[0].instance;
		syslog(LOG_ERR, "target zone is not found, default to %d\n",
			target_thermal_zone);
	}
	while (1) {
		sleep(ticktime);
		show_title_bar();
		show_sensors_w();
		update_thermal_data();
		if (!dialogue_on) {
			show_data_w();
			show_cooling_device();
		}
		cur_thermal_record++;
		time_elapsed += ticktime;
		controller_handler(trec[0].temp[target_tz_index] / 1000,
				&yk);
		trec[0].pid_out_pct = yk;
		if (!dialogue_on)
			show_control_w();
		if (tmon_exit)
			break;
	}
	tmon_cleanup();
	return 0;
}