chiark / gitweb /
Rename formats-util.h to format-util.h
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Mon, 7 Nov 2016 15:14:59 +0000 (10:14 -0500)
committerSven Eden <yamakuzure@gmx.net>
Mon, 17 Jul 2017 15:58:35 +0000 (17:58 +0200)
We don't have plural in the name of any other -util files and this
inconsistency trips me up every time I try to type this file name
from memory. "formats-util" is even hard to pronounce.

24 files changed:
src/basic/cgroup-util.c
src/basic/log.c
src/basic/process-util.h
src/basic/socket-util.c
src/basic/user-util.c
src/basic/util.h
src/libelogind/sd-bus/bus-creds.c
src/libelogind/sd-bus/bus-kernel.c
src/libelogind/sd-bus/bus-socket.c
src/libelogind/sd-login/sd-login.c
src/libelogind/sd-login/test-login.c
src/login/inhibit.c
src/login/logind-acl.c
src/login/logind-action.c
src/login/logind-dbus.c
src/login/logind-inhibit.c
src/login/logind-seat.c
src/login/logind-session.c
src/login/logind-user-dbus.c
src/login/logind-user.c
src/login/logind-utmp.c
src/login/logind.c
src/login/pam_elogind.c
src/shared/clean-ipc.c

index 953bb86..b95d70a 100644 (file)
@@ -28,6 +28,7 @@
 #include <sys/stat.h>
 //#include <sys/statfs.h>
 #include <sys/types.h>
+#include <sys/xattr.h>
 #include <unistd.h>
 
 #include "alloc-util.h"
@@ -37,7 +38,7 @@
 #include "extract-word.h"
 #include "fd-util.h"
 #include "fileio.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "fs-util.h"
 //#include "log.h"
 #include "login-util.h"
index 0783372..2f54194 100644 (file)
@@ -249,14 +249,14 @@ int log_open(void) {
                 return 0;
         }
 
