From 3306102f87947f12a18f29a667098f2ed0179394 Mon Sep 17 00:00:00 2001 From: short <> Date: Tue, 15 Jun 2004 11:38:56 +0000 Subject: [PATCH] Implemented LSB init scripts compliance. --- src/startup-chkconfig.c | 54 ++++++++++++++++++++++++++++++++++++++++--------- udpgate.spec.in | 4 +++- 2 files changed, 48 insertions(+), 10 deletions(-) diff --git a/src/startup-chkconfig.c b/src/startup-chkconfig.c index 79a610b..09900d6 100644 --- a/src/startup-chkconfig.c +++ b/src/startup-chkconfig.c @@ -27,6 +27,7 @@ #include #include #include +#include #include "startup-chkconfig.h" /* self */ @@ -36,7 +37,13 @@ /* Config: */ -#define INIT_D_PATHNAME G_STRINGIFY(SYSCONFDIR) "/rc.d/init.d/" PACKAGE +/* Do not: /etc/rc.d/init.d/... + * to comply with http://www.linuxbase.org/spec/booksets/LSB-Core/LSB-Core.html#INITSRCINSTRM + */ +#define INIT_D_PATHNAME G_STRINGIFY(SYSCONFDIR) "/init.d/" PACKAGE + +#define COMMAND_INSTALL_INIT_D "/usr/lib/lsb/install_initd" +#define COMMAND_REMOVE_INIT_D "/usr/lib/lsb/remove_initd" #define STATUS_0_1(status) ( \ @@ -45,6 +52,21 @@ && !WIFSTOPPED((status))) \ ? -1 : WEXITSTATUS((status))) +static gboolean chkexec(const gchar *binary) +{ +struct stat statbuf; + + g_return_val_if_fail(binary!=NULL,FALSE); + + if (stat(COMMAND_INSTALL_INIT_D,&statbuf)) + return FALSE; + if ((statbuf.st_mode&(S_IFMT|0111))!=(S_IFREG|0111)) + return FALSE; + + return TRUE; +} + + gboolean startup_chkconfig_init(void) { static gboolean r,r_set=FALSE; @@ -53,13 +75,18 @@ static gboolean r,r_set=FALSE; int status; const gchar *command="chkconfig " PACKAGE; - status=system(command); - if (STATUS_0_1(status)<0) { - g_warning(_("Error checking validity of chkconfig(8) setup; automatic startup disabled; failed command: %s"),command); - r=FALSE; - } - else + /* LSB compliant 'query' is not standardized. */ + if (chkexec(COMMAND_INSTALL_INIT_D) && chkexec(COMMAND_REMOVE_INIT_D)) r=TRUE; + else { + status=system(command); + if (STATUS_0_1(status)<0) { + g_warning(_("Error checking validity of chkconfig(8) setup; automatic startup disabled; failed command: %s"),command); + r=FALSE; + } + else + r=TRUE; + } r_set=TRUE; } return r; @@ -75,6 +102,7 @@ const gchar *command="chkconfig " PACKAGE; if (!startup_chkconfig_init()) return FALSE; + /* LSB compliant 'query' is not standardized. */ status=system(command); status_0_1=STATUS_0_1(status); if (status_0_1<0) { @@ -88,7 +116,7 @@ const gchar *command="chkconfig " PACKAGE; gboolean startup_chkconfig_on(void) { int status; -const gchar *command="chkconfig --add " PACKAGE; +const gchar *command="chkconfig --add"; if (!startup_chkconfig_init()) return FALSE; @@ -101,7 +129,12 @@ const gchar *command="chkconfig --add " PACKAGE; TRUE)) /* pathname_backup */ return FALSE; #endif /* ENABLE_BUNDLE */ + + if (chkexec(COMMAND_INSTALL_INIT_D)) + command=COMMAND_INSTALL_INIT_D; + command=udpgate_printf_alloca("%s %s",command,PACKAGE); status=system(command); + if (0!=STATUS_0_1(status)) { g_warning(_("Error registering automatic program startup by: %s"),command); return FALSE; @@ -111,12 +144,15 @@ const gchar *command="chkconfig --add " PACKAGE; gboolean startup_chkconfig_off(void) { -const gchar *command="chkconfig --del " PACKAGE; +const gchar *command="chkconfig --del"; int status; if (!startup_chkconfig_init()) return FALSE; + if (chkexec(COMMAND_REMOVE_INIT_D)) + command=COMMAND_REMOVE_INIT_D; + command=udpgate_printf_alloca("%s %s",command,PACKAGE); status=system(command); if (0!=STATUS_0_1(status)) { g_warning(_("Error removing program's system startup registrance by: %s"),command); diff --git a/udpgate.spec.in b/udpgate.spec.in index 062b8d2..2b33d9a 100644 --- a/udpgate.spec.in +++ b/udpgate.spec.in @@ -69,7 +69,9 @@ rm -rf $RPM_BUILD_ROOT %defattr(-,root,root) %doc README NEWS AUTHORS %attr(644,root,root) %{_mandir}/man?/@PACKAGE@.* -%attr(755,root,root) %{_sysconfdir}/rc.d/init.d/@PACKAGE@ +# Do not: /etc/rc.d/init.d/... +# to comply with http://www.linuxbase.org/spec/booksets/LSB-Core/LSB-Core.html#INITSRCINSTRM +%attr(755,root,root) %{_sysconfdir}/init.d/@PACKAGE@ # %config(noreplace) %{_sysconfdir}/sysconfig/@PACKAGE@ %{_bindir}/@PACKAGE@ %{_datadir}/locale/*/LC_MESSAGES/@PACKAGE@.mo -- 1.8.3.1