Skip to content

Commit

Permalink
struct instead of object
Browse files Browse the repository at this point in the history
  • Loading branch information
chu11 committed May 10, 2019
1 parent 6a85d5a commit 912cf6c
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 236 deletions.
7 changes: 0 additions & 7 deletions src/common/libsubprocess/Makefile.am
Expand Up @@ -17,8 +17,6 @@ noinst_LTLIBRARIES = \
libsubprocess_la_SOURCES = \
command.c \
command.h \
hooks.c \
hooks.h \
local.c \
local.h \
remote.c \
Expand All @@ -35,7 +33,6 @@ fluxcoreinclude_HEADERS = \

TESTS = \
test_cmd.t \
test_hooks.t \
test_subprocess.t

check_PROGRAMS = \
Expand All @@ -61,10 +58,6 @@ test_cmd_t_SOURCES = test/cmd.c
test_cmd_t_CPPFLAGS = $(test_cppflags)
test_cmd_t_LDADD = $(test_ldadd)

test_hooks_t_SOURCES = test/hooks.c
test_hooks_t_CPPFLAGS = $(test_cppflags)
test_hooks_t_LDADD = $(test_ldadd)

test_subprocess_t_SOURCES = test/subprocess.c
test_subprocess_t_CPPFLAGS = \
-DTEST_SUBPROCESS_DIR=\"$(top_builddir)/src/common/libsubprocess/\" \
Expand Down
72 changes: 0 additions & 72 deletions src/common/libsubprocess/hooks.c

This file was deleted.

23 changes: 0 additions & 23 deletions src/common/libsubprocess/hooks.h

This file was deleted.

26 changes: 12 additions & 14 deletions src/common/libsubprocess/local.c
Expand Up @@ -28,21 +28,9 @@
#include "subprocess.h"
#include "subprocess_private.h"
#include "command.h"
#include "hooks.h"
#include "local.h"
#include "util.h"

static void local_run_hooks (flux_subprocess_t *p,
flux_subprocess_hook_type_t type)
{
if (p->hooks && p->hooks->cbs[type]) {
/* always a chance caller may destroy subprocess in callback */
flux_subprocess_ref (p);
(*p->hooks->cbs[type]) (p, p->hooks->args[type]);
flux_subprocess_unref (p);
}
}

static void local_channel_flush (struct subprocess_channel *c)
{
/* This is a full channel with read and write, a close on the
Expand Down Expand Up @@ -528,7 +516,12 @@ static int local_child (flux_subprocess_t *p)
_exit (1);
}

local_run_hooks (p, FLUX_SUBPROCESS_HOOK_TYPE_PRE_EXEC);
if (p->hooks.pre_exec_cb) {
/* always a chance caller may destroy subprocess in callback */
flux_subprocess_ref (p);
(*p->hooks.pre_exec_cb) (p, p->hooks.pre_exec_arg);
flux_subprocess_unref (p);
}

