Skip to contentSkip to conversation

Use the plymouth local protocol instead the plymouth binary

PATCH In review Werner Fink 2 participants 5 messages Apr 22, 2016 – May 20, 2016 Util-Linux package

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Use the plymouth local protocol instead the plymouth binary

for stopping plymouthd. That do not depend on the existence of the plymouth binary if it e.g. becomes uninstalled or an other service is providing plymouthd facilities.

---
 include/plymouth-ctrl.h |  64 ++++++++++++++++++++++
 lib/Makemodule.am       |   1 +
 lib/plymouth-ctrl.c     | 140 ++++++++++++++++++++++++++++++++++++++++++++++++
 login-utils/sulogin.c   |  44 ++-------------
 term-utils/agetty.c     |  48 +++--------------
 5 files changed, 215 insertions(+), 82 deletions(-)
 create mode 100644 include/plymouth-ctrl.h
 create mode 100644 lib/plymouth-ctrl.c
plymouth-ctrl.h new file +64 -0
new file mode 100644
index 0000000..27c5ebc
@@ -0,0 +1,64 @@
+/*
+ * plymouth-ctrl.h	Header file for communcations with plymouthd
+ *
+ * Copyright (c) 2016 SUSE Linux GmbH, All rights reserved.
+ * Copyright (c) 2016 Werner Fink <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *  
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * Author: Werner Fink <[email protected]>
+ */
+
+/*
+ * Taken from plymouth 0.9.0 src/ply-boot-protocol.h
+ */
+
+#ifndef UTIL_LINUX_PLYMOUTH_CTRL_H
+#define UTIL_LINUX_PLYMOUTH_CTRL_H
+
+#define PLYMOUTH_SOCKET_PATH	"\0/org/freedesktop/plymouthd"
+#define ANSWER_TYP		'\x2'
+#define ANSWER_ENQ		'\x5'
+#define ANSWER_ACK		'\x6'
+#define ANSWER_MLT		'\t'
+#define ANSWER_NCK		'\x15'
+
+#define MAGIC_PRG_STOP		'A'
+#define MAGIC_PRG_CONT		'a'
+#define MAGIC_UPDATE		'U'
+#define MAGIC_SYS_UPDATE	'u'
+#define MAGIC_SYS_INIT		'S'
+#define MAGIC_DEACTIVATE	'D'
+#define MAGIC_REACTIVATE	'r'
+#define MAGIC_SHOW_SPLASH	'$'
+#define MAGIC_HIDE_SPLASH	'H'
+#define MAGIC_CHMOD		'C'
+#define MAGIC_CHROOT		'R'
+#define MAGIC_ACTIVE_VT		'V'
+#define MAGIC_QUESTION		'W'
+#define MAGIC_SHOW_MSG		'M'
+#define MAGIC_HIDE_MSG		'm'
+#define MAGIC_KEYSTROKE		'K'
+#define MAGIC_KEYSTROKE_RM	'L'
+#define MAGIC_PING		'P'
+#define MAGIC_QUIT		'Q'
+#define MAGIC_CACHED_PWD	'c'
+#define MAGIC_ASK_PWD		'*'
+#define MAGIC_DETAILS		'!'
+
+extern int plymouth_command(int cmd, ...);
+
+#endif /* UTIL_LINUX_PLYMOUTH_CTRL_H */
Makemodule.am +1 -0
index 054b816..cbf5cee 100644
@@ -16,6 +16,7 @@ libcommon_la_SOURCES = \
 	lib/md5.c \
 	lib/pager.c \
 	lib/path.c \
+	lib/plymouth-ctrl.c \
 	lib/randutils.c \
 	lib/setproctitle.c \
 	lib/strutils.c \
plymouth-ctrl.c new file +140 -0

140 lines not on this page · raw message

sulogin.c +4 -40

68 lines not on this page · raw message

agetty.c +6 -42

91 lines not on this page · raw message

Signature · 1 line
2.6.6
maintainer
#1 lore raw
Quoted 14 lines · Werner Fink
plymouth-ctrl.c new file +14 -0
+static int open_un_socket_and_connect(void)
+{
+	struct sockaddr_un su = {		/* The abstract UNIX socket of plymouth */
+		.sun_family = AF_UNIX,
+		.sun_path = PLYMOUTH_SOCKET_PATH,
+	};
+	const int one = 1;
+	int fd, ret;
+
+	fd = socket(PF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
+	if (fd < 0) {
+		warnx(_("can not open UNIX socket"));
+		goto err;
+	}

plymouth-ctrl.c line 84

Quoted 10 lines
plymouth-ctrl.c new file +10 -0
+
+	ret = setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &one, (socklen_t)sizeof(one));
+	if (ret < 0) {
+		warnx(_("can not set option for UNIX socket"));
+		close(fd);
+		fd = -1;
+		goto err;
+	}
+
+	ret = connect(fd, &su, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(su.sun_path+1));
                                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^

Review

Quoted 1 line
(quoted diff) +1 -0
+	if (ret < 0) {

This is strange code, connect() returns -1 on error, I have doubts you will ever see ret < 0 and why connect() return value is not enough, why we need 1 + strlen(su.sun_path+1))?

Quoted 17 lines
plymouth-ctrl.c new file +17 -0
+		if (errno != ECONNREFUSED)
+			warnx(_("can not connect on UNIX socket"));
+		close(fd);
+		fd = -1;
+		goto err;
+	}
+err:
+	return fd;
+}
+
+int plymouth_command(int cmd, ...)
+{
+	char answer[2], command[2];
+	struct sigaction sp, op;
+	int fdsock = -1, ret = 0;
+
+	sigemptyset (&sp.sa_mask);

plymouth-ctrl.c line 112

Quoted 10 lines
plymouth-ctrl.c new file +10 -0
+	sp.sa_handler = SIG_IGN;
+	sp.sa_flags = SA_RESTART;
+	sigaction(SIGPIPE, &sp, &op);
+
+	command[1] = '\0';
+	switch (cmd) {
+	case MAGIC_PING:
+		fdsock = open_un_socket_and_connect();
+		if (fdsock >= 0) {
+			command[0] = cmd;

maybe define cmd as char or uint8_t

Review

Quoted 1 line
(quoted diff) +1 -0
+			write_all(fdsock, command, strlen(command)+1);

why we need strlen(command)+1 everywhere if the commend is just one char+\0, sizeof(command) would be enough.

Quoted 26 lines
plymouth-ctrl.c new file +26 -0
+		}
+		break;
+	case MAGIC_QUIT:
+		fdsock = open_un_socket_and_connect();
+		if (fdsock >= 0) {
+			command[0] = cmd;
+			write_all(fdsock, command, strlen(command)+1);
+		}
+		break;
+	default:
+		warnx(_("the plymouth request %c is not implemented"), cmd);
+	case '?':
+		goto err;
+	}
+
+	answer[0] = '\0';
+	if (fdsock >= 0) {
+		if (can_read(fdsock, 1000))
+			read_all(fdsock, &answer[0], sizeof(answer));
+		close(fdsock);
+	}
+	sigaction(SIGPIPE, &op, NULL);
+	ret = (answer[0] == ANSWER_ACK) ? 1 : 0;
+err:
+	return ret;
+}

...

sulogin.c static void tcinit(struct console *con) · line 108

Quoted 12 lines

/*
* Fix the tty modes and set reasonable defaults. */

sulogin.c +3 -2
@@ -138,8 +103,9 @@ static void tcinit(struct console *con)
 	struct termios lock;
 	int fd = con->fd;
 #ifdef TIOCGLCKTRMIOS
-	int i = (plymouth_command("--ping")) ? 20 : 0;
-
+	int i = (plymouth_command(MAGIC_PING)) ? 20 : 0;
+	if (i)
+		plymouth_command(MAGIC_QUIT);

