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

Re: RFS: ttylog (updated package)



On Sat, Mar 26, 2011 at 03:24:48PM -0400, Robert James Clay wrote:
> Dear mentors,
> 
> I am looking for a sponsor for the new version 0.1.d-1
> of my package "ttylog".
> 
> It builds these binary packages:
> ttylog     - serial port logger
> 
> The package appears to be lintian clean.
> 
> The upload would fix these bugs: 566938
> 
> Debian Changelog for 0.1.d-1:
>   * New upstream release.
>   * Set debhelper Build-Depends to version 7.
>   * Explicitly set Debian package format as 1.0.
>   * Changed debian/watch to point to Sourceforge.
>   * Change Maintainer email address to jame@rocasa.us.
>   * Set Standards Version to 3.9.1; no changes necessary.
>   * Detailed the Debian packaging copyright in debian/copyright.
>   * Change homepage in debian/control to Sourceforge project site.
>   * Add Vcs-Git & Vcs-Browser to debian/control. (Closes: #566938)
>   * Changed to using dh_prep in the install target of debian/rules.
> 
> Note that I currently intend to resolve Debian bug # 553945 and
> Sourceforge bug # 3214825 in the next version of ttylog.

Hi,

Let me first note that I'm not a Debian Developer and thus cannot really
help you by uploading the package :)  Still, what do you think about the
following comments and suggestions? :)  Of course, it's your package, so
you are free to say you do not like any or all of them; most of those
are just things that I've been doing to my own packages little by
little, just suggestions for yours.

First, I've attached a series of patches to the ttylog upstream:
- if the user has set the standard CPPFLAGS, CFLAGS or LDFLAGS variables
  in the environment, use them instead of -g -O2

- if the user runs ttylog with invalid arguments, exit with a status of
  1, not 0 (not really necessary, just, I don't know, good practice? :)

- a bit stricter checking of command-line arguments:
  - do not try to retrieve the -1st element of an array if there is no
    baud-rate option on the command line
  - check for buffer overflow attempts through a looong modem name :)

- check for errors in tcgetattr(), tcsetattr(), select(), etc.

- fix some compiler warnings if stricter warning options are passed to
  the compiler

- check for some more errors so as to be able to build a hardened
  executable

And then, there are a couple of ideas for the Debian packaging itself:
- switch directly to the 3.0 (quilt) source format - unless, of course,
  you have a reason to stick to 1.0?  If there are no patches to the
  source, it's all the same, except that a recent dpkg-buildpackage will
  generate a IMHO more manageable *_debian.tar.gz instead of *.diff.gz

- bump the debhelper compatibility level to 7 and let dh_clean and
  dh_installchangelogs do their job (they can guess what files to remove
  or install by themselves now :)

- make even better use of debhelper 7 - since your Debian packaging is
  very simple, the rules file may be brought down to only a couple of
  lines by using the dh(1) helper tool

- use the dpkg-buildflags program introduced in dpkg-dev 1.15.7 to
  obtain the default values for CPPFLAGS, CFLAGS and LDFLAGS; besides
  other things, this takes care of e.g. "noopt" being specified in the
  DEB_BUILD_OPTIONS variable
  - note that this patch adds the debian/patches/01-flags.patch to the
    upstream Makefile, which is actually the first patch in the
    "upstream" series above; this might not be necessary if you like
    this change and accept it upstream :)

- build with the -Werror compiler flag if the user requests it by
  specifying "werror" in the DEB_BUILD_OPTIONS variable (useful for
  testing sometimes)

- build with lots of compiler warnings and harden the build using
  the hardening-includes package
  - note that this patch adds the debian/patches/02-cleanup.patch to
    the upstream ttylog.c file, which combines almost all of the patches
    in the "upstream" series above; this might not be necessary if you
    like the changes and accept them upstream :)

- remove the README.Debian file - it only repeats the package's short
  and long description, I don't think that it provides any other useful
  information

- shorten the watch file a bit by removing not-really-needed comments

