static void get_database_dir(void)
{
if (!database_dir) {
- if (OPT_GIVEN(AFS_DATABASE_DIR))
- database_dir = para_strdup(OPT_STRING_VAL(AFS_DATABASE_DIR));
- else {
- const char *home = get_homedir();
- database_dir = make_message(
- "%s/.paraslash/afs_database-0.7", home);
- }
+ database_dir = OPT_GIVEN(AFS_DATABASE_DIR)?
+ para_strdup(OPT_STRING_VAL(AFS_DATABASE_DIR)) :
+ make_message("%s/afs_database-0.7", get_confdir());
}
PARA_INFO_LOG("afs_database dir %s\n", database_dir);
}
__noreturn static void interactive_session(void)
{
int ret;
- char *history_file;
struct sigaction act;
struct i9e_client_info ici = {
.fds = {0, 1, 2},
};
PARA_NOTICE_LOG("\n%s\n", version_text("audioc"));
- if (OPT_GIVEN(HISTORY_FILE))
- history_file = para_strdup(OPT_STRING_VAL(HISTORY_FILE));
- else {
- const char *home = get_homedir();
- history_file = make_message("%s/.paraslash/audioc.history",
- home);
- }
- ici.history_file = history_file;
-
+ ici.history_file = OPT_GIVEN(HISTORY_FILE)?
+ para_strdup(OPT_STRING_VAL(HISTORY_FILE)) :
+ make_message("%s/audioc.history", get_confdir());
act.sa_handler = i9e_signal_dispatch;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
i9e_close();
para_log = stderr_log;
out:
- free(history_file);
+ free(ici.history_file);
free(socket_name);
if (ret < 0)
PARA_ERROR_LOG("%s\n", para_strerror(-ret));
};
PARA_NOTICE_LOG("\n%s\n", version_text("client"));
- if (CLIENT_OPT_GIVEN(HISTORY_FILE, ct->lpr))
- ici.history_file = para_strdup(CLIENT_OPT_STRING_VAL(
- HISTORY_FILE, ct->lpr));
- else {
- const char *home = get_homedir();
- ici.history_file = make_message("%s/.paraslash/client.history",
- home);
- }
+ ici.history_file = CLIENT_OPT_GIVEN(HISTORY_FILE, ct->lpr)?
+ para_strdup(CLIENT_OPT_STRING_VAL(HISTORY_FILE, ct->lpr)) :
+ make_message("%s/client.history", get_confdir());
act.sa_handler = i9e_signal_dispatch;
sigemptyset(&act.sa_mask);
act.sa_flags = 0;
kf = para_strdup(CLIENT_OPT_STRING_VAL(KEY_FILE, lpr));
else {
struct stat statbuf;
- const char *home = get_homedir();
- kf = make_message("%s/.paraslash/key.%s", home, user);
+ const char *confdir = get_confdir();
+ kf = make_message("%s/key.%s", confdir, user);
if (stat(kf, &statbuf) != 0) { /* assume file does not exist */
free(kf);
- kf = make_message("%s/.ssh/id_rsa", home);
+ kf = make_message("%s/.ssh/id_rsa", confdir);
}
}
PARA_INFO_LOG("user: %s\n", user);
*/
__must_check __malloc static char *random_filename(void)
{
- char *result;
- const char *home = get_homedir();
-
srandom(clock_get_realtime(NULL)->tv_usec);
- result = make_message("%s/.paraslash/%08ld", home,
- para_random(99999999));
- return result;
+ return make_message("%s/%08ld", get_confdir(), para_random(99999999));
}
static int prepare_output_file(struct writer_node *wn)
struct lls_parse_result *old_lpr = *lpr, *cf_lpr, *merged_lpr;
const char *subcmd_name;
- if (path)
- cf = para_strdup(path);
- else {
- const char *home = get_homedir();
- cf = make_message("%s/.paraslash/%s", home, dflt);
- }
+ cf = path? para_strdup(path) : make_message("%s/%s",
+ get_confdir(), dflt);
ret = mmap_full_file(cf, O_RDONLY, &map, &sz, NULL);
if (ret < 0) {
if (ret == -E_EMPTY)
if (OPT_GIVEN(HISTORY_FILE))
history_file = para_strdup(OPT_STRING_VAL(HISTORY_FILE));
else {
- const char *home = get_homedir();
- char *dot_para = make_message("%s/.paraslash", home);
+ const char *confdir = get_confdir();
- ret = para_mkdir(dot_para);
+ ret = para_mkdir(confdir);
/* warn, but otherwise ignore mkdir error */
if (ret < 0)
- PARA_WARNING_LOG("Can not create %s: %s\n", dot_para,
+ PARA_WARNING_LOG("Can not create %s: %s\n", confdir,
para_strerror(-ret));
- history_file = make_message("%s/play.history", dot_para);
- free(dot_para);
+ history_file = make_message("%s/play.history", confdir);
}
ici.history_file = history_file;
ici.loglevel = loglevel;
daemon_set_flag(DF_LOG_TIMING);
daemon_set_priority(OPT_UINT32_VAL(PRIORITY));
if (!reload || getpid() != afs_pid) {
- char *user_list_file;
- if (OPT_GIVEN(USER_LIST))
- user_list_file = para_strdup(OPT_STRING_VAL(USER_LIST));
- else {
- const char *home = get_homedir();
- user_list_file = make_message("%s/.paraslash/server.users", home);
- }
+ char *user_list_file = OPT_GIVEN(USER_LIST)?
+ para_strdup(OPT_STRING_VAL(USER_LIST)) :
+ make_message("%s/server.users", get_confdir());
user_list_init(user_list_file);
free(user_list_file);
}
- return;
}
/*
}
/**
- * Investigate $HOME to get the home directory of the calling user.
+ * Return the expansion of $HOME/.paraslash.
*
- * \return A pointer to read-only memory that must not be freed by the caller.
- * If the environment variable HOME is unset or empty, the function prints an
- * error message and aborts.
+ * \return A pointer to memory that must not be freed by the caller. If the
+ * environment variable HOME is unset or empty, the function prints an error
+ * message and aborts.
*
* \sa getenv(3), getuid(2).
*/
-const char *get_homedir(void)
+const char *get_confdir(void)
{
- const char *home = getenv("HOME");
- if (home && *home)
- return home;
- PARA_EMERG_LOG("fatal: HOME is unset or empty");
- exit(EXIT_FAILURE);
+ static const char *dot_para;
+ const char *home;
+
+ if (dot_para)
+ return dot_para;
+ home = getenv("HOME");
+ if (!home || !*home) {
+ PARA_EMERG_LOG("fatal: HOME is unset or empty");
+ exit(EXIT_FAILURE);
+ }
+ dot_para = make_message("%s/.paraslash", home);
+ return dot_para;
}
/**
__must_check __malloc __printf_1_2 char *make_message(const char *fmt, ...);
__must_check __malloc char *para_strcat(char *a, const char *b);
__must_check __malloc char *para_logname(void);
-const char *get_homedir(void);
+const char *get_confdir(void);
__malloc char *para_hostname(void);
__printf_2_3 int para_printf(struct para_buffer *b, const char *fmt, ...);
int para_atoi64(const char *str, int64_t *result);
static void set_paths(const struct lls_parse_result *lpr)
{
- const char *home = get_homedir();
+ const char *confdir = get_confdir();
if (OPT_GIVEN(SRC_DATABASE_DIR, lpr))
src_db_dir = para_strdup(OPT_STRING_VAL(SRC_DATABASE_DIR,
lpr));
else
- src_db_dir = make_message(
- "%s/.paraslash/afs_database-0.4", home);
+ src_db_dir = make_message("%s/afs_database-0.4", confdir);
if (OPT_GIVEN(DST_DATABASE_DIR, lpr))
dst_db_dir = para_strdup(OPT_STRING_VAL(DST_DATABASE_DIR,
lpr));
else
- dst_db_dir = make_message(
- "%s/.paraslash/afs_database-0.7", home);
+ dst_db_dir = make_message("%s/afs_database-0.7", confdir);
src_aft_dir = make_message("%s/audio_files", src_db_dir);
dst_aft_dir = make_message("%s/audio-files", src_db_dir);
PARA_NOTICE_LOG("source aft dir: %s\n", src_aft_dir);