ports/81481: portmanage maybe fflush(3) before system(3) and isatty(3) before mod. xterm title

Ove Svensson ove.svensson at rixmail.se
Wed May 25 21:20:20 UTC 2005


>Number:         81481
>Category:       ports
>Synopsis:       portmanage maybe fflush(3) before system(3) and isatty(3) before mod. xterm title
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-ports-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          update
>Submitter-Id:   current-users
>Arrival-Date:   Wed May 25 21:20:18 GMT 2005
>Closed-Date:
>Last-Modified:
>Originator:     Ove Svensson
>Release:        FreeBSD 5.4-STABLE i386
>Organization:
>Environment:
portmanager-0.2.9_4
System: FreeBSD oves 5.4-STABLE FreeBSD 5.4-STABLE #0: Thu May 19 21:19:36 CEST 2005 root at oves:/usr/obj/usr/src/sys/MY_5_STABLE_050519 i386


>Description:
In some situations, when re-directing the output from portmanager, e.g., 
portmanager -sl | more, the output doesn't come out as expected

Also, portmanager attempts to modify the xterm title, even when output is 
re-directed, resulting in escape sequences in the output.

>How-To-Repeat:
For example
$ portmanager -sl
========================================================================
PMGRrShowLeaves 0.2.9_4 info: Creating inital data bases
------------------------------------------------------------------------
------------------------------------------------------------------------
Ports with no ports depending on them AKA "leaf ports."
These ports may be safely deinstalled because no other ports rely on them."
------------------------------------------------------------------------
portmanager-0.2.9_4 dir -=> /usr/ports/sysutils/portmanager
COMMENT=                FreeBSD installed ports status and safe update utility

But, when redirecting you get
$ portmanager -sl | more
COMMENT=                FreeBSD installed ports status and safe update utility
========================================================================
PMGRrShowLeaves 0.2.9_4 info: Creating inital data bases
------------------------------------------------------------------------
------------------------------------------------------------------------
Ports with no ports depending on them AKA "leaf ports."
These ports may be safely deinstalled because no other ports rely on them."
------------------------------------------------------------------------
portmanager-0.2.9_4 dir -=> /usr/ports/sysutils/portmanager


>Fix:
A possible solution would be to fflush(stdout) before each call to system.
To fix the modification of xterm title, even when redirecting, one can
test isatty(fileno(stdout)) before printing the escape sequence.
Included is a patch for doing this

diff -ruN ./libPMGR/src/PMGRrDoUpgrade.c /tmp/portmanager-0.2.9-modified/libPMGR/src/PMGRrDoUpgrade.c
--- ./libPMGR/src/PMGRrDoUpgrade.c	Tue May 24 16:16:19 2005
+++ /tmp/portmanager-0.2.9-modified/libPMGR/src/PMGRrDoUpgrade.c	Tue May 24 16:21:26 2005
@@ -249,6 +249,7 @@
 									idx, property->fieldInstalledPortName ) );		
 
 						fprintf( stdout, "executing: %s\n", command );
+                                                while( fflush( stdout ) );
 						errorCode	= system( command );
 						while( fflush( stdout ) );
 					}
diff -ruN ./libPMGR/src/PMGRrReadConfigure.c /tmp/portmanager-0.2.9-modified/libPMGR/src/PMGRrReadConfigure.c
--- ./libPMGR/src/PMGRrReadConfigure.c	Thu Feb 17 18:39:55 2005
+++ /tmp/portmanager-0.2.9-modified/libPMGR/src/PMGRrReadConfigure.c	Tue May 24 16:21:26 2005
@@ -96,6 +96,7 @@
 		fprintf( stdout, "moving %s to %s%s\n", configFileNameOld, configFileNameOld, "_OLD" );
 		fprintf( stdout, "portmanager configuration file is now called %s. Please review %s%s and %s and make any nessesary changes.\n",
 			property->configConfFileName, property->configConfFileName, ".SAMPLE", configFileNameOld);
+                while( fflush( stdout ) );
 		system( command );		
 
 		/*zzzzzzzzzzzzzz*/
@@ -131,6 +132,7 @@
 		strcat( command, property->configConfFileName );
 		strcat( command, ".SAMPLE " );
 		strcat( command, property->configConfFileName );
+                while( fflush( stdout ) );
 		system( command );
 
 		/*zzzzzzzzzzzzzz*/
@@ -174,6 +176,7 @@
 	{
 		fprintf( stdout, "%s %s DEBUG (54): command = %s\n", id, VERSION, command );		
 	}
+        while( fflush( stdout ) );
 	system( command );
 
 	configDbFileSize	= MGrFileSize(  property->configDbFileName );
diff -ruN ./libPMGR/src/PMGRrShowLeaves.c /tmp/portmanager-0.2.9-modified/libPMGR/src/PMGRrShowLeaves.c
--- ./libPMGR/src/PMGRrShowLeaves.c	Thu Feb 17 18:39:55 2005
+++ /tmp/portmanager-0.2.9-modified/libPMGR/src/PMGRrShowLeaves.c	Tue May 24 16:21:26 2005
@@ -74,6 +74,7 @@
 			strcpy( command, "grep COMMENT " );
 			strcat( command, leafPortDir );
 			strcat( command, "/Makefile" );
