+static int request_cancel_client(Client *current) {
+ FsckdMessage cancel_msg = {
+ .cancel = 1,
+ };
+
+ ssize_t n;
+
+ n = send(current->fd, &cancel_msg, sizeof(FsckdMessage), 0);
+ if (n < 0)
+ return log_warning_errno(errno, "Cannot send cancel to fsck on (%u:%u): %m", major(current->devnum), minor(current->devnum));
+ if ((size_t) n < sizeof(FsckdMessage)) {
+ log_warning("Short send when sending cancel to fsck on (%u:%u).", major(current->devnum), minor(current->devnum));
+ return -EIO;
+ }
+
+ current->cancelled = true;
+ return 0;
+}
+
+static void client_free(Client *c) {
+ assert(c);
+
+ if (c->manager)
+ LIST_REMOVE(clients, c->manager->clients, c);
+
+ safe_close(c->fd);
+ free(c);
+}
+
+static void plymouth_disconnect(Manager *m) {
+ assert(m);
+
+ m->plymouth_event_source = sd_event_source_unref(m->plymouth_event_source);
+ m->plymouth_fd = safe_close(m->plymouth_fd);
+ m->plymouth_cancel_sent = false;
+}
+
+static int plymouth_feedback_handler(sd_event_source *s, int fd, uint32_t revents, void *userdata) {
+ Manager *m = userdata;
+ Client *current;
+ char buffer[6];
+ ssize_t l;
+
+ assert(m);
+
+ l = read(m->plymouth_fd, buffer, sizeof(buffer));
+ if (l < 0) {
+ log_warning_errno(errno, "Got error while reading from plymouth: %m");
+ plymouth_disconnect(m);
+ return -errno;
+ }
+ if (l == 0) {
+ plymouth_disconnect(m);
+ return 0;
+ }
+
+ if (buffer[0] == '\15')
+ log_error("Message update to plymouth wasn't delivered successfully");
+
+ /* the only answer support type we requested is a key interruption */
+ if (buffer[0] == '\2' && buffer[5] == '\3') {
+ m->cancel_requested = true;
+
+ /* cancel all connected clients */
+ LIST_FOREACH(clients, current, m->clients)
+ request_cancel_client(current);
+ }
+
+ return 0;
+}
+
+static int send_message_plymouth_socket(int plymouth_fd, const char *message, bool update) {
+ _cleanup_free_ char *packet = NULL;
+ int n;
+ char mode = 'M';
+
+ if (update)
+ mode = 'U';
+
+ if (asprintf(&packet, "%c\002%c%s%n", mode, (int) (strlen(message) + 1), message, &n) < 0)
+ return log_oom();
+
+ return loop_write(plymouth_fd, packet, n + 1, true);
+}
+
+static int send_message_plymouth(Manager *m, const char *message) {
+ const char *plymouth_cancel_message = NULL;
+ int r;
+
+ r = connect_plymouth(m);
+ if (r < 0)
+ return r;
+
+ if (!m->plymouth_cancel_sent) {
+
+ /* Indicate to plymouth that we listen to Ctrl+C */
+ r = loop_write(m->plymouth_fd, PLYMOUTH_REQUEST_KEY, sizeof(PLYMOUTH_REQUEST_KEY), true);
+ if (r < 0)
+ return log_warning_errno(r, "Can't send to plymouth cancel key: %m");
+
+ m->plymouth_cancel_sent = true;