[PATCH 1/2] Use O_CLOEXEC where adequate, simplify its use.
Ray Strode
halfline at gmail.com
Wed Nov 7 11:42:46 PST 2012
Hi,
Pushed, thanks!
--Ray
On Mon, Nov 5, 2012 at 9:07 PM, Cristian RodrÃguez
<crrodriguez at opensuse.org> wrote:
> ---
> configure.ac | 4 +--
> src/libply-splash-core/ply-text-progress-bar.c | 2 +-
> src/libply-splash-graphics/ply-image.c | 2 +-
> src/libply/ply-event-loop.c | 2 +-
> src/libply/ply-key-file.c | 2 +-
> src/libply/ply-logger.c | 2 +-
> src/libply/ply-progress.c | 4 +++
> src/libply/ply-utils.c | 33 +++----------------------
> src/plugins/splash/script/script-debug.c | 4 +++
> src/plugins/splash/script/script-execute.c | 6 ++++-
> src/plugins/splash/script/script-lib-image.c | 6 ++---
> src/plugins/splash/script/script-lib-math.c | 5 ++--
> src/plugins/splash/script/script-lib-plymouth.c | 6 ++---
> src/plugins/splash/script/script-lib-string.c | 6 ++---
> src/plugins/splash/script/script-object.c | 6 ++++-
> src/plugins/splash/script/script-parse.c | 6 ++++-
> src/plugins/splash/script/script-scan.c | 6 ++++-
> src/plugins/splash/script/script.c | 6 ++++-
> src/ply-boot-server.c | 2 +-
> src/viewer/plymouth-log-viewer.c | 4 +++
> 20 files changed, 60 insertions(+), 54 deletions(-)
>
> diff --git a/configure.ac b/configure.ac
> index 2ab0893..c20974e 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 bf4b378..ea92d49 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 3e09f68..be85809 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 3cfad76..4abf25f 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 a3d5a11..72264e1 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 f51bb84..5ea0b5e 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 2091a27..cf372cd 100644
> --- a/src/libply/ply-progress.c
> +++ b/src/libply/ply-progress.c
> @@ -22,6 +22,10 @@
> * Charlie Brej <cbrej at cs.man.ac.uk>
> */
>
> +#ifdef HAVE_CONFIG_H
> +#include "config.h"
> +#endif
> +
> #include <assert.h>
> #include <errno.h>
> #include <math.h>
> diff --git a/src/libply/ply-utils.c b/src/libply/ply-utils.c
> index 60d59d1..5a79bb4 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 355c2b2..118574b 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 <cbrej at cs.man.ac.uk>
> */
> +#ifdef HAVE_CONFIG_H
> +#include "config.h"
> +#endif
> +
> #include "ply-hashtable.h"
> #include <stdlib.h>
> #include <string.h>
> diff --git a/src/plugins/splash/script/script-execute.c b/src/plugins/splash/script/script-execute.c
> index 6abd3a6..c06959b 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 <cbrej at cs.man.ac.uk>
> */
> -#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 5be27fb..f08be31 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 <cbrej at cs.man.ac.uk>
> */
> -#define _GNU_SOURCE
> +
> +#include "config.h"
> +
> #include "ply-image.h"
> #include "ply-label.h"
> #include "ply-pixel-buffer.h"
> @@ -36,8 +38,6 @@
> #include <stdlib.h>
> #include <string.h>
>
> -#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 a1afc04..1a07b04 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 <cbrej at cs.man.ac.uk>
> */
> -#define _GNU_SOURCE
> +
> +#include "config.h"
> +
> #include "script.h"
> #include "script-parse.h"
> #include "script-execute.h"
> @@ -31,7 +33,6 @@
> #include <string.h>
> #include <math.h>
>
> -#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 5c648a6..7f143ae 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 <cbrej at cs.man.ac.uk>
> */
> -#define _GNU_SOURCE
> +
> +#include "config.h"
> +
> #include "ply-boot-splash-plugin.h"
> #include "ply-utils.h"
> #include "script.h"
> @@ -32,8 +34,6 @@
> #include <stdlib.h>
> #include <string.h>
>
> -#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 dbd63fe..0b836eb 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 <cbrej at cs.man.ac.uk>
> */
> -#define _GNU_SOURCE
> +
> +#include "config.h"
> +
> #include "script.h"
> #include "script-parse.h"
> #include "script-execute.h"
> @@ -31,8 +33,6 @@
> #include <stdlib.h>
> #include <string.h>
>
> -#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 465fef6..7c16c94 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 <cbrej at cs.man.ac.uk>
> */
> -#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 10eb667..4adf273 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 <cbrej at cs.man.ac.uk>
> */
> -#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 ead752f..3efef48 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 <cbrej at cs.man.ac.uk>
> */
> +#ifdef HAVE_CONFIG_H
> +#include "config.h"
> +#endif
> +
> #include <stdio.h>
> #include <stdlib.h>
> #include <fcntl.h>
> @@ -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 635a8b4..3290825 100644
> --- a/src/plugins/splash/script/script.c
> +++ b/src/plugins/splash/script/script.c
> @@ -19,7 +19,11 @@
> *
> * Written by: Charlie Brej <cbrej at cs.man.ac.uk>
> */
> -#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 f15ade7..2d2a5b8 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 c20e391..ca54e0f 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 <stdlib.h>
> #include <string.h>
> #include <sys/types.h>
> --
> 1.8.0
>
> _______________________________________________
> plymouth mailing list
> plymouth at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/plymouth
More information about the plymouth
mailing list