Skip to content

Commit

Permalink
Merge pull request systemd#29156 from bluca/signal_dump_jobs
Browse files Browse the repository at this point in the history
core: dump jobs list on sigrtmin+18 with 0x500
  • Loading branch information
bluca committed Sep 11, 2023
2 parents f96a32c + 0112c37 commit 93f42f0
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 20 deletions.
45 changes: 25 additions & 20 deletions src/core/execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -5236,29 +5236,34 @@ int exec_spawn(Unit *unit,
void exec_context_init(ExecContext *c) {
assert(c);

c->umask = 0022;
c->ioprio = IOPRIO_DEFAULT_CLASS_AND_PRIO;
c->cpu_sched_policy = SCHED_OTHER;
c->syslog_priority = LOG_DAEMON|LOG_INFO;
c->syslog_level_prefix = true;
c->ignore_sigpipe = true;
c->timer_slack_nsec = NSEC_INFINITY;
c->personality = PERSONALITY_INVALID;
for (ExecDirectoryType t = 0; t < _EXEC_DIRECTORY_TYPE_MAX; t++)
c->directories[t].mode = 0755;
c->timeout_clean_usec = USEC_INFINITY;
c->capability_bounding_set = CAP_MASK_UNSET;
assert_cc(NAMESPACE_FLAGS_INITIAL != NAMESPACE_FLAGS_ALL);
c->restrict_namespaces = NAMESPACE_FLAGS_INITIAL;
c->log_level_max = -1;
*c = (ExecContext) {
.umask = 0022,
.ioprio = IOPRIO_DEFAULT_CLASS_AND_PRIO,
.cpu_sched_policy = SCHED_OTHER,
.syslog_priority = LOG_DAEMON|LOG_INFO,
.syslog_level_prefix = true,
.ignore_sigpipe = true,
.timer_slack_nsec = NSEC_INFINITY,
.personality = PERSONALITY_INVALID,
.timeout_clean_usec = USEC_INFINITY,
.capability_bounding_set = CAP_MASK_UNSET,
.restrict_namespaces = NAMESPACE_FLAGS_INITIAL,
.log_level_max = -1,
#if HAVE_SECCOMP
c->syscall_errno = SECCOMP_ERROR_NUMBER_KILL;
.syscall_errno = SECCOMP_ERROR_NUMBER_KILL,
#endif
c->tty_rows = UINT_MAX;
c->tty_cols = UINT_MAX;
.tty_rows = UINT_MAX,
.tty_cols = UINT_MAX,
.private_mounts = -1,
.memory_ksm = -1,
};

for (ExecDirectoryType t = 0; t < _EXEC_DIRECTORY_TYPE_MAX; t++)
c->directories[t].mode = 0755;

numa_policy_reset(&c->numa_policy);
c->private_mounts = -1;
c->memory_ksm = -1;

assert_cc(NAMESPACE_FLAGS_INITIAL != NAMESPACE_FLAGS_ALL);
}

void exec_context_done(ExecContext *c) {
Expand Down
16 changes: 16 additions & 0 deletions src/core/manager-dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,22 @@ void manager_dump_jobs(Manager *s, FILE *f, char **patterns, const char *prefix)
}
}

int manager_get_dump_jobs_string(Manager *m, char **patterns, const char *prefix, char **ret) {
_cleanup_(memstream_done) MemStream ms = {};
FILE *f;

assert(m);
assert(ret);

f = memstream_init(&ms);
if (!f)
return -errno;

manager_dump_jobs(m, f, patterns, prefix);

return memstream_finalize(&ms, ret, NULL);
}

void manager_dump_units(Manager *s, FILE *f, char **patterns, const char *prefix) {
Unit *u;
const char *t;
Expand Down
1 change: 1 addition & 0 deletions src/core/manager-dump.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "manager.h"

void manager_dump_jobs(Manager *s, FILE *f, char **patterns, const char *prefix);
int manager_get_dump_jobs_string(Manager *m, char **patterns, const char *prefix, char **ret);
void manager_dump_units(Manager *s, FILE *f, char **patterns, const char *prefix);
void manager_dump(Manager *s, FILE *f, char **patterns, const char *prefix);
int manager_get_dump_string(Manager *m, char **patterns, char **ret);
Expand Down
13 changes: 13 additions & 0 deletions src/core/manager.c
Original file line number Diff line number Diff line change
Expand Up @@ -3030,6 +3030,19 @@ static int manager_dispatch_signal_fd(sd_event_source *source, int fd, uint32_t
manager_override_log_target(m, LOG_TARGET_NULL);
break;

case MANAGER_SIGNAL_COMMAND_DUMP_JOBS: {
_cleanup_free_ char *dump_jobs = NULL;

r = manager_get_dump_jobs_string(m, /* patterns= */ NULL, " ", &dump_jobs);
if (r < 0) {
log_warning_errno(errno, "Failed to acquire manager jobs dump: %m");
break;
}

log_dump(LOG_INFO, dump_jobs);
break;
}

default:
generic = true;
}
Expand Down
9 changes: 9 additions & 0 deletions src/core/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "sd-device.h"
#include "sd-event.h"

#include "common-signal.h"
#include "cgroup-util.h"
#include "cgroup.h"
#include "fdset.h"
Expand All @@ -23,6 +24,14 @@ typedef struct Unit Unit;
/* Enforce upper limit how many names we allow */
#define MANAGER_MAX_NAMES 131072 /* 128K */

/* On sigrtmin+18, private commands */
enum {
MANAGER_SIGNAL_COMMAND_DUMP_JOBS = _COMMON_SIGNAL_COMMAND_PRIVATE_BASE + 0,
_MANAGER_SIGNAL_COMMAND_MAX,
};

assert_cc((int) _MANAGER_SIGNAL_COMMAND_MAX <= (int) _COMMON_SIGNAL_COMMAND_PRIVATE_END);

typedef struct Manager Manager;

/* An externally visible state. We don't actually maintain this as state variable, but derive it from various fields
Expand Down
5 changes: 5 additions & 0 deletions src/shared/common-signal.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
#pragma once

#include <syslog.h>

Expand Down Expand Up @@ -48,6 +49,10 @@ enum {

COMMON_SIGNAL_COMMAND_MEMORY_PRESSURE = 0x300,
COMMON_SIGNAL_COMMAND_MALLOC_INFO,

/* Private signals start at 0x500 */
_COMMON_SIGNAL_COMMAND_PRIVATE_BASE = 0x500,
_COMMON_SIGNAL_COMMAND_PRIVATE_END = 0xfff,
};

struct sigrtmin18_info {
Expand Down

0 comments on commit 93f42f0

Please sign in to comment.