Tue, 22 Apr 2014 17:26:30 +0200
Basic package is complete
/***************************************************************************** * Copyright (C) 2014 * * Michiel Broek <mbroek at mbse dot eu> * * This file is part of the mbsePi-apps * * This 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, or (at your option) any * later version. * * mbsePi-apps 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 EC-65K; see the file COPYING. If not, write to the Free * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *****************************************************************************/ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <getopt.h> #include <sys/types.h> #include <signal.h> #include "main.h" void help(void) { fprintf(stdout, "Usage: thermomeneters [-d] [-h]\n"); fprintf(stdout, " -d --debug Debug on\n"); fprintf(stdout, " -h --help Display this help\n"); } void die(int onsig) { switch (onsig) { case SIGHUP: fprintf(stdout, "[main] Hangup detected"); break; case SIGINT: fprintf(stdout, "[main] Interrupt from keyboard"); break; case SIGTERM: fprintf(stdout, "[main] Termination signal received"); break; default: fprintf(stdout, "[main] die on signal %d", onsig); } exit(onsig); } int main(int argc, char *argv[]) { int i, c; while (1) { int option_index = 0; static struct option long_options[] = { {"debug", 0, 0, 'c'}, {"help", 0, 0, 'h'}, {0, 0, 0, 0} }; c = getopt_long(argc, argv, "dh", long_options, &option_index); if (c == -1) break; switch (c) { case 'd': break; case 'h': help(); return 1; } } /* * Catch all the signals we can, and ignore the rest. Note that SIGKILL can't be ignored * but that's live. This daemon should only be stopped by SIGTERM. * Don't catch SIGCHLD. */ for (i = 0; i < NSIG; i++) { if ((i != SIGCHLD) && (i != SIGKILL) && (i != SIGSTOP)) signal(i, (void (*))die); } return 0; }