Example #1
0
/*
 * ut_sigaction -- a sigaction that cannot return < 0
 */
int
ut_sigaction(const char *file, int line, const char *func,
		int signum, struct sigaction *act, struct sigaction *oldact)
{
#ifndef _WIN32
	int retval = sigaction(signum, act, oldact);
	if (retval != 0)
		ut_fatal(file, line, func, "!sigaction: %s", strsignal(signum));
	return retval;
#else
	if (signum == SIGABRT) {
		DWORD dwMode = GetErrorMode();
		SetErrorMode(dwMode | SEM_NOGPFAULTERRORBOX |
			SEM_FAILCRITICALERRORS);
		_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
	}
	if (signum == SIGSEGV) {
		Sa_handler = act->sa_handler;
		Signum = signum;
		AddVectoredExceptionHandler(0, exception_handler);
	}

	_crt_signal_t retval = signal(signum, act->sa_handler);
	if (retval == SIG_ERR)
		ut_fatal(file, line, func, "!signal: %d", signum);

	if (oldact != NULL) {
		oldact->sa_handler = retval;
	}
	return 0;
#endif
}
Example #2
0
int
ut_fcntl(const char *file, int line, const char *func, int fd,
         int cmd, int num, ...)
{

    int retval;
    va_list args;
    uint64_t arg = 0;

    /*
     * In the case of fcntl, num is always 0 or 1
     */
    if (num != 0) {
        va_start(args, num);
        arg = va_arg(args, uint64_t);
        retval = fcntl(fd, cmd, arg);
        va_end(args);
    } else
        retval = fcntl(fd, cmd);

    if (retval < 0)
        ut_fatal(file, line, func, "!fcntl: %d", fd);

    return retval;
}
Example #3
0
/*
 * ut_close -- a close that cannot return -1
 */
int
ut_close(const char *file, int line, const char *func, int fd)
{
    int retval = close(fd);

    if (retval != 0)
        ut_fatal(file, line, func, "!close: %d", fd);

    return retval;
}
Example #4
0
/*
 * ut_umount -- a umount that cannot return -1
 */
int
ut_umount(const char *file, int line, const char *func, const char *tar)
{
    int retval = umount(tar);

    if (retval < 0)
        ut_fatal(file, line, func, "!umount: %s", tar);

    return retval;
}
Example #5
0
/*
 * ut_closedir -- a closedir that cannot return -1
 */
int
ut_closedir(const char *file, int line, const char *func, DIR *dirp)
{
    int retval = closedir(dirp);

    if (retval < 0)
        ut_fatal(file, line, func, "!closedir: %p", dirp);

    return retval;
}
Example #6
0
/*
 * ut_unlink -- an unlink that cannot return -1
 */
int
ut_unlink(const char *file, int line, const char *func, const char *path)
{
    int retval = unlink(path);

    if (retval != 0)
        ut_fatal(file, line, func, "!unlink: %s", path);

    return retval;
}
Example #7
0
/*
 * ut_malloc -- a malloc that cannot return NULL
 */
void *
ut_malloc(const char *file, int line, const char *func, size_t size)
{
	void *retval = malloc(size);

	if (retval == NULL)
		ut_fatal(file, line, func, "cannot malloc %zu bytes", size);

	return retval;
}
Example #8
0
/*
 * ut_flock -- a flock that cannot return -1
 */
int
ut_flock(const char *file, int line, const char *func, int fd, int op)
{
    int retval = flock(fd, op);

    if (retval != 0)
        ut_fatal(file, line, func, "!flock: %d", fd);

    return retval;
}
Example #9
0
/*
 * ut_symlink -- a symlink that cannot return -1
 */
int
ut_symlink(const char *file, int line, const char *func, const char *oldpath,
           const char *newpath)
{
    int retval = symlink(oldpath, newpath);

    if (retval < 0)
        ut_fatal(file, line, func, "!symlink: %s %s", oldpath, newpath);

    return retval;
}
Example #10
0
/*
 * ut_mknod -- a mknod that cannot return -1
 */
