From: John L. <mov...@us...> - 2003-08-08 01:35:03
|
Update of /cvsroot/oprofile/oprofile/dae In directory sc8-pr-cvs1:/tmp/cvs-serv18529/dae Modified Files: Makefile.am oprofiled.c Log Message: share some daemon code Index: Makefile.am =================================================================== RCS file: /cvsroot/oprofile/oprofile/dae/Makefile.am,v retrieving revision 1.12 retrieving revision 1.13 diff -u -p -d -r1.12 -r1.13 --- Makefile.am 8 Aug 2003 01:16:47 -0000 1.12 +++ Makefile.am 8 Aug 2003 01:35:00 -0000 1.13 @@ -37,12 +37,14 @@ oprofiled_SOURCES = $(dist_sources) if enable_abi oprofiled_LDADD = \ ../libabi/libabi.a \ + ../daemon/libdaemon.a \ ../libdb/libodb.a \ ../libop/libop.a \ ../libutil/libutil.a LINKER=$(CXX) else oprofiled_LDADD = \ + ../daemon/libdaemon.a \ ../libdb/libodb.a \ ../libop/libop.a \ ../libutil/libutil.a Index: oprofiled.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/dae/oprofiled.c,v retrieving revision 1.124 retrieving revision 1.125 diff -u -p -d -r1.124 -r1.125 --- oprofiled.c 8 Aug 2003 01:22:36 -0000 1.124 +++ oprofiled.c 8 Aug 2003 01:35:00 -0000 1.125 @@ -19,6 +19,7 @@ #include "opd_parse_proc.h" #include "opd_kernel.h" #include "opd_printf.h" +#include "opd_util.h" #include "op_version.h" #include "op_popt.h" @@ -79,7 +80,6 @@ static fd_t devfd; static fd_t notedevfd; static void opd_sighup(int val); -static void opd_open_logfile(void); static struct poptOption options[] = { { "pid-filter", 0, POPT_ARG_INT, &pid_filter, 0, "only profile the given process ID", "pid" }, @@ -97,28 +97,6 @@ static struct poptOption options[] = { /** - * opd_open_logfile - open the log file - * - * Open the logfile on stdout and stderr. This function - * assumes that 1 and 2 are the lowest close()d file - * descriptors. Failure to open on either descriptor is - * a fatal error. - */ -static void opd_open_logfile(void) -{ - if (open(OP_LOG_FILE, O_WRONLY|O_CREAT|O_NOCTTY|O_APPEND, 0755) == -1) { - perror("oprofiled: couldn't re-open stdout: "); - exit(EXIT_FAILURE); - } - - if (dup2(1, 2) == -1) { - perror("oprofiled: couldn't dup stdout to stderr: "); - exit(EXIT_FAILURE); - } -} - - -/** * op_open_files - open necessary files * * Open the device files and the log file, @@ -317,56 +295,6 @@ static void opd_options(int argc, char c } -/** - * opd_fork - fork and return as child - * - * fork() and exit the parent with _exit(). - * Failure is fatal. - */ -static void opd_fork(void) -{ - switch (fork()) { - case -1: - perror("oprofiled: fork() failed: "); - exit(EXIT_FAILURE); - break; - case 0: - break; - default: - /* parent */ - _exit(EXIT_SUCCESS); - break; - } -} - - -/** - * opd_go_daemon - become daemon process - * - * Become an un-attached daemon in the standard - * way (fork(),chdir(),setsid(),fork()). - * Parents perform _exit(). - * - * Any failure is fatal. - */ -static void opd_go_daemon(void) -{ - opd_fork(); - - if (chdir(OP_BASE_DIR)) { - fprintf(stderr,"oprofiled: opd_go_daemon: couldn't chdir to " - OP_BASE_DIR ": %s", strerror(errno)); - exit(EXIT_FAILURE); - } - - if (setsid() < 0) { - perror("oprofiled: opd_go_daemon: couldn't setsid: "); - exit(EXIT_FAILURE); - } - - opd_fork(); -} - static void opd_do_samples(struct op_buffer_head const * buf); static void opd_do_notes(struct op_note const * opd_buf, size_t count); |