- convert the copyright file to the latest revision of the
  machine-readable copyright format currently being discussed as Debian
  Enhancement Proposal 5 (DEP 5, http://dep.debian.net/)

- bump the debhelper compatibility level to 8 with no further changes

Thanks for making Debian better by taking care of its packages!

G'luck,
Peter

-- 
Peter Pentchev	roam@ringlet.net roam@FreeBSD.org peter@packetscale.com
PGP key:	http://people.FreeBSD.org/~roam/roam.key.asc
Key fingerprint	FDBA FD79 C26F 3C51 C95E  DF9E ED18 B68D 1619 4553
I am the meaning of this sentence.
From b7f45d61313e4fff7efb5547033808e016f17930 Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 28 Mar 2011 13:53:20 +0300
Subject: [PATCH 1/6] Honor the compiler/linker names and flags.

---
 Makefile |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index e86e813..dfee6ff 100644
--- a/Makefile
+++ b/Makefile
@@ -1,15 +1,15 @@
-CC = gcc
-C_ARGS = -Wall -g -O2
-INS = /usr/bin/install
-GZIP = /bin/gzip
+CC ?= gcc
+CFLAGS ?= -Wall -g -O2
+INS ?= /usr/bin/install
+GZIP ?= /bin/gzip
 
 all:	ttylog
 
 ttylog:	ttylog.o
-		$(CC) $(C_ARGS) -o ttylog ttylog.o
+		$(CC) $(LDFLAGS) -o ttylog ttylog.o
 
 ttylog.o:	ttylog.c
-		$(CC) $(C_ARGS) -c ttylog.c
+		$(CC) $(CPPFLAGS) $(CFLAGS) -c ttylog.c
 
 clean: 
 		rm -f *.o ttylog core *~
-- 
1.7.4.1

From 23703b1ce0f0edb1348ffffb8c7c9f6eb9f36eda Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 28 Mar 2011 13:56:57 +0300
Subject: [PATCH 2/6] Exit with a status 1 on error conditions.

---
 ttylog.c |    8 ++++----
 1 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/ttylog.c b/ttylog.c
index 1bc1fae..bf81e04 100644
--- a/ttylog.c
+++ b/ttylog.c
@@ -52,7 +52,7 @@ main (int argc, char *argv[])
   if (argc < 2)
     {
       printf ("%s: no params. try %s -h\n", argv[0], argv[0]);
-      exit (0);
+      exit (1);
     }
 
   for (i = 1; i < argc; i++)
@@ -89,7 +89,7 @@ main (int argc, char *argv[])
 	  if (baud == -1)
 	    {
 	      printf ("%s: invalid baud rate %s\n", argv[0], argv[i + 1]);
-	      exit (0);
+	      exit (1);
 	    }
 	}
 
@@ -109,7 +109,7 @@ main (int argc, char *argv[])
 
   if (!strlen(modem_device)) {
     printf ("%s: no device is set. Use %s -h for more information.\n", argv[0], argv[0]);
-    exit (0);
+    exit (1);
   }
 
 
@@ -117,7 +117,7 @@ main (int argc, char *argv[])
   if (logfile == NULL)
     {
       printf ("%s: invalid device %s\n", argv[0], modem_device);
-      exit (0);
+      exit (1);
 
     }
   fd = fileno (logfile);
-- 
1.7.4.1

From 49cfba65d5fe508f4007d8d61b55049728d03892 Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 28 Mar 2011 14:02:06 +0300
Subject: [PATCH 3/6] A bit stricter checking of command-line arguments.

---
 ttylog.c |   18 +++++++++++++++++-
 1 files changed, 17 insertions(+), 1 deletions(-)

diff --git a/ttylog.c b/ttylog.c
index bf81e04..ac753df 100644
--- a/ttylog.c
+++ b/ttylog.c
@@ -86,6 +86,11 @@ main (int argc, char *argv[])
 		if (!strcmp (argv[i + 1], BAUD_T[j]))
 		  baud = j;
 	    }
+	  else
+	    {
+	      printf ("%s: the -b option requires an argument\n", argv[0]);
+	      exit(1);
+	    }
 	  if (baud == -1)
 	    {
 	      printf ("%s: invalid baud rate %s\n", argv[0], argv[i + 1]);
@@ -97,10 +102,18 @@ main (int argc, char *argv[])
 	{
 	  if (argv[i + 1] != NULL)
 	    {
+	      snprintf (modem_device, sizeof(modem_device), "%s", argv[i + 1]);
+	      if (strcmp(modem_device, argv[i + 1]) != 0)
+		{
+		  printf ("%s: modem device name too long\n", argv[0]);
+		  exit (1);
+		}
 	      strcpy (modem_device, argv[i + 1]);
 	    }
 	  else
 	    {
+	      printf ("%s: the -d option requires an argument\n", argv[0]);
+	      exit (1);
 	    }
 	}
 
@@ -111,7 +124,10 @@ main (int argc, char *argv[])
     printf ("%s: no device is set. Use %s -h for more information.\n", argv[0], argv[0]);
     exit (1);
   }
-
+  if (baud == -1) {
+    printf ("%s: no baud rate specified\n", argv[0]);
+    exit (1);
+  }
 
   logfile = fopen (modem_device, "rb");
   if (logfile == NULL)
