Back to index

avfs  1.0.1
Defines | Functions | Variables
sysdeps.c File Reference
#include "internal.h"
#include "config.h"
#include "info.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <unistd.h>
#include <fcntl.h>
#include <syslog.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/time.h>

Go to the source code of this file.

Defines

#define DEFAULT_LOGMASK   (AVLOG_ERROR | AVLOG_WARNING)
#define LOGMSG_SIZE   1024

Functions

static AV_LOCK_DECL (loglock)
static int debug_get (struct entry *ent, const char *param, char **retp)
static int debug_set (struct entry *ent, const char *param, const char *val)
static void log_open ()
static void log_close ()
static void log_init ()
static int logfile_get (struct entry *ent, const char *param, char **retp)
static int logfile_set (struct entry *ent, const char *param, const char *val)
static void filelog (const char *msg)
void av_init_logstat ()
void av_log (int type, const char *format,...)
avdev_t av_mkdev (int major, int minor)
void av_splitdev (avdev_t dev, int *majorp, int *minorp)
char * av_get_config (const char *param)
void av_default_stat (struct avstat *stbuf)
void av_curr_time (avtimestruc_t *tim)
avtime_t av_time ()
void av_sleep (unsigned long msec)
avtime_t av_mktime (struct avtm *tp)
void av_localtime (avtime_t t, struct avtm *tp)
void av_registerfd (int fd)

Variables

static int loginited
static int logmask
static char * logfile
static int logfd

Define Documentation

Definition at line 34 of file sysdeps.c.

#define LOGMSG_SIZE   1024

Definition at line 151 of file sysdeps.c.


Function Documentation

void av_curr_time ( avtimestruc_t *  tim)

Definition at line 274 of file sysdeps.c.

{
    struct timeval tv;

    gettimeofday(&tv, NULL);

    tim->sec = tv.tv_sec;
    tim->nsec = tv.tv_usec * 1000;
}

Here is the caller graph for this function:

void av_default_stat ( struct avstat stbuf)

Definition at line 249 of file sysdeps.c.

{
    static avuid_t myuid = -1;
    static avuid_t mygid = -1;

    if(myuid == -1) {
        myuid = getuid();
        mygid = getgid();
    }

    stbuf->dev = 0;
    stbuf->ino = 0;
    stbuf->mode = 0;
    stbuf->nlink = 0;
    stbuf->uid = myuid;
    stbuf->gid = mygid;
    stbuf->rdev = 0;
    stbuf->size = 0;
    stbuf->blksize = 512;
    stbuf->blocks = 0;
    av_curr_time(&stbuf->atime);
    stbuf->mtime = stbuf->atime;
    stbuf->ctime = stbuf->atime;
}

Here is the call graph for this function:

Here is the caller graph for this function:

char* av_get_config ( const char *  param)

Definition at line 230 of file sysdeps.c.

