/*************************************************************************** * Copyright (C) 2006 by couriousous, blino, trem * * couriousous@mandriva.org * * oblin@mandriva.com * * trem@mandriva.org * * * * 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; either version 2 of the License, or * * (at your option) any later version. * * * * 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. * ***************************************************************************/ #ifndef __PRCSYS_H__ #define __PRCSYS_H__ #define _GNU_SOURCE #include #include #include #include #include #include #include #include #include #include #include #include #define NAME_LENGTH 256 #define MODE_START 'S' #define MODE_KILL 'K' #define CMD_START "start" #define CMD_STOP "stop" #define FORMAT_CMD "%s %s 2>&1" #define FORMAT_CMD_OUTPUT "%s %s > %s 2>&1" #define malloc_or_die(ptr,size) do { ptr = malloc(size); if(ptr == NULL) { printf("Out of memory, Line: %d\n",__LINE__); exit(1); } } while(0) /* Here is a simplified internal service representations : struct service ------------- ,-> ------------- ,->------------- - service 1 - / - service 2 - / - service N - - next ->~ - next ->~ - next -> NULL - provides ->+ - provides - - provides - - requires ->|--+ - requires - - requires - ------------- | | ------------- ------------- | | struct proreq | \ --------------+ \ struct proreq - Provide 1 - ->-------------- - next ->+ - Requires 1 - --------------- | - serv ->---> Pointer over a struct service. / - next ->+ / -------------- | --------------+ / - Provide 2 - / - next ->+ -------------+ --------------- | - Requires 2 - / - serv - / - next ->+ --------------+ -------------- | - Provide N - / - next ->NULL / --------------- -------------+ - Requires N - - serv - - next ->NULL -------------- */ /* list of requires/provides */ struct proreq { char name[NAME_LENGTH]; /* Requires/Provide name */ struct service * serv; struct proreq * next; /* next requires/provide in the list */ }; /* list of services */ struct service { char name[NAME_LENGTH]; /* name of the service */ char file[NAME_LENGTH]; /* path to service' file */ pthread_mutex_t mut; /* mutex, used to protect cond */ pthread_cond_t cond; /* condition to tell "I'm started" change */ int ready; /* this service is ready to be manager, ie started or stopped */ int is_lsb; /* this is a LSB script */ int compat_mode; /* run this service in compat mode if true */ int raw_console; /* flag to tell "I want direct console access", ie when the service is inteactive */ int count; /* used for internal loop detection between service */ struct proreq * provides; /* list of service' provides */ struct proreq * requires; /* list of service' requires */ struct service * next; /* next service in the list */ }; /* head of the service list */ extern struct service *servlist; /* mutex to protect console access */ extern pthread_mutex_t console_mutex; /* general current mode, MODE_START or MODE_KILL */ extern char mode; /* test mode, we don't execute script, we only show in which order we launch them */ extern int test_mode; /* help mode, we only write help and quit */ extern int help_mode; /* debug mode, if enabled, log a lot of stuff */ extern int debug; #endif