!563 [sync] PR-562: fix the compilation warning caused by misusing const

From: @openeuler-sync-bot 
Reviewed-by: @jiayi0118 
Signed-off-by: @jiayi0118
This commit is contained in:
openeuler-ci-bot 2024-02-29 13:03:11 +00:00 committed by Gitee
commit 8628ba696c
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 44 additions and 43 deletions

View File

@ -15,24 +15,22 @@ Fixes #26872.
(cherry picked from commit 7002c5c210a7ae3607bd8a424112e9f8789bc5f9)
(cherry picked from commit 89f780969b4436cf766eb9c0d6412362fc85f042)
Conflict:keep variable unit_id and job_type to solve compilation failure
Conflict:keep variable unit_id and job_type to solve compilation failure and keep pairs as (char **)
Reference:https://github.com/systemd/systemd-stable/commit/1ece85e7d4af7517aa9cfe12b21cde1d82fa3167
---
src/core/transaction.c | 18 +++++++++++-------
1 file changed, 11 insertions(+), 7 deletions(-)
src/core/transaction.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/core/transaction.c b/src/core/transaction.c
index ebe5f19..9532531 100644
index ebe5f19..aca3c4e 100644
--- a/src/core/transaction.c
+++ b/src/core/transaction.c
@@ -328,22 +328,26 @@ _pure_ static bool unit_matters_to_anchor(Unit *u, Job *j) {
return false;
@@ -329,21 +329,25 @@ _pure_ static bool unit_matters_to_anchor(Unit *u, Job *j) {
}
-static char* merge_unit_ids(const char* unit_log_field, char **pairs) {
static char* merge_unit_ids(const char* unit_log_field, char **pairs) {
- char **unit_id, **job_type, *ans = NULL;
- size_t size = 0, next;
+static char* merge_unit_ids(const char* unit_log_field, char * const* pairs) {
+ char **unit_id, **job_type = NULL;
+ _cleanup_free_ char *ans = NULL;
+ size_t size = 0;

View File

@ -14,10 +14,10 @@ Subject: [PATCH] process-util: log more information when running
4 files changed, 66 insertions(+)
diff --git a/src/basic/process-util.c b/src/basic/process-util.c
index 5452edd..f137ba0 100644
index 018cbb5..8d56a69 100644
--- a/src/basic/process-util.c
+++ b/src/basic/process-util.c
@@ -42,6 +42,7 @@
@@ -44,6 +44,7 @@
#include "stdio-util.h"
#include "string-table.h"
#include "string-util.h"
@ -25,11 +25,11 @@ index 5452edd..f137ba0 100644
#include "terminal-util.h"
#include "user-util.h"
#include "utf8.h"
@@ -189,6 +190,36 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags
@@ -256,6 +257,36 @@ int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags
return 0;
}
+int print_process_cmdline_with_arg(pid_t pid, int argc, char *argv[], char *filter[]) {
+int print_process_cmdline_with_arg(pid_t pid, int argc, char *argv[], const char * const *filter) {
+ bool is_filtered = false;
+ int r;
+ const char *arg_cmdline = "[";
@ -41,7 +41,7 @@ index 5452edd..f137ba0 100644
+ return r;
+ } else {
+ for (int i = 0; i < argc; i++ ) {
+ if (filter && strv_find(filter, argv[i])) {
+ if (filter && strv_find((char * const *) filter, argv[i])) {
+ is_filtered = true;
+ break;
+ }
@ -63,22 +63,22 @@ index 5452edd..f137ba0 100644
static int can_do = -1;
diff --git a/src/basic/process-util.h b/src/basic/process-util.h
index 41d4759..4d8147e 100644
index 6f9b577..687c7c1 100644
--- a/src/basic/process-util.h
+++ b/src/basic/process-util.h
@@ -38,6 +38,7 @@ typedef enum ProcessCmdlineFlags {
@@ -41,6 +41,7 @@ typedef enum ProcessCmdlineFlags {
int get_process_comm(pid_t pid, char **name);
int get_process_cmdline(pid_t pid, size_t max_columns, ProcessCmdlineFlags flags, char **line);
+int print_process_cmdline_with_arg(pid_t pid, int argc, char *argv[], char *filter[]);
+int print_process_cmdline_with_arg(pid_t pid, int argc, char *argv[], const char * const *filter);
int get_process_exe(pid_t pid, char **name);
int get_process_uid(pid_t pid, uid_t *uid);
int get_process_gid(pid_t pid, gid_t *gid);
diff --git a/src/systemctl/systemctl.c b/src/systemctl/systemctl.c
index 1c01914..dd5bee9 100644
index 2f6f581..a2d5a67 100644
--- a/src/systemctl/systemctl.c
+++ b/src/systemctl/systemctl.c
@@ -12,6 +12,7 @@
@@ -2,6 +2,7 @@
#include <getopt.h>
#include <locale.h>
@ -86,12 +86,12 @@ index 1c01914..dd5bee9 100644
#include <unistd.h>
#include "sd-daemon.h"
@@ -9272,6 +9273,14 @@ static int logind_cancel_shutdown(void) {
@@ -1113,6 +1114,14 @@ static int systemctl_main(int argc, char *argv[]) {
static int run(int argc, char *argv[]) {
int r;
+ pid_t ppid;
+ char *filter[] = {
+ const char * const filter[] = {
+ "status", "show", "cat",
+ "is-active", "is-failed", "is-enabled", "is-system-running",
+ "list-units", "list-sockets", "list-timers", "list-dependencies",
@ -101,7 +101,7 @@ index 1c01914..dd5bee9 100644
setlocale(LC_ALL, "");
log_parse_environment();
@@ -9291,6 +9300,9 @@ static int run(int argc, char *argv[]) {
@@ -1127,6 +1136,9 @@ static int run(int argc, char *argv[]) {
if (r <= 0)
goto finish;
@ -112,38 +112,38 @@ index 1c01914..dd5bee9 100644
if (!arg_quiet)
log_info("Running in chroot, ignoring request.");
diff --git a/src/test/test-process-util.c b/src/test/test-process-util.c
index 8dc9fdd..1cb4ee2 100644
index 8c76392..1dc1eb3 100644
--- a/src/test/test-process-util.c
+++ b/src/test/test-process-util.c
@@ -601,6 +601,27 @@ static void test_ioprio_class_from_to_string(void) {
@@ -874,6 +874,27 @@ static void test_get_process_ppid(void) {
}
}
+static void test_print_process_cmdline_with_arg(pid_t pid) {
+ char *arg_filter_empty[] = {"", NULL};
+ char *arg_filter_1_in[] = {"status", NULL};
+ char *arg_filter_1_no[] = {"stop", NULL};
+ char *arg_filter_2_in[] = {"restart", "status", NULL};
+ char *arg_filter_2_no[] = {"restart", "stop", NULL};
+ char *arg_var_1[1] = {"systemctl"};
+ char *arg_var_10[10] = {"systemctl", "restart", "1", "2", "3", "4", "5", "6", "7", "8"};
+ char *arg_var_filter[3] = {"systemctl", "status", "dbus.service"};
+ const char * const arg_filter_empty[] = {"", NULL};
+ const char * const arg_filter_1_in[] = {"status", NULL};
+ const char * const arg_filter_1_no[] = {"stop", NULL};
+ const char * const arg_filter_2_in[] = {"restart", "status", NULL};
+ const char * const arg_filter_2_no[] = {"restart", "stop", NULL};
+ const char *arg_var_1[1] = {"systemctl"};
+ const char *arg_var_10[10] = {"systemctl", "restart", "1", "2", "3", "4", "5", "6", "7", "8"};
+ const char *arg_var_filter[3] = {"systemctl", "status", "dbus.service"};
+ assert_se(print_process_cmdline_with_arg(pid, 0, NULL, NULL) >=0);
+ assert_se(print_process_cmdline_with_arg(pid, 1, arg_var_1, NULL) >= 0);
+ assert_se(print_process_cmdline_with_arg(pid, 10, arg_var_10, NULL) >= 0);
+ assert_se(print_process_cmdline_with_arg(897349, 1, arg_var_1, NULL) < 0);
+ assert_se(print_process_cmdline_with_arg(897349, 10, arg_var_10, NULL) < 0);
+ assert_se(print_process_cmdline_with_arg(pid, 3, arg_var_filter, arg_filter_empty) >= 0);
+ assert_se(print_process_cmdline_with_arg(pid, 3, arg_var_filter, arg_filter_1_in) >= 0);
+ assert_se(print_process_cmdline_with_arg(pid, 3, arg_var_filter, arg_filter_1_no) >= 0);
+ assert_se(print_process_cmdline_with_arg(pid, 3, arg_var_filter, arg_filter_2_in) >= 0);
+ assert_se(print_process_cmdline_with_arg(pid, 3, arg_var_filter, arg_filter_2_no) >= 0);
+ assert_se(print_process_cmdline_with_arg(pid, 1, (char **) arg_var_1, NULL) >= 0);
+ assert_se(print_process_cmdline_with_arg(pid, 10, (char **) arg_var_10, NULL) >= 0);
+ assert_se(print_process_cmdline_with_arg(897349, 1, (char **) arg_var_1, NULL) < 0);
+ assert_se(print_process_cmdline_with_arg(897349, 10, (char **) arg_var_10, NULL) < 0);
+ assert_se(print_process_cmdline_with_arg(pid, 3, (char **) arg_var_filter, arg_filter_empty) >= 0);
+ assert_se(print_process_cmdline_with_arg(pid, 3, (char **) arg_var_filter, arg_filter_1_in) >= 0);
+ assert_se(print_process_cmdline_with_arg(pid, 3, (char **) arg_var_filter, arg_filter_1_no) >= 0);
+ assert_se(print_process_cmdline_with_arg(pid, 3, (char **) arg_var_filter, arg_filter_2_in) >= 0);
+ assert_se(print_process_cmdline_with_arg(pid, 3, (char **) arg_var_filter, arg_filter_2_no) >= 0);
+}
+
int main(int argc, char *argv[]) {
log_show_color(true);
test_setup_logging(LOG_INFO);
@@ -627,6 +648,7 @@ int main(int argc, char *argv[]) {
@@ -904,6 +925,7 @@ int main(int argc, char *argv[]) {
test_ioprio_class_from_to_string();
test_setpriority_closest();
test_get_process_ppid();
@ -152,5 +152,5 @@ index 8dc9fdd..1cb4ee2 100644
return 0;
}
--
2.23.0
2.33.0

View File

@ -21,7 +21,7 @@
Name: systemd
Url: https://www.freedesktop.org/wiki/Software/systemd
Version: 249
Release: 70
Release: 71
License: MIT and LGPLv2+ and GPLv2+
Summary: System and Service Manager
@ -2135,6 +2135,9 @@ grep -q -E '^KEYMAP="?fi-latin[19]"?' /etc/vconsole.conf 2>/dev/null &&
%{_libdir}/security/pam_systemd.so
%changelog
* Thu Feb 29 2024 licunlong <licunlong1@huawei.com> - 249-71
- fix the compilation warning caused by misusing const
* Wed Feb 28 2024 huyubiao <huyubiao@huawei.com> - 249-70
- Type:bugfix
- CVE:NA