New upstream version 2019.6
This commit is contained in:
commit
4a3cae5aba
48 files changed
+997
-280
No files matched your search
@@ -56,23 +56,25 @@ libglnx_la_LIBADD = $(libglnx_libs)
|
||||
libglnx_tests = test-libglnx-xattrs test-libglnx-fdio test-libglnx-errors test-libglnx-macros test-libglnx-shutil
|
||||
TESTS += $(libglnx_tests)
|
||||
|
||||
libglnx_testlib_sources = $(libglnx_srcpath)/tests/libglnx-testlib.c
|
||||
|
||||
check_PROGRAMS += $(libglnx_tests)
|
||||
test_libglnx_xattrs_SOURCES = $(libglnx_srcpath)/tests/test-libglnx-xattrs.c
|
||||
test_libglnx_xattrs_SOURCES = $(libglnx_testlib_sources) $(libglnx_srcpath)/tests/test-libglnx-xattrs.c
|
||||
test_libglnx_xattrs_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
|
||||
test_libglnx_xattrs_LDADD = $(libglnx_libs) libglnx.la
|
||||
|
||||
test_libglnx_fdio_SOURCES = $(libglnx_srcpath)/tests/test-libglnx-fdio.c
|
||||
test_libglnx_fdio_SOURCES = $(libglnx_testlib_sources) $(libglnx_srcpath)/tests/test-libglnx-fdio.c
|
||||
test_libglnx_fdio_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
|
||||
test_libglnx_fdio_LDADD = $(libglnx_libs) libglnx.la
|
||||
|
||||
test_libglnx_errors_SOURCES = $(libglnx_srcpath)/tests/test-libglnx-errors.c
|
||||
test_libglnx_errors_SOURCES = $(libglnx_testlib_sources) $(libglnx_srcpath)/tests/test-libglnx-errors.c
|
||||
test_libglnx_errors_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
|
||||
test_libglnx_errors_LDADD = $(libglnx_libs) libglnx.la
|
||||
|
||||
test_libglnx_macros_SOURCES = $(libglnx_srcpath)/tests/test-libglnx-macros.c
|
||||
test_libglnx_macros_SOURCES = $(libglnx_testlib_sources) $(libglnx_srcpath)/tests/test-libglnx-macros.c
|
||||
test_libglnx_macros_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
|
||||
test_libglnx_macros_LDADD = $(libglnx_libs) libglnx.la
|
||||
|
||||
test_libglnx_shutil_SOURCES = $(libglnx_srcpath)/tests/test-libglnx-shutil.c
|
||||
test_libglnx_shutil_SOURCES = $(libglnx_testlib_sources) $(libglnx_srcpath)/tests/test-libglnx-shutil.c
|
||||
test_libglnx_shutil_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
|
||||
test_libglnx_shutil_LDADD = $(libglnx_libs) libglnx.la
|
||||
@@ -56,23 +56,25 @@ libglnx_la_LIBADD = $(libglnx_libs)
|
||||
libglnx_tests = test-libglnx-xattrs test-libglnx-fdio test-libglnx-errors test-libglnx-macros test-libglnx-shutil
|
||||
TESTS += $(libglnx_tests)
|
||||
|
||||
libglnx_testlib_sources = libglnx/tests/libglnx-testlib.c
|
||||
|
||||
check_PROGRAMS += $(libglnx_tests)
|
||||
test_libglnx_xattrs_SOURCES = libglnx/tests/test-libglnx-xattrs.c
|
||||
test_libglnx_xattrs_SOURCES = $(libglnx_testlib_sources) libglnx/tests/test-libglnx-xattrs.c
|
||||
test_libglnx_xattrs_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
|
||||
test_libglnx_xattrs_LDADD = $(libglnx_libs) libglnx.la
|
||||
|
||||
test_libglnx_fdio_SOURCES = libglnx/tests/test-libglnx-fdio.c
|
||||
test_libglnx_fdio_SOURCES = $(libglnx_testlib_sources) libglnx/tests/test-libglnx-fdio.c
|
||||
test_libglnx_fdio_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
|
||||
test_libglnx_fdio_LDADD = $(libglnx_libs) libglnx.la
|
||||
|
||||
test_libglnx_errors_SOURCES = libglnx/tests/test-libglnx-errors.c
|
||||
test_libglnx_errors_SOURCES = $(libglnx_testlib_sources) libglnx/tests/test-libglnx-errors.c
|
||||
test_libglnx_errors_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
|
||||
test_libglnx_errors_LDADD = $(libglnx_libs) libglnx.la
|
||||
|
||||
test_libglnx_macros_SOURCES = libglnx/tests/test-libglnx-macros.c
|
||||
test_libglnx_macros_SOURCES = $(libglnx_testlib_sources) libglnx/tests/test-libglnx-macros.c
|
||||
test_libglnx_macros_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
|
||||
test_libglnx_macros_LDADD = $(libglnx_libs) libglnx.la
|
||||
|
||||
test_libglnx_shutil_SOURCES = libglnx/tests/test-libglnx-shutil.c
|
||||
test_libglnx_shutil_SOURCES = $(libglnx_testlib_sources) libglnx/tests/test-libglnx-shutil.c
|
||||
test_libglnx_shutil_CFLAGS = $(AM_CFLAGS) $(libglnx_cflags)
|
||||
test_libglnx_shutil_LDADD = $(libglnx_libs) libglnx.la
|
||||
@@ -28,6 +28,32 @@ One could also compare this project to gnulib; the salient differences
|
||||
there are that at least some of this module is eventually destined for
|
||||
inclusion in GLib.
|
||||
|
||||
Adding this to your project
|
||||
---------------------------
|
||||
|
||||
## Meson
|
||||
|
||||
First, set up a Git submodule:
|
||||
|
||||
```
|
||||
git submodule add https://gitlab.gnome.org/GNOME/libglnx subprojects/libglnx
|
||||
```
|
||||
|
||||
Or a Git [subtree](https://github.com/git/git/blob/master/contrib/subtree/git-subtree.txt):
|
||||
|
||||
```
|
||||
git remote add libglnx https://gitlab.gnome.org/GNOME/libglnx.git
|
||||
git fetch libglnx
|
||||
git subtree add -P subprojects/libglnx libglnx/master
|
||||
```
|
||||
|
||||
Then, in your top-level `meson.build`:
|
||||
|
||||
```
|
||||
libglnx_dep = subproject('libglnx').get_variable('libglnx_dep')
|
||||
# now use libglnx_dep in your dependencies
|
||||
```
|
||||
|
||||
Porting from libgsystem
|
||||
-----------------------
|
||||
|
||||
|
||||
+63
-8
@@ -277,17 +277,19 @@ glnx_open_tmpfile_linkable_at (int dfd,
|
||||
return open_tmpfile_core (dfd, subpath, flags, out_tmpf, error);
|
||||
}
|
||||
|
||||
|
||||
/* A variant of `glnx_open_tmpfile_linkable_at()` which doesn't support linking.
|
||||
* Useful for true temporary storage. The fd will be allocated in /var/tmp to
|
||||
* ensure maximum storage space.
|
||||
* Useful for true temporary storage. The fd will be allocated in the specified
|
||||
* directory.
|
||||
*/
|
||||
gboolean
|
||||
glnx_open_anonymous_tmpfile (int flags,
|
||||
GLnxTmpfile *out_tmpf,
|
||||
GError **error)
|
||||
glnx_open_anonymous_tmpfile_full (int flags,
|
||||
const char *dir,
|
||||
GLnxTmpfile *out_tmpf,
|
||||
GError **error)
|
||||
{
|
||||
/* Add in O_EXCL */
|
||||
if (!open_tmpfile_core (AT_FDCWD, "/var/tmp", flags | O_EXCL, out_tmpf, error))
|
||||
if (!open_tmpfile_core (AT_FDCWD, dir, flags | O_EXCL, out_tmpf, error))
|
||||
return FALSE;
|
||||
if (out_tmpf->path)
|
||||
{
|
||||
@@ -299,6 +301,21 @@ glnx_open_anonymous_tmpfile (int flags,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* A variant of `glnx_open_tmpfile_linkable_at()` which doesn't support linking.
|
||||
* Useful for true temporary storage. The fd will be allocated in /var/tmp to
|
||||
* ensure maximum storage space.
|
||||
*
|
||||
* If you need the file on a specific filesystem use glnx_open_anonymous_tmpfile_full()
|
||||
* which lets you pass a directory.
|
||||
*/
|
||||
gboolean
|
||||
glnx_open_anonymous_tmpfile (int flags,
|
||||
GLnxTmpfile *out_tmpf,
|
||||
GError **error)
|
||||
{
|
||||
return glnx_open_anonymous_tmpfile_full (flags, "/var/tmp", out_tmpf, error);
|
||||
}
|
||||
|
||||
/* Use this after calling glnx_open_tmpfile_linkable_at() to give
|
||||
* the file its final name (link into place).
|
||||
*/
|
||||
@@ -346,8 +363,7 @@ glnx_link_tmpfile_at (GLnxTmpfile *tmpf,
|
||||
{
|
||||
/* This case we have O_TMPFILE, so our reference to it is via /proc/self/fd */
|
||||
char proc_fd_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(tmpf->fd) + 1];
|
||||
|
||||
sprintf (proc_fd_path, "/proc/self/fd/%i", tmpf->fd);
|
||||
snprintf (proc_fd_path, sizeof (proc_fd_path), "/proc/self/fd/%i", tmpf->fd);
|
||||
|
||||
if (replace)
|
||||
{
|
||||
@@ -407,6 +423,45 @@ glnx_link_tmpfile_at (GLnxTmpfile *tmpf,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* glnx_tmpfile_reopen_rdonly:
|
||||
* @tmpf: tmpfile
|
||||
* @error: Error
|
||||
*
|
||||
* Give up write access to the file descriptior. One use
|
||||
* case for this is fs-verity, which requires a read-only fd.
|
||||
* It could also be useful to allocate an anonymous tmpfile
|
||||
* write some sort of caching/indexing data to it, then reopen it
|
||||
* read-only thereafter.
|
||||
**/
|
||||
gboolean
|
||||
glnx_tmpfile_reopen_rdonly (GLnxTmpfile *tmpf,
|
||||
GError **error)
|
||||
{
|
||||
g_return_val_if_fail (tmpf->fd >= 0, FALSE);
|
||||
g_return_val_if_fail (tmpf->src_dfd == AT_FDCWD || tmpf->src_dfd >= 0, FALSE);
|
||||
|
||||
glnx_fd_close int rdonly_fd = -1;
|
||||
|
||||
if (tmpf->path)
|
||||
{
|
||||
if (!glnx_openat_rdonly (tmpf->src_dfd, tmpf->path, FALSE, &rdonly_fd, error))
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* This case we have O_TMPFILE, so our reference to it is via /proc/self/fd */
|
||||
char proc_fd_path[strlen("/proc/self/fd/") + DECIMAL_STR_MAX(tmpf->fd) + 1];
|
||||
snprintf (proc_fd_path, sizeof (proc_fd_path), "/proc/self/fd/%i", tmpf->fd);
|
||||
|
||||
if (!glnx_openat_rdonly (AT_FDCWD, proc_fd_path, TRUE, &rdonly_fd, error))
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
glnx_close_fd (&tmpf->fd);
|
||||
tmpf->fd = glnx_steal_fd (&rdonly_fd);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* glnx_openat_rdonly:
|
||||
* @dfd: File descriptor for origin directory
|
||||
|
||||
@@ -83,6 +83,13 @@ glnx_open_anonymous_tmpfile (int flags,
|
||||
GLnxTmpfile *out_tmpf,
|
||||
GError **error);
|
||||
|
||||
gboolean
|
||||
glnx_open_anonymous_tmpfile_full (int flags,
|
||||
const char *dir,
|
||||
GLnxTmpfile *out_tmpf,
|
||||
GError **error);
|
||||
|
||||
|
||||
gboolean
|
||||
glnx_open_tmpfile_linkable_at (int dfd,
|
||||
const char *subpath,
|
||||
@@ -103,6 +110,10 @@ glnx_link_tmpfile_at (GLnxTmpfile *tmpf,
|
||||
const char *target,
|
||||
GError **error);
|
||||
|
||||
gboolean
|
||||
glnx_tmpfile_reopen_rdonly (GLnxTmpfile *tmpf,
|
||||
GError **error);
|
||||
|
||||
gboolean
|
||||
glnx_openat_rdonly (int dfd,
|
||||
const char *path,
|
||||
|
||||
@@ -31,6 +31,16 @@ G_BEGIN_DECLS
|
||||
/* All of these are for C only. */
|
||||
#ifndef __GI_SCANNER__
|
||||
|
||||
/* fixes builds against musl, taken from glibc unistd.h */
|
||||
#ifndef TEMP_FAILURE_RETRY
|
||||
#define TEMP_FAILURE_RETRY(expression) \
|
||||
(__extension__ \
|
||||
({ long int __result; \
|
||||
do __result = (long int) (expression); \
|
||||
while (__result == -1L && errno == EINTR); \
|
||||
__result; }))
|
||||
#endif
|
||||
|
||||
/* Taken from https://github.com/systemd/systemd/src/basic/string-util.h
|
||||
* at revision v228-666-gcf6c8c4
|
||||
*/
|
||||
|
||||
@@ -36,7 +36,6 @@
|
||||
#include <stdlib.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/syscall.h>
|
||||
#include <uchar.h>
|
||||
#include <unistd.h>
|
||||
|
||||
/* The precise definition of __O_TMPFILE is arch specific; use the
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||
*
|
||||
* Copyright 2019 Collabora Ltd.
|
||||
*
|
||||
* This library 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 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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 this library; if not, write to the
|
||||
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
||||
* Boston, MA 02111-1307, USA.
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "libglnx-testlib.h"
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
#include "libglnx.h"
|
||||
|
||||
struct _GLnxTestAutoTempDir
|
||||
{
|
||||
gchar *old_cwd;
|
||||
int old_cwd_fd;
|
||||
GLnxTmpDir temp_dir;
|
||||
};
|
||||
|
||||
_GLnxTestAutoTempDir *
|
||||
_glnx_test_auto_temp_dir_enter (void)
|
||||
{
|
||||
GError *error = NULL;
|
||||
_GLnxTestAutoTempDir *ret = g_new0 (_GLnxTestAutoTempDir, 1);
|
||||
|
||||
glnx_mkdtemp ("glnx-test-XXXXXX", 0700, &ret->temp_dir, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
/* just for better diagnostics */
|
||||
ret->old_cwd = g_get_current_dir ();
|
||||
|
||||
glnx_opendirat (-1, ".", TRUE, &ret->old_cwd_fd, &error);
|
||||
g_assert_no_error (error);
|
||||
|
||||
if (fchdir (ret->temp_dir.fd) != 0)
|
||||
g_error ("fchdir(<fd for \"%s\">): %s", ret->temp_dir.path, g_strerror (errno));
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void
|
||||
_glnx_test_auto_temp_dir_leave (_GLnxTestAutoTempDir *dir)
|
||||
{
|
||||
GError *error = NULL;
|
||||
|
||||
if (fchdir (dir->old_cwd_fd) != 0)
|
||||
g_error ("fchdir(<fd for \"%s\">): %s", dir->old_cwd, g_strerror (errno));
|
||||
|
||||
glnx_tmpdir_delete (&dir->temp_dir, NULL, &error);
|
||||
g_assert_no_error (error);
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
/* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*-
|
||||
*
|
||||
* Copyright (C) 2017 Red Hat, Inc.
|
||||
* Copyright 2019 Collabora Ltd.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -20,6 +21,10 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
#include "glnx-backport-autoptr.h"
|
||||
|
||||
typedef GError _GLnxTestAutoError;
|
||||
static inline void
|
||||
_glnx_test_auto_error_cleanup (_GLnxTestAutoError *autoerror)
|
||||
@@ -32,3 +37,12 @@ G_DEFINE_AUTOPTR_CLEANUP_FUNC(_GLnxTestAutoError, _glnx_test_auto_error_cleanup)
|
||||
#define _GLNX_TEST_DECLARE_ERROR(local_error, error) \
|
||||
g_autoptr(_GLnxTestAutoError) local_error = NULL; \
|
||||
GError **error = &local_error
|
||||
|
||||
typedef struct _GLnxTestAutoTempDir _GLnxTestAutoTempDir;
|
||||
|
||||
_GLnxTestAutoTempDir *_glnx_test_auto_temp_dir_enter (void);
|
||||
void _glnx_test_auto_temp_dir_leave (_GLnxTestAutoTempDir *dir);
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(_GLnxTestAutoTempDir, _glnx_test_auto_temp_dir_leave);
|
||||
|
||||
#define _GLNX_TEST_SCOPED_TEMP_DIR \
|
||||
g_autoptr(_GLnxTestAutoTempDir) temp_dir = _glnx_test_auto_temp_dir_enter ()
|
||||
@@ -237,6 +237,7 @@ test_filecopy (void)
|
||||
|
||||
int main (int argc, char **argv)
|
||||
{
|
||||
_GLNX_TEST_SCOPED_TEMP_DIR;
|
||||
int ret;
|
||||
|
||||
g_test_init (&argc, &argv, NULL);
|
||||
|
||||
Reference in new issue
Block a user