From eca7e9588607797db52b9f1d935397c5dba46366 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Wed, 21 Nov 2018 01:44:16 +0000 Subject: [PATCH] Move kill_save_errno to a separate header file This function is going to be used outside strace.c, so make it globally available and move it to a separate header file. * strace.c (kill_save_errno): Add "inline" keyword, change return type from "void" to "int", move the function ... * kill_save_errno.h: ... to this new file. * Makefile.am (strace_SOURCES): Add it. --- Makefile.am | 1 + kill_save_errno.h | 44 ++++++++++++++++++++++++++++++++++++++++++++ strace.c | 10 +--------- 3 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 kill_save_errno.h diff --git a/Makefile.am b/Makefile.am index 350bc51a..3b678b7c 100644 --- a/Makefile.am +++ b/Makefile.am @@ -178,6 +178,7 @@ strace_SOURCES = \ kexec.c \ keyctl.c \ keyctl_kdf_params.h \ + kill_save_errno.h \ kvm.c \ largefile_wrappers.h \ ldt.c \ diff --git a/kill_save_errno.h b/kill_save_errno.h new file mode 100644 index 00000000..5b89ce96 --- /dev/null +++ b/kill_save_errno.h @@ -0,0 +1,44 @@ +/* + * Copyright (c) 2012-2018 The strace developers. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef STRACE_KILL_SAVE_ERRNO_H +#define STRACE_KILL_SAVE_ERRNO_H + +#include +#include +#include + +static inline int +kill_save_errno(pid_t pid, int sig) +{ + int saved_errno = errno; + int rc = kill(pid, sig); + errno = saved_errno; + return rc; +} + +#endif /* !STRACE_KILL_SAVE_ERRNO_H */ diff --git a/strace.c b/strace.c index 62142d86..c99cf63f 100644 --- a/strace.c +++ b/strace.c @@ -51,6 +51,7 @@ #endif #include +#include "kill_save_errno.h" #include "largefile_wrappers.h" #include "mmap_cache.h" #include "number_set.h" @@ -432,15 +433,6 @@ set_cloexec_flag(int fd) perror_msg_and_die("fcntl(%d, F_SETFD, %#x)", fd, newflags); } -static void -kill_save_errno(pid_t pid, int sig) -{ - int saved_errno = errno; - - (void) kill(pid, sig); - errno = saved_errno; -} - /* * When strace is setuid executable, we have to swap uids * before and after filesystem and process management operations. -- 2.50.1