would be possible to #define PLYMOUTH_TERMIOS_FLAGS_DELAY, now we have 20s in sulogins and 30s in agetty. Why?

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com
#2 lore raw
Quoted 26 lines · Karel Zak
Quoted 14 lines · Werner Fink
plymouth-ctrl.c new file +14 -0
+static int open_un_socket_and_connect(void)
+{
+	struct sockaddr_un su = {		/* The abstract UNIX socket of plymouth */
+		.sun_family = AF_UNIX,
+		.sun_path = PLYMOUTH_SOCKET_PATH,
+	};
+	const int one = 1;
+	int fd, ret;
+
+	fd = socket(PF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0);
+	if (fd < 0) {
+		warnx(_("can not open UNIX socket"));
+		goto err;
+	}

plymouth-ctrl.c line 84

Quoted 10 lines
plymouth-ctrl.c new file +10 -0
+
+	ret = setsockopt(fd, SOL_SOCKET, SO_PASSCRED, &one, (socklen_t)sizeof(one));
+	if (ret < 0) {
+		warnx(_("can not set option for UNIX socket"));
+		close(fd);
+		fd = -1;
+		goto err;
+	}
+
+	ret = connect(fd, &su, offsetof(struct sockaddr_un, sun_path) + 1 + strlen(su.sun_path+1));
                                                                  ^^^^^^^^^^^^^^^^^^^^^^^^^
Quoted 5 lines

Review

Quoted 1 line
(quoted diff) +1 -0
+	if (ret < 0) {

This is strange code, connect() returns -1 on error, I have doubts you will ever see ret < 0 and why connect() return value is not enough, why we need 1 + strlen(su.sun_path+1))?

AFAIK and AFAICS the plymouth socket has a leading NULL byte. That is that PLYMOUTH_SOCKET_PATH is defined as "\0/org/freedesktop/plymouthd". If I would not add both +1 the NULL byte would destroy first the result of strlen() as well the NULL byte would not be counted as well.

Quoted 22 lines
Quoted 22 lines
plymouth-ctrl.c new file +21 -0
+		if (errno != ECONNREFUSED)
+			warnx(_("can not connect on UNIX socket"));
+		close(fd);
+		fd = -1;
+		goto err;
+	}
+err:
+	return fd;
+}
+
+int plymouth_command(int cmd, ...)
+{
+	char answer[2], command[2];
+	struct sigaction sp, op;
+	int fdsock = -1, ret = 0;
+
+	sigemptyset (&sp.sa_mask);
+	sp.sa_handler = SIG_IGN;
+	sp.sa_flags = SA_RESTART;
+	sigaction(SIGPIPE, &sp, &op);
+
Quoted 8 lines

plymouth-ctrl.c line 112

Quoted 6 lines
plymouth-ctrl.c new file +6 -0
+	command[1] = '\0';
+	switch (cmd) {
+	case MAGIC_PING:
+		fdsock = open_un_socket_and_connect();
+		if (fdsock >= 0) {
+			command[0] = cmd;

maybe define cmd as char or uint8_t

Yep, but does not hurt I guess.

Quoted 5 lines

Review

Quoted 2 lines
(quoted diff) +1 -0
+			write_all(fdsock, command, strlen(command)+1);

why we need strlen(command)+1 everywhere if the commend is just one char+\0, sizeof(command) would be enough.

It is plymouthd which does require the lasting NULL byte here as the command read by plymouthd has always the size of uint8_t header[2] compare with ply_boot_connection_read_request() in src/ply-boot-server.c

Quoted 30 lines
Quoted 27 lines
plymouth-ctrl.c new file +26 -0
+		}
+		break;
+	case MAGIC_QUIT:
+		fdsock = open_un_socket_and_connect();
+		if (fdsock >= 0) {
+			command[0] = cmd;
+			write_all(fdsock, command, strlen(command)+1);
+		}
+		break;
+	default:
+		warnx(_("the plymouth request %c is not implemented"), cmd);
+	case '?':
+		goto err;
+	}
+
+	answer[0] = '\0';
+	if (fdsock >= 0) {
+		if (can_read(fdsock, 1000))
+			read_all(fdsock, &answer[0], sizeof(answer));
+		close(fdsock);
+	}
+	sigaction(SIGPIPE, &op, NULL);
+	ret = (answer[0] == ANSWER_ACK) ? 1 : 0;
+err:
+	return ret;
+}

...

Quoted 15 lines

sulogin.c static void tcinit(struct console *con) · line 108

Quoted 12 lines

/*
* Fix the tty modes and set reasonable defaults. */

sulogin.c +3 -2
@@ -138,8 +103,9 @@ static void tcinit(struct console *con)
 	struct termios lock;
 	int fd = con->fd;
 #ifdef TIOCGLCKTRMIOS
-	int i = (plymouth_command("--ping")) ? 20 : 0;
-
+	int i = (plymouth_command(MAGIC_PING)) ? 20 : 0;
+	if (i)
+		plymouth_command(MAGIC_QUIT);

would be possible to #define PLYMOUTH_TERMIOS_FLAGS_DELAY, now we have 20s in sulogins and 30s in agetty. Why?

Ahh ... indeed this is a good point :)

Werner

Signature · 2 lines
  "Having a smoking section in a restaurant is like having
          a peeing section in a swimming pool." -- Edward Burr
#3 lore raw
In reply to Karel Zak
Quoted 10 lines · Karel Zak

Review

Quoted 5 lines
(quoted diff) +3 -2
-	int i = (plymouth_command("--ping")) ? 20 : 0;
-
+	int i = (plymouth_command(MAGIC_PING)) ? 20 : 0;
+	if (i)
+		plymouth_command(MAGIC_QUIT);

would be possible to #define PLYMOUTH_TERMIOS_FLAGS_DELAY, now we have 20s in sulogins and 30s in agetty. Why?

Karel

OK, let's see if the patch in the attachment does it better here.

Werner

Signature · 2 lines
  "Having a smoking section in a restaurant is like having
          a peeing section in a swimming pool." -- Edward Burr