-- 
1.7.4.1

From 14ddf10a632ff957e22207a45464b7afa324086d Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 28 Mar 2011 14:08:16 +0300
Subject: [PATCH 4/6] A bit more error checking on file/device I/O.

---
 ttylog.c |   29 +++++++++++++++++++++++++----
 1 files changed, 25 insertions(+), 4 deletions(-)

diff --git a/ttylog.c b/ttylog.c
index ac753df..db5307a 100644
--- a/ttylog.c
+++ b/ttylog.c
@@ -137,8 +137,17 @@ main (int argc, char *argv[])
 
     }
   fd = fileno (logfile);
+  if (fd == -1)
+    {
+      perror ("Could not obtain the file descriptor for the modem device");
+      exit (1);
+    }
 
-  tcgetattr (fd, &oldtio);	/* save current serial port settings */
+  if (tcgetattr (fd, &oldtio) == -1)	/* save current serial port settings */
+    {
+      perror ("Could not get the modem device's configuration");
+      exit (1);
+    }
   bzero (&newtio, sizeof (newtio));	/* clear struct for new port settings */
 
   newtio.c_cflag = BAUD_B[baud] | CRTSCTS | CS8 | CLOCAL | CREAD;
@@ -146,8 +155,16 @@ main (int argc, char *argv[])
   newtio.c_oflag = 0;
   newtio.c_lflag = ICANON;
 
-  tcflush (fd, TCIFLUSH);
-  tcsetattr (fd, TCSANOW, &newtio);
+  if (tcflush (fd, TCIFLUSH) == -1)
+    {
+      perror ("Could not flush the modem device");
+      exit (1);
+    }
+  if (tcsetattr (fd, TCSANOW, &newtio) == -1)
+    {
+      perror ("Could not configure the modem device");
+      exit (1);
+    }
 
   /* Clear the device */
   FD_ZERO (&rfds);
@@ -167,7 +184,11 @@ main (int argc, char *argv[])
 	}
     }
 
+  if (tcsetattr (fd, TCSANOW, &oldtio) == -1)
+    {
+      perror ("Could not restore the modem device's configuration");
+      exit (1);
+    }
   fclose (logfile);
-  tcsetattr (fd, TCSANOW, &oldtio);
   return 0;
 }
-- 
1.7.4.1

From 17e1f0f8d01242b93df3071563b002db8ff80cb6 Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 28 Mar 2011 14:19:03 +0300
Subject: [PATCH 5/6] Fix some compiler warnings at higher warning levels.

---
 ttylog.c |    7 ++++++-
 1 files changed, 6 insertions(+), 1 deletions(-)

diff --git a/ttylog.c b/ttylog.c
index db5307a..e3040f4 100644
--- a/ttylog.c
+++ b/ttylog.c
@@ -16,6 +16,11 @@
  along with this program; if not, write to the Free Software
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
+
+#define _BSD_SOURCE
+#define _XOPEN_SOURCE	600
+
+#include <sys/select.h>
 #include <sys/stat.h>
 #include <termios.h>
 #include <stdio.h>
@@ -30,7 +35,7 @@
 
 char flush = 0;
 
-char *BAUD_T[] =
+const char *BAUD_T[] =
 {"300", "1200", "2400", "4800", "9600", "19200", "38400", "57600", "115200"};
 
 int BAUD_B[] =
-- 
1.7.4.1

From 3262b4f0c2c1344c59c63eff63a4fefa5e32c6c1 Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 28 Mar 2011 14:27:41 +0300
Subject: [PATCH 6/6] More error checking: fgets() and select().

---
 ttylog.c |   13 ++++++++++---
 1 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/ttylog.c b/ttylog.c
index e3040f4..f233f4e 100644
--- a/ttylog.c
+++ b/ttylog.c
@@ -174,16 +174,23 @@ main (int argc, char *argv[])
   /* Clear the device */
   FD_ZERO (&rfds);
   FD_SET (fd, &rfds);
-  fgets (line, 1024, logfile);
+  if (fgets (line, 1024, logfile) != NULL)
+    {
+      printf ("%s", line);
+    }
 
   while (1)
     {
       FD_ZERO (&rfds);
       FD_SET (fd, &rfds);
       retval = select (fd + 1, &rfds, NULL, NULL, NULL);
-      if (retval)
+      if (retval == -1)
+	{
+	  perror ("Could not select() on the modem device");
+	  break;
+	}
+      else if (retval > 0 && fgets (line, 1024, logfile) != NULL)
 	{
-	  fgets (line, 1024, logfile);
 	  printf ("%s\n", line);
 	  if (flush) { fflush(stdout); }
 	}
-- 
1.7.4.1

From 786f5c1923a2c18a4e8bebe045ebfa095d516b0b Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 28 Mar 2011 13:24:15 +0300
Subject: [PATCH 01/11] Switch to the 3.0 (quilt) source format.

This allows us to build directly from the Git checkout directory :)
---
 debian/source/format |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/debian/source/format b/debian/source/format
