afsd: include sys/resource.h in afsd_kernel.c
[openafs.git] / src / afsd / afsd_kernel.c
index 7f1c874..eeb42af 100644 (file)
 
 #include <assert.h>
 #include <afs/afsutil.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <signal.h>
-#include <string.h>
-#include <stdlib.h>
-#include <time.h>
-#include <sys/types.h>
-#include <sys/stat.h>
 #include <sys/file.h>
-#include <errno.h>
-#include <sys/time.h>
-#include <dirent.h>
 #include <sys/wait.h>
 
-
-#ifdef HAVE_SYS_PARAM_H
-#include <sys/param.h>
+#if defined(AFS_LINUX20_ENV)
+#include <sys/resource.h>
 #endif
 
 #ifdef HAVE_SYS_FS_TYPES_H
 #include <sys/fstyp.h>
 #endif
 
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
-#ifdef HAVE_FCNTL_H
-#include <fcntl.h>
-#endif
+#include <ctype.h>
 
-#include <netinet/in.h>
+#include <afs/opr.h>
 #include <afs/afs_args.h>
 #include <afs/cellconfig.h>
-#include <ctype.h>
 #include <afs/afssyscalls.h>
 #include <afs/afsutil.h>
 
 #ifdef AFS_DARWIN_ENV
 #ifdef AFS_DARWIN80_ENV
-#include <sys/ioctl.h>
 #include <sys/xattr.h>
 #endif
 #include <mach/mach.h>
@@ -292,15 +272,12 @@ aix_vmount(const char *cacheMountDir)
     int size, error;
 
     size = sizeof(struct vmount) + ROUNDUP(strlen(cacheMountDir) + 1) + 5 * 4;
-    /* Malloc the vmount structure */
-    if ((vmountp = (struct vmount *)malloc(size)) == (struct vmount *)NULL) {
+    /* Malloc and zero the vmount structure */
+    if ((vmountp = calloc(1, size)) == NULL) {
        printf("Can't allocate space for the vmount structure (AIX)\n");
        exit(1);
     }
 
-    /* zero out the vmount structure */
-    memset(vmountp, '\0', size);
-
     /* transfer info into the vmount structure */
     vmountp->vmt_revision = VMT_REVISION;
     vmountp->vmt_length = size;
@@ -374,49 +351,49 @@ vmountdata(struct vmount * vmtp, char *obj, char *stub, char *host,
 #ifdef AFS_HPUX_ENV
 #define        MOUNTED_TABLE   MNT_MNTTAB
 #else
-#ifdef AFS_SUN5_ENV
-#define        MOUNTED_TABLE   MNTTAB
-#else
 #define        MOUNTED_TABLE   MOUNTED
 #endif
-#endif
 
 static int
 HandleMTab(char *cacheMountDir)
 {
-#if (defined (AFS_SUN_ENV) || defined (AFS_HPUX_ENV) || defined(AFS_SUN5_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)) && !defined(AFS_SUN58_ENV)
+#if (defined (AFS_HPUX_ENV) || defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV))
     FILE *tfilep;
-#ifdef AFS_SUN5_ENV
-    char tbuf[16];
-    struct mnttab tmntent;
-
-    memset(&tmntent, '\0', sizeof(struct mnttab));
-    if (!(tfilep = fopen(MOUNTED_TABLE, "a+"))) {
-       printf("Can't open %s\n", MOUNTED_TABLE);
-       perror(MNTTAB);
-       exit(-1);
-    }
-    tmntent.mnt_special = "AFS";
-    tmntent.mnt_mountp = cacheMountDir;
-    tmntent.mnt_fstype = "xx";
-    tmntent.mnt_mntopts = "rw";
-    sprintf(tbuf, "%ld", (long)time((time_t *) 0));
-    tmntent.mnt_time = tbuf;
-    putmntent(tfilep, &tmntent);
-    fclose(tfilep);
-#else
 #if defined(AFS_SGI_ENV) || defined(AFS_LINUX20_ENV)
     struct mntent tmntent;
+    char *dir;
+    int i;
 
     tfilep = setmntent("/etc/mtab", "a+");
+    if (!tfilep) {
+       printf("Can't open /etc/mtab for writing (errno %d); not adding "
+              "an entry for AFS\n", errno);
+       return 1;
+    }
+
+    dir = strdup(cacheMountDir);
+
+    /* trim trailing slashes; don't look at dir[0] in case we are somehow
+     * just "/" */
+    for (i = strlen(dir)-1; i > 0; i--) {
+       if (dir[i] == '/') {
+           dir[i] = '\0';
+       } else {
+           break;
+       }
+    }
+
     tmntent.mnt_fsname = "AFS";
-    tmntent.mnt_dir = cacheMountDir;
+    tmntent.mnt_dir = dir;
     tmntent.mnt_type = "afs";
     tmntent.mnt_opts = "rw";
     tmntent.mnt_freq = 1;
     tmntent.mnt_passno = 3;
     addmntent(tfilep, &tmntent);
     endmntent(tfilep);
+
+    free(dir);
+    dir = NULL;
 #else
     struct mntent tmntent;
 
@@ -441,7 +418,6 @@ HandleMTab(char *cacheMountDir)
     addmntent(tfilep, &tmntent);
     endmntent(tfilep);
 #endif /* AFS_SGI_ENV */
-#endif /* AFS_SUN5_ENV */
 #endif /* unreasonable systems */
 #ifdef AFS_DARWIN_ENV
 #ifndef AFS_DARWIN100_ENV
@@ -541,6 +517,21 @@ afsd_daemon(int nochdir, int noclose)
 }
 
 int
+afsd_check_mount(const char *rn, const char *mountdir)
+{
+    struct stat statbuf;
+
+    if (stat(mountdir, &statbuf)) {
+       printf("%s: Mountpoint %s missing.\n", rn, mountdir);
+       return -1;
+    } else if (!S_ISDIR(statbuf.st_mode)) {
+       printf("%s: Mountpoint %s is not a directory.\n", rn, mountdir);
+       return -1;
+    }
+    return 0;
+}
+
+int
 main(int argc, char **argv)
 {
     int code;