public inbox for linux-bluetooth@vger.kernel.org
 help / color / mirror / Atom feed
From: James Cameron <james.cameron@hp.com>
To: 256436@bugs.debian.org, bluez-devel@lists.sourceforge.net
Subject: [Bluez-devel] [PATCH] pand/main.c, restore signals for dev-up script
Date: Sun, 27 Jun 2004 23:33:25 +1000	[thread overview]
Message-ID: <20040627133325.GA23996@hp.com> (raw)


[-- Attachment #1.1: Type: text/plain, Size: 2363 bytes --]

Problem: pand dev-up script on Debian fails to "ifup bnep0", the error
is "Failed to bring up bnep0".

Diagnosis: dev-up script inherits the SIG_IGN of SIGCHLD and SIGPIPE
done by pand/main.c, in addition to some open sockets.  The ifup program
requires signals in default state.

Solution: restore signals to SIG_DFL, close some of the sockets.  A
patch for this is attached, less comments.  The patch applies cleanly to
both the Debian revision of pand/main.c 1.3, and to the current revision
1.4 in CVS.


Discussion:

Restoring the signals takes a call to sigaction() after fork() but
before exec().  This call undoes the initialisation call in main().

Closing the sockets can be done automatically on fork(), or manually.
My patch does it manually.

Closing the sockets automatically would require setting FD_CLOEXEC on
them after they are created.  fcntl(sk, F_SETFD, FD_CLOEXEC);

Closing the sockets manually requires the socket file descriptors to be
sent to run_devup(); this seems ugly to me, I'm not altogether happy
with the way I've done it and I hope the maintainer will rethink this
for me.  Perhaps making the socket numbers global would make more sense.

Even then, tests show that there are *three* file descriptors inherited
by the dev-up script, and I've only been able to find two.  Hopefully
the maintainer knows where the other one is; bnep_init()?

Here's how I found the open sockets ... (a) place a "sleep 30m" in
dev-up, (b) cause pand to run dev-up, (c) find pid of sleep, (d) run
lsof -p ...

sleep   16393 root    0u   CHR    1,3         163834 /dev/null
sleep   16393 root    1w   REG    3,4     258  48965 /tmp/dev-up.16391.log
sleep   16393 root    2w   REG    3,4     258  48965 /tmp/dev-up.16391.log
sleep   16393 root    3u  sock    0,4           4477 can't identify protocol
sleep   16393 root    5u  sock    0,4           4480 can't identify protocol
sleep   16393 root    6u  sock    0,4          27277 can't identify protocol

The signals were found using "cat /proc/${pid}/status", and confirmed
with strace.

Please let me know if my patch is applied.  Thanks!

-- 
James Cameron                         http://quozl.netrek.org/
HP Open Source, Volunteer             http://opensource.hp.com/
PPTP Client Project, Release Engineer http://pptpclient.sourceforge.net/

[-- Attachment #1.2: pand-256436.patch --]
[-- Type: text/plain, Size: 1132 bytes --]

--- bluez-utils-2.7/pand/main.c	2004-05-09 20:39:43.000000000 +1000
+++ bluez-utils-2.7-4-jc1/pand/main.c	2004-06-27 23:02:00.000000000 +1000
@@ -84,9 +84,10 @@
 	KILL
 } modes;
 
-static void run_devup(char *dev, char *dst)
+static void run_devup(char *dev, char *dst, int sk, int nsk)
 {
 	char *argv[4], prog[40];
+	struct sigaction sa;
 
 	sprintf(prog, "%s/%s", PAND_CONFIG_DIR, PAND_DEVUP_CMD);
 
@@ -96,6 +97,15 @@
 	if (fork())
 		return;
 
+	close(sk);
+	if (nsk != -1)
+		close(nsk);
+	
+	memset(&sa, 0, sizeof(sa));
+	sa.sa_handler = SIG_DFL;
+	sigaction(SIGCHLD, &sa, NULL);
+	sigaction(SIGPIPE, &sa, NULL);
+
 	argv[0] = prog;
 	argv[1] = dev;
 	argv[2] = dst;
@@ -184,7 +194,7 @@
 
 			syslog(LOG_INFO, "New connection from %s %s", str, netdev);
 
-			run_devup(netdev, str);
+			run_devup(netdev, str, sk, nsk);
 		} else {
 			syslog(LOG_ERR, "Connection failed. %s(%d)",
 					strerror(errno), errno);
@@ -274,7 +284,7 @@
 
 		syslog(LOG_INFO, "%s connected", netdev);
 
-		run_devup(netdev, dst);
+		run_devup(netdev, dst, sk, -1);
 
 		if (persist)
 			w4_hup(sk);

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

             reply	other threads:[~2004-06-27 13:33 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-06-27 13:33 James Cameron [this message]
2004-06-27 20:06 ` [Bluez-devel] [PATCH] pand/main.c, restore signals for dev-up script Marcel Holtmann
2004-06-27 23:34   ` James Cameron
2004-06-28  7:44     ` Marcel Holtmann
2004-06-28  8:53       ` James Cameron
2004-06-28  9:05         ` Marcel Holtmann
2004-06-28  9:55           ` James Cameron
2004-06-28 10:13             ` Marcel Holtmann
2004-06-28 10:19               ` James Cameron
2004-06-28 10:39                 ` Marcel Holtmann
2004-06-28 12:06                   ` James Cameron
2004-06-28 12:54                     ` Marcel Holtmann
2004-06-28 22:48                       ` James Cameron
2004-06-28 23:26                         ` Marcel Holtmann
2004-06-29  5:23                           ` James Cameron
2004-06-29  8:58                             ` Marcel Holtmann
2004-06-29 10:55                               ` James Cameron
2004-06-29 11:26                                 ` Marcel Holtmann
2004-06-30  0:15                                   ` James Cameron
2004-06-30  9:06                                     ` Marcel Holtmann

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=20040627133325.GA23996@hp.com \
    --to=james.cameron@hp.com \
    --cc=256436@bugs.debian.org \
    --cc=bluez-devel@lists.sourceforge.net \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox