Util-Linux Archive on lore.kernel.org
 help / Atom feed
* [PATCH 2/3] agetty: Watch only protocol requested by issue escapes
@ 2018-10-10 17:26 Stanislav Brabec
  2018-10-11 12:01 ` Karel Zak
  0 siblings, 1 reply; 2+ messages in thread
From: Stanislav Brabec @ 2018-10-10 17:26 UTC (permalink / raw)
  To: util-linux

To decrease number of reloads, watch only protocol requested by \4 and \6
escapes in issue file.

Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
---
 term-utils/agetty.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/term-utils/agetty.c b/term-utils/agetty.c
index 2f27d7f71..27e97091b 100644
--- a/term-utils/agetty.c
+++ b/term-utils/agetty.c
@@ -153,6 +153,7 @@
 # define AGETTY_RELOAD_FDNONE	-2			/* uninitialized fd */
 static int inotify_fd = AGETTY_RELOAD_FDNONE;
 static int netlink_fd = AGETTY_RELOAD_FDNONE;
+static __u32 netlink_groups;
 #endif
 
 /*
@@ -1546,7 +1547,7 @@ static void open_netlink(void)
 	if (sock >= 0) {
 		addr.nl_family = AF_NETLINK;
 		addr.nl_pid = getpid();
-		addr.nl_groups = RTMGRP_IPV4_IFADDR | RTMGRP_IPV6_IFADDR;
+		addr.nl_groups = netlink_groups;
 		if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) < 0)
 			close(sock);
 		else
@@ -1729,6 +1730,9 @@ static void print_issue_file(struct options *op, struct termios *tp)
 #ifdef ISSUEDIR_SUPPORT
 	int dd = -1, nfiles = 0, i;
 	struct dirent **namelist = NULL;
+#endif
+#ifdef AGETTY_RELOAD
+	netlink_groups = 0;
 #endif
 	if ((op->flags & F_NONL) == 0) {
 		/* Issue not in use, start with a new line. */
@@ -1820,6 +1824,10 @@ static void print_issue_file(struct options *op, struct termios *tp)
 	if (dd >= 0)
 		close(dd);
 #endif
+#ifdef AGETTY_RELOAD
+	if (netlink_groups != 0)
+		open_netlink();
+#endif
 }
 #endif /* ISSUE_SUPPORT */
 
@@ -2624,10 +2632,6 @@ static void output_special_char(unsigned char c, struct options *op,
 		struct ifaddrs *addrs = NULL;
 		char iface[128];
 
-#ifdef AGETTY_RELOAD
-		open_netlink();
-#endif
-
 		if (getifaddrs(&addrs))
 			break;
 
@@ -2637,6 +2641,11 @@ static void output_special_char(unsigned char c, struct options *op,
 			output_iface_ip(addrs, NULL, family);
 
 		freeifaddrs(addrs);
+
+		if (c == '4')
+			netlink_groups |= RTMGRP_IPV4_IFADDR;
+		else
+			netlink_groups |= RTMGRP_IPV6_IFADDR;
 		break;
 	}
 	default:
-- 
2.19.0

-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                         e-mail: sbrabec@suse.com
Křižíkova 148/34 (Corso IIa)                  tel: +49 911 7405384547
186 00 Praha 8-Karlín                          fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH 2/3] agetty: Watch only protocol requested by issue escapes
  2018-10-10 17:26 [PATCH 2/3] agetty: Watch only protocol requested by issue escapes Stanislav Brabec
@ 2018-10-11 12:01 ` Karel Zak
  0 siblings, 0 replies; 2+ messages in thread
From: Karel Zak @ 2018-10-11 12:01 UTC (permalink / raw)
  To: Stanislav Brabec; +Cc: util-linux

On Wed, Oct 10, 2018 at 07:26:27PM +0200, Stanislav Brabec wrote:
>  term-utils/agetty.c | 19 ++++++++++++++-----
>  1 file changed, 14 insertions(+), 5 deletions(-)

Applied, thanks.

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, back to index

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-10-10 17:26 [PATCH 2/3] agetty: Watch only protocol requested by issue escapes Stanislav Brabec
2018-10-11 12:01 ` Karel Zak

Util-Linux Archive on lore.kernel.org

Archives are clonable: git clone --mirror https://lore.kernel.org/util-linux/0 util-linux/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 util-linux util-linux/ https://lore.kernel.org/util-linux \
		util-linux@vger.kernel.org util-linux@archiver.kernel.org
	public-inbox-index util-linux


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.util-linux


AGPL code for this site: git clone https://public-inbox.org/ public-inbox