[systemd-commits] 7 commits - src/ask-password-api.c src/ask-password.c src/cryptsetup.c src/gnome-ask-password-agent.vala src/mount.c src/reply-password.c src/tty-ask-password-agent.c src/unit.c units/local-fs.target

Lennart Poettering lennart at kemper.freedesktop.org
Wed Apr 13 12:44:19 PDT 2011


 src/ask-password-api.c            |   12 +++++++++---
 src/ask-password.c                |   12 +++++++++---
 src/cryptsetup.c                  |    7 ++++++-
 src/gnome-ask-password-agent.vala |    2 +-
 src/mount.c                       |    6 +++++-
 src/reply-password.c              |    2 +-
 src/tty-ask-password-agent.c      |   33 +++++++++++++++++++--------------
 src/unit.c                        |    3 +++
 units/local-fs.target             |    2 +-
 9 files changed, 54 insertions(+), 25 deletions(-)

New commits:
commit ded803353137a5b33d3fc460790c0e9b5cb257c1
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Apr 13 21:43:36 2011 +0200

    ask-password: use kill(PID, 0) before querying a password

diff --git a/src/tty-ask-password-agent.c b/src/tty-ask-password-agent.c
index 4a29aba..d7e1eba 100644
--- a/src/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent.c
@@ -291,6 +291,13 @@ static int parse_password(const char *filename, char **wall) {
                 }
         }
 
+        if (pid > 0 &&
+            kill(pid, 0) < 0 &&
+            errno == ESRCH) {
+                r = 0;
+                goto finish;
+        }
+
         if (arg_action == ACTION_LIST)
                 printf("'%s' (PID %u)\n", message, pid);
         else if (arg_action == ACTION_WALL) {

commit 7dcda352a609d063098e238db09c03cdc25c564b
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Apr 13 21:42:46 2011 +0200

    ask-password: support passwords without timeouts

diff --git a/src/ask-password-api.c b/src/ask-password-api.c
index 384cfc8..04d5623 100644
--- a/src/ask-password-api.c
+++ b/src/ask-password-api.c
@@ -404,13 +404,13 @@ int ask_password_agent(
 
                 t = now(CLOCK_MONOTONIC);
 
-                if (until <= t) {
+                if (until > 0 && until <= t) {
                         log_notice("Timed out");
                         r = -ETIME;
                         goto finish;
                 }
 
-                if ((k = poll(pollfd, _FD_MAX, (until-t)/USEC_PER_MSEC)) < 0) {
+                if ((k = poll(pollfd, _FD_MAX, until > 0 ? (int) ((until-t)/USEC_PER_MSEC) : -1)) < 0) {
 
                         if (errno == EINTR)
                                 continue;
diff --git a/src/ask-password.c b/src/ask-password.c
index c773764..6330369 100644
--- a/src/ask-password.c
+++ b/src/ask-password.c
@@ -101,7 +101,7 @@ static int parse_argv(int argc, char *argv[]) {
                         break;
 
                 case ARG_TIMEOUT:
-                        if (parse_usec(optarg, &arg_timeout) < 0 || arg_timeout <= 0) {
+                        if (parse_usec(optarg, &arg_timeout) < 0) {
                                 log_error("Failed to parse --timeout parameter %s", optarg);
                                 return -EINVAL;
                         }
@@ -139,6 +139,7 @@ static int parse_argv(int argc, char *argv[]) {
 
 int main(int argc, char *argv[]) {
         int r;
+        usec_t timeout;
 
         log_parse_environment();
         log_open();
@@ -146,10 +147,15 @@ int main(int argc, char *argv[]) {
         if ((r = parse_argv(argc, argv)) <= 0)
                 goto finish;
 
+        if (arg_timeout > 0)
+                timeout = now(CLOCK_MONOTONIC) + arg_timeout;
+        else
+                timeout = 0;
+
         if (arg_use_tty && isatty(STDIN_FILENO)) {
                 char *password = NULL;
 
-                if ((r = ask_password_tty(arg_message, now(CLOCK_MONOTONIC) + arg_timeout, NULL, &password)) >= 0) {
+                if ((r = ask_password_tty(arg_message, timeout, NULL, &password)) >= 0) {
                         puts(password);
                         free(password);
                 }
@@ -157,7 +163,7 @@ int main(int argc, char *argv[]) {
         } else {
                 char **l;
 
-                if ((r = ask_password_agent(arg_message, arg_icon, now(CLOCK_MONOTONIC) + arg_timeout, arg_accept_cached, &l)) >= 0) {
+                if ((r = ask_password_agent(arg_message, arg_icon, timeout, arg_accept_cached, &l)) >= 0) {
                         char **p;
 
                         STRV_FOREACH(p, l) {
diff --git a/src/cryptsetup.c b/src/cryptsetup.c
index 3aa822a..f52a41b 100644
--- a/src/cryptsetup.c
+++ b/src/cryptsetup.c
@@ -309,7 +309,10 @@ int main(int argc, char *argv[]) {
                 if (opt_readonly)
                         flags |= CRYPT_ACTIVATE_READONLY;
 
-                until = now(CLOCK_MONOTONIC) + (opt_timeout > 0 ? opt_timeout : DEFAULT_TIMEOUT_USEC);
+                if (opt_timeout > 0)
+                        until = now(CLOCK_MONOTONIC) + opt_timeout;
+                else
+                        until = 0;
 
                 opt_tries = opt_tries > 0 ? opt_tries : 3;
                 opt_key_size = (opt_key_size > 0 ? opt_key_size : 256);
@@ -404,6 +407,8 @@ int main(int argc, char *argv[]) {
                                 }
                         }
 
+                        k = 0;
+
                         if (!opt_type || streq(opt_type, CRYPT_LUKS1))
                                 k = crypt_load(cd, CRYPT_LUKS1, NULL);
 
diff --git a/src/gnome-ask-password-agent.vala b/src/gnome-ask-password-agent.vala
index 2bfc6a9..c31c07e 100644
--- a/src/gnome-ask-password-agent.vala
+++ b/src/gnome-ask-password-agent.vala
@@ -165,7 +165,7 @@ public class MyStatusIcon : StatusIcon {
                         if (not_after_as_string.scanf("%llu", out not_after) != 1)
                                 return false;
 
-                        if (not_after < now)
+                        if (not_after > 0 && not_after < now)
                                 return false;
 
                         socket = key_file.get_string("Ask", "Socket");
diff --git a/src/tty-ask-password-agent.c b/src/tty-ask-password-agent.c
index a414cba..4a29aba 100644
--- a/src/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent.c
@@ -261,7 +261,6 @@ static int parse_password(const char *filename, char **wall) {
 
         FILE *f;
         int r;
-        usec_t n;
 
         assert(filename);
 
@@ -279,16 +278,17 @@ static int parse_password(const char *filename, char **wall) {
                 goto finish;
         }
 
-        if (!socket_name || not_after <= 0) {
+        if (!socket_name) {
                 log_error("Invalid password file %s", filename);
                 r = -EBADMSG;
                 goto finish;
         }
 
-        n = now(CLOCK_MONOTONIC);
-        if (n > not_after) {
-                r = 0;
-                goto finish;
+        if (not_after > 0) {
+                if (now(CLOCK_MONOTONIC) > not_after) {
+                        r = 0;
+                        goto finish;
+                }
         }
 
         if (arg_action == ACTION_LIST)

commit d55f4f3f92f56f76bdd06192d6a2ef3ee9fe4772
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Apr 13 21:26:30 2011 +0200

    ask-password: always send final NUL char

diff --git a/src/reply-password.c b/src/reply-password.c
index 575a437..bd55e65 100644
--- a/src/reply-password.c
+++ b/src/reply-password.c
@@ -82,7 +82,7 @@ int main(int argc, char *argv[]) {
                 }
 
                 truncate_nl(packet+1);
-                length = strlen(packet+1) + 1;
+                length = 1 + strlen(packet+1) + 1;
         } else if (streq(argv[1], "0")) {
                 packet[0] = '-';
                 length = 1;
diff --git a/src/tty-ask-password-agent.c b/src/tty-ask-password-agent.c
index dcf4b33..a414cba 100644
--- a/src/tty-ask-password-agent.c
+++ b/src/tty-ask-password-agent.c
@@ -369,10 +369,15 @@ static int parse_password(const char *filename, char **wall) {
                                 release_terminal();
                         }
 
-                        asprintf(&packet, "+%s", password);
-                        free(password);
+                        packet_length = 1+strlen(password)+1;
+                        if (!(packet = new(char, packet_length)))
+                                r = -ENOMEM;
+                        else {
+                                packet[0] = '+';
+                                strcpy(packet+1, password);
+                        }
 
-                        packet_length = strlen(packet);
+                        free(password);
                 }
 
                 if (r == -ETIME || r == -ENOENT) {
@@ -382,17 +387,10 @@ static int parse_password(const char *filename, char **wall) {
                 }
 
                 if (r < 0) {
-
                         log_error("Failed to query password: %s", strerror(-r));
                         goto finish;
                 }
 
-                if (!packet) {
-                        log_error("Out of memory");
-                        r = -ENOMEM;
-                        goto finish;
-                }
-
                 if ((socket_fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) {
                         log_error("socket(): %m");
                         r = -errno;

commit 8254a475893e746eb667c0666a69a871d7fc4732
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Apr 13 21:24:17 2011 +0200

    ask-password: properly accept empty passwords from agent

diff --git a/src/ask-password-api.c b/src/ask-password-api.c
index da967ab..384cfc8 100644
--- a/src/ask-password-api.c
+++ b/src/ask-password-api.c
@@ -481,7 +481,13 @@ int ask_password_agent(
                 if (passphrase[0] == '+') {
                         char **l;
 
-                        if (!(l = strv_parse_nulstr(passphrase+1, n-1))) {
+                        if (n == 1)
+                                l = strv_new("", NULL);
+                        else
+                                l = strv_parse_nulstr(passphrase+1, n-1);
+                                /* An empty message refers to the empty password */
+
+                        if (!l) {
                                 r = -ENOMEM;
                                 goto finish;
                         }

commit df18d8c8959bbd9d7b866c6946aa856e462a06b3
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Apr 13 04:35:34 2011 +0200

    unit: skip default cgroup setup if we have no hierarchy to work on

diff --git a/src/unit.c b/src/unit.c
index e19061c..f50477f 100644
--- a/src/unit.c
+++ b/src/unit.c
@@ -1876,6 +1876,9 @@ int unit_add_default_cgroups(Unit *u) {
         /* Adds in the default cgroups, if they weren't specified
          * otherwise. */
 
+        if (!u->meta.manager->cgroup_hierarchy)
+                return 0;
+
         if ((r = unit_add_one_default_cgroup(u, NULL)) < 0)
                 return r;
 

commit 090bf7cbc4c2c4363e74c7f250ac65e7e2323ca6
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Apr 13 04:35:07 2011 +0200

    units: isolate emergency.target instead of emergency.service when we fail to mount all file systems

diff --git a/units/local-fs.target b/units/local-fs.target
index 79fd9b8..1886f74 100644
--- a/units/local-fs.target
+++ b/units/local-fs.target
@@ -9,5 +9,5 @@
 
 [Unit]
 Description=Local File Systems
-OnFailure=emergency.service
+OnFailure=emergency.target
 OnFailureIsolate=yes

commit d893269d9ffa6e72c60c9645ae88f83e826a14f2
Author: Lennart Poettering <lennart at poettering.net>
Date:   Wed Apr 13 04:34:35 2011 +0200

    mount: don't pull in stdio logger for root mount unit

diff --git a/src/mount.c b/src/mount.c
index 49bfd07..d7a300e 100644
--- a/src/mount.c
+++ b/src/mount.c
@@ -65,7 +65,11 @@ static void mount_init(Unit *u) {
         m->directory_mode = 0755;
 
         exec_context_init(&m->exec_context);
-        m->exec_context.std_output = EXEC_OUTPUT_KMSG;
+
+        /* The stdio/kmsg bridge socket is on /, in order to avoid a
+         * dep loop, don't use kmsg logging for -.mount */
+        if (!unit_has_name(u, "-.mount"))
+                m->exec_context.std_output = EXEC_OUTPUT_KMSG;
 
         /* We need to make sure that /bin/mount is always called in
          * the same process group as us, so that the autofs kernel



More information about the systemd-commits mailing list