Simplify checkpoint_action allocation
* src/checkpoint.c: Include <flexmember.h>. (struct checkpoint_action): New member commandbuf. (checkpoint_action_tail): Now pointer to pointer, to simplify updating. All uses changed. (alloc_action): New arg quoted_string, to lessen number of separate allocations. All uses changed.
This commit is contained in:
@@ -19,10 +19,14 @@
|
|||||||
|
|
||||||
#include <system.h>
|
#include <system.h>
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
#include "wordsplit.h"
|
|
||||||
|
#include <wordsplit.h>
|
||||||
|
|
||||||
|
#include <flexmember.h>
|
||||||
|
#include <fprintftime.h>
|
||||||
|
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#include <termios.h>
|
#include <termios.h>
|
||||||
#include "fprintftime.h"
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
enum checkpoint_opcode
|
enum checkpoint_opcode
|
||||||
@@ -47,13 +51,15 @@ struct checkpoint_action
|
|||||||
char *command;
|
char *command;
|
||||||
int signal;
|
int signal;
|
||||||
} v;
|
} v;
|
||||||
|
char commandbuf[FLEXIBLE_ARRAY_MEMBER];
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Checkpointing counter */
|
/* Checkpointing counter */
|
||||||
static intmax_t checkpoint;
|
static intmax_t checkpoint;
|
||||||
|
|
||||||
/* List of checkpoint actions */
|
/* List of checkpoint actions */
|
||||||
static struct checkpoint_action *checkpoint_action, *checkpoint_action_tail;
|
static struct checkpoint_action *checkpoint_action,
|
||||||
|
**checkpoint_action_tail = &checkpoint_action;
|
||||||
|
|
||||||
/* State of the checkpoint system */
|
/* State of the checkpoint system */
|
||||||
enum {
|
enum {
|
||||||
@@ -66,37 +72,26 @@ static int checkpoint_state;
|
|||||||
static sigset_t sigs;
|
static sigset_t sigs;
|
||||||
|
|
||||||
static struct checkpoint_action *
|
static struct checkpoint_action *
|
||||||
alloc_action (enum checkpoint_opcode opcode)
|
alloc_action (enum checkpoint_opcode opcode, char const *quoted_string)
|
||||||
{
|
{
|
||||||
struct checkpoint_action *p = xzalloc (sizeof *p);
|
idx_t quoted_size = quoted_string ? strlen (quoted_string) + 1 : 0;
|
||||||
if (checkpoint_action_tail)
|
struct checkpoint_action *p = xmalloc (FLEXSIZEOF (struct checkpoint_action,
|
||||||
checkpoint_action_tail->next = p;
|
commandbuf, quoted_size));
|
||||||
else
|
*checkpoint_action_tail = p;
|
||||||
checkpoint_action = p;
|
checkpoint_action_tail = &p->next;
|
||||||
checkpoint_action_tail = p;
|
p->next = NULL;
|
||||||
p->opcode = opcode;
|
p->opcode = opcode;
|
||||||
return p;
|
if (quoted_string)
|
||||||
}
|
|
||||||
|
|
||||||
static char *
|
|
||||||
copy_string_unquote (const char *str)
|
|
||||||
{
|
|
||||||
idx_t len = strlen (str);
|
|
||||||
if ((*str == '"' || *str == '\'') && 1 < len && *str == str[len - 1])
|
|
||||||
{
|
{
|
||||||
str++;
|
p->v.command = memcpy (p->commandbuf, quoted_string, quoted_size);
|
||||||
len -= 2;
|
unquote_string (p->v.command);
|
||||||
}
|
}
|
||||||
char *output = ximemdup0 (str, len);
|
return p;
|
||||||
unquote_string (output);
|
|
||||||
return output;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
checkpoint_compile_action (const char *str)
|
checkpoint_compile_action (const char *str)
|
||||||
{
|
{
|
||||||
struct checkpoint_action *act;
|
|
||||||
|
|
||||||
if (checkpoint_state == CHKP_INIT)
|
if (checkpoint_state == CHKP_INIT)
|
||||||
{
|
{
|
||||||
sigemptyset (&sigs);
|
sigemptyset (&sigs);
|
||||||
@@ -104,42 +99,33 @@ checkpoint_compile_action (const char *str)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (strcmp (str, ".") == 0 || strcmp (str, "dot") == 0)
|
if (strcmp (str, ".") == 0 || strcmp (str, "dot") == 0)
|
||||||
alloc_action (cop_dot);
|
alloc_action (cop_dot, NULL);
|
||||||
else if (strcmp (str, "bell") == 0)
|
else if (strcmp (str, "bell") == 0)
|
||||||
alloc_action (cop_bell);
|
alloc_action (cop_bell, NULL);
|
||||||
else if (strcmp (str, "echo") == 0)
|
else if (strcmp (str, "echo") == 0)
|
||||||
alloc_action (cop_echo);
|
alloc_action (cop_echo, NULL)->v.command = NULL;
|
||||||
else if (strncmp (str, "echo=", 5) == 0)
|
else if (strncmp (str, "echo=", 5) == 0)
|
||||||
{
|
alloc_action (cop_echo, str + 5);
|
||||||
act = alloc_action (cop_echo);
|
|
||||||
act->v.command = copy_string_unquote (str + 5);
|
|
||||||
}
|
|
||||||
else if (strncmp (str, "exec=", 5) == 0)
|
else if (strncmp (str, "exec=", 5) == 0)
|
||||||
{
|
alloc_action (cop_exec, str + 5);
|
||||||
act = alloc_action (cop_exec);
|
|
||||||
act->v.command = copy_string_unquote (str + 5);
|
|
||||||
}
|
|
||||||
else if (strncmp (str, "ttyout=", 7) == 0)
|
else if (strncmp (str, "ttyout=", 7) == 0)
|
||||||
{
|
alloc_action (cop_ttyout, str + 7);
|
||||||
act = alloc_action (cop_ttyout);
|
|
||||||
act->v.command = copy_string_unquote (str + 7);
|
|
||||||
}
|
|
||||||
else if (strncmp (str, "sleep=", 6) == 0)
|
else if (strncmp (str, "sleep=", 6) == 0)
|
||||||
{
|
{
|
||||||
char const *arg = str + 6;
|
char const *arg = str + 6;
|
||||||
char *p;
|
char *p;
|
||||||
act = alloc_action (cop_sleep);
|
alloc_action (cop_sleep, NULL)->v.time
|
||||||
act->v.time = stoint (arg, &p, NULL, 0, TYPE_MAXIMUM (time_t));
|
= stoint (arg, &p, NULL, 0, TYPE_MAXIMUM (time_t));
|
||||||
if ((p == arg) | *p)
|
if ((p == arg) | *p)
|
||||||
paxfatal (0, _("%s: not a valid timeout"), str);
|
paxfatal (0, _("%s: not a valid timeout"), str);
|
||||||
}
|
}
|
||||||
else if (strcmp (str, "totals") == 0)
|
else if (strcmp (str, "totals") == 0)
|
||||||
alloc_action (cop_totals);
|
alloc_action (cop_totals, NULL);
|
||||||
else if (strncmp (str, "wait=", 5) == 0)
|
else if (strncmp (str, "wait=", 5) == 0)
|
||||||
{
|
{
|
||||||
act = alloc_action (cop_wait);
|
int sig = decode_signal (str + 5);
|
||||||
act->v.signal = decode_signal (str + 5);
|
alloc_action (cop_wait, NULL)->v.signal = sig;
|
||||||
sigaddset (&sigs, act->v.signal);
|
sigaddset (&sigs, sig);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
paxfatal (0, _("%s: unknown checkpoint action"), str);
|
paxfatal (0, _("%s: unknown checkpoint action"), str);
|
||||||
|
|||||||
Reference in New Issue
Block a user