Skip to content

Commit

Permalink
SWPTP-1551: add run_dir_mode and state_dir_mode options
Browse files Browse the repository at this point in the history
  • Loading branch information
abower-amd committed Jan 31, 2025
1 parent 1233a63 commit 4df2fee
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/include/sfptpd_general_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
#define SFPTPD_DEFAULT_CONTROL_PATH SFPTPD_CONTROL_SOCKET_PATH
#define SFPTPD_DEFAULT_METRICS_PATH SFPTPD_METRICS_SOCKET_PATH
#define SFPTPD_DEFAULT_RUN_DIR SFPTPD_RUN_DIR
#define SFPTPD_DEFAULT_RUN_DIR_MODE 0770
#define SFPTPD_DEFAULT_STATE_DIR_MODE 0777
#define SFPTPD_DEFAULT_TRACE_LEVEL 0
#define SFPTPD_DEFAULT_SYNC_INTERVAL -4
#define SFPTPD_DEFAULT_CLOCK_CTRL (SFPTPD_CLOCK_CTRL_SLEW_AND_STEP)
Expand Down Expand Up @@ -248,6 +250,8 @@ typedef struct sfptpd_config_general {
char state_path[PATH_MAX];
char control_path[PATH_MAX];
char metrics_path[PATH_MAX];
mode_t run_dir_mode;
mode_t state_dir_mode;
sfptpd_config_timestamping_t timestamping;
long double convergence_threshold;
long double step_threshold;
Expand Down
36 changes: 35 additions & 1 deletion src/sfptpd_general_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ static int parse_metrics_path(struct sfptpd_config_section *section, const char
unsigned int num_params, const char * const params[]);
static int parse_run_dir(struct sfptpd_config_section *section, const char *option,
unsigned int num_params, const char * const params[]);
static int parse_access_mode(struct sfptpd_config_section *section, const char *option,
unsigned int num_params, const char * const params[]);
static int parse_sync_interval(struct sfptpd_config_section *section, const char *option,
unsigned int num_params, const char * const params[]);
static int parse_sync_threshold(struct sfptpd_config_section *section, const char *option,
Expand Down Expand Up @@ -217,6 +219,16 @@ static const sfptpd_config_option_t config_general_options[] =
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_run_dir,
.dfl = SFPTPD_CONFIG_DFL_STR(SFPTPD_DEFAULT_RUN_DIR)},
{"run_dir_mode", "MODE",
"Specifies MODE with which to create run directory, subject to umask",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_access_mode,
.dfl = SFPTPD_CONFIG_DFL(SFPTPD_DEFAULT_RUN_DIR_MODE)},
{"state_dir_mode", "MODE",
"Specifies MODE with which to create state directory, subject to umask",
1, SFPTPD_CONFIG_SCOPE_GLOBAL,
parse_access_mode,
.dfl = SFPTPD_CONFIG_DFL(SFPTPD_DEFAULT_STATE_DIR_MODE)},
{"sync_interval", "NUMBER",
"Specifies the interval in 2^NUMBER seconds at which the clocks "
"are synchronized to the local reference clock, where NUMBER is "
Expand Down Expand Up @@ -942,6 +954,27 @@ static int parse_run_dir(struct sfptpd_config_section *section, const char *opti
return 0;
}

static int parse_access_mode(struct sfptpd_config_section *section, const char *option,
unsigned int num_params, const char * const params[])
{
sfptpd_config_general_t *general = (sfptpd_config_general_t *)section;
assert(num_params == 1);
int tokens;
int mode;

tokens = sscanf(params[0], "%o", &mode);
if (tokens != 1)
return EINVAL;

if (!strcmp(option, "state_dir_mode"))
general->state_dir_mode = mode;
else if (!strcmp(option, "run_dir_mode"))
general->run_dir_mode = mode;
else
return EINVAL;

return 0;
}

static int parse_sync_interval(struct sfptpd_config_section *section, const char *option,
unsigned int num_params, const char * const params[])
Expand Down Expand Up @@ -1456,7 +1489,6 @@ static int parse_trace_level(struct sfptpd_config_section *section, const char *
return 0;
}


static int parse_test_mode(struct sfptpd_config_section *section, const char *option,
unsigned int num_params, const char * const params[])
{
Expand Down Expand Up @@ -1880,6 +1912,8 @@ static struct sfptpd_config_section *general_config_create(const char *name,
sfptpd_strncpy(new->control_path, SFPTPD_DEFAULT_CONTROL_PATH, sizeof(new->control_path));
sfptpd_strncpy(new->metrics_path, SFPTPD_DEFAULT_METRICS_PATH, sizeof(new->metrics_path));
sfptpd_strncpy(new->run_dir, SFPTPD_RUN_DIR, sizeof(new->run_dir));
new->state_dir_mode = SFPTPD_DEFAULT_STATE_DIR_MODE;
new->run_dir_mode = SFPTPD_DEFAULT_RUN_DIR_MODE;

new->clocks.sync_interval = SFPTPD_DEFAULT_SYNC_INTERVAL;
new->clocks.control = SFPTPD_DEFAULT_CLOCK_CTRL;
Expand Down
2 changes: 1 addition & 1 deletion src/sfptpd_logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -441,7 +441,7 @@ int sfptpd_log_open(struct sfptpd_config *config)
}

/* Make sure that the directory for saved clock state exists */
rc_dircreate = (mkdir(state_path, 0777) < 0) ? errno : 0;
rc_dircreate = (mkdir(state_path, general_config->state_dir_mode) < 0) ? errno : 0;
if (chown(state_path, general_config->uid, general_config->gid))
TRACE_L4("could not set state directory ownership, %s\n",
strerror(errno));
Expand Down
2 changes: 1 addition & 1 deletion src/sfptpd_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ static int rundir_create(struct sfptpd_config *config)
if (path[0] == '\0')
return 0;

rc = mkdir(path, 0750);
rc = mkdir(path, gconf->run_dir_mode);
if (rc == -1) {
rc = errno;
if (rc != EEXIST) {
Expand Down

0 comments on commit 4df2fee

Please sign in to comment.