int
ut_mknod(const char *file, int line, const char *func, const char *pathname,
         mode_t mode, dev_t dev)
{
    int retval = mknod(pathname, mode, dev);

    if (retval < 0)
        ut_fatal(file, line, func, "!mknod: %s", pathname);

    return retval;
}
Example #11
0
/*
 * ut_chmod -- a chmod that cannot return -1
 */
int
ut_chmod(const char *file, int line, const char *func, const char *path,
         mode_t mode)
{
    int retval = chmod(path, mode);

    if (retval < 0)
        ut_fatal(file, line, func, "!mode: %s %o", path, mode);

    return retval;
}
Example #12
0
/*
 * ut_write -- a write that can't return -1
 */
size_t
ut_write(const char *file, int line, const char *func, int fd,
         const void *buf, size_t count)
{
    ssize_t retval = write(fd, buf, count);

    if (retval < 0)
        ut_fatal(file, line, func, "!write: %d", fd);

    return (size_t)retval;
}
Example #13
0
/*
 * ut_rename -- a rename that cannot return -1
 */
int
ut_rename(const char *file, int line, const char *func,
          const char *oldpath, const char *newpath)
{
    int retval = rename(oldpath, newpath);

    if (retval < 0)
        ut_fatal(file, line, func, "!rename: %s %s", oldpath, newpath);

    return retval;
}
Example #14
0
/*
 * ut_rmdir -- a rmdir that cannot return -1
 */
int
ut_rmdir(const char *file, int line, const char *func,
         const char *pathname)
{
    int retval = rmdir(pathname);

    if (retval < 0)
        ut_fatal(file, line, func, "!rmdir: %s", pathname);

    return retval;
}
Example #15
0
/*
 * ut_opendir -- an opendir that cannot return NULL
 */
DIR *
ut_opendir(const char *file, int line, const char *func,
           const char *name)
{
    DIR *retval = opendir(name);

    if (retval == NULL)
        ut_fatal(file, line, func, "!opendir: %s", name);

    return retval;
}
Example #16
0
/*
 * ut_read -- a read that can't return -1
 */
size_t
ut_read(const char *file, int line, const char *func, int fd,
        void *buf, size_t count)
{
    ssize_t retval = read(fd, buf, count);

    if (retval < 0)
        ut_fatal(file, line, func, "!read: %d", fd);

    return (size_t)retval;
}
Example #17
0
/*
 * ut_stat -- a stat that cannot return -1
 */
int
ut_stat(const char *file, int line, const char *func, const char *path,
        struct stat *st_bufp)
{
    int retval = stat(path, st_bufp);

    if (retval < 0)
        ut_fatal(file, line, func, "!stat: %s", path);

    return retval;
}
Example #18
0
/*
 * ut_fstat -- a fstat that cannot return -1
 */
int
ut_fstat(const char *file, int line, const char *func, int fd,
         struct stat *st_bufp)
{
    int retval = fstat(fd, st_bufp);

    if (retval < 0)
        ut_fatal(file, line, func, "!fstat: %d", fd);

    return retval;
}
Example #19
0
/*
 * ut_readlink -- a readlink that can't return -1
 */
size_t
ut_readlink(const char *file, int line, const char *func, const char *path,
            void *buf, size_t count)
{
    ssize_t retval = readlink(path, buf, count);

    if (retval < 0)
        ut_fatal(file, line, func, "!readlink: %s", path);

    return (size_t)retval;
}
Example #20
0
/*
 * ut_lseek -- an lseek that can't return -1
 */
off_t
ut_lseek(const char *file, int line, const char *func, int fd,
         off_t offset, int whence)
{
    off_t retval = lseek(fd, offset, whence);

    if (retval == -1)
        ut_fatal(file, line, func, "!lseek: %d", fd);

    return retval;
}
Example #21
0
/*
 * ut_dirfd -- a dirfd that cannot return -1
 */
