What is the use of #define _REENTRANT in my code?

 
0
 

Hi,
I am having problems with my C++ Programs on Sun Solaris server since I have upgraded my C++ compiler from Sun Forte Developer 7 compiler to Sun Studio 9 C++ complier 5.6.

I have my own string class which I had issues but now compiles ok after puting option -library=iostream in my makefile.

My string library make file has " /opt/SUNWspro/bin/CC -g -xs -xar -library=iostream -YP " options wwhile compiling.

After creating my libraries, I compiled my main C++ program, which compiles OK but when I execute I get following error.

"getfile: syntax error at line 2 : `newline or ;' unexpected"

getfile.c is my c++ program which has following code at the start.
-------------------------------------------------
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <iostream.h>
#include <cmqc.h>
#define _REENTRANT
#include <string.h>
#include <wait.h>
#include <sys/wait.h>
-----------------------------------------------------
I can't understand where in line 2 I am having errors.

If I remove _REENTRANT then I get the following error
"The function "strtok_r" must have a prototype." which I have used in my code in the same getfile.c program.

Any suggestions comments will be very much appreciated.

Thanks
Ravi

 
0
 

If it is your code, and you wrote that line, how come you are asking us what the meaning of that particular line is? Anyway, judging from the meaning of the word Re-entrant, that would mean that this program is designed to be run in multiple threads, and very well maybe a compiler specific flag. You better refer the compiler documentation or the program documentation if it was not written by you. Anyother things would be difficult to say unless we see the relevant source code.

 
0
 

If it is your code, and you wrote that line, how come you are asking us what the meaning of that particular line is? Anyway, judging from the meaning of the word Re-entrant, that would mean that this program is designed to be run in multiple threads, and very well maybe a compiler specific flag. You better refer the compiler documentation or the program documentation if it was not written by you. Anyother things would be difficult to say unless we see the relevant source code.

Thanks for the prompt reply.
I have written the code few years back and copied most of it from HP Server earlier. I know _REENTRANT does in a sence that it allows the program to be multi threaded. But I could not understand when I removed it why I am geting the strtok error.
When I live it the REENTRANT code the program compiles without any errors/warnings but when I execute it it gives error at line 2
"getfile: syntax error at line 2 : `newline or ;' unexpected"
which I cann;t understand.
I have enclosed the getfile.c code which has lot of MQ related code and my own local include files, but if you look at the code there is nothing wrong at line 2.
Any more suggestions.
Thanks
Ravi

Attachments getfile.c (23.82 KB)
The attachment preview is chopped off after the first 10 KB. Please download the entire file.
// ---------------------------------------------------------------------
// FILE
//	cmms_to_unisys.C
//
// MODULE
//	cmms_to_unisys
//
// DESCRIPTION
//	Process transactional message file.
//
// COMMAND LINE
//
// NOTES
//
// MODIFICATION HISTORY
//	31-Jun-03	RB	Written by Ravi Bhave
//	18-Feb-04	RB  Added ftp check to make sure the file is put to SYS.
//	15-Jun-04   RB  Puts empty file back to IBM even we have ftp errors.
//	07-Apr-05	RB  Added 2nd attempt for ftp upload to sys004.
//
// REVISION CONTROL
// ------------------------------------------------------------------------
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <iostream.h>
#include <cmqc.h>
//#define _REENTRANT
#include <string.h>
#include <wait.h>
#include <sys/wait.h>
#include <imqi.hpp> //MQSeries MQI
#include <cmqc.h>
#include "apperror.h"
#include "appswitch.h"
#include "array.h"
#include "errlog.h"
#include "general.h"
#include "datetime.h"
#include "infolog.h"
#include "cmms_files.h"
#include "ini_file.h"
#include "file_utils.h"
#include "file_base.h"
#include "socket_recv.h"
#include "process_check.h"
#include "signal_handler.h"

static void MainInit(int argc, char *argv[]);
static void MainProcess(void);
static void MainFinish(void);
static void LoadIniFile( void );

static InfoLog_c InfoLog;
static const int MAX_NUM_PROBLEM_FILES = 4;	// after processing
static int MinAge = 60;
static int CycleInterval = 60;
static FileBase_c       OutFile;
static String line;
int	Idx = 0;
static SocketDgram_c        IPC_Out;

static Array_c<String> QMgrName;
static Array_c<String> MqName;
static Array_c<String> IbmHost;
static Array_c<String> IbmUser;
static Array_c<String> IbmPasswd;
static Array_c<String> MqFile;
static Array_c<String> IbmDir;
static Array_c<String> UnisysFileName;
static Array_c<int> RepeatFtp;
static Array_c<String> DestHost;
static Array_c<String> UnisysUser;
static Array_c<String> UnisysPwd;
static Array_c<String> Message;
static Array_c<String> QMessage;
static String MQNAME;
static String QMGRNAME;

ImqQueueManager			Mgr;	// Queue Manager.
ImqQueue				Queue;	// Queue.	
//ImqMessage * holdmsg = new ImqMessage;	// Data message;
ImqMessage 				holdmsg;	// Data message;

String	MQFILENAME;
String	IBMHOST;
String	IBMUSER;
String	IBMPASSWD;
//String	IBMDIR;
String	UNISYSFILENAME;
String	UNISYSUSER;
String	UNISYSPWD;
String	DESTHOST;
int	REPEATFTP;

int MqLength;
static String UnisysUserName;
static String UnisysPassword;
static String UnisysHostName;
static String UnisysPortName;
static String RHost;
static String RLoginName;
static String RPassword;
bool_t Destruct( FALSE );
bool_t FtpError( FALSE );

AppErr_t MqGet( int MQLENGTH , bool_t Destruct );
AppErr_t GetDataFile( String MqFileName );

int main(int argc, char *argv[])
{
cout << "line 109 " << endl;
	int	ExitCode = 0;
	try {
		MainInit( argc, argv );
		MainProcess();
		MainFinish();
		return ( ExitCode );
	}
	catch ( char *Mesg ) {
		ErrLogWrite( EL_SYS, "Exception: %s", Mesg );
		ExitCode = -1;
	}
	catch ( const char *Mesg ) {
		ErrLogWrite( EL_SYS, "Exception: %s", Mesg );
		ExitCode = -1;
	}
	catch ( String &Str ) {
		ErrLogWrite( EL_SYS, "Exception: %s", Str.Get() );
		ExitCode = -1;
	}
	// Thow 0 for a normal exit:
	catch ( AppErr_t AppStatus ) {
		ExitCode = (int) AppStatus;
	}
	// Thow 0 for a normal exit:
	catch ( int ExitStatus ) {
		ExitCode = ExitStatus;
		// This is the only case where we don't execute MainFinish()
		// and is only used when we request SWITCH_HELP for an option
		if ( ExitCode == -1 ) {
			return ( ExitCode );
		}
	}
	catch ( ... ) {
		ErrLogWriteErrno( EL_SYS, UNKNOWN_EXCEPTION );
		ExitCode = -1;
	}
	// Always execute MainFinish after a throw():
	MainFinish();
	return ( ExitCode );
}

// ------------------------------------------------------------------//
//				***MainInit***		     						 //
// ------------------------------------------------------------------//

