Skip to content

Commit

Permalink
flux-exec: use zlistx_t over zlist_t
Browse files Browse the repository at this point in the history
Problem: In the near future additional code flux-exec will use the
zlistx_t data structure.  Some other code in flux-exec already uses
the zhashx_t data structure.  One lingering data structure still
uses the zlist_t data structure.

For consistency going forward, convert the lingering use of zlist_t
to zlistx_t.
  • Loading branch information
chu11 committed Nov 1, 2024
1 parent d9f61f4 commit f95b205
Showing 1 changed file with 18 additions and 19 deletions.
37 changes: 18 additions & 19 deletions src/cmd/flux-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int exit_code = 0;
zhashx_t *exitsets;
struct idset *hanging;

zlist_t *subprocesses;
zlistx_t *subprocesses;

optparse_t *opts = NULL;

Expand Down Expand Up @@ -232,22 +232,22 @@ static void stdin_cb (flux_reactor_t *r,
log_err_exit ("fbuf_read");

if (lenp) {
p = zlist_first (subprocesses);
p = zlistx_first (subprocesses);
while (p) {
if (flux_subprocess_state (p) == FLUX_SUBPROCESS_INIT
|| flux_subprocess_state (p) == FLUX_SUBPROCESS_RUNNING) {
if (flux_subprocess_write (p, "stdin", ptr, lenp) < 0)
log_err_exit ("flux_subprocess_write");
}
p = zlist_next (subprocesses);
p = zlistx_next (subprocesses);
}
}
else {
p = zlist_first (subprocesses);
p = zlistx_first (subprocesses);
while (p) {
if (flux_subprocess_close (p, "stdin") < 0)
log_err_exit ("flux_subprocess_close");
p = zlist_next (subprocesses);
p = zlistx_next (subprocesses);
}
flux_watcher_stop (stdin_w);
}
Expand Down Expand Up @@ -291,9 +291,9 @@ static flux_subprocess_t *imp_kill (flux_subprocess_t *p, int signum)
&ops);
}

static void killall (zlist_t *l, int signum)
static void killall (zlistx_t *l, int signum)
{
flux_subprocess_t *p = zlist_first (l);
flux_subprocess_t *p = zlistx_first (l);
while (p) {
if (flux_subprocess_state (p) == FLUX_SUBPROCESS_RUNNING) {
if (use_imp) {
Expand All @@ -316,7 +316,7 @@ static void killall (zlist_t *l, int signum)
flux_future_destroy (f);
}
}
p = zlist_next (l);
p = zlistx_next (l);
}
}

Expand Down Expand Up @@ -361,9 +361,9 @@ static void signal_cb (int signum)
}
}

void subprocess_destroy (void *arg)
void subprocess_destroy (void **arg)
{
flux_subprocess_t *p = arg;
flux_subprocess_t *p = *arg;
flux_subprocess_destroy (p);
}

Expand Down Expand Up @@ -704,8 +704,9 @@ int main (int argc, char *argv[])
free (nodeset);
}

if (!(subprocesses = zlist_new ()))
log_err_exit ("zlist_new");
if (!(subprocesses = zlistx_new ()))
log_err_exit ("zlistx_new");
zlistx_set_destructor (subprocesses, subprocess_destroy);

if (!(exitsets = zhashx_new ()))
log_err_exit ("zhashx_new()");
Expand All @@ -725,10 +726,8 @@ int main (int argc, char *argv[])
NULL,
NULL)))
log_err_exit ("flux_rexec");
if (zlist_append (subprocesses, p) < 0)
log_err_exit ("zlist_append");
if (!zlist_freefn (subprocesses, p, subprocess_destroy, true))
log_err_exit ("zlist_freefn");
if (!zlistx_add_end (subprocesses, p))
log_err_exit ("zlistx_add_end");
rank = idset_next (targets, rank);
}

Expand All @@ -739,11 +738,11 @@ int main (int argc, char *argv[])
*/
if (optparse_getopt (opts, "noinput", NULL) > 0) {
flux_subprocess_t *p;
p = zlist_first (subprocesses);
p = zlistx_first (subprocesses);
while (p) {
if (flux_subprocess_close (p, "stdin") < 0)
log_err_exit ("flux_subprocess_close");
p = zlist_next (subprocesses);
p = zlistx_next (subprocesses);
}
}
/* configure stdin watcher
Expand Down Expand Up @@ -800,7 +799,7 @@ int main (int argc, char *argv[])
log_fini ();

zhashx_destroy (&exitsets);
zlist_destroy (&subprocesses);
zlistx_destroy (&subprocesses);

return exit_code;
}
Expand Down

0 comments on commit f95b205

Please sign in to comment.