[FreeNX-kNX] Updated Fedora RPM's

tom.horsley at att.net tom.horsley at att.net
Mon May 8 18:52:50 UTC 2006


 -------------- Original message ----------------------
From: Rick Stout <zipsonic at gmail.com>
> FC5 is one of the first (maybe even the first) to use the new modular
> X.org. NX is still built using the older X11R6 structure. I don't know
> that it is possible to change the nxagent build without destroying the
> whole build process. If someone can come up with a patch that fixes
> this, i will gladly apply it.

It isn't linux unless people are making gratuitous changes that
force everyone else to make gratuitous changes to keep up :-).

> 
> For now, though, I will update the package to create a symlink for this.
> BTW, where are you seeing problems? I've been running fc5 with freenx
> since the day it was released, and I havent really seen any problems
> with the packages, other than what i've pointed out.

I see it in older applications that get colors the old fashoined
way (Motif programs, things based on just Xlib like fvwm). The
applications either don't work at all because they don't react
well to not being able to lookup color names, or they do things
like fvwm where all my menus show up black on black :-).

Anyway, rather than trying to actually modify the build process,
you might want to just run the executables through my string
changer program (I'll see if I can successfully attach a copy).
The program was originally written for doing X builds so I could
debug in one directory tree, then when everything worked, do
a string change of all the built-in paths, so it has a lot of
history already fixing patchs in X programs.
-------------- next part --------------
/* This is the "sc" (string change) program, designed to edit both binaries
 * and text files to replace one string with another (shorter or equal length)
 * string wherever it occurs.
 *
 * usage: sc file old-str new-str
 */

#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>

int
main(int argc, char ** argv)
{
   int fd;
   struct stat statbuf;
   unsigned long oldlen;
   unsigned long newlen;
   void * buf;
   char * os = argv[2];
   char * ns = argv[3];
   unsigned long len_os = strlen(os);
   unsigned long len_ns = strlen(ns);
   char * scan;
   unsigned long scanlen;

   if (argc != 4) {
      fputs("usage: sc file old-str new-str\n", stderr);
      exit(2);
   }
   if (len_os < len_ns) {
      fputs("Gack! New string longer than old string!\n", stderr);
      exit(2);
   }
   fd = open(argv[1], O_RDWR, 0);
   if (fd < 0) {
      perror("open");
      exit(2);
   }
   if (fstat(fd, &statbuf) != 0) {
      perror("fstat");
      exit(2);
   }
   if (! S_ISREG(statbuf.st_mode)) {
      fputs("Gack! Not a regular file!\n", stderr);
      exit(2);
   }
   if (statbuf.st_size == 0) {
      /* Empty file - no need to do anything here... */
      return 0;
   }
   oldlen = statbuf.st_size;
   newlen = oldlen;
   buf = mmap(0, oldlen, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
   scan = (char *)buf;
   scanlen = newlen;

   /* Here we finally modify all strings in the file. */

   while (scanlen > 0) {
      unsigned long skiplen;
      char * c1p;

      /* Look for 1st character of old string in buffer */

      c1p = (char *)memchr((const void *)scan, os[0], scanlen);

      if (c1p == NULL) {
         /* No more occurrences of old string, get out of loop */
         break;
      }

      skiplen = c1p - scan;
      scanlen -= skiplen;
      scan += skiplen;

      if (scanlen < len_os) {
         /* No more occurrences of old string, get out of loop */
         break;
      }

      /* See if we really found start of old string */

      if (memcmp((const void *)scan, (const void *)os, len_os) == 0) {
         /* Hot dog! We found a matching string. We need to substitute the
            new string and decide what to do with the remainder of the file
         */
         memcpy((void *)scan, (const void *)ns, len_ns);
         scan += len_ns;
         scanlen -= len_ns;
         if (len_ns < len_os) {
            /* We substituted a shorter string, so need to look for the end
               of the string and move up all the rest of the string by
               (len_os - len_ns) chars. The end of the string is either a
               null byte (if we can find one) or the end of the file. If we
               go all the way to end of file, also need to remember to make
               the file shorter when we are done.
            */
            char * nullp = (char *)memchr((const void *)scan, 0, scanlen);
            unsigned long shrink = len_os - len_ns;
            unsigned long slen;
            if (nullp == NULL) {
               /* No null byte, shrink whole file */
               nullp = scan + scanlen;
               newlen -= shrink;
               scanlen -= shrink;
            }
            slen = nullp - scan;
            memmove((void *)scan, (void *)(scan + shrink), slen - shrink);
            memset((void *)(nullp - shrink), 0, shrink);
         }
      } else {

         /* Nope, this wasn't a match, just move up 1 char and try again */

         scan += 1;
         scanlen -= 1;
      }
   }
   if (munmap(buf, oldlen) != 0) {
      perror("munmap");
      exit(2);
   }
   if (newlen < oldlen) {
      if (ftruncate(fd, newlen) != 0) {
         perror("ftruncate");
         exit(2);
      }
   }
   return 0;
}


More information about the FreeNX-kNX mailing list