void MainInit(int argc, char *argv[])
{
	cout << "line 156 " << endl;
	ErrLogWrite( EL_SYS, String( "Main Init Socket: " ) << GetSocketName() );
	SetProgramName( basename( argv[0] ) );
	SetUserName();
	TestingOff();
	ErrLogInit( GetProgramName(), GetUserName() );
	String OptionList;
	OptionList << ":" <<
		SWITCH_HELP <<
		SWITCH_TESTING <<
		SWITCH_DEBUG_ON <<
		SWITCH_DEBUG_NAME << ":" <<
		SWITCH_DO_NOT_MOVE <<
		SWITCH_MIN_AGE << ':' <<
		SWITCH_BACKGROUND << ':' << 
		SWITCH_SOCKET << ':'
		;
	int OptErr = 0;
	char Option;
	while( (Option = getopt(argc, argv, OptionList.Get())) != -1 ) {
		switch ( Option ) {
			case SWITCH_HELP :
				OptErr = -1;
				break;
			case SWITCH_TESTING :
				TestingOn();
				break;
			case SWITCH_DEBUG_ON :
				DbgInit( GetProgramName() );
				break;
			case SWITCH_SOCKET :
           		SetSocketName( optarg );
           		if ( DbgIsEnabled() ) {
           			DbgInit( GetSocketName() );
           		}
           		break;
			case ':' :
				ErrLogWrite( EL_SYS, String( "Option -" ) <<
				(char) optopt << " supplied with no argument" );
				OptErr++;
				break;
			case '?' :
				ErrLogWrite( EL_SYS, String( "Invalid option -" ) <<
				(char) optopt );
				OptErr++;
				break;
			default :
				ErrLogWrite( EL_SYS,
				"getopt() returned unexpected option -%c",(char)optopt );
				OptErr++;
				break;
		}
		if ( OptErr ) {
			cerr << "Usage: " << basename( argv[0] )
				<< " [-" << SWITCH_DEBUG_ON << "]"
				<< " [-" << SWITCH_DEBUG_NAME << " name]"
				<< " [-" << SWITCH_SOCKET << " socket_name]"
				<< " [-" << SWITCH_DB_CONNECT << " connect-string]"
				<< " [-" << SWITCH_ORACLE_SERVICE << " oracle-service]"
				<< " [-" << SWITCH_MIN_AGE << " file-age]"
				<< " [-" << SWITCH_CYCLE_TIME << " retry-time]"
				<< " [-" << SWITCH_BACKGROUND << "]"
				<< "\n"
				<< "\t-" << SWITCH_DEBUG_ON
				<< "  Turn debugging on\n"
				<< "\t-" << SWITCH_DEBUG_NAME
				<< "  Turn debug on to program with socket set to <name>\n"
				<< "\t-" << SWITCH_DB_CONNECT
				<< "  Connect to database with <connect-string>.\n"
				<< "\t\tDefaults to ORACLE_CONNECT_STRING env variable.\n"
				<< "\t-" << SWITCH_ORACLE_SERVICE
				<< "  Connect to database with service <oracle-service>.\n"
				<< "\t\tDefaults to ORACLE_SERVICE env variable.\n"
				<< "\t-" << SWITCH_MIN_AGE
				<< "  Mininum file age in seconds\n"
				<< "\t-" << SWITCH_CYCLE_TIME
				<< "  Sleep for this many minutes between runs\n"
				<< "\t-" << SWITCH_BACKGROUND
				<< "  Don't run in background\n"
				<< flush;
			// Special case of just displaying the Usage info:
			if ( OptErr == -1 ) {
				throw( -1 );
			}
			String CmdLine( ": " );
			int argCount = argc;
			char **argPointer = argv;
			while ( argCount-- > 0 ) {
				CmdLine << *argPointer++ << " ";
			}
			throw( String( INVALID_COMMAND_LINE ) << CmdLine );
		}
	}				
	// Check that we are the only one using the socket:
	// Make sure we are the only copy running with this socket:
	if ( IsSocketUsed( GetSocketName() ) ) {
		ErrLogWrite( EL_SYS, String( "Socket: " ) << GetSocketName() <<
				" is already in use." );
		throw ( FAIL );
	}
	SetProgramName(GetSocketName());
    	// Read the INI file:
	LoadIniFile( );

	ErrLogWrite( EL_INFO, PROGRAM_STARTED );

	// Always catch SIGTERM as this is the mechanism to terminate in an
	//	orderly manner:
	SH_Catch( SIGTERM );
	SH_Catch( SIGINT );
	
	return;
}