index d3827e7..163aaf8 100644
--- a/debian/source/format
+++ b/debian/source/format
@@ -1 +1 @@
-1.0
+3.0 (quilt)
-- 
1.7.4.1

From cc9ba52be6bb02f6eb866128cc174282c523ab7c Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 28 Mar 2011 13:28:26 +0300
Subject: [PATCH 02/11] Bump the debhelper compatibility level to 7.

- dh_clean removes *-stamp automatically now
- dh_installchangelogs knows the name of the changelog file
---
 debian/compat |    2 +-
 debian/rules  |    3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)

diff --git a/debian/compat b/debian/compat
index 7ed6ff8..7f8f011 100644
--- a/debian/compat
+++ b/debian/compat
@@ -1 +1 @@
-5
+7
diff --git a/debian/rules b/debian/rules
index 1a9bb4c..1f1c39d 100755
--- a/debian/rules
+++ b/debian/rules
@@ -23,7 +23,6 @@ build-stamp: configure-stamp
 clean:
 	dh_testdir
 	dh_testroot
-	rm -f build-stamp configure-stamp
 
 	# Add here commands to clean up after the build process.
 	$(MAKE) clean
@@ -49,7 +48,7 @@ binary-arch: build install
 	dh_testdir
 	dh_testroot
 	dh_installdocs
-	dh_installchangelogs ChangeLog
+	dh_installchangelogs
 	dh_link
 	dh_strip
 	dh_compress
-- 
1.7.4.1

From a3986a136bef10dda208d7c8240d1b248fb8e2ac Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 28 Mar 2011 13:33:09 +0300
Subject: [PATCH 03/11] Minimize the rules file using debhelper 7's dh(1) tool.

---
 debian/rules |   59 +--------------------------------------------------------
 1 files changed, 2 insertions(+), 57 deletions(-)

diff --git a/debian/rules b/debian/rules
index 1f1c39d..5f90dbf 100755
--- a/debian/rules
+++ b/debian/rules
@@ -4,60 +4,5 @@
 # Uncomment this to turn on verbose mode.
 export DH_VERBOSE=1
 
-configure: configure-stamp
-configure-stamp:
-	dh_testdir
-	# Add here commands to configure the package.
-	touch configure-stamp
-
-build: build-stamp
-
-build-stamp: configure-stamp 
-	dh_testdir
-
-	# Add here commands to compile the package.
-	$(MAKE)
-	
-	touch build-stamp
-
-clean:
-	dh_testdir
-	dh_testroot
-
-	# Add here commands to clean up after the build process.
-	$(MAKE) clean
-
-	dh_clean
-
-install: build
-	dh_testdir
-	dh_testroot
-	dh_prep
-	dh_installdirs
-
-	# Add here commands to install the package into debian/ttylog.
-	$(MAKE) install DESTDIR=$(CURDIR)/debian/ttylog
-
-
-# Build architecture-independent files here.
-binary-indep: build install
-# We have nothing to do by default.
-
-# Build architecture-dependent files here.
-binary-arch: build install
-	dh_testdir
-	dh_testroot
-	dh_installdocs
-	dh_installchangelogs
-	dh_link
-	dh_strip
-	dh_compress
-	dh_fixperms
-	dh_installdeb
-	dh_shlibdeps
-	dh_gencontrol
-	dh_md5sums
-	dh_builddeb
-
-binary: binary-indep binary-arch
-.PHONY: build clean binary-indep binary-arch binary install configure
+%:
+	dh $@
-- 
1.7.4.1

From 912d50457bcdde0ffe4fbf9066d1ea322426625c Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 28 Mar 2011 13:42:13 +0300
Subject: [PATCH 04/11] Use dpkg-buildflags to obtain the default CPPFLAGS, CFLAGS and LDFLAGS.

This adds a Makefile patch that would look better in the master branch.
---
 debian/control                |    2 +-
 debian/patches/01-flags.patch |   29 +++++++++++++++++++++++++++++
 debian/patches/series         |    1 +
 debian/rules                  |    6 ++++++
 4 files changed, 37 insertions(+), 1 deletions(-)
 create mode 100644 debian/patches/01-flags.patch
 create mode 100644 debian/patches/series

