Implemented LSB init scripts compliance.
authorshort <>
Tue, 15 Jun 2004 11:38:56 +0000 (11:38 +0000)
committershort <>
Tue, 15 Jun 2004 11:38:56 +0000 (11:38 +0000)
src/startup-chkconfig.c
udpgate.spec.in

index 79a610b..09900d6 100644 (file)
@@ -27,6 +27,7 @@
 #include <glib/gmem.h>
 #include <unistd.h>
 #include <string.h>
+#include <sys/stat.h>
 
 #include "startup-chkconfig.h" /* self */
 
 
 
 /* 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) ( \
                                                && !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);
index 062b8d2..2b33d9a 100644 (file)
@@ -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