/*************************************************************************** * 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. * ***************************************************************************/ #include "prcsys.h" #include "prcsys_files.h" #include "prcsys_list.h" #include "prcsys_action.h" #include "prcsys_log.h" /** * This is the help function. It's called when the option * "--help" is on the command line or if an argument is incorrect. * */ void usage(char * softname) { printf("Usage: %s [--test] [--debug [--verbose]] [--logfile ] \n" " could be:\n" " S : start\n" " K : kill\n" " is the directory holding all script for the runlevel\n" "\n" "for example, to test the distribution's start, run:\n" "$ %s --test S /etc/rc5.d/\n", softname, softname); exit(1); } int main(int argc, char ** argv) { char *env, *command, *directory; int c, option_index = 0; int verbose = 0; char * logfile = NULL; struct option long_options[] = { /* These options set a flag. */ {"test", no_argument, &test_mode, 1}, {"help", no_argument, &help_mode, 1}, {"debug",no_argument, &debug, 1}, {"verbose",no_argument, &verbose,1}, {"logfile",required_argument,NULL,2}, {0, 0, 0, 0} }; /* parse command line for flag */ while ( (c = getopt_long (argc, argv, "", long_options, &option_index)) != -1 ) if(c == 2) logfile = optarg; /* parse the argument */ if ( argc - optind == 2 ) { command = argv[optind]; directory = argv[optind+1]; } else { /* not enough parameter or too many parameter */ usage(argv[0]); } if(verbose && !debug) { printf("Cannot be verbose and not in debug mode\n"); usage(argv[0]); } if(verbose) debug++; openlog(logfile); /* run the action given in the command line */ switch (*command) { case MODE_START: mode_start(directory); break; case MODE_KILL : mode_kill(directory); break; default: printf("Unknow mode %s\n", command); exit(1); break; }; closelog(); if((env = getenv("progress")) != NULL) return atoi(env); return 0; }