systemd: move basic systemd library to shared/nm-utils
For better or worse, we already pull in large parts of systemd sources. I need a base64 decode implementation (because glib's g_base64_decode() cannot reject invalid encodings). Instead of coming up with my own or copy-paste if from somewhere, reuse systemd's unbase64mem(). But for that, make systemd's basic bits an independent static library first because I will need it in libnm-core. This doesn't really change anything except making "libnm-systemd-core.la" an indpendent static library that could be used from "libnm-core". We shall still be mindful about which internal code of systemd we use, and only access functionality that is exposed via "systemd/nm-sd-utils-shared.h".
This commit is contained in:
28
shared/systemd/src/basic/umask-util.h
Normal file
28
shared/systemd/src/basic/umask-util.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1+ */
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "macro.h"
|
||||
|
||||
static inline void umaskp(mode_t *u) {
|
||||
umask(*u);
|
||||
}
|
||||
|
||||
#define _cleanup_umask_ _cleanup_(umaskp)
|
||||
|
||||
struct _umask_struct_ {
|
||||
mode_t mask;
|
||||
bool quit;
|
||||
};
|
||||
|
||||
static inline void _reset_umask_(struct _umask_struct_ *s) {
|
||||
umask(s->mask);
|
||||
};
|
||||
|
||||
#define RUN_WITH_UMASK(mask) \
|
||||
for (_cleanup_(_reset_umask_) struct _umask_struct_ _saved_umask_ = { umask(mask), false }; \
|
||||
!_saved_umask_.quit ; \
|
||||
_saved_umask_.quit = true)
|
Reference in New Issue
Block a user