1 diff --git a/src/spnavd.c b/src/spnavd.c
2 index 2d4eca6..a5227ed 100644
5 @@ -27,6 +27,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
6 #include <sys/select.h>
7 #include <sys/socket.h>
9 +#include <sys/types.h>
14 @@ -47,13 +49,39 @@ static void handle_events(fd_set *rset);
15 static void sig_handler(int s);
16 static char *fix_path(char *str);
18 -static char *cfgfile = DEF_CFGFILE;
19 +static char* config_path;
23 + if((buf = getenv("XDG_CONFIG_HOME"))) {
24 + if(config_path == NULL) {
25 + config_path = malloc(strlen(buf) + strlen("/spnavrc") + 1);
26 + if ( config_path != NULL) {
27 + sprintf(config_path, "%s/spnavrc", buf);
32 + if (!(buf = getenv("HOME"))) {
33 + struct passwd *pw = getpwuid(getuid());
36 + config_path = malloc(strlen(buf) + strlen("/.config/spnavrc") + 1);
37 + if ( config_path != NULL) {
38 + sprintf(config_path, "%s/.config/spnavrc", buf);
44 +static char *cfgfile = NULL;
45 static char *logfile = DEF_LOGFILE;
46 static char *pidpath = NULL;
48 int main(int argc, char **argv)
50 int i, pid, ret, become_daemon = 1;
51 + cfgfile = cfg_path();
53 for(i=1; i<argc; i++) {
54 if(argv[i][0] == '-') {
55 @@ -247,7 +275,7 @@ static void print_usage(const char *argv0)
56 printf("usage: %s [options]\n", argv0);
58 printf(" -d: do not daemonize\n");
59 - printf(" -c <file>: config file path (default: " DEF_CFGFILE ")\n");
60 + printf(" -c <file>: config file path (default: %s)\n", cfg_path());
61 printf(" -l <file>|syslog: log file path or log to syslog (default: " DEF_LOGFILE ")\n");
62 printf(" -v: verbose output\n");
63 printf(" -V,-version: print version number and exit\n");