Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
Bug 192682 - New "checkdir" applet for baselayout 2
Summary: New "checkdir" applet for baselayout 2
Status: RESOLVED FIXED
Alias: None
Product: Gentoo Linux
Classification: Unclassified
Component: [OLD] baselayout (show other bugs)
Hardware: All Linux
: High enhancement (vote)
Assignee: Gentoo's Team for Core System packages
URL:
Whiteboard:
Keywords:
: 205183 (view as bug list)
Depends on:
Blocks:
 
Reported: 2007-09-16 12:38 UTC by Renato Caldas
Modified: 2008-01-19 20:37 UTC (History)
1 user (show)

See Also:
Package list:
Runtime testing required: ---


Attachments
The patch against baselayout 2 (checkdir_baselayout2.patch,3.80 KB, patch)
2007-09-16 12:39 UTC, Renato Caldas
Details | Diff
Checkdir patch v2, some corrections/improvements (checkdir_baselayout2_v2.patch,4.06 KB, patch)
2007-09-18 19:13 UTC, Renato Caldas
Details | Diff
Checkdir patch v2, the correct one (checkdir_baselayout2_v2.patch,4.02 KB, patch)
2007-09-18 19:16 UTC, Renato Caldas
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Renato Caldas 2007-09-16 12:38:01 UTC
This applet checks for the existance of a directory and optionally checks its ownership. The syntax is "checkdir -d <directory> [-o <owner:group>]".

This is required in some of the init scripts for a proper support of tmpfs /var/run (see bug 181527). Unfortunately not all packages support this feature, as they rely on the "keepdir"s created by the ebuild, which breaks stuff if the /var/run dir is mounted in tmpfs. And those who do support it, do not use an "unified way" to do it.

So this is the reason for this simple applet. I've created it against baselayout 2 because I don't have baselayout 1, but I guess it would be simple to port, as it is a simple "mkdir -p <dir> && chown <owner:group>" made in c.

I've named it checkdir because I couldn't think of any other name, so please feel free to change it to something more appropriate.
Comment 1 Renato Caldas 2007-09-16 12:39:20 UTC
Created attachment 131042 [details, diff]
The patch against baselayout 2

This patch is against baselayout-2.0.0_rc4
Comment 2 SpanKY gentoo-dev 2007-09-16 18:57:22 UTC
i dont see why people cant just run `mkdir` and such, but that's me ...

you should have [-m mode] in there, and considering checkdir *requires* a directory, having the -d in there is unintuitive

your coding style is largely incompatible as well ... we generally use LKML which means you need to cuddle all of your "if" braces
Comment 3 Renato Caldas 2007-09-16 19:56:21 UTC
(In reply to comment #2)
> i dont see why people cant just run `mkdir` and such, but that's me ...

I guess people tend to like "simple one-liners" :)

> you should have [-m mode] in there, and considering checkdir *requires* a
> directory, having the -d in there is unintuitive

I guess I can add/correct those.

> your coding style is largely incompatible as well ... we generally use LKML
> which means you need to cuddle all of your "if" braces

I gess I can also adapt this.

Of course, all of the above changes are subject to the acceptance of the applet.. I'm not going to spend more time on it if it's going to be ditched ;)
Comment 4 SpanKY gentoo-dev 2007-09-16 20:51:28 UTC
i dont really see a problem with the thing ... Roy ?
Comment 5 Roy Marples (RETIRED) gentoo-dev 2007-09-17 08:50:02 UTC
I don't overly object to it. Possibly the concept is over engineered, but heh.

Anyway, if you're going to do a job, do it properly!

start-stop-daemon uses chuid/user, so lets use user instead of owner.
Also, uid's should work just as good.
While we're checking who owns the directory, maybe it would be a good idea to check the permissions too?

checkdir --mode g+rw --user root:0 /foo/bar
checkdir --mode 0755 --user 0 --group wheel /foo/bar

I would expect the above two to work equally well.

Maybe add options for --test and --quiet. I would expect --test to return 0 if nothing needs to be done.
Comment 6 SpanKY gentoo-dev 2007-09-17 09:07:47 UTC
symbolic mode parsing is going to be a pain, so i'd make that the last thing to implement (if we do it at all) ...
Comment 7 Renato Caldas 2007-09-17 10:08:38 UTC
(In reply to comment #6)
> symbolic mode parsing is going to be a pain, so i'd make that the last thing to
> implement (if we do it at all) ...

I guess we can cheat.. :) A simple "system" or equivalent call should do the trick .. Or we can borrow the code from the chmod util..
Comment 8 Renato Caldas 2007-09-17 11:00:20 UTC
(In reply to comment #2)
> (...) and considering checkdir *requires* a
> directory, having the -d in there is unintuitive

I've done this, but there is a caveat: the "directory" argument doesn't show up in the usage message. So there's no way of letting the user know that the directory option is required, or that it even exists.

Unless we change the "usage" function.. I can do that if necessary :)
Comment 9 Roy Marples (RETIRED) gentoo-dev 2007-09-17 12:40:34 UTC
I think what Mike means is that every non option argument is a directory, like so

checkdir --user root:0 /dir1 /dir2 /dir3 /dir4

So you would have this at the end of your option parsing

    while (optind < argc) {
        if (! rc_isdir (argv[optind])) {
            eerror ("%s: `%s' is not a directory", argv[0], argv[optind]);
        } else {
           /* Option is a directory, so check it */
           check_dir (argv[optind]);
        }
        optind++;
    }
Comment 10 SpanKY gentoo-dev 2007-09-17 15:19:15 UTC
correct, that's what i meant
Comment 11 Renato Caldas 2007-09-18 17:29:51 UTC
(In reply to comment #10)
> correct, that's what i meant
> 

Right, but that was not the problem I was talking about. The problem is that the usage message doesn't mention the existence of the "directory" argument(s). That may not be a problem at all, but I'm not sure.
Comment 12 Roy Marples (RETIRED) gentoo-dev 2007-09-18 17:42:43 UTC
none of our other applets presently do either :P
I'll probably address that defect tomorrow, but in the meantime you should address my concerns and we'll address your one later.
Comment 13 Renato Caldas 2007-09-18 19:13:15 UTC
Created attachment 131237 [details, diff]
Checkdir patch v2, some corrections/improvements

Here it is, version 2 of the patch:
* support for multiple directories
* hopefully more LKML-style :)

The mode support is still missing. I have a separate patch that uses system("chmod foo bar") to set the mode, but that's kind of cheating ;)
Comment 14 Renato Caldas 2007-09-18 19:16:00 UTC
Created attachment 131238 [details, diff]
Checkdir patch v2, the correct one

Ops, nevermind the previous one, it had the options messed up. This is the right one.
Comment 15 Roy Marples (RETIRED) gentoo-dev 2007-09-19 16:47:43 UTC
http://sources.gentoo.org/viewcvs.py/baselayout/trunk/src/checkown.c?view=markup

I've added the applet as checkown as it could be used to check files also.

It currently accepts --mode 0522 as well, but it's not parsing g+w type ones. Of course it could be made to if needed.

Thanks!
Comment 16 Renato Caldas 2007-09-19 17:21:57 UTC
Nice :)

[how] can it be ported to baselayout 1? I'd really like to see the init scripts using it for creation of /var/run dirs :)
Comment 17 Roy Marples (RETIRED) gentoo-dev 2007-09-19 21:44:02 UTC
I have no interest in backporting it to baselayout-1.
Comment 18 Renato Caldas 2007-09-19 22:47:55 UTC
(In reply to comment #17)
> I have no interest in backporting it to baselayout-1.
> 

Hum but then it will only be used when baselayout 2 becomes stable and baselayout 1 gets removed from portage. Otherwise it would make no sense to change the init scripts, as they would become incompatible..

And judging from the lack of interest from the "hardened" guys, it may take some time for baselayout v1 to be removed..
Comment 19 Roy Marples (RETIRED) gentoo-dev 2007-09-20 07:23:27 UTC
(In reply to comment #18)
> Hum but then it will only be used when baselayout 2 becomes stable and
> baselayout 1 gets removed from portage. Otherwise it would make no sense to
> change the init scripts, as they would become incompatible..

That is true. There are other new init script features also waiting in the wings, checkown is not unique in this respect.

> And judging from the lack of interest from the "hardened" guys, it may take
> some time for baselayout v1 to be removed..

hardened team has no say in this afaik. It's just the arch teams that matter and the only ones currently not keyworded are the obscure ones vapier maintains.
Comment 20 SpanKY gentoo-dev 2008-01-14 08:41:36 UTC
*** Bug 205183 has been marked as a duplicate of this bug. ***
Comment 21 SpanKY gentoo-dev 2008-01-19 20:37:43 UTC
*** Bug 205183 has been marked as a duplicate of this bug. ***