File: cron-conf.c

package info (click to toggle)
mpdcron 0.3%2Bgit20161228-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster
  • size: 1,304 kB
  • sloc: ansic: 12,825; ruby: 587; makefile: 178; sh: 95
file content (86 lines) | stat: -rw-r--r-- 2,311 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/* vim: set cino= fo=croql sw=8 ts=8 sts=0 noet cin fdm=syntax : */

/*
 * Copyright (c) 2009, 2010 Ali Polatel <alip@exherbo.org>
 *
 * This file is part of the mpdcron mpd client. mpdcron is free software;
 * you can redistribute it and/or modify it under the terms of the GNU General
 * Public License version 2, as published by the Free Software Foundation.
 *
 * mpdcron is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "cron-defs.h"

#include <stdlib.h>
#include <string.h>

#include <glib.h>
#include <libdaemon/dpid.h>

struct mpdcron_config conf;

const char *
conf_pid_file_proc(void)
{
	char *name;

	if (conf.pid_path)
		return conf.pid_path;
	name = g_strdup_printf("%s.pid", daemon_pid_file_ident);
	conf.pid_path = g_build_filename(conf.home_path, name, NULL);
	g_free(name);
	return conf.pid_path;
}

int
conf_init(void)
{
	memset(&conf, 0, sizeof(struct mpdcron_config));

	/* Get home directory */
	if (g_getenv(ENV_HOME_DIR))
		conf.home_path = g_strdup(g_getenv(ENV_HOME_DIR));
	else if (g_getenv("HOME"))
		conf.home_path = g_build_filename(g_getenv("HOME"), DOT_MPDCRON, NULL);
	else {
		g_critical("Neither "ENV_HOME_DIR" nor HOME is set, exiting!");
		return -1;
	}

	/* Set keyfile path */
	conf.conf_path = g_build_filename(conf.home_path, PACKAGE".conf", NULL);

#ifdef HAVE_GMODULE
	/* Set module path */
	conf.mod_path = g_build_filename(conf.home_path, DOT_MODULES, NULL);
#endif /* HAVE_GMODULE */

	/* Get Mpd host, port, password */
	if ((conf.hostname = g_getenv(ENV_MPD_HOST)) == NULL)
		conf.hostname = "localhost";
	if ((conf.port = g_getenv(ENV_MPD_PORT)) == NULL)
		conf.port = "6600";
	conf.password = g_getenv(ENV_MPD_PASSWORD);

	return 0;
}

void
conf_free(void)
{
	g_free(conf.home_path);
	g_free(conf.conf_path);
	g_free(conf.pid_path);
#ifdef HAVE_GMODULE
	g_free(conf.mod_path);
#endif /* HAVE_GMODULE */
	memset(&conf, 0, sizeof(struct mpdcron_config));
}