Announcement

Collapse
No announcement yet.

IFS Open - Authority Issue?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • IFS Open - Authority Issue?

    Hello, thanks in advance for any guidance. I am using the Open API in an RPGLE program (shown below), if the file is not in the IFS the open should create the empty file. We have 2 users where the FD returns as -1. Other users work correctly, FD returns as 0. All authorities appear to be identical and the authority on the IFS appears to be correct. Is there a way to get more logging info so I can see why the Open is failing?

    Code:
    iFileID = OpenFile(%addr(szTempFile):O_RDWR+O_CREAT+O_TRUNC:
    S_IRWXU);
    
    if iFileID <> -1;
    // Write "from" addresses
    if %PARMS()>=14;
    szAlias=' "' + %trim(PFromAlias) + '"';
    else;
    szAlias='';
    endif;

  • #2
    What is the value of errno after the failed open? That should give you a hint.

    In case you don't have it - this is how to get the value and the associated text version

    Code:
    [B]// Prototype for __errno() - Retrieve pointer to C errno[/B]
    [B]Dcl-Pr GetErrno Pointer Extproc('__errno');[/B]
    [B]End-Pr; [/B]
    
    [B]// ErrorNo is BASED on pointer returned by __errno()[/B]
    [B]Dcl-S ErrorNo Int(10) Based(pErrorNo); [/B]
    
    [B]// Prototype for strerror() - Retrieve error text for errno[/B]
    [B]Dcl-Pr StrError Pointer ExtProc('strerror');[/B]
    [B]errno Int(10) Value;[/B]
    [B]End-Pr; [/B]
    
    [B]// Variables for strerror() function[/B]
    [B]Dcl-S pErrorTxt Pointer;[/B]
    
    [B]Dcl-S message Char(52);
    
    // Get the errno value [/B]
    [B]pErrorNo = GetErrno();[/B]
    
    // And use it to retrieve text version (52 may not be long enough but it is all Dsply can do!
    [B]pErrorTxt = StrError(ErrorNo);[/B]
    
    [B]message = 'Error code: ' + %char(ErrorNo) + ': '[/B]
    [B]+ [/B][B]%Str(pErrorTxt)[/B][B];[/B]
    
    [B]dsply message;[/B]




    Last edited by JonBoy; March 11, 2021, 03:34 PM.

    Comment


    • #3
      Thanks JonBoy.

      It was -1. I found some Klement stuff on error handling just after posting this. I was able to find out the initial slash '/' was missing on the IFS path. I'm good now.

      Comment


      • #4
        Glad you got it sorted. I was going to mention the checking the path but figured you'd done that.

        Re errno though ... you are mistaking the error condition indicated by a file handle of -1 _but_ that is not the errno - the errno tells you the underlying cause for the -1.

        Comment


        • #5
          And I'm quite sure that the user profiles for the 2 users had Home directory specified.
          The other users hadn't.

          Comment


          • #6
            1. Please understand that the names of these routines, like open(), are standards. They are used across many different OSes (all Linuxes, all Unixes, Windows, macOS and IBM i). Changing the name from "open" "OpenFile" does NOT make your program easier to follow -- it makes it harder.
            2. There is no reason to pass %ADDR() for the filename unless you're doing something tricky. The prototype has options(*string) which allows you to pass the variable as-is.
            3. You aren't looking at errno at all. This is not a good idea, and will make your program a pain to maintain. Please add code to return the correct error message or at least error number when something fails with -1.

            Comment


            • #7
              Thanks Scott, this was an existing program that sends email attachments. All it did was check for the -1 and would exit. I was trying to figure out why it was returning the -1. Using your copy book and sub procedure I was able to determine there was a problem with the path.

              Comment

              Working...
              X