Blob Blame History Raw
diff -up ./NEWS.ori ./NEWS
--- ./NEWS.ori	2022-08-15 11:59:35.929714848 +0200
+++ ./NEWS	2022-08-15 12:00:12.892937479 +0200
@@ -1,4 +1,14 @@
 procps-ng-NEXT
+<<<<<<< HEAD
+=======
+  * library
+    Re-add elogind support                                 merge #151
+  * ps: threads again display when -L is used with -q      issue #234
+  * ps: proper aix format string behavior was restored
+  * sysctl: print dotted keys again
+
+procps-ng-4.0.0
+>>>>>>> b159c198 (sysctl: print dotted keys again)
 ---------------
   * Rename pwait to pidwait
 
diff -up ./sysctl.c.ori ./sysctl.c
--- ./sysctl.c.ori	2022-08-15 11:59:35.934714878 +0200
+++ ./sysctl.c	2022-08-15 12:00:12.893937485 +0200
@@ -152,7 +152,7 @@ static SysctlSetting *setting_new(
         strcat(path + proc_len, key+1);
     else
         strcat(path + proc_len, key);
-    /* change . to / */
+    /* change . to / for path */
     slashdot(path + proc_len, '.', '/');
 
     s = xmalloc(sizeof(SysctlSetting));
@@ -510,7 +510,8 @@ static int WriteSetting(
 
     int rc = EXIT_SUCCESS;
     FILE *fp;
-	struct stat ts;
+    struct stat ts;
+    char *dotted_key;
 
     if (!key || !path)
         return rc;
@@ -523,13 +524,22 @@ static int WriteSetting(
         return rc;
 	}
 
-	if ((ts.st_mode & S_IWUSR) == 0) {
-		xwarn(_("setting key \"%s\""), key);
+    /* Convert the globbed path into a dotted key */
+    if ( (dotted_key = strdup(path + strlen(PROC_PATH))) == NULL) {
+	xerrx(EXIT_FAILURE, _("strdup key"));
+	return EXIT_FAILURE;
+    }
+    slashdot(dotted_key, '/', '.');
+
+    if ((ts.st_mode & S_IWUSR) == 0) {
+        xwarn(_("setting key \"%s\""), dotted_key);
+	free(dotted_key);
         return rc;
 	}
 
-	if (S_ISDIR(ts.st_mode)) {
-		xwarn(_("setting key \"%s\""), key);
+    if (S_ISDIR(ts.st_mode)) {
+        xwarn(_("setting key \"%s\""), dotted_key);
+	free(dotted_key);
         return rc;
 	}
 
@@ -539,7 +549,7 @@ static int WriteSetting(
             case ENOENT:
                 if (!IgnoreError) {
                     xwarnx(_("\"%s\" is an unknown key%s"),
-                           key, (ignore_failure?_(", ignoring"):""));
+                           dotted_key, (ignore_failure?_(", ignoring"):""));
 				if (!ignore_failure)
 				    rc = EXIT_FAILURE;
 			}
@@ -548,11 +558,11 @@ static int WriteSetting(
             case EROFS:
             case EACCES:
                 xwarnx(_("permission denied on key \"%s\"%s"),
-                       key, (ignore_failure?_(", ignoring"):""));
+                       dotted_key, (ignore_failure?_(", ignoring"):""));
                 break;
             default:
                 xwarn(_("setting key \"%s\"%s"),
-                      key, (ignore_failure?_(", ignoring"):""));
+                      dotted_key, (ignore_failure?_(", ignoring"):""));
                 break;
             }
             if (!ignore_failure && errno != ENOENT)
@@ -561,7 +571,7 @@ static int WriteSetting(
 	    if (0 < fprintf(fp, "%s\n", value))
 		rc = EXIT_SUCCESS;
             if (close_stream(fp) != 0) {
-                xwarn(_("setting key \"%s\""), path);
+                xwarn(_("setting key \"%s\""), dotted_key);
                 return rc;
             }
         }
@@ -571,7 +581,7 @@ static int WriteSetting(
             printf("%s\n", value);
         } else {
             if (PrintName) {
-                printf("%s = %s\n", path, value);
+                printf("%s = %s\n", dotted_key, value);
             } else {
                 if (PrintNewline)
                     printf("%s\n", value);
@@ -580,6 +590,7 @@ static int WriteSetting(
             }
         }
     }
+    free(dotted_key);
     return rc;
 }
 
diff -up ./testsuite/sysctl_slash_test.conf.ori ./testsuite/sysctl_slash_test.conf
--- ./testsuite/sysctl_slash_test.conf.ori	2022-08-15 12:00:12.894937491 +0200
+++ ./testsuite/sysctl_slash_test.conf	2022-08-15 12:00:12.893937485 +0200
@@ -0,0 +1 @@
+kernel/hostname = procps-test
diff -up ./testsuite/sysctl.test/sysctl_write.exp.ori ./testsuite/sysctl.test/sysctl_write.exp
--- ./testsuite/sysctl.test/sysctl_write.exp.ori	2022-08-15 11:59:35.934714878 +0200
+++ ./testsuite/sysctl.test/sysctl_write.exp	2022-08-15 12:00:12.893937485 +0200
@@ -3,11 +3,19 @@ set sysctl ${topdir}sysctl
 
 set test "sysctl write from command line"
 spawn $sysctl --dry-run kernel.hostname=procps-test
-expect_pass "$test" "/proc/sys/kernel/hostname = procps-test"
+expect_pass "$test" "kernel.hostname = procps-test"
+
+set test "sysctl write from command line using slash"
+spawn $sysctl --dry-run kernel/hostname=procps-test
+expect_pass "$test" "kernel.hostname = procps-test"
 
 set test "sysctl write from configuration file"
 spawn $sysctl --dry-run -f ${topdir}testsuite/sysctl_glob_test.conf
-expect_pass "$test" "/proc/sys/fs/protected_fifos = 2\\s+/proc/sys/fs/protected_symlinks = 2\\s+/proc/sys/fs/protected_hardlinks = 1"
+expect_pass "$test" "fs.protected_fifos = 2\\s+fs.protected_symlinks = 2\\s+fs.protected_hardlinks = 1"
+
+set test "sysctl write from file with slashes"
+spawn $sysctl --dry-run -f ${topdir}testsuite/sysctl_slash_test.conf
+expect_pass "$test" "kernel.hostname = procps-test"
 
 set hostname_file "/proc/sys/kernel/hostname"
 if {[file exists ${hostname_file}]} {
@@ -25,5 +33,5 @@ if {[file exists ${hostname_file}]} {
     expect_spawn_retval "$test" 0
   }
 } else {
-  unsupported "sysctl write: hostname file doe not exist"
+  unsupported "sysctl write: hostname file does not exist"
 }