mirror of
https://github.com/systemd/systemd.git
synced 2025-02-03 17:47:28 +03:00
Merge pull request #31729 from aafeijoo-suse/logind-cleanups
logind: coding style cleanups
This commit is contained in:
commit
8fb8c037b3
@ -221,7 +221,7 @@ int manager_add_inhibitor(Manager *m, const char* id, Inhibitor **ret) {
|
||||
|
||||
i = hashmap_get(m->inhibitors, id);
|
||||
if (!i) {
|
||||
r = inhibitor_new(&i, m, id);
|
||||
r = inhibitor_new(m, id, &i);
|
||||
if (r < 0)
|
||||
return r;
|
||||
}
|
||||
|
@ -29,13 +29,13 @@
|
||||
|
||||
static void inhibitor_remove_fifo(Inhibitor *i);
|
||||
|
||||
int inhibitor_new(Inhibitor **ret, Manager *m, const char* id) {
|
||||
int inhibitor_new(Manager *m, const char* id, Inhibitor **ret) {
|
||||
_cleanup_(inhibitor_freep) Inhibitor *i = NULL;
|
||||
int r;
|
||||
|
||||
assert(ret);
|
||||
assert(m);
|
||||
assert(id);
|
||||
assert(ret);
|
||||
|
||||
i = new(Inhibitor, 1);
|
||||
if (!i)
|
||||
@ -43,6 +43,8 @@ int inhibitor_new(Inhibitor **ret, Manager *m, const char* id) {
|
||||
|
||||
*i = (Inhibitor) {
|
||||
.manager = m,
|
||||
.id = strdup(id),
|
||||
.state_file = path_join("/run/systemd/inhibit/", id),
|
||||
.what = _INHIBIT_WHAT_INVALID,
|
||||
.mode = _INHIBIT_MODE_INVALID,
|
||||
.uid = UID_INVALID,
|
||||
@ -50,12 +52,9 @@ int inhibitor_new(Inhibitor **ret, Manager *m, const char* id) {
|
||||
.pid = PIDREF_NULL,
|
||||
};
|
||||
|
||||
i->state_file = path_join("/run/systemd/inhibit", id);
|
||||
if (!i->state_file)
|
||||
if (!i->id || !i->state_file)
|
||||
return -ENOMEM;
|
||||
|
||||
i->id = basename(i->state_file);
|
||||
|
||||
r = hashmap_put(m->inhibitors, i->id, i);
|
||||
if (r < 0)
|
||||
return r;
|
||||
@ -79,8 +78,9 @@ Inhibitor* inhibitor_free(Inhibitor *i) {
|
||||
|
||||
/* Note that we don't remove neither the state file nor the fifo path here, since we want both to
|
||||
* survive daemon restarts */
|
||||
free(i->state_file);
|
||||
free(i->fifo_path);
|
||||
free(i->state_file);
|
||||
free(i->id);
|
||||
|
||||
pidref_done(&i->pid);
|
||||
|
||||
|
@ -32,7 +32,7 @@ struct Inhibitor {
|
||||
|
||||
sd_event_source *event_source;
|
||||
|
||||
const char *id;
|
||||
char *id;
|
||||
char *state_file;
|
||||
|
||||
bool started;
|
||||
@ -51,7 +51,7 @@ struct Inhibitor {
|
||||
int fifo_fd;
|
||||
};
|
||||
|
||||
int inhibitor_new(Inhibitor **ret, Manager *m, const char* id);
|
||||
int inhibitor_new(Manager *m, const char* id, Inhibitor **ret);
|
||||
Inhibitor* inhibitor_free(Inhibitor *i);
|
||||
|
||||
DEFINE_TRIVIAL_CLEANUP_FUNC(Inhibitor*, inhibitor_free);
|
||||
|
Loading…
x
Reference in New Issue
Block a user