inhibit.c revision b9c26b413497a0014ac2058a0ec04849a83df1ea
/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
/***
This file is part of systemd.
Copyright 2012 Lennart Poettering
under the terms of the GNU Lesser General Public License as published by
the Free Software Foundation; either version 2.1 of the License, or
(at your option) any later version.
systemd is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with systemd; If not, see <http://www.gnu.org/licenses/>.
***/
#include <getopt.h>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <dbus.h>
#include <unistd.h>
#include "dbus-common.h"
#include "util.h"
#include "build.h"
#include "strv.h"
static const char* arg_what = "idle:sleep:shutdown";
static const char* arg_why = "Unknown reason";
static const char* arg_mode = "block";
static enum {
} arg_action = ACTION_INHIBIT;
int fd;
bus,
"org.freedesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
"Inhibit",
&reply,
NULL,
if (fd)
return fd;
return fd;
}
unsigned n = 0;
int r;
bus,
"org.freedesktop.login1",
"/org/freedesktop/login1",
"org.freedesktop.login1.Manager",
"ListInhibitors",
&reply,
NULL,
if (r)
return -ENOMEM;
goto finish;
r = -ENOMEM;
goto finish;
}
r = -EIO;
goto finish;
}
printf("%-21s %-20s %-20s %-5s %6s %6s\n",
"WHAT",
"WHO",
"WHY",
"MODE",
"UID",
"PID");
r = -EIO;
goto finish;
}
r = -EIO;
goto finish;
}
printf("%-21s %-20s %-20s %-5s %6lu %6lu\n",
n++;
}
printf("\n%u inhibitors listed.\n", n);
r = 0;
if (reply)
return r;
}
static int help(void) {
printf("%s [OPTIONS...] {COMMAND} ...\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" --what=WHAT Operations to inhibit, colon separated list of idle,\n"
" sleep, shutdown\n"
" --who=STRING A descriptive string who is inhibiting\n"
" --why=STRING A descriptive string why is being inhibited\n"
" --mode=MODE One of block or delay\n"
" --list List active inhibitors\n",
return 0;
}
enum {
ARG_VERSION = 0x100,
};
};
int c;
switch (c) {
case 'h':
help();
return 0;
case ARG_VERSION:
return 0;
case ARG_WHAT:
break;
case ARG_WHO:
break;
case ARG_WHY:
break;
case ARG_MODE:
break;
case ARG_LIST:
break;
default:
log_error("Unknown option code %c", c);
return -EINVAL;
}
}
log_error("Missing command line to execute.");
return -EINVAL;
}
return 1;
}
int r, exit_code = 0;
int fd = -1;
log_open();
if (r <= 0)
goto finish;
if (!bus) {
r = -EIO;
goto finish;
}
if (arg_action == ACTION_LIST) {
if (r < 0) {
goto finish;
}
} else {
char *w = NULL;
if (!arg_who)
free(w);
if (fd < 0) {
r = fd;
goto finish;
}
if (pid < 0) {
log_error("Failed to fork: %m");
r = -errno;
goto finish;
}
if (pid == 0) {
/* Child */
}
if (r >= 0)
exit_code = r;
}
if (bus) {
}
if (fd >= 0)
return r < 0 ? EXIT_FAILURE : exit_code;
}