AFS-PAG
view release on metacpan or search on metacpan
kafs/kafs.c view on Meta::CPAN
#include <config.h>
#include <portable/kafs.h>
#include <portable/system.h>
#include <errno.h>
#include <fcntl.h>
#include <signal.h>
#ifdef HAVE_SYS_IOCCOM_H
# include <sys/ioccom.h>
#endif
#include <sys/ioctl.h>
#include <sys/stat.h>
/* Used for unused parameters to silence gcc warnings. */
#define UNUSED __attribute__((__unused__))
/* Provided by the relevant sys-*.c file. */
static int k_syscall(long, long, long, long, long, int *);
/*
* Include the syscall implementation for this host, based on the configure
* results. An include of the C source is easier to handle in the build
* machinery than lots of Automake conditionals.
*
* The included file must provide a k_syscall implementation.
*/
#if defined(HAVE_KAFS_DARWIN8)
# include <kafs/sys-darwin8.c>
#elif defined(HAVE_KAFS_DARWIN10)
# include <kafs/sys-darwin10.c>
#elif defined(HAVE_KAFS_LINUX)
# include <kafs/sys-linux.c>
#elif defined(HAVE_KAFS_SOLARIS)
# include <kafs/sys-solaris.c>
#elif defined(HAVE_KAFS_SYSCALL)
# include <kafs/sys-syscall.c>
#else
# error "Unknown AFS system call implementation"
#endif
/*
* On some platforms, k_hasafs needs to try a system call. This attempt may
* fail with SIGSYS. We therefore set a signal handler that changes a static
* variable if SIGSYS is received.
*
* It's really ugly to do this in library or PAM module in so many ways.
* Static variables are evil, changing signal handlers out from under an
* application is evil, and the interaction of signals and threads is probably
* nasty. The only things that make this better is that this case will never
* be triggered in the normal case of AFS being loaded and the only time that
* we change this static variable is to say that the call failed, so there
* shouldn't be a collision of updates from multiple calls.
*
* It's probably safe to just ignore SIGSYS instead, but this feels more
* thorough.
*/
static volatile sig_atomic_t syscall_okay = 1;
/*
* Signal handler to catch failed system calls and change the okay flag.
*/
#ifdef SIGSYS
static void
sigsys_handler(int s UNUSED)
{
syscall_okay = 0;
signal(SIGSYS, sigsys_handler);
}
#endif /* SIGSYS */
/*
* The other system calls are implemented in terms of k_pioctl. This
* interface assumes that all pointers can be represented in a long, but then
* so does the whole AFS system call interface.
*/
int
k_pioctl(char *path, int cmd, struct ViceIoctl *cmarg, int follow)
{
int err, rval;
rval = k_syscall(20, (long) path, cmd, (long) cmarg, follow, &err);
if (rval != 0)
err = rval;
return err;
}
/*
* Probe to see if AFS is available and we can make system calls successfully.
* This just attempts the set token system call with an empty token structure,
* which will be a no-op in the kernel.
*/
int
k_hasafs(void)
{
struct ViceIoctl iob;
int rval, saved_errno, okay;
void (*saved_func)(int);
saved_errno = errno;
#ifdef SIGSYS
saved_func = signal(SIGSYS, sigsys_handler);
#endif
iob.in = NULL;
iob.in_size = 0;
iob.out = NULL;
iob.out_size = 0;
rval = k_pioctl(NULL, _IOW('V', 3, struct ViceIoctl), &iob, 0);
#ifdef SIGSYS
signal(SIGSYS, saved_func);
#endif
okay = (syscall_okay && rval == -1 && errno == EINVAL);
errno = saved_errno;
return okay;
}
( run in 2.078 seconds using v1.01-cache-2.11-cpan-ceb78f64989 )