utils.c
Go to the documentation of this file.
00001 /*******************************************************************************
00002 #                                                                              #
00003 #      MJPG-streamer allows to stream JPG frames from an input-plugin          #
00004 #      to several output plugins                                               #
00005 #                                                                              #
00006 #      Copyright (C) 2007 Tom Stöveken                                         #
00007 #                                                                              #
00008 # This program is free software; you can redistribute it and/or modify         #
00009 # it under the terms of the GNU General Public License as published by         #
00010 # the Free Software Foundation; version 2 of the License.                      #
00011 #                                                                              #
00012 # This program is distributed in the hope that it will be useful,              #
00013 # but WITHOUT ANY WARRANTY; without even the implied warranty of               #
00014 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                #
00015 # GNU General Public License for more details.                                 #
00016 #                                                                              #
00017 # You should have received a copy of the GNU General Public License            #
00018 # along with this program; if not, write to the Free Software                  #
00019 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA    #
00020 #                                                                              #
00021 *******************************************************************************/
00022 
00023 #include <stdio.h>
00024 #include <stdlib.h>
00025 #include <unistd.h>
00026 #include <linux/types.h>
00027 #include <string.h>
00028 #include <fcntl.h>
00029 #include <wait.h>
00030 #include <time.h>
00031 #include <limits.h>
00032 #include <linux/stat.h>
00033 #include <sys/stat.h>
00034 
00035 #include "utils.h"
00036 
00037 /******************************************************************************
00038 Description.:
00039 Input Value.:
00040 Return Value:
00041 ******************************************************************************/
00042 void daemon_mode(void)
00043 {
00044     int fr = 0;
00045 
00046     fr = fork();
00047     if(fr < 0) {
00048         fprintf(stderr, "fork() failed\n");
00049         exit(1);
00050     }
00051     if(fr > 0) {
00052         exit(0);
00053     }
00054 
00055     if(setsid() < 0) {
00056         fprintf(stderr, "setsid() failed\n");
00057         exit(1);
00058     }
00059 
00060     fr = fork();
00061     if(fr < 0) {
00062         fprintf(stderr, "fork() failed\n");
00063         exit(1);
00064     }
00065     if(fr > 0) {
00066         fprintf(stderr, "forked to background (%d)\n", fr);
00067         exit(0);
00068     }
00069 
00070     umask(0);
00071 
00072     fr = chdir("/");
00073     if(fr != 0) {
00074         fprintf(stderr, "chdir(/) failed\n");
00075         exit(0);
00076     }
00077 
00078     close(0);
00079     close(1);
00080     close(2);
00081 
00082     open("/dev/null", O_RDWR);
00083 
00084     fr = dup(0);
00085     fr = dup(0);
00086 }
00087 


corobot_pantilt
Author(s):
autogenerated on Wed Aug 26 2015 11:10:04