Skip to content

Commit

Permalink
fixup! mock my_execvp
Browse files Browse the repository at this point in the history
Signed-off-by: Yury V. Zaytsev <[email protected]>
  • Loading branch information
zyv committed Aug 30, 2024
1 parent 791363f commit 94a2809
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 12 deletions.
10 changes: 9 additions & 1 deletion lib/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ typedef struct
mc_pipe_stream_t err;
} mc_pipe_t;

/* sighandler_t is GNU extension */
#ifndef HAVE_SIGHANDLER_T
typedef void (*sighandler_t) (int);
#endif

/*** structures declarations (and typedefs of structures)*****************************************/

/*** global variables defined in .c file *********************************************************/
Expand Down Expand Up @@ -200,9 +205,12 @@ const char *get_owner (uid_t uid);
/* Returns a copy of *s until a \n is found and is below top */
const char *extract_line (const char *s, const char *top);

/* Process spawning */
/* Mocks */
sighandler_t my_signal (int signum, sighandler_t handler) __attribute__((weak));
pid_t my_fork (void) __attribute__((weak));
int my_execvp (const char *file, char *const argv[]) __attribute__((weak));

/* Process spawning */
int my_system (int flags, const char *shell, const char *command);
int my_systeml (int flags, const char *shell, ...);
int my_systemv (const char *command, char *const argv[]);
Expand Down
19 changes: 15 additions & 4 deletions lib/utilunix.c
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,17 @@ my_exit (int status)
_exit (status);
}

/* --------------------------------------------------------------------------------------------- */
/**
* Wrapper for signal() system call.
*/

sighandler_t
my_signal (int signum, sighandler_t handler)
{
return signal (signum, handler);
}

/* --------------------------------------------------------------------------------------------- */
/**
* Wrapper for fork() system call.
Expand Down Expand Up @@ -452,10 +463,10 @@ my_systemv (const char *command, char *const argv[])
break;
case FORK_CHILD:
{
signal (SIGINT, SIG_DFL);
signal (SIGQUIT, SIG_DFL);
signal (SIGTSTP, SIG_DFL);
signal (SIGCHLD, SIG_DFL);
my_signal (SIGINT, SIG_DFL);
my_signal (SIGQUIT, SIG_DFL);
my_signal (SIGTSTP, SIG_DFL);
my_signal (SIGCHLD, SIG_DFL);

my_execvp (command, argv);
my_exit (127); /* Exec error */
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -499,7 +499,7 @@ main (int argc, char *argv[])
if (mc_global.tty.alternate_plus_minus)
numeric_keypad_mode ();

(void) signal (SIGCHLD, SIG_DFL); /* Disable the SIGCHLD handler */
(void) my_signal (SIGCHLD, SIG_DFL); /* Disable the SIGCHLD handler */

if (mc_global.tty.console_flag != '\0')
handle_console (CONSOLE_DONE);
Expand Down
7 changes: 1 addition & 6 deletions tests/lib/utilunix__my_system-common.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,6 @@

#include "lib/vfs/vfs.h"

/* sighandler_t is GNU extension */
#ifndef HAVE_SIGHANDLER_T
typedef void (*sighandler_t) (int);
#endif

/* --------------------------------------------------------------------------------------------- */

/* @CapturedValue */
Expand Down Expand Up @@ -133,7 +128,7 @@ static sighandler_t signal__return_value = NULL;

/* @Mock */
sighandler_t
signal (int signum, sighandler_t handler)
my_signal (int signum, sighandler_t handler)
{
int *tmp_signum;
sighandler_t *tmp_handler;
Expand Down

0 comments on commit 94a2809

Please sign in to comment.