Merge branch 'nd/i18n-2.8.0'
[gitweb.git] / credential-cache--daemon.c
index 118d04f137fad72e7bc3aa5693129d75e0aa3b83..caef21e4fc91898f209709f723de1df5afc66a66 100644 (file)
@@ -96,12 +96,12 @@ static int read_request(FILE *fh, struct credential *c,
        static struct strbuf item = STRBUF_INIT;
        const char *p;
 
-       strbuf_getline(&item, fh, '\n');
+       strbuf_getline_lf(&item, fh);
        if (!skip_prefix(item.buf, "action=", &p))
                return error("client sent bogus action line: %s", item.buf);
        strbuf_addstr(action, p);
 
-       strbuf_getline(&item, fh, '\n');
+       strbuf_getline_lf(&item, fh);
        if (!skip_prefix(item.buf, "timeout=", &p))
                return error("client sent bogus timeout line: %s", item.buf);
        *timeout = atoi(p);
@@ -236,6 +236,15 @@ static void init_socket_directory(const char *path)
                if (mkdir(dir, 0700) < 0)
                        die_errno("unable to mkdir '%s'", dir);
        }
+
+       if (chdir(dir))
+               /*
+                * We don't actually care what our cwd is; we chdir here just to
+                * be a friendly daemon and avoid tying up our original cwd.
+                * If this fails, it's OK to just continue without that benefit.
+                */
+               ;
+
        free(path_copy);
 }
 
@@ -262,6 +271,9 @@ int main(int argc, const char **argv)
        if (!socket_path)
                usage_with_options(usage, options);
 
+       if (!is_absolute_path(socket_path))
+               die("socket directory must be an absolute path");
+
        init_socket_directory(socket_path);
        register_tempfile(&socket_file, socket_path);