-        if (!IN_SET(log_target, LOG_TARGET_AUTO, LOG_TARGET_SAFE) ||
+        if ((log_target != LOG_TARGET_AUTO && log_target != LOG_TARGET_SAFE) ||
             getpid() == 1 ||
             isatty(STDERR_FILENO) <= 0) {
 
 #if 0 /// elogind does not support logging to systemd-journald
-                if (IN_SET(log_target, LOG_TARGET_AUTO,
-                                       LOG_TARGET_JOURNAL_OR_KMSG,
-                                       LOG_TARGET_JOURNAL)) {
+                if (log_target == LOG_TARGET_AUTO ||
+                    log_target == LOG_TARGET_JOURNAL_OR_KMSG ||
+                    log_target == LOG_TARGET_JOURNAL) {
                         r = log_open_journal();
                         if (r >= 0) {
                                 log_close_syslog();
@@ -266,8 +266,8 @@ int log_open(void) {
                 }
 #endif // 0
 
-                if (IN_SET(log_target, LOG_TARGET_SYSLOG_OR_KMSG,
-                                       LOG_TARGET_SYSLOG)) {
+                if (log_target == LOG_TARGET_SYSLOG_OR_KMSG ||
+                    log_target == LOG_TARGET_SYSLOG) {
                         r = log_open_syslog();
                         if (r >= 0) {
                                 log_close_journal();
@@ -276,11 +276,11 @@ int log_open(void) {
                         }
                 }
 
-                if (IN_SET(log_target, LOG_TARGET_AUTO,
-                                       LOG_TARGET_SAFE,
-                                       LOG_TARGET_JOURNAL_OR_KMSG,
-                                       LOG_TARGET_SYSLOG_OR_KMSG,
-                                       LOG_TARGET_KMSG)) {
+                if (log_target == LOG_TARGET_AUTO ||
+                    log_target == LOG_TARGET_SAFE ||
+                    log_target == LOG_TARGET_JOURNAL_OR_KMSG ||
+                    log_target == LOG_TARGET_SYSLOG_OR_KMSG ||
+                    log_target == LOG_TARGET_KMSG) {
                         r = log_open_kmsg();
                         if (r >= 0) {
                                 log_close_journal();
@@ -513,7 +513,7 @@ static int log_do_header(
                  line ? "CODE_LINE=" : "",
                  line ? 1 : 0, line, /* %.0d means no output too, special case for 0 */
                  line ? "\n" : "",
-                 isempty(func) ? "" : "CODE_FUNC=",
+                 isempty(func) ? "" : "CODE_FUNCTION=",
                  isempty(func) ? "" : func,
                  isempty(func) ? "" : "\n",
                  error ? "ERRNO=" : "",
@@ -603,9 +603,9 @@ static int log_dispatch(
                         *(e++) = 0;
 
 #if 0 /// elogind does not support logging to systemd-journald
-                if (IN_SET(log_target, LOG_TARGET_AUTO,
-                                       LOG_TARGET_JOURNAL_OR_KMSG,
-                                       LOG_TARGET_JOURNAL)) {
+                if (log_target == LOG_TARGET_AUTO ||
+                    log_target == LOG_TARGET_JOURNAL_OR_KMSG ||
+                    log_target == LOG_TARGET_JOURNAL) {
 
                         k = write_to_journal(level, error, file, line, func, object_field, object, extra_field, extra, buffer);
                         if (k < 0) {
@@ -616,8 +616,8 @@ static int log_dispatch(
                 }
 #endif // 0
 
-                if (IN_SET(log_target, LOG_TARGET_SYSLOG_OR_KMSG,
-                                       LOG_TARGET_SYSLOG)) {
+                if (log_target == LOG_TARGET_SYSLOG_OR_KMSG ||
+                    log_target == LOG_TARGET_SYSLOG) {
 
                         k = write_to_syslog(level, error, file, line, func, buffer);
                         if (k < 0) {
@@ -628,11 +628,11 @@ static int log_dispatch(
                 }
 
                 if (k <= 0 &&
-                    IN_SET(log_target, LOG_TARGET_AUTO,
-                                       LOG_TARGET_SAFE,
-                                       LOG_TARGET_SYSLOG_OR_KMSG,
-                                       LOG_TARGET_JOURNAL_OR_KMSG,
-                                       LOG_TARGET_KMSG)) {
+                    (log_target == LOG_TARGET_AUTO ||
+                     log_target == LOG_TARGET_SAFE ||
+                     log_target == LOG_TARGET_SYSLOG_OR_KMSG ||
+                     log_target == LOG_TARGET_JOURNAL_OR_KMSG ||
+                     log_target == LOG_TARGET_KMSG)) {
 
                         k = write_to_kmsg(level, error, file, line, func, buffer);
                         if (k < 0) {
@@ -898,9 +898,9 @@ int log_struct_internal(
                 level = log_facility | LOG_PRI(level);
 
 #if 0 /// elogind does not support logging to systemd-journald
-        if (IN_SET(log_target, LOG_TARGET_AUTO,
-                               LOG_TARGET_JOURNAL_OR_KMSG,
-                               LOG_TARGET_JOURNAL) &&
+        if ((log_target == LOG_TARGET_AUTO ||
+             log_target == LOG_TARGET_JOURNAL_OR_KMSG ||
+             log_target == LOG_TARGET_JOURNAL) &&
             journal_fd >= 0) {
                 char header[LINE_MAX];
                 struct iovec iovec[17] = {};
@@ -999,30 +999,24 @@ static int parse_proc_cmdline_item(const char *key, const char *value, void *dat
         if (streq(key, "debug") && !value)
                 log_set_max_level(LOG_DEBUG);
 
-        else if (proc_cmdline_key_streq(key, "systemd.log_target")) {
-
-                if (proc_cmdline_value_missing(key, value))
-                        return 0;
+        else if (streq(key, "systemd.log_target") && value) {
 
                 if (log_set_target_from_string(value) < 0)
                         log_warning("Failed to parse log target '%s'. Ignoring.", value);
 
-        } else if (proc_cmdline_key_streq(key, "systemd.log_level")) {
-
-                if (proc_cmdline_value_missing(key, value))
-                        return 0;
+        } else if (streq(key, "systemd.log_level") && value) {
 
                 if (log_set_max_level_from_string(value) < 0)
                         log_warning("Failed to parse log level '%s'. Ignoring.", value);
 
-        } else if (proc_cmdline_key_streq(key, "systemd.log_color")) {
+        } else if (streq(key, "systemd.log_color") && value) {
 
-                if (log_show_color_from_string(value ?: "1") < 0)
+                if (log_show_color_from_string(value) < 0)
                         log_warning("Failed to parse log color setting '%s'. Ignoring.", value);
 
-        } else if (proc_cmdline_key_streq(key, "systemd.log_location")) {
+        } else if (streq(key, "systemd.log_location") && value) {
 
-                if (log_show_location_from_string(value ?: "1") < 0)
+                if (log_show_location_from_string(value) < 0)
                         log_warning("Failed to parse log location setting '%s'. Ignoring.", value);
         }
 
@@ -1033,9 +1027,10 @@ void log_parse_environment(void) {
         const char *e;
 
         if (get_ctty_devnr(0, NULL) < 0)
-                /* Only try to read the command line in daemons.  We assume that anything that has a controlling tty is
-                   user stuff. */
-                (void) proc_cmdline_parse(parse_proc_cmdline_item, NULL, PROC_CMDLINE_STRIP_RD_PREFIX);
+                /* Only try to read the command line in daemons.
+                   We assume that anything that has a controlling
+                   tty is user stuff. */
+                (void) parse_proc_cmdline(parse_proc_cmdline_item, NULL, true);
 
         e = secure_getenv("SYSTEMD_LOG_TARGET");
         if (e && log_set_target_from_string(e) < 0)
@@ -1101,8 +1096,8 @@ int log_show_location_from_string(const char *e) {
 }
 
 bool log_on_console(void) {
-        if (IN_SET(log_target, LOG_TARGET_CONSOLE,
-                               LOG_TARGET_CONSOLE_PREFIXED))
+        if (log_target == LOG_TARGET_CONSOLE ||
+            log_target == LOG_TARGET_CONSOLE_PREFIXED)
                 return true;
 
         return syslog_fd < 0 && kmsg_fd < 0 && journal_fd < 0;
@@ -1161,8 +1156,8 @@ int log_syntax_internal(
 
         PROTECT_ERRNO;
         char buffer[LINE_MAX];
+        int r;
         va_list ap;
-        const char *unit_fmt = NULL;
 
         if (error < 0)
                 error = -error;
@@ -1181,15 +1176,24 @@ int log_syntax_internal(
         va_end(ap);
 
         if (unit)
-                unit_fmt = getpid() == 1 ? "UNIT=%s" : "USER_UNIT=%s";
-
-        return log_struct_internal(
-                        level, error,
-                        file, line, func,
-                        "MESSAGE_ID=" SD_MESSAGE_INVALID_CONFIGURATION_STR,
-                        "CONFIG_FILE=%s", config_file,
-                        "CONFIG_LINE=%u", config_line,
-                        LOG_MESSAGE("%s:%u: %s", config_file, config_line, buffer),
-                        unit_fmt, unit,
-                        NULL);
+                r = log_struct_internal(
+                                level, error,
+                                file, line, func,
+                                getpid() == 1 ? "UNIT=%s" : "USER_UNIT=%s", unit,
+                                LOG_MESSAGE_ID(SD_MESSAGE_INVALID_CONFIGURATION),
+                                "CONFIG_FILE=%s", config_file,
+                                "CONFIG_LINE=%u", config_line,
+                                LOG_MESSAGE("[%s:%u] %s", config_file, config_line, buffer),
+                                NULL);
+        else
+                r = log_struct_internal(
+                                level, error,
+                                file, line, func,
+                                LOG_MESSAGE_ID(SD_MESSAGE_INVALID_CONFIGURATION),
+                                "CONFIG_FILE=%s", config_file,
+                                "CONFIG_LINE=%u", config_line,
+                                LOG_MESSAGE("[%s:%u] %s", config_file, config_line, buffer),
+                                NULL);
+
+        return r;
 }
index c05d05d..e904fee 100644 (file)
@@ -26,8 +26,9 @@
 #include <stdio.h>
 #include <string.h>
 #include <sys/types.h>
+#include <sys/resource.h>
 
-#include "formats-util.h"
+#include "format-util.h"
 #include "macro.h"
 
 #define procfs_file_alloca(pid, field)                                  \
index 4c18693..1d43a48 100644 (file)
@@ -33,7 +33,7 @@
 #include "alloc-util.h"
 #include "fd-util.h"
 #include "fileio.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "log.h"
 #include "macro.h"
 #include "missing.h"
index 9ef19a1..5133613 100644 (file)
@@ -34,7 +34,7 @@
 #include "alloc-util.h"
 #include "fd-util.h"
 #include "fileio.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "macro.h"
 #include "missing.h"
 #include "parse-util.h"
index 75631c4..5283f96 100644 (file)
@@ -41,7 +41,7 @@
 #include <time.h>
 #include <unistd.h>
 
-#include "formats-util.h"
+#include "format-util.h"
 #include "macro.h"
 #include "missing.h"
 #include "time-util.h"
index 255d1c5..3cb9961 100644 (file)
@@ -30,7 +30,7 @@
 #include "cgroup-util.h"
 #include "fd-util.h"
 #include "fileio.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "hexdecoct.h"
 #include "parse-util.h"
 #include "process-util.h"
index 5db011b..aef1511 100644 (file)
@@ -42,7 +42,7 @@
 #include "capability-util.h"
 #include "fd-util.h"
 #include "fileio.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "memfd-util.h"
 #include "parse-util.h"
 #include "stdio-util.h"
@@ -1650,7 +1650,7 @@ int bus_kernel_create_bus(const char *name, bool world, char **s) {
         if (s) {
                 char *p;
 
-                p = strjoin("/sys/fs/kdbus/", n->str, "/bus", NULL);
+                p = strjoin("/sys/fs/kdbus/", n->str, "/bus");
                 if (!p) {
                         safe_close(fd);
                         return -ENOMEM;
index cfd7753..e6ed15e 100644 (file)
@@ -30,7 +30,7 @@
 #include "bus-message.h"
 #include "bus-socket.h"
 #include "fd-util.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "hexdecoct.h"
 #include "macro.h"
 #include "missing.h"
index f41e1a8..9d09684 100644 (file)
@@ -31,7 +31,7 @@
 #include "escape.h"
 #include "fd-util.h"
 #include "fileio.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "fs-util.h"
 #include "hostname-util.h"
 #include "io-util.h"
index e0a838d..e1559c6 100644 (file)
@@ -24,7 +24,7 @@
 
 #include "alloc-util.h"
 #include "fd-util.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "string-util.h"
 #include "strv.h"
 #include "util.h"
index 5906cec..896fd57 100644 (file)
@@ -29,7 +29,7 @@
 #include "bus-error.h"
 #include "bus-util.h"
 #include "fd-util.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "process-util.h"
 #include "signal-util.h"
 #include "strv.h"
index 0cef88a..1b69f4b 100644 (file)
@@ -25,7 +25,7 @@
 #include "dirent-util.h"
 #include "escape.h"
 #include "fd-util.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "logind-acl.h"
 #include "set.h"
 #include "string-util.h"
index bcf7b86..48d9fb8 100644 (file)
@@ -23,7 +23,7 @@
 #include "bus-error.h"
 #include "bus-util.h"
 #include "conf-parser.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "logind-action.h"
 #include "process-util.h"
 #include "sleep-config.h"
index 971b447..a605666 100644 (file)
@@ -1301,7 +1301,8 @@ static int flush_devices(Manager *m) {
         } else {
                 struct dirent *de;
 
-                FOREACH_DIRENT_ALL(de, d, break) {
+                while ((de = readdir(d))) {
+
                         if (!dirent_is_file(de))
                                 continue;
 
@@ -1446,7 +1447,7 @@ static int bus_manager_log_shutdown(
                 p = strjoina(p, " (", m->wall_message, ").");
 
         return log_struct(LOG_NOTICE,
-                          "MESSAGE_ID=" SD_MESSAGE_SHUTDOWN_STR,
+                          LOG_MESSAGE_ID(SD_MESSAGE_SHUTDOWN),
                           p,
                           q,
                           NULL);
@@ -2464,9 +2465,13 @@ static int method_set_wall_message(
                 return 1; /* Will call us back */
 #endif // 0
 
-        r = free_and_strdup(&m->wall_message, empty_to_null(wall_message));
-        if (r < 0)
-                return log_oom();
+        if (isempty(wall_message))
+                m->wall_message = mfree(m->wall_message);
+        else {
+                r = free_and_strdup(&m->wall_message, wall_message);
+                if (r < 0)
+                        return log_oom();
+        }
 
         m->enable_wall_messages = enable_wall_messages;
 
index a7e5c01..5ca42b1 100644 (file)
@@ -26,7 +26,7 @@
 #include "escape.h"
 #include "fd-util.h"
 #include "fileio.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "logind-inhibit.h"
 #include "mkdir.h"
 #include "parse-util.h"
index 92fa3c9..f94d7a2 100644 (file)
@@ -420,7 +420,7 @@ int seat_start(Seat *s) {
                 return 0;
 
         log_struct(LOG_INFO,
-                   "MESSAGE_ID=" SD_MESSAGE_SEAT_START_STR,
+                   LOG_MESSAGE_ID(SD_MESSAGE_SEAT_START),
                    "SEAT_ID=%s", s->id,
                    LOG_MESSAGE("New seat %s.", s->id),
                    NULL);
@@ -450,7 +450,7 @@ int seat_stop(Seat *s, bool force) {
 
         if (s->started)
                 log_struct(LOG_INFO,
-                           "MESSAGE_ID=" SD_MESSAGE_SEAT_STOP_STR,
+                           LOG_MESSAGE_ID(SD_MESSAGE_SEAT_STOP),
                            "SEAT_ID=%s", s->id,
                            LOG_MESSAGE("Removed seat %s.", s->id),
                            NULL);
@@ -547,6 +547,8 @@ int seat_attach_session(Seat *s, Session *session) {
         LIST_PREPEND(sessions_by_seat, s->sessions, session);
         seat_assign_position(s, session);
 
+        seat_send_changed(s, "Sessions", NULL);
+
         /* On seats with VTs, the VT logic defines which session is active. On
          * seats without VTs, we automatically activate new sessions. */
         if (!seat_has_vts(s))
index bd2aac9..0799a98 100644 (file)
@@ -592,7 +592,7 @@ int session_start(Session *s) {
                 return r;
 
         log_struct(s->class == SESSION_BACKGROUND ? LOG_DEBUG : LOG_INFO,
-                   "MESSAGE_ID=" SD_MESSAGE_SESSION_START_STR,
+                   LOG_MESSAGE_ID(SD_MESSAGE_SESSION_START),
                    "SESSION_ID=%s", s->id,
                    "USER_ID=%s", s->user->name,
                    "LEADER="PID_FMT, s->leader,
@@ -617,10 +617,12 @@ int session_start(Session *s) {
 
         /* Send signals */
         session_send_signal(s, true);
-        user_send_changed(s->user, "Display", NULL);
+        user_send_changed(s->user, "Sessions", "Display", NULL);
         if (s->seat) {
                 if (s->seat->active == s)
-                        seat_send_changed(s->seat, "ActiveSession", NULL);
+                        seat_send_changed(s->seat, "Sessions", "ActiveSession", NULL);
+                else
+                        seat_send_changed(s->seat, "Sessions", NULL);
         }
 
         return 0;
@@ -718,7 +720,7 @@ int session_finalize(Session *s) {
 
         if (s->started)
                 log_struct(s->class == SESSION_BACKGROUND ? LOG_DEBUG : LOG_INFO,
-                           "MESSAGE_ID=" SD_MESSAGE_SESSION_STOP_STR,
+                           LOG_MESSAGE_ID(SD_MESSAGE_SESSION_STOP),
                            "SESSION_ID=%s", s->id,
                            "USER_ID=%s", s->user->name,
                            "LEADER="PID_FMT, s->leader,
@@ -748,10 +750,11 @@ int session_finalize(Session *s) {
                         seat_set_active(s->seat, NULL);
 
                 seat_save(s->seat);
+                seat_send_changed(s->seat, "Sessions", NULL);
         }
 
         user_save(s->user);
-        user_send_changed(s->user, "Display", NULL);
+        user_send_changed(s->user, "Sessions", "Display", NULL);
 
         return 0;
 }
index af6392e..987c630 100644 (file)
@@ -22,7 +22,7 @@
 
 #include "alloc-util.h"
 #include "bus-util.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "logind-user.h"
 #include "logind.h"
 #include "signal-util.h"
index 304e6b5..c1fd75a 100644 (file)
 #include "bus-common-errors.h"
 #include "bus-error.h"
 #include "bus-util.h"
+#include "cgroup-util.h"
 #include "clean-ipc.h"
 #include "conf-parser.h"
 #include "escape.h"
 #include "fd-util.h"
 #include "fileio.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "fs-util.h"
 #include "hashmap.h"
 #include "label.h"
index 4fcc25a..4fe5ff0 100644 (file)
@@ -29,7 +29,7 @@
 #include "bus-common-errors.h"
 #include "bus-error.h"
 #include "bus-util.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "logind.h"
 //#include "special.h"
 #include "strv.h"
index 2efa78c..83b06af 100644 (file)
@@ -36,7 +36,7 @@
 #include "def.h"
 #include "dirent-util.h"
 #include "fd-util.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "logind.h"
 #include "selinux-util.h"
 #include "signal-util.h"
@@ -1208,15 +1208,12 @@ int main(int argc, char *argv[]) {
         log_set_target(LOG_TARGET_AUTO);
         log_set_facility(LOG_AUTH);
         log_parse_environment();
-
 #ifdef ENABLE_DEBUG_ELOGIND
         log_set_max_level(LOG_DEBUG);
         log_set_target(LOG_TARGET_SYSLOG_OR_KMSG);
 #endif // ENABLE_DEBUG_ELOGIND
-
         log_open();
 
-
         umask(0022);
 
         if (argc != 1) {
index b0f75b2..dab082a 100644 (file)
@@ -36,7 +36,7 @@
 #include "def.h"
 #include "fd-util.h"
 #include "fileio.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "hostname-util.h"
 #include "login-util.h"
 #include "macro.h"
index 8c60bdc..ba48fb0 100644 (file)
@@ -36,7 +36,7 @@
 #include "dirent-util.h"
 #include "fd-util.h"
 #include "fileio.h"
-#include "formats-util.h"
+#include "format-util.h"
 #include "log.h"
 #include "macro.h"
 #include "string-util.h"