Compare commits

...

11 Commits

Author SHA1 Message Date
openeuler-ci-bot
0aebecc0ac
!34 回合chkconfig上游社区补丁解耦对cgroup的依赖
From: @dongyuzhen 
Reviewed-by: @xujing99 
Signed-off-by: @xujing99
2024-08-22 06:14:18 +00:00
dongyuzhen
f2df7684f8 fix systemdActive() 2024-08-22 11:38:22 +08:00
openeuler-ci-bot
5a98753610
!20 enable make check
From: @xujing99 
Reviewed-by: @licunlong 
Signed-off-by: @licunlong
2023-02-13 11:26:51 +00:00
xujing
2e7c3e9dbc enable make check 2023-02-13 19:11:13 +08:00
openeuler-ci-bot
36d30def25
!15 【openEuler-20.03-LTS-SP3】Fix coredump while parseServiceInfo return non-zero
From: @yixiangzhike 
Reviewed-by: @xujing99 
Signed-off-by: @xujing99
2022-08-27 02:46:26 +00:00
yixiangzhike
098e22e644 Fix coredump while parseServiceInfo return non-zero
Signed-off-by: yixiangzhike <yixiangzhike007@163.com>
2022-08-27 10:20:24 +08:00
openeuler-ci-bot
9a5461a085 !5 【软件包升级】update version to 1.14
Merge pull request !5 from BenjaminHw/master
2020-08-22 09:57:43 +08:00
openeuler-ci-bot
653b411ff9 !3 update chkconfig to 1.14
Merge pull request !3 from wangchen/wangchen
2020-07-31 15:44:22 +08:00
wangchen2020
a1e80d2fcd update chkconfig to 1.14 2020-07-31 11:11:09 +08:00
openeuler-ci-bot
0a7e4dcce7 !2 add yaml file
Merge pull request !2 from wangchen/wangchen
2020-06-22 09:30:03 +08:00
wangchen2020
b4a754bd10 add yaml file 2020-06-17 15:24:00 +08:00
12 changed files with 92 additions and 696 deletions

View File

@ -1,28 +0,0 @@
From 078a271ef3dbfcb99b78a433166b4ee6e560b2ff Mon Sep 17 00:00:00 2001
From: Jan Macku <jamacku@redhat.com>
Date: Fri, 8 Mar 2019 16:43:58 +0100
Subject: [PATCH] Remove mistakenly added text
---
alternatives.8 | 8 --------
1 file changed, 8 deletions(-)
diff --git a/alternatives.8 b/alternatives.8
index a512873..b2f938e 100644
--- a/alternatives.8
+++ b/alternatives.8
@@ -448,11 +448,3 @@ version 2 or later for copying conditions. There is NO WARRANTY.
.SH "SEE ALSO"
.BR ln (1),
FHS, the Filesystem Hierarchy Standard.
-alternatives.c
-chkconfig.c
-COPYING
-leveldb.c
-leveldb.h
-Makefile
-ntsysv.c
-ook
--
2.21.0.windows.1

View File