{
    const char *val;

    val = NULL;

    if(strcmp(param, "moduledir") == 0) 
        val = MODULE_DIR;
    else if(strcmp(param, "compiledate") == 0) 
        val = COMPILE_DATE;
    else if(strcmp(param, "compilesystem") == 0) 
        val = COMPILE_SYSTEM;
  
    if(val == NULL)
        return NULL;

    return av_strdup(val);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void av_init_logstat ( )

Definition at line 168 of file sysdeps.c.

{
    struct statefile statf;

    if(!loginited)
        log_init();

    statf.data = NULL;
    statf.get = debug_get;
    statf.set = debug_set;

    av_avfsstat_register("debug", &statf);

    statf.get = logfile_get;
    statf.set = logfile_set;

    av_avfsstat_register("logfile", &statf);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void av_localtime ( avtime_t  t,
struct avtm tp 
)

Definition at line 321 of file sysdeps.c.

{
    struct tm tms;
  
    localtime_r(&t, &tms);
  
    tp->sec  = tms.tm_sec;
    tp->min  = tms.tm_min;
    tp->hour = tms.tm_hour;
    tp->day  = tms.tm_mday;
    tp->mon  = tms.tm_mon;
    tp->year = tms.tm_year;
}

Here is the caller graph for this function:

static AV_LOCK_DECL ( loglock  ) [static]
void av_log ( int  type,
const char *  format,
  ... 
)

Definition at line 187 of file sysdeps.c.

{
    va_list ap;
    char buf[LOGMSG_SIZE+1];

    AV_LOCK(loglock);

    if(!loginited)
        log_init();

    if((type & logmask) == 0) {
        AV_UNLOCK(loglock);
        return;
    }

    va_start(ap, format);
#ifdef HAVE_VSNPRINTF
    vsnprintf(buf, LOGMSG_SIZE, format, ap);
#else
    strncpy(buf, format, LOGMSG_SIZE);
#endif  
    buf[LOGMSG_SIZE] = '\0';
    va_end(ap);

    if(logfile == NULL)
        syslog(LOG_INFO, "%s", buf);
    else
        filelog(buf);
    AV_UNLOCK(loglock);
}

Here is the call graph for this function:

avdev_t av_mkdev ( int  major,
int  minor 
)

Definition at line 218 of file sysdeps.c.

{
    return makedev(major, minor);
}

Here is the caller graph for this function:

avtime_t av_mktime ( struct avtm tp)

Definition at line 306 of file sysdeps.c.

{
    struct tm tms;
  
    tms.tm_sec  = tp->sec;
    tms.tm_min  = tp->min;
    tms.tm_hour = tp->hour;
    tms.tm_mday = tp->day;
    tms.tm_mon  = tp->mon;
    tms.tm_year = tp->year;
    tms.tm_isdst = -1;

    return mktime(&tms);
}

Here is the caller graph for this function:

void av_registerfd ( int  fd)

Definition at line 336 of file sysdeps.c.

{
    fcntl(fd, F_SETFD, FD_CLOEXEC);
}

Here is the caller graph for this function:

void av_sleep ( unsigned long  msec)

Definition at line 289 of file sysdeps.c.

{
    struct timespec rem;
    int res;

    rem.tv_sec = msec / 1000;
    rem.tv_nsec = (msec % 1000) * 1000 * 1000;

    do {
        struct timespec req;

        req = rem;
        res = nanosleep(&req, &rem);
    } while(res == -1 && errno == EINTR);
}

Here is the caller graph for this function:

void av_splitdev ( avdev_t  dev,
int *  majorp,
int *  minorp 
)

Definition at line 223 of file sysdeps.c.

{
    *majorp = major(dev);
    *minorp = minor(dev);
}

Definition at line 284 of file sysdeps.c.

{
    return time(NULL);
}

Here is the caller graph for this function:

static int debug_get ( struct entry ent,
const char *  param,
char **  retp 
) [static]

Definition at line 42 of file sysdeps.c.

{
    char buf[32];
    
    AV_LOCK(loglock);
    sprintf(buf, "%02o\n", logmask);
    AV_UNLOCK(loglock);

    *retp = av_strdup(buf);
    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int debug_set ( struct entry ent,
const char *  param,
const char *  val 
) [static]

Definition at line 54 of file sysdeps.c.

{
    int mask;

    if(val[0] < '0' || val[0] > '7' || val[1] < '0' || val[1] > '7' ||
       (val[2] != '\0' && !isspace((int) val[2]))) 
        return -EIO;

    mask = (val[0] - '0') * 8 + (val[1] - '0');
    
    AV_LOCK(loglock);
    logmask = mask;
    AV_UNLOCK(loglock);

    return 0;
}

Here is the caller graph for this function:

static void filelog ( const char *  msg) [static]

Definition at line 152 of file sysdeps.c.

{
    char buf[LOGMSG_SIZE + 128];

    if(logfd != -1) {
        struct avtm tmbuf;

        av_localtime(time(NULL), &tmbuf);
        sprintf(buf, "%02i/%02i %02i:%02i:%02i avfs[%lu]: %s\n", 
                tmbuf.mon + 1, tmbuf.day, tmbuf.hour, tmbuf.min, tmbuf.sec,
                (unsigned long) getpid(), msg);
        
        write(logfd, buf, strlen(buf));
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void log_close ( ) [static]

Definition at line 83 of file sysdeps.c.

{
    if(logfile != NULL) {
        if(strcmp(logfile, "-") != 0 && logfd != -1)
            close(logfd);
    } else {
        closelog();
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void log_init ( ) [static]

Definition at line 93 of file sysdeps.c.

{
    char *logenv;

    logmask = DEFAULT_LOGMASK;
    logenv = getenv("AVFS_DEBUG");
    if(logenv != NULL &&
       logenv[0] >= '0' && logenv[0] <= '7' &&
       logenv[1] >= '0' && logenv[1] <= '7' &&
       logenv[2] == '\0')
        logmask = (logenv[0] - '0') * 8 + (logenv[1] - '0');

    logfile = getenv("AVFS_LOGFILE");
    log_open();
    loginited = 1;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void log_open ( ) [static]

Definition at line 71 of file sysdeps.c.

{
    if(logfile != NULL) {
        if(strcmp(logfile, "-") == 0)
            logfd = STDERR_FILENO;
        else
            logfd = open(logfile, O_WRONLY | O_APPEND | O_CREAT, 0600);
    } else {
        openlog("avfs", LOG_CONS | LOG_PID, LOG_USER);
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int logfile_get ( struct entry ent,
const char *  param,
char **  retp 
) [static]

Definition at line 110 of file sysdeps.c.

{
    char *s;

    AV_LOCK(loglock);
    if(logfile != NULL)
        s = av_stradd(NULL, logfile, "\n", NULL);
    else
        s = av_strdup("");
    AV_UNLOCK(loglock);

    *retp = s;

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

static int logfile_set ( struct entry ent,
const char *  param,
const char *  val 
) [static]

Definition at line 126 of file sysdeps.c.

{
    char *s;
    unsigned int len;

    s = av_strdup(val);
    len = strlen(s);
    if(len > 0 && s[len-1] == '\n')
        s[len-1] = '\0';

    if(s[0] == '\0') {
        av_free(s);
        s = NULL;
    }

    AV_LOCK(loglock);
    log_close();
    av_free(logfile);
    logfile = s;
    log_open();
    AV_UNLOCK(loglock);

    return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

int logfd [static]

Definition at line 39 of file sysdeps.c.

char* logfile [static]

Definition at line 38 of file sysdeps.c.

int loginited [static]

Definition at line 36 of file sysdeps.c.

int logmask [static]

Definition at line 37 of file sysdeps.c.