#include #include #include #include #include #ifndef RTLD_LOCAL #define RTLD_LOCAL 0 #endif static struct passwd *(*rl_getpwuid)(uid_t); static struct passwd *(*rl_getpwnam)(const char *); static void *libc7_h; static int (*rl_sigaction)(int, const void *, void *); static int (*rl_sigprocmask)(int, const void *, void *); #define APPLIX_SIGSYS 12 #define APPLIX_SIG_IGN ((void (*)(int))1) static void (*(*rl_signal)(int, void (*)(int)))(int); struct old_sigaction { void *handler; unsigned int mask; int flags; }; struct new_sigaction { void *handler; int flags; unsigned int mask[4]; }; static void libc7_init(void) { if (libc7_h) return; libc7_h = dlopen("libc.so.7", RTLD_LAZY | RTLD_LOCAL); if (!libc7_h) return; rl_sigaction = dlsym(libc7_h, "sigaction"); rl_sigprocmask = dlsym(libc7_h, "sigprocmask"); rl_signal = dlsym(libc7_h, "signal"); rl_getpwuid = dlsym(libc7_h, "getpwuid"); rl_getpwnam = dlsym(libc7_h, "getpwnam"); if (rl_signal) rl_signal(APPLIX_SIGSYS, APPLIX_SIG_IGN); } int sigaction(int sig, const struct old_sigaction *act, struct old_sigaction *oact) { struct new_sigaction m_act; struct new_sigaction m_oact; struct new_sigaction *ap = NULL; struct new_sigaction *op = NULL; int ret; if (!libc7_h) libc7_init(); if (act) { memset(&m_act, 0, sizeof(m_act)); m_act.handler = act->handler; m_act.flags = act->flags; m_act.mask[0] = act->mask; ap = &m_act; } if (oact) op = &m_oact; ret = rl_sigaction ? rl_sigaction(sig, ap, op) : -1; if (ret == 0 && oact && op) { oact->handler = m_oact.handler; oact->flags = m_oact.flags; oact->mask = m_oact.mask[0]; } return ret; } int sigprocmask(int how, const unsigned int *set, unsigned int *oset) { unsigned int m_set[4]; unsigned int m_oset[4]; void *sp = NULL; void *op = NULL; int ret; if (!libc7_h) libc7_init(); memset(m_set, 0, sizeof(m_set)); memset(m_oset, 0, sizeof(m_oset)); if (set) { m_set[0] = *set; sp = m_set; } if (oset) op = m_oset; ret = rl_sigprocmask ? rl_sigprocmask(how, sp, op) : -1; if (ret == 0 && oset && op) *oset = m_oset[0]; return ret; } struct passwd * getpwuid(uid_t uid) { if (!libc7_h) libc7_init(); if (rl_getpwuid) return rl_getpwuid(uid); errno = ENOENT; return NULL; } struct passwd * getpwnam(const char *name) { if (!libc7_h) libc7_init(); if (rl_getpwnam) return rl_getpwnam(name); errno = ENOENT; return NULL; }