From 137483035afdde9918c9e4b9cabeefda6d63b887 Mon Sep 17 00:00:00 2001
From: Werner Fink <[email protected]>
Date: Fri, 22 Apr 2016 12:16:04 +0200
Subject: [PATCH] Use the plymouth local protocol instead the plymouth binary

for stopping plymouthd. That do not depend on the existence of the plymouth binary if it e.g. becomes uninstalled or an other service is providing plymouthd facilities.

---
 include/plymouth-ctrl.h |  65 +++++++++++++++++++++
 lib/Makemodule.am       |   1 +
 lib/plymouth-ctrl.c     | 147 ++++++++++++++++++++++++++++++++++++++++++++++++
 login-utils/sulogin.c   |  44 ++-------------
 term-utils/agetty.c     |  48 ++--------------
 5 files changed, 223 insertions(+), 82 deletions(-)
 create mode 100644 include/plymouth-ctrl.h
 create mode 100644 lib/plymouth-ctrl.c
plymouth-ctrl.h new file +65 -0
new file mode 100644
index 0000000..e1df363
@@ -0,0 +1,65 @@
+/*
+ * plymouth-ctrl.h	Header file for communcations with plymouthd
+ *
+ * Copyright (c) 2016 SUSE Linux GmbH, All rights reserved.
+ * Copyright (c) 2016 Werner Fink <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *  
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING); if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * Author: Werner Fink <[email protected]>
+ */
+
+/*
+ * Taken from plymouth 0.9.0 src/ply-boot-protocol.h
+ */
+
+#ifndef UTIL_LINUX_PLYMOUTH_CTRL_H
+#define UTIL_LINUX_PLYMOUTH_CTRL_H
+
+#define PLYMOUTH_SOCKET_PATH	"\0/org/freedesktop/plymouthd"
+#define ANSWER_TYP		'\x2'
+#define ANSWER_ENQ		'\x5'
+#define ANSWER_ACK		'\x6'
+#define ANSWER_MLT		'\t'
+#define ANSWER_NCK		'\x15'
+
+#define MAGIC_PRG_STOP		'A'
+#define MAGIC_PRG_CONT		'a'
+#define MAGIC_UPDATE		'U'
+#define MAGIC_SYS_UPDATE	'u'
+#define MAGIC_SYS_INIT		'S'
+#define MAGIC_DEACTIVATE	'D'
+#define MAGIC_REACTIVATE	'r'
+#define MAGIC_SHOW_SPLASH	'$'
+#define MAGIC_HIDE_SPLASH	'H'
+#define MAGIC_CHMOD		'C'
+#define MAGIC_CHROOT		'R'
+#define MAGIC_ACTIVE_VT		'V'
+#define MAGIC_QUESTION		'W'
+#define MAGIC_SHOW_MSG		'M'
+#define MAGIC_HIDE_MSG		'm'
+#define MAGIC_KEYSTROKE		'K'
+#define MAGIC_KEYSTROKE_RM	'L'
+#define MAGIC_PING		'P'
+#define MAGIC_QUIT		'Q'
+#define MAGIC_CACHED_PWD	'c'
+#define MAGIC_ASK_PWD		'*'
+#define MAGIC_DETAILS		'!'
+
+#define PLYMOUTH_TERMIOS_FLAGS_DELAY	30
+extern int plymouth_command(int cmd, ...);
+
+#endif /* UTIL_LINUX_PLYMOUTH_CTRL_H */
Makemodule.am +1 -0
index 054b816..cbf5cee 100644
@@ -16,6 +16,7 @@ libcommon_la_SOURCES = \
 	lib/md5.c \
 	lib/pager.c \
 	lib/path.c \
+	lib/plymouth-ctrl.c \
 	lib/randutils.c \
 	lib/setproctitle.c \
 	lib/strutils.c \
plymouth-ctrl.c new file +147 -0

147 lines not on this page · raw message

sulogin.c +4 -40

68 lines not on this page · raw message

agetty.c +6 -42

91 lines not on this page · raw message

Signature · 1 line
2.6.6
maintainer
#4 lore raw
Quoted 8 lines · Dr. Werner Fink
 include/plymouth-ctrl.h |  65 +++++++++++++++++++++
 lib/Makemodule.am       |   1 +
 lib/plymouth-ctrl.c     | 147 ++++++++++++++++++++++++++++++++++++++++++++++++
 login-utils/sulogin.c   |  44 ++-------------
 term-utils/agetty.c     |  48 ++--------------
 5 files changed, 223 insertions(+), 82 deletions(-)
 create mode 100644 include/plymouth-ctrl.h
 create mode 100644 lib/plymouth-ctrl.c

Applied with minor changes, thanks.

Karel

Signature · 2 lines
 Karel Zak  <[email protected]>
 http://karelzak.blogspot.com