if (p->flags & FLUX_SUBPROCESS_FLAGS_SETPGRP) {
if (setpgrp () < 0) {
Expand Down Expand Up @@ -627,7 +620,12 @@ static int local_fork (flux_subprocess_t *p)

p->state = FLUX_SUBPROCESS_STARTED;

local_run_hooks (p, FLUX_SUBPROCESS_HOOK_TYPE_POST_FORK);
if (p->hooks.post_fork_cb) {
/* always a chance caller may destroy subprocess in callback */
flux_subprocess_ref (p);
(*p->hooks.post_fork_cb) (p, p->hooks.post_fork_arg);
flux_subprocess_unref (p);
}

return (0);
}
Expand Down
8 changes: 2 additions & 6 deletions src/common/libsubprocess/subprocess.c
Expand Up @@ -125,8 +125,6 @@ static void subprocess_free (flux_subprocess_t *p)

close_pair_fds (p->sync_fds);

flux_subprocess_hooks_destroy (p->hooks);

flux_watcher_destroy (p->state_prep_w);
flux_watcher_destroy (p->state_idle_w);
flux_watcher_destroy (p->state_check_w);
Expand Down Expand Up @@ -182,10 +180,8 @@ static flux_subprocess_t * subprocess_create (flux_t *h,
if (ops)
p->ops = *ops;

if (hooks) {
if (!(p->hooks = flux_subprocess_hooks_copy (hooks)))
goto error;
}
if (hooks)
p->hooks = *hooks;

p->h = h;
p->reactor = r;
Expand Down
57 changes: 12 additions & 45 deletions src/common/libsubprocess/subprocess.h
Expand Up @@ -34,13 +34,6 @@ typedef struct flux_subprocess flux_subprocess_t;
/* flux_subprocess_server_t: Handler for a subprocess remote server */
typedef struct flux_subprocess_server flux_subprocess_server_t;

/*
* flux_subprocess_hooks_t: An object that stores callbacks to
* execute at pre-defined points. Hooks can only be executed on
* local processes.
*/
typedef struct flux_subprocess_hooks flux_subprocess_hooks_t;

/*
* Subprocess states, on changes, will lead to calls to
* on_state_change below.
Expand Down Expand Up @@ -77,14 +70,6 @@ enum {
FLUX_SUBPROCESS_FLAGS_SETPGRP = 2,
};

/*
* Subprocess hook points
*/
typedef enum {
FLUX_SUBPROCESS_HOOK_TYPE_PRE_EXEC,
FLUX_SUBPROCESS_HOOK_TYPE_POST_FORK,
} flux_subprocess_hook_type_t;

/*
* Typedefs for subprocess hooks and callbacks:
*
Expand Down Expand Up @@ -112,6 +97,18 @@ typedef struct {
flux_subprocess_output_f on_stderr; /* Read of stderr is ready */
} flux_subprocess_ops_t;

/*
* flux_subprocess_hooks_t: An object that stores callbacks to
* execute at pre-defined points. Hooks can only be executed on
* local processes.
*/
typedef struct {
flux_subprocess_hook_f pre_exec_cb;
void *pre_exec_arg;
flux_subprocess_hook_f post_fork_cb;
void *post_fork_arg;
} flux_subprocess_hooks_t;

/*
* General support:
*/
Expand Down Expand Up @@ -238,36 +235,6 @@ int flux_cmd_add_channel (flux_cmd_t *cmd, const char *name);
int flux_cmd_setopt (flux_cmd_t *cmd, const char *var, const char *val);
const char *flux_cmd_getopt (flux_cmd_t *cmd, const char *var);

/*
* Hooks:
*/

/*
* Create a subprocess hooks object, which can be passed to flux_exec() or
* flux_local_exec().
*/
flux_subprocess_hooks_t * flux_subprocess_hooks_create (void);

/*
* Create a copy of a flux_subprocess_hooks_t object.
*/
flux_subprocess_hooks_t * flux_subprocess_hooks_copy (
const flux_subprocess_hooks_t *hooks);

/*
* Destroy and free hooks object
*/
void flux_subprocess_hooks_destroy (flux_subprocess_hooks_t *hooks);

/*
* Add callback at hook location 'type'. Callbacks are called in the
* order they are added.
*/
int flux_subprocess_hooks_add (flux_subprocess_hooks_t *hooks,
flux_subprocess_hook_type_t type,
flux_subprocess_hook_f cb,
void *arg);

/*
* Subprocesses:
*/
Expand Down
2 changes: 1 addition & 1 deletion src/common/libsubprocess/subprocess_private.h
Expand Up @@ -97,7 +97,7 @@ struct flux_subprocess {
/* fds[0] is parent/user, fds[1] is child */
int sync_fds[2]; /* socketpair for fork/exec sync */
flux_watcher_t *child_w;
flux_subprocess_hooks_t *hooks;
flux_subprocess_hooks_t hooks;

/* remote */

Expand Down
68 changes: 0 additions & 68 deletions src/common/libsubprocess/test/hooks.c

This file was deleted.

0 comments on commit 912cf6c

Please sign in to comment.