]> git.ipfire.org Git - thirdparty/systemd.git/blob - device.c
first attempt at proper service/socket logic
[thirdparty/systemd.git] / device.c
1 /*-*- Mode: C; c-basic-offset: 8 -*-*/
2
3 #include "name.h"
4 #include "device.h"
5 #include "strv.h"
6
7 static void device_done(Name *n) {
8 Device *d = DEVICE(n);
9
10 assert(d);
11 strv_free(d->sysfs);
12 }
13
14 static void device_dump(Name *n, FILE *f, const char *prefix) {
15
16 static const char* const state_table[_DEVICE_STATE_MAX] = {
17 [DEVICE_DEAD] = "dead",
18 [DEVICE_AVAILABLE] = "available"
19 };
20
21 Device *s = DEVICE(n);
22
23 assert(s);
24
25 fprintf(f,
26 "%sDevice State: %s\n",
27 prefix, state_table[s->state]);
28 }
29
30 static NameActiveState device_active_state(Name *n) {
31 return DEVICE(n)->state == DEVICE_DEAD ? NAME_INACTIVE : NAME_ACTIVE;
32 }
33
34 const NameVTable device_vtable = {
35 .suffix = ".device",
36
37 .init = name_load_fragment_and_dropin,
38 .done = device_done,
39 .dump = device_dump,
40
41 .active_state = device_active_state
42 };