forked from jirihnidek/daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jiri Hnidek
committed
Feb 27, 2015
1 parent
ec7c4d9
commit 76484ce
Showing
4 changed files
with
133 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
# Minimal version of CMake | ||
cmake_minimum_required (VERSION 2.6) | ||
|
||
# Build type | ||
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) | ||
message(STATUS "Setting build type to 'Debug' as none was specified.") | ||
set(CMAKE_BUILD_TYPE Debug CACHE STRING "Choose the type of build." FORCE) | ||
# Set the possible values of build type for cmake-gui | ||
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" | ||
"MinSizeRel" "RelWithDebInfo") | ||
endif () | ||
|
||
# Define project name | ||
project (Daemon) | ||
|
||
# The version number | ||
set (${PROJECT_NAME}_VERSION_MAJOR 0) | ||
set (${PROJECT_NAME}_VERSION_MINOR 1) | ||
set (${PROJECT_NAME}_PATCH_LEVEL 0) | ||
|
||
set (${PROJECT_NAME}_VERSION | ||
"${${PROJECT_NAME}_VERSION_MAJOR}.${${PROJECT_NAME}_VERSION_MINOR}") | ||
|
||
# Set up directory with 3rd party cmake modules | ||
set (CMAKE_MODULE_PATH | ||
${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/build_files/cmake/modules/") | ||
|
||
# Set output directory for binaries | ||
set (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin/) | ||
|
||
# Set up required subdirectories | ||
add_subdirectory (src) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
# daemon | ||
Simple example of daemon for linux | ||
# Example of Linux Daemon | ||
|
||
This repository contains simple example of daemon for Linux OS. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
set (daemon_src daemon.c) | ||
|
||
# Make build flags compiler specific | ||
if (CMAKE_COMPILER_IS_GNUCC) | ||
if (CMAKE_BUILD_TYPE STREQUAL "Debug") | ||
set (CMAKE_C_FLAGS "-D_REETRANT -ggdb -fPIC -Wall -Wextra -pedantic -O0") | ||
elseif( CMAKE_BUILD_TYPE STREQUAL "Release" ) | ||
set (CMAKE_C_FLAGS "-D_REETRANT -DNDEBUG -fPIC -Wall -Wextra -pedantic -O3") | ||
endif () | ||
endif (CMAKE_COMPILER_IS_GNUCC) | ||
|
||
add_executable (daemon ${daemon_src}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* | ||
* ***** BEGIN GPL LICENSE BLOCK ***** | ||
* | ||
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
* | ||
* ***** END GPL LICENSE BLOCK ***** | ||
* | ||
* Contributor(s): Jiri Hnidek <jiri.hnidek@tul.cz>. | ||
* | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <unistd.h> | ||
#include <syslog.h> | ||
#include <signal.h> | ||
#include <getopt.h> | ||
|
||
static int running = 0; | ||
static int delay = 1; | ||
static int counter = 0; | ||
|
||
/** | ||
* \brief Callback function for handling signals. | ||
* \param sig identifier of signal | ||
*/ | ||
void vs_handle_signal(int sig) | ||
{ | ||
if(sig == SIGINT) { | ||
running = 0; | ||
|
||
/* Reset signal handling to default behavior */ | ||
signal(SIGINT, SIG_DFL); | ||
} | ||
} | ||
|
||
int main(int argc, char *argv[]) | ||
{ | ||
static struct option long_options[] = { | ||
{"confile", required_argument, 0, 'c'}, | ||
{NULL, 0, 0, 0} | ||
}; | ||
int value, option_index = 0; | ||
|
||
while( (value = getopt_long(argc, argv, "c:", long_options, &option_index)) != -1) { | ||
switch(value) { | ||
case 'c': | ||
printf("option -c %s\n", optarg); | ||
break; | ||
case '?': | ||
break; | ||
default: | ||
break; | ||
} | ||
} | ||
|
||
running = 1; | ||
|
||
openlog(argv[0], LOG_PID|LOG_CONS, LOG_USER); | ||
signal(SIGINT, vs_handle_signal); | ||
|
||
syslog(LOG_INFO, "Started %s", argv[0]); | ||
while(running == 1) { | ||
fprintf(stdout, "Debug: %d\n", counter++); | ||
sleep(delay); | ||
} | ||
|
||
syslog(LOG_INFO, "Stoped %s", argv[0]); | ||
closelog(); | ||
|
||
return EXIT_SUCCESS; | ||
} |