Beispiel #1
0
        public void InitializeAsyncLocks()
        {
            CreateAndCloseLockFile();

            uint groupId = (uint)Mono.Unix.Native.Syscall.getgrnam(System.Environment.GetEnvironmentVariable("KUDU_RUN_USER")).gr_gid;

            //
            // chown the file file
            //

            Mono.Unix.Native.Syscall.chown(_lockFile, Mono.Unix.Native.Syscall.getuid(), groupId);

            //
            // setup permissions 770 on the file.
            //

            Mono.Unix.Native.FilePermissions permissions =
                Mono.Unix.Native.FilePermissions.S_IRWXU |
                Mono.Unix.Native.FilePermissions.S_IRGRP |
                Mono.Unix.Native.FilePermissions.S_IWGRP |
                Mono.Unix.Native.FilePermissions.S_IXGRP;

            //
            // chmod the file.
            //

            Mono.Unix.Native.Syscall.chmod(_lockFile, permissions);
        }
Beispiel #2
0
        /*
         * ~FileRWLock()
         * {
         *  if (_fd != 0)
         *  {
         *      Mono.Unix.Native.Syscall.close(_fd);
         *      _fd = 0;
         *  }
         * }
         */

        public void InitializeAsyncLocks()
        {
            //
            // Create the file.
            //

            int fd = Mono.Unix.Native.Syscall.open(
                _lockFile,
                Mono.Unix.Native.OpenFlags.O_CREAT | Mono.Unix.Native.OpenFlags.O_WRONLY | Mono.Unix.Native.OpenFlags.O_APPEND | Mono.Unix.Native.OpenFlags.O_NONBLOCK,
                FilePermissions.ACCESSPERMS);

            if (fd == -1)
            {
                Errno error = Mono.Unix.Native.Syscall.GetLastError();
                throw new Exception("FileRWLock: file open returned:  " + error.ToString());
            }

            _fd = fd;

            //
            // close the file.
            //

            Mono.Unix.Native.Syscall.close(fd);

            uint groupId = (uint)Mono.Unix.Native.Syscall.getgrnam("kudu_group").gr_gid;

            //
            // chown the file file
            //

            Mono.Unix.Native.Syscall.chown(_lockFile, Mono.Unix.Native.Syscall.getuid(), groupId);

            //
            // setup permissions 770 on the file.
            //

            Mono.Unix.Native.FilePermissions permissions =
                Mono.Unix.Native.FilePermissions.S_IRWXU |
                Mono.Unix.Native.FilePermissions.S_IRGRP |
                Mono.Unix.Native.FilePermissions.S_IWGRP |
                Mono.Unix.Native.FilePermissions.S_IXGRP;

            //
            // chmod the file.
            //

            Mono.Unix.Native.Syscall.chmod(_lockFile, permissions);
        }
Beispiel #3
0
        public static void open(string path, OpenFlags flags, Mono.Unix.Native.FilePermissions mode, Action <FileStream, Exception> callback) // fd, error
        {
            ThreadPool.QueueUserWorkItem(a =>
            {
                try
                {
                    FileMode fm;
                    FileAccess fa;
                    FileShare fs = FileShare.ReadWrite;

                    if (0 != (flags & OpenFlags.O_CREAT))
                    {
                        fm = FileMode.Create;
                    }
                    else
                    {
                        fm = FileMode.Open;
                    }

                    if (0 != (flags & OpenFlags.O_RDWR))
                    {
                        fa = FileAccess.ReadWrite;
                    }
                    else if (0 != (flags & OpenFlags.O_WRONLY))
                    {
                        fa = FileAccess.Write;
                    }
                    else
                    {
                        fa = FileAccess.Read;
                    }


                    var stream = new FileStream(path, fm, fa, fs);
                    Boundary.Instance.ExecuteOnTargetLoop(() => callback(stream, null));
                }
                catch (Exception e)
                {
                    Boundary.Instance.ExecuteOnTargetLoop(() => callback(null, e));
                }
            });
        }
Beispiel #4
0
 static extern IntPtr eio_open(string path, OpenFlags flags, mode_t mode, int pri, eio_cb cb, IntPtr data);
Beispiel #5
0
 static extern IntPtr eio_open(string path, OpenFlags flags, mode_t mode, int pri, eio_cb cb, IntPtr data);