Skip to content

Commit 5bea5ce

Browse files
committed
Merge commit '36c81e9374e236f506866e978d339efd72b39104' as 'subprojects/libglnx'
2 parents a307c62 + 36c81e9 commit 5bea5ce

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+9368
-0
lines changed

subprojects/libglnx/.gitignore

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Copyright 2015 Colin Walters
2+
# SPDX-License-Identifier: LGPL-2.1-or-later
3+
4+
# A path ostree writes to work around automake bug with
5+
# subdir-objects
6+
Makefile-libglnx.am.inc
7+
8+
libglnx-config.h
9+
10+
# Some standard bits
11+
.deps
12+
.libs
13+
.dirstamp
14+
*.typelib
15+
*.la
16+
*.lo
17+
*.o
18+
*.pyc
19+
*.stamp
20+
*~
21+

subprojects/libglnx/.gitlab-ci.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# Copyright 2019 Endless OS Foundation LLC
2+
# SPDX-License-Identifier: LGPL-2.0-or-later
3+
4+
image: registry.fedoraproject.org/fedora:30
5+
6+
stages:
7+
- build
8+
9+
before_script:
10+
- dnf install -y gcc git meson ninja-build "pkgconfig(gio-2.0)" "pkgconfig(gio-unix-2.0)" "pkgconfig(glib-2.0)" xz
11+
12+
build:
13+
stage: build
14+
script:
15+
- meson _build .
16+
- ninja -C _build
17+
- meson test -C _build
18+
# Run it again! This previously did not work.
19+
- meson test -C _build
20+
# Ensure that we can build as a subproject
21+
- rm -fr _build/meson-dist
22+
- meson dist -C _build
23+
- mkdir -p tests/use-as-subproject/subprojects/libglnx
24+
- tar --strip-components=1 -C tests/use-as-subproject/subprojects/libglnx -xf _build/meson-dist/*.tar.xz
25+
- meson tests/use-as-subproject/_build tests/use-as-subproject
26+
- ninja -C tests/use-as-subproject/_build
27+
- meson test -C tests/use-as-subproject/_build
28+
artifacts:
29+
when: on_failure
30+
name: "libglnx-${CI_COMMIT_REF_NAME}-${CI_JOB_NAME}"
31+
paths:
32+
- "${CI_PROJECT_DIR}/_build/meson-logs"
33+
34+
reuse:
35+
stage: build
36+
image:
37+
name: fsfe/reuse:latest
38+
entrypoint: [""]
39+
before_script: []
40+
script:
41+
- reuse lint

subprojects/libglnx/COPYING

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
This project's licensing is REUSE-compliant <https://reuse.software/>.
2+
See individual files for full details of copyright and licensing,
3+
and see LICENSES/*.txt for the license text.

subprojects/libglnx/LICENSES/LGPL-2.0-or-later.txt

Lines changed: 174 additions & 0 deletions
Large diffs are not rendered by default.

subprojects/libglnx/LICENSES/LGPL-2.1-or-later.txt

Lines changed: 502 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
This work is provided "as is"; redistribution and modification
2+
in whole or in part, in any medium, physical or electronic is
3+
permitted without restriction.
4+
5+
This work is distributed in the hope that it will be useful,
6+
but WITHOUT ANY WARRANTY; without even the implied warranty of
7+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
8+
9+
In no event shall the authors or contributors be liable for any
10+
direct, indirect, incidental, special, exemplary, or consequential
11+
damages (including, but not limited to, procurement of substitute
12+
goods or services; loss of use, data, or profits; or business
13+
interruption) however caused and on any theory of liability, whether
14+
in contract, strict liability, or tort (including negligence or
15+
otherwise) arising in any way out of the use of this software, even
16+
if advised of the possibility of such damage.
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# Copyright (C) 2015 Colin Walters <[email protected]>
2+
# SPDX-License-Identifier: LGPL-2.0-or-later
3+
#
4+
# This library is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU Lesser General Public
6+
# License as published by the Free Software Foundation; either
7+
# version 2 of the License, or (at your option) any later version.
8+
#
9+
# This library is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12+
# Lesser General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU Lesser General Public
15+
# License along with this library; if not, write to the
16+
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17+
# Boston, MA 02111-1307, USA.
18+
19+
EXTRA_DIST += \
20+
$(libglnx_srcpath)/README.md \
21+
$(libglnx_srcpath)/COPYING \
22+
$(libglnx_srcpath)/LICENSES/LGPL-2.0-or-later.txt \
23+
$(libglnx_srcpath)/LICENSES/LGPL-2.1-or-later.txt \
24+
$(libglnx_srcpath)/libglnx.m4 \
25+
$(NULL)
26+
27+
BUILT_SOURCES += $(top_builddir)/libglnx-config.h
28+
CLEANFILES += $(top_builddir)/libglnx-config.h
29+
$(top_builddir)/libglnx-config.h: Makefile.am
30+
echo '#include "config.h"' > $@
31+
32+
libglnx_la_SOURCES = \
33+
$(libglnx_srcpath)/glnx-macros.h \
34+
$(libglnx_srcpath)/glnx-backport-autocleanups.h \
35+
$(libglnx_srcpath)/glnx-backport-autoptr.h \
36+
$(libglnx_srcpath)/glnx-backport-testutils.h \
37+
$(libglnx_srcpath)/glnx-backport-testutils.c \
38+
$(libglnx_srcpath)/glnx-backports.h \
39+
$(libglnx_srcpath)/glnx-backports.c \
40+
$(libglnx_srcpath)/glnx-local-alloc.h \
41+
$(libglnx_srcpath)/glnx-local-alloc.c \
42+
$(libglnx_srcpath)/glnx-errors.h \
43+
$(libglnx_srcpath)/glnx-errors.c \
44+
$(libglnx_srcpath)/glnx-console.h \
45+
$(libglnx_srcpath)/glnx-console.c \
46+
$(libglnx_srcpath)/glnx-dirfd.h \
47+
$(libglnx_srcpath)/glnx-dirfd.c \
48+
$(libglnx_srcpath)/glnx-fdio.h \
49+
$(libglnx_srcpath)/glnx-fdio.c \
50+
$(libglnx_srcpath)/glnx-lockfile.h \
51+
$(libglnx_srcpath)/glnx-lockfile.c \
52+
$(libglnx_srcpath)/glnx-missing-syscall.h \
53+
$(libglnx_srcpath)/glnx-missing.h \
54+
$(libglnx_srcpath)/glnx-xattrs.h \
55+
$(libglnx_srcpath)/glnx-xattrs.c \
56+
$(libglnx_srcpath)/glnx-shutil.h \
57+
$(libglnx_srcpath)/glnx-shutil.c \
58+
$(libglnx_srcpath)/libglnx.h \
59+
$(libglnx_srcpath)/tests/libglnx-testlib.h \
60+
$(NULL)
61+
62+
libglnx_la_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags) -I$(builddir)
63+
libglnx_la_LDFLAGS = -avoid-version -Bsymbolic-functions -export-symbols-regex "^glnx_" -no-undefined -export-dynamic
64+
libglnx_la_LIBADD = $(libglnx_libs)
65+
66+
libglnx_tests = test-libglnx-xattrs test-libglnx-fdio test-libglnx-errors test-libglnx-macros test-libglnx-shutil
67+
TESTS += $(libglnx_tests)
68+
69+
libglnx_testlib_sources = $(libglnx_srcpath)/tests/libglnx-testlib.c
70+
71+
check_PROGRAMS += $(libglnx_tests)
72+
test_libglnx_xattrs_SOURCES = $(libglnx_testlib_sources) $(libglnx_srcpath)/tests/test-libglnx-xattrs.c
73+
test_libglnx_xattrs_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
74+
test_libglnx_xattrs_LDADD = $(libglnx_libs) libglnx.la
75+
76+
test_libglnx_fdio_SOURCES = $(libglnx_testlib_sources) $(libglnx_srcpath)/tests/test-libglnx-fdio.c
77+
test_libglnx_fdio_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
78+
test_libglnx_fdio_LDADD = $(libglnx_libs) libglnx.la
79+
80+
test_libglnx_errors_SOURCES = $(libglnx_testlib_sources) $(libglnx_srcpath)/tests/test-libglnx-errors.c
81+
test_libglnx_errors_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
82+
test_libglnx_errors_LDADD = $(libglnx_libs) libglnx.la
83+
84+
test_libglnx_macros_SOURCES = $(libglnx_testlib_sources) $(libglnx_srcpath)/tests/test-libglnx-macros.c
85+
test_libglnx_macros_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
86+
test_libglnx_macros_LDADD = $(libglnx_libs) libglnx.la
87+
88+
test_libglnx_shutil_SOURCES = $(libglnx_testlib_sources) $(libglnx_srcpath)/tests/test-libglnx-shutil.c
89+
test_libglnx_shutil_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
90+
test_libglnx_shutil_LDADD = $(libglnx_libs) libglnx.la

subprojects/libglnx/README.md

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
libglnx is the successor to [libgsystem](https://gitlab.gnome.org/Archive/libgsystem).
2+
3+
It is for modules which depend on both GLib and Linux, intended to be
4+
used as a git submodule.
5+
6+
Features:
7+
8+
- File APIs which use `openat()` like APIs, but also take a `GCancellable`
9+
to support dynamic cancellation
10+
- APIs also have a `GError` parameter
11+
- High level "shutil", somewhat inspired by Python's
12+
- A "console" API for tty output
13+
- A backport of the GLib cleanup macros for projects which can't yet take
14+
a dependency on 2.40.
15+
16+
Why?
17+
----
18+
19+
There are multiple projects which have a hard dependency on Linux and
20+
GLib, such as NetworkManager, ostree, flatpak, etc. It makes sense
21+
for them to be able to share Linux-specific APIs.
22+
23+
This module also contains some code taken from systemd, which has very
24+
high quality LGPLv2+ shared library code, but most of the internal
25+
shared library is private, and not namespaced.
26+
27+
One could also compare this project to gnulib; the salient differences
28+
there are that at least some of this module is eventually destined for
29+
inclusion in GLib.
30+
31+
Adding this to your project
32+
---------------------------
33+
34+
## Meson
35+
36+
First, set up a Git submodule:
37+
38+
```
39+
git submodule add https://gitlab.gnome.org/GNOME/libglnx subprojects/libglnx
40+
```
41+
42+
Or a Git [subtree](https://github.com/git/git/blob/master/contrib/subtree/git-subtree.txt):
43+
44+
```
45+
git remote add libglnx https://gitlab.gnome.org/GNOME/libglnx.git
46+
git fetch libglnx
47+
git subtree add -P subprojects/libglnx libglnx/master
48+
```
49+
50+
Then, in your top-level `meson.build`:
51+
52+
```
53+
libglnx_dep = subproject('libglnx').get_variable('libglnx_dep')
54+
# now use libglnx_dep in your dependencies
55+
```
56+
57+
Porting from libgsystem
58+
-----------------------
59+
60+
For all of the filesystem access code, libglnx exposes only
61+
fd-relative API, not `GFile*`. It does use `GCancellable` where
62+
applicable.
63+
64+
For local allocation macros, you should start using the `g_auto`
65+
macros from GLib. A backport is included in libglnx. There are a few
66+
APIs not defined in GLib yet, such as `glnx_autofd`.
67+
68+
`gs_transfer_out_value` is replaced by `g_steal_pointer`.
69+
70+
Contributing
71+
------------
72+
73+
Development happens in GNOME Gitlab: https://gitlab.gnome.org/GNOME/libglnx
74+
75+
(If you're seeing this on the Github mirror, we used to do development
76+
on Github but that was before GNOME deployed Gitlab.)
77+
78+
<!--
79+
Copyright 2015-2018 Colin Walters
80+
Copyright 2019 Endless OS Foundation LLC
81+
SPDX-License-Identifier: LGPL-2.1-or-later
82+
-->
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
/*
2+
* Copyright © 2015 Canonical Limited
3+
* SPDX-License-Identifier: LGPL-2.0-or-later
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 2 of the licence, or (at your option) any later version.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
17+
*
18+
* Author: Ryan Lortie <[email protected]>
19+
*/
20+
21+
#pragma once
22+
23+
#include <glnx-backport-autoptr.h>
24+
25+
#if !GLIB_CHECK_VERSION(2, 43, 4)
26+
27+
static inline void
28+
g_autoptr_cleanup_generic_gfree (void *p)
29+
{
30+
void **pp = (void**)p;
31+
if (*pp)
32+
g_free (*pp);
33+
}
34+
35+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GAsyncQueue, g_async_queue_unref)
36+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GBookmarkFile, g_bookmark_file_free)
37+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GBytes, g_bytes_unref)
38+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GChecksum, g_checksum_free)
39+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDateTime, g_date_time_unref)
40+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDir, g_dir_close)
41+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GError, g_error_free)
42+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GHashTable, g_hash_table_unref)
43+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GHmac, g_hmac_unref)
44+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GIOChannel, g_io_channel_unref)
45+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GKeyFile, g_key_file_unref)
46+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GList, g_list_free)
47+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GArray, g_array_unref)
48+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GPtrArray, g_ptr_array_unref)
49+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMainContext, g_main_context_unref)
50+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMainLoop, g_main_loop_unref)
51+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSource, g_source_unref)
52+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMappedFile, g_mapped_file_unref)
53+
#if GLIB_CHECK_VERSION(2, 36, 0)
54+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMarkupParseContext, g_markup_parse_context_unref)
55+
#endif
56+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(gchar, g_free)
57+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GNode, g_node_destroy)
58+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GOptionContext, g_option_context_free)
59+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GOptionGroup, g_option_group_free)
60+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GPatternSpec, g_pattern_spec_free)
61+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GQueue, g_queue_free)
62+
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GQueue, g_queue_clear)
63+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GRand, g_rand_free)
64+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GRegex, g_regex_unref)
65+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMatchInfo, g_match_info_unref)
66+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GScanner, g_scanner_destroy)
67+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSequence, g_sequence_free)
68+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSList, g_slist_free)
69+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GStringChunk, g_string_chunk_free)
70+
G_DEFINE_AUTO_CLEANUP_FREE_FUNC(GStrv, g_strfreev, NULL)
71+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GThread, g_thread_unref)
72+
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GMutex, g_mutex_clear)
73+
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GCond, g_cond_clear)
74+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTimer, g_timer_destroy)
75+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTimeZone, g_time_zone_unref)
76+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTree, g_tree_unref)
77+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariant, g_variant_unref)
78+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantBuilder, g_variant_builder_unref)
79+
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GVariantBuilder, g_variant_builder_clear)
80+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantIter, g_variant_iter_free)
81+
#if GLIB_CHECK_VERSION(2, 40, 0)
82+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantDict, g_variant_dict_unref)
83+
G_DEFINE_AUTO_CLEANUP_CLEAR_FUNC(GVariantDict, g_variant_dict_clear)
84+
#endif
85+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVariantType, g_variant_type_free)
86+
#if GLIB_CHECK_VERSION(2, 40, 0)
87+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSubprocess, g_object_unref)
88+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSubprocessLauncher, g_object_unref)
89+
#endif
90+
91+
/* Add GObject-based types as needed. */
92+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GAsyncResult, g_object_unref)
93+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GCancellable, g_object_unref)
94+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GConverter, g_object_unref)
95+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GConverterOutputStream, g_object_unref)
96+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDataInputStream, g_object_unref)
97+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFile, g_object_unref)
98+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileEnumerator, g_object_unref)
99+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileIOStream, g_object_unref)
100+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileInfo, g_object_unref)
101+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileInputStream, g_object_unref)
102+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileMonitor, g_object_unref)
103+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GFileOutputStream, g_object_unref)
104+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GInputStream, g_object_unref)
105+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMemoryInputStream, g_object_unref)
106+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMemoryOutputStream, g_object_unref)
107+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GMount, g_object_unref)
108+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GOutputStream, g_object_unref)
109+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSocket, g_object_unref)
110+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GSocketAddress, g_object_unref)
111+
#if GLIB_CHECK_VERSION(2, 36, 0)
112+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTask, g_object_unref)
113+
#endif
114+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTlsCertificate, g_object_unref)
115+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTlsDatabase, g_object_unref)
116+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GTlsInteraction, g_object_unref)
117+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDBusConnection, g_object_unref)
118+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GDBusMessage, g_object_unref)
119+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GVolumeMonitor, g_object_unref)
120+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GZlibCompressor, g_object_unref)
121+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GZlibDecompressor, g_object_unref)
122+
123+
#endif
124+
125+
#if !GLIB_CHECK_VERSION(2, 45, 8)
126+
127+
static inline void
128+
g_autoptr_cleanup_gstring_free (GString *string)
129+
{
130+
if (string)
131+
g_string_free (string, TRUE);
132+
}
133+
134+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GString, g_autoptr_cleanup_gstring_free)
135+
136+
#endif

0 commit comments

Comments
 (0)