Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 577285 Details for
Bug 664783
race condition in radvd pidfile creation
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
Upsteam patch ported to 1.6
radvd-1.6-Use-libdaemon-for-daemonization.patch (text/plain), 5.75 KB, created by
Petr Pisar
on 2012-04-13 09:52:40 UTC
(
hide
)
Description:
Upsteam patch ported to 1.6
Filename:
MIME Type:
Creator:
Petr Pisar
Created:
2012-04-13 09:52:40 UTC
Size:
5.75 KB
patch
obsolete
>From d207d9cd89ee15cdf3d3de8465e452a72998b2ca Mon Sep 17 00:00:00 2001 >From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com> >Date: Thu, 5 Apr 2012 15:24:22 +0200 >Subject: [PATCH] Use libdaemon for daemonization > >The libc daemon(3) function suffers from race bewtween exiting parent >and saving PID into a file. > >Using libdaemon library one can avoid this race and can simplify PID >file manipulation. > >The only difference against older implementation is, the PID file will >be inspected, created, and removed only if daemonization is requested. >--- > Makefile.am | 3 +- > README | 2 + > configure.in | 2 + > radvd.c | 92 ++++++++++++++++++++++++++++++++-------------------------- > 4 files changed, 57 insertions(+), 42 deletions(-) > >diff --git a/Makefile.am b/Makefile.am >index b39a934..45f5029 100644 >--- a/Makefile.am >+++ b/Makefile.am >@@ -29,7 +29,8 @@ sbin_PROGRAMS = radvd radvdump > > radvd_SOURCES = $(COMMON_SRC) radvd.c timer.c send.c process.c interface.c \ > device.c device-common.c privsep.c gram.y gram.h scanner.l >-radvd_LDADD = -lfl >+radvd_CPPFLAGS = @DAEMON_CFLAGS@ >+radvd_LDADD = -lfl @DAEMON_LIBS@ > EXTRA_radvd_SOURCES = device-linux.c device-bsd44.c privsep-linux.c privsep-bsd44.c > YFLAGS = -d > CFLAGS = @CFLAGS@ -Wall -Wpointer-arith -Wcast-qual -Wcast-align \ >diff --git a/README b/README >index 0867576..21a49a6 100644 >--- a/README >+++ b/README >@@ -3,6 +3,8 @@ $Id: README,v 1.9 2005/12/31 16:10:05 psavola Exp $ > Installation: > ============= > >+Install 'pkg-config' and 'libdaemon'. >+ > Run configure, e.g. > > ./configure --prefix=/usr/local --sysconfdir=/etc --mandir=/usr/share/man >diff --git a/configure.in b/configure.in >index 2ceccb3..f49bdb7 100644 >--- a/configure.in >+++ b/configure.in >@@ -104,6 +104,8 @@ AC_CHECK_LIB(c, inet_ntop,, > # prevent caching > unset ac_cv_lib_inet6_inet_ntop > >+PKG_CHECK_MODULES([DAEMON], libdaemon) >+ > dnl Checks for header files. > AC_HEADER_STDC > AC_CHECK_HEADERS(sys/time.h) >diff --git a/radvd.c b/radvd.c >index 6c8d37d..5af9c08 100644 >--- a/radvd.c >+++ b/radvd.c >@@ -18,6 +18,8 @@ > #include <includes.h> > #include <radvd.h> > #include <pathnames.h> >+#include <libdaemon/dfork.h> >+#include <libdaemon/dpid.h> > > struct Interface *IfaceList = NULL; > >@@ -45,6 +47,7 @@ struct option prog_opt[] = { > extern FILE *yyin; > > char *conf_file = NULL; >+char *pidfile = NULL; > char *pname; > int sock = -1; > >@@ -64,23 +67,23 @@ void usage(void); > int drop_root_privileges(const char *); > int readin_config(char *); > int check_conffile_perm(const char *, const char *); >+const char *get_pidfile(void); > > int > main(int argc, char *argv[]) > { > unsigned char msg[MSG_SIZE_RECV]; >- char pidstr[16]; >- ssize_t ret; > int c, log_method; >- char *logfile, *pidfile; >+ char *logfile; > sigset_t oset, nset; >- int facility, fd; >+ int facility; > char *username = NULL; > char *chrootdir = NULL; > int singleprocess = 0; > #ifdef HAVE_GETOPT_LONG > int opt_idx; > #endif >+ pid_t pid; > > pname = ((pname=strrchr(argv[0],'/')) != NULL)?pname+1:argv[0]; > >@@ -233,32 +236,6 @@ main(int argc, char *argv[]) > exit(1); > } > >- if ((fd = open(pidfile, O_RDONLY, 0)) > 0) >- { >- ret = read(fd, pidstr, sizeof(pidstr) - 1); >- if (ret < 0) >- { >- flog(LOG_ERR, "cannot read radvd pid file, terminating: %s", strerror(errno)); >- exit(1); >- } >- pidstr[ret] = '\0'; >- if (!kill((pid_t)atol(pidstr), 0)) >- { >- flog(LOG_ERR, "radvd already running, terminating."); >- exit(1); >- } >- close(fd); >- fd = open(pidfile, O_CREAT|O_TRUNC|O_WRONLY, 0644); >- } >- else /* FIXME: not atomic if pidfile is on an NFS mounted volume */ >- fd = open(pidfile, O_CREAT|O_EXCL|O_WRONLY, 0644); >- >- if (fd < 0) >- { >- flog(LOG_ERR, "cannot create radvd pid file, terminating: %s", strerror(errno)); >- exit(1); >- } >- > /* > * okay, config file is read in, socket and stuff is setup, so > * lets fork now... >@@ -266,9 +243,37 @@ main(int argc, char *argv[]) > > if (get_debuglevel() == 0) { > >- /* Detach from controlling terminal */ >- if (daemon(0, 0) < 0) >- perror("daemon"); >+ if (daemon_retval_init()) { >+ flog(LOG_ERR, "Could not initialize daemon IPC."); >+ exit(1); >+ } >+ >+ pid = daemon_fork(); >+ if (-1 == pid) { >+ flog(LOG_ERR, "Could not fork: %s", strerror(errno)); >+ daemon_retval_done(); >+ exit(1); >+ } >+ if (0 < pid) { >+ if (daemon_retval_wait(0)) { >+ flog(LOG_ERR, "Could not daemonize."); >+ exit(1); >+ } >+ exit(0); >+ } >+ >+ daemon_pid_file_proc = get_pidfile; >+ if (daemon_pid_file_is_running() >= 0) { >+ flog(LOG_ERR, "radvd already running, terminating."); >+ daemon_retval_send(1); >+ exit(1); >+ } >+ if (daemon_pid_file_create()) { >+ flog(LOG_ERR, "Cannot create radvd PID file, terminating: %s", >+ strerror(errno)); >+ daemon_retval_send(2); >+ exit(1); >+ } > > /* close old logfiles, including stderr */ > log_close(); >@@ -276,9 +281,13 @@ main(int argc, char *argv[]) > /* reopen logfiles, but don't log to stderr unless explicitly requested */ > if (log_method == L_STDERR_SYSLOG) > log_method = L_SYSLOG; >- if (log_open(log_method, pname, logfile, facility) < 0) >+ if (log_open(log_method, pname, logfile, facility) < 0) { >+ flog(LOG_ERR, "log_open() failed: %s", strerror(errno)); >+ daemon_retval_send(3); > exit(1); >+ } > >+ daemon_retval_send(0); > } > > /* >@@ -295,12 +304,6 @@ main(int argc, char *argv[]) > signal(SIGTERM, sigterm_handler); > signal(SIGINT, sigint_handler); > >- snprintf(pidstr, sizeof(pidstr), "%ld\n", (long)getpid()); >- >- write(fd, pidstr, strlen(pidstr)); >- >- close(fd); >- > config_interface(); > kickoff_adverts(); > >@@ -329,10 +332,17 @@ main(int argc, char *argv[]) > } > } > >- unlink(pidfile); >+ if (get_debuglevel() == 0) { >+ flog(LOG_INFO, "removing %s", pidfile); >+ unlink(pidfile); >+ } > exit(0); > } > >+const char *get_pidfile(void) { >+ return pidfile; >+} >+ > void > timer_handler(void *data) > { >-- >1.7.7.6 >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 664783
:
577068
| 577285