diff --git a/debian/control b/debian/control
index 12f1165..405cf1d 100644
--- a/debian/control
+++ b/debian/control
@@ -2,7 +2,7 @@ Source: ttylog
 Section: utils
 Priority: extra
 Maintainer: Robert James Clay <jame@rocasa.us>
-Build-Depends: debhelper (>= 7)
+Build-Depends: debhelper (>= 7), dpkg-dev (>= 1.15.7~)
 Standards-Version: 3.9.1
 Vcs-Git: git://ttylog.git.sourceforge.net/gitroot/ttylog/ttylog.git
 Vcs-Browser: http://ttylog.git.sourceforge.net/git/gitweb.cgi?p=ttylog/ttylog.git
diff --git a/debian/patches/01-flags.patch b/debian/patches/01-flags.patch
new file mode 100644
index 0000000..f7a87f9
--- /dev/null
+++ b/debian/patches/01-flags.patch
@@ -0,0 +1,29 @@
+Description: Honor compiler/linker names and flags.
+Forwarded: no
+Author: Peter Pentchev <roam@ringlet.net>
+Last-Update: 2011-03-28
+
+--- a/Makefile
++++ b/Makefile
+@@ -1,15 +1,15 @@
+-CC = gcc
+-C_ARGS = -Wall -g -O2
+-INS = /usr/bin/install
+-GZIP = /bin/gzip
++CC ?= gcc
++CFLAGS ?= -Wall -g -O2
++INS ?= /usr/bin/install
++GZIP ?= /bin/gzip
+ 
+ all:	ttylog
+ 
+ ttylog:	ttylog.o
+-		$(CC) $(C_ARGS) -o ttylog ttylog.o
++		$(CC) $(LDFLAGS) -o ttylog ttylog.o
+ 
+ ttylog.o:	ttylog.c
+-		$(CC) $(C_ARGS) -c ttylog.c
++		$(CC) $(CPPFLAGS) $(CFLAGS) -c ttylog.c
+ 
+ clean: 
+ 		rm -f *.o ttylog core *~
diff --git a/debian/patches/series b/debian/patches/series
new file mode 100644
index 0000000..59cece9
--- /dev/null
+++ b/debian/patches/series
@@ -0,0 +1 @@
+01-flags.patch
diff --git a/debian/rules b/debian/rules
index 5f90dbf..7b3fc6c 100755
--- a/debian/rules
+++ b/debian/rules
@@ -4,5 +4,11 @@
 # Uncomment this to turn on verbose mode.
 export DH_VERBOSE=1
 
+CFLAGS:=	$(shell dpkg-buildflags --get CFLAGS)
+CPPFLAGS:=	$(shell dpkg-buildflags --get CPPFLAGS)
+LDFLAGS:=	$(shell dpkg-buildflags --get LDFLAGS)
+
+CFLAGS+=	-Wall
+
 %:
 	dh $@
-- 
1.7.4.1

From 7f875f010b70a1d836a229e6d56e327a1874441f Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 28 Mar 2011 13:44:34 +0300
Subject: [PATCH 05/11] Build with -Werror if requested in DEB_BUILD_OPTIONS.

---
 debian/rules |    3 +++
 1 files changed, 3 insertions(+), 0 deletions(-)

diff --git a/debian/rules b/debian/rules
index 7b3fc6c..708bf1b 100755
--- a/debian/rules
+++ b/debian/rules
@@ -9,6 +9,9 @@ CPPFLAGS:=	$(shell dpkg-buildflags --get CPPFLAGS)
 LDFLAGS:=	$(shell dpkg-buildflags --get LDFLAGS)
 
 CFLAGS+=	-Wall
+ifneq (,$(filter werror,$(DEB_BUILD_OPTIONS)))
+	CFLAGS+=	-Werror
+endif
 
 %:
 	dh $@
-- 
1.7.4.1

From 7a0ff09efd9a07aff9801b4809febdadbd44d9b3 Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 28 Mar 2011 14:34:22 +0300
Subject: [PATCH 06/11] Fix a couple of compiler (and hardening) warnings.

---
 debian/patches/02-cleanup.patch |  168 +++++++++++++++++++++++++++++++++++++++
 debian/patches/series           |    1 +
 debian/rules                    |    5 +-
 3 files changed, 173 insertions(+), 1 deletions(-)
 create mode 100644 debian/patches/02-cleanup.patch

