N-sim
Emulation and simulation of
Wireless Sensor Networks



   Home


   Project Page


   Download


   CVS



   Installation


   Configuration


   Plug-ins




 Hosted by
SourceForge.net Logo

/home/brennan/n-sim/OrbisQuartus/shared/daemon.c

Go to the documentation of this file.
00001 
00014 /*
00015  * Copyright 2007. Los Alamos National Security, LLC. This material
00016  * was produced under U.S. Government contract DE-AC52-06NA25396 for
00017  * Los Alamos National Laboratory (LANL), which is operated by Los
00018  * Alamos National Security, LLC, for the Department of Energy. The
00019  * U.S. Government has rights to use, reproduce, and distribute this
00020  * software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY,
00021  * LLC, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL
00022  * LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to
00023  * produce derivative works, such modified software should be clearly
00024  * marked, so as not to confuse it with the version available from LANL.
00025  *
00026  * Additionally, this program is free software; you can redistribute
00027  * it and/or modify it under the terms of the GNU General Public
00028  * License as published by the Free Software Foundation; version 2 of
00029  * the License. Accordingly, this program is distributed in the hope
00030  * it will be useful, but WITHOUT ANY WARRANTY; without even the
00031  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
00032  * PURPOSE. See the GNU General Public License for more details.
00033  */
00034 
00035 
00036 #include <stdio.h>
00037 #include "mutex.h"
00038 #include "daemon.h"
00039 
00041 #include <signal.h>
00042 #include <errno.h>
00043 
00044 
00045 volatile unsigned short __shutdown__;
00046 mutex_t stop_mutex;
00047 volatile unsigned short __quit__;
00048 mutex_t quit_mutex;
00049 
00050 
00051 #ifndef USING_L4
00052 void sigint_handler(int s) {
00053         __shutdown__ = 1;
00054         __quit__ = 1;
00055 }
00056 #endif
00057 
00058 int daemon_init(void)
00059 {
00060 #ifndef USING_L4
00061         struct sigaction sa;
00062 
00063         sa.sa_handler = sigint_handler;
00064         sigemptyset(&sa.sa_mask);
00065         sa.sa_flags = SA_RESTART;
00066 
00067         if (sigaction(SIGINT, &sa, NULL) == -1) {
00068                 perror("sigaction");
00069                 return errno;
00070         }
00071 #endif
00072 
00073         __shutdown__ = 0;
00074         mutex_init(&stop_mutex);
00075         __quit__ = 0;
00076         mutex_init(&quit_mutex);
00077 
00078         return 0;
00079 }
00080 
00081 int daemon_shuttingdown(void)
00082 {
00083         int down = 0;
00084         mutex_lock(&stop_mutex);
00085         down = __shutdown__;
00086         mutex_unlock(&stop_mutex);
00087         return down;
00088 }
00089 
00090 void daemon_shutdown(void)
00091 {
00092         mutex_lock(&stop_mutex);
00093         __shutdown__ = 1;
00094         mutex_unlock(&stop_mutex);
00095 }
00096 
00097 int daemon_quitting(void)
00098 {
00099         int down = 0;
00100         mutex_lock(&quit_mutex);
00101         down = __quit__;
00102         mutex_unlock(&quit_mutex);
00103         return down;
00104 }
00105 
00106 void daemon_quit(void)
00107 {
00108         mutex_lock(&quit_mutex);
00109         __quit__ = 1;
00110         mutex_unlock(&quit_mutex);
00111 }


© 2007, Los Alamos National Security, LLC.