Re: [util-linux] [PATCH 4/5] sulogin: mount temporary /dev and /proc if not found

Dave Reisner
2012-12-07T17:01:21Z

On Fri, Dec 07, 2012 at 04:49:17PM +0100, Dr. Werner Fink wrote:
> On Fri, Dec 07, 2012 at 09:17:09AM -0500, Dave Reisner wrote:
> > On Fri, Dec 07, 2012 at 09:00:57AM +0100, Werner Fink wrote:
> > > +# define dovoid(f) if ((f)){}
> > > +static __attribute__((__constructor__)) void getmounts(void)
> > > +{
> > > + struct statfs st;
> > > + if (statfs("/proc", &st) == 0 && st.f_type != PROC_SUPER_MAGIC) {
> >
> > Why not use the standard mountpoint check -- compare the devno with / ?
> >
> > > + if (mount("proc", "/proc", "proc", MS_RELATIME, NULL) == 0)
> > > + mounts |= MNT_PROCFS;
> > > + }
> > > + if (statfs("/dev", &st) == 0 && st.f_type != TMPFS_MAGIC) {
> > > + if (mount("devtmpfs", "/dev", "devtmpfs", MS_RELATIME, "mode=0755,nr_inodes=0") == 0) {
> > > + mounts |= MNT_DEVTMPFS;
> >
> > Isn't all the work below here redundant? devtmpfs provides these
> > things.
> >
> > > + (void)mknod("/dev/console", S_IFCHR|S_IRUSR|S_IWUSR, makedev(TTYAUX_MAJOR, 1));
> > > + if (symlink("/proc/self/fd", "/dev/fd") == 0) {
> > > + dovoid(symlink("fd/0", "/dev/stdin"));
> > > + dovoid(symlink("fd/1", "/dev/stdout"));
> > > + dovoid(symlink("fd/2", "/dev/stderr"));
> > > + }
> > > + }
> > > + }
> > > + if (mounts) atexit(putmounts);
> > > +}
> > > +# undef dovoid
> > > +#endif
> > > +
> > > static void usage(FILE *out)
> > > {
> > > fputs(USAGE_HEADER, out);
>
> We're talking about the very early boot stage, there is no udev nor anything else
> and the I've choosen this as this had worked very well in initrd where it had crashed
> before. I do not say that there is no other way to do this but this way it works and
> the links I've done had been missed.

Ok, I didn't realize udev still was responsible for these links these
days, but perusing the code shows otherwise. Could you explain why
sulogin is wanted in the initramfs? Seems like an odd use case to me.

> If in initrd the sulogin will be called after mounting /proc and /dev and running
> udev rules or enabling the links in initrd then the code does only check for existence
> of /proc and /dev.

If you're in the initramfs, rootfs is tmpfs. Won't your statfs check
return a buffer which has f_type == TMPFS_MAGIC even if /dev is not
mounted?

> Werner
>
> --
> "Having a smoking section in a restaurant is like having
> a peeing section in a swimming pool." -- Edward Burr
> --
> To unsubscribe from this list: send the line "unsubscribe util-linux" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html