linux-hotplug.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kay Sievers <kay.sievers@vrfy.org>
To: linux-hotplug@vger.kernel.org
Subject: Re: udev: remove permissions file from udev
Date: Sun, 19 Dec 2004 19:57:58 +0000	[thread overview]
Message-ID: <1103486278.5746.35.camel@localhost.localdomain> (raw)
In-Reply-To: <1103476209.5746.19.camel@localhost.localdomain>

[-- Attachment #1: Type: text/plain, Size: 536 bytes --]

On Sun, 2004-12-19 at 18:31 +0100, Marco d'Itri wrote:
> On Dec 19, Kay Sievers <kay.sievers@vrfy.org> wrote:

> (Feature request: would it be possible to extend the rules files parser
> to support continuation lines? I'd like it to consider lines starting
> with white space as part of the previous line.)

How about the usual backslash at the end of the line. Here is a simple
patch, that just replaces backslashes/newlines with spaces. So it will
obviously not work if key values continue at the next line. How does
that sound?

Kay

[-- Attachment #2: udev-backslash-01.patch --]
[-- Type: text/x-patch, Size: 6698 bytes --]

diff -Nru a/namedev_parse.c b/namedev_parse.c
--- a/namedev_parse.c	2004-12-19 20:52:01 +01:00
+++ b/namedev_parse.c	2004-12-19 20:52:01 +01:00
@@ -126,14 +126,15 @@
 	cur = 0;
 	lineno = 0;
 	while (cur < bufsize) {
+		int i;
+
 		count = buf_get_line(buf, bufsize, cur);
 		bufline = &buf[cur];
 		cur += count+1;
 		lineno++;
 
 		if (count >= LINE_SIZE) {
-			info("line too long, rule skipped %s, line %d",
-			     filename, lineno);
+			info("line too long, rule skipped %s, line %d", filename, lineno);
 			continue;
 		}
 
@@ -149,8 +150,12 @@
 		if (bufline[0] == COMMENT_CHARACTER)
 			continue;
 
+		/* remove backslash and newline from multi line rules */
 		strncpy(line, bufline, count);
 		line[count] = '\0';
+		for (i = 0 ; i < count; i++)
+			if (line[i] == '\\' || line[i] == '\n')
+				line[i] = ' ';
 		dbg_parse("read '%s'", line);
 
 		/* get all known keys */
diff -Nru a/test/udev-test.pl b/test/udev-test.pl
--- a/test/udev-test.pl	2004-12-19 20:52:01 +01:00
+++ b/test/udev-test.pl	2004-12-19 20:52:01 +01:00
@@ -190,6 +190,36 @@
 EOF
 	},
 	{
+		desc		=> "Handle backslashed multi lines in config file (and replace kernel name)",
+		subsys		=> "tty",
+		devpath		=> "/class/tty/ttyUSB0",
+		exp_name	=> "visor" ,
+		conf		=> <<EOF
+KERNEL="ttyUSB0", \\
+NAME="visor"
+
+EOF
+	},
+	{
+		desc		=> "Handle stupid backslashed multi lines in config file (and replace kernel name)",
+		subsys		=> "tty",
+		devpath		=> "/class/tty/ttyUSB0",
+		exp_name	=> "visor" ,
+		conf		=> <<EOF
+
+#
+\\
+
+\\\\
+
+#\\
+
+KERNEL="ttyUSB0", \\
+NAME="visor"
+
+EOF
+	},
+	{
 		desc		=> "subdirectory handling",
 		subsys		=> "tty",
 		devpath		=> "/class/tty/ttyUSB0",
diff -Nru a/udev.h b/udev.h
--- a/udev.h	2004-12-19 20:52:01 +01:00
+++ b/udev.h	2004-12-19 20:52:01 +01:00
@@ -37,7 +37,7 @@
 #define SUBSYSTEM_SIZE			32
 #define SEQNUM_SIZE			32
 
-#define LINE_SIZE			256
+#define LINE_SIZE			512
 
 #define DEVD_DIR			"/etc/dev.d"
 #define DEVD_SUFFIX			".dev"
@@ -74,7 +74,6 @@
 extern int udev_remove_device(struct udevice *udev);
 extern void udev_init_config(void);
 extern int udev_start(void);
-extern int parse_get_pair(char **orig_string, char **left, char **right);
 extern void udev_multiplex_directory(struct udevice *udev, const char *basedir, const char *suffix);
 
 extern char sysfs_path[SYSFS_PATH_MAX];
diff -Nru a/udev_config.c b/udev_config.c
--- a/udev_config.c	2004-12-19 20:52:01 +01:00
+++ b/udev_config.c	2004-12-19 20:52:01 +01:00
@@ -91,41 +91,6 @@
 		udev_hotplug_d = 0;
 }
 
-int parse_get_pair(char **orig_string, char **left, char **right)
-{
-	char *temp;
-	char *string = *orig_string;
-
-	if (!string)
-		return -ENODEV;
-
-	/* eat any whitespace */
-	while (isspace(*string) || *string == ',')
-		++string;
-
-	/* split based on '=' */
-	temp = strsep(&string, "=");
-	*left = temp;
-	if (!string)
-		return -ENODEV;
-
-	/* take the right side and strip off the '"' */
-	while (isspace(*string))
-		++string;
-	if (*string == '"')
-		++string;
-	else
-		return -ENODEV;
-
-	temp = strsep(&string, "\"");
-	if (!string || *temp == '\0')
-		return -ENODEV;
-	*right = temp;
-	*orig_string = string;
-	
-	return 0;
-}
-
 static int parse_config_file(void)
 {
 	char line[LINE_SIZE];
@@ -254,20 +219,13 @@
 			strfieldcpy(udev_config_filename, temp);
 	}
 
-	dbg("sysfs_path='%s'", sysfs_path);
-	dbg_parse("udev_root = %s", udev_root);
-	dbg_parse("udev_config_filename = %s", udev_config_filename);
-	dbg_parse("udev_db_path = %s", udev_db_path);
-	dbg_parse("udev_rules_filename = %s", udev_rules_filename);
-	dbg_parse("udev_log = %d", udev_log);
-
 	parse_config_file();
-
-	dbg("udev_root = %s", udev_root);
-	dbg("udev_config_filename = %s", udev_config_filename);
-	dbg("udev_db_path = %s", udev_db_path);
-	dbg("udev_rules_filename = %s", udev_rules_filename);
-	dbg("udev_log = %d", udev_log);
+	dbg("sysfs_path='%s'", sysfs_path);
+	dbg("udev_root='%s'", udev_root);
+	dbg("udev_config_filename='%s'", udev_config_filename);
+	dbg("udev_db_path='%s'", udev_db_path);
+	dbg("udev_rules_filename='%s'", udev_rules_filename);
+	dbg("udev_log=%d", udev_log);
 }
 
 void udev_init_config(void)
diff -Nru a/udev_utils.c b/udev_utils.c
--- a/udev_utils.c	2004-12-19 20:52:01 +01:00
+++ b/udev_utils.c	2004-12-19 20:52:01 +01:00
@@ -25,6 +25,7 @@
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
+#include <ctype.h>
 #include <dirent.h>
 #include <sys/stat.h>
 #include <sys/mman.h>
@@ -111,6 +112,41 @@
 	return mkdir(p, 0755);
 }
 
