Giter VIP home page Giter VIP logo

portlibfori's Introduction

Porting Library for IBM i

Summary

Provides various functions for PASE which are not provided by the AIX runtime.

This makes porting applications easier. Currently provides the following libraries:

libutil

Contains various functions found in Linux, BSD, etc but not found on AIX:

  • openpty
  • forkpty
  • login_tty
  • getopt_long
  • getopt_long_only
  • mkdtemp
  • backtrace
  • backtrace_symbols
  • libutil_getprogname
  • libutil_setprogname

libiperf

IBM i performance statistics library, modeled after AIX's libperfstat.

Currently only supports a quite limited selection of APIs:

  • iperfstat_memory_get_main_storage_size
  • iperfstat_cpu_get_number

Building

    make
    make install

The Makefile supports PREFIX and DESTDIR variables. The default prefix is /usr/local. To install to a different prefix specify it like so:

    make PREFIX=/QOpenSys/my/prefix install

License

Most code is licensed under MIT. See LICENSE for more info.

portlibfori's People

Contributors

aaronbartell avatar abmusse avatar kadler avatar markdirish avatar nattynarwhal avatar naveen-ram avatar theprez avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

portlibfori's Issues

Implement glob(3)

The AIX libc glob is a bit anemic feature wise (AFAIK missing a few flags), and I'm suspecting it may be buggy. I've had a few complaints about it.

I was thinking of vendoring say, a BSD's implementation in our application (and am tempted to do just that), but I bet it'd probably be better if it were provided in here, since other software may be using it.

Port backtrace_symbols_fd

I noticed that we have backtrace_symbols I think we should also have backtrace_symbols_fd.

This will be handy when building open source projects.

For example when porting over mariadb I ran into an into a linker error because bactrace_symbols_fd is not implemented.

Add a passwd utility

Would be useful to have a password change utility, like the standard Unix passwd.

The easiest way to implement such a tool would be to use QSYCHGPW using _PGMCALL.

Helpfully, the API takes in CCSID arguments for both old and new passwords, so we can pass in 1208 (or the output of Qp2paseCCSID).

When run as root, passwd doesn't prompt for the old password. The API does support this by passing *NOPWD, for the old password, but the user would need *SECADM special authority. We could check for this with #11 then not prompt.

Implement dladdr

dladdr is a GNU extension to the common dl family of functions: dlopen, dlsym, etc.

It has been implemented on many other operating systems:

It seems like the FreeBSD and macOS implementations are ports of or just compatible with the Solaris version.

One thing we need to think about is what to return for the dli_fname? Do we include the member name (if any) or just the file path. A given path that includes the member in the /path/to/lib(member.so) syntax is a valid file path, so that could be confusing, however it would be unique to AIX/PASE. The HP-UX version at least has defined system-specific fields, so I think we can follow them.

Add API(s) for getting user's special authorities

I think it should work something like this:

// sort of modeled after getpwnam/getpwuid
int get_special_authorities_uid(uid_t uid);
int get_special_authorities_nam(const char* name);

int auth = get_special_authorities_uid(0); // QSECOFR
assert(auth & AUTH_ALLOBJ);

int auth = get_special_authorities("*CURRENT");
if (auth & AUTH_JOBCTL) printf("Current user has *JOBCTL\n");

The API would be based on QSYUSRI.

@ThePrez had a previous attempt when it was on BitBucket: https://bitbucket.org/litmis/portlibfori/pull-requests/1/checkspcaut/diff That went a different way, using QSYCUSRS instead. The semantics are slightly different between these two approaches.

QSYUSRI tells which authorities are given to a user profile object outright, but an MI program can adopt or drop authorites so the authorities checked by QSYCUSRS could be different for the same user when called by different programs. PASE does not support adopted authority, though, so it's largely irrelevant unless you're calling in to PASE from ILE, which isn't very common. For any program started from PASE, it will only have the authorities specified by the user profile that it was started under.

backtrace segmentation fault

While running mysql_install_db I ran into the following error:

/QOpenSys/pkgs/bin/mysql_install_db[2]: 8628721 Memory fault(coredump)

Examining the core file I found:

