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 315593 Details for
Bug 460645
qdiskd isn't always closing file descriptors properly before forking
[?]
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]
Adds pthread_mutex_lock()ing around the opens and fork
qdisk-safe-fork.patch (text/plain), 3.95 KB, created by
Sean E. Millichamp
on 2008-09-02 20:21:15 UTC
(
hide
)
Description:
Adds pthread_mutex_lock()ing around the opens and fork
Filename:
MIME Type:
Creator:
Sean E. Millichamp
Created:
2008-09-02 20:21:15 UTC
Size:
3.95 KB
patch
obsolete
>diff -Nru cman-2.0.84-fixed/cman/qdisk/disk_util.c cman-2.0.84/cman/qdisk/disk_util.c >--- cman-2.0.84-fixed/cman/qdisk/disk_util.c 2008-04-15 16:15:23.000000000 -0400 >+++ cman-2.0.84/cman/qdisk/disk_util.c 2008-09-02 15:54:47.000000000 -0400 >@@ -35,6 +35,7 @@ > #include <unistd.h> > #include <sys/time.h> > #include <time.h> >+#include "util.h" > > > inline void >@@ -67,7 +68,7 @@ > struct timeval junk; > int rv; > >- fp = fopen("/proc/uptime","r"); >+ fp = safe_fopen("/proc/uptime","r"); > if (!fp) > return -1; > >diff -Nru cman-2.0.84-fixed/cman/qdisk/main.c cman-2.0.84/cman/qdisk/main.c >--- cman-2.0.84-fixed/cman/qdisk/main.c 2008-04-15 16:15:23.000000000 -0400 >+++ cman-2.0.84/cman/qdisk/main.c 2008-09-02 15:55:14.000000000 -0400 >@@ -42,6 +42,7 @@ > #include <signal.h> > #include <ccs.h> > #include "score.h" >+#include "util.h" > #include "clulog.h" > #if (!defined(LIBCMAN_VERSION) || \ > (defined(LIBCMAN_VERSION) && LIBCMAN_VERSION < 2)) >@@ -672,7 +673,7 @@ > if (strcmp(ctx->qc_status_file, "-") == 0) { > fp = stdout; > } else { >- fp = fopen(ctx->qc_status_file, "w+"); >+ fp = safe_fopen(ctx->qc_status_file, "w+"); > if (fp == NULL) > return; > need_close = 1; >diff -Nru cman-2.0.84-fixed/cman/qdisk/Makefile cman-2.0.84/cman/qdisk/Makefile >--- cman-2.0.84-fixed/cman/qdisk/Makefile 2008-04-15 16:15:23.000000000 -0400 >+++ cman-2.0.84/cman/qdisk/Makefile 2008-09-02 15:56:30.000000000 -0400 >@@ -28,10 +28,10 @@ > install ${TARGET} ${sbindir} > > qdiskd: disk.o crc32.o disk_util.o main.o score.o bitmap.o clulog.o \ >- gettid.o proc.o daemon_init.o ../lib/libcman.a >+ gettid.o proc.o daemon_init.o util.o ../lib/libcman.a > gcc -o $@ $^ -lpthread -L../lib -L${ccslibdir} -lccs > >-mkqdisk: disk.o crc32.o disk_util.o \ >+mkqdisk: disk.o crc32.o disk_util.o util.o \ > proc.o mkqdisk.o > gcc -o $@ $^ > >diff -Nru cman-2.0.84-fixed/cman/qdisk/score.c cman-2.0.84/cman/qdisk/score.c >--- cman-2.0.84-fixed/cman/qdisk/score.c 2008-04-15 16:15:23.000000000 -0400 >+++ cman-2.0.84/cman/qdisk/score.c 2008-09-02 15:54:06.000000000 -0400 >@@ -36,6 +36,7 @@ > #include <sys/mman.h> > #include "disk.h" > #include "score.h" >+#include "util.h" > > static pthread_mutex_t sc_lock = PTHREAD_MUTEX_INITIALIZER; > static int _score = 0, _maxscore = 0, _score_thread_running = 0; >@@ -113,7 +114,7 @@ > > h->nextrun = now + h->interval; > >- pid = fork(); >+ pid = safe_fork(); > if (pid < 0) > return -1; > >diff -Nru cman-2.0.84-fixed/cman/qdisk/util.c cman-2.0.84/cman/qdisk/util.c >--- cman-2.0.84-fixed/cman/qdisk/util.c 1969-12-31 19:00:00.000000000 -0500 >+++ cman-2.0.84/cman/qdisk/util.c 2008-09-02 16:03:45.000000000 -0400 >@@ -0,0 +1,44 @@ >+#include <fcntl.h> >+#include <pthread.h> >+#include <stdio.h> >+#include <unistd.h> >+#include "util.h" >+ >+static pthread_mutex_t safe_fd_lock; >+ >+FILE *safe_fopen(const char *path, const char *mode) { >+ FILE *fp; >+ int fd, ret; >+ pthread_mutex_lock(&safe_fd_lock); >+ fp = fopen(path, mode); >+ if (fp) { >+ /* Set close-on-exec bit */ >+ fd = fileno(fp); >+ if (fd < 0) { >+ fclose(fp); >+ return (FILE *)NULL; >+ } >+ ret = fcntl(fd, F_GETFD, 0); >+ if (ret < 0) { >+ fclose(fp); >+ pthread_mutex_unlock(&safe_fd_lock); >+ return (FILE *)NULL; >+ } >+ ret |= FD_CLOEXEC; >+ if (fcntl(fd, F_SETFD, ret) < 0) { >+ fclose(fp); >+ pthread_mutex_unlock(&safe_fd_lock); >+ return (FILE *)NULL; >+ } >+ } >+ pthread_mutex_unlock(&safe_fd_lock); >+ return fp; >+} >+ >+pid_t safe_fork(void) { >+ int ret; >+ pthread_mutex_lock(&safe_fd_lock); >+ ret = fork(); >+ pthread_mutex_unlock(&safe_fd_lock); >+ return ret; >+} >diff -Nru cman-2.0.84-fixed/cman/qdisk/util.h cman-2.0.84/cman/qdisk/util.h >--- cman-2.0.84-fixed/cman/qdisk/util.h 1969-12-31 19:00:00.000000000 -0500 >+++ cman-2.0.84/cman/qdisk/util.h 2008-09-02 15:56:57.000000000 -0400 >@@ -0,0 +1,10 @@ >+#ifndef _UTIL_H >+#define _UTIL_H >+ >+#include <stdio.h> >+#include <unistd.h> >+ >+FILE *safe_fopen(const char *path, const char *mode); >+pid_t safe_fork(void); >+ >+#endif
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 460645
:
315353
| 315593