lib/sysroot: Add journal-msg signal
This will allow us to drop the awful hack in rpm-ostree where we watch our own stdout. In general, libraries shouldn't write to stdout. Also we can kill the systemd journal wrapper code. There's some duplication at each call site now...but it's easier than trying to write a `sd_journal_send()` wrapper. I was originally going to have this emit all of the structured data too as a `GVariant` but decided it wasn't worth it right now. Closes: #1052 Approved by: jlebon
This commit is contained in:
1 parent
75bce24cb9
commit
de153dea30
8 files changed
+75
-211
No files matched your search
@@ -47,9 +47,9 @@
|
||||
#include "ostree-linuxfsutil.h"
|
||||
#include "libglnx.h"
|
||||
|
||||
#define OSTREE_VARRELABEL_ID "da679b08acd34504b789d96f818ea781"
|
||||
#define OSTREE_CONFIGMERGE_ID "d3863baec13e4449ab0384684a8af3a7"
|
||||
#ifdef HAVE_LIBSYSTEMD
|
||||
#define OSTREE_VARRELABEL_ID SD_ID128_MAKE(da,67,9b,08,ac,d3,45,04,b7,89,d9,6f,81,8e,a7,81)
|
||||
#define OSTREE_CONFIGMERGE_ID SD_ID128_MAKE(d3,86,3b,ae,c1,3e,44,49,ab,03,84,68,4a,8a,f3,a7)
|
||||
#define OSTREE_DEPLOYMENT_COMPLETE_ID SD_ID128_MAKE(dd,44,0e,3e,54,90,83,b6,3d,0e,fc,7d,c1,52,55,f1)
|
||||
#endif
|
||||
|
||||
@@ -429,11 +429,19 @@ merge_configuration_from (OstreeSysroot *sysroot,
|
||||
cancellable, error))
|
||||
return glnx_prefix_error (error, "While computing configuration diff");
|
||||
|
||||
ot_log_structured_print_id_v (OSTREE_CONFIGMERGE_ID,
|
||||
"Copying /etc changes: %u modified, %u removed, %u added",
|
||||
modified->len,
|
||||
removed->len,
|
||||
added->len);
|
||||
{ g_autofree char *msg =
|
||||
g_strdup_printf ("Copying /etc changes: %u modified, %u removed, %u added",
|
||||
modified->len, removed->len, added->len);
|
||||
#ifdef HAVE_LIBSYSTEMD
|
||||
sd_journal_send ("MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(OSTREE_CONFIGMERGE_ID),
|
||||
"MESSAGE=%s", msg,
|
||||
"ETC_N_MODIFIED=%u", modified->len,
|
||||
"ETC_N_REMOVED=%u", removed->len,
|
||||
"ETC_N_ADDED=%u", added->len,
|
||||
NULL);
|
||||
#endif
|
||||
_ostree_sysroot_emit_journal_msg (sysroot, msg);
|
||||
}
|
||||
|
||||
glnx_fd_close int orig_etc_fd = -1;
|
||||
if (!glnx_opendirat (merge_deployment_dfd, "usr/etc", TRUE, &orig_etc_fd, error))
|
||||
@@ -688,9 +696,15 @@ selinux_relabel_var_if_needed (OstreeSysroot *sysroot,
|
||||
|
||||
if (!deployment_var_labeled)
|
||||
{
|
||||
ot_log_structured_print_id_v (OSTREE_VARRELABEL_ID,
|
||||
"Relabeling /var (no stamp file '%s' found)",
|
||||
selabeled);
|
||||
{ g_autofree char *msg =
|
||||
g_strdup_printf ("Relabeling /var (no stamp file '%s' found)", selabeled);
|
||||
#ifdef HAVE_LIBSYSTEMD
|
||||
sd_journal_send ("MESSAGE_ID=" SD_ID128_FORMAT_STR, SD_ID128_FORMAT_VAL(OSTREE_VARRELABEL_ID),
|
||||
"MESSAGE=%s", msg,
|
||||
NULL);
|
||||
#endif
|
||||
_ostree_sysroot_emit_journal_msg (sysroot, msg);
|
||||
}
|
||||
|
||||
g_autoptr(GFile) deployment_var_path = ot_fdrel_to_gfile (os_deploy_dfd, "var");
|
||||
if (!selinux_relabel_dir (sysroot, sepolicy,
|
||||
@@ -1917,8 +1931,7 @@ ostree_sysroot_write_deployments_with_options (OstreeSysroot *self,
|
||||
"OSTREE_SYNCFS_EXTRA_MSEC=%" G_GUINT64_FORMAT, syncstats.extra_syncfs_msec,
|
||||
NULL);
|
||||
#endif
|
||||
if (!ot_stdout_is_journal ())
|
||||
g_print ("%s\n", msg);
|
||||
_ostree_sysroot_emit_journal_msg (self, msg);
|
||||
}
|
||||
|
||||
if (!_ostree_sysroot_bump_mtime (self, error))
|
||||
|
||||
@@ -69,6 +69,10 @@ struct OstreeSysroot {
|
||||
#define _OSTREE_SYSROOT_DEPLOYMENT_RUNSTATE_DIR "/run/ostree/deployment-state/"
|
||||
#define _OSTREE_SYSROOT_DEPLOYMENT_RUNSTATE_FLAG_DEVELOPMENT "unlocked-development"
|
||||
|
||||
void
|
||||
_ostree_sysroot_emit_journal_msg (OstreeSysroot *self,
|
||||
const char *msg);
|
||||
|
||||
gboolean
|
||||
_ostree_sysroot_read_boot_loader_configs (OstreeSysroot *self,
|
||||
int bootversion,
|
||||
|
||||
@@ -58,8 +58,18 @@ find_booted_deployment (OstreeSysroot *self,
|
||||
*/
|
||||
typedef struct {
|
||||
GObjectClass parent_class;
|
||||
|
||||
/* Signals */
|
||||
void (*journal_msg) (OstreeSysroot *sysroot,
|
||||
const char *msg);
|
||||
} OstreeSysrootClass;
|
||||
|
||||
enum {
|
||||
JOURNAL_MSG_SIGNAL,
|
||||
LAST_SIGNAL,
|
||||
};
|
||||
static guint signals[LAST_SIGNAL] = { 0 };
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
|
||||
@@ -159,6 +169,27 @@ ostree_sysroot_class_init (OstreeSysrootClass *klass)
|
||||
"",
|
||||
G_TYPE_FILE,
|
||||
G_PARAM_READWRITE | G_PARAM_CONSTRUCT_ONLY));
|
||||
|
||||
/**
|
||||
* OstreeSysroot::journal-msg:
|
||||
* @self: Self
|
||||
* @msg: Human-readable string (should not contain newlines)
|
||||
*
|
||||
* libostree will log to the journal various events, such as the /etc merge
|
||||
* status, and transaction completion. Connect to this signal to also
|
||||
* synchronously receive the text for those messages. This is intended to be
|
||||
* used by command line tools which link to libostree as a library.
|
||||
*
|
||||
* Currently, the structured data is only available via the systemd journal.
|
||||
*
|
||||
* Since: 2017.10
|
||||
*/
|
||||
signals[JOURNAL_MSG_SIGNAL] =
|
||||
g_signal_new ("journal-msg",
|
||||
G_OBJECT_CLASS_TYPE (object_class),
|
||||
G_SIGNAL_RUN_LAST,
|
||||
G_STRUCT_OFFSET (OstreeSysrootClass, journal_msg),
|
||||
NULL, NULL, NULL, G_TYPE_NONE, 1, G_TYPE_STRING);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -319,6 +350,13 @@ ostree_sysroot_ensure_initialized (OstreeSysroot *self,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
_ostree_sysroot_emit_journal_msg (OstreeSysroot *self,
|
||||
const char *msg)
|
||||
{
|
||||
g_signal_emit (self, signals[JOURNAL_MSG_SIGNAL], 0, msg);
|
||||
}
|
||||
|
||||
gboolean
|
||||
_ostree_sysroot_parse_deploy_path_name (const char *name,
|
||||
char **out_csum,
|
||||
|
||||
Reference in new issue
Block a user