diff --git a/debian/patches/02-cleanup.patch b/debian/patches/02-cleanup.patch
new file mode 100644
index 0000000..4eeb389
--- /dev/null
+++ b/debian/patches/02-cleanup.patch
@@ -0,0 +1,168 @@
+Description: Clean up the ttylog code a bit.
+ - exit with status 1 on error conditions
+ - check command-line arguments stricter
+ - check for errors on file and device I/O
+ - fix some compiler warnings
+Forwarded: no
+Author: Peter Pentchev <roam@ringlet.net>
+Last-Update: 2011-03-28
+
+--- a/ttylog.c
++++ b/ttylog.c
+@@ -16,6 +16,11 @@
+  along with this program; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
++
++#define _BSD_SOURCE
++#define _XOPEN_SOURCE	600
++
++#include <sys/select.h>
+ #include <sys/stat.h>
+ #include <termios.h>
+ #include <stdio.h>
+@@ -30,7 +35,7 @@
+ 
+ char flush = 0;
+ 
+-char *BAUD_T[] =
++const char *BAUD_T[] =
+ {"300", "1200", "2400", "4800", "9600", "19200", "38400", "57600", "115200"};
+ 
+ int BAUD_B[] =
+@@ -52,7 +57,7 @@
+   if (argc < 2)
+     {
+       printf ("%s: no params. try %s -h\n", argv[0], argv[0]);
+-      exit (0);
++      exit (1);
+     }
+ 
+   for (i = 1; i < argc; i++)
+@@ -86,10 +91,15 @@
+ 		if (!strcmp (argv[i + 1], BAUD_T[j]))
+ 		  baud = j;
+ 	    }
++	  else
++	    {
++	      printf ("%s: the -b option requires an argument\n", argv[0]);
++	      exit(1);
++	    }
+ 	  if (baud == -1)
+ 	    {
+ 	      printf ("%s: invalid baud rate %s\n", argv[0], argv[i + 1]);
+-	      exit (0);
++	      exit (1);
+ 	    }
+ 	}
+ 
+@@ -97,10 +107,18 @@
+ 	{
+ 	  if (argv[i + 1] != NULL)
+ 	    {
++	      snprintf (modem_device, sizeof(modem_device), "%s", argv[i + 1]);
++	      if (strcmp(modem_device, argv[i + 1]) != 0)
++		{
++		  printf ("%s: modem device name too long\n", argv[0]);
++		  exit (1);
++		}
+ 	      strcpy (modem_device, argv[i + 1]);
+ 	    }
+ 	  else
+ 	    {
++	      printf ("%s: the -d option requires an argument\n", argv[0]);
++	      exit (1);
+ 	    }
+ 	}
+ 
+@@ -109,20 +127,32 @@
+ 
+   if (!strlen(modem_device)) {
+     printf ("%s: no device is set. Use %s -h for more information.\n", argv[0], argv[0]);
+-    exit (0);
++    exit (1);
++  }
++  if (baud == -1) {
++    printf ("%s: no baud rate specified\n", argv[0]);
++    exit (1);
+   }
+-
+ 
+   logfile = fopen (modem_device, "rb");
+   if (logfile == NULL)
+     {
+       printf ("%s: invalid device %s\n", argv[0], modem_device);
+-      exit (0);
++      exit (1);
+ 
+     }
+   fd = fileno (logfile);
++  if (fd == -1)
++    {
++      perror ("Could not obtain the file descriptor for the modem device");
++      exit (1);
++    }
+ 
+-  tcgetattr (fd, &oldtio);	/* save current serial port settings */
++  if (tcgetattr (fd, &oldtio) == -1)	/* save current serial port settings */
++    {
++      perror ("Could not get the modem device's configuration");
++      exit (1);
++    }
+   bzero (&newtio, sizeof (newtio));	/* clear struct for new port settings */
+ 
+   newtio.c_cflag = BAUD_B[baud] | CRTSCTS | CS8 | CLOCAL | CREAD;
+@@ -130,28 +160,47 @@
+   newtio.c_oflag = 0;
+   newtio.c_lflag = ICANON;
+ 
+-  tcflush (fd, TCIFLUSH);
+-  tcsetattr (fd, TCSANOW, &newtio);
++  if (tcflush (fd, TCIFLUSH) == -1)
++    {
++      perror ("Could not flush the modem device");
++      exit (1);
++    }
++  if (tcsetattr (fd, TCSANOW, &newtio) == -1)
++    {
++      perror ("Could not configure the modem device");
++      exit (1);
++    }
+ 
+   /* Clear the device */
+   FD_ZERO (&rfds);
+   FD_SET (fd, &rfds);
+-  fgets (line, 1024, logfile);
++  if (fgets (line, 1024, logfile) != NULL)
++    {
++      printf ("%s", line);
++    }
+ 
+   while (1)
+     {
+       FD_ZERO (&rfds);
+       FD_SET (fd, &rfds);
+       retval = select (fd + 1, &rfds, NULL, NULL, NULL);
+-      if (retval)
++      if (retval == -1)
++	{
++	  perror ("Could not select() on the modem device");
++	  break;
++	}
++      else if (retval > 0 && fgets (line, 1024, logfile) != NULL)
+ 	{
+-	  fgets (line, 1024, logfile);
+ 	  printf ("%s\n", line);
+ 	  if (flush) { fflush(stdout); }
+ 	}
+     }
+ 
++  if (tcsetattr (fd, TCSANOW, &oldtio) == -1)
++    {
++      perror ("Could not restore the modem device's configuration");
++      exit (1);
++    }
+   fclose (logfile);
+-  tcsetattr (fd, TCSANOW, &oldtio);
+   return 0;
+ }
diff --git a/debian/patches/series b/debian/patches/series
index 59cece9..e3b8eb1 100644
--- a/debian/patches/series
+++ b/debian/patches/series
@@ -1 +1,2 @@
 01-flags.patch
