vserver 1.9.5.x5
[linux-2.6.git] / fs / fcntl.c
index 4cac5ba..65c30d6 100644 (file)
@@ -4,6 +4,7 @@
  *  Copyright (C) 1991, 1992  Linus Torvalds
  */
 
+#include <linux/syscalls.h>
 #include <linux/init.h>
 #include <linux/mm.h>
 #include <linux/fs.h>
@@ -41,38 +42,6 @@ static inline int get_close_on_exec(unsigned int fd)
        return res;
 }
 
-
-/* Expand files.  Return <0 on error; 0 nothing done; 1 files expanded,
- * we may have blocked. 
- *
- * Should be called with the files->file_lock spinlock held for write.
- */
-static int expand_files(struct files_struct *files, int nr)
-{
-       int err, expand = 0;
-#ifdef FDSET_DEBUG     
-       printk (KERN_ERR "%s %d: nr = %d\n", __FUNCTION__, current->pid, nr);
-#endif
-       
-       if (nr >= files->max_fdset) {
-               expand = 1;
-               if ((err = expand_fdset(files, nr)))
-                       goto out;
-       }
-       if (nr >= files->max_fds) {
-               expand = 1;
-               if ((err = expand_fd_array(files, nr)))
-                       goto out;
-       }
-       err = expand;
- out:
-#ifdef FDSET_DEBUG     
-       if (err)
-               printk (KERN_ERR "%s %d: return %d\n", __FUNCTION__, current->pid, err);
-#endif
-       return err;
-}
-
 /*
  * locate_fd finds a free file descriptor in the open_fds fdset,
  * expanding the fd arrays if necessary.  Must be called with the
@@ -87,7 +56,7 @@ static int locate_fd(struct files_struct *files,
        int error;
 
        error = -EINVAL;
-       if (orig_start >= current->rlim[RLIMIT_NOFILE].rlim_cur)
+       if (orig_start >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
                goto out;
 
 repeat:
@@ -106,7 +75,7 @@ repeat:
        }
        
        error = -EMFILE;
-       if (newfd >= current->rlim[RLIMIT_NOFILE].rlim_cur)
+       if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
                goto out;
        if (!vx_files_avail(1))
                goto out;
@@ -142,7 +111,7 @@ static int dupfd(struct file *file, unsigned int start)
                FD_SET(fd, files->open_fds);
                FD_CLR(fd, files->close_on_exec);
                spin_unlock(&files->file_lock);
-               // vx_openfd_inc(fd);
+               vx_openfd_inc(fd);
                fd_install(fd, file);
        } else {
                spin_unlock(&files->file_lock);
@@ -165,7 +134,7 @@ asmlinkage long sys_dup2(unsigned int oldfd, unsigned int newfd)
        if (newfd == oldfd)
                goto out_unlock;
        err = -EBADF;
-       if (newfd >= current->rlim[RLIMIT_NOFILE].rlim_cur)
+       if (newfd >= current->signal->rlim[RLIMIT_NOFILE].rlim_cur)
                goto out_unlock;
        get_file(file);                 /* We are now finished with oldfd */
 
@@ -190,10 +159,12 @@ asmlinkage long sys_dup2(unsigned int oldfd, unsigned int newfd)
        FD_SET(newfd, files->open_fds);
        FD_CLR(newfd, files->close_on_exec);
        spin_unlock(&files->file_lock);
-       // vx_openfd_inc(newfd);
 
        if (tofree)
                filp_close(tofree, files);
+       else
+               vx_openfd_inc(newfd);   /* fd was unused */
+
        err = newfd;
 out:
        return err;
@@ -295,8 +266,6 @@ void f_delown(struct file *filp)
        f_modown(filp, 0, 0, 0, 1);
 }
 
-EXPORT_SYMBOL(f_delown);
-
 static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
                struct file *filp)
 {
@@ -367,7 +336,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
        return err;
 }
 
-asmlinkage long sys_fcntl(int fd, unsigned int cmd, unsigned long arg)
+asmlinkage long sys_fcntl(unsigned int fd, unsigned int cmd, unsigned long arg)
 {      
        struct file *filp;
        long err = -EBADF;
@@ -437,11 +406,12 @@ static long band_table[NSIGPOLL] = {
 };
 
 static inline int sigio_perm(struct task_struct *p,
-                             struct fown_struct *fown)
+                             struct fown_struct *fown, int sig)
 {
-       return ((fown->euid == 0) ||
-               (fown->euid == p->suid) || (fown->euid == p->uid) ||
-               (fown->uid == p->suid) || (fown->uid == p->uid));
+       return (((fown->euid == 0) ||
+                (fown->euid == p->suid) || (fown->euid == p->uid) ||
+                (fown->uid == p->suid) || (fown->uid == p->uid)) &&
+               !security_file_send_sigiotask(p, fown, sig));
 }
 
 static void send_sigio_to_task(struct task_struct *p,
@@ -449,10 +419,7 @@ static void send_sigio_to_task(struct task_struct *p,
                               int fd,
                               int reason)
 {
-       if (!sigio_perm(p, fown))
-               return;
-
-       if (security_file_send_sigiotask(p, fown, fd, reason))
+       if (!sigio_perm(p, fown, fown->signum))
                return;
 
        switch (fown->signum) {
@@ -514,7 +481,7 @@ void send_sigio(struct fown_struct *fown, int fd, int band)
 static void send_sigurg_to_task(struct task_struct *p,
                                 struct fown_struct *fown)
 {
-       if (sigio_perm(p, fown))
+       if (sigio_perm(p, fown, SIGURG))
                send_group_sig_info(SIGURG, SEND_SIG_PRIV, p);
 }
 
@@ -547,7 +514,7 @@ int send_sigurg(struct fown_struct *fown)
        return ret;
 }
 
-static rwlock_t fasync_lock = RW_LOCK_UNLOCKED;
+static DEFINE_RWLOCK(fasync_lock);
 static kmem_cache_t *fasync_cache;
 
 /*