Linux => OpenSolaris Porting Code Fixes

This page lists various common issues faced when porting Linux code to Nexenta. It's aim to collect the various common issues faced when moving packages from Ubuntu to ncp. This will be added to the Documentation page once the list is more comprehensive and detailed.

See the diffs at http://www.nexenta.org/diffs-gnusolaris/ and check your package's diff.. the fix is usually in there.

A great resource for Solaris patching is in the pkgbuild.sf.net project's SFE repository. Find them at https://svn.sourceforge.net/svnroot/pkgbuild/spec-files-extra/trunk/patches/


Changing Dependencies

(these changes would go into debian/control in the Dependency fields)

at -> at | sunwcsu

pax -> pax | sunwcsu


  • isfinite()

Add to offending cpp file.

#if defined(sun)

#ifndef isfinite

#define isfinite(val) (val <= std::numeric_limits<double>::max())

#endif

#endif


  • alloca

Add #include <alloca.h> to the file.


  • readdir_r

Add -D_POSIX_PTHREAD_SEMANTICS to CFLAGS in the configure.in file.


  • undefined reference to `libintl_gettext'

Application needs to be linked with libintl. Either configure script or debian/rules needs to be fixed. Defining LDFLAGS=-lintl in debian/rules the easiest but fixing configure script to correctly 'detect' libintl is the cleanest.


  • apt-get install package : dpkg: error processing * : trying to overwrite <file>

This occurs when a package tries to overwrite a file that has already been installed to the system by another package. Only one package may install a file to the system. To workaround this, you can:-

Modify the "install" target in the Makefile of the package to remove the file from being installed

You can remove this file after build in debian/rules add the following lines:

  • install/packagename::rm debian/packagebuilddirname/path/to/file

dpkg-divert: http://www.debian-administration.org/articles/118


  • Dpatch error: unable to patch 01_some_patch: No permission

This usually occurs when the patched in the debian/patches directory are missing the 'x' flag. the workaround is to go into the debian patchs directory and "chmod +x *patch"


  • implicit declaration of function 'asprintf'

Either add '-D_GNU_SOURCE' as a parameter to gcc in the Makefile/configure.in or add a "#define _GNU_SOURCE" in the offending c file


  • u_int32_not defined (or u_int16_not defined or u_int64_not defined)

  • Add the following to the offending file. Usually, you'll need to add the below lines for all three variants.
    #ifndef u_int32_t
    #define u_int32_t uint32_t
    #endif


  • error: 'NAME_MAX' undeclared (first use in this function)

  • If you want the maximum length of a full path name, and not just the length of the basename, you can use PATH_MAX.


  • strerror_r : cannot convert int to char *

  • background here (http://man-wiki.net/index.php/3:strerror_r) .. this function is defined differently in POSIX and GNU.

  • you'd need to fix it from first method to second:
  • char *result = strerror_r(errnum, buf, bufsize);
  • #ifndef sun
           char *result = strerror_r(errnum, buf, bufsize);
    #else
          strerror_r(errnum, buf, bufsize);
          char *result = buf;
    #endif


  • winsize not defined.

This should have been in sys/ioctl.h in linux, and is found in sys/termios.h in solaris. Add below to offending line

#ifdef sun
#include <sys/termios.h>
#endif


  • error: 'struct dirent' has no member named 'd_type' `DT_DIR undeclared (first use this function)

The struct dirent definition in solaris does not contain the d_type field. You would need to make the changes as follows

  if (de->d_type == DT_DIR)
  {
    return 0;
  }
 changes to
  struct stat s; /*include sys/stat.h if necessary */
  ..
  ..
  stat(de->d_name, &s);
  if (s.st_mode & S_IFDIR)
  {
    return 0;
  }


  • FNM_CASEFOLD not defined

Add the following at the beginning of the file

#ifndef FNM_CASEFOLD

#define FNM_CASEFOLD (1 << 4)

#endif


  • "Compiler or options invalid for pre-UNIX 03 X/Open applications and pre-2001 POSIX applications"

Remove the -std=c9x or -std=c99 option in CFLAGS, either in configure.ac, configure or Makefile

or

Add -D_XPG6


  • undefined reference to `error_print_progname'

  • undefined reference to `error'

add LDFLAGS += -lrecode to debian/rules


  • error: #error "Compiler or options invalid for pre-UNIX 03 X/Open applications and pre-2001 POSIX applications"

Multiple reasons.. try removing --std=c9x flag to configure if present.


  • error: paths.h: No such file or directory

todo: explain



  • openpty() not defined / not in scope

This isnt available on Solaris. Example of porting.

#ifdef sun

  • char * slavename;
  • //extern char *ptsname(int *);
  • master = open("/dev/ptmx", O_RDWR);
  • grantpt(master); unlockpt(master);
  • slavename = ptsname(master);
  • slave = open(slavename, O_RDWR);

#else

  • if (openpty(&master, &slave, line, NULL, NULL)) {

    • return -1;
    } return master;

#endif


  • . add your own..