From: Cristian Rodríguez Date: Tue, 6 Nov 2012 02:07:46 +0000 (-0300) Subject: Use O_CLOEXEC where adequate, simplify its use. X-Git-Tag: 0.9.0~114 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=91a1d438d4df63099bd2e954eddb64148c292eb8;p=thirdparty%2Fplymouth.git Use O_CLOEXEC where adequate, simplify its use. --- diff --git a/configure.ac b/configure.ac index 2ab0893b..c20974e2 100644 --- a/configure.ac +++ b/configure.ac @@ -6,7 +6,7 @@ AC_CONFIG_AUX_DIR(build-tools) AC_USE_SYSTEM_EXTENSIONS AC_SYS_LARGEFILE AC_PROG_AWK -AC_PROG_CC +AC_PROG_CC_STDC AM_PROG_CC_C_O AC_HEADER_STDC AC_C_CONST @@ -16,7 +16,7 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) AM_MAINTAINER_MODE([enable]) PKG_PROG_PKG_CONFIG -LT_INIT +LT_INIT([dlopen disable-static pic-only]) ## increment if the interface has additions, changes, removals. LT_CURRENT=3 diff --git a/src/libply-splash-core/ply-text-progress-bar.c b/src/libply-splash-core/ply-text-progress-bar.c index bf4b3781..ea92d49f 100644 --- a/src/libply-splash-core/ply-text-progress-bar.c +++ b/src/libply-splash-core/ply-text-progress-bar.c @@ -104,7 +104,7 @@ get_os_string (void) buf = NULL; - fd = open (RELEASE_FILE, O_RDONLY); + fd = open (RELEASE_FILE, O_RDONLY|O_CLOEXEC); if (fd == -1) goto out; diff --git a/src/libply-splash-graphics/ply-image.c b/src/libply-splash-graphics/ply-image.c index 3e09f68c..be858095 100644 --- a/src/libply-splash-graphics/ply-image.c +++ b/src/libply-splash-graphics/ply-image.c @@ -123,7 +123,7 @@ ply_image_load (ply_image_t *image) assert (image != NULL); - fp = fopen (image->filename, "r"); + fp = fopen (image->filename, "re"); if (fp == NULL) return false; diff --git a/src/libply/ply-event-loop.c b/src/libply/ply-event-loop.c index 3cfad764..4abf25fc 100644 --- a/src/libply/ply-event-loop.c +++ b/src/libply/ply-event-loop.c @@ -491,7 +491,7 @@ ply_event_loop_new (void) loop = calloc (1, sizeof (ply_event_loop_t)); - loop->epoll_fd = epoll_create (PLY_EVENT_LOOP_NUM_EVENT_HANDLERS); + loop->epoll_fd = epoll_create1(EPOLL_CLOEXEC); loop->wakeup_time = PLY_EVENT_LOOP_NO_TIMED_WAKEUP; assert (loop->epoll_fd >= 0); diff --git a/src/libply/ply-key-file.c b/src/libply/ply-key-file.c index a3d5a11c..72264e15 100644 --- a/src/libply/ply-key-file.c +++ b/src/libply/ply-key-file.c @@ -75,7 +75,7 @@ ply_key_file_open_file (ply_key_file_t *key_file) { assert (key_file != NULL); - key_file->fp = fopen (key_file->filename, "r"); + key_file->fp = fopen (key_file->filename, "re"); if (key_file->fp == NULL) { diff --git a/src/libply/ply-logger.c b/src/libply/ply-logger.c index f51bb847..5ea0b5eb 100644 --- a/src/libply/ply-logger.c +++ b/src/libply/ply-logger.c @@ -40,7 +40,7 @@ #include "ply-list.h" #ifndef PLY_LOGGER_OPEN_FLAGS -#define PLY_LOGGER_OPEN_FLAGS (O_WRONLY | O_TRUNC | O_CREAT | O_NOFOLLOW) +#define PLY_LOGGER_OPEN_FLAGS (O_WRONLY | O_TRUNC | O_CREAT | O_NOFOLLOW | O_CLOEXEC) #endif #ifndef PLY_LOGGER_MAX_INJECTION_SIZE diff --git a/src/libply/ply-progress.c b/src/libply/ply-progress.c index 2091a27e..cf372cdd 100644 --- a/src/libply/ply-progress.c +++ b/src/libply/ply-progress.c @@ -22,6 +22,10 @@ * Charlie Brej */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c index 60d59d16..5a79bb4d 100644 --- a/src/libply/ply-utils.c +++ b/src/libply/ply-utils.c @@ -87,27 +87,9 @@ ply_open_unidirectional_pipe (int *sender_fd, assert (sender_fd != NULL); assert (receiver_fd != NULL); - if (pipe (pipe_fds) < 0) + if (pipe2 (pipe_fds, O_CLOEXEC | O_NONBLOCK) < 0) return false; - if (fcntl (pipe_fds[0], F_SETFD, O_NONBLOCK | FD_CLOEXEC) < 0) - { - ply_save_errno (); - close (pipe_fds[0]); - close (pipe_fds[1]); - ply_restore_errno (); - return false; - } - - if (fcntl (pipe_fds[1], F_SETFD, O_NONBLOCK | FD_CLOEXEC) < 0) - { - ply_save_errno (); - close (pipe_fds[0]); - close (pipe_fds[1]); - ply_restore_errno (); - return false; - } - *sender_fd = pipe_fds[1]; *receiver_fd = pipe_fds[0]; @@ -120,20 +102,11 @@ ply_open_unix_socket (void) int fd; const int should_pass_credentials = true; - fd = socket (PF_UNIX, SOCK_STREAM, 0); + fd = socket (PF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0); if (fd < 0) return -1; - if (fcntl (fd, F_SETFD, O_NONBLOCK | FD_CLOEXEC) < 0) - { - ply_save_errno (); - close (fd); - ply_restore_errno (); - - return -1; - } - if (setsockopt (fd, SOL_SOCKET, SO_PASSCRED, &should_pass_credentials, sizeof (should_pass_credentials)) < 0) { @@ -971,7 +944,7 @@ ply_get_process_parent_pid (pid_t pid) asprintf (&path, "/proc/%ld/stat", (long) pid); ppid = 0; - fp = fopen (path, "r"); + fp = fopen (path, "re"); if (fp == NULL) { diff --git a/src/plugins/splash/script/script-debug.c b/src/plugins/splash/script/script-debug.c index 355c2b2a..118574b0 100644 --- a/src/plugins/splash/script/script-debug.c +++ b/src/plugins/splash/script/script-debug.c @@ -19,6 +19,10 @@ * * Written by: Charlie Brej */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "ply-hashtable.h" #include #include diff --git a/src/plugins/splash/script/script-execute.c b/src/plugins/splash/script/script-execute.c index 6abd3a68..c06959bb 100644 --- a/src/plugins/splash/script/script-execute.c +++ b/src/plugins/splash/script/script-execute.c @@ -19,7 +19,11 @@ * * Written by: Charlie Brej */ -#define _GNU_SOURCE + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "ply-hashtable.h" #include "ply-list.h" #include "ply-logger.h" diff --git a/src/plugins/splash/script/script-lib-image.c b/src/plugins/splash/script/script-lib-image.c index 5be27fbe..f08be313 100644 --- a/src/plugins/splash/script/script-lib-image.c +++ b/src/plugins/splash/script/script-lib-image.c @@ -19,7 +19,9 @@ * * Written by: Charlie Brej */ -#define _GNU_SOURCE + +#include "config.h" + #include "ply-image.h" #include "ply-label.h" #include "ply-pixel-buffer.h" @@ -36,8 +38,6 @@ #include #include -#include "config.h" - #include "script-lib-image.script.h" static void image_free (script_obj_t *obj) diff --git a/src/plugins/splash/script/script-lib-math.c b/src/plugins/splash/script/script-lib-math.c index a1afc041..1a07b048 100644 --- a/src/plugins/splash/script/script-lib-math.c +++ b/src/plugins/splash/script/script-lib-math.c @@ -19,7 +19,9 @@ * * Written by: Charlie Brej */ -#define _GNU_SOURCE + +#include "config.h" + #include "script.h" #include "script-parse.h" #include "script-execute.h" @@ -31,7 +33,6 @@ #include #include -#include "config.h" #include "script-lib-math.script.h" diff --git a/src/plugins/splash/script/script-lib-plymouth.c b/src/plugins/splash/script/script-lib-plymouth.c index 5c648a6f..7f143aed 100644 --- a/src/plugins/splash/script/script-lib-plymouth.c +++ b/src/plugins/splash/script/script-lib-plymouth.c @@ -19,7 +19,9 @@ * * Written by: Charlie Brej */ -#define _GNU_SOURCE + +#include "config.h" + #include "ply-boot-splash-plugin.h" #include "ply-utils.h" #include "script.h" @@ -32,8 +34,6 @@ #include #include -#include "config.h" - #include "script-lib-plymouth.script.h" static script_return_t plymouth_set_function (script_state_t *state, diff --git a/src/plugins/splash/script/script-lib-string.c b/src/plugins/splash/script/script-lib-string.c index dbd63fe7..0b836ebd 100644 --- a/src/plugins/splash/script/script-lib-string.c +++ b/src/plugins/splash/script/script-lib-string.c @@ -19,7 +19,9 @@ * * Written by: Charlie Brej */ -#define _GNU_SOURCE + +#include "config.h" + #include "script.h" #include "script-parse.h" #include "script-execute.h" @@ -31,8 +33,6 @@ #include #include -#include "config.h" - #include "script-lib-string.script.h" diff --git a/src/plugins/splash/script/script-object.c b/src/plugins/splash/script/script-object.c index 465fef62..7c16c94d 100644 --- a/src/plugins/splash/script/script-object.c +++ b/src/plugins/splash/script/script-object.c @@ -19,7 +19,11 @@ * * Written by: Charlie Brej */ -#define _GNU_SOURCE + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "ply-hashtable.h" #include "ply-list.h" #include "ply-bitarray.h" diff --git a/src/plugins/splash/script/script-parse.c b/src/plugins/splash/script/script-parse.c index 10eb667d..4adf2737 100644 --- a/src/plugins/splash/script/script-parse.c +++ b/src/plugins/splash/script/script-parse.c @@ -19,7 +19,11 @@ * * Written by: Charlie Brej */ -#define _GNU_SOURCE + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "ply-hashtable.h" #include "ply-list.h" #include "ply-bitarray.h" diff --git a/src/plugins/splash/script/script-scan.c b/src/plugins/splash/script/script-scan.c index ead752f1..3efef48a 100644 --- a/src/plugins/splash/script/script-scan.c +++ b/src/plugins/splash/script/script-scan.c @@ -19,6 +19,10 @@ * * Written by: Charlie Brej */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include @@ -61,7 +65,7 @@ static script_scan_t *script_scan_new (void) script_scan_t *script_scan_file (const char *filename) { - int fd = open (filename, O_RDONLY); + int fd = open (filename, O_RDONLY|O_CLOEXEC); if (fd < 0) return NULL; script_scan_t *scan = script_scan_new (); scan->name = strdup (filename); diff --git a/src/plugins/splash/script/script.c b/src/plugins/splash/script/script.c index 635a8b4a..32908259 100644 --- a/src/plugins/splash/script/script.c +++ b/src/plugins/splash/script/script.c @@ -19,7 +19,11 @@ * * Written by: Charlie Brej */ -#define _GNU_SOURCE + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "ply-hashtable.h" #include "ply-list.h" #include "ply-bitarray.h" diff --git a/src/ply-boot-server.c b/src/ply-boot-server.c index f15ade78..2d2a5b85 100644 --- a/src/ply-boot-server.c +++ b/src/ply-boot-server.c @@ -776,7 +776,7 @@ ply_boot_server_on_new_connection (ply_boot_server_t *server) assert (server != NULL); - fd = accept (server->socket_fd, NULL, NULL); + fd = accept4 (server->socket_fd, NULL, NULL, SOCK_CLOEXEC); if (fd < 0) return; diff --git a/src/viewer/plymouth-log-viewer.c b/src/viewer/plymouth-log-viewer.c index c20e3916..ca54e0f0 100644 --- a/src/viewer/plymouth-log-viewer.c +++ b/src/viewer/plymouth-log-viewer.c @@ -20,6 +20,10 @@ * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include