Back to index

avfs  1.0.1
Classes | Functions
avfscoda.h File Reference
#include <sys/types.h>
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  child_message

Functions

void run (int cfs, const char *codadir, int dm)
void child_process (int infd, int outfd)
int mount_coda (const char *dev, const char *dir, int devfd, int quiet)
int unmount_coda (const char *dir, int quiet)
void set_signal_handlers ()
void clean_exit (int status)
void run_exit ()
void user_child (pid_t pid)

Class Documentation

struct child_message

Definition at line 11 of file avfscoda.h.

Class Members
int path1size
int path2size
int reqsize

Function Documentation

void child_process ( int  infd,
int  outfd 
)

Definition at line 526 of file child.c.

{
    int res;
    int insize;
    int numread;
    char ibuf[MAXPMSGLEN];
    char *bufcpy;
    pthread_attr_t attr;
    pthread_t thrid;

    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);

    child_outfd = outfd;

#if 0
    pid_t pid = getpid();
    uid_t uid = getuid();
    gid_t gid = getgid();
       

    fprintf(stderr, "My pid: %i\n", pid);
    sleep(15);
#endif
    
    while(1) {
        numread = read(infd, &insize, sizeof(insize));
        if(numread == -1) {
            fprintf(stderr, "Error reading from device: %s\n",
                    strerror(errno));
            exit(1);
        }
        if(insize > MAXPMSGLEN || insize <= 0) {
            fprintf(stderr, "Error: illegal size");
            exit(1);
        }
              
        numread = read(infd, ibuf, insize);
        if(numread == -1) {
            fprintf(stderr, "Error reading from device: %s\n", 
                    strerror(errno));
            exit(1);
        }
       
       bufcpy = malloc(numread);
       if(bufcpy == NULL) {
           fprintf(stderr, "Out of memory\n");
           exit(1);
       }
       
       memcpy(bufcpy, ibuf, numread);


#if MULTITHREADED
       res = pthread_create(&thrid, &attr, process_request, bufcpy);
       if(res != 0) {
           fprintf(stderr, "Error creating thread: %s\n", strerror(errno));
           exit(1);
       }
#else
        process_request(bufcpy);
#endif
       
    }
}

Here is the call graph for this function:

Here is the caller graph for this function:

void clean_exit ( int  status)

Definition at line 30 of file avfscoda.c.

