[systemd-devel] [PATCH 1/2] ptyfwd: Set the size of the PTY base on the size of stdout, not stdin.
--- src/shared/ptyfwd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/shared/ptyfwd.c b/src/shared/ptyfwd.c index 7225b93..85a0ddc 100644 --- a/src/shared/ptyfwd.c +++ b/src/shared/ptyfwd.c @@ -305,7 +305,7 @@ static int process_pty_loop(int master, sigset_t *mask, pid_t kill_pid, int sign struct winsize ws; /* The window size changed, let's forward that. */ -if (ioctl(STDIN_FILENO, TIOCGWINSZ, ws) = 0) +if (ioctl(STDOUT_FILENO, TIOCGWINSZ, ws) = 0) ioctl(master, TIOCSWINSZ, ws); } else if (sfsi.ssi_signo == SIGTERM kill_pid 0 signo 0 !tried_orderly_shutdown) { @@ -346,7 +346,7 @@ int process_pty(int master, sigset_t *mask, pid_t kill_pid, int signo) { struct winsize ws; int r; -if (ioctl(STDIN_FILENO, TIOCGWINSZ, ws) = 0) +if (ioctl(STDOUT_FILENO, TIOCGWINSZ, ws) = 0) ioctl(master, TIOCSWINSZ, ws); if (tcgetattr(STDIN_FILENO, saved_attr) = 0) { -- 1.8.4.2 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] nspawn (ptyfwd): Correctly handle output redirection
At Tue, 5 Nov 2013 19:59:46 +0100, Lennart Poettering wrote: On Mon, 04.11.13 11:05, Luke T. Shumaker (luke...@sbcglobal.net) wrote: A couple of weeks ago, I reported a bug that systemd-nspawn does not correctly handle I/O redirection[1]. I described in detail the several smaller bugs that lead up to both stdin and stdout redirection being broken, and uploaded a patch that fixes stdout redirection. That patch is attached here. Stdin redirection is more involved to fix. Hmm, can you rebase on current git please? Sorry it took so long, I've been unable to devote much time to this. Happy hacking, ~ Luke Shumaker ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 2/2] ptyfwd: Don't set the output prop of stdin, nor the input props of stdout.
It was calling cfmakeraw(3) on the properties for STDIN_FILENO; cfmakeraw sets both input and output properties. If (and only if) stdin and stdout are the same device is this correct. Otherwise, we must change only the input properties of stdin, and only the output properties of stdout. --- src/shared/ptyfwd.c | 35 +++ 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/shared/ptyfwd.c b/src/shared/ptyfwd.c index 85a0ddc..72aa59e 100644 --- a/src/shared/ptyfwd.c +++ b/src/shared/ptyfwd.c @@ -341,29 +341,40 @@ static int process_pty_loop(int master, sigset_t *mask, pid_t kill_pid, int sign } int process_pty(int master, sigset_t *mask, pid_t kill_pid, int signo) { -struct termios saved_attr; -bool saved = false; +struct termios saved_stdin_attr, raw_stdin_attr; +struct termios saved_stdout_attr, raw_stdout_attr; +bool saved_stdin = false; +bool saved_stdout = false; struct winsize ws; int r; if (ioctl(STDOUT_FILENO, TIOCGWINSZ, ws) = 0) ioctl(master, TIOCSWINSZ, ws); -if (tcgetattr(STDIN_FILENO, saved_attr) = 0) { -struct termios raw_attr; -saved = true; +if (tcgetattr(STDIN_FILENO, saved_stdin_attr) = 0) { +saved_stdin = true; -raw_attr = saved_attr; -cfmakeraw(raw_attr); -raw_attr.c_lflag = ~ECHO; - -tcsetattr(STDIN_FILENO, TCSANOW, raw_attr); +raw_stdin_attr = saved_stdin_attr; +cfmakeraw(raw_stdin_attr); +raw_stdin_attr.c_oflag = saved_stdin_attr.c_oflag; +tcsetattr(STDIN_FILENO, TCSANOW, raw_stdin_attr); +} +if (tcgetattr(STDOUT_FILENO, saved_stdout_attr) = 0) { +saved_stdout = true; + +raw_stdout_attr = saved_stdout_attr; +cfmakeraw(raw_stdout_attr); +raw_stdout_attr.c_iflag = saved_stdout_attr.c_iflag; +raw_stdout_attr.c_lflag = saved_stdout_attr.c_lflag; +tcsetattr(STDOUT_FILENO, TCSANOW, raw_stdout_attr); } r = process_pty_loop(master, mask, kill_pid, signo); -if (saved) -tcsetattr(STDIN_FILENO, TCSANOW, saved_attr); +if (saved_stdout) +tcsetattr(STDOUT_FILENO, TCSANOW, saved_stdout_attr); +if (saved_stdin) +tcsetattr(STDIN_FILENO, TCSANOW, saved_stdin_attr); return r; -- 1.8.4.2 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
Re: [systemd-devel] Restart instantiated services after suspend
2013/11/20 Lennart Poettering lenn...@poettering.net: On Tue, 19.11.13 14:18, Marcos Felipe Rasia de Mello (marcos...@gmail.com) wrote: Hi folks, I am trying to disable HDDs power management in a systemd way (aka no shell scripts :) /etc/udev/rules.d/99-hdparm.rules SUBSYSTEM==block, KERNEL==sd*, ATTR{removable}==0, TAG+=systemd, ENV{SYSTEMD_WANTS}+=hdparm@%k.service Why do you do this asyncrhonously via a systemd service? Given that this tool runs and terminates quickly invokign this with RUN inside of the udev rule itself sounds like the best approach. If suspend/resume did not reset HDD power setting, sure, better run hdparm directly from the udev rule. My initial idea was rerun hdparm@ transient units after suspend with something like what you have suggested: mkdir /etc/systemd/system/sleep.target.wants ln -s /etc/systemd/system/hdparm@.service /etc/systemd/system/sleep.target.wants/ but it did not work so here I am. :) It works fine, but after the machine wakes up from suspend, I need that all hdparm@.service be run again. Is there a way to accomplish this? Well, you could drop in a service into sleep.target.wants/ which orders itself after systemd-suspend.service... ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 1/2] systemctl: refactor show()
v2, don't leave in unused function --- src/systemctl/systemctl.c | 36 +--- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 84826a3..6cb7a82 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -3594,16 +3594,13 @@ static int show_one( return r; } -static int show_one_by_pid( -const char *verb, +static int get_unit_dbus_path_by_pid( sd_bus *bus, uint32_t pid, -bool *new_line, -bool *ellipsized) { +char **unit) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; _cleanup_bus_message_unref_ sd_bus_message *reply = NULL; -const char *path = NULL; int r; r = sd_bus_call_method( @@ -3620,11 +3617,11 @@ static int show_one_by_pid( return r; } -r = sd_bus_message_read(reply, o, path); +r = sd_bus_message_read(reply, o, unit); if (r 0) return bus_log_parse_error(r); -return show_one(verb, bus, path, false, new_line, ellipsized); +return 0; } static int show_all( @@ -3692,41 +3689,34 @@ static int show(sd_bus *bus, char **args) { ret = show_all(args[0], bus, false, new_line, ellipsized); else STRV_FOREACH(name, args+1) { +_cleanup_free_ char *unit = NULL; uint32_t id; if (safe_atou32(*name, id) 0) { -_cleanup_free_ char *p = NULL, *n = NULL; +_cleanup_free_ char *n = NULL; /* Interpret as unit name */ n = unit_name_mangle(*name); if (!n) return log_oom(); -p = unit_dbus_path_from_name(n); -if (!p) +unit = unit_dbus_path_from_name(n); +if (!unit) return log_oom(); -r = show_one(args[0], bus, p, show_properties, new_line, ellipsized); -if (r != 0) -ret = r; - } else if (show_properties) { -_cleanup_free_ char *p = NULL; - /* Interpret as job id */ -if (asprintf(p, /org/freedesktop/systemd1/job/%u, id) 0) +if (asprintf(unit, /org/freedesktop/systemd1/job/%u, id) 0) return log_oom(); -r = show_one(args[0], bus, p, show_properties, new_line, ellipsized); -if (r != 0) -ret = r; - } else { /* Interpret as PID */ -r = show_one_by_pid(args[0], bus, id, new_line, ellipsized); -if (r != 0) +r = get_unit_dbus_path_by_pid(bus, id, unit); +if (r 0) ret = r; } + +show_one(args[0], bus, unit, show_properties, new_line, ellipsized); } if (ellipsized !arg_quiet) -- 1.8.4.4 ___ systemd-devel mailing list systemd-devel@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/systemd-devel
[systemd-devel] [PATCH 2/2] systemctl: add systemctl cat
--- TODO | 2 -- src/shared/fileio.c | 73 - src/shared/fileio.h | 1 + src/systemctl/systemctl.c | 91 +++ 4 files changed, 164 insertions(+), 3 deletions(-) diff --git a/TODO b/TODO index 6ba4b31..7c6003b 100644 --- a/TODO +++ b/TODO @@ -125,8 +125,6 @@ Features: * optimize the cgroup propagation bits, especially unit_get_members_mask(), cgroup_context_get_mask() -* systemctl cat or systemctl view command or or so, that cats the backing unit file of a service, plus its drop-ins and shows them in a pager - * rfkill,backlight: we probably should run the load tools inside of the udev rules so that the state is properly initialized by the time other software sees it * tmpfiles: when applying ownership to /run/log/journal, also do this for the journal fails contained in it diff --git a/src/shared/fileio.c b/src/shared/fileio.c index 733b320..ac1b409 100644 --- a/src/shared/fileio.c +++ b/src/shared/fileio.c @@ -20,6 +20,7 @@ ***/ #include unistd.h +#include sys/sendfile.h #include fileio.h #include util.h #include strv.h @@ -117,6 +118,77 @@ int read_one_line_file(const char *fn, char **line) { return 0; } +ssize_t sendfile_full(int out_fd, const char *fn) { +_cleanup_fclose_ FILE *f; +struct stat st; +int r; +ssize_t s; + +size_t n, l; +_cleanup_free_ char *buf = NULL; + +assert(out_fd 0); +assert(fn); + +f = fopen(fn, r); +if (!f) +return -errno; + +r = fstat(fileno(f), st); +if (r 0) +return -errno; + +s = sendfile(out_fd, fileno(f), NULL, st.st_size); +if (s 0) +if (errno == EINVAL || errno == ENOSYS) { +/* continue below */ +} else +return -errno; +else +return s; + +/* sendfile() failed, fall back to read/write */ + +/* Safety check */ +if (st.st_size 4*1024*1024) +return -E2BIG; + +n = st.st_size 0 ? st.st_size : LINE_MAX; +l = 0; + +while (true) { +char *t; +size_t k; + +t = realloc(buf, n); +if (!t) +return -ENOMEM; + +buf = t; +k = fread(buf + l, 1, n - l, f); + +if (k = 0) { +if (ferror(f)) +return -errno; + +break; +} + +l += k; +n *= 2; + +/* Safety check */ +if (n 4*1024*1024) +return -E2BIG; +} + +r = write(out_fd, buf, l); +if (r 0) +return -errno; + +return (ssize_t) l; +} + int read_full_file(const char *fn, char **contents, size_t *size) { _cleanup_fclose_ FILE *f = NULL; size_t n, l; @@ -168,7 +240,6 @@ int read_full_file(const char *fn, char **contents, size_t *size) { buf[l] = 0; *contents = buf; -buf = NULL; if (size) *size = l; diff --git a/src/shared/fileio.h b/src/shared/fileio.h index 59e4150..06c2887 100644 --- a/src/shared/fileio.h +++ b/src/shared/fileio.h @@ -31,6 +31,7 @@ int write_string_file_atomic(const char *fn, const char *line); int read_one_line_file(const char *fn, char **line); int read_full_file(const char *fn, char **contents, size_t *size); +ssize_t sendfile_full(int out_fd, const char *fn); int parse_env_file(const char *fname, const char *separator, ...) _sentinel_; int load_env_file(const char *fname, const char *separator, char ***l); diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c index 6cb7a82..18d5e45 100644 --- a/src/systemctl/systemctl.c +++ b/src/systemctl/systemctl.c @@ -3665,6 +3665,95 @@ static int show_all( return 0; } +static int cat(sd_bus *bus, char **args) { +int r = 0; +char **name; + +_cleanup_free_ char *unit = NULL, *n = NULL; + +assert(bus); +assert(args); + +pager_open_if_enabled(); + +STRV_FOREACH(name, args+1) { +_cleanup_free_ char *fragment_path = NULL; +_cleanup_strv_free_ char **dropin_paths = NULL; +sd_bus_error error; +FILE *stdout; +char **path; + +n = unit_name_mangle(*name); +if (!n) +return log_oom(); + +unit = unit_dbus_path_from_name(n); +if (!unit) +return log_oom(); + +if (need_daemon_reload(bus, n)) { +log_error(Unit file of %s changed on disk. Run 'systemctl%s daemon-reload'., +