*/
#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) ( \
!(WIFEXITED((status)) && (WEXITSTATUS((status))==0 || WEXITSTATUS((status))==1) \
&& !WIFSTOPPED((status))) \
? -1 : WEXITSTATUS((status)))
-static gboolean chkexec(const gchar *binary)
+
+static gboolean udpgate_startup_chkconfig_init(UdpgateStartup *udpgate_startup)
{
-struct stat statbuf;
+int status;
+const gchar *command="chkconfig " PACKAGE " 2>/dev/null";
- g_return_val_if_fail(binary!=NULL,FALSE);
+ g_return_val_if_fail(UDPGATE_IS_STARTUP_CHKCONFIG(udpgate_startup),FALSE);
- if (stat(COMMAND_INSTALL_INIT_D,&statbuf))
- return FALSE;
- if ((statbuf.st_mode&(S_IFMT|0111))!=(S_IFREG|0111))
+ status=system(command);
+ if (STATUS_0_1(status)<0)
return FALSE;
-
return TRUE;
}
-
-gboolean startup_chkconfig_init(void)
-{
-static gboolean r,r_set=FALSE;
-
- if (!r_set) {
-int status;
-const gchar *command="chkconfig " PACKAGE;
-
- /* 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;
-}
-
-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;
- 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);
- /* LSB compliant 'query' is not standardized. */
status=system(command);
status_0_1=STATUS_0_1(status);
if (status_0_1<0) {
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)
{
+const gchar *command="chkconfig --add " PACKAGE;
int status;
-const gchar *command="chkconfig --add";
- 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(
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)) {
return TRUE;
}
-gboolean startup_chkconfig_off(void)
+static gboolean udpgate_startup_chkconfig_off(UdpgateStartup *udpgate_startup)
{
-const gchar *command="chkconfig --del";
+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);
- 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);
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;
+}