Menu

#1993 Some issues with building oorexx

5.0.0
open
nobody
None
none
5
2025-01-17
2025-01-08
No

Hi! I have packaged oorexx 5.0.0 for pkgsrc, the package building framework for lots of different Unix and Unix-like systems. See http://cvsweb.netbsd.org/bsdweb.cgi/pkgsrc/lang/oorexx/ .

As part of the build, nearly at the end, the build procedure runs the just-built executable rexximage. This unfortunately has a few problems.

  1. /tmp/pkgsrc/lang/oorexx/default/cmake-pkgsrc-build/bin/rexximage: Shared object "librexx.so.4" not found. It needs some shared libraries, but since they are built but not installed yet, they can't be found. This is annoying but can be worked around, unless the next item applies.
  2. This is totally incompatible with cross-building. Say building on x86_64 with a cross compiler which creates aarch64 binaries. Scenarios like this can not work.
  3. Furthermore there is the annoyance that running rexximage apparently starts a process rxapi which remains running after the build. Since pkgsrc bulk-builds packages, this pollutes the build system. There does not appear to be a method to cleanly get rid of this process. Obviously, running kill commands on a build server is not appropriate.

The best solution would be to not run any build-products at all. This will solve all 3 issues.

Barring that, can we at least have some sort of fix for item 3? This is in my view the most pressing issue. Leaving processes running is just rude.

Thanks in advance,
-Olaf.

Discussion

  • Per Olov Jonsson

    Hi Olaf!
    It would be great if you could make it work for pkgsrc (which I am not really familiar with). Besides Win and macOS we do build for .deb, .rpm and .pkg. We build FreeBSD, OpenBSD, NetBSD, Manjaro, Arch Linux, OpenIndiana and Solaris so the build process it not a problem for us for those platforms but we only managed to build an installer that works on FreeBSD. Regarding 2 above I can confirm that crossbuilding works for macOS at least, for those two platforms you mention. Regarding 1 above maybe you can get some hints from looking at the attached log of our building FreeBSD, as well as hour build commands. You will notice that we build once locally a "portable" installer (a zipped copy of the necessary binaries basically) that can run from anywhere, look at CMakeLists.txt for more detail. At the end we use CPack to create an installer that can be distributed. But, as I said, this only works for us on FreeBSD so if you make ooRexx available on pggsrc that would be great.
    Regarding 3 above I am not a developer but to my knowledge rxapi is the API used by the interpreter and yes, it stys behind, unless you kill it. We have a kill command in the build process to make sure we are using the right version of it. If you are not able to use pkill this might be problematic.

     
  • Olaf Seibert

    Olaf Seibert - 2025-01-14

    Hi Per! Thanks for your reply.
    I was looking through the cmakefile stuff and found some steps to kill rxapi, but only on Windows (it says that otherwise the build fails; I suppose that the file is locked as long as it is being executed).

    Pkgsrc and FreeBSD ports were, once upon a time, the same thing, one forked from the other and now they have some of the same principles but many different details. The main building part of the log looks very similar to what I get from pkgsrc.

    I came up with a few patches (I tried to keep them fairly small) to add an argument to the rxapi command so that it terminates the currently running server. For that I turn the lock file into a pid file (containing the process ID of the server), which I was kind of missing anyway. When you run rxapi stop it consults the lock file and sends a SIGTERM signal to the process id that it finds.

    While browsing through the sources, I got the impression that just calling LocalAPIManager::getInstance()->shutdown(); should find the server and send it a SHUTDOWN_SERVER message. That would be cleaner than sending signals, but for some reason it didn't work for me.

    So I plan to add these patches in pkgsrc: (it seems the indenting gets mangled by sourceforge)

    Doesn't respect CMAKE_INSTALL_MANDIR.
    Add a command to terminate rxapi after it was started.
    
    --- CMakeLists.txt.orig 2023-04-19 14:25:14.000000000 +0000
    +++ CMakeLists.txt
    @@ -290,7 +290,7 @@ else ()
        set (INSTALL_INCLUDE_DIR include)
        set (INSTALL_SAMPLES_DIR share/${CMAKE_PROJECT_NAME}/samples)
        set (INSTALL_DOC_DIR share/${CMAKE_PROJECT_NAME}/doc)
    
    -   set (INSTALL_MAN_DIR share/man)
    +   set (INSTALL_MAN_DIR ${CMAKE_INSTALL_MANDIR})
     endif ()
    
     # Set compiler and linker flags common to all build environments
    @@ -1035,6 +1035,7 @@ endif ()
     # Build the rexx.img file
     add_custom_command(OUTPUT ${ORX_IMAGE_OUTPUT_LOCATION}/rexx.img
                COMMAND $<TARGET_FILE:rexximage> ${ORX_IMAGE_OUTPUT_LOCATION}/rexx.img
    
    +           COMMAND $<TARGET_FILE:rxapi> stop
                DEPENDS rexximage rxapi ${image_class_files} ${platform_rexx_img_depends}
                WORKING_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY})
    
    Make terminateServer() resistant to being called more than once.
    
    --- rexxapi/server/APIServer.cpp.orig   2025-01-14 14:01:33.240245578 +0000
    +++ rexxapi/server/APIServer.cpp
    @@ -64,8 +64,10 @@ void APIServer::initServer(ServerConnect
     void APIServer::terminateServer()
     {
         // flip the sign over to the closed side.
    
    -    connectionManager->disconnect();
    -    delete connectionManager;
    +    if (connectionManager) {
    +       connectionManager->disconnect();
    +       delete connectionManager;
    +    }
         connectionManager = NULL;
         serverActive = false;
     }
    
     A combination of changes to make it possible to terminate the rxapi process
    which is auto-started:
    
    - use the lock file as a pid-file,
    - add a command line argument "stop" that sends SIGTERM to the pid from the
      pidfile,
    - let the signal handler continue running so that cleanup code can run.
    For whatever reason, "LocalAPIManager::getInstance()->shutdown();" did not work.
    
    --- rexxapi/server/platform/unix/APIService.cpp.orig    2025-01-14 10:40:19.996374412 +0000
    +++ rexxapi/server/platform/unix/APIService.cpp
    @@ -64,7 +64,8 @@ void Stop(int signo)
     {
         apiServer.terminateServer();     // shut everything down
    
    
    -    exit(1);
    +    /* Do not exit here, but let the main loop finish and the epilog code clean
    +     * up the lock file. */
     }
    
    
    @@ -118,9 +119,15 @@ void releaseLock (const char *lockFileNa
      */
     int main(int argc, char *argv[])
     {
    
    +    int stopflag = 0;
    +
         if (argc > 1)
         {
    -        printf("rxapi: no args allowed\n");
    +       if (strcmp(argv[1], "stop") == 0) {
    +           stopflag = 1;
    +       } else {
    +           printf("rxapi: no args allowed\n");
    +       }
         }
    
         // a buffer for generating the name
    @@ -133,6 +140,16 @@ int main(int argc, char *argv[])
         snprintf(lockFileName, sizeof(lockFileName), "%s.lock", pipePath);
         printf("rxapi: lockfile path is %s\n", lockFileName);
    
    
    +    if (stopflag) {
    +   FILE *f = fopen(lockFileName, "r");
    +   long pid = 0;
    +
    +   if (f && fscanf(f, "%ld", &pid) == 1 && pid > 1 &&
    +       kill(pid, SIGTERM) == 0) {
    +       exit(0);
    +   }
    +   exit(1);
    +    }
         // see if we can get the lock file before proceeding. This is one
         // file per user.
         int fd;
    @@ -142,6 +159,11 @@ int main(int argc, char *argv[])
             return EACCES;
         }
         printf("rxapi: lockfile lock acquired\n");
    +    {
    +       char pidstring[32];
    +       sprintf(pidstring, "%ld\n", (long)getpid());
    +       write(fd, pidstring, strlen(pidstring));
    +    }
    
         struct sigaction sa;
    

    I offer this of course as a patch for you. You can probably make this a bit nicer and possibly also use this for terminating the Windows executable. Maybe it's even trivially possible to make my idea of LocalAPIManager::getInstance()->shutdown(); make work; I would prefer that over sending signals.

     
  • Olaf Seibert

    Olaf Seibert - 2025-01-17

    I just committed a newer version of the patches above to pkgsrc. I made the condition to send the signal a bit stricter: only if the exclusive lock is not obtained. That should mean that an rxapi process is actually running.

    Should be available from http://cvsweb.netbsd.org/bsdweb.cgi/pkgsrc/lang/oorexx/patches/ soon.

     

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB