Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patches 2 upstream systemd #32430

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/analyze/analyze-plot.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "unit-def.h"
#include "version.h"

#define SCALE_X (0.1 / 1000.0) /* pixels per us */
#define SCALE_X (0.1 * svg_timescale / 1000.0) /* pixels per us */
#define SCALE_Y (20.0)

#define svg(...) printf(__VA_ARGS__)
Expand All @@ -30,6 +30,9 @@
svg("</text>\n"); \
} while (false)

#define svg_timestamp(b, t, y) \
svg_text(b, t, y, "%u.%03us", (unsigned)((t) / USEC_PER_SEC), (unsigned)(((t) % USEC_PER_SEC) / USEC_PER_MSEC))


typedef struct HostInfo {
char *hostname;
Expand Down Expand Up @@ -366,6 +369,9 @@ static int produce_plot_as_svg(
svg_bar("generators", boot->generators_start_time, boot->generators_finish_time, y);
svg_bar("unitsload", boot->unitsload_start_time, boot->unitsload_finish_time, y);
svg_text(true, boot->userspace_time, y, "systemd");
if (detailed_svg) {
svg_timestamp(false, boot->userspace_time, y);
}
y++;

for (; u->has_data; u++)
Expand Down
17 changes: 16 additions & 1 deletion src/analyze/analyze.c
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ RuntimeScope arg_runtime_scope = RUNTIME_SCOPE_SYSTEM;
RecursiveErrors arg_recursive_errors = _RECURSIVE_ERRORS_INVALID;
bool arg_man = true;
bool arg_generators = false;
double svg_timescale = 1.0;
bool detailed_svg = false;
char *arg_root = NULL;
static char *arg_image = NULL;
char *arg_security_policy = NULL;
Expand Down Expand Up @@ -274,6 +276,8 @@ static int help(int argc, char *argv[], void *userdata) {
" security review of the unit(s)\n"
" --unit=UNIT Evaluate conditions and asserts of unit\n"
" --table Output plot's raw time data as a table\n"
" -s --scale=FACTOR Stretch the x-axis of the plot by FACTOR (default: 1.0)\n"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shorthands are prime real estate, and sd-analyze has tons of options and will get more. This is not something common enough to warrant taking over one of the 52 available single-letter options, so please just use the long one

" --detailed Add more details to SVG plot, e.g. show activation timestamps\n\n"
" -h --help Show this help\n"
" --version Show package version\n"
" -q --quiet Do not emit hints\n"
Expand Down Expand Up @@ -322,6 +326,7 @@ static int parse_argv(int argc, char *argv[]) {
ARG_TABLE,
ARG_NO_LEGEND,
ARG_TLDR,
ARG_DETAILED_SVG,
};

static const struct option options[] = {
Expand Down Expand Up @@ -356,6 +361,8 @@ static int parse_argv(int argc, char *argv[]) {
{ "table", optional_argument, NULL, ARG_TABLE },
{ "no-legend", optional_argument, NULL, ARG_NO_LEGEND },
{ "tldr", no_argument, NULL, ARG_TLDR },
{ "scale", required_argument, NULL, 's' },
{ "detailed", no_argument, NULL, ARG_DETAILED_SVG },
{}
};

Expand All @@ -364,7 +371,7 @@ static int parse_argv(int argc, char *argv[]) {
assert(argc >= 0);
assert(argv);

while ((c = getopt_long(argc, argv, "hH:M:U:q", options, NULL)) >= 0)
while ((c = getopt_long(argc, argv, "hH:M:U:q:s", options, NULL)) >= 0)
switch (c) {

case 'h':
Expand Down Expand Up @@ -549,6 +556,14 @@ static int parse_argv(int argc, char *argv[]) {
arg_cat_flags = CAT_TLDR;
break;

case 's':
svg_timescale = strtod(optarg, NULL);
break;

case ARG_DETAILED_SVG:
detailed_svg = true;
break;

case '?':
return -EINVAL;

Expand Down
2 changes: 2 additions & 0 deletions src/analyze/analyze.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ extern RuntimeScope arg_runtime_scope;
extern RecursiveErrors arg_recursive_errors;
extern bool arg_man;
extern bool arg_generators;
extern double svg_timescale;
extern bool detailed_svg;
extern char *arg_root;
extern char *arg_security_policy;
extern bool arg_offline;
Expand Down
22 changes: 22 additions & 0 deletions src/core/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -1699,6 +1699,17 @@ static void cmdline_take_random_seed(void) {
"This functionality should not be used outside of testing environments.");
}

static void set_suid_dumpable(void) {
const char *sd_path = "/proc/sys/fs/suid_dumpable";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, we already do this?

fs.suid_dumpable=2

const char *value = "2";

/* Write suid_dumpable setting: */
int r = write_string_file(sd_path, value, 0);

if (r < 0)
log_emergency("Failed to write to /proc/sys/fs/suid_dumpable");
}

static void initialize_coredump(bool skip_setup) {
if (getpid_cached() != 1)
return;
Expand Down Expand Up @@ -2032,6 +2043,14 @@ static int invoke_main_loop(
assert(ret_switch_root_init);
assert(ret_error_message);

log_warning("sd: i=userspace, inactive_exit="USEC_FMT, m->timestamps[MANAGER_TIMESTAMP_USERSPACE].monotonic);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If anything, these definitely shouldn't be logged at the warning level (debug seems to be appropriate).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

and they can all be queried at runtime, and some are already logged later, so doesn't seem worth adding any of these

log_warning("sd: i=security, inactive_exit="USEC_FMT, m->timestamps[MANAGER_TIMESTAMP_SECURITY_START].monotonic);
log_warning("sd: i=security, active_enter="USEC_FMT, m->timestamps[MANAGER_TIMESTAMP_SECURITY_FINISH].monotonic);
log_warning("sd: i=generators, inactive_exit="USEC_FMT, m->timestamps[MANAGER_TIMESTAMP_GENERATORS_START].monotonic);
log_warning("sd: i=generators, active_enter="USEC_FMT, m->timestamps[MANAGER_TIMESTAMP_GENERATORS_FINISH].monotonic);
log_warning("sd: i=units_load, inactive_exit="USEC_FMT, m->timestamps[MANAGER_TIMESTAMP_UNITS_LOAD_START].monotonic);
log_warning("sd: i=units_load, active_enter="USEC_FMT, m->timestamps[MANAGER_TIMESTAMP_UNITS_LOAD_FINISH].monotonic);

for (;;) {
int objective = manager_loop(m);
if (objective < 0) {
Expand Down Expand Up @@ -3002,6 +3021,8 @@ int main(int argc, char *argv[]) {
kernel_timestamp = DUAL_TIMESTAMP_NULL;
}

log_warning("sd: status changed: INITIALIZING, t="USEC_FMT, userspace_timestamp.monotonic);

initialize_coredump(skip_setup);

r = fixup_environment();
Expand Down Expand Up @@ -3137,6 +3158,7 @@ int main(int argc, char *argv[]) {
}

/* A core pattern might have been specified via the cmdline. */
set_suid_dumpable();
initialize_core_pattern(skip_setup);

/* Make /usr/ read-only */
Expand Down
9 changes: 9 additions & 0 deletions src/core/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -3785,6 +3785,11 @@ static void manager_notify_finished(Manager *m) {
FORMAT_TIMESPAN(total_usec, USEC_PER_MSEC)));
}

log_warning("sd: i=userspace, active_enter="USEC_FMT, m->timestamps[MANAGER_TIMESTAMP_FINISH].monotonic);
log_warning("sd: status changed: %s, t="USEC_FMT,
(set_size(m->failed_units) > 0) ? "DEGRADED(startdone)": "RUNNING",
m->timestamps[MANAGER_TIMESTAMP_FINISH].monotonic);

bus_manager_send_finished(m, firmware_usec, loader_usec, kernel_usec, initrd_usec, userspace_usec, total_usec);

log_taint_string(m);
Expand Down Expand Up @@ -4552,6 +4557,10 @@ int manager_update_failed_units(Manager *m, Unit *u, bool failed) {
size = set_size(m->failed_units);

if (failed) {
log_warning("sd: status changed: %s, t="USEC_FMT,
dual_timestamp_is_set(m->timestamps + MANAGER_TIMESTAMP_FINISH) ? "DEGRADED"
: "STARTING(degraded)",
u->inactive_enter_timestamp.monotonic);
r = set_ensure_put(&m->failed_units, NULL, u);
if (r < 0)
return log_oom();
Expand Down
11 changes: 11 additions & 0 deletions src/core/mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -1108,6 +1108,7 @@ static int mount_set_mount_command(Mount *m, ExecCommand *c, const MountParamete

static void mount_enter_mounting(Mount *m) {
MountParameters *p;
DIR* dp;
bool source_is_dir = true;
int r;

Expand Down Expand Up @@ -1168,6 +1169,16 @@ static void mount_enter_mounting(Mount *m) {
m->control_command_id = MOUNT_EXEC_MOUNT;
m->control_command = m->exec_command + MOUNT_EXEC_MOUNT;

dp = opendir(m->where);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we want to nuke any files from the filesystem which are not under our direct control.

if (!dp) {
//this is not a directory but rather file or link
remove(m->where);
mkdir_p(m->where, m->directory_mode);
}
else {
closedir(dp);
}

/* Create the source directory for bind-mounts if needed */
if (p && mount_is_bind(p)) {
r = mkdir_p_label(p->what, m->directory_mode);
Expand Down
24 changes: 20 additions & 4 deletions src/core/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -2622,15 +2622,31 @@ void unit_notify(Unit *u, UnitActiveState os, UnitActiveState ns, bool reload_su
if (!MANAGER_IS_RELOADING(m)) {
dual_timestamp_now(&u->state_change_timestamp);

if (UNIT_IS_INACTIVE_OR_FAILED(os) && !UNIT_IS_INACTIVE_OR_FAILED(ns))
if (UNIT_IS_INACTIVE_OR_FAILED(os) && !UNIT_IS_INACTIVE_OR_FAILED(ns)) {
u->inactive_exit_timestamp = u->state_change_timestamp;
else if (!UNIT_IS_INACTIVE_OR_FAILED(os) && UNIT_IS_INACTIVE_OR_FAILED(ns))
log_warning("sd: u=%s, inactive_exit="USEC_FMT,
u->id, u->inactive_exit_timestamp.monotonic);
}
else if (!UNIT_IS_INACTIVE_OR_FAILED(os) && UNIT_IS_INACTIVE_OR_FAILED(ns)) {
u->inactive_enter_timestamp = u->state_change_timestamp;
log_warning("sd: u=%s, inactive_enter="USEC_FMT,
u->id, u->inactive_enter_timestamp.monotonic);
}

if (!UNIT_IS_ACTIVE_OR_RELOADING(os) && UNIT_IS_ACTIVE_OR_RELOADING(ns))
if (!UNIT_IS_ACTIVE_OR_RELOADING(os) && UNIT_IS_ACTIVE_OR_RELOADING(ns)) {
u->active_enter_timestamp = u->state_change_timestamp;
else if (UNIT_IS_ACTIVE_OR_RELOADING(os) && !UNIT_IS_ACTIVE_OR_RELOADING(ns))
log_warning("sd: u=%s, active_enter="USEC_FMT,
u->id, u->active_enter_timestamp.monotonic);
if (unit_has_name(u, SPECIAL_BASIC_TARGET)) {
log_warning("sd: status changed: STARTING, t="USEC_FMT,
u->active_enter_timestamp.monotonic);
}
}
else if (UNIT_IS_ACTIVE_OR_RELOADING(os) && !UNIT_IS_ACTIVE_OR_RELOADING(ns)) {
u->active_exit_timestamp = u->state_change_timestamp;
log_warning("sd: u=%s, active_exit="USEC_FMT,
u->id, u->active_exit_timestamp.monotonic);
}
}

/* Keep track of failed units */
Expand Down