X-Git-Url: http://git.jankratochvil.net/?a=blobdiff_plain;f=src%2Fstartup-chkconfig.c;h=b9891e55791bd3e8d27675babd4cdecac5870ca5;hb=39cbef607ca66475fc2ec6a2355505f012be9988;hp=09900d621e163528766e9ae1875341399fff8df4;hpb=3306102f87947f12a18f29a667098f2ed0179394;p=udpgate.git diff --git a/src/startup-chkconfig.c b/src/startup-chkconfig.c index 09900d6..b9891e5 100644 --- a/src/startup-chkconfig.c +++ b/src/startup-chkconfig.c @@ -42,9 +42,6 @@ */ #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) \ @@ -52,87 +49,57 @@ && !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); +/* 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"; - 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( INIT_D_PATHNAME, /* pathname */ PACKAGE ".init", /* basename */ 0755, /* pathname_mode */ - TRUE)) /* pathname_backup */ + BUNDLE_UTIL_BACKUP_MASK)) /* flags */ 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)) { @@ -142,25 +109,58 @@ const gchar *command="chkconfig --add"; 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; +}