ALT Linux Sisyphus discussions
 help / color / mirror / Atom feed
From: Sergey Vlasov <vsu@altlinux.ru>
To: sisyphus@lists.altlinux.org
Subject: Re: [sisyphus] I: nut-2.6.0, please test/help
Date: Sun, 20 Feb 2011 15:48:10 +0300
Message-ID: <20110220124810.GA6541@atlas.home> (raw)
In-Reply-To: <4D60E2BE.8070700@kalina.in.ua>

[-- Attachment #1: Type: text/plain, Size: 2648 bytes --]

On Sun, Feb 20, 2011 at 11:45:34AM +0200, Yura Kalinichenko wrote:
> Michael Shigorin пишет:
> > 	Здравствуйте.
> > Пилю тут урывками свежий nut, 
> Аналогично. Что радует - оно уже таки нормально конфигурится под ALT >=4.
> > - без указания опции "-4" upsd/upsdrvctl не стартуют при
> >   отсутствии ipv6, поскольку надо там аж 127.0.0.1 --
> >   воткнуто по умолчанию в /etc/sysconfig/upsd, спросил апстрим
> Я посмотрел как оно было сделано в 2.2.2 и повторил, вряд ли правильно - 
> но "чтоб работало". По крайней мере upsd поднялся.
> 
> diff -U 2 -r nut-2.6.0.orig/server/upsd.c nut-2.6.0/server/upsd.c
> --- nut-2.6.0.orig/server/upsd.c        2010-12-24 15:24:12 +0200
> +++ nut-2.6.0/server/upsd.c     2011-02-12 12:58:33 +0200
> @@ -546,10 +546,11 @@
>         /* default behaviour if no LISTEN addres has been specified */
>         if (!firstaddr) {
> -               if (opt_af != AF_INET) {
> -                       listen_add("::1", string_const(PORT));
> -               }
> 
> -               if (opt_af != AF_INET6) {
> +               if (opt_af == AF_INET6) {
> +                       listen_add("::1", string_const(PORT));
> +               } else if (opt_af == AF_INET) {
>                         listen_add("127.0.0.1", string_const(PORT));
> +               } else {
> +                       listen_add("0.0.0.0", string_const(PORT));
>                 }
>         }

Такой вариант явно никуда не годится - по умолчанию пропадает не
только поддержка IPv6, но и привязка к localhost.  Вместо этого,
вероятно, надо для случая opt_af == AF_UNSPEC (опции -4 или -6 не
заданы явно) перед выполнением listen_add("::1", string_const(PORT))
проверять возможность создания сокета AF_INET6.

(Патч не тестировался даже gcc.)

--- nut-2.6.0/server/upsd.c.alt-ipv6-optional	2010-12-24 16:24:12.000000000 +0300
+++ nut-2.6.0/server/upsd.c	2011-02-20 15:44:01.508000003 +0300
@@ -539,6 +539,19 @@ static void client_readline(ctype_t *cli
 	return;
 }
 
+static int ipv6_available(void)
+{
+	int sock_fd;
+
+	if ((sock_fd = socket(AF_INET6, SOCK_STREAM, IPPROTO_TCP)) < 0) {
+		upsdebug_with_errno(3, "ipv6_available: socket");
+		return 0;
+	}
+
+	close(sock_fd);
+	return 1;
+}
+
 void server_load(void)
 {
 	stype_t	*server;
@@ -546,7 +559,9 @@ void server_load(void)
 	/* default behaviour if no LISTEN addres has been specified */
 	if (!firstaddr) {
 		if (opt_af != AF_INET) {
-			listen_add("::1", string_const(PORT));
+			if (opt_af == AF_INET6 || ipv6_available()) {
+				listen_add("::1", string_const(PORT));
+			}
 		}
 
 		if (opt_af != AF_INET6) {

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

  reply	other threads:[~2011-02-20 12:48 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-02-19 21:54 Michael Shigorin
2011-02-20  9:45 ` Yura Kalinichenko
2011-02-20 12:48   ` Sergey Vlasov [this message]
2011-02-20 19:24     ` Yura Kalinichenko

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20110220124810.GA6541@atlas.home \
    --to=vsu@altlinux.ru \
    --cc=sisyphus@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Sisyphus discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/sisyphus/0 sisyphus/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 sisyphus sisyphus/ http://lore.altlinux.org/sisyphus \
		sisyphus@altlinux.ru sisyphus@altlinux.org sisyphus@lists.altlinux.org sisyphus@lists.altlinux.ru sisyphus@lists.altlinux.com sisyphus@linuxteam.iplabs.ru sisyphus@list.linux-os.ru
	public-inbox-index sisyphus

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.sisyphus


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