@ -1,78 +0,0 @@
From 049c69f5c73ec399311548774a055b3bac6968f9 Mon Sep 17 00:00:00 2001
From: luochunsheng <luochunsheng@huawei.com>
Date: Tue, 9 Apr 2019 20:38:13 +0800
Subject: [PATCH] added check if correct symlink exists
---
alternatives.c | 39 +++++++++++++++++++++++++--------------
1 file changed, 25 insertions(+), 14 deletions(-)
diff --git a/alternatives.c b/alternatives.c
index cdfec6d..b02cce2 100644
--- a/alternatives.c
+++ b/alternatives.c
@@ -456,6 +456,7 @@ static int removeLinks(struct linkSet * l, const char * altDir, int flags) {
static int makeLinks(struct linkSet * l, const char * altDir, int flags) {
char * sl;
+ char buf[PATH_MAX];
sl = alloca(strlen(altDir) + strlen(l->title) + 2);
sprintf(sl, "%s/%s", altDir, l->title);
@@ -463,12 +464,17 @@ static int makeLinks(struct linkSet * l, const char * altDir, int flags) {
if (FL_TEST(flags)) {
printf(_("would link %s -> %s\n"), l->facility, sl);
} else {
- unlink(l->facility);
+ memset(buf, 0, sizeof(buf));
+ readlink(l->facility, buf, sizeof(buf));
- if (symlink(sl, l->facility)) {
- fprintf(stderr, _("failed to link %s -> %s: %s\n"),
- l->facility, sl, strerror(errno));
- return 1;
+ if(strcmp(sl, buf) != 0) {
+ unlink(l->facility);
+
+ if (symlink(sl, l->facility)) {
+ fprintf(stderr, _("failed to link %s -> %s: %s\n"), l->facility,
+ sl, strerror(errno));
+ return 1;
+ }
}
}
} else
@@ -478,16 +484,21 @@ static int makeLinks(struct linkSet * l, const char * altDir, int flags) {
if (FL_TEST(flags)) {
printf(_("would link %s -> %s\n"), sl, l->target);
} else {
- if (unlink(sl) && errno != ENOENT){
- fprintf(stderr, _("failed to remove link %s: %s\n"),
- sl, strerror(errno));
- return 1;
- }
+ memset(buf, 0, sizeof(buf));
+ readlink(sl, buf, sizeof(buf));
+
+ if(strcmp(l->target, buf) != 0) {
+ if (unlink(sl) && errno != ENOENT) {
+ fprintf(stderr, _("failed to remove link %s: %s\n"), sl,
+ strerror(errno));
+ return 1;
+ }
- if (symlink(l->target, sl)) {
- fprintf(stderr, _("failed to link %s -> %s: %s\n"),
- sl, l->target, strerror(errno));
- return 1;
+ if (symlink(l->target, sl)) {
+ fprintf(stderr, _("failed to link %s -> %s: %s\n"), sl, l->target,
+ strerror(errno));
+ return 1;
+ }
}
}
--
1.8.3.1

View File

@ -0,0 +1,44 @@
From 5b5268cc2d7fec04365996026f64992db6c45aa9 Mon Sep 17 00:00:00 2001
From: Marcos Mello <marcosfrm@gmail.com>
Date: Sun, 15 Oct 2023 14:35:06 -0300
Subject: [PATCH] leveldb: fix systemdActive()
/sys/fs/cgroup/systemd is long gone:
https://systemd.io/CGROUP_DELEGATION/
Check for /run/systemd/system/ directory existence instead:
https://www.freedesktop.org/software/systemd/man/sd_booted.html
Closes fedora-sysv/chkconfig#116
Reference:https://github.com/fedora-sysv/chkconfig/commit/5b5268cc2d7fec04365996026f64992db6c45aa9
Conflict:NA
---
leveldb.c | 8 +-------
1 file changed, 1 insertion(+), 7 deletions(-)
diff --git a/leveldb.c b/leveldb.c
index 7b8c1bd..564a207 100644
--- a/leveldb.c
+++ b/leveldb.c
@@ -946,13 +946,7 @@ int systemdIsInit() {
}
int systemdActive() {
- struct stat a, b;
-
- if (lstat("/sys/fs/cgroup", &a) < 0)
- return 0;
- if (lstat("/sys/fs/cgroup/systemd", &b) < 0)
- return 0;
- if (a.st_dev == b.st_dev)
+ if (access("/run/systemd/system/", F_OK) < 0)
return 0;
if (!systemdIsInit())
return 0;
--
2.33.0

View File

@ -1,48 +0,0 @@
From ea46d5c41457be0987c8d16bcefec9ad196b06c8 Mon Sep 17 00:00:00 2001
From: kangenbo <kangenbo@huawei.com>
Date: Sat, 26 Jan 2019 08:56:48 -0500
Subject: [PATCH] bugfix: huawei-bugfix-alternatives-prettier-list-output
---
alternatives.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/alternatives.c b/alternatives.c
index c1a68db..2f60011 100644
--- a/alternatives.c
+++ b/alternatives.c
@@ -946,20 +946,27 @@ static int removeAll(const char * title, const char * altDir, const char * state
static int listServices(const char * altDir, const char * stateDir, int flags) {
DIR *dir;
struct dirent *ent;
- dir = opendir(stateDir);
struct alternativeSet set;
+ int max_name = 0;
+ int l;
+ dir = opendir(stateDir);
if(dir == NULL)
return 2;
while((ent = readdir(dir)) != NULL) {
if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
continue;
-
+ l = strlen(ent->d_name);
+ max_name = max_name > l ? max_name : l;
+ }
+ rewinddir(dir);
+ while((ent = readdir(dir)) != NULL) {
+ if(!strcmp(ent->d_name, ".") || !strcmp(ent->d_name, ".."))
+ continue;
if (readConfig(&set, ent->d_name, altDir, stateDir, flags))
return 2;
-
- printf("%s\t%s\t%s\n", ent->d_name, set.mode == AUTO?"auto":"manual", set.currentLink);
+ printf("%-*s\t%s\t%s\n", max_name, ent->d_name, set.mode == AUTO?"auto ":"manual", set.currentLink);
}
closedir(dir);
--
1.8.3.1

View File

@ -1,402 +0,0 @@
From ea44baee1c8f424cb49aea59ccc58db0a0147be3 Mon Sep 17 00:00:00 2001
From: kangenbo <kangenbo@huawei.com>
Date: Sat, 26 Jan 2019 09:00:48 -0500
Subject: [PATCH] bugfix: huawei-bugfix-leveldb-don-t-crash-on-long-names
---
leveldb.c | 13 +++++--
po/chkconfig.pot | 117 +++++++++++++++++++++++++++++--------------------------
2 files changed, 70 insertions(+), 60 deletions(-)
diff --git a/leveldb.c b/leveldb.c
index 52d5970..b8cf21c 100644
--- a/leveldb.c
+++ b/leveldb.c
@@ -705,23 +705,28 @@ int currentRunlevel(void) {
}
int findServiceEntries(char * name, int level, glob_t * globresptr) {
- char match[200];
+ char *match;
glob_t globres;
int rc;
- sprintf(match, "%s/rc%d.d/[SK][0-9][0-9]%s", RUNLEVELS, level, name);
-
+ rc = asprintf(&match, "%s/rc%d.d/[SK][0-9][0-9]%s", RUNLEVELS, level, name);
+ if (rc < 0) {
+ fprintf(stderr, _("failed to glob pattern %s: %s\n"), match,strerror(errno));
+ return 1;
+ }
rc = glob(match, GLOB_ERR | GLOB_NOSORT, NULL, &globres);
if (rc && rc != GLOB_NOMATCH) {
fprintf(stderr, _("failed to glob pattern %s: %s\n"), match,
strerror(errno));
+ free(match);
return 1;
} else if (rc == GLOB_NOMATCH) {
globresptr->gl_pathc = 0;
+ free(match);
return 0;
}
-
+ free(match);
*globresptr = globres;
return 0;
}
diff --git a/po/chkconfig.pot b/po/chkconfig.pot
index 813d10e..88c8c0c 100644
--- a/po/chkconfig.pot
+++ b/po/chkconfig.pot
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2016-06-29 14:31+0200\n"
+"POT-Creation-Date: 2017-06-09 14:53+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -207,22 +207,22 @@ msgstr ""
msgid "failed to open %s/init.d: %s\n"
msgstr ""
-#: ../leveldb.c:717
+#: ../leveldb.c:715 ../leveldb.c:723
#, c-format
msgid "failed to glob pattern %s: %s\n"
msgstr ""
-#: ../leveldb.c:760
+#: ../leveldb.c:768
#, c-format
msgid "cannot determine current run level\n"
msgstr ""
-#: ../leveldb.c:840
+#: ../leveldb.c:848
#, c-format
msgid "Unable to set selinux context for %s: %s\n"
msgstr ""
-#: ../leveldb.c:864
+#: ../leveldb.c:872
#, c-format
msgid "failed to make symlink %s: %s\n"
msgstr ""
@@ -291,255 +291,260 @@ msgstr ""
#: ../alternatives.c:80
#, c-format
-msgid "\n"
+msgid " alternatives --remove-all <name>\n"
msgstr ""
#: ../alternatives.c:81
#, c-format
+msgid "\n"
+msgstr ""
+
+#: ../alternatives.c:82
+#, c-format
msgid ""
"common options: --verbose --test --help --usage --version --keep-missing\n"
msgstr ""
-#: ../alternatives.c:82
+#: ../alternatives.c:83
#, c-format
msgid " --altdir <directory> --admindir <directory>\n"
msgstr ""
-#: ../alternatives.c:214
+#: ../alternatives.c:215
#, c-format
msgid "reading %s\n"
msgstr ""
-#: ../alternatives.c:218
+#: ../alternatives.c:219
#, c-format
msgid "failed to open %s: %s\n"
msgstr ""
-#: ../alternatives.c:227
+#: ../alternatives.c:228
#, c-format
msgid "failed to read %s: %s\n"
msgstr ""
-#: ../alternatives.c:236
+#: ../alternatives.c:237
#, c-format
msgid "%s empty!\n"
msgstr ""
-#: ../alternatives.c:245
+#: ../alternatives.c:246
#, c-format
msgid "bad mode on line 1 of %s\n"
msgstr ""
-#: ../alternatives.c:252
+#: ../alternatives.c:253
#, c-format
msgid "bad primary link in %s\n"
msgstr ""
-#: ../alternatives.c:264
+#: ../alternatives.c:265
#, c-format
msgid "path %s unexpected in %s\n"
msgstr ""
-#: ../alternatives.c:273
+#: ../alternatives.c:274
#, c-format
msgid "missing path for slave %s in %s\n"
msgstr ""
-#: ../alternatives.c:283
+#: ../alternatives.c:284
#, c-format
msgid "unexpected end of file in %s\n"
msgstr ""
-#: ../alternatives.c:292
+#: ../alternatives.c:293
#, c-format
msgid "path to alternate expected in %s\n"
msgstr ""
-#: ../alternatives.c:293 ../alternatives.c:318 ../alternatives.c:330
-#: ../alternatives.c:347 ../alternatives.c:366
+#: ../alternatives.c:294 ../alternatives.c:319 ../alternatives.c:331
+#: ../alternatives.c:348 ../alternatives.c:367
#, c-format
msgid "unexpected line in %s: %s\n"
msgstr ""
-#: ../alternatives.c:317
+#: ../alternatives.c:318
#, c-format
msgid "closing '@' missing or the family is empty in %s\n"
msgstr ""
-#: ../alternatives.c:329
+#: ../alternatives.c:330
#, c-format
msgid "numeric priority expected in %s\n"
msgstr ""
-#: ../alternatives.c:346
+#: ../alternatives.c:347
#, c-format
msgid "slave path expected in %s\n"
msgstr ""
-#: ../alternatives.c:374
+#: ../alternatives.c:375
#, c-format
msgid "failed to read link %s: %s\n"
msgstr ""
-#: ../alternatives.c:388
+#: ../alternatives.c:389
#, c-format
msgid "link points to no alternative -- setting mode to manual\n"
msgstr ""
-#: ../alternatives.c:393
+#: ../alternatives.c:394
#, c-format
msgid "link changed -- setting mode to manual\n"
msgstr ""
-#: ../alternatives.c:424 ../alternatives.c:431
+#: ../alternatives.c:425 ../alternatives.c:432
#, c-format
msgid "would remove %s\n"
msgstr ""
-#: ../alternatives.c:426 ../alternatives.c:433 ../alternatives.c:466
+#: ../alternatives.c:427 ../alternatives.c:434 ../alternatives.c:467
#, c-format
msgid "failed to remove link %s: %s\n"
msgstr ""
-#: ../alternatives.c:448 ../alternatives.c:463
+#: ../alternatives.c:449 ../alternatives.c:464
#, c-format
msgid "would link %s -> %s\n"
msgstr ""
-#: ../alternatives.c:453 ../alternatives.c:472
+#: ../alternatives.c:454 ../alternatives.c:473
#, c-format
msgid "failed to link %s -> %s: %s\n"
msgstr ""
-#: ../alternatives.c:459
+#: ../alternatives.c:460
#, c-format
msgid "failed to link %s -> %s: %s exists and it is not a symlink\n"
msgstr ""
-#: ../alternatives.c:504
+#: ../alternatives.c:505
#, c-format
msgid "%s already exists\n"
msgstr ""
-#: ../alternatives.c:506
+#: ../alternatives.c:507
#, c-format
msgid "failed to create %s: %s\n"
msgstr ""
-#: ../alternatives.c:539
+#: ../alternatives.c:540
#, c-format
msgid "failed to replace %s with %s: %s\n"
msgstr ""
-#: ../alternatives.c:565 ../alternatives.c:571 ../alternatives.c:582
-#: ../alternatives.c:588
+#: ../alternatives.c:566 ../alternatives.c:572 ../alternatives.c:583
+#: ../alternatives.c:589
#, c-format
msgid "running %s\n"
msgstr ""
-#: ../alternatives.c:618
+#: ../alternatives.c:619
#, c-format
msgid "the primary link for %s must be %s\n"
msgstr ""
-#: ../alternatives.c:699
+#: ../alternatives.c:700
#, c-format
msgid "link %s incorrect for slave %s (%s %s)\n"
msgstr ""
-#: ../alternatives.c:740
+#: ../alternatives.c:741
#, c-format
msgid "%s - status is auto.\n"
msgstr ""
-#: ../alternatives.c:742
+#: ../alternatives.c:743
#, c-format
msgid "%s - status is manual.\n"
msgstr ""
-#: ../alternatives.c:744
+#: ../alternatives.c:745
#, c-format
msgid " link currently points to %s\n"
msgstr ""
-#: ../alternatives.c:749
+#: ../alternatives.c:750
#, c-format
msgid "family %s "
msgstr ""
-#: ../alternatives.c:750
+#: ../alternatives.c:751
#, c-format
msgid "priority %d\n"
msgstr ""
-#: ../alternatives.c:752
+#: ../alternatives.c:753
#, c-format
msgid " slave %s: %s\n"
msgstr ""
-#: ../alternatives.c:757
+#: ../alternatives.c:758
#, c-format
msgid "Current `best' version is %s.\n"
msgstr ""
-#: ../alternatives.c:788
+#: ../alternatives.c:789
#, c-format
msgid "There is %d program that provides '%s'.\n"
msgstr ""
-#: ../alternatives.c:788
+#: ../alternatives.c:789
#, c-format
msgid "There are %d programs which provide '%s'.\n"
msgstr ""
-#: ../alternatives.c:790
+#: ../alternatives.c:791
#, c-format
msgid " Selection Command\n"
msgstr ""
-#: ../alternatives.c:804
+#: ../alternatives.c:805
#, c-format
msgid "Enter to keep the current selection[+], or type selection number: "
msgstr ""
-#: ../alternatives.c:807
+#: ../alternatives.c:808
#, c-format
msgid ""
"\n"
"error reading choice\n"
msgstr ""
-#: ../alternatives.c:844 ../alternatives.c:872
+#: ../alternatives.c:845 ../alternatives.c:873
#, c-format
msgid "%s has not been configured as an alternative for %s\n"
msgstr ""
-#: ../alternatives.c:888
+#: ../alternatives.c:889
#, c-format
msgid "(would remove %s\n"
msgstr ""
-#: ../alternatives.c:890
+#: ../alternatives.c:891
#, c-format
msgid "failed to remove %s: %s\n"
msgstr ""
-#: ../alternatives.c:1009
+#: ../alternatives.c:1038
#, c-format
msgid "--family can't contain the symbol '@'\n"
msgstr ""
-#: ../alternatives.c:1062
+#: ../alternatives.c:1093
#, c-format
msgid "altdir %s invalid\n"
msgstr ""
-#: ../alternatives.c:1068
+#: ../alternatives.c:1099
#, c-format
msgid "admindir %s invalid\n"
msgstr ""
-#: ../alternatives.c:1078
+#: ../alternatives.c:1109
#, c-format
msgid "alternatives version %s\n"
msgstr ""
--
1.8.3.1

Binary file not shown.

BIN
chkconfig-1.14.tar.gz Normal file

Binary file not shown.

View File

@ -1,22 +1,20 @@
Name: chkconfig
Version: 1.10
Release: 8
Version: 1.14
Release: 4
Summary: chkconfig updates and queries runlevel information for system services
License: GPLv2
URL: https://github.com/fedora-sysv/chkconfig
Source0: https://github.com/fedora-sysv/chkconfig/archive/%{version}.tar.gz#/%{name}-%{version}.tar.gz
Patch6000: bugfix-alternatives-prettier-list-output.patch
Patch6001: bugfix-leveldb-don-t-crash-on-long-names.patch
Patch6002: man-alternatives-list-does-not-accept-name.patch
Patch6003: paths-to-targets-and-facilities-normalized-bug-14853.patch
Patch6004: added-check-if-correct-symlink-exists.patch
Patch6005: Remove-mistakenly-added-text.patch
BuildRequires: gcc newt-devel gettext popt-devel libselinux-devel
BuildRequires: gcc newt-devel gettext popt-devel libselinux-devel beakerlib
Conflicts: initscripts <= 5.30-1
Provides: ntsysv = %{version}-%{release}
Obsoletes: ntsysv < %{version}-%{release}
Patch0: fix-coredump-while-parseServiceInfo-return-1.patch
Patch6000: backport-leveldb-fix-systemdActive.patch
%description
chkconfig provides a simple command-line tool for maintaining
the /etc/rc[0-6].d directory hierarchy by relieving system
@ -63,6 +61,18 @@ mkdir -p %{buildroot}%{_sysconfdir}/chkconfig.d
%{_mandir}/man8/*
%changelog
* Thu Aug 22 2024 dongyuzhen <dongyuzhen@h-partners.com> - 1.14-4
- fix systemdActive()
* Mon Feb 13 2023 xujing <xujing125@huawei.com> - 1.14-3
- enable make check
* Sat Aug 27 2022 yixiangzhike <yixiangzhike007@163.com> - 1.14-2
- fix coredump while parseServiceInfo return non-zero
* Fri Jul 31 2020 wangchen <wangchen137@huawei.com> - 1.14-1
- Update to 1.14
* Tue Dec 24 2019 openEuler Buildteam <buildteam@openeuler.org> - 1.10-8
- Add obsoletes of ntsysv

4
chkconfig.yaml Normal file
View File

@ -0,0 +1,4 @@
version_control: github
src_repo: fedora-sysv/chkconfig
tag_prefix:
seperator: "."

View File

@ -0,0 +1,25 @@
From 05f7ea8fa198a6b98dd98cb1a8b1774da701e917 Mon Sep 17 00:00:00 2001
From: xujing <xujing125@huawei.com>
Date: Fri, 12 Aug 2022 10:01:32 +0800
Subject: [PATCH] fix coredump while parseServiceInfo return 1
---
leveldb.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/leveldb.c b/leveldb.c
index 7b8c1bd..8a7a81d 100644
--- a/leveldb.c
+++ b/leveldb.c
@@ -377,7 +377,7 @@ int readServiceInfo(char *name, int type, struct service *service,
asprintf(&filename, RUNLEVELS "/chkconfig.d/%s", name);
if ((fd = open(filename, O_RDONLY)) >= 0) {
parseret = parseServiceInfo(fd, name, &serv_overrides, honorHide, 1);
- if (parseret >= 0) {
+ if (parseret == 0) {
if (serv_overrides.name)
serv.name = serv_overrides.name;
if (serv_overrides.levels != -1)
--
2.27.0

View File

@ -1,24 +0,0 @@
From 3e7257fe4bf7ec253a782fa6a9e5f061bbf8ddde Mon Sep 17 00:00:00 2001
From: Lukas Nykryn <lnykryn@redhat.com>
Date: Tue, 2 Oct 2018 17:48:42 +0200
Subject: [PATCH] man: alternatives --list does not accept name
---
alternatives.8 | 1 -
1 file changed, 1 deletion(-)
diff --git a/alternatives.8 b/alternatives.8
index 941dba4..a512873 100644
--- a/alternatives.8
+++ b/alternatives.8
@@ -48,7 +48,6 @@ alternatives \- maintain symbolic links determining default commands
.B alternatives
.RI [ options ]
.B --list
-.I name
.PP
.B alternatives
.RI [ options ]
--
2.21.0.windows.1

View File

@ -1,107 +0,0 @@
From 624427e2c458ec94fe6ef33e9efeb7876042aa21 Mon Sep 17 00:00:00 2001
From: luochunsheng <luochunsheng@huawei.com>
Date: Tue, 9 Apr 2019 20:18:39 +0800
Subject: [PATCH] paths to targets and facilities normalized, bug #1485304
---
alternatives.c | 31 +++++++++++++++++++++++--------
1 file changed, 23 insertions(+), 8 deletions(-)
diff --git a/alternatives.c b/alternatives.c
index c1a68db..cdfec6d 100644
--- a/alternatives.c
+++ b/alternatives.c
@@ -85,6 +85,21 @@ static int usage(int rc) {
exit(rc);
}
+const char *normalize_path(const char *s) {
+ if (s) {
+ const char *src = s;
+ char *dst = (char *)s;
+ while ((*dst = *src) != '\0') {
+ do {
+ src++;
+ } while (*dst == '/' && *src == '/');
+ dst++;
+ }
+ }
+ return (const char *)s;
+}
+
+
int streq(const char *a, const char *b) {
if (a && b)
return strcmp(a, b) ? 0 : 1;
@@ -147,7 +162,7 @@ static void setupDoubleArg(enum programModes * mode, const char *** nextArgPtr,
nextArg++;
if (!*nextArg) usage(2);
- *target = strdup(*nextArg);
+ *target = strdup(normalize_path(*nextArg));
*nextArgPtr = nextArg + 1;
}
@@ -155,7 +170,7 @@ static void setupLinkSet(struct linkSet * set, const char *** nextArgPtr) {
const char ** nextArg = *nextArgPtr;
if (!*nextArg || **nextArg != '/') usage(2);
- set->facility = strdup(*nextArg);
+ set->facility = strdup(normalize_path(*nextArg));
nextArg++;
if (!*nextArg || **nextArg == '/') usage(2);
@@ -163,7 +178,7 @@ static void setupLinkSet(struct linkSet * set, const char *** nextArgPtr) {
nextArg++;
if (!*nextArg || **nextArg != '/') usage(2);
- set->target = strdup(*nextArg);
+ set->target = strdup(normalize_path(*nextArg));
*nextArgPtr = nextArg + 1;
}
@@ -295,7 +310,7 @@ static int readConfig(struct alternativeSet * set, const char * title,
return 1;
}
- set->alts[set->numAlts].master.facility = strdup(groups[0].facility);
+ set->alts[set->numAlts].master.facility = strdup(normalize_path(groups[0].facility));
set->alts[set->numAlts].master.title = strdup(groups[0].title);
set->alts[set->numAlts].master.target = line;
set->alts[set->numAlts].numSlaves = numGroups - 1;
@@ -352,7 +367,7 @@ static int readConfig(struct alternativeSet * set, const char * title,
set->alts[set->numAlts].slaves[i - 1].title =
strdup(groups[i].title);
set->alts[set->numAlts].slaves[i - 1].facility =
- strdup(groups[i].facility);
+ strdup(normalize_path(groups[i].facility));
set->alts[set->numAlts].slaves[i - 1].target = (line && strlen(line)) ? line : NULL;
}
@@ -396,7 +411,7 @@ static int readConfig(struct alternativeSet * set, const char * title,
set->current = i;
}
- set->currentLink = strdup(linkBuf);
+ set->currentLink = strdup(normalize_path(linkBuf));
return 0;
}
@@ -1060,12 +1075,12 @@ int main(int argc, const char ** argv) {
} else if (!strcmp(*nextArg, "--altdir")) {
nextArg++;
if (!*nextArg) usage(2);
- altDir = strdup(*nextArg);
+ altDir = strdup(normalize_path(*nextArg));
nextArg++;
} else if (!strcmp(*nextArg, "--admindir")) {
nextArg++;
if (!*nextArg) usage(2);
- stateDir = strdup(*nextArg);
+ stateDir = strdup(normalize_path(*nextArg));
nextArg++;
} else if (!strcmp(*nextArg, "--list")) {
if (mode != MODE_UNKNOWN) usage(2);
--
1.8.3.1