#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 STATUS_0_1(status) ( \
&& !WIFSTOPPED((status))) \
? -1 : WEXITSTATUS((status)))
-gboolean startup_chkconfig_init(void)
-{
-static gboolean r,r_set=FALSE;
- if (!r_set) {
+static gboolean udpgate_startup_chkconfig_init(UdpgateStartup *udpgate_startup)
+{
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
- r=TRUE;
- r_set=TRUE;
- }
- return r;
+const gchar *command="chkconfig " PACKAGE " 2>/dev/null";
+
+ g_return_val_if_fail(UDPGATE_IS_STARTUP_CHKCONFIG(udpgate_startup),FALSE);
+
+ status=system(command);
+ if (STATUS_0_1(status)<0)
+ return FALSE;
+ return TRUE;
}
-gboolean startup_chkconfig_query(gboolean *is_on)
+static gboolean udpgate_startup_chkconfig_query(UdpgateStartup *udpgate_startup,gboolean *is_on)
{
int status,status_0_1;
-const gchar *command="chkconfig " PACKAGE;
+/* FC4 chkconfig-1.3.20-1 dumps its help to stderr and returns 1 for: chkconfig PACKAGE
+ * without its existing: /etc/init.d/PACKAGE
+ */
+const gchar *command="chkconfig " PACKAGE " 2>/dev/null";
- g_return_val_if_fail(is_on!=NULL,FALSE);
-
- if (!startup_chkconfig_init())
- return FALSE;
+ g_return_val_if_fail(UDPGATE_IS_STARTUP_CHKCONFIG(udpgate_startup),FALSE);
status=system(command);
status_0_1=STATUS_0_1(status);
g_warning(_("Error checking registrance of this program automatic startup by: %s"),command);
return FALSE;
}
- *is_on=(status_0_1==0);
+ if (is_on)
+ *is_on=(status_0_1==0);
return TRUE;
}
-gboolean startup_chkconfig_on(void)
+static gboolean udpgate_startup_chkconfig_on(UdpgateStartup *udpgate_startup)
{
-int status;
const gchar *command="chkconfig --add " PACKAGE;
+int status;
- if (!startup_chkconfig_init())
- return FALSE;
+ g_return_val_if_fail(UDPGATE_IS_STARTUP_CHKCONFIG(udpgate_startup),FALSE);
#ifdef ENABLE_BUNDLE
if (!bundle_util_file_write(
INIT_D_PATHNAME, /* pathname */
PACKAGE ".init", /* basename */
0755, /* pathname_mode */
- TRUE)) /* pathname_backup */
+ BUNDLE_UTIL_BACKUP_MASK)) /* flags */
return FALSE;
#endif /* ENABLE_BUNDLE */
+
status=system(command);
+
if (0!=STATUS_0_1(status)) {
g_warning(_("Error registering automatic program startup by: %s"),command);
return FALSE;
return TRUE;
}
-gboolean startup_chkconfig_off(void)
+static gboolean udpgate_startup_chkconfig_off(UdpgateStartup *udpgate_startup)
{
const gchar *command="chkconfig --del " PACKAGE;
int status;
- if (!startup_chkconfig_init())
- return FALSE;
+ g_return_val_if_fail(UDPGATE_IS_STARTUP_CHKCONFIG(udpgate_startup),FALSE);
status=system(command);
if (0!=STATUS_0_1(status)) {
g_warning(_("Error removing program's system startup registrance by: %s"),command);
return FALSE;
}
+
#ifdef ENABLE_BUNDLE
if (!bundle_util_file_remove(INIT_D_PATHNAME,PACKAGE ".init"))
return FALSE;
#endif /* ENABLE_BUNDLE */
+
return TRUE;
}
+
+static void udpgate_startup_chkconfig_class_init (UdpgateStartupChkconfigClass *class)
+{
+ UdpgateStartupClass *udpgate_startup_class = UDPGATE_STARTUP_CLASS(class);
+
+ udpgate_startup_class->init = udpgate_startup_chkconfig_init;
+ udpgate_startup_class->query = udpgate_startup_chkconfig_query;
+ udpgate_startup_class->on = udpgate_startup_chkconfig_on;
+ udpgate_startup_class->off = udpgate_startup_chkconfig_off;
+}
+
+GType udpgate_startup_chkconfig_get_type(void)
+{
+ static GType udpgate_startup_chkconfig_type=0;
+
+ if (!udpgate_startup_chkconfig_type) {
+ static const GTypeInfo udpgate_startup_chkconfig_info={
+ sizeof(UdpgateStartupChkconfigClass),
+ NULL, /* base_init */
+ NULL, /* base_finalize */
+ (GClassInitFunc)udpgate_startup_chkconfig_class_init,
+ NULL, /* class_finalize */
+ NULL, /* class_data */
+ sizeof(UdpgateStartupChkconfig),
+ 0, /* n_preallocs */
+ NULL, /* instance_init */
+ NULL, /* value_table */
+ };
+
+ udpgate_startup_chkconfig_type=g_type_register_static(UDPGATE_TYPE_STARTUP,"UdpgateStartupChkconfig",
+ &udpgate_startup_chkconfig_info,0);
+ }
+
+ return udpgate_startup_chkconfig_type;
+}