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

Dr. Werner Fink
2012-12-07T15:49:21Z

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.

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.

Werner

--
"Having a smoking section in a restaurant is like having
a peeing section in a swimming pool." -- Edward Burr