+static void on_plymouth_disconnect(Manager *m) {
+ 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];
+ int r;
+
+ assert(m);
+
+ r = read(m->plymouth_fd, buffer, sizeof(buffer));
+ if (r <= 0)
+ on_plymouth_disconnect(m);
+ else {
+ 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;
+
+ plymouth_cancel_message = strjoina("fsckd-cancel-msg:", _("Press Ctrl+C to cancel all filesystem checks in progress"));
+
+ r = send_message_plymouth_socket(m->plymouth_fd, plymouth_cancel_message, false);
+ if (r < 0)
+ log_warning_errno(r, "Can't send filesystem cancel message to plymouth: %m");
+
+ } else if (m->numdevices == 0) {
+
+ m->plymouth_cancel_sent = false;
+
+ r = send_message_plymouth_socket(m->plymouth_fd, "", false);
+ if (r < 0)
+ log_warning_errno(r, "Can't clear plymouth filesystem cancel message: %m");
+ }
+
+ r = send_message_plymouth_socket(m->plymouth_fd, message, true);
+ if (r < 0)
+ return log_warning_errno(r, "Couldn't send \"%s\" to plymouth: %m", message);
+
+ return 0;
+}
+