// ------------------------------------------------------------------//
//				***MainProcess***		     						 //
// ------------------------------------------------------------------//
void MainProcess()
{
	int i;
	int j;
	for( i = 0 ; i < Idx ; i++ ) {
		Mgr.setName(QMgrName[i].Get());
		Queue.setName( MqName[i].Get());
		//ErrLogWrite( EL_SYS, "QName before get %s", MqName[i].Get());
		if ( MqGet( MqLength, Destruct ) == SUCCESS ) {
			for ( j = 0 ; j < Message.GetNumItems(); j++ ) {
				//ErrLogWrite(EL_SYS, "Messages %s:%s", QMessage[j].Get(), Message[i].Get());
				if ( QMessage[j] == Message[i] ) {
					QMessage.Delete(j);
					MQFILENAME = MqFile[i];
					UNISYSFILENAME = UnisysFileName[i];
					IBMHOST = IbmHost[i];
					IBMUSER = IbmUser[i];
					IBMPASSWD = IbmPasswd[i];
					UNISYSUSER = UnisysUser[i];
					UNISYSPWD = UnisysPwd[i];
					REPEATFTP = RepeatFtp[i];
					DESTHOST = DestHost[i];
					if( GetDataFile(MQFILENAME) == SUCCESS ) {
						// MQGET DESTRUCTIVELY;
						Destruct = TRUE;
						if( MqGet( MqLength, Destruct ) == SUCCESS ) {
							ErrLogWrite(EL_SYS, "Message removed destructively from the queue.");
						    exit(0);
						}
						else {
							ErrLogWrite( EL_SYS, "Could not remove the message destructively from the queue. Try again.");
							MqGet(MqLength, Destruct);
				
						}
					}
					else {
						ErrLogWrite( EL_SYS,"Message on the queue matched but could not get the datafile.");
						Destruct = FALSE;
						break;
					}
				}
				// Increment as we are breaking from outer for loop. 
				i++;
			}
			break;
		}
		
	}
	if ( Destruct != TRUE ) {
		Destruct = TRUE;
		if ( MqGet( MqLength, Destruct ) == SUCCESS ) {
			if ( FtpError == FALSE ) {
				ErrLogWrite(EL_SYS,"Unmatched message on the queue %s removed :%s", QMessage[j].Get(),Message[i].Get());
			}
			else {
				ErrLogWrite(EL_SYS,"FTP Error, removed the message from the queue %s", QMessage[j].Get());
				FtpError = FALSE;
			}
		}
		else {
			ErrLogWrite(EL_SYS,"No message on the queue", QMessage[j].Get());
		}
	}
	return;
}


// ------------------------------------------------------------------//
//				***MainFinish***		     						 //
// ------------------------------------------------------------------//
void MainFinish()
{
	return;
}


// --------------------------------------------------------------------
// NAME
//	MqGet
//
// DESCRIPTION
//	Get the file/message from the queue specified.
// ARGUMENTS
//	Queue Name, Queue Manager
// RETURNS
//	FAIL if fails to put the file on the queue.
//	SUCCESS if succeeds
 
0
 

This is a long shot, but can you just try this and tell me what happens?

#ifndef _REENTRANT
#define _REENTRANT
#endif
 
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <iostream.h>
#include <cmqc.h>
#include <string.h>
#include <wait.h>
#include <sys/wait.h>
 
0
 

This is a long shot, but can you just try this and tell me what happens?

#ifndef _REENTRANT
#define _REENTRANT
#endif
 
#include <stdlib.h>
#include <unistd.h>
#include <ctype.h>
#include <iostream.h>
#include <cmqc.h>
#include <string.h>
#include <wait.h>
#include <sys/wait.h>

Tried your suggestion in my getfile.c program and still the same error.
Thanks
Ravi

 
0
 

Sorry no idea. Never developed anything in the Solaris environment. So guess someone else will have to take over this thread.

 
-1
 

Take off the line #define _REENTRANT from your file
Instead use the following flag during compilation.
CC -c -D_SOLARIS_ -D_REENTRANT
Let me know if it fixed your problem.

Comments
Don't bump a 4 year old thread
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article