/* $Id$ * UDP Gateway utility startup scripts support using chkconfig(8) * Copyright (C) 2004 Jan Kratochvil * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; exactly version 2 of June 1991 is required * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include "config.h" #include #include #include #include #include #include #include #include #include "startup-chkconfig.h" /* self */ #ifdef ENABLE_BUNDLE #include "bundle-util.h" #endif /* Config: */ #define INIT_D_PATHNAME G_STRINGIFY(SYSCONFDIR) "/rc.d/init.d/" PACKAGE #define STATUS_0_1(status) ( \ !(WIFEXITED((status)) && (WEXITSTATUS((status))==0 || WEXITSTATUS((status))==1) \ && !WIFSIGNALED((status)) \ && !WIFSTOPPED((status))) \ ? -1 : WEXITSTATUS((status))) gboolean startup_chkconfig_init(void) { static gboolean r,r_set=FALSE; if (!r_set) { 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; } gboolean startup_chkconfig_query(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; 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); return TRUE; } gboolean startup_chkconfig_on(void) { int status; const gchar *command="chkconfig --add " PACKAGE; if (!startup_chkconfig_init()) return FALSE; #ifdef ENABLE_BUNDLE if (!bundle_util_file_write( INIT_D_PATHNAME, /* pathname */ PACKAGE ".init", /* basename */ 0755, /* pathname_mode */ TRUE)) /* pathname_backup */ 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) { const gchar *command="chkconfig --del " PACKAGE; int status; if (!startup_chkconfig_init()) return 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; }