* Mathieu Desnoyers <mathieu.desnoyers@polymtl.ca>
*/
-#define _GNU_SOURCE
+#ifdef HAVE_CONFIG_H
#include <config.h>
+#endif
+
+#define _GNU_SOURCE
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
char path_trace[PATH_MAX];
int path_trace_len;
char *path_trace_ptr;
+ int open_ret = 0;
if(channel_dir == NULL) {
perror(subchannel_name);
- return ENOENT;
+ open_ret = ENOENT;
+ goto end;
}
printf("Creating trace subdirectory %s\n", subtrace_name);
ret = mkdir(subtrace_name, S_IRWXU|S_IRWXG|S_IRWXO);
if(ret == -1) {
- if(errno == EEXIST && append_mode) {
- printf("Appending to directory %s as resquested\n", subtrace_name);
- } else {
+ if(errno != EEXIST) {
perror(subtrace_name);
- return -1;
+ open_ret = -1;
+ goto end;
}
}
}
} else {
printf("File %s exists, cannot open. Try append mode.\n", path_trace);
- return -1;
+ open_ret = -1;
+ goto end;
}
} else {
if(errno == ENOENT) {
}
}
+end:
closedir(channel_dir);
- return 0;
+ return open_ret;
}
int main(int argc, char ** argv)
{
int ret;
- pid_t pid;
struct channel_trace_fd fd_pairs = { NULL, 0 };
struct sigaction act;
show_info();
if(daemon_mode) {
- pid = fork();
-
- if(pid > 0) {
- /* parent */
- return 0;
- } else if(pid < 0) {
- /* error */
- printf("An error occured while forking.\n");
- return -1;
- }
- /* else, we are the child, continue... */
- }
+ ret = daemon(0, 0);
+
+ if(ret == -1) {
+ perror("An error occured while daemonizing.");
+ exit(-1);
+ }
+ }
/* Connect the signal handlers */
act.sa_handler = handler;