* 2.6.0-test11 - fork, dup, dup2 oddities
@ 2003-12-07 21:03 Lukas Hejtmanek
2003-12-08 0:46 ` Greg KH
0 siblings, 1 reply; 3+ messages in thread
From: Lukas Hejtmanek @ 2003-12-07 21:03 UTC (permalink / raw)
To: linux-kernel
Hello,
I have 2.6.0-test11 kernel. I try to run pppd with pppd call gprs. In gprs
I have device /dev/ttyUSB0. It fails. I've found that it happened ONLY if I use
detach option.
I have tried /dev/ircomm0 as well with the same result. However with /dev/ttySL0
(that is symlink to pty created by modem driver) it works ok with or withoud
detach option.
I've tried to debug pppd and discovered failing code:
/* make sure fds 0, 1, 2 are occupied */
while ((fd = dup(in)) >= 0) {
if (fd > 2) {
close(fd);
break;
}
}
/* dup in and out to fds > 2 */
{
int fd1 = in, fd2 = out, fd3 = log_to_fd;
in = dup(in);
out = dup(out);
if (log_to_fd >= 0) {
errfd = dup(log_to_fd);
} else {
errfd = open(_PATH_CONNERRS, O_WRONLY | O_APPEND | O_CREAT, 0600);
}
close(fd1);
close(fd2);
close(fd3);
}
/* close fds 0 - 2 and any others we can think of */
close(0);
close(1);
close(2);
if (the_channel->close)
(*the_channel->close)();
closelog();
close(fd_devnull);
/* dup the in, out, err fds to 0, 1, 2 */
dup2(in, 0);
close(in);
dup2(out, 1);
close(out);
if (errfd >= 0) {
dup2(errfd, 2);
close(errfd);
}
setuid(uid);
if (getuid() != uid) {
error("setuid failed");
exit(1);
}
setgid(getgid());
execl("/bin/sh", "sh", "-c", program, (char *)0);
error("could not exec /bin/sh: %m");
exit(99);
execl exit with code 02.
program is equal to:
/usr/sbin/chat -V -s '' ATZ OK 'AT+CGDCONT=1,\"IP\",\"ointernet\"' OK 'ATD*99***1#' CONNECT
in=10, out=10 (it is opened /dev/ttyUSB0)
It works OK with 2.4.22 or if do not use previous fork.
--
Lukáš Hejtmánek
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: 2.6.0-test11 - fork, dup, dup2 oddities
2003-12-07 21:03 2.6.0-test11 - fork, dup, dup2 oddities Lukas Hejtmanek
@ 2003-12-08 0:46 ` Greg KH
2003-12-08 1:11 ` Lukas Hejtmanek
0 siblings, 1 reply; 3+ messages in thread
From: Greg KH @ 2003-12-08 0:46 UTC (permalink / raw)
To: Lukas Hejtmanek; +Cc: linux-kernel
On Sun, Dec 07, 2003 at 10:03:05PM +0100, Lukas Hejtmanek wrote:
> Hello,
>
> I have 2.6.0-test11 kernel. I try to run pppd with pppd call gprs. In gprs
> I have device /dev/ttyUSB0. It fails. I've found that it happened ONLY
> if I use detach option.
The ttyUSB* nodes right now have a bug that prevents more than one
open() to work properly. Well actually, the bug is on the close()
part...
Anyway, can you try the patch I posted here yesterday? A copy of it is
below. It should fix this bug. Please let me know either way.
thanks,
greg k-h
diff -Nru a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c
--- a/drivers/usb/serial/usb-serial.c Fri Dec 5 17:37:16 2003
+++ b/drivers/usb/serial/usb-serial.c Fri Dec 5 17:37:16 2003
@@ -493,12 +493,15 @@
return retval;
}
-static void __serial_close(struct usb_serial_port *port, struct file *filp)
+static void serial_close(struct tty_struct *tty, struct file * filp)
{
- if (!port->open_count) {
- dbg ("%s - port not opened", __FUNCTION__);
+ struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
+ struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
+
+ if (!serial)
return;
- }
+
+ dbg("%s - port %d", __FUNCTION__, port->number);
--port->open_count;
if (port->open_count <= 0) {
@@ -506,30 +509,18 @@
* port is being closed by the last owner */
port->serial->type->close(port, filp);
port->open_count = 0;
+
+ if (port->tty) {
+ if (port->tty->driver_data)
+ port->tty->driver_data = NULL;
+ port->tty = NULL;
+ }
}
module_put(port->serial->type->owner);
kobject_put(&port->serial->kobj);
}
-static void serial_close(struct tty_struct *tty, struct file * filp)
-{
- struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
- struct usb_serial *serial = get_usb_serial (port, __FUNCTION__);
-
- if (!serial)
- return;
-
- dbg("%s - port %d", __FUNCTION__, port->number);
-
- /* if disconnect beat us to the punch here, there's nothing to do */
- if (tty && tty->driver_data) {
- __serial_close(port, filp);
- tty->driver_data = NULL;
- }
- port->tty = NULL;
-}
-
static int serial_write (struct tty_struct * tty, int from_user, const unsigned char *buf, int count)
{
struct usb_serial_port *port = (struct usb_serial_port *) tty->driver_data;
@@ -848,19 +839,6 @@
dbg ("%s - %s", __FUNCTION__, kobj->name);
serial = to_usb_serial(kobj);
-
- /* fail all future close/read/write/ioctl/etc calls */
- for (i = 0; i < serial->num_ports; ++i) {
- port = serial->port[i];
- if (port->tty != NULL) {
- port->tty->driver_data = NULL;
- while (port->open_count > 0) {
- __serial_close(port, NULL);
- }
- port->tty = NULL;
- }
- }
-
serial_shutdown (serial);
/* return the minor range that this device had */
@@ -1242,7 +1220,7 @@
/* register all of the individual ports with the driver core */
for (i = 0; i < num_ports; ++i) {
port = serial->port[i];
- port->dev.parent = &serial->dev->dev;
+ port->dev.parent = &interface->dev;
port->dev.driver = NULL;
port->dev.bus = &usb_serial_bus_type;
port->dev.release = &port_release;
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: 2.6.0-test11 - fork, dup, dup2 oddities
2003-12-08 0:46 ` Greg KH
@ 2003-12-08 1:11 ` Lukas Hejtmanek
0 siblings, 0 replies; 3+ messages in thread
From: Lukas Hejtmanek @ 2003-12-08 1:11 UTC (permalink / raw)
To: Greg KH; +Cc: linux-kernel
On Sun, Dec 07, 2003 at 04:46:55PM -0800, Greg KH wrote:
> The ttyUSB* nodes right now have a bug that prevents more than one
> open() to work properly. Well actually, the bug is on the close()
> part...
>
> Anyway, can you try the patch I posted here yesterday? A copy of it is
> below. It should fix this bug. Please let me know either way.
Thanks, this patch works for me. pppd now correctly connect via ttyUSB.
However similar patch will be need for ircomm-tty. That is not functional as
well.
--
Lukáš Hejtmánek
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2003-12-08 1:12 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-12-07 21:03 2.6.0-test11 - fork, dup, dup2 oddities Lukas Hejtmanek
2003-12-08 0:46 ` Greg KH
2003-12-08 1:11 ` Lukas Hejtmanek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).