Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[please ignore] CI test #138

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ install:
[ -d $(DESTDIR)/$(SBINDIR) ] || mkdir -p $(DESTDIR)/$(SBINDIR)
[ -d $(DESTDIR)/$(MANDIR) ] || mkdir -p $(DESTDIR)/$(MANDIR)
[ -d $(DESTDIR)/$(MANDIR)/man8 ] || mkdir -p $(DESTDIR)/$(MANDIR)/man8
[ -d $(DESTDIR)/$(ALTDIR) ] || mkdir -p -m 755 $(DESTDIR)/$(ALTDIR)
[ -d $(DESTDIR)/$(ALTDATADIR) ] || mkdir -p -m 755 $(DESTDIR)/$(ALTDATADIR)
[ -d $(DESTDIR)/$(SYSTEMDUTILDIR) ] || mkdir -p -m 755 $(DESTDIR)/$(SYSTEMDUTILDIR)

Expand Down
2 changes: 2 additions & 0 deletions alternatives.8
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ A directory, by default
containing
.BR alternatives '
state information.
/etc/alternatives.admindir on OSTree-based systems.
.TP
link group
A set of related symlinks, intended to be updated as a group.
Expand Down Expand Up @@ -416,6 +417,7 @@ option.
.TP
.I /var/lib/alternatives/
The default administration directory.
/etc/alternatives.admindir on OSTree-based systems.
Can be overridden by the
.B --admindir
option.
Expand Down
43 changes: 42 additions & 1 deletion alternatives.c
Original file line number Diff line number Diff line change
Expand Up @@ -1290,6 +1290,33 @@ static int listServices(const char *altDir, const char *stateDir, int flags) {
return 0;
}

int dirExists(const char *path) {
struct stat sb;

if (stat(path, &sb)) {
if (errno == ENOENT) {
return 0;
}
}

if (!S_ISDIR(sb.st_mode) || access(path, F_OK)) {
fprintf(stderr, _("admindir %s invalid\n"), path);
exit(2);
}

return 1;
}

int canUseAlternativeAdminDirUnderOSTree() {
if (dirExists("/var/lib/alternatives")) { return 0; }

if (fileExists("/run/ostree-booted") || isLink("/ostree")) {
return 1;
}

return 0;
}

int main(int argc, const char **argv) {
const char **nextArg;
char *end;
Expand All @@ -1300,10 +1327,11 @@ int main(int argc, const char **argv) {
struct alternative newAlt = {-1, {NULL, NULL, NULL}, NULL, NULL, 0, NULL};
int flags = 0;
char *altDir = "/etc/alternatives";
char *stateDir = "/var/lib/alternatives";
char *stateDir= NULL;
struct stat sb;
struct linkSet newSet = {NULL, NULL, NULL};


setlocale(LC_ALL, "");
bindtextdomain("chkconfig", "/usr/share/locale");
textdomain("chkconfig");
Expand Down Expand Up @@ -1428,6 +1456,19 @@ int main(int argc, const char **argv) {
exit(2);
}

if ((stateDir == NULL)) {
if (canUseAlternativeAdminDirUnderOSTree()) {
stateDir = "/etc/alternatives.admindir";
} else {
stateDir = "/var/lib/alternatives";
}

if ((dirExists(stateDir) == 0) && (mkdir(stateDir, 0755) == -1)) {
fprintf(stderr, _("creating admindir: %s\n"), strerror(errno));
exit(2);
}
}

if (stat(stateDir, &sb) || !S_ISDIR(sb.st_mode) || access(stateDir, F_OK)) {
fprintf(stderr, _("admindir %s invalid\n"), stateDir);
exit(2);
Expand Down
7 changes: 3 additions & 4 deletions chkconfig.spec
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Provides: /sbin/chkconfig
%description
Chkconfig is a basic system utility. It updates and queries runlevel
information for system services. Chkconfig manipulates the numerous
symbolic links in /etc/rc.d, to relieve system administrators of some
symbolic links in /etc/rc.d, to relieve system administrators of some
of the drudgery of manually editing the symbolic links.

%package -n ntsysv
Expand Down Expand Up @@ -81,9 +81,7 @@ mkdir -p $RPM_BUILD_ROOT/etc/chkconfig.d
%{_sysconfdir}/chkconfig.d
%{_sysconfdir}/init.d
%{_sysconfdir}/rc.d
%{_sysconfdir}/rc.d/init.d
%{_sysconfdir}/rc[0-6].d
%{_sysconfdir}/rc.d/rc[0-6].d
%{_mandir}/*/chkconfig*
%{_prefix}/lib/systemd/systemd-sysv-install

Expand All @@ -95,11 +93,12 @@ mkdir -p $RPM_BUILD_ROOT/etc/chkconfig.d
%files -n alternatives
%license COPYING
%dir /etc/alternatives
%ghost /etc/alternatives.admindir
%ghost /var/lib/alternatives
%{_sbindir}/update-alternatives
%{_sbindir}/alternatives
%{_mandir}/*/update-alternatives*
%{_mandir}/*/alternatives*
%dir /var/lib/alternatives

%changelog
* Fri Jun 21 2024 Jan Macku <[email protected]> - 1.28-1
Expand Down
Loading