Linux系统调用(219)\chroot()函数UnixLinux

算法 ww9992019com 发表于 1 周前

www.9951026.com开户请拨15894452300法国猫科新物种上海南汇区sayQ6J<div style="width:100%;float:left;" class="article-content">

                <input type="hidden" name="article_id" id="article_id" value="1501">
                <input type="hidden" name="catid" id="catid" value="0">

                <p>

chroot - 改变根目录</p>

<h1 class="manpages">

内容简介</h1>

<table cellpadding="5" class="src">

<tbody>

    <tr>

        <td>

            <pre courier new monospace font-size: margin-bottom:>

<b>#include &lt;unistd.h&gt;</b> </pre>

            <p>

                <b>int chroot(const char *</b><i>path</i><b>);</b></p>

        </td>

    </tr>

</tbody>

</table>

<h1 class="manpages">

描述</h1>

<p>

<b>chroot</b>() <span>改变根目录中指定的路径。此目录将用于与/开头的路径名。根目录继承当前进程的的所有子目录。</span></p>

<p>

Only a privileged process (Linux: one with the <b>CAP_SYS_CHROOT</b> capability) may call<b>chroot</b>(2).This call changes an ingredient in the pathname resolution process and does nothing else.</p>

<p>

This call does not change the current working directory, so that after the call ‘.’ can be outside the tree rooted at ‘/’. In particular, the superuser can escape from a ‘chroot jail’ by doing ‘mkdir foo; chroot foo; cd ..’.</p>

<p>

This call does not close open file descriptors, and such file descriptors may allow access to files outside the chroot tree.</p>

<h1 class="manpages">

返回值</h1>

<p>

On success, zero is returned. On error, -1 is returned, and <i>errno</i> is set appropriately.</p>

<h1 class="manpages">

错误</h1>

<p>

Depending on the file system, other errors can be returned. The more general errors are listed below:</p>

<table border="1" cellpadding="5" cellspacing="0" class="src">

<tbody>

    <tr>

        <th width="25%">

            Error Code</th>

        <th>

            描述</th>

    </tr>

    <tr valign="top">

        <td>

            <b>EACCES</b></td>

        <td valign="bottom">

            Search permission is denied on a component of the path prefix. (See also <b>path_resolution</b>(2).)</td>

    </tr>

    <tr valign="top">

        <td>

            <b>EFAULT</b></td>

        <td valign="bottom">

            <i>path</i> points outside your accessible address space.</td>

    </tr>

    <tr valign="top">

        <td>

            <b>EIO</b></td>

        <td valign="bottom">

            An I/O error occurred.</td>

    </tr>

    <tr valign="top">

        <td>

            <b>ELOOP</b></td>

        <td valign="bottom">

            Too many symbolic links were encountered in resolving <i>path</i>.</td>

    </tr>

    <tr>

        <td>

            <b>ENAMETOOLONG</b></td>

        <td>

            <i>path</i> is too long.</td>

    </tr>

    <tr valign="top">

        <td>

            <b>ENOENT</b></td>

        <td valign="bottom">

            The file does not exist.</td>

    </tr>

    <tr valign="top">

        <td>

            <b>ENOMEM</b></td>

        <td valign="bottom">

            Insufficient kernel memory was available.</td>

    </tr>

    <tr>

        <td>

            <b>ENOTDIR</b></td>

        <td>

            A component of <i>path</i> is not a directory.</td>

    </tr>

    <tr valign="top">

        <td>

            <b>EPERM</b></td>

        <td valign="bottom">

            The caller has insufficient privilege.</td>

    </tr>

</tbody>

</table>

<h1 class="manpages">

遵循于</h1>

<p>

SVr4, 4.4BSD, SUSv2 (marked LEGACY). This function is not part of POSIX.1-2001.</p>

<h1 class="manpages">

注意</h1>

<p>

A child process created via <b>fork</b>(2) inherits its parent’s root directory. The root directory is left unchanged by <b>execve</b>(2).</p>

<p>

FreeBSD has a stronger <b>jail</b>() system call.</p>

<h1 class="manpages">

另请参阅</h1>

<ul>

<li>

    <p>

        <a href="http://www.yiibai.com/unix_system_calls/chdir.html">chdir (2)</a></p>

</li>

<li>

    <p>

        <a href="http://www.yiibai.com/unix_system_calls/path_resolution.html">path_resolution (2)</a></p>

    <div>

         </div>

</li>

</ul>

                <br>
                <p style="text-align:center;float:left;width:100%;margin-top:24px;margin-bottom:18px;">
                        <button class="layui-btn layui-btn-danger" id="btn-reward"> ¥ 我要打赏 </button>  
                        <button class="layui-btn" id="article-perfect">
                            <i class="layui-icon layui-icon-edit"></i>教程纠错
                        </button>
                        <button class="layui-btn layui-btn-normal" id="action-collection">
                            <i class="layui-icon layui-icon-rate"></i>收藏
                        </button>
                </p>



                <div style="width:100%;margin-bottom: 16px; height: 32px;margin-top:18px;float:left;">

                    <span style="float:left;">上一篇:<a href="http://f2e.im/u/ww9992019com" title="chown()函数 Unix/Linux"><i class="layui-icon"></i>
                            chown()函数 Unix/Linux</a></span>
                                            <span style="float:right;">下一篇:<a href="http://f2e.im/u/ww9992019com" style="float:right;" title="下一篇:clone()函数 Unix/Linux"><i class="layui-icon"></i>
                            clone()函数 Unix/Linux</a></span>
                                            <div id="googlead" style="float:left;margin-top:8px;">
                        <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
                        <!-- yiibai下方 -->
                        <ins class="adsbygoogle" style="display:inline-block;width:728px;height:90px" data-ad-client="ca-pub-1090193214637198" data-ad-slot="6494738921"></ins>
                        <script>
                            (adsbygoogle = window.adsbygoogle || []).push({});
                        </script>
                    </div>
                </div>

                <div style="width:100%;margin-top:18px;float:left;">


            </div>
暂无回复,说出你的观点吧
登录后即可参与回复