ALT Linux Community general discussions
 help / color / mirror / Atom feed
From: Valentin Lavrinenko <lvu@uaservice.com.ua>
To: ALT Linux Community <community@lists.altlinux.org>
Subject: Re: [Comm] Re: /sbin/ifup ppp0 - некорректная работа по Ctrl-C
Date: Fri, 21 Oct 2005 11:11:21 +0300
Message-ID: <4358A2A9.4090406@uaservice.com.ua> (raw)
In-Reply-To: <20051020115520.GF16082@osdn.org.ua>

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

Hi!

Michael Shigorin wrote:

>Вы ещё не списались с Денисом?
>
Еще нет.

В общем, я, похоже, нашел, в чем проблема, и даже сумел ее поправить.
При этом наткнулся на баг (точнее, даже пару связанных) в pppd, повесил
на http://ppp.samba.org/cgi-bin/ppp-bugs/incoming?id=1285.

К сожалению, я не могу зарегистрироваться в багзилле - видимо, наш сервак
рубит письмо с подтверждением. Так что патч приаттачен к письму. Основная
идея: когда юзер нажал Ctrl-C, pppp-watch смотрит .pid-файл, создаваемый 
pppd,
и, если нашел - по полученному pid'у убивает pppd. Однако, pppd создает этот
файл не сразу, а только когда установится соединение (отработает 
chat-скрипт,
например). Поэтому, если .pid-файл не найден, то мы ищем pppd, запущенный
с нужным на параметром, в /proc. Если нашли - ждем 10 секунд (должно 
хватить),
периодически проверяя, не появился ли .pid-файл, как только появился - 
убиваем
pppd.

Можно юыло бы, найдя pppd в /proc, сразу убивать pppd, но этому мешает 
упомянутая
выше бага.

Если этот патч появится в Сизифе - буду очень рад, если в backports - 
еще больше :)

[-- Attachment #2: net-scripts-pppd_sigterm.patch --]
[-- Type: text/x-patch, Size: 2344 bytes --]

diff -ur net-scripts-0.4.9.1/src/ppp-watch.c net-scripts-0.4.9.1-lvu/src/ppp-watch.c
--- net-scripts-0.4.9.1/src/ppp-watch.c	2001-03-05 02:22:06 +0200
+++ net-scripts-0.4.9.1-lvu/src/ppp-watch.c	2005-10-21 10:31:23 +0300
@@ -75,6 +75,7 @@
 #include <sys/wait.h>
 #include <termios.h>
 #include <net/if.h>
+#include <glob.h>
 
 #include "shvar.h"
 #include "alloc.h"
@@ -116,6 +117,43 @@
 }
 
 
+static int
+get_pppd_pid(char *device) {
+    int i;
+    glob_t globbuf;
+    int ge = glob("/proc/*/cmdline", 0, NULL, &globbuf);
+    if (!ge) {
+	for (i = 0; i < globbuf.gl_pathc; ++i) {	    
+	    FILE *fcmdline;
+	    char cmdline[1024]; // hope this will be enough
+	    if (fcmdline = fopen(globbuf.gl_pathv[i], "r")) {
+		int num_read;
+		num_read = fread(cmdline, 1, 1024, fcmdline);
+		if (num_read > 0 && !strcmp(cmdline, "/usr/sbin/pppd")) {
+		    int prev_linkname = 0;
+		    char *p = cmdline;
+		    while (*p && p - cmdline < 1024) {
+			if (prev_linkname && !strcmp(p, device)) {
+			    int retval;
+			    globbuf.gl_pathv[i][strlen(globbuf.gl_pathv[i])-8] = 0;
+			    retval = atoi(globbuf.gl_pathv[i]+6);
+			    globfree(&globbuf);
+			    fclose(fcmdline);
+			    return retval;
+			}
+			prev_linkname = !strcmp(p, "linkname");
+			p += strlen(p) + 1;
+		    }		    
+		}
+		fclose(fcmdline);
+	    }
+	}
+	globfree(&globbuf);
+	return 0;
+    }
+    else
+	return -1;
+}
 
 static void
 detach(int now, int parentExitCode, char *device) {
@@ -550,6 +588,20 @@
 	    if (physicalDevice) { free(physicalDevice); physicalDevice = NULL; }
 	    physicalDevice = pppLogicalToPhysical(&pppdPid, real_device);
 	    if (physicalDevice) { free(physicalDevice); physicalDevice = NULL; }
+	    if (!pppdPid && get_pppd_pid(device))
+	    {
+		// We suspect that pppd is running, but haven't created
+		// .pid file yet. So we'll wait for 10 seconds, checking
+		// for .pid file every 10 milliseconds.
+		int i;
+		for (i = 0; i < 1000 && !pppdPid && get_pppd_pid(device) !=0 ; ++i)
+		{
+		    usleep(10000);
+		    physicalDevice = pppLogicalToPhysical(&pppdPid, real_device);
+		    if (physicalDevice) { free(physicalDevice); physicalDevice = NULL; }
+		}
+		sleep(2); // Else pppd may hangup, seems there's a bug in it
+	    }
 	    if (!pppdPid) cleanExit(35);
 	    kill(pppdPid, sendsig);
 	    if (sendsig == SIGKILL) {

  reply	other threads:[~2005-10-21  8:11 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-10-12 11:12 [Comm] " Valentin Lavrinenko
2005-10-18 11:24 ` Valentin Lavrinenko
2005-10-18 18:34   ` [Comm] " Michael Shigorin
2005-10-19  6:45     ` Valentin Lavrinenko
2005-10-19 12:20       ` Michael Shigorin
2005-10-19 13:49         ` Valentin Lavrinenko
2005-10-19 13:54           ` Michael Shigorin
2005-10-20  6:33             ` Valentin Lavrinenko
2005-10-20 11:55               ` Michael Shigorin
2005-10-21  8:11                 ` Valentin Lavrinenko [this message]
2005-10-21 12:09                   ` Michael Shigorin

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=4358A2A9.4090406@uaservice.com.ua \
    --to=lvu@uaservice.com.ua \
    --cc=community@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 Community general discussions

This inbox may be cloned and mirrored by anyone:

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

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


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