Exemple #1
0
/**
 * type_of:
 * @parent: parent object for new string,
 * @iter: D-Bus signature iterator.
 *
 * Converts the D-Bus basic type at the current element of the iterator
 * @iter into an appropriate C type to hold it.
 *
 * If @parent is not NULL, it should be a pointer to another object which
 * will be used as a parent for the returned string.  When all parents
 * of the returned string are freed, the returned string will also be
 * freed.
 *
 * Returns: newly allocated string or NULL if allocation failed.
 **/
char *
type_of (const void *       parent,
	 DBusSignatureIter *iter)
{
	int dbus_type;

	nih_assert (iter != NULL);

	dbus_type = dbus_signature_iter_get_current_type (iter);

	switch (dbus_type) {
	case DBUS_TYPE_BYTE:
		return nih_strdup (parent, "uint8_t");
	case DBUS_TYPE_BOOLEAN:
		return nih_strdup (parent, "int");
	case DBUS_TYPE_INT16:
		return nih_strdup (parent, "int16_t");
	case DBUS_TYPE_UINT16:
		return nih_strdup (parent, "uint16_t");
	case DBUS_TYPE_INT32:
		return nih_strdup (parent, "int32_t");
	case DBUS_TYPE_UINT32:
		return nih_strdup (parent, "uint32_t");
	case DBUS_TYPE_INT64:
		return nih_strdup (parent, "int64_t");
	case DBUS_TYPE_UINT64:
		return nih_strdup (parent, "uint64_t");
	case DBUS_TYPE_DOUBLE:
		return nih_strdup (parent, "double");
	case DBUS_TYPE_STRING:
		return nih_strdup (parent, "char *");
	case DBUS_TYPE_OBJECT_PATH:
		return nih_strdup (parent, "char *");
	case DBUS_TYPE_SIGNATURE:
		return nih_strdup (parent, "char *");
	case DBUS_TYPE_UNIX_FD:
		return nih_strdup (parent, "int");
	default:
		nih_assert_not_reached ();
	}
}
Exemple #2
0
/**
 * type_const:
 * @dbus_type: D-Bus type constant.
 *
 * Converts an integer D-Bus type constant into the string name of the
 * constant, used when generating code.
 *
 * Returns: constant string.
 **/
const char *
type_const (int dbus_type)
{
	switch (dbus_type) {
	case DBUS_TYPE_BYTE:
		return "DBUS_TYPE_BYTE";
	case DBUS_TYPE_BOOLEAN:
		return "DBUS_TYPE_BOOLEAN";
	case DBUS_TYPE_INT16:
		return "DBUS_TYPE_INT16";
	case DBUS_TYPE_UINT16:
		return "DBUS_TYPE_UINT16";
	case DBUS_TYPE_INT32:
		return "DBUS_TYPE_INT32";
	case DBUS_TYPE_UINT32:
		return "DBUS_TYPE_UINT32";
	case DBUS_TYPE_INT64:
		return "DBUS_TYPE_INT64";
	case DBUS_TYPE_UINT64:
		return "DBUS_TYPE_UINT64";
	case DBUS_TYPE_DOUBLE:
		return "DBUS_TYPE_DOUBLE";
	case DBUS_TYPE_STRING:
		return "DBUS_TYPE_STRING";
	case DBUS_TYPE_OBJECT_PATH:
		return "DBUS_TYPE_OBJECT_PATH";
	case DBUS_TYPE_SIGNATURE:
		return "DBUS_TYPE_SIGNATURE";
	case DBUS_TYPE_ARRAY:
		return "DBUS_TYPE_ARRAY";
	case DBUS_TYPE_STRUCT:
		return "DBUS_TYPE_STRUCT";
	case DBUS_TYPE_DICT_ENTRY:
		return "DBUS_TYPE_DICT_ENTRY";
	case DBUS_TYPE_UNIX_FD:
		return "DBUS_TYPE_UNIX_FD";
	default:
		nih_assert_not_reached ();
	}
}
Exemple #3
0
int
main (int   argc,
      char *argv[])
{
	char **args;
	int    runlevel;
	int    ret;

	nih_main_init (argv[0]);

	nih_option_set_usage ("RUNLEVEL");
	nih_option_set_synopsis (_("Change runlevel."));
	nih_option_set_help (
		_("RUNLEVEL should be one of 0123456sS, where s and S are "
		  "considered identical.\n"
		  "\n"
		  "RUNLEVEL may also be Q or q to instruct the init daemon "
		  "to reload its configuration, this is rarely necessary "
		  "since the daemon watches its configuration for changes.\n"
		  "\n"
		  "RUNLEVEL may be U or u to instruct the init daemon to "
		  "re-execute itself, this is not recommended since Upstart "
		  "does not currently preserve its state.\n"));

	args = nih_option_parser (NULL, argc, argv, options, FALSE);
	if (! args)
		exit (1);

	/* First argument must be a single character we know */
	if (! args[0]) {
		fprintf (stderr, _("%s: missing runlevel\n"), program_name);
		nih_main_suggest_help ();
		exit (1);
	}
	if ((! strchr ("0123456SsQqUu", args[0][0])) || args[0][1]) {
		fprintf (stderr, _("%s: illegal runlevel: %s\n"),
			 program_name, args[0]);
		nih_main_suggest_help ();
		exit (1);
	}

	/* Check we're root */
	setuid (geteuid ());
	if (getuid ()) {
		nih_fatal (_("Need to be root"));
		exit (1);
	}

	/* Send the appropriate message */
	runlevel = args[0][0];

	switch (runlevel) {
	case '0':
	case '1':
	case '2':
	case '3':
	case '4':
	case '5':
	case '6':
		ret = sysv_change_runlevel (runlevel, extra_env, NULL, NULL);
		break;
	case 'S':
	case 's':
		ret = sysv_change_runlevel ('S', extra_env, NULL, NULL);
		break;
	case 'Q':
	case 'q':
		ret = kill (1, SIGHUP);
		if (ret < 0)
			nih_error_raise_system ();
		break;
	case 'U':
	case 'u':
		ret = kill (1, SIGTERM);
		if (ret < 0)
			nih_error_raise_system ();
		break;
	default:
		nih_assert_not_reached ();
	}

	if (ret < 0) {
		NihError *err;

		err = nih_error_get ();
		nih_error ("%s", err->message);
		nih_free (err);

		exit (1);
	}

	return 0;
}