int
ut_dirfd(const char *file, int line, const char *func,
         DIR *dirp)
{
    int retval = dirfd(dirp);

    if (retval < 0)
        ut_fatal(file, line, func, "!dirfd: %p", dirp);

    return retval;
}
Example #22
0
/*
 * ut_mkdir -- a mkdir that cannot return -1
 */
int
ut_mkdir(const char *file, int line, const char *func,
         const char *pathname, mode_t mode)
{
    int retval = mkdir(pathname, mode);

    if (retval < 0)
        ut_fatal(file, line, func, "!mkdir: %s", pathname);

    return retval;
}
Example #23
0
/*
 * ut_access -- an access that cannot return -1
 */
int
ut_access(const char *file, int line, const char *func, const char *path,
          int mode)
{
    int retval = access(path, mode);

    if (retval != 0)
        ut_fatal(file, line, func, "!access: %s: %d", path, mode);

    return retval;
}
Example #24
0
/*
 * ut_sigaction -- a sigaction that cannot return < 0
 */
int
ut_sigaction(const char *file, int line, const char *func,
		int signum, struct sigaction *act, struct sigaction *oldact)
{
	int retval = sigaction(signum, act, oldact);

	if (retval != 0)
		ut_fatal(file, line, func, "!sigaction: %s", strsignal(signum));

	return retval;
}
Example #25
0
/*
 * ut_memalign -- like malloc but page-aligned memory
 */
void *
ut_memalign(const char *file, int line, const char *func, size_t alignment,
    size_t size)
{
	void *retval;

	if ((errno = posix_memalign(&retval, alignment, size)) != 0)
		ut_fatal(file, line, func,
		    "!memalign %zu bytes (%zu alignment)", size, alignment);

	return retval;
}
Example #26
0
/*
 * ut_munmap -- a munmap call that cannot return -1
 */
int
ut_munmap(const char *file, int line, const char *func, void *addr,
          size_t length)
{
    int retval = munmap(addr, length);

    if (retval < 0)
        ut_fatal(file, line, func, "!munmap: addr=0x%llx length=0x%zx",
                 (unsigned long long)addr, length);

    return retval;
}
Example #27
0
/*
 * ut_ftruncate -- a ftruncate that cannot return -1
 */
int
ut_ftruncate(const char *file, int line, const char *func, int fd,
             off_t length)
{
    int retval = ftruncate(fd, length);

    if (retval < 0)
        ut_fatal(file, line, func, "!ftruncate: %d %llu",
                 fd, (unsigned long long)length);

    return retval;
}
Example #28
0
/*
 * ut_pselect -- a pselect that cannot return -1
 */
int
ut_pselect(const char *file, int line, const char *func, int nfds,
           fd_set *rfds, fd_set *wfds, fd_set *efds, const struct timespec *tv,
           const sigset_t *sigmask)
{
    int retval = pselect(nfds, rfds, wfds, efds, tv, sigmask);

    if (retval < 0)
        ut_fatal(file, line, func, "!pselect");

    return retval;
}
Example #29
0
/*
 * ut_strdup -- a strdup that cannot return NULL
 */
char *
ut_strdup(const char *file, int line, const char *func,
    const char *str)
{
	char *retval = strdup(str);

	if (retval == NULL)
		ut_fatal(file, line, func, "cannot strdup %zu bytes",
		    strlen(str));

	return retval;
}
Example #30
0
/*
 * ut_truncate -- a truncate that cannot return -1
 */
int
ut_truncate(const char *file, int line, const char *func, const char *path,
            off_t length)
{
    int retval = truncate(path, length);

    if (retval < 0)
        ut_fatal(file, line, func, "!truncate: %s %llu",
                 path, (unsigned long long)length);

    return retval;
}