Thanks. I'll commit, but I have unimportant nitpicks below; If you'll want
to change anything (you don't have to), you can do it in a followup patch
after this one is already comitted.


--
Nadav Har'El
n...@scylladb.com

On Tue, Jan 23, 2018 at 2:11 PM, Waldemar Kozaczuk <jwkozac...@gmail.com>
wrote:

> This adds /proc/sys/kernel/hostname to procfs in order to support
> os.Hostname() implementation in golang. Please look at
> https://golang.org/src/os/sys_linux.go.
>
> Most of this patch was authored by Benoit Canet.
>
> Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>
> ---
>  fs/procfs/procfs_vnops.cc | 23 +++++++++++++++++++++++
>  1 file changed, 23 insertions(+)
>
> diff --git a/fs/procfs/procfs_vnops.cc b/fs/procfs/procfs_vnops.cc
> index dc66ff5..a9aef72 100644
> --- a/fs/procfs/procfs_vnops.cc
> +++ b/fs/procfs/procfs_vnops.cc
> @@ -5,6 +5,8 @@
>   * BSD license as described in the LICENSE file in the top-level
> directory.
>   */
>
> +#include <unistd.h>
> +
>  #include <osv/dentry.h>
>  #include <osv/vnode.h>
>  #include <osv/mount.h>
> @@ -350,6 +352,19 @@ static std::string procfs_mounts()
>         return rstr;
>  }
>
> +static std::string procfs_hostname()
> +{
> +    char hostname[4096];
>

This is excessive, our host name cannot longer than sizeof
utsname.nodename, but I don't
know which constant or macro or something to suggest instead.

+    memset(hostname, 0, 4096);
>

I don't think we need this. Note that our (Musl's) gethostname()
implementation always ensures
that the result ends with null, even if truncated. For this reason I think
we can also use 4096
below, not 4095.

>
> +
> +    int ret = gethostname(hostname, 4095);
> +    if (ret < 0) {
> +        return std::string("");
> +    }
> +
> +    return std::string(hostname);
> +}
> +
>  static int
>  procfs_mount(mount* mp, const char *dev, int flags, const void* data)
>  {
> @@ -359,10 +374,18 @@ procfs_mount(mount* mp, const char *dev, int flags,
> const void* data)
>      self->add("maps", inode_count++, mmu::procfs_maps);
>      self->add("stat", inode_count++, procfs_stats);
>
> +    auto kernel = make_shared<proc_dir_node>(inode_count++);
> +    kernel->add("hostname", inode_count++, procfs_hostname);
> +
> +    auto sys = make_shared<proc_dir_node>(inode_count++);
> +    sys->add("kernel", kernel);
> +
>      auto* root = new proc_dir_node(vp->v_ino);
>      root->add("self", self);
>      root->add("0", self); // our standard pid
>      root->add("mounts", inode_count++, procfs_mounts);
> +    root->add("sys", sys);
> +
>      root->add("cpuinfo", inode_count++, [] { return
> processor::features_str(); });
>
>      vp->v_data = static_cast<void*>(root);
> --
> 2.7.4
>
> --
> You received this message because you are subscribed to the Google Groups
> "OSv Development" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to osv-dev+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to