I can't get this to compile! I have no clue what I did wrong
Code:
Also, here is the makefile if it helps.
Code:
Edit: Here is the compilation error
Code:
Code:
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
using namespace std;
pid_t pid;
pid = fork(); //Clone to make a child process
if(pid < 0) //If our PID is less than 0, then something has gone wrong while forking
exit(EXIT_FAILURE);
if(pid > 0) //If out PID is greater than 0, then we're all good
exit(EXIT_SUCCESS);
/* If we have gotten this far we are in the child process now */
umask(0); //Set the usermask to 0
openlog(argv[0],LOG_NOWAIT|LOG_PID,LOG_USER); //Connect to the syslog server
syslog(LOG_NOTICE, "Successfully started skeletor backend.\n");
pid_t sid;
sid = setsid(); //Let's try and create our own process group
if (sid < 0) {
syslog(LOG_ERR, "Could not create process group.\n");
exit(EXIT_FAILURE);
}
if((chdir("/")) < 0){
syslog(LOG_ERR, "Could not change working directory to /\n");
exit(EXIT_FAILURE);
}
/* Close the standard file descriptors as not to waste memory and for safety */
close(STDIN_FILENO);
close(STDOUT_FILENO);
close(STDERR_FILENO);
/* Here is where the main loop of the daemon is. */
syslog(LOG_NOTICE, "Test 123! I am exiting now!\n");
Also, here is the makefile if it helps.
Code:
CC=gcc
CFLAGS=-I.
DEPS =
OBJ = main.o
EXE = skeletor
%.o: %.c $(DEPS)
$(CC) -c -o $(EXE) $< $(CFLAGS)
hellomake: $(OBJ)
gcc -o $@ $^ $(CFLAGS)
Edit: Here is the compilation error
Code:
g++ -c -o main.o main.cpp
main.cpp:8:1: error: ‘pid’ does not name a type
main.cpp:9:1: error: expected unqualified-id before ‘if’
main.cpp:11:1: error: expected unqualified-id before ‘if’
main.cpp:15:6: error: expected constructor, destructor, or type conversion before ‘(’ token
main.cpp:16:8: error: expected constructor, destructor, or type conversion before ‘(’ token
main.cpp:17:7: error: expected constructor, destructor, or type conversion before ‘(’ token
main.cpp:20:1: error: ‘sid’ does not name a type
main.cpp:21:1: error: expected unqualified-id before ‘if’
main.cpp:26:1: error: expected unqualified-id before ‘if’
main.cpp:32:6: error: expected constructor, destructor, or type conversion before ‘(’ token
main.cpp:33:6: error: expected constructor, destructor, or type conversion before ‘(’ token
main.cpp:34:6: error: expected constructor, destructor, or type conversion before ‘(’ token
main.cpp:37:7: error: expected constructor, destructor, or type conversion before ‘(’ token
make: *** [main.o] Error 1