forked from flux-framework/flux-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
output: split config out of main output plugin
- Loading branch information
Showing
5 changed files
with
208 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
/************************************************************\ | ||
* Copyright 2024 Lawrence Livermore National Security, LLC | ||
* (c.f. AUTHORS, NOTICE.LLNS, COPYING) | ||
* | ||
* This file is part of the Flux resource manager framework. | ||
* For details, see https://github.com/flux-framework. | ||
* | ||
* SPDX-License-Identifier: LGPL-3.0 | ||
\************************************************************/ | ||
|
||
#if HAVE_CONFIG_H | ||
#include <config.h> | ||
#endif | ||
|
||
/* Note: necessary for shell log functions | ||
*/ | ||
#define FLUX_SHELL_PLUGIN_NAME "output.config" | ||
|
||
#include <unistd.h> | ||
#include <sys/types.h> | ||
#include <sys/stat.h> | ||
#include <fcntl.h> | ||
#include <errno.h> | ||
|
||
#include <jansson.h> | ||
|
||
#include <flux/shell.h> | ||
|
||
#include "ccan/str/str.h" | ||
|
||
#include "output/conf.h" | ||
|
||
static int output_stream_getopts (flux_shell_t *shell, | ||
const char *name, | ||
struct output_stream *stream) | ||
{ | ||
const char *type = NULL; | ||
|
||
if (flux_shell_getopt_unpack (shell, | ||
"output", | ||
"{s?s s?{s?s s?s s?b s?{s?s}}}", | ||
"mode", &stream->mode, | ||
name, | ||
"type", &type, | ||
"path", &stream->template, | ||
"label", &stream->label, | ||
"buffer", | ||
"type", &stream->buffer_type) < 0) { | ||
shell_log_error ("failed to read %s output options", name); | ||
return -1; | ||
} | ||
if (type && streq (type, "kvs")) { | ||
stream->template = NULL; | ||
stream->type = FLUX_OUTPUT_TYPE_KVS; | ||
return 0; | ||
} | ||
if (stream->template) | ||
stream->type = FLUX_OUTPUT_TYPE_FILE; | ||
|
||
if (strcasecmp (stream->buffer_type, "none") == 0) | ||
stream->buffer_type = "none"; | ||
else if (strcasecmp (stream->buffer_type, "line") == 0) | ||
stream->buffer_type = "line"; | ||
else { | ||
shell_log_error ("invalid buffer type specified: %s", | ||
stream->buffer_type); | ||
stream->buffer_type = "line"; | ||
} | ||
return 0; | ||
} | ||
|
||
void output_config_destroy (struct output_config *conf) | ||
{ | ||
if (conf) { | ||
int saved_errno = errno; | ||
free (conf); | ||
errno = saved_errno; | ||
} | ||
} | ||
|
||
struct output_config *output_config_create (flux_shell_t *shell) | ||
{ | ||
struct output_config *conf; | ||
|
||
if (!(conf = calloc (1, sizeof (*conf)))) | ||
return NULL; | ||
|
||
conf->stdout.type = FLUX_OUTPUT_TYPE_KVS; | ||
conf->stdout.mode = "truncate"; | ||
conf->stdout.buffer_type = "line"; | ||
if (output_stream_getopts (shell, "stdout", &conf->stdout) < 0) | ||
goto error; | ||
|
||
/* stderr defaults except for buffer_type inherit from stdout: | ||
*/ | ||
conf->stderr = conf->stdout; | ||
conf->stderr.buffer_type = "none"; | ||
if (output_stream_getopts (shell, "stderr", &conf->stderr) < 0) | ||
goto error; | ||
|
||
return conf; | ||
error: | ||
output_config_destroy (conf); | ||
return NULL; | ||
} | ||
|
||
/* vi: ts=4 sw=4 expandtab | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/************************************************************\ | ||
* Copyright 2019 Lawrence Livermore National Security, LLC | ||
* (c.f. AUTHORS, NOTICE.LLNS, COPYING) | ||
* | ||
* This file is part of the Flux resource manager framework. | ||
* For details, see https://github.com/flux-framework. | ||
* | ||
* SPDX-License-Identifier: LGPL-3.0 | ||
\************************************************************/ | ||
|
||
#ifndef HAVE_SHELL_OUTPUT_CONFIG_H | ||
#define HAVE_SHELL_OUTPUT_CONFIG_H | ||
|
||
#include <flux/shell.h> | ||
|
||
#include "output/filehash.h" | ||
|
||
enum { | ||
FLUX_OUTPUT_TYPE_KVS = 0, | ||
FLUX_OUTPUT_TYPE_FILE = 1, | ||
}; | ||
|
||
struct output_stream { | ||
int type; | ||
const char *buffer_type; | ||
const char *template; | ||
const char *mode; | ||
bool label; | ||
struct file_entry *fp; | ||
}; | ||
|
||
struct output_config { | ||
struct output_stream stdout; | ||
struct output_stream stderr; | ||
}; | ||
|
||
struct output_config *output_config_create (flux_shell_t *shell); | ||
|
||
void output_config_destroy (struct output_config *conf); | ||
|
||
#endif /* !HAVE_SHELL_OUTPUT_CONFIG_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/************************************************************\ | ||
* Copyright 2024 Lawrence Livermore National Security, LLC | ||
* (c.f. AUTHORS, NOTICE.LLNS, COPYING) | ||
* | ||
* This file is part of the Flux resource manager framework. | ||
* For details, see https://github.com/flux-framework. | ||
* | ||
* SPDX-License-Identifier: LGPL-3.0 | ||
\************************************************************/ | ||
|
||
#ifndef SHELL_OUTPUT_H | ||
#define SHELL_OUTPUT_H | ||
|
||
#include <flux/shell.h> | ||
|
||
#include "output/conf.h" | ||
#include "output/filehash.h" | ||
#include "output/client.h" | ||
#include "output/kvs.h" | ||
|
||
struct shell_output { | ||
flux_shell_t *shell; | ||
int refcount; | ||
struct output_config *conf; | ||
struct output_client *client; | ||
struct kvs_output *kvs; | ||
struct idset *active_shells; | ||
struct filehash *files; | ||
}; | ||
|
||
#endif /* !SHELL_OUTPUT_H */ |