X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=src%2Fmachine%2Fmachine.c;h=a49cf81906039799b949ed61e76c7a4c455eac42;hb=4eb20caa4d32eb69abbf6ece4c9f22d02196f956;hp=e45c443495c0650f5372d927a2c2f29b44298f47;hpb=89f7c8465cd1ab37347dd0c15920bce31e8225df;p=elogind.git diff --git a/src/machine/machine.c b/src/machine/machine.c index e45c44349..a49cf8190 100644 --- a/src/machine/machine.c +++ b/src/machine/machine.c @@ -123,17 +123,42 @@ int machine_save(Machine *m) { "NAME=%s\n", m->name); - if (m->unit) - fprintf(f, "SCOPE=%s\n", m->unit); /* We continue to call this "SCOPE=" because it is internal only, and we want to stay compatible with old files */ + if (m->unit) { + _cleanup_free_ char *escaped; + + escaped = cescape(m->unit); + if (!escaped) { + r = -ENOMEM; + goto finish; + } + + fprintf(f, "SCOPE=%s\n", escaped); /* We continue to call this "SCOPE=" because it is internal only, and we want to stay compatible with old files */ + } if (m->scope_job) fprintf(f, "SCOPE_JOB=%s\n", m->scope_job); - if (m->service) - fprintf(f, "SERVICE=%s\n", m->service); + if (m->service) { + _cleanup_free_ char *escaped; - if (m->root_directory) - fprintf(f, "ROOT=%s\n", m->root_directory); + escaped = cescape(m->service); + if (!escaped) { + r = -ENOMEM; + goto finish; + } + fprintf(f, "SERVICE=%s\n", escaped); + } + + if (m->root_directory) { + _cleanup_free_ char *escaped; + + escaped = cescape(m->root_directory); + if (!escaped) { + r = -ENOMEM; + goto finish; + } + fprintf(f, "ROOT=%s\n", escaped); + } if (!sd_id128_equal(m->id, SD_ID128_NULL)) fprintf(f, "ID=" SD_ID128_FORMAT_STR "\n", SD_ID128_FORMAT_VAL(m->id)); @@ -252,7 +277,7 @@ static int machine_start_scope(Machine *m, sd_bus_message *properties, sd_bus_er if (!m->unit) { _cleanup_free_ char *escaped = NULL; - char *scope, *description, *job; + char *scope, *description, *job = NULL; escaped = unit_name_escape(m->name); if (!escaped) @@ -303,7 +328,7 @@ int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error) { log_struct(LOG_INFO, MESSAGE_ID(SD_MESSAGE_MACHINE_START), "NAME=%s", m->name, - "LEADER=%lu", (unsigned long) m->leader, + "LEADER="PID_FMT, m->leader, "MESSAGE=New machine %s.", m->name, NULL); @@ -322,7 +347,7 @@ int machine_start(Machine *m, sd_bus_message *properties, sd_bus_error *error) { static int machine_stop_scope(Machine *m) { _cleanup_bus_error_free_ sd_bus_error error = SD_BUS_ERROR_NULL; - char *job; + char *job = NULL; int r; assert(m); @@ -350,7 +375,7 @@ int machine_stop(Machine *m) { log_struct(LOG_INFO, MESSAGE_ID(SD_MESSAGE_MACHINE_STOP), "NAME=%s", m->name, - "LEADER=%lu", (unsigned long) m->leader, + "LEADER="PID_FMT, m->leader, "MESSAGE=Machine %s terminated.", m->name, NULL); @@ -410,7 +435,15 @@ int machine_kill(Machine *m, KillWho who, int signo) { if (!m->unit) return -ESRCH; - return manager_kill_unit(m->manager, m->unit, who, signo, NULL); + if (who == KILL_LEADER) { + /* If we shall simply kill the leader, do so directly */ + + if (kill(m->leader, signo) < 0) + return -errno; + } + + /* Otherwise make PID 1 do it for us, for the entire cgroup */ + return manager_kill_unit(m->manager, m->unit, signo, NULL); } static const char* const machine_class_table[_MACHINE_CLASS_MAX] = {