* [PATCH] static-nodes: add shell consumable format
@ 2013-09-19 14:48 Dave Reisner
2013-09-19 15:44 ` Lucas De Marchi
2013-09-19 15:48 ` Tom Gundersen
0 siblings, 2 replies; 5+ messages in thread
From: Dave Reisner @ 2013-09-19 14:48 UTC (permalink / raw)
To: linux-modules; +Cc: Dave Reisner
This adds an additional format to kmod static-nodes, which writes
output as shell commands, e.g.:
mknod '/dev/btrfs-control' c 10 234
mknod '/dev/loop-control' c 10 237
mkdir -m 755 -p '/dev/net'
mknod '/dev/net/tun' c 10 200
Consumers of this format can simply pipe the output to a shell,
creating the necessary static nodes. This could be useful for an
initramfs which doesn't have systemd-tmpfiles but which still relies on
static node creation which recent udev will no longer handle.
---
tools/static-nodes.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/tools/static-nodes.c b/tools/static-nodes.c
index 0195390..2d68537 100644
--- a/tools/static-nodes.c
+++ b/tools/static-nodes.c
@@ -43,11 +43,13 @@ struct static_nodes_format {
static const struct static_nodes_format static_nodes_format_human;
static const struct static_nodes_format static_nodes_format_tmpfiles;
static const struct static_nodes_format static_nodes_format_devname;
+static const struct static_nodes_format static_nodes_format_shell;
static const struct static_nodes_format *static_nodes_formats[] = {
&static_nodes_format_human,
&static_nodes_format_tmpfiles,
&static_nodes_format_devname,
+ &static_nodes_format_shell,
};
static const char cmdopts_s[] = "o:f:h";
@@ -126,6 +128,28 @@ static const struct static_nodes_format static_nodes_format_devname = {
.description = "the modules.devname format.",
};
+static int write_shell(FILE *out, char modname[], char devname[], char type, unsigned int maj, unsigned int min)
+{
+ const char *dir = strrchr(devname, '/');
+
+ if (dir) {
+ if (fprintf(out, "mkdir -m 755 -p '/dev/%.*s'\n",
+ (int)(dir - devname), devname) < 0)
+ return EXIT_FAILURE;
+ }
+
+ if (fprintf(out, "mknod '/dev/%s' %c %u %u\n", devname, type, maj, min) < 0)
+ return EXIT_FAILURE;
+
+ return EXIT_SUCCESS;
+}
+
+static const struct static_nodes_format static_nodes_format_shell = {
+ .name = "shell",
+ .write = write_shell,
+ .description = "mknod commands for consumption by a shell.",
+};
+
static void help(void)
{
size_t i;
--
1.8.4
^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [PATCH] static-nodes: add shell consumable format
2013-09-19 14:48 [PATCH] static-nodes: add shell consumable format Dave Reisner
@ 2013-09-19 15:44 ` Lucas De Marchi
2013-09-19 15:53 ` Tom Gundersen
2013-09-19 15:48 ` Tom Gundersen
1 sibling, 1 reply; 5+ messages in thread
From: Lucas De Marchi @ 2013-09-19 15:44 UTC (permalink / raw)
To: Dave Reisner; +Cc: linux-modules, Harald Hoyer
On Thu, Sep 19, 2013 at 9:48 AM, Dave Reisner <dreisner@archlinux.org> wrote:
> This adds an additional format to kmod static-nodes, which writes
> output as shell commands, e.g.:
>
> mknod '/dev/btrfs-control' c 10 234
> mknod '/dev/loop-control' c 10 237
> mkdir -m 755 -p '/dev/net'
> mknod '/dev/net/tun' c 10 200
>
> Consumers of this format can simply pipe the output to a shell,
> creating the necessary static nodes. This could be useful for an
> initramfs which doesn't have systemd-tmpfiles but which still relies on
> static node creation which recent udev will no longer handle.
I got a similar request from Harald (CC'ed), but instead to create the
nodes ourselves.
The way you did fits better with the current purpose of the
static-nodes, but I'm ok with creating the nodes ourselves, too.
Harald, would this work for you as well?
Lucas De Marchi
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] static-nodes: add shell consumable format
2013-09-19 14:48 [PATCH] static-nodes: add shell consumable format Dave Reisner
2013-09-19 15:44 ` Lucas De Marchi
@ 2013-09-19 15:48 ` Tom Gundersen
2013-09-19 15:56 ` Dave Reisner
1 sibling, 1 reply; 5+ messages in thread
From: Tom Gundersen @ 2013-09-19 15:48 UTC (permalink / raw)
To: Dave Reisner; +Cc: linux-modules@vger.kernel.org
On Thu, Sep 19, 2013 at 4:48 PM, Dave Reisner <dreisner@archlinux.org> wrote:
> This adds an additional format to kmod static-nodes, which writes
> output as shell commands, e.g.:
>
> mknod '/dev/btrfs-control' c 10 234
> mknod '/dev/loop-control' c 10 237
> mkdir -m 755 -p '/dev/net'
> mknod '/dev/net/tun' c 10 200
>
> Consumers of this format can simply pipe the output to a shell,
> creating the necessary static nodes. This could be useful for an
> initramfs which doesn't have systemd-tmpfiles but which still relies on
> static node creation which recent udev will no longer handle.
Seems reasonable enough, so if it is useful no objections from me.
However, two questions: why not simply ship systemd-tmpfiles in the
initramfs to do this (which would also do things like selinux labels
for those who care about that). Alternatively, why not just parse one
of the existing formats in your shell script?
-t
> tools/static-nodes.c | 24 ++++++++++++++++++++++++
> 1 file changed, 24 insertions(+)
>
> diff --git a/tools/static-nodes.c b/tools/static-nodes.c
> index 0195390..2d68537 100644
> --- a/tools/static-nodes.c
> +++ b/tools/static-nodes.c
> @@ -43,11 +43,13 @@ struct static_nodes_format {
> static const struct static_nodes_format static_nodes_format_human;
> static const struct static_nodes_format static_nodes_format_tmpfiles;
> static const struct static_nodes_format static_nodes_format_devname;
> +static const struct static_nodes_format static_nodes_format_shell;
>
> static const struct static_nodes_format *static_nodes_formats[] = {
> &static_nodes_format_human,
> &static_nodes_format_tmpfiles,
> &static_nodes_format_devname,
> + &static_nodes_format_shell,
> };
>
> static const char cmdopts_s[] = "o:f:h";
> @@ -126,6 +128,28 @@ static const struct static_nodes_format static_nodes_format_devname = {
> .description = "the modules.devname format.",
> };
>
> +static int write_shell(FILE *out, char modname[], char devname[], char type, unsigned int maj, unsigned int min)
> +{
> + const char *dir = strrchr(devname, '/');
> +
> + if (dir) {
> + if (fprintf(out, "mkdir -m 755 -p '/dev/%.*s'\n",
> + (int)(dir - devname), devname) < 0)
> + return EXIT_FAILURE;
> + }
> +
> + if (fprintf(out, "mknod '/dev/%s' %c %u %u\n", devname, type, maj, min) < 0)
> + return EXIT_FAILURE;
> +
> + return EXIT_SUCCESS;
> +}
> +
> +static const struct static_nodes_format static_nodes_format_shell = {
> + .name = "shell",
> + .write = write_shell,
> + .description = "mknod commands for consumption by a shell.",
> +};
> +
> static void help(void)
> {
> size_t i;
> --
> 1.8.4
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-modules" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] static-nodes: add shell consumable format
2013-09-19 15:44 ` Lucas De Marchi
@ 2013-09-19 15:53 ` Tom Gundersen
0 siblings, 0 replies; 5+ messages in thread
From: Tom Gundersen @ 2013-09-19 15:53 UTC (permalink / raw)
To: Lucas De Marchi; +Cc: Dave Reisner, linux-modules, Harald Hoyer
On Thu, Sep 19, 2013 at 5:44 PM, Lucas De Marchi
<lucas.de.marchi@gmail.com> wrote:
> On Thu, Sep 19, 2013 at 9:48 AM, Dave Reisner <dreisner@archlinux.org> wrote:
>> This adds an additional format to kmod static-nodes, which writes
>> output as shell commands, e.g.:
>>
>> mknod '/dev/btrfs-control' c 10 234
>> mknod '/dev/loop-control' c 10 237
>> mkdir -m 755 -p '/dev/net'
>> mknod '/dev/net/tun' c 10 200
>>
>> Consumers of this format can simply pipe the output to a shell,
>> creating the necessary static nodes. This could be useful for an
>> initramfs which doesn't have systemd-tmpfiles but which still relies on
>> static node creation which recent udev will no longer handle.
>
> I got a similar request from Harald (CC'ed), but instead to create the
> nodes ourselves.
>
> The way you did fits better with the current purpose of the
> static-nodes, but I'm ok with creating the nodes ourselves, too.
For what it is worth, the reason I didn't originally create the nodes
in kmod was that I didn't want to redo mkdir_label_parents() and
label_context_set() in kmod. If you don't use SELinux I guess this
doesn't matter though.
Harald: why not put systemd-tmpfiles in dracut?
Cheers,
Tom
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] static-nodes: add shell consumable format
2013-09-19 15:48 ` Tom Gundersen
@ 2013-09-19 15:56 ` Dave Reisner
0 siblings, 0 replies; 5+ messages in thread
From: Dave Reisner @ 2013-09-19 15:56 UTC (permalink / raw)
To: Tom Gundersen; +Cc: Dave Reisner, linux-modules@vger.kernel.org
On Thu, Sep 19, 2013 at 05:48:58PM +0200, Tom Gundersen wrote:
> On Thu, Sep 19, 2013 at 4:48 PM, Dave Reisner <dreisner@archlinux.org> wrote:
> > This adds an additional format to kmod static-nodes, which writes
> > output as shell commands, e.g.:
> >
> > mknod '/dev/btrfs-control' c 10 234
> > mknod '/dev/loop-control' c 10 237
> > mkdir -m 755 -p '/dev/net'
> > mknod '/dev/net/tun' c 10 200
> >
> > Consumers of this format can simply pipe the output to a shell,
> > creating the necessary static nodes. This could be useful for an
> > initramfs which doesn't have systemd-tmpfiles but which still relies on
> > static node creation which recent udev will no longer handle.
>
> Seems reasonable enough, so if it is useful no objections from me.
>
> However, two questions: why not simply ship systemd-tmpfiles in the
> initramfs to do this (which would also do things like selinux labels
> for those who care about that). Alternatively, why not just parse one
> of the existing formats in your shell script?
I started writing the code to parse the raw devname format in shell, and
decided it would be easier to borrow the already existing parser in the
static nodes tool. Other people might get use out of it too if they
don't want to deal with systemd-tmpfiles.
> -t
>
> > tools/static-nodes.c | 24 ++++++++++++++++++++++++
> > 1 file changed, 24 insertions(+)
> >
> > diff --git a/tools/static-nodes.c b/tools/static-nodes.c
> > index 0195390..2d68537 100644
> > --- a/tools/static-nodes.c
> > +++ b/tools/static-nodes.c
> > @@ -43,11 +43,13 @@ struct static_nodes_format {
> > static const struct static_nodes_format static_nodes_format_human;
> > static const struct static_nodes_format static_nodes_format_tmpfiles;
> > static const struct static_nodes_format static_nodes_format_devname;
> > +static const struct static_nodes_format static_nodes_format_shell;
> >
> > static const struct static_nodes_format *static_nodes_formats[] = {
> > &static_nodes_format_human,
> > &static_nodes_format_tmpfiles,
> > &static_nodes_format_devname,
> > + &static_nodes_format_shell,
> > };
> >
> > static const char cmdopts_s[] = "o:f:h";
> > @@ -126,6 +128,28 @@ static const struct static_nodes_format static_nodes_format_devname = {
> > .description = "the modules.devname format.",
> > };
> >
> > +static int write_shell(FILE *out, char modname[], char devname[], char type, unsigned int maj, unsigned int min)
> > +{
> > + const char *dir = strrchr(devname, '/');
> > +
> > + if (dir) {
> > + if (fprintf(out, "mkdir -m 755 -p '/dev/%.*s'\n",
> > + (int)(dir - devname), devname) < 0)
> > + return EXIT_FAILURE;
> > + }
> > +
> > + if (fprintf(out, "mknod '/dev/%s' %c %u %u\n", devname, type, maj, min) < 0)
> > + return EXIT_FAILURE;
> > +
> > + return EXIT_SUCCESS;
> > +}
> > +
> > +static const struct static_nodes_format static_nodes_format_shell = {
> > + .name = "shell",
> > + .write = write_shell,
> > + .description = "mknod commands for consumption by a shell.",
> > +};
> > +
> > static void help(void)
> > {
> > size_t i;
> > --
> > 1.8.4
> >
> > --
> > To unsubscribe from this list: send the line "unsubscribe linux-modules" in
> > the body of a message to majordomo@vger.kernel.org
> > More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2013-09-19 15:56 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-09-19 14:48 [PATCH] static-nodes: add shell consumable format Dave Reisner
2013-09-19 15:44 ` Lucas De Marchi
2013-09-19 15:53 ` Tom Gundersen
2013-09-19 15:48 ` Tom Gundersen
2013-09-19 15:56 ` Dave Reisner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).