[PATCH] replace deprecated termio ioctl interface calls.



Oliver Falk wrote:
> Hi list!
> 
> For reference: https://bugzilla.redhat.com/show_bug.cgi?id=464760
> 
> While trying to compile NM-1:0.7.0-0.11.svn4022.2 on alpha, I ran into a
> compile error:
> 
> """
> nm-serial-device.c: In function 'nm_serial_device_open':
> nm-serial-device.c:348: error: array subscript is above array bounds
> nm-serial-device.c:349: error: array subscript is above array bounds
> """
> 
> After analysing the problem, I found out that stdbuf is defined as "struct
> termio". Take a look at termio.h:
> """
> [oliver kriek ~]$ cat /usr/include/termio.h
> /* Compatible <termio.h> for old `struct termio' ioctl interface.
>     This is obsolete; use the POSIX.1 `struct termios' interface
>     defined in <termios.h> instead.  */
> 
> #include <termios.h>
> #include <sys/ioctl.h>
> """
> 
> A simple fix - at least for alpha - is to use "struct termios" instead (I'll
> include a patch!). However, I have not tested this on x86 or any other 
> platform - this is up to you! :-)
> 

I've attached a more complete patch (based on the NM-0_7 branch), which replaces
the struct termio ioctl calls completely.
The 0.7.1 package now builds fine again on alpha [1].

Please review and apply.

Cheers,
Michael

[1]
https://buildd.debian.org/fetch.cgi?pkg=network-manager;ver=0.7.1-1;arch=alpha;stamp=1239931427

-- 
Why is it that all of the instruments seeking intelligent life in the
universe are pointed away from Earth?
From e7f09bb883f91b2af0f135559208dc0f6a437201 Mon Sep 17 00:00:00 2001
From: Michael Biebl <biebl debian org>
Date: Fri, 17 Apr 2009 01:52:01 +0200
Subject: [PATCH] Use struct termios interface

Use the POSIX.1 struct termios interface instead of the obsolete struct
termio ioctl interface.
---
 src/nm-serial-device.c |   13 ++++++-------
 1 files changed, 6 insertions(+), 7 deletions(-)

diff --git a/src/nm-serial-device.c b/src/nm-serial-device.c
index 1cba1ca..afdc6a6 100644
--- a/src/nm-serial-device.c
+++ b/src/nm-serial-device.c
@@ -21,13 +21,12 @@
 
 #define _GNU_SOURCE  /* for strcasestr() */
 
-#include <termio.h>
+#include <termios.h>
 #include <unistd.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <errno.h>
-#include <sys/ioctl.h>
 #include <string.h>
 #include <stdlib.h>
 #include <glib.h>
@@ -346,7 +345,7 @@ static gboolean
 config_fd (NMSerialDevice *device, NMSettingSerial *setting)
 {
 	NMSerialDevicePrivate *priv = NM_SERIAL_DEVICE_GET_PRIVATE (device);
-	struct termio stbuf;
+	struct termios stbuf;
 	int speed;
 	int bits;
 	int parity;
@@ -357,7 +356,7 @@ config_fd (NMSerialDevice *device, NMSettingSerial *setting)
 	parity = parse_parity (nm_setting_serial_get_parity (setting));
 	stopbits = parse_stopbits (nm_setting_serial_get_stopbits (setting));
 
-	ioctl (priv->fd, TCGETA, &stbuf);
+	tcgetattr (priv->fd, &stbuf);
 
 	stbuf.c_iflag &= ~(IGNCR | ICRNL | IUCLC | INPCK | IXON | IXANY | IGNPAR );
 	stbuf.c_oflag &= ~(OPOST | OLCUC | OCRNL | ONLCR | ONLRET);
@@ -370,7 +369,7 @@ config_fd (NMSerialDevice *device, NMSettingSerial *setting)
 	stbuf.c_cflag &= ~(CBAUD | CSIZE | CSTOPB | CLOCAL | PARENB);
 	stbuf.c_cflag |= (speed | bits | CREAD | 0 | parity | stopbits);
 
-	if (ioctl (priv->fd, TCSETA, &stbuf) < 0) {
+	if (tcgetattr (priv->fd, &stbuf) < 0) {
 		nm_warning ("(%s) cannot control device (errno %d)",
 		            nm_device_get_iface (NM_DEVICE (device)), errno);
 		return FALSE;
@@ -404,7 +403,7 @@ nm_serial_device_open (NMSerialDevice *device,
 		return FALSE;
 	}
 
-	if (ioctl (priv->fd, TCGETA, &priv->old_t) < 0) {
+	if (tcgetattr (priv->fd, &priv->old_t) < 0) {
 		nm_warning ("(%s) cannot control device (errno %d)", iface, errno);
 		close (priv->fd);
 		return FALSE;
@@ -447,7 +446,7 @@ nm_serial_device_close (NMSerialDevice *device)
 			priv->channel = NULL;
 		}
 
-		ioctl (priv->fd, TCSETA, &priv->old_t);
+		tcsetattr (priv->fd, TCSANOW, &priv->old_t);
 		close (priv->fd);
 		priv->fd = 0;
 	}
-- 
1.6.2.3

Attachment: signature.asc
Description: OpenPGP digital signature



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]