chiark / gitweb /
journalctl: use _COMM= match for scripts
[elogind.git] / src / core / transaction.c
index dbc30af7d1c90c23f3bce82f2b4d29a1ad1be693..27efef7cc68124d38990efeb941d9b7b466c42c8 100644 (file)
@@ -24,6 +24,7 @@
 
 #include "transaction.h"
 #include "bus-errors.h"
+#include "dbus-common.h"
 
 static void transaction_unlink_job(Transaction *tr, Job *j, bool delete_dependencies);
 
@@ -97,6 +98,7 @@ static void transaction_merge_and_delete_job(Transaction *tr, Job *j, Job *other
         j->type = t;
         j->state = JOB_WAITING;
         j->override = j->override || other->override;
+        j->irreversible = j->irreversible || other->irreversible;
 
         j->matters_to_anchor = j->matters_to_anchor || other->matters_to_anchor;
 
@@ -138,7 +140,7 @@ static void transaction_merge_and_delete_job(Transaction *tr, Job *j, Job *other
         transaction_delete_job(tr, other, true);
 }
 
-static bool job_is_conflicted_by(Job *j) {
+_pure_ static bool job_is_conflicted_by(Job *j) {
         JobDependency *l;
 
         assert(j);
@@ -318,7 +320,7 @@ rescan:
         }
 }
 
-static bool unit_matters_to_anchor(Unit *u, Job *j) {
+_pure_ static bool unit_matters_to_anchor(Unit *u, Job *j) {
         assert(u);
         assert(!j->transaction_prev);
 
@@ -395,8 +397,8 @@ static int transaction_verify_order_one(Transaction *tr, Job *j, Job *from, unsi
                                        "Job %s/%s deleted to break ordering cycle starting with %s/%s",
                                        delete->unit->id, job_type_to_string(delete->type),
                                        j->unit->id, job_type_to_string(j->type));
-                        status_printf(ANSI_HIGHLIGHT_RED_ON " SKIP " ANSI_HIGHLIGHT_OFF, true,
-                                      "Ordering cycle found, skipping %s", unit_description(delete->unit));
+                        unit_status_printf(delete->unit, ANSI_HIGHLIGHT_RED_ON " SKIP " ANSI_HIGHLIGHT_OFF,
+                                           "Ordering cycle found, skipping %s");
                         transaction_delete_unit(tr, delete->unit);
                         return -EAGAIN;
                 }
@@ -488,7 +490,7 @@ rescan:
         }
 }
 
-static int transaction_is_destructive(Transaction *tr, DBusError *e) {
+static int transaction_is_destructive(Transaction *tr, JobMode mode, DBusError *e) {
         Iterator i;
         Job *j;
 
@@ -503,7 +505,7 @@ static int transaction_is_destructive(Transaction *tr, DBusError *e) {
                 assert(!j->transaction_prev);
                 assert(!j->transaction_next);
 
-                if (j->unit->job &&
+                if (j->unit->job && (mode == JOB_FAIL || j->unit->job->irreversible) &&
                     !job_type_is_superset(j->type, j->unit->job->type)) {
 
                         dbus_set_error(e, BUS_ERROR_TRANSACTION_IS_DESTRUCTIVE, "Transaction is destructive.");
@@ -709,12 +711,10 @@ int transaction_activate(Transaction *tr, Manager *m, JobMode mode, DBusError *e
         transaction_drop_redundant(tr);
 
         /* Ninth step: check whether we can actually apply this */
-        if (mode == JOB_FAIL) {
-                r = transaction_is_destructive(tr, e);
-                if (r < 0) {
-                        log_notice("Requested transaction contradicts existing jobs: %s", bus_error(e, r));
-                        return r;
-                }
+        r = transaction_is_destructive(tr, mode, e);
+        if (r < 0) {
+                log_notice("Requested transaction contradicts existing jobs: %s", bus_error(e, r));
+                return r;
         }
 
         /* Tenth step: apply changes */
@@ -733,8 +733,11 @@ int transaction_activate(Transaction *tr, Manager *m, JobMode mode, DBusError *e
                  * feature for cosmetics, not actually useful for
                  * anything beyond that. */
 
-                if (m->idle_pipe[0] < 0 && m->idle_pipe[1] < 0)
+                if (m->idle_pipe[0] < 0 && m->idle_pipe[1] < 0 &&
+                    m->idle_pipe[2] < 0 && m->idle_pipe[3] < 0) {
                         pipe2(m->idle_pipe, O_NONBLOCK|O_CLOEXEC);
+                        pipe2(m->idle_pipe + 2, O_NONBLOCK|O_CLOEXEC);
+                }
         }
 
         return 0;
@@ -770,6 +773,7 @@ static Job* transaction_add_one_job(Transaction *tr, JobType type, Unit *unit, b
         j->marker = NULL;
         j->matters_to_anchor = false;
         j->override = override;
+        j->irreversible = tr->irreversible;
 
         LIST_PREPEND(Job, transaction, f, j);
 
@@ -850,12 +854,13 @@ int transaction_add_job_and_dependencies(
 
         if (unit->load_state != UNIT_LOADED &&
             unit->load_state != UNIT_ERROR &&
+            unit->load_state != UNIT_NOT_FOUND &&
             unit->load_state != UNIT_MASKED) {
                 dbus_set_error(e, BUS_ERROR_LOAD_FAILED, "Unit %s is not loaded properly.", unit->id);
                 return -EINVAL;
         }
 
-        if (type != JOB_STOP && unit->load_state == UNIT_ERROR) {
+        if (type != JOB_STOP && (unit->load_state == UNIT_ERROR || unit->load_state == UNIT_NOT_FOUND)) {
                 dbus_set_error(e, BUS_ERROR_LOAD_FAILED,
                                "Unit %s failed to load: %s. "
                                "See system logs and 'systemctl status %s' for details.",
@@ -1106,7 +1111,7 @@ int transaction_add_isolate_jobs(Transaction *tr, Manager *m) {
         return 0;
 }
 
-Transaction *transaction_new(void) {
+Transaction *transaction_new(bool irreversible) {
         Transaction *tr;
 
         tr = new0(Transaction, 1);
@@ -1119,6 +1124,8 @@ Transaction *transaction_new(void) {
                 return NULL;
         }
 
+        tr->irreversible = irreversible;
+
         return tr;
 }