+int parse_get_pair(char **orig_string, char **left, char **right)
+{
+	char *temp;
+	char *string = *orig_string;
+
+	if (!string)
+		return -ENODEV;
+
+	/* eat any whitespace */
+	while (isspace(*string) || *string == ',')
+		++string;
+
+	/* split based on '=' */
+	temp = strsep(&string, "=");
+	*left = temp;
+	if (!string)
+		return -ENODEV;
+
+	/* take the right side and strip off the '"' */
+	while (isspace(*string))
+		++string;
+	if (*string == '"')
+		++string;
+	else
+		return -ENODEV;
+
+	temp = strsep(&string, "\"");
+	if (!string || *temp == '\0')
+		return -ENODEV;
+	*right = temp;
+	*orig_string = string;
+	
+	return 0;
+}
+
 int file_map(const char *filename, char **buf, size_t *bufsize)
 {
 	struct stat stats;
@@ -143,11 +179,21 @@
 	munmap(buf, bufsize);
 }
 
-size_t buf_get_line(char *buf, size_t buflen, size_t cur)
+/* return number of chars until the next newline, skip escaped newline */
+size_t buf_get_line(const char *buf, size_t buflen, size_t cur)
 {
-	size_t count = 0;
+	int escape = 0;
+	size_t count;
 
-	for (count = cur; count < buflen && buf[count] != '\n'; count++);
+	for (count = cur; count < buflen; count++) {
+		if (!escape && buf[count] == '\n')
+			break;
+
+		if (buf[count] == '\\')
+			escape = 1;
+		else
+			escape = 0;
+	}
 
 	return count - cur;
 }
diff -Nru a/udev_utils.h b/udev_utils.h
--- a/udev_utils.h	2004-12-19 20:52:01 +01:00
+++ b/udev_utils.h	2004-12-19 20:52:01 +01:00
@@ -79,9 +79,10 @@
 extern void udev_init_device(struct udevice *udev, const char* devpath, const char *subsystem);
 extern int kernel_release_satisfactory(int version, int patchlevel, int sublevel);
 extern int create_path(const char *path);
+extern int parse_get_pair(char **orig_string, char **left, char **right);
 extern int file_map(const char *filename, char **buf, size_t *bufsize);
 extern void file_unmap(char *buf, size_t bufsize);
-extern size_t buf_get_line(char *buf, size_t buflen, size_t cur);
+extern size_t buf_get_line(const char *buf, size_t buflen, size_t cur);
 extern void no_trailing_slash(char *path);
 typedef int (*file_fnct_t)(const char *filename, void *data);
 extern int  call_foreach_file(file_fnct_t fnct, const char *dirname,

  parent reply	other threads:[~2004-12-19 19:57 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-12-19 17:10 udev: remove permissions file from udev Kay Sievers
2004-12-19 17:31 ` Marco d'Itri
2004-12-19 17:36 ` Willem Riede
2004-12-19 17:49 ` Kay Sievers
2004-12-19 18:12 ` Kay Sievers
2004-12-19 19:57 ` Kay Sievers [this message]
2004-12-20  0:59 ` Marco d'Itri
2004-12-20  1:17 ` Kay Sievers
2004-12-20 13:36 ` Kay Sievers
2004-12-20 14:03 ` Marco d'Itri
2004-12-20 14:54 ` Kay Sievers
2004-12-20 17:13 ` Lindsay Haisley
2004-12-20 20:30 ` Kay Sievers
2004-12-20 20:49 ` Kay Sievers
2004-12-20 20:51 ` Marco d'Itri
2004-12-20 20:55 ` Kay Sievers
2004-12-20 20:58 ` Tobias Klauser
2004-12-20 23:36 ` Lindsay Haisley
2004-12-21  3:04 ` Kay Sievers
2004-12-22  3:41 ` Willem Riede
2004-12-22  6:18 ` Greg KH
2004-12-22 14:25 ` Willem Riede

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1103486278.5746.35.camel@localhost.localdomain \
    --to=kay.sievers@vrfy.org \
    --cc=linux-hotplug@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).