#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;
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;
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) {
gboolean startup_chkconfig_on(void)
{
int status;
-const gchar *command="chkconfig --add " PACKAGE;
+const gchar *command="chkconfig --add";
if (!startup_chkconfig_init())
return FALSE;
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;
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);
%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