afsd: include sys/resource.h in afsd_kernel.c
[openafs.git] / src / afsd / afsd_kernel.c
index 5c58a32..eeb42af 100644 (file)
@@ -10,6 +10,8 @@
 #include <afsconfig.h>
 #include <afs/param.h>
 
+#include <roken.h>
+
 #define VFS 1
 
 #include <afs/cmd.h>
 #include "afsd.h"
 
 #include <assert.h>
-#include <potpourri.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>
@@ -105,24 +86,6 @@ kern_return_t DiskArbDiskAppearedWithMountpointPing_auto(char *, unsigned int,
 #include <mach/mach_port.h>
 #include <mach/mach_interface.h>
 #include <mach/mach_init.h>
-
-#include <CoreFoundation/CoreFoundation.h>
-
-#include <SystemConfiguration/SystemConfiguration.h>
-#include <SystemConfiguration/SCDynamicStore.h>
-
-#include <IOKit/pwr_mgt/IOPMLib.h>
-#include <IOKit/IOMessage.h>
-
-#include <dns_sd.h>
-
-typedef struct DNSSDState
-{
-    DNSServiceRef       service;
-    CFRunLoopSourceRef  source;
-    CFSocketRef         socket;
-} DNSSDState;
-
 #endif /* AFS_DARWIN_ENV */
 
 #ifndef MOUNT_AFS
@@ -130,6 +93,7 @@ typedef struct DNSSDState
 #endif /* MOUNT_AFS */
 
 #ifdef AFS_SGI65_ENV
+# include <sched.h>
 # define SET_RTPRI(P) {  \
     struct sched_param sp; \
     sp.sched_priority = P; \
@@ -241,8 +205,17 @@ afsd_call_syscall(long param1, long param2, long param3, long param4, long param
 #endif
             error=syscall_data.retval;
     }
+# elif defined(AFS_SUN511_ENV)
+       {
+           int rval;
+           rval = ioctl_sun_afs_syscall(AFSCALL_CALL, param1, param2, param3,
+                                        param4, param5, param6, &error);
+           if (rval) {
+               error = rval;
+           }
+       }
 # else /* AFS_DARWIN80_ENV */
-    error =
+       error =
        syscall(AFS_SYSCALL, AFSCALL_CALL, param1, param2, param3, param4,
                param5, param6, param7);
 # endif /* !AFS_DARWIN80_ENV */
@@ -293,21 +266,18 @@ afsd_call_syscall(call, parm0, parm1, parm2, parm3, parm4, parm5, parm6)
 
 #define        ROUNDUP(x)  (((x) + 3) & ~3)
 
-aix_vmount()
+aix_vmount(const char *cacheMountDir)
 {
     struct vmount *vmountp;
     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;
@@ -381,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;
 
@@ -448,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
@@ -497,7 +466,7 @@ afsd_mount_afs(const char *rn, const char *cacheMountDir)
 #elif defined(AFS_FBSD_ENV)
     if ((mount("AFS", cacheMountDir, mountFlags, (caddr_t) 0)) < 0) {
 #elif defined(AFS_AIX_ENV)
-    if (aix_vmount()) {
+    if (aix_vmount(cacheMountDir)) {
 #elif defined(AFS_HPUX100_ENV)
     if ((mount("", cacheMountDir, mountFlags, "afs", NULL, 0)) < 0) {
 #elif defined(AFS_SUN5_ENV)
@@ -548,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;