diff options
author | Tom Gundersen <teg@jklm.no> | 2014-11-05 20:15:53 +0100 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2014-12-11 13:54:17 +0100 |
commit | 3b5bf48d38a0daf8c095beaad1abd65d5bae30d5 (patch) | |
tree | d5e491d0fb3746191ec5dbcc4c48304d7111ae70 | |
parent | 29a4d476bd9da3e72ec73664d2597d8eebdbe0fe (diff) |
libsystemd: add initial sd-device library
-rw-r--r-- | Makefile.am | 6 | ||||
-rw-r--r-- | src/libsystemd/sd-device/device-util.h | 28 | ||||
-rw-r--r-- | src/libsystemd/sd-device/sd-device.c | 58 | ||||
-rw-r--r-- | src/systemd/sd-device.h | 42 |
4 files changed, 133 insertions, 1 deletions
diff --git a/Makefile.am b/Makefile.am index 5c8f6a6b5..d7a587118 100644 --- a/Makefile.am +++ b/Makefile.am @@ -218,6 +218,7 @@ AM_CPPFLAGS = \ -I $(top_srcdir)/src/libsystemd/sd-rtnl \ -I $(top_srcdir)/src/libsystemd/sd-network \ -I $(top_srcdir)/src/libsystemd/sd-hwdb \ + -I $(top_srcdir)/src/libsystemd/sd-device \ -I $(top_srcdir)/src/libsystemd-network \ -I $(top_srcdir)/src/libsystemd-terminal \ $(OUR_CPPFLAGS) @@ -2644,6 +2645,7 @@ libsystemd_internal_la_SOURCES = \ src/systemd/sd-path.h \ src/systemd/sd-network.h \ src/systemd/sd-hwdb.h \ + src/systemd/sd-device.h \ src/libsystemd/sd-bus/sd-bus.c \ src/libsystemd/sd-bus/bus-control.c \ src/libsystemd/sd-bus/bus-control.h \ @@ -2707,7 +2709,9 @@ libsystemd_internal_la_SOURCES = \ src/libsystemd/sd-network/network-util.c \ src/libsystemd/sd-hwdb/sd-hwdb.c \ src/libsystemd/sd-hwdb/hwdb-util.h \ - src/libsystemd/sd-hwdb/hwdb-intenal.h + src/libsystemd/sd-hwdb/hwdb-intenal.h \ + src/libsystemd/sd-device/sd-device.c \ + src/libsystemd/sd-device/device-util.h nodist_libsystemd_internal_la_SOURCES = \ src/libsystemd/libsystemd.sym diff --git a/src/libsystemd/sd-device/device-util.h b/src/libsystemd/sd-device/device-util.h new file mode 100644 index 000000000..87cda99f9 --- /dev/null +++ b/src/libsystemd/sd-device/device-util.h @@ -0,0 +1,28 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#pragma once + +/*** + This file is part of systemd. + + Copyright 2014 Tom Gundersen <teg@jklm.no> + + systemd is free software; you can redistribute it and/or modify it + 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 "util.h" + +DEFINE_TRIVIAL_CLEANUP_FUNC(sd_device*, sd_device_unref); + +#define _cleanup_device_unref_ _cleanup_(sd_device_unrefp) diff --git a/src/libsystemd/sd-device/sd-device.c b/src/libsystemd/sd-device/sd-device.c new file mode 100644 index 000000000..715eae469 --- /dev/null +++ b/src/libsystemd/sd-device/sd-device.c @@ -0,0 +1,58 @@ +/*** + This file is part of systemd. + + Copyright 2008-2012 Kay Sievers <kay@vrfy.org> + Copyright 2014 Tom Gundersen <teg@jklm.no> + + systemd is free software; you can redistribute it and/or modify it + 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 "refcnt.h" + +#include "sd-device.h" + +struct sd_device { + RefCount n_ref; +} + +static int device_new(sd_device **ret) { + _cleanup_device_unref_ sd_device *device = NULL; + + assert(ret); + + device = new0(sd_device, 1); + if (!device) + return -ENOMEM; + + device->n_ref = REFCNT_INIT; + + *ret = device; + device = NULL; + + return 0; +} + +_public_ sd_device *sd_device_ref(sd_device *device) { + if (device) + assert_se(REFCNT_INC(device->n_ref) >= 2); + + return device; +} + +_public_ sd_device *sd_device_unref(sd_device *device) { + if (device && REFCNT_DEC(device->n_ref) <= 0) + free(device); + + return NULL; +} diff --git a/src/systemd/sd-device.h b/src/systemd/sd-device.h new file mode 100644 index 000000000..5504e4911 --- /dev/null +++ b/src/systemd/sd-device.h @@ -0,0 +1,42 @@ +/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/ + +#ifndef foosddevicehfoo +#define foosddevicehfoo + +/*** + This file is part of systemd. + + Copyright 2008-2012 Kay Sievers <kay@vrfy.org> + Copyright 2014 Tom Gundersen <teg@jklm.no> + + systemd is free software; you can redistribute it and/or modify it + 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 <sys/types.h> +#include <stdint.h> + +#include "_sd-common.h" + +_SD_BEGIN_DECLARATIONS; + +typedef struct sd_device sd_device; + +sd_device *sd_device_ref(sd_device *device); +sd_device *sd_device_unref(sd_device *device); + +int sd_device_new_from_syspath(sd_device **ret, const char *syspath); + +_SD_END_DECLARATIONS; + +#endif |