Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[mms-engine] Use random temporary data directory by default. JB#50508
  • Loading branch information
monich committed Dec 18, 2020
1 parent 713d541 commit cb698c2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 12 deletions.
46 changes: 35 additions & 11 deletions mms-engine/main.c
Expand Up @@ -410,7 +410,7 @@ mms_app_parse_options(

char* root_dir_help = g_strdup_printf(
"Root directory for MMS files [%s]",
config->root_dir);
config->root_dir ? config->root_dir : "dynamic");
char* retry_secs_help = g_strdup_printf(
"Retry period in seconds [%d]",
config->retry_secs);
Expand Down Expand Up @@ -535,13 +535,11 @@ mms_app_parse_options(
if (!ok) {
fprintf(stderr, "%s\n", GERRMSG(error));
g_error_free(error);
*result = RET_ERR;
} else if (argc > 1) {
char* help = g_option_context_get_help(options, TRUE, NULL);
/* No arguments expected */
fprintf(stderr, "%s", help);
g_free(help);
*result = RET_ERR;
ok = FALSE;
} else if (log_modules) {
MMSLogModule** ptr = mms_app_log_modules;
Expand Down Expand Up @@ -587,19 +585,35 @@ mms_app_parse_options(
}
if (root_dir) {
g_free(opt->global.root_dir);
/* The directory will actually be created on demand */
config->root_dir = opt->global.root_dir = root_dir;
root_dir = NULL;
} else if (!config->root_dir) {
GError* error = NULL;

config->root_dir = opt->global.root_dir =
g_dir_make_tmp("mms-engine-XXXXXX", &error);
if (config->root_dir) {
GDEBUG("Created %s", config->root_dir);
} else {
GERR("%s", GERRMSG(error));
g_error_free(error);
}
}
if (keep_running) opt->flags |= MMS_ENGINE_FLAG_KEEP_RUNNING;
if (disable_dbus_log) opt->flags |= MMS_ENGINE_FLAG_DISABLE_DBUS_LOG;
if (session_bus) {
GDEBUG("Attaching to session bus");
opt->dbus.type = G_BUS_TYPE_SESSION;
if (config->root_dir) {
if (keep_running) opt->flags |= MMS_ENGINE_FLAG_KEEP_RUNNING;
if (disable_dbus_log) opt->flags |= MMS_ENGINE_FLAG_DISABLE_DBUS_LOG;
if (session_bus) {
GDEBUG("Attaching to session bus");
opt->dbus.type = G_BUS_TYPE_SESSION;
} else {
GDEBUG("Attaching to system bus");
opt->dbus.type = G_BUS_TYPE_SYSTEM;
}
*result = RET_OK;
} else {
GDEBUG("Attaching to system bus");
opt->dbus.type = G_BUS_TYPE_SYSTEM;
ok = FALSE;
}
*result = RET_OK;
}

g_option_context_free(options);
Expand Down Expand Up @@ -658,6 +672,16 @@ int main(int argc, char* argv[])
g_main_loop_unref(loop);
mms_engine_unref(engine);
}
if (!config->keep_temp_files &&
g_file_test(config->root_dir, G_FILE_TEST_IS_DIR)) {
/* The data directory must be empty if we don't keep files. */
if (rmdir(config->root_dir) == 0) {
GDEBUG("Deleted %s", config->root_dir);
} else {
GWARN("Failed to delete %s: %s", config->root_dir,
strerror(errno));
}
}
GINFO("Exiting");
}
if (gutil_log_func == gutil_log_syslog) {
Expand Down
2 changes: 1 addition & 1 deletion mms-lib/include/mms_settings.h
Expand Up @@ -34,7 +34,7 @@ typedef struct mms_config_copy {
char* root_dir; /* Allocated copy of root_dir */
} MMSConfigCopy;

#define MMS_CONFIG_DEFAULT_ROOT_DIR "/tmp/mms"
#define MMS_CONFIG_DEFAULT_ROOT_DIR NULL /* Dynamic */
#define MMS_CONFIG_DEFAULT_RETRY_SECS (15)
#define MMS_CONFIG_DEFAULT_NETWORK_IDLE_SECS (10)
#define MMS_CONFIG_DEFAULT_IDLE_SECS (30)
Expand Down

0 comments on commit cb698c2

Please sign in to comment.