1053
959
if (strstr(args[0], "session")) {
1055
m = dbus_message_new_method_call(
961
ret = bus_method_call_with_reply (
1056
963
"org.freedesktop.login1",
1057
964
"/org/freedesktop/login1",
1058
965
"org.freedesktop.login1.Manager",
1061
log_error("Could not allocate message.");
1066
if (!dbus_message_append_args(m,
1067
DBUS_TYPE_STRING, &args[i],
1068
DBUS_TYPE_INVALID)) {
1069
log_error("Could not append arguments to message.");
969
DBUS_TYPE_STRING, &args[i],
1074
972
} else if (strstr(args[0], "user")) {
1078
ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL);
976
ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
1080
978
log_error("User %s unknown.", args[i]);
1084
m = dbus_message_new_method_call(
1085
"org.freedesktop.login1",
1086
"/org/freedesktop/login1",
1087
"org.freedesktop.login1.Manager",
1090
log_error("Could not allocate message.");
1095
982
u = (uint32_t) uid;
1096
if (!dbus_message_append_args(m,
1097
DBUS_TYPE_UINT32, &u,
1098
DBUS_TYPE_INVALID)) {
1099
log_error("Could not append arguments to message.");
983
ret = bus_method_call_with_reply (
985
"org.freedesktop.login1",
986
"/org/freedesktop/login1",
987
"org.freedesktop.login1.Manager",
991
DBUS_TYPE_UINT32, &u,
1105
m = dbus_message_new_method_call(
995
ret = bus_method_call_with_reply (
1106
997
"org.freedesktop.login1",
1107
998
"/org/freedesktop/login1",
1108
999
"org.freedesktop.login1.Manager",
1111
log_error("Could not allocate message.");
1116
if (!dbus_message_append_args(m,
1117
DBUS_TYPE_STRING, &args[i],
1118
DBUS_TYPE_INVALID)) {
1119
log_error("Could not append arguments to message.");
1003
DBUS_TYPE_STRING, &args[i],
1125
reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);
1127
log_error("Failed to issue method call: %s", bus_error_message(&error));
1132
1009
if (!dbus_message_get_args(reply, &error,
1133
1010
DBUS_TYPE_OBJECT_PATH, &path,
1140
1017
r = show_one(args[0], bus, path, show_properties, &new_line);
1144
dbus_message_unref(m);
1145
dbus_message_unref(reply);
1151
dbus_message_unref(m);
1154
dbus_message_unref(reply);
1156
1023
dbus_error_free(&error);
1161
1028
static int activate(DBusConnection *bus, char **args, unsigned n) {
1162
DBusMessage *m = NULL;
1170
dbus_error_init(&error);
1172
1034
for (i = 1; i < n; i++) {
1175
m = dbus_message_new_method_call(
1036
ret = bus_method_call_with_reply (
1176
1038
"org.freedesktop.login1",
1177
1039
"/org/freedesktop/login1",
1178
1040
"org.freedesktop.login1.Manager",
1179
1041
streq(args[0], "lock-session") ? "LockSession" :
1180
1042
streq(args[0], "unlock-session") ? "UnlockSession" :
1181
1043
streq(args[0], "terminate-session") ? "TerminateSession" :
1184
log_error("Could not allocate message.");
1189
if (!dbus_message_append_args(m,
1190
DBUS_TYPE_STRING, &args[i],
1191
DBUS_TYPE_INVALID)) {
1192
log_error("Could not append arguments to message.");
1197
reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);
1199
log_error("Failed to issue method call: %s", bus_error_message(&error));
1204
dbus_message_unref(m);
1205
dbus_message_unref(reply);
1047
DBUS_TYPE_STRING, &args[i],
1211
dbus_message_unref(m);
1213
dbus_error_free(&error);
1218
1057
static int kill_session(DBusConnection *bus, char **args, unsigned n) {
1219
DBusMessage *m = NULL;
1227
dbus_error_init(&error);
1229
1062
if (!arg_kill_who)
1230
1063
arg_kill_who = "all";
1232
1065
for (i = 1; i < n; i++) {
1235
m = dbus_message_new_method_call(
1236
"org.freedesktop.login1",
1237
"/org/freedesktop/login1",
1238
"org.freedesktop.login1.Manager",
1241
log_error("Could not allocate message.");
1246
if (!dbus_message_append_args(m,
1247
DBUS_TYPE_STRING, &args[i],
1248
DBUS_TYPE_STRING, &arg_kill_who,
1249
DBUS_TYPE_INT32, arg_signal,
1250
DBUS_TYPE_INVALID)) {
1251
log_error("Could not append arguments to message.");
1256
reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);
1258
log_error("Failed to issue method call: %s", bus_error_message(&error));
1263
dbus_message_unref(m);
1264
dbus_message_unref(reply);
1068
r = bus_method_call_with_reply (
1070
"org.freedesktop.login1",
1071
"/org/freedesktop/login1",
1072
"org.freedesktop.login1.Manager",
1076
DBUS_TYPE_STRING, &args[i],
1077
DBUS_TYPE_STRING, &arg_kill_who,
1078
DBUS_TYPE_INT32, &arg_signal,
1270
dbus_message_unref(m);
1272
dbus_error_free(&error);
1277
1087
static int enable_linger(DBusConnection *bus, char **args, unsigned n) {
1278
DBusMessage *m = NULL;
1282
1089
dbus_bool_t b, interactive = true;
1287
dbus_error_init(&error);
1093
polkit_agent_open_if_enabled();
1289
1095
b = streq(args[0], "enable-linger");
1291
1097
for (i = 1; i < n; i++) {
1296
m = dbus_message_new_method_call(
1297
"org.freedesktop.login1",
1298
"/org/freedesktop/login1",
1299
"org.freedesktop.login1.Manager",
1302
log_error("Could not allocate message.");
1307
ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL);
1309
log_error("Failed to resolve user %s: %s", args[i], strerror(-ret));
1102
r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
1104
log_error("Failed to resolve user %s: %s", args[i], strerror(-r));
1313
1108
u = (uint32_t) uid;
1314
if (!dbus_message_append_args(m,
1315
DBUS_TYPE_UINT32, &u,
1316
DBUS_TYPE_BOOLEAN, &b,
1317
DBUS_TYPE_BOOLEAN, &interactive,
1318
DBUS_TYPE_INVALID)) {
1319
log_error("Could not append arguments to message.");
1324
reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);
1326
log_error("Failed to issue method call: %s", bus_error_message(&error));
1331
dbus_message_unref(m);
1332
dbus_message_unref(reply);
1109
r = bus_method_call_with_reply (
1111
"org.freedesktop.login1",
1112
"/org/freedesktop/login1",
1113
"org.freedesktop.login1.Manager",
1117
DBUS_TYPE_UINT32, &u,
1118
DBUS_TYPE_BOOLEAN, &b,
1119
DBUS_TYPE_BOOLEAN, &interactive,
1340
dbus_message_unref(m);
1342
dbus_error_free(&error);
1347
1128
static int terminate_user(DBusConnection *bus, char **args, unsigned n) {
1348
DBusMessage *m = NULL;
1356
dbus_error_init(&error);
1358
1133
for (i = 1; i < n; i++) {
1363
m = dbus_message_new_method_call(
1364
"org.freedesktop.login1",
1365
"/org/freedesktop/login1",
1366
"org.freedesktop.login1.Manager",
1369
log_error("Could not allocate message.");
1374
ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL);
1376
log_error("Failed to look up user %s: %s", args[i], strerror(-ret));
1138
r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
1140
log_error("Failed to look up user %s: %s", args[i], strerror(-r));
1380
1144
u = (uint32_t) uid;
1381
if (!dbus_message_append_args(m,
1382
DBUS_TYPE_UINT32, &u,
1383
DBUS_TYPE_INVALID)) {
1384
log_error("Could not append arguments to message.");
1389
reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);
1391
log_error("Failed to issue method call: %s", bus_error_message(&error));
1396
dbus_message_unref(m);
1397
dbus_message_unref(reply);
1145
r = bus_method_call_with_reply (
1147
"org.freedesktop.login1",
1148
"/org/freedesktop/login1",
1149
"org.freedesktop.login1.Manager",
1153
DBUS_TYPE_UINT32, &u,
1405
dbus_message_unref(m);
1407
dbus_error_free(&error);
1412
1162
static int kill_user(DBusConnection *bus, char **args, unsigned n) {
1413
DBusMessage *m = NULL;
1421
dbus_error_init(&error);
1423
1167
if (!arg_kill_who)
1424
1168
arg_kill_who = "all";
1426
1170
for (i = 1; i < n; i++) {
1431
m = dbus_message_new_method_call(
1432
"org.freedesktop.login1",
1433
"/org/freedesktop/login1",
1434
"org.freedesktop.login1.Manager",
1437
log_error("Could not allocate message.");
1442
ret = get_user_creds((const char**) (args+i), &uid, NULL, NULL);
1444
log_error("Failed to look up user %s: %s", args[i], strerror(-ret));
1175
r = get_user_creds((const char**) (args+i), &uid, NULL, NULL, NULL);
1177
log_error("Failed to look up user %s: %s", args[i], strerror(-r));
1448
1181
u = (uint32_t) uid;
1449
if (!dbus_message_append_args(m,
1450
DBUS_TYPE_UINT32, &u,
1451
DBUS_TYPE_INT32, arg_signal,
1452
DBUS_TYPE_INVALID)) {
1453
log_error("Could not append arguments to message.");
1458
reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);
1460
log_error("Failed to issue method call: %s", bus_error_message(&error));
1465
dbus_message_unref(m);
1466
dbus_message_unref(reply);
1182
r = bus_method_call_with_reply (
1184
"org.freedesktop.login1",
1185
"/org/freedesktop/login1",
1186
"org.freedesktop.login1.Manager",
1190
DBUS_TYPE_UINT32, &u,
1191
DBUS_TYPE_INT32, &arg_signal,
1474
dbus_message_unref(m);
1476
dbus_error_free(&error);
1481
1200
static int attach(DBusConnection *bus, char **args, unsigned n) {
1482
DBusMessage *m = NULL;
1486
1202
dbus_bool_t interactive = true;
1491
dbus_error_init(&error);
1206
polkit_agent_open_if_enabled();
1493
1208
for (i = 2; i < n; i++) {
1496
m = dbus_message_new_method_call(
1497
"org.freedesktop.login1",
1498
"/org/freedesktop/login1",
1499
"org.freedesktop.login1.Manager",
1502
log_error("Could not allocate message.");
1507
if (!dbus_message_append_args(m,
1508
DBUS_TYPE_STRING, &args[1],
1509
DBUS_TYPE_STRING, &args[i],
1510
DBUS_TYPE_BOOLEAN, &interactive,
1511
DBUS_TYPE_INVALID)) {
1512
log_error("Could not append arguments to message.");
1517
reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);
1519
log_error("Failed to issue method call: %s", bus_error_message(&error));
1524
dbus_message_unref(m);
1525
dbus_message_unref(reply);
1211
r = bus_method_call_with_reply (
1213
"org.freedesktop.login1",
1214
"/org/freedesktop/login1",
1215
"org.freedesktop.login1.Manager",
1219
DBUS_TYPE_STRING, &args[1],
1220
DBUS_TYPE_STRING, &args[i],
1221
DBUS_TYPE_BOOLEAN, &interactive,
1531
dbus_message_unref(m);
1533
dbus_error_free(&error);
1538
1230
static int flush_devices(DBusConnection *bus, char **args, unsigned n) {
1539
DBusMessage *m = NULL, *reply = NULL;
1542
1231
dbus_bool_t interactive = true;
1547
dbus_error_init(&error);
1549
m = dbus_message_new_method_call(
1550
"org.freedesktop.login1",
1551
"/org/freedesktop/login1",
1552
"org.freedesktop.login1.Manager",
1555
log_error("Could not allocate message.");
1560
if (!dbus_message_append_args(m,
1561
DBUS_TYPE_BOOLEAN, &interactive,
1562
DBUS_TYPE_INVALID)) {
1563
log_error("Could not append arguments to message.");
1568
reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);
1570
log_error("Failed to issue method call: %s", bus_error_message(&error));
1577
dbus_message_unref(m);
1580
dbus_message_unref(reply);
1582
dbus_error_free(&error);
1235
polkit_agent_open_if_enabled();
1237
return bus_method_call_with_reply (
1239
"org.freedesktop.login1",
1240
"/org/freedesktop/login1",
1241
"org.freedesktop.login1.Manager",
1245
DBUS_TYPE_BOOLEAN, &interactive,
1249
static int lock_sessions(DBusConnection *bus, char **args, unsigned n) {
1252
polkit_agent_open_if_enabled();
1254
return bus_method_call_with_reply (
1256
"org.freedesktop.login1",
1257
"/org/freedesktop/login1",
1258
"org.freedesktop.login1.Manager",
1259
streq(args[0], "lock-sessions") ? "LockSessions" : "UnlockSessions",
1587
1265
static int terminate_seat(DBusConnection *bus, char **args, unsigned n) {
1588
DBusMessage *m = NULL;
1596
dbus_error_init(&error);
1598
1270
for (i = 1; i < n; i++) {
1601
m = dbus_message_new_method_call(
1602
"org.freedesktop.login1",
1603
"/org/freedesktop/login1",
1604
"org.freedesktop.login1.Manager",
1607
log_error("Could not allocate message.");
1612
if (!dbus_message_append_args(m,
1613
DBUS_TYPE_STRING, &args[i],
1614
DBUS_TYPE_INVALID)) {
1615
log_error("Could not append arguments to message.");
1620
reply = dbus_connection_send_with_reply_and_block(bus, m, -1, &error);
1622
log_error("Failed to issue method call: %s", bus_error_message(&error));
1627
dbus_message_unref(m);
1628
dbus_message_unref(reply);
1273
r = bus_method_call_with_reply (
1275
"org.freedesktop.login1",
1276
"/org/freedesktop/login1",
1277
"org.freedesktop.login1.Manager",
1281
DBUS_TYPE_STRING, &args[i],
1634
dbus_message_unref(m);
1636
dbus_error_free(&error);
1641
1290
static int help(void) {
1643
1292
printf("%s [OPTIONS...] {COMMAND} ...\n\n"
1644
1293
"Send control commands to or query the login manager.\n\n"
1645
" -h --help Show this help\n"
1646
" --version Show package version\n"
1647
" -p --property=NAME Show only properties by this name\n"
1648
" -a --all Show all properties, including empty ones\n"
1649
" --kill-who=WHO Who to send signal to\n"
1650
" -s --signal=SIGNAL Which signal to send\n"
1651
" -H --host=[USER@]HOST\n"
1652
" Show information for remote host\n"
1653
" -P --privileged Acquire privileges before execution\n"
1654
" --no-pager Do not pipe output into a pager\n\n"
1294
" -h --help Show this help\n"
1295
" --version Show package version\n"
1296
" -p --property=NAME Show only properties by this name\n"
1297
" -a --all Show all properties, including empty ones\n"
1298
" --kill-who=WHO Who to send signal to\n"
1299
" --full Do not ellipsize output\n"
1300
" -s --signal=SIGNAL Which signal to send\n"
1301
" --no-ask-password Don't prompt for password\n"
1302
" -H --host=[USER@]HOST Show information for remote host\n"
1303
" -P --privileged Acquire privileges before execution\n"
1304
" --no-pager Do not pipe output into a pager\n\n"
1656
1306
" list-sessions List sessions\n"
1657
1307
" session-status [ID...] Show session status\n"
1685
1337
ARG_VERSION = 0x100,
1340
ARG_NO_ASK_PASSWORD,
1690
1344
static const struct option options[] = {
1691
{ "help", no_argument, NULL, 'h' },
1692
{ "version", no_argument, NULL, ARG_VERSION },
1693
{ "property", required_argument, NULL, 'p' },
1694
{ "all", no_argument, NULL, 'a' },
1695
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
1696
{ "kill-who", required_argument, NULL, ARG_KILL_WHO },
1697
{ "signal", required_argument, NULL, 's' },
1698
{ "host", required_argument, NULL, 'H' },
1699
{ "privileged",no_argument, NULL, 'P' },
1700
{ NULL, 0, NULL, 0 }
1345
{ "help", no_argument, NULL, 'h' },
1346
{ "version", no_argument, NULL, ARG_VERSION },
1347
{ "property", required_argument, NULL, 'p' },
1348
{ "all", no_argument, NULL, 'a' },
1349
{ "no-pager", no_argument, NULL, ARG_NO_PAGER },
1350
{ "kill-who", required_argument, NULL, ARG_KILL_WHO },
1351
{ "signal", required_argument, NULL, 's' },
1352
{ "host", required_argument, NULL, 'H' },
1353
{ "privileged", no_argument, NULL, 'P' },
1354
{ "no-ask-password", no_argument, NULL, ARG_NO_ASK_PASSWORD },
1355
{ "full", no_argument, NULL, ARG_FULL },
1356
{ NULL, 0, NULL, 0 }