chiark / gitweb /
core: reuse the same /tmp, /var/tmp and inaccessible dir
[elogind.git] / src / shared / util.c
index b7ba7fbe84ad0f24ef704239f228561caf85623a..34c5330838908227199eae79cd85b0d2350e0951 100644 (file)
@@ -2963,7 +2963,7 @@ int status_welcome(void) {
         if (r < 0 && r != -ENOENT)
                 log_warning("Failed to read /etc/os-release: %s", strerror(-r));
 
-        return status_printf(NULL, false,
+        return status_printf(NULL, false, false,
                              "\nWelcome to \x1B[%sm%s\x1B[0m!\n",
                              isempty(ansi_color) ? "1" : ansi_color,
                              isempty(pretty_name) ? "Linux" : pretty_name);
@@ -3607,8 +3607,8 @@ void execute_directory(const char *directory, DIR *d, char *argv[]) {
 
         assert(directory);
 
-        /* Executes all binaries in a directory in parallel and waits
-         * until all they all finished. */
+        /* Executes all binaries in a directory in parallel and
+         * waits for them to finish. */
 
         if (!d) {
                 if (!(_d = opendir(directory))) {
@@ -5237,10 +5237,6 @@ int get_shell(char **_sh) {
         return 0;
 }
 
-void freep(void *p) {
-        free(*(void**) p);
-}
-
 void fclosep(FILE **f) {
         if (*f)
                 fclose(*f);
@@ -5261,10 +5257,6 @@ void closedirp(DIR **d) {
                 closedir(*d);
 }
 
-void umaskp(mode_t *u) {
-        umask(*u);
-}
-
 bool filename_is_safe(const char *p) {
 
         if (isempty(p))
@@ -5690,3 +5682,47 @@ int search_and_fopen_nulstr(const char *path, const char *mode, const char *sear
 
         return search_and_fopen_internal(path, mode, s, _f);
 }
+
+int create_tmp_dir(char template[], mode_t mask, bool need_sticky, char** dir_name) {
+        int r = 0;
+        char *d = NULL;
+        bool remove = false;
+        mode_t _cleanup_umask_ u;
+
+        assert(dir_name);
+
+        u = umask(mask);
+        d = mkdtemp(template);
+        if (!d) {
+                r = -errno;
+                log_debug("Can't create directory");
+                goto fail;
+        }
+
+        remove = true;
+
+        log_debug("Created temporary directory : %s", template);
+
+        d = strdup(template);
+        if (!d) {
+                r = log_oom();
+                goto fail;
+        }
+
+        if (need_sticky) {
+                r = chmod(template, 0777 | S_ISVTX);
+                if (r < 0) {
+                        r = -errno;
+                        goto fail;
+                }
+                log_debug("Setting sticky bit on : %s", template);
+        }
+
+        *dir_name = d;
+
+        return 0;
+fail:
+        if (remove)
+                rmdir(template);
+        return r;
+}