2 * UDP Gateway utility startup scripts support using chkconfig(8)
3 * Copyright (C) 2004 Jan Kratochvil <project-udpgate@jankratochvil.net>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; exactly version 2 of June 1991 is required
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include <glib/gmessages.h>
24 #include <sys/types.h>
27 #include <glib/gmem.h>
31 #include "startup-chkconfig.h" /* self */
34 #include "bundle-util.h"
39 #define INIT_D_PATHNAME G_STRINGIFY(SYSCONFDIR) "/rc.d/init.d/" PACKAGE
42 #define STATUS_0_1(status) ( \
43 !(WIFEXITED((status)) && (WEXITSTATUS((status))==0 || WEXITSTATUS((status))==1) \
44 && !WIFSIGNALED((status)) \
45 && !WIFSTOPPED((status))) \
46 ? -1 : WEXITSTATUS((status)))
48 gboolean startup_chkconfig_init(void)
50 static gboolean r,r_set=FALSE;
54 const gchar *command="chkconfig " PACKAGE;
56 status=system(command);
57 if (STATUS_0_1(status)<0) {
58 g_warning(_("Error checking validity of chkconfig(8) setup; automatic startup disabled; failed command: %s"),command);
68 gboolean startup_chkconfig_query(gboolean *is_on)
70 int status,status_0_1;
71 const gchar *command="chkconfig " PACKAGE;
73 g_return_val_if_fail(is_on!=NULL,FALSE);
75 if (!startup_chkconfig_init())
78 status=system(command);
79 status_0_1=STATUS_0_1(status);
81 g_warning(_("Error checking registrance of this program automatic startup by: %s"),command);
84 *is_on=(status_0_1==0);
88 gboolean startup_chkconfig_on(void)
91 const gchar *command="chkconfig --add " PACKAGE;
93 if (!startup_chkconfig_init())
97 if (!bundle_util_file_write(INIT_D_PATHNAME,PACKAGE ".init",0755))
99 #endif /* ENABLE_BUNDLE */
100 status=system(command);
101 if (0!=STATUS_0_1(status)) {
102 g_warning(_("Error registering automatic program startup by: %s"),command);
108 gboolean startup_chkconfig_off(void)
110 const gchar *command="chkconfig --del " PACKAGE;
113 if (!startup_chkconfig_init())
116 status=system(command);
117 if (0!=STATUS_0_1(status)) {
118 g_warning(_("Error removing program's system startup registrance by: %s"),command);
122 if (!bundle_util_file_remove(INIT_D_PATHNAME,PACKAGE ".init"))
124 #endif /* ENABLE_BUNDLE */