+                        while( fflush( stdout ) );
 			system( command );
 			free(command);
 			fprintf( stdout, "\n" );
diff -ruN ./libPMGR/src/PMGRrShowLeavesDelete.c /tmp/portmanager-0.2.9-modified/libPMGR/src/PMGRrShowLeavesDelete.c
--- ./libPMGR/src/PMGRrShowLeavesDelete.c	Tue May 24 16:16:19 2005
+++ /tmp/portmanager-0.2.9-modified/libPMGR/src/PMGRrShowLeavesDelete.c	Tue May 24 16:21:26 2005
@@ -81,6 +81,7 @@
 		{
 			if( key != 10 )
 			{
+                                while( fflush( stdout ) );
 				system( "clear" );
 				fprintf( stdout,"%s\n", SINGLE_LINES );
 				fprintf( stdout, "Ports with no ports depending on them AKA \"leaf ports.\"\n" );
@@ -104,6 +105,7 @@
 					command[0]	= 0;
 					strcat( command, "cat " );
 					strcat( command, pkgDescFile );
+                                        while( fflush( stdout ) );
 					system( command );
 					free( pkgDescFile );
 					free( command );
@@ -119,6 +121,7 @@
 					strcat( command, "grep COMMENT " );
 					strcat( command, leafPortDir );
 					strcat( command, "/Makefile" );
+                                        while( fflush( stdout ) );
 					system( command );
 					free(command);
 				}
@@ -207,6 +210,7 @@
 	strcat( command, "pkg_delete -f " );
 	strcat( command, leafPortName );
 	fprintf( stdout, "\nexecuting: %s\n", command );
+        while( fflush( stdout ) );
 	system( command );
 	free(command);
 
@@ -228,6 +232,7 @@
 	strcat( command, leafPortDir );
 	strcat( command, ";make distclean" );
 	fprintf( stdout, "\nexecuting: %s\n", command );
+        while( fflush( stdout ) );
 	system( command );
 	free(command);
 
diff -ruN ./libPMGR/src/PMGRrStatus.c /tmp/portmanager-0.2.9-modified/libPMGR/src/PMGRrStatus.c
--- ./libPMGR/src/PMGRrStatus.c	Tue May 24 16:16:19 2005
+++ /tmp/portmanager-0.2.9-modified/libPMGR/src/PMGRrStatus.c	Tue May 24 16:21:26 2005
@@ -130,6 +130,7 @@
 			strcat( command, installedPortName );
 			fprintf( stdout,"%s\n", command );
 			fprintf( stdout,"%s\n", SINGLE_LINES );
+                        while( fflush( stdout ) );
 			system( command );
 			free( command );
 			/* since installedPortName is no longer in ports collection need to delete record and restart */
diff -ruN ./libPMGR/src/PMGRrUpgrade.c /tmp/portmanager-0.2.9-modified/libPMGR/src/PMGRrUpgrade.c
--- ./libPMGR/src/PMGRrUpgrade.c	Tue May 24 16:16:19 2005
+++ /tmp/portmanager-0.2.9-modified/libPMGR/src/PMGRrUpgrade.c	Tue May 24 16:21:26 2005
@@ -87,7 +87,7 @@
 	(int)percentDone, QTY_outOfDatePortsDb-1, TOTAL_outOfDatePortsDb );
 		while( fflush( stdout ) );
 
-		if( !strncmp( getenv("TERM"), "xterm", 5 ) )
+		if( !strncmp( getenv("TERM"), "xterm", 5 ) && isatty(fileno(stdout)) )
 		{
 			stringSize	= strlen( id )
 					+ strlen( " done:%" )
@@ -109,7 +109,7 @@
 			/*
 			 *  Set xterm title bar indicator
 			 */
-			if( !strncmp( getenv("TERM"), "xterm", 5 ) )
+			if( !strncmp( getenv("TERM"), "xterm", 5 ) && isatty(fileno(stdout)) )
 			{
 				stringSize	= strlen( id )
 						+ strlen( " finished" )
diff -ruN ./portmanager/portmanager.c /tmp/portmanager-0.2.9-modified/portmanager/portmanager.c
--- ./portmanager/portmanager.c	Tue May 24 16:16:19 2005
+++ /tmp/portmanager-0.2.9-modified/portmanager/portmanager.c	Tue May 24 16:21:26 2005
@@ -134,7 +134,7 @@
 	/*
 	 * set xterm title
 	 */
-	if( !strncmp( getenv("TERM"), "xterm", 5 ) )
+	if( !strncmp( getenv("TERM"), "xterm", 5 ) && isatty(fileno(stdout)) )
 	{
 		stringSize	= strlen( id )
 				+ 1
@@ -247,6 +247,7 @@
 			strcat( command, "rm -f " );
 			strcat( command, property.cacheDbFileName );
 			fprintf( stdout, "%s %s info: executing %s\n", id, VERSION, command );
+                        while( fflush( stdout ) );
 			system( command );
 			free( command ); 
 
@@ -266,6 +267,7 @@
 			strcat( command, "rm -f " );
 			strcat( command, property.cacheDbFileName );
 			fprintf( stdout, "%s %s info: executing %s\n", id, VERSION, command );
+                        while( fflush( stdout ) );
 			system( command );
 			free( command ); 
 

>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the freebsd-ports-bugs mailing list