Skip to contentSkip to conversation

nfs-utils: Allow setting of commented out values in nfs.conf

PATCH In review Justin Mitchell 2 participants 2 messages Oct 25, 2018 – Nov 29, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nfs-utils: Allow setting of commented out values in nfs.conf

When using nfsconf tool to set values, allow it to uncomment a setting it finds in the relevant section if it would otherwise have had to create a new one.

---
 support/nfs/conffile.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
support/nfs/conffile.c +22 -0
index 3845b94..713f81b 100644
@@ -1830,6 +1830,8 @@ conf_write(const char *filename, const char *section, const char *arg,
 
 			/* this is the section we care about */
 			if (where != NULL && is_section(where->text, section, arg)) {
+				struct outbuffer *section_start = where;
+
 				/* is there an existing assignment */
 				while ((where = TAILQ_NEXT(where, link)) != NULL) {
 					if (is_tag(where->text, tag)) {
@@ -1838,6 +1840,26 @@ conf_write(const char *filename, const char *section, const char *arg,
 					}
 				}
 
+				/* no active assignment, but is there a commented one */
+				if (!found) {
+					where = section_start;
+					while ((where = TAILQ_NEXT(where, link)) != NULL) {
+						if (is_comment(where->text)) {
+							char *cline = where->text;
+							while (isspace(*cline)) cline++;
+
+							if (*cline != '#') continue;
+							cline++;
+
+							if (is_tag(cline, tag)) {
+								found = true;
+								break;
+							}
+						}
+					}
+				}
+
+				/* replace the located tag with an updated one */
 				if (found) {
 					struct outbuffer *prev = TAILQ_PREV(where, tailhead, link);
 					bool again = false;
Signature · 1 line
1.8.3.1
#1 lore raw
Quoted 5 lines · Justin Mitchell

When using nfsconf tool to set values, allow it to uncomment a setting it finds in the relevant section if it would otherwise have had to create a new one.

Committed... Sorry it too so long....

steved.

Quoted 45 lines
---
 support/nfs/conffile.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
support/nfs/conffile.c +22 -0
index 3845b94..713f81b 100644
@@ -1830,6 +1830,8 @@ conf_write(const char *filename, const char *section, const char *arg,
 
 			/* this is the section we care about */
 			if (where != NULL && is_section(where->text, section, arg)) {
+				struct outbuffer *section_start = where;
+
 				/* is there an existing assignment */
 				while ((where = TAILQ_NEXT(where, link)) != NULL) {
 					if (is_tag(where->text, tag)) {
@@ -1838,6 +1840,26 @@ conf_write(const char *filename, const char *section, const char *arg,
 					}
 				}
 
+				/* no active assignment, but is there a commented one */
+				if (!found) {
+					where = section_start;
+					while ((where = TAILQ_NEXT(where, link)) != NULL) {
+						if (is_comment(where->text)) {
+							char *cline = where->text;
+							while (isspace(*cline)) cline++;
+
+							if (*cline != '#') continue;
+							cline++;
+
+							if (is_tag(cline, tag)) {
+								found = true;
+								break;
+							}
+						}
+					}
+				}
+
+				/* replace the located tag with an updated one */
 				if (found) {
 					struct outbuffer *prev = TAILQ_PREV(where, tailhead, link);
 					bool again = false;