{
    /* Just in case */
    if(getpid() != main_pid) exit(status);

    run_exit();

    if(mount_pid != -1) kill(mount_pid, SIGKILL);

    exit(status);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int mount_coda ( const char *  dev,
const char *  dir,
int  devfd,
int  quiet 
)

Definition at line 20 of file mount.c.

{
    int res;
    const char *type;
    FILE *fd;
    struct mntent ent;
    void *mntdata = NULL;
#ifdef CODA_MOUNT_VERSION
    struct coda_mount_data data;
    
    data.version = CODA_MOUNT_VERSION;
    data.fd = devfd;
    mntdata = &data;
#endif
    type = "coda";
    res = mount("coda", dir, type, MS_MGC_VAL | MS_NOSUID | MS_NODEV, mntdata);
    
    if(res == -1) {
       if(!quiet) 
           fprintf(stderr, "mount failed: %s\n", strerror(errno));

       return -1;
    }
    
    fd = setmntent("/etc/mtab", "a");
    if(fd == NULL) {
       fprintf(stderr, "setmntent(\"/etc/mtab\") failed: %s\n",
              strerror(errno));
       return -1;
    }
    
    ent.mnt_fsname = (char *) dev;
    ent.mnt_dir = (char *) dir;
    ent.mnt_type = (char *) type;
    ent.mnt_opts = "rw,nosuid,nodev";
    ent.mnt_freq = 0;
    ent.mnt_passno = 0;
    res = addmntent(fd, & ent);
    if(res != 0) {
       fprintf(stderr, "addmntent() failed: %s\n", strerror(errno));
    }
    
    endmntent(fd);
    
    return 0;
}

Here is the caller graph for this function:

void run ( int  cfs,
const char *  codadir,
int  dm 
)

Definition at line 1613 of file dispatch.c.

{
    int i;

    openlog("avfscoda", LOG_CONS, LOG_USER);
       
    codafd = cfs;
    codadir = dir;
    logfile = stderr;
    numfids = 0;
    checknum = 0;
    debugmode = dm;
       
    for(i = 0; i < MAXUSERS; i++)
        currusers[i].serverpid = -1;
       
    set_signal_handlers();
       
    process();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void run_exit ( )

Definition at line 1183 of file dispatch.c.

{
    int i;
       
    for(i = 0; i < MAXUSERS; i++) {
        if(currusers[i].serverpid > 0) {
            kill(currusers[i].serverpid, SIGTERM);
        }
    }
       
    /* FIXME: should wait until the children are all dead */
       
    coda_flush();
    close(codafd);
    unmount_coda(codadir, 0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 73 of file avfscoda.c.

{
    struct sigaction sa;

    sa.sa_handler = exit_handler;
    sigemptyset(&(sa.sa_mask));
    sa.sa_flags = 0;

    if (sigaction(SIGHUP, &sa, NULL) == -1 || 
       sigaction(SIGINT, &sa, NULL) == -1 || 
       sigaction(SIGTERM, &sa, NULL) == -1) {
       
       perror("Cannot set exit signal handlers");
       clean_exit(1);
    }

    sa.sa_handler = SIG_IGN;
    
    if(sigaction(SIGPIPE, &sa, NULL) == -1) {
       perror("Cannot set ignored signals");
       clean_exit(1);
    }

}

Here is the call graph for this function:

Here is the caller graph for this function:

int unmount_coda ( const char *  dir,
int  quiet 
)

Definition at line 67 of file mount.c.

{
    int res;
    FILE *fdold, *fdnew;
    struct mntent *entp;
    
    res = umount(dir);
    
    if(res == -1) {
       if(!quiet) 
           fprintf(stderr, "umount failed: %s\n", strerror(errno));

       return -1;
    }
    
    fdold = setmntent("/etc/mtab", "r");
    if(fdold == NULL) {
       fprintf(stderr, "setmntent(\"/etc/mtab\") failed: %s\n",
              strerror(errno));
       return -1;
    }

    fdnew = setmntent("/etc/mtab~", "w");
    if(fdnew == NULL) {
       fprintf(stderr, "setmntent(\"/etc/mtab~\") failed: %s\n",
              strerror(errno));
       return -1;
    }

    do {
       entp = getmntent(fdold);
       if(entp != NULL) {
           if(strcmp(entp->mnt_dir, dir) != 0) {
              res = addmntent(fdnew, entp);
              if(res != 0) {
                  fprintf(stderr, "addmntent() failed: %s\n",
                         strerror(errno));
              }
           }
       }
    } while(entp != NULL);

    endmntent(fdold);
    endmntent(fdnew);

    res = rename("/etc/mtab~", "/etc/mtab");
    if(res == -1) {
       fprintf(stderr, "rename(\"/etc/mtab~\", \"/etc/mtab\") failed: %s\n", 
              strerror(errno));
       return -1;
    }
    
    return 0;
}

Here is the caller graph for this function:

void user_child ( pid_t  pid)

Definition at line 1200 of file dispatch.c.

{
    int i;
       
    for(i = 0; i < MAXUSERS; i++) {
        if(currusers[i].serverpid == pid) {
            log("Child %i (%i/%i) exited\n", 
                pid, currusers[i].uid, 
                currusers[i].gid);
                     
            currusers[i].serverpid = 0;
                     
            return;
        }
    }
       
    logerr("Unknown child %i exited\n", pid);
}

Here is the call graph for this function:

Here is the caller graph for this function: