~xnox/upstart/shrink-notifications

« back to all changes in this revision

Viewing changes to init/control.c

  • Committer: Dimitri John Ledkov
  • Date: 2014-06-05 22:35:01 UTC
  • mfrom: (1620.2.44 upstart-async)
  • Revision ID: dimitri.ledkov@canonical.com-20140605223501-z4hj7xddug95y59u
Merge cgroups work.

Show diffs side-by-side

added added

removed removed

Lines of Context:
63
63
 
64
64
#include "com.ubuntu.Upstart.h"
65
65
 
 
66
#ifdef ENABLE_CGROUPS
 
67
#include "cgroup.h"
 
68
#endif /* ENABLE_CGROUPS */
 
69
 
66
70
/* Prototypes for static functions */
67
71
static int   control_server_connect      (DBusServer *server, DBusConnection *conn);
68
72
static void  control_disconnected        (DBusConnection *conn);
975
979
}
976
980
 
977
981
/**
 
982
 * control_notify_cgroup_manager_address:
 
983
 * @data: not used,
 
984
 * @message: D-Bus connection and message received,
 
985
 * @address: D-Bus address that cgroup manager is connected to.
 
986
 *
 
987
 * Implements the NotifyCGroupManagerAddress method of the
 
988
 * com.ubuntu.Upstart interface.
 
989
 *
 
990
 * Called to allow the cgroup manager to be contacted,
 
991
 * thus enabling the cgroup stanza.
 
992
 *
 
993
 * Returns: zero on success, negative value on raised error.
 
994
 **/
 
995
int
 
996
control_notify_cgroup_manager_address (void            *data,
 
997
                                       NihDBusMessage  *message,
 
998
                                       const char      *address)
 
999
{
 
1000
        nih_assert (message);
 
1001
        nih_assert (address);
 
1002
 
 
1003
        if (! control_check_permission (message)) {
 
1004
                nih_dbus_error_raise_printf (
 
1005
                        DBUS_INTERFACE_UPSTART ".Error.PermissionDenied",
 
1006
                        _("You do not have permission to notify cgroup manager address"));
 
1007
                return -1;
 
1008
        }
 
1009
 
 
1010
#ifdef ENABLE_CGROUPS
 
1011
        if (! cgroup_support_enabled ())
 
1012
                return 0;
 
1013
 
 
1014
        /* Already called */
 
1015
        if (cgroup_manager_available ())
 
1016
                return 0;
 
1017
 
 
1018
        if (! cgroup_manager_set_address (address)) {
 
1019
                nih_dbus_error_raise_printf (DBUS_ERROR_NO_MEMORY,
 
1020
                                _("Out of Memory"));
 
1021
                return -1;
 
1022
        }
 
1023
 
 
1024
        nih_debug ("set cgroup manager address");
 
1025
 
 
1026
        if (! job_class_induct_jobs ()) {
 
1027
                nih_dbus_error_raise_printf (DBUS_ERROR_NO_MEMORY,
 
1028
                                _("Out of Memory"));
 
1029
                return -1;
 
1030
        }
 
1031
 
 
1032
#else
 
1033
        nih_debug ("cgroup support not available");
 
1034
#endif /* ENABLE_CGROUPS */
 
1035
 
 
1036
        return 0;
 
1037
}
 
1038
 
 
1039
/**
978
1040
 * control_bus_flush:
979
1041
 *
980
1042
 * Drain any remaining messages in the D-Bus queue.