Skip to content
This repository has been archived by the owner on Oct 2, 2024. It is now read-only.

Commit

Permalink
basic suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
lucaudill committed Aug 21, 2023
1 parent 1a95531 commit 0a99a41
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
3 changes: 1 addition & 2 deletions bin/ch-run.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ extern void warnings_reprint(void);
const struct argp argp = { options, parse_opt, args_doc, usage };
extern char **environ; // see environ(7)
extern char *warnings;
extern const size_t warnings_size;


/** Main **/
Expand All @@ -126,7 +125,7 @@ int main(int argc, char *argv[])
int arg_next;
char ** c_argv;

// initialze “warnings” buffer
// initialize “warnings” buffer
warnings = mmap(NULL, warnings_size, PROT_READ | PROT_WRITE,
MAP_SHARED | MAP_ANONYMOUS, -1, 0);

Expand Down
24 changes: 10 additions & 14 deletions bin/ch_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,16 @@ char *host_tmp = NULL;
char *username = NULL;

/* List of warnings to be re-printed on exit. This is a buffer of shared memory
allocated by mmap(2), structured as a sequence of
null-terminated character strings. Warnings that do not fit in this buffer
will be lost, though we allocate enough memory that this is unlikely. See
“warnings_append()” for more details. */
allocated by mmap(2), structured as a sequence of null-terminated character
strings. Warnings that do not fit in this buffer will be lost, though we
allocate enough memory that this is unlikely. See “warnings_append()” for
more details. */
char *warnings;

/* Current byte offset from start of “warnings” buffer. This gives the address
where the next appended string will start. */
size_t warnings_offset = 0;

/* Size of “warnings” buffer, in bytes. We want this to be big enough that we
don’t need to worry about running out of room. */
const size_t warnings_size = 4096;


/** Function prototypes (private) **/

Expand Down Expand Up @@ -465,7 +461,8 @@ noreturn void msg_fatal(const char *file, int line, int errno_,
void msgv(enum log_level level, const char *file, int line, int errno_,
const char *fmt, va_list ap)
{
char *message = "";
char *message = NULL;
char *ap_msg = "";
if (level > verbose)
return;

Expand All @@ -487,7 +484,6 @@ void msgv(enum log_level level, const char *file, int line, int errno_,
if (fmt == NULL)
fmt = "please report this bug";

char *ap_msg = "";
T_ (1 <= vasprintf(&ap_msg, fmt, ap));
T_ (1 <= asprintf(&message, "%s%s", message, ap_msg));

Expand Down Expand Up @@ -667,10 +663,10 @@ void version(void)
fprintf(stderr, "%s\n", VERSION);
}

/* Append null-terminated string “str” to the memory buffer “offset” bytes away
from the address pointed to by “addr”. Buffer should be “size” bytes long.
Return the number of bytes written. If there isn’t enough room for the
string, do nothing and return zero. */
/* Append null-terminated string “str” to the memory buffer “offset” bytes after
from the address pointed to by “addr”. Buffer length is “size” bytes. Return
the number of bytes written. If there isn’t enough room for the string, do
nothing and return zero. */
size_t warnings_append(char *addr, char *str, size_t size, size_t offset)
{
size_t written = 0;
Expand Down
6 changes: 5 additions & 1 deletion bin/ch_misc.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@
and hopefully others support the following extension. */
#define noreturn __attribute__ ((noreturn))


/* Size of “warnings” buffer, in bytes. We want this to be big enough that we
don’t need to worry about running out of room. */
#define warnings_size 4096

/* Test some value, and if it's not what we expect, exit with a fatal error.
These are macros so we have access to the file and line number.
Expand Down Expand Up @@ -105,7 +110,6 @@ extern char *host_tmp;
extern char *username;
extern char *warnings;
extern size_t warnings_offset;
extern const size_t warnings_size;


/** Function prototypes **/
Expand Down
2 changes: 1 addition & 1 deletion lib/charliecloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class Download_Mode(enum.Enum):
log_fp = sys.stderr # File object to print logs to.
trace_fatal = False # Add abbreviated traceback to fatal error hint.

# Warnings to be re-printed when program exists
# Warnings to be re-printed when program exits
warnings = []

# True if the download cache is enabled.
Expand Down

0 comments on commit 0a99a41

Please sign in to comment.