2
* Copyright (C) 2010-2011 Robert Ancell.
3
* Author: Robert Ancell <robert.ancell@canonical.com>
5
* This program is free software: you can redistribute it and/or modify it under
6
* the terms of the GNU General Public License as published by the Free Software
7
* Foundation, either version 3 of the License, or (at your option) any later
8
* version. See http://www.gnu.org/copyleft/gpl.html the full text of the
16
#include <glib/gi18n.h>
22
g_printerr (/* Text printed out when an unknown command-line argument provided */
23
_("Run 'dm-tool --help' to see a full list of available command line options."));
28
main (int argc, char **argv)
33
GDBusProxy *dm_proxy, *seat_proxy;
39
for (arg_index = 1; arg_index < argc; arg_index++)
41
gchar *arg = argv[arg_index];
43
if (!g_str_has_prefix (arg, "-"))
46
if (strcmp (arg, "-h") == 0 || strcmp (arg, "--help") == 0)
48
g_printerr ("Usage:\n"
49
" dm-tool [OPTION...] COMMAND [ARGS...] - Display Manager tool\n"
52
" -h, --help Show help options\n"
53
" -v, --version Show release version\n"
56
" switch-to-greeter Switch to the greeter\n"
57
" switch-to-user USERNAME [SESSION] Switch to a user session\n"
58
" switch-to-guest [SESSION] Switch to a guest session\n"
59
" add-seat TYPE [NAME=VALUE...] Add a dynamic seat\n");
62
else if (strcmp (arg, "-v") == 0 || strcmp (arg, "--version") == 0)
64
/* NOTE: Is not translated so can be easily parsed */
65
g_printerr ("lightdm %s\n", VERSION);
70
g_printerr ("Unknown option %s\n", arg);
76
if (arg_index >= argc)
78
g_printerr ("Missing command\n");
83
dm_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
84
G_DBUS_PROXY_FLAGS_NONE,
86
"org.freedesktop.DisplayManager",
87
"/org/freedesktop/DisplayManager",
88
"org.freedesktop.DisplayManager",
93
g_printerr ("Unable to contact display manager: %s\n", error->message);
96
g_clear_error (&error);
98
seat_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
99
G_DBUS_PROXY_FLAGS_NONE,
101
"org.freedesktop.DisplayManager",
102
g_getenv ("XDG_SEAT_PATH"),
103
"org.freedesktop.DisplayManager.Seat",
108
g_printerr ("Unable to contact display manager: %s\n", error->message);
111
g_clear_error (&error);
113
command = argv[arg_index];
115
n_options = argc - arg_index;
116
options = argv + arg_index;
117
if (strcmp (command, "switch-to-greeter") == 0)
121
g_printerr ("Usage switch-to-greeter\n");
126
if (!g_dbus_proxy_call_sync (seat_proxy,
128
g_variant_new ("()"),
129
G_DBUS_CALL_FLAGS_NONE,
134
g_printerr ("Unable to switch to greeter: %s\n", error->message);
139
else if (strcmp (command, "switch-to-user") == 0)
141
gchar *username, *session = "";
145
g_printerr ("Usage switch-to-user USERNAME [SESSION]\n");
150
username = options[0];
152
session = options[1];
154
if (!g_dbus_proxy_call_sync (seat_proxy,
156
g_variant_new ("(ss)", username, session),
157
G_DBUS_CALL_FLAGS_NONE,
162
g_printerr ("Unable to switch to user %s: %s\n", username, error->message);
167
else if (strcmp (command, "switch-to-guest") == 0)
173
g_printerr ("Usage switch-to-guest [SESSION]\n");
179
session = options[0];
181
if (!g_dbus_proxy_call_sync (seat_proxy,
183
g_variant_new ("(s)", session),
184
G_DBUS_CALL_FLAGS_NONE,
189
g_printerr ("Unable to switch to guest: %s\n", error->message);
194
else if (strcmp (command, "add-seat") == 0)
198
GVariantBuilder *properties;
203
g_printerr ("Usage add-seat TYPE [NAME=VALUE...]\n");
209
properties = g_variant_builder_new (G_VARIANT_TYPE ("a(ss)"));
211
for (i = 0; i < n_options; i++)
213
gchar *property, *name, *value;
215
property = g_strdup (options[i]);
217
value = strchr (property, '=');
226
g_variant_builder_add_value (properties, g_variant_new ("(ss)", "name", "value"));
230
result = g_dbus_proxy_call_sync (dm_proxy,
232
g_variant_new ("(sa(ss))", type, properties),
233
G_DBUS_CALL_FLAGS_NONE,
238
g_printerr ("Unable to add seat: %s\n", error->message);
242
if (!g_variant_is_of_type (result, G_VARIANT_TYPE ("(o)")))
244
g_printerr ("Unexpected response to AddSeat: %s\n", g_variant_get_type_string (result));
248
g_variant_get (result, "(&o)", path);
249
g_print ("%s\n", path);
254
g_printerr ("Unknown command %s\n", command);