× The internal search function is temporarily non-functional. The current search engine is no longer viable and we are researching alternatives.
As a stop gap measure, we are using Google's custom search engine service.
If you know of an easy to use, open source, search engine ... please contact support@midrange.com.



Hi Steve,

Each time you call opendir(), you open a connection to a directory. It's very much like opening a file -- an open path is created to the directory for you to work with. The opendir() API returns a pointer that you use to refer to that open path.

For each value that opendir() returns, you MUST save it into a variable, and you MUST call closedir() with the same value. That means that if your program changes the value of the variable, you won't be able to close the open path, and it'll stay open forever!

By default, each job has a limit of around 200 open IFS objects before it starts failing. (that limit can be changed, but rarely needs to be.)

Based on the code you've posted, you never close the /transfer, /transfer/WMS or /transfer/WMS/Upload directories. You save the open file info into the "dir" variable, but then you overwrite the value of "Dir" before you ever close the directory -- making it impossible to close!

Now, I don't understand why you're opening each preceding IFS directory. That's not normally necessary! I assume you needed it for some diagnostic reason? I dunno... but people don't usually do that, and it seems like a strange thing to do. It's not necessary for your program to work correctly.

However, if for some reason you want to keep opening those directories, you also need to close them. Just call closedir() prior to opening the next one and close up that previously opened directory.

If you don't do that, you'll leave the directories open, and things will start to fail after your program has been run enough times to run out of file handles. At the default of 200, you'd hit the limit after your program has been run about 60 times (give or take a few). If it's run every 4 minutes, that'd be about 4 hours between failures.

Once it fails, it'd keep failing until you restarted the job.

It may happen more frequently if you have other IFS resources open in your job. (Even if they're used by the OS)

Anyway -- either stop opening all those unnecessary directories, or make sure they get closed and you won't have that problem anymore. If this doesn't help, then please post information about the error. You're populating a variable named 'errno' and 'errmsg' with useful diagnostic error information, but you're not telling us what the values of these are! That leaves us having to take wild guesses!



Steve Seroogy wrote:
I'm having problems with a program that was written using opendir and
closedir. This program is run every 4 minutes, We are opening one
directory at a time when it can't open it is creates a dump. The
problem is when it dump it continues to dump every 4 minutes and never
process the information the program was intending to process. It seems
to start dumping at dump3 and then every time it runs it dumps at all
dump commands. Below is the code can some one give me advice. I don't
mind that it dumps but it should keeping dump every time is dumps. It
seems something is not getting reset prior to running again.
// Open upload directory -- must go through path one directory at a
CurrentDir = '/transfer/WMS/Upload/MAPICS/'; Dir = opendir('/transfer'); // in the case of errors, the program will retrieve the error numbe
// and description and create a dump. If Dir = *null; error_p = strerror(errno); errmsg = %str(error_p); dump 'dump1'; Endif; Dir = opendir('/transfer/WMS/'); If Dir = *null; error_p = strerror(errno); errmsg = %str(error_p); dump 'dump2'; Endif; Dir = opendir('/transfer/WMS/Upload/'); If Dir = *null; error_p = strerror(errno); errmsg = %str(error_p); dump 'dump3'; Endif; Dir = opendir('/transfer/WMS/Upload/MAPICS/');
If Dir = *null; error_p = strerror(errno); errmsg = %str(error_p); dump 'dump4'; Endif; // read first file in directory p_dirent = readdir(Dir); Dow p_dirent <> *null; //retrieve file name DataFile = %subst(d_name:1:d_namelen); If %trim(DataFile) <> '.' and %trim(DataFile) <> '..'; OpenDirWithFile = %trim(CurrentDir) + %trim(Datafile); // set flags and open file (read only, exclusive open, text dat
flags = O_RDONLY + O_SHARE_NONE + O_TEXTDATA; FDCurrent = open(OpenDirWithFile : flags); // FDCurrent will be -1 if there is an open error on the file // it will contain a pointer value if it is successful If FDCurrent < 0; error_p = strerror(errno); errmsg = %str(error_p); dump 'dump5'; endif; // Open file If FDCurrent >= 0; // retrieve file name without extension //Position = 0; //Position = %scan(CurExt : Datafile : 1); // create new file name for history //NewFile = %subst(Datafile:1:Position - 1) + NewExt; NewFile = Datafile; // create path and file name to write to history directory
HistoryFolder = '/transfer/WMS/Upload/MAPICS.SAVE'; Path = %trim(HistoryFolder) + '/' + %trim(Newfile); // set file usage (create if not created, read/write, clear)
Flags = O_CREAT + O_WRONLY + O_TRUNC + O_TEXTDATA; //set file authority (open to everyone) Mode = S_IRWXU + S_IRWXG + S_IRWXO; // create file in new directory NewfileD = Open(%trimr(path) : flags : mode); // retrieve record count, close file if error cuz won't be a
If fstat(FDCurrent : %addr(FileStat)) < 0; error_p = strerror(errno); errmsg = %str(error_p); dump 'dump6'; callp close(FDCurrent); EndIf; // set data structure to value that is pointed to by FileSta
p_statds = %addr(FileStat); // retrieve record count by dividing file size by record siz
Recordcount = st_size / %size(rddata); // set number of reads to record count and goto pos of next For Recno = 1 to RecordCount; pos = (recno - 1) * %size(rddata); callp lseek(FDCurrent : pos : SEEK_SET); // set file data to Upload data structure (RecLen is a va
// just contains the length of the record written to Uplo
RecLen = read(FDCurrent : %addr(upload) : %size(upload));
If RecLen < 1; error_p = strerror(errno); errmsg = %str(error_p); dump 'dump7'; callp close(FDCurrent); EndIf; // save data to variable to write to history file %subst(WriteData:1:%size(Upload)) = Upload; // write the record to the mapics file Callp WriteTofile(); // write data to history file If write(NewFileD:%addr(WriteData):%size(WriteData)) < %size(WriteData); error_p = strerror(errno); errmsg = %str(error_p); dump 'dump8'; callp close(FDCurrent); EndIf; Endfor; // close current file callp close(FDCurrent); // delete file from current directory
Callp Unlink(OpenDirWithFile); // close history file callp close(NewFileD); Endif; Endif; // read next file in directory
p_dirent = readdir(Dir); Enddo; callp closedir(Dir); *inlr = *on; Return; /end-free
Steve Seroogy
Business Analyst
Phone: (262) 544-4811 x2734
Fax: (262) 968-9372

Generac Power System, Inc
Hwy 59 and Hillside Road
Waukesha, Wisconsin 53187




As an Amazon Associate we earn from qualifying purchases.

This thread ...

Replies:

Follow On AppleNews
Return to Archive home page | Return to MIDRANGE.COM home page

This mailing list archive is Copyright 1997-2024 by midrange.com and David Gibbs as a compilation work. Use of the archive is restricted to research of a business or technical nature. Any other uses are prohibited. Full details are available on our policy page. If you have questions about this, please contact [javascript protected email address].

Operating expenses for this site are earned using the Amazon Associate program and Google Adsense.