Пример #1
0
        /// <summary>
        /// Changes the current directory to newDir
        /// </summary>
        /// <param name="newDir">The new working directory</param>
        /// <returns>Errorcode</returns>
        public static ErrorCode ChDir(string newDir)
        {
            newDir = VFS.CreateAbsolutePath(newDir);
            Node node = VFS.GetByAbsolutePath(newDir);

            if (node == null)
            {
                Heap.Free(newDir);
                return(ErrorCode.ENOENT);
            }

            if (node.Flags != NodeFlags.DIRECTORY)
            {
                Heap.Free(newDir);
                Heap.Free(node);
                return(ErrorCode.ENOTDIR);
            }

            Heap.Free(node);

            // GetByAbsolutePath makes sure there's a slash on the end
            Tasking.CurrentTask.CurrentDirectory = newDir;

            return(ErrorCode.SUCCESS);
        }
Пример #2
0
        /// <summary>
        /// Creates another process from an executable
        /// </summary>
        /// <param name="path">The path to the executable</param>
        /// <param name="argv">The arguments</param>
        /// <param name="envp">The environment path</param>
        /// <returns>Errorcode</returns>
        public static int Run(string path, string[] argv, string[] envp)
        {
            // TODO: envp
            path = VFS.CreateAbsolutePath(path);
            int pid = Loader.StartProcess(path, argv, Task.SpawnFlags.NONE);

            Heap.Free(path);
            return(pid);
        }
Пример #3
0
        /// <summary>
        /// Replaces the current process with another executable
        /// </summary>
        /// <param name="path">The path to the executable</param>
        /// <param name="argv">The arguments</param>
        /// <param name="envp">The environment path</param>
        /// <returns>Errorcode</returns>
        public static int Execve(string path, string[] argv, string[] envp)
        {
            // TODO: envp
            path = VFS.CreateAbsolutePath(path);
            int error = Loader.StartProcess(path, argv, Task.SpawnFlags.SWAP_PID);

            Heap.Free(path);
            if (error < 0)
            {
                return(error);
            }

            // We spawned a task but the current process should actually be replaced
            // So we must kill the current process
            Tasking.RemoveTaskByPID(Tasking.CurrentTask.PID);

            return(0);
        }