xsel

Program for manipulating the X clipboard
git clone https://git.sinitax.com/kfish/xsel
Log | Files | Refs | README | LICENSE | sfeed.txt

commit 7c07370d643696de3b354f11fe2e56131c1f2cb5
parent 9674445d8ea9f60f4d1a154be6fdb12e7af8f0c6
Author: valeth <patrick.auernig@gmail.com>
Date:   Sat, 21 Nov 2015 12:20:04 +0100

change get_homedir to get_xdg_cache_home
don't write logfiles into the users home directory
thats just rude :)

Diffstat:
Mxsel.c | 45+++++++++++----------------------------------
1 file changed, 11 insertions(+), 34 deletions(-)

diff --git a/xsel.c b/xsel.c @@ -340,38 +340,15 @@ _xs_strncpy (char * dest, const char * src, size_t n) * Get the user's home directory. */ static char * -get_homedir (void) +get_xdg_cache_home (void) { - uid_t uid; - char * username, * homedir; - struct passwd * pw; + char * cachedir; - if ((homedir = getenv ("HOME")) != NULL) { - return homedir; - } - - /* else ... go hunting for it */ - uid = getuid (); - - username = getenv ("LOGNAME"); - if (!username) username = getenv ("USER"); - - if (username) { - pw = getpwnam (username); - if (pw && pw->pw_uid == uid) goto gotpw; - } - - pw = getpwuid (uid); - -gotpw: - - if (!pw) { - exit_err ("error retrieving passwd entry"); + if ((cachedir = getenv ("XDG_CACHE_HOME")) != NULL) { + return cachedir; + } else { + return strcat(getenv ("HOME"), "/.cache") } - - homedir = _xs_strdup (pw->pw_dir); - - return homedir; } /* @@ -459,7 +436,7 @@ become_daemon (void) { pid_t pid; int null_r_fd, null_w_fd, log_fd; - char * homedir; + char * cachedir; if (no_daemon) { /* If the user has specified a timeout, enforce it even if we don't @@ -468,14 +445,14 @@ become_daemon (void) return; } - homedir = get_homedir (); + cachedir = get_xdg_cache_home(); /* Check that we can open a logfile before continuing */ /* If the user has specified a --logfile, use that ... */ if (logfile[0] == '\0') { /* ... otherwise use the default logfile */ - snprintf (logfile, MAXFNAME, "%s/.xsel.log", homedir); + snprintf (logfile, MAXFNAME, "%s/.xsel.log", cachedir); } /* Make sure to create the logfile with sane permissions */ @@ -503,8 +480,8 @@ become_daemon (void) umask (0); - if (chdir (homedir) == -1) { - print_debug (D_WARN, "Could not chdir to %s\n", homedir); + if (chdir (cachedir) == -1) { + print_debug (D_WARN, "Could not chdir to %s\n", cachedir); if (chdir ("/") == -1) { exit_err ("Error chdir to /"); }