Program terminated with signal SIGSEGV, Segmentation fault.
#0  0x0900000000985dc0 in backtrace () from /QOpenSys/pkgs/lib/libutil.so.2(shr_64.o)
(gdb) bt
#0  0x0900000000985dc0 in backtrace () from /QOpenSys/pkgs/lib/libutil.so.2(shr_64.o)
#1  0x0000000100031c48 in sf_malloc (size=1480, my_flags=16)
    at /home/AMUSSE/rpmbuild/BUILD/mariadb-10.3.14/mysys/safemalloc.c:141
#2  0x000000010003074c in my_malloc (size=1480, my_flags=16)
    at /home/AMUSSE/rpmbuild/BUILD/mariadb-10.3.14/mysys/my_malloc.c:101
#3  0x0000000100f042ec in init_queue (queue=0x180cee7e8 <_thralarm.bss_3_+312>, max_elements=184, 
    offset_to_key=0, max_at_top=0 '�', compare=@0x1803cc4d8: 0x10129fe08 <compare_ulong>, first_cmp_arg=0x0, 
    offset_to_queue_pos=25, auto_extent=10) at /home/AMUSSE/rpmbuild/BUILD/mariadb-10.3.14/mysys/queues.c:79
#4  0x000000010129ff00 in init_thr_alarm (max_alarms=183)
    at /home/AMUSSE/rpmbuild/BUILD/mariadb-10.3.14/mysys/thr_alarm.c:92
#5  0x0000000100009dec in signal_hand (arg=0x0) at /home/AMUSSE/rpmbuild/BUILD/mariadb-10.3.14/sql/mysqld.cc:3512
#6  0x0900000000583da4 in _pthread_body () from /QOpenSys/usr/lib/libpthreads.a(shr_xpg5_64.o)
#7  0x0000000000000000 in ?? ()

replacement wrappers for *at functions

Functions like openat are broken under PASE (is this documented anywhere?), where they only work on AT_FDCWD instead of arbitrary FDs, returning EINVAL. This has made a lot of people very angry and been widely regarded as a bad move, because most at function users are using non-cwd paths.

It is possible to write a wrapper. It would get the current working directory as an FD, switch CWD to it so that the FD-relative path would work, then switch back once the non-at version of the function has been called. Note that open is annoying because of it using variadic arguments, but many other functions outside of say, linkat could perhaps be generated from a template. Also note there's no mutex, so you will have a very bad time in a threaded application.

int openat_shim(int fd, const char *path, int flags, ...)
{
        // For the shim, get current cwd, change current cwd to passed fd, open file, then change back.
        char current_cwd[MAXPATHLEN];
        getcwd(current_cwd, MAXPATHLEN);
        int current_cwd_fd = open(current_cwd, O_RDONLY);
        if (current_cwd_fd == -1) {
                return -1;
        }
        if (fchdir(fd) == -1) {
                goto fin;
        }
        // Massage the va_list if required
        int retval = -1;
        if (flags & O_CREAT) {
                mode_t mode;
                va_list ap;
                va_start(ap, flags);
                mode = va_arg(ap, mode_t);
                retval = open(path, flags, mode);
                va_end(ap);
        } else {
                retval = open(path, flags);
        }
fin:
        fchdir(current_cwd_fd);
        close(current_cwd_fd);
        return retval;
}

Ideally, it'd be nice if PASE had this fixed properly, but 🤷

Build fails when wrapper headers are installed

This is due to a problem when the wrapper header finds the wrapper header as the next in the include_next chain.

gcc -c -D__PASE__ -fPIC -Iutil -isystem /QOpenSys/usr/include -o util/getopt_long.o util/getopt_long.c
util/getopt_long.c: In function 'pase_warn':
util/getopt_long.c:172:10: warning: implicit declaration of function 'vfprintf' [-Wimplicit-function-declaration]
     rc = vfprintf(stderr, fmt, args);
          ^~~~~~~~

Here util/getopt_long.c has #include <stdio.h>. Because of -Iutil`, this gets loaded from util/stdio.h which has

#ifndef LIBUTIL_SYS_FILE_H
#define LIBUTIL_SYS_FILE_H

#include_next <stdio.h>
...

Because of our GCC in PASE injects -I/QOpenSys/pkgs/include, if this wrapper header is installed, it will find this one next. Now when it gets loaded, because the LIBUTIL_SYS_FILE_H header guard is already defined the #ifndef block will be skipped and the real system stdio.h is never included.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.