+02-cleanup.patch
diff --git a/debian/rules b/debian/rules
index 708bf1b..67ee9b7 100755
--- a/debian/rules
+++ b/debian/rules
@@ -8,7 +8,10 @@ CFLAGS:=	$(shell dpkg-buildflags --get CFLAGS)
 CPPFLAGS:=	$(shell dpkg-buildflags --get CPPFLAGS)
 LDFLAGS:=	$(shell dpkg-buildflags --get LDFLAGS)
 
-CFLAGS+=	-Wall
+CFLAGS+=	-pipe -Wall -W -ansi -pedantic -Wbad-function-cast \
+		-Wcast-align -Wcast-qual -Wchar-subscripts -Winline \
+		-Wmissing-prototypes -Wnested-externs -Wpointer-arith \
+		-Wredundant-decls -Wshadow -Wstrict-prototypes -Wwrite-strings
 ifneq (,$(filter werror,$(DEB_BUILD_OPTIONS)))
 	CFLAGS+=	-Werror
 endif
-- 
1.7.4.1

From 643a91eb6e1bf0b089c0d71662d9151d3670b06a Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 28 Mar 2011 14:35:02 +0300
Subject: [PATCH 07/11] Harden the build unless "nohardening" is specified in DEB_BUILD_OPTIONS.

---
 debian/control |    2 +-
 debian/rules   |    8 ++++++++
 2 files changed, 9 insertions(+), 1 deletions(-)

diff --git a/debian/control b/debian/control
index 405cf1d..1ce22a7 100644
--- a/debian/control
+++ b/debian/control
@@ -2,7 +2,7 @@ Source: ttylog
 Section: utils
 Priority: extra
 Maintainer: Robert James Clay <jame@rocasa.us>
-Build-Depends: debhelper (>= 7), dpkg-dev (>= 1.15.7~)
+Build-Depends: debhelper (>= 7), dpkg-dev (>= 1.15.7~), hardening-includes
 Standards-Version: 3.9.1
 Vcs-Git: git://ttylog.git.sourceforge.net/gitroot/ttylog/ttylog.git
 Vcs-Browser: http://ttylog.git.sourceforge.net/git/gitweb.cgi?p=ttylog/ttylog.git
diff --git a/debian/rules b/debian/rules
index 67ee9b7..387cdf1 100755
--- a/debian/rules
+++ b/debian/rules
@@ -16,5 +16,13 @@ ifneq (,$(filter werror,$(DEB_BUILD_OPTIONS)))
 	CFLAGS+=	-Werror
 endif
 
+include /usr/share/hardening-includes/hardening.make
+ifeq (,$(filter nohardening,$(DEB_BUILD_OPTIONS)))
+CFLAGS+=	$(HARDENING_CFLAGS)
+LDFLAGS+=	$(HARDENING_LDFLAGS)
+endif
+
+export CPPFLAGS CFLAGS LDFLAGS
+
 %:
 	dh $@
-- 
1.7.4.1

From 614c3e9d17423a351ba1a9196ce01d903b1fa6f5 Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 28 Mar 2011 14:35:41 +0300
Subject: [PATCH 08/11] Remove the README.Debian file that only repeats the package description.

---
 debian/README.Debian |    6 ------
 1 files changed, 0 insertions(+), 6 deletions(-)
 delete mode 100644 debian/README.Debian

diff --git a/debian/README.Debian b/debian/README.Debian
deleted file mode 100644
index 19fada1..0000000
--- a/debian/README.Debian
+++ /dev/null
@@ -1,6 +0,0 @@
-ttylog for Debian
-----------------------
-
-Print everything onto stdout comes from a serial device.
-
-Tibor Koleszar <oldw@debian.org>, Fri,  4 Jun 1999 10:20:26 +0200
-- 
1.7.4.1

From fd74c537073259151be478260e636fffb37be900 Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 28 Mar 2011 14:36:05 +0300
Subject: [PATCH 09/11] Shorten the watch file a bit.

---
 debian/watch |    5 -----
 1 files changed, 0 insertions(+), 5 deletions(-)

diff --git a/debian/watch b/debian/watch
index 6daa0f9..f251080 100644
--- a/debian/watch
+++ b/debian/watch
@@ -1,8 +1,3 @@
 # ttylog watch control file for uscan
-
-# Compulsory line, this is a version 3 file
 version=3
-
-# Check at sourceforge for new ttylog versions,
-# for devscripts >= 2.9
 http://sf.net/ttylog/ttylog-(.*)\.tar\.gz
-- 
1.7.4.1

From 18dde1e38d060b8c54edea8bb263ed9865df45b1 Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 28 Mar 2011 14:40:46 +0300
Subject: [PATCH 10/11] Convert the copyright file to DEP 5 rev. 173.

---
 debian/copyright |   42 +++++++++++++++++++++---------------------
 1 files changed, 21 insertions(+), 21 deletions(-)

diff --git a/debian/copyright b/debian/copyright
index b687d37..8f0ce54 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -1,36 +1,36 @@
-This package was debianized by Tibor Koleszar <oldw@debian.org> on
-Fri,  4 Jun 1999 10:20:26 +0200.
+Format: http://svn.debian.org/wsvn/dep/web/deps/dep5.mdwn?op=file&rev=173
+Upstream-Name: ttylog
+Upstream-Contact: Robert James Clay <jame@rocasa.us>
+Source: http://ttylog.sourceforge.net
+License: GPL-2+
 
+Files: *
 Copyright:
+   1999-2002 Tibor Koleszar <oldw@debian.org>
+   2008-2011 Robert James Clay <jame@rocasa.us>
+License: GPL-2+
 
- Copyright 1999-2002 Tibor Koleszar <oldw@debian.org>
- Copyright 2008-2011 Robert James Clay <jame@rocasa.us>
-
-License:
+Files: debian/*
+Copyright:
+   Copyright 1999-2002 Tibor Koleszar <oldw@debian.org>
+   Copyright   2006    Andrew Pollock <apollock@debian.org>
+   Copyright 2008-2011 Robert James Clay <jame@rocasa.us>
+License: GPL-2+
 
+License: GPL-2+
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.
-
+   .
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
-
+   .
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Boston, MA  02111-1301, USA.
-
-On Debian systems, the full text of the GPL can be found at
-/usr/share/common-licenses/GPL-2
-
-
-# The license for the Debian packaging is GPL-2, see above, and the 
-Copyright is as follows:
-
-   Copyright 1999-2002 Tibor Koleszar <oldw@debian.org>
-   Copyright   2006    Andrew Pollock <apollock@debian.org>
-   Copyright 2008-2011 Robert James Clay <jame@rocasa.us>
-
-
+   .
+   On Debian systems, the full text of the GPL can be found at
+   /usr/share/common-licenses/GPL-2
-- 
1.7.4.1

From de9bdcf2d8f5ddd64ea448c94c5b025d045e1c00 Mon Sep 17 00:00:00 2001
From: Peter Pentchev <roam@ringlet.net>
Date: Mon, 28 Mar 2011 15:00:31 +0300
Subject: [PATCH 11/11] Bump the debhelper compat level to 8 with no further changes.

---
 debian/compat  |    2 +-
 debian/control |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/debian/compat b/debian/compat
index 7f8f011..45a4fb7 100644
--- a/debian/compat
+++ b/debian/compat
@@ -1 +1 @@
-7
+8
diff --git a/debian/control b/debian/control
index 1ce22a7..05df314 100644
--- a/debian/control
+++ b/debian/control
@@ -2,7 +2,7 @@ Source: ttylog
 Section: utils
 Priority: extra
 Maintainer: Robert James Clay <jame@rocasa.us>
-Build-Depends: debhelper (>= 7), dpkg-dev (>= 1.15.7~), hardening-includes
+Build-Depends: debhelper (>= 8), dpkg-dev (>= 1.15.7~), hardening-includes
 Standards-Version: 3.9.1
 Vcs-Git: git://ttylog.git.sourceforge.net/gitroot/ttylog/ttylog.git
 Vcs-Browser: http://ttylog.git.sourceforge.net/git/gitweb.cgi?p=ttylog/ttylog.git
-- 
1.7.4.1

Attachment: signature.asc
Description: Digital signature


Reply to: