From: John L. <mov...@us...> - 2003-08-08 01:43:23
|
Update of /cvsroot/oprofile/oprofile/daemon In directory sc8-pr-cvs1:/tmp/cvs-serv20015/daemon Modified Files: opd_util.c opd_util.h oprofiled.c Log Message: share opd_write_abi() Index: opd_util.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/daemon/opd_util.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -p -d -r1.1 -r1.2 --- opd_util.c 8 Aug 2003 01:35:00 -0000 1.1 +++ opd_util.c 8 Aug 2003 01:43:20 -0000 1.2 @@ -59,15 +59,6 @@ static void opd_fork(void) } -/** - * 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. - */ void opd_go_daemon(void) { opd_fork(); @@ -84,4 +75,18 @@ void opd_go_daemon(void) } opd_fork(); +} + + +void opd_write_abi(void) +{ +#ifdef OPROF_ABI + char * cbuf; + + cbuf = xmalloc(strlen(OP_BASE_DIR) + 5); + strcpy(cbuf, OP_BASE_DIR); + strcat(cbuf, "/abi"); + op_write_abi_to_file(cbuf); + free(cbuf); +#endif } Index: opd_util.h =================================================================== RCS file: /cvsroot/oprofile/oprofile/daemon/opd_util.h,v retrieving revision 1.1 retrieving revision 1.2 diff -u -p -d -r1.1 -r1.2 --- opd_util.h 8 Aug 2003 01:35:01 -0000 1.1 +++ opd_util.h 8 Aug 2003 01:43:20 -0000 1.2 @@ -33,4 +33,10 @@ void opd_open_logfile(void); */ void opd_go_daemon(void); + +/** + * opd_write_abi - write out the ABI description if needed + */ +void opd_write_abi(void); + #endif /* OPD_UTIL_H */ Index: oprofiled.c =================================================================== RCS file: /cvsroot/oprofile/oprofile/daemon/oprofiled.c,v retrieving revision 1.36 retrieving revision 1.37 diff -u -p -d -r1.36 -r1.37 --- oprofiled.c 8 Aug 2003 01:22:36 -0000 1.36 +++ oprofiled.c 8 Aug 2003 01:43:20 -0000 1.37 @@ -16,6 +16,7 @@ #include "opd_image.h" #include "opd_kernel.h" #include "opd_printf.h" +#include "opd_util.h" #include "op_version.h" #include "op_popt.h" @@ -74,7 +75,6 @@ static sigset_t maskset; static fd_t devfd; static void opd_sighup(int val); -static void opd_open_logfile(void); static struct poptOption options[] = { { "mount", 'm', POPT_ARG_STRING, &mount, 0, "path to mounted oprofilefs", "dir" }, @@ -93,28 +93,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); - } -} - - -/** * opd_open_files - open necessary files * * Open the device files and the log file, @@ -273,57 +251,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(); -} - - /** Done writing out the samples, indicate with complete_dump file */ static void complete_dump() { @@ -472,20 +399,6 @@ static void setup_signals(void) } -static void write_abi(void) -{ -#ifdef OPROF_ABI - char * cbuf; - - cbuf = xmalloc(strlen(OP_BASE_DIR) + 5); - strcpy(cbuf, OP_BASE_DIR); - strcat(cbuf, "/abi"); - op_write_abi_to_file(cbuf); - free(cbuf); -#endif -} - - static size_t opd_pointer_size(void) { size_t size; @@ -542,7 +455,7 @@ int main(int argc, char const * argv[]) opd_init_kernel_image(); opd_reread_module_info(); - write_abi(); + opd_write_abi(); if (atexit(clean_exit)) { fprintf(stderr, "Couldn't set exit cleanup !\n"); |