]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/libsystemd-terminal/subterm.c
treewide: use log_*_errno whenever %m is in the format string
[thirdparty/systemd.git] / src / libsystemd-terminal / subterm.c
index ef112d4014a9c262754a3e0c81baab469740a8af..f2651b24ac3759a148a3d623ad7bc3b1b8c56f0d 100644 (file)
@@ -103,7 +103,7 @@ static int output_winch(Output *o) {
 
         r = ioctl(o->fd, TIOCGWINSZ, &wsz);
         if (r < 0) {
-                log_error("error: cannot read window-size: %m");
+                log_error_errno(errno, "error: cannot read window-size: %m");
                 return -errno;
         }
 
@@ -125,10 +125,8 @@ static int output_flush(Output *o) {
                 return 0;
 
         len = loop_write(o->fd, o->obuf, o->n_obuf, false);
-        if (len < 0) {
-                log_error_errno(-len, "error: cannot write to TTY (%zd): %m", len);
-                return len;
-        }
+        if (len < 0)
+                return log_error_errno(len, "error: cannot write to TTY (%zd): %m", len);
 
         o->n_obuf = 0;
 
@@ -156,10 +154,8 @@ static int output_write(Output *o, const void *buf, size_t size) {
                 return r;
 
         len = loop_write(o->fd, buf, size, false);
-        if (len < 0) {
-                log_error_errno(-len, "error: cannot write to TTY (%zd): %m", len);
-                return len;
-        }
+        if (len < 0)
+                return log_error_errno(len, "error: cannot write to TTY (%zd): %m", len);
 
         return 0;
 }
@@ -612,12 +608,12 @@ static int terminal_winch_fn(sd_event_source *source, const struct signalfd_sigi
         if (t->pty) {
                 r = pty_resize(t->pty, t->output->in_width, t->output->in_height);
                 if (r < 0)
-                        log_error_errno(-r, "error: pty_resize() (%d): %m", r);
+                        log_error_errno(r, "error: pty_resize() (%d): %m", r);
         }
 
         r = term_screen_resize(t->screen, t->output->in_width, t->output->in_height);
         if (r < 0)
-                log_error_errno(-r, "error: term_screen_resize() (%d): %m", r);
+                log_error_errno(r, "error: term_screen_resize() (%d): %m", r);
 
         terminal_dirty(t);
 
@@ -656,10 +652,8 @@ static int terminal_write_tmp(Terminal *t) {
         if (t->pty) {
                 for (i = 0; i < num; ++i) {
                         r = pty_write(t->pty, vec[i].iov_base, vec[i].iov_len);
-                        if (r < 0) {
-                                log_error_errno(-r, "error: cannot write to PTY (%d): %m", r);
-                                return r;
-                        }
+                        if (r < 0)
+                                return log_error_errno(r, "error: cannot write to PTY (%d): %m", r);
                 }
         }
 
@@ -713,7 +707,7 @@ static int terminal_io_fn(sd_event_source *source, int fd, uint32_t revents, voi
                 if (errno == EAGAIN || errno == EINTR)
                         return 0;
 
-                log_error("error: cannot read from TTY (%d): %m", -errno);
+                log_error_errno(errno, "error: cannot read from TTY (%d): %m", -errno);
                 return -errno;
         }
 
@@ -725,10 +719,8 @@ static int terminal_io_fn(sd_event_source *source, int fd, uint32_t revents, voi
                 n_str = term_utf8_decode(&t->utf8, &str, buf[i]);
                 for (j = 0; j < n_str; ++j) {
                         type = term_parser_feed(t->parser, &seq, str[j]);
-                        if (type < 0) {
-                                log_error_errno(-type, "error: term_parser_feed() (%d): %m", type);
-                                return type;
-                        }
+                        if (type < 0)
+                                return log_error_errno(type, "error: term_parser_feed() (%d): %m", type);
 
                         if (!t->is_menu) {
                                 r = terminal_push_tmp(t, str[j]);
@@ -777,10 +769,8 @@ static int terminal_pty_fn(Pty *pty, void *userdata, unsigned int event, const v
                 break;
         case PTY_DATA:
                 r = term_screen_feed_text(t->screen, ptr, size);
-                if (r < 0) {
-                        log_error_errno(-r, "error: term_screen_feed_text() (%d): %m", r);
-                        return r;
-                }
+                if (r < 0)
+                        return log_error_errno(r, "error: term_screen_feed_text() (%d): %m", r);
 
                 terminal_dirty(t);
                 break;
@@ -833,13 +823,13 @@ static int terminal_new(Terminal **out, int in_fd, int out_fd) {
 
         r = tcgetattr(in_fd, &in_attr);
         if (r < 0) {
-                log_error("error: tcgetattr() (%d): %m", -errno);
+                log_error_errno(errno, "error: tcgetattr() (%d): %m", -errno);
                 return -errno;
         }
 
         r = tcgetattr(out_fd, &out_attr);
         if (r < 0) {
-                log_error("error: tcgetattr() (%d): %m", -errno);
+                log_error_errno(errno, "error: tcgetattr() (%d): %m", -errno);
                 return -errno;
         }
 
@@ -857,49 +847,49 @@ static int terminal_new(Terminal **out, int in_fd, int out_fd) {
 
         r = tcsetattr(t->in_fd, TCSANOW, &in_attr);
         if (r < 0) {
-                log_error_errno(-r, "error: tcsetattr() (%d): %m", r);
+                log_error_errno(r, "error: tcsetattr() (%d): %m", r);
                 goto error;
         }
 
         r = tcsetattr(t->out_fd, TCSANOW, &out_attr);
         if (r < 0) {
-                log_error_errno(-r, "error: tcsetattr() (%d): %m", r);
+                log_error_errno(r, "error: tcsetattr() (%d): %m", r);
                 goto error;
         }
 
         r = sd_event_default(&t->event);
         if (r < 0) {
-                log_error_errno(-r, "error: sd_event_default() (%d): %m", r);
+                log_error_errno(r, "error: sd_event_default() (%d): %m", r);
                 goto error;
         }
 
         r = sigprocmask_many(SIG_BLOCK, SIGINT, SIGQUIT, SIGTERM, SIGWINCH, SIGCHLD, -1);
         if (r < 0) {
-                log_error_errno(-r, "error: sigprocmask_many() (%d): %m", r);
+                log_error_errno(r, "error: sigprocmask_many() (%d): %m", r);
                 goto error;
         }
 
         r = sd_event_add_signal(t->event, NULL, SIGINT, NULL, NULL);
         if (r < 0) {
-                log_error_errno(-r, "error: sd_event_add_signal() (%d): %m", r);
+                log_error_errno(r, "error: sd_event_add_signal() (%d): %m", r);
                 goto error;
         }
 
         r = sd_event_add_signal(t->event, NULL, SIGQUIT, NULL, NULL);
         if (r < 0) {
-                log_error_errno(-r, "error: sd_event_add_signal() (%d): %m", r);
+                log_error_errno(r, "error: sd_event_add_signal() (%d): %m", r);
                 goto error;
         }
 
         r = sd_event_add_signal(t->event, NULL, SIGTERM, NULL, NULL);
         if (r < 0) {
-                log_error_errno(-r, "error: sd_event_add_signal() (%d): %m", r);
+                log_error_errno(r, "error: sd_event_add_signal() (%d): %m", r);
                 goto error;
         }
 
         r = sd_event_add_signal(t->event, NULL, SIGWINCH, terminal_winch_fn, t);
         if (r < 0) {
-                log_error_errno(-r, "error: sd_event_add_signal() (%d): %m", r);
+                log_error_errno(r, "error: sd_event_add_signal() (%d): %m", r);
                 goto error;
         }
 
@@ -907,7 +897,7 @@ static int terminal_new(Terminal **out, int in_fd, int out_fd) {
         t->is_dirty = true;
         r = sd_event_add_time(t->event, &t->frame_timer, CLOCK_MONOTONIC, 0, 0, terminal_frame_timer_fn, t);
         if (r < 0) {
-                log_error_errno(-r, "error: sd_event_add_time() (%d): %m", r);
+                log_error_errno(r, "error: sd_event_add_time() (%d): %m", r);
                 goto error;
         }
 
@@ -929,7 +919,7 @@ static int terminal_new(Terminal **out, int in_fd, int out_fd) {
 
         r = term_screen_resize(t->screen, t->output->in_width, t->output->in_height);
         if (r < 0) {
-                log_error_errno(-r, "error: term_screen_resize() (%d): %m", r);
+                log_error_errno(r, "error: term_screen_resize() (%d): %m", r);
                 goto error;
         }
 
@@ -951,10 +941,9 @@ static int terminal_run(Terminal *t) {
         assert_return(t, -EINVAL);
 
         pid = pty_fork(&t->pty, t->event, terminal_pty_fn, t, t->output->in_width, t->output->in_height);
-        if (pid < 0) {
-                log_error_errno(-pid, "error: cannot fork PTY (%d): %m", pid);
-                return pid;
-        } else if (pid == 0) {
+        if (pid < 0)
+                return log_error_errno(pid, "error: cannot fork PTY (%d): %m", pid);
+        else if (pid == 0) {
                 /* child */
 
                 char **argv = (char*[]){
@@ -966,7 +955,7 @@ static int terminal_run(Terminal *t) {
                 setenv("COLORTERM", "systemd-subterm", 1);
 
                 execve(argv[0], argv, environ);
-                log_error("error: cannot exec %s (%d): %m", argv[0], -errno);
+                log_error_errno(errno, "error: cannot exec %s (%d): %m", argv[0], -errno);
                 _exit(1);
         }
 
@@ -993,7 +982,7 @@ int main(int argc, char *argv[]) {
 
 out:
         if (r < 0)
-                log_error_errno(-r, "error: terminal failed (%d): %m", r);
+                log_error_errno(r, "error: terminal failed (%d): %m", r);
         terminal_free(t);
         return -r;
 }