chiark / gitweb /
systemctl: append .service to unit names lacking suffix
[elogind.git] / src / shared / util.c
index a0755efb147593a2046e0feaf386986b047b4664..af975956dbca755091ca60981e5432e37b8328a4 100644 (file)
@@ -909,8 +909,7 @@ int load_env_file(
                         continue;
 
                 if (!(u = normalize_env_assignment(p))) {
-                        log_error("Out of memory");
-                        r = -ENOMEM;
+                        r = log_oom();
                         goto finish;
                 }
 
@@ -918,8 +917,7 @@ int load_env_file(
                 free(u);
 
                 if (!t) {
-                        log_error("Out of memory");
-                        r = -ENOMEM;
+                        r = log_oom();
                         goto finish;
                 }
 
@@ -3776,18 +3774,27 @@ int fd_columns(int fd) {
         return ws.ws_col;
 }
 
-unsigned columns(void) {
-        static __thread int parsed_columns = 0;
+static unsigned columns_cached(bool cached) {
+        static __thread int parsed_columns = 0, env_columns = -1;
         const char *e;
 
-        if (_likely_(parsed_columns > 0))
+        if (_likely_(parsed_columns > 0 && cached))
                 return parsed_columns;
 
-        e = getenv("COLUMNS");
-        if (e)
-                parsed_columns = atoi(e);
+        if (_unlikely_(env_columns == -1)) {
+                e = getenv("COLUMNS");
+                if (e)
+                        env_columns = atoi(e);
+                else
+                        env_columns = 0;
+        }
 
-        if (parsed_columns <= 0)
+        if (env_columns > 0) {
+                parsed_columns = env_columns;
+                return parsed_columns;
+        }
+
+        if (parsed_columns <= 0 || !cached)
                 parsed_columns = fd_columns(STDOUT_FILENO);
 
         if (parsed_columns <= 0)
@@ -3796,6 +3803,14 @@ unsigned columns(void) {
         return parsed_columns;
 }
 
+unsigned columns(void) {
+        return columns_cached(true);
+}
+
+unsigned columns_uncached(void) {
+        return columns_cached(false);
+}
+
 int fd_lines(int fd) {
         struct winsize ws;
         zero(ws);
@@ -4278,7 +4293,7 @@ void execute_directory(const char *directory, DIR *d, char *argv[]) {
                         continue;
 
                 if (asprintf(&path, "%s/%s", directory, de->d_name) < 0) {
-                        log_error("Out of memory");
+                        log_oom();
                         continue;
                 }
 
@@ -4905,7 +4920,12 @@ int socket_from_display(const char *display, char **path) {
         return 0;
 }
 
-int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **home) {
+int get_user_creds(
+                const char **username,
+                uid_t *uid, gid_t *gid,
+                const char **home,
+                const char **shell) {
+
         struct passwd *p;
         uid_t u;
 
@@ -4926,6 +4946,10 @@ int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **h
 
                 if (home)
                         *home = "/root";
+
+                if (shell)
+                        *shell = "/bin/sh";
+
                 return 0;
         }
 
@@ -4957,6 +4981,9 @@ int get_user_creds(const char **username, uid_t *uid, gid_t *gid, const char **h
         if (home)
                 *home = p->pw_dir;
 
+        if (shell)
+                *shell = p->pw_shell;
+
         return 0;
 }