chiark / gitweb /
unit: optionally allow making cgroup attribute changes persistent
[elogind.git] / src / core / service.c
index 017d292a8b70d3db51003c45b5ec1d7171c50a90..ee5a1a41e574b58b51f6894b9bd968a1127bceee 100644 (file)
@@ -322,7 +322,8 @@ static void service_done(Unit *u) {
 static char *sysv_translate_name(const char *name) {
         char *r;
 
-        if (!(r = new(char, strlen(name) + sizeof(".service"))))
+        r = new(char, strlen(name) + sizeof(".service"));
+        if (!r)
                 return NULL;
 
         if (endswith(name, ".sh"))
@@ -348,16 +349,12 @@ static int sysv_translate_facility(const char *name, const char *filename, char
 
         static const char * const table[] = {
                 /* LSB defined facilities */
-                "local_fs",             SPECIAL_LOCAL_FS_TARGET,
-                /* Due to unfortunate name selection in Mandriva,
-                 * $network is provided by network-up which is ordered
-                 * after network which actually starts interfaces.
-                 * To break the loop, just ignore it */
+                "local_fs",             NULL,
                 "network",              SPECIAL_NETWORK_TARGET,
                 "named",                SPECIAL_NSS_LOOKUP_TARGET,
                 "portmap",              SPECIAL_RPCBIND_TARGET,
                 "remote_fs",            SPECIAL_REMOTE_FS_TARGET,
-                "syslog",               SPECIAL_SYSLOG_TARGET,
+                "syslog",               NULL,
                 "time",                 SPECIAL_TIME_SYNC_TARGET,
         };
 
@@ -378,8 +375,9 @@ static int sysv_translate_facility(const char *name, const char *filename, char
                 if (!table[i+1])
                         return 0;
 
-                if (!(r = strdup(table[i+1])))
-                        return -ENOMEM;
+                r = strdup(table[i+1]);
+                if (!r)
+                        return log_oom();
 
                 goto finish;
         }
@@ -1523,6 +1521,9 @@ static void service_set_state(Service *s, ServiceState state) {
                 s->control_command_id = _SERVICE_EXEC_COMMAND_INVALID;
         }
 
+        if (state == SERVICE_FAILED)
+                service_notify_sockets_dead(s, s->result == SERVICE_FAILURE_START_LIMIT);
+
         if (state == SERVICE_DEAD ||
             state == SERVICE_STOP ||
             state == SERVICE_STOP_SIGTERM ||
@@ -1530,7 +1531,6 @@ static void service_set_state(Service *s, ServiceState state) {
             state == SERVICE_STOP_POST ||
             state == SERVICE_FINAL_SIGTERM ||
             state == SERVICE_FINAL_SIGKILL ||
-            state == SERVICE_FAILED ||
             state == SERVICE_AUTO_RESTART)
                 service_notify_sockets_dead(s, false);
 
@@ -2939,13 +2939,13 @@ static void service_sigchld_event(Unit *u, pid_t pid, int code, int status) {
                                 f = SERVICE_SUCCESS;
                 }
 
-                log_struct(f == SERVICE_SUCCESS ? LOG_DEBUG : LOG_NOTICE,
+                log_struct_unit(f == SERVICE_SUCCESS ? LOG_DEBUG : LOG_NOTICE,
+                           u->id,
                            "MESSAGE=%s: main process exited, code=%s, status=%i/%s",
                                   u->id, sigchld_code_to_string(code), status,
                                   strna(code == CLD_EXITED
                                         ? exit_status_to_string(status, EXIT_STATUS_FULL)
                                         : signal_to_string(status)),
-                           "UNIT=%s", u->id,
                            "EXIT_CODE=%s", sigchld_code_to_string(code),
                            "EXIT_STATUS=%i", status,
                            NULL);
@@ -3832,13 +3832,15 @@ DEFINE_STRING_TABLE_LOOKUP(start_limit_action, StartLimitAction);
 
 const UnitVTable service_vtable = {
         .object_size = sizeof(Service),
-        .exec_context_offset = offsetof(Service, exec_context),
 
         .sections =
                 "Unit\0"
                 "Service\0"
                 "Install\0",
 
+        .exec_context_offset = offsetof(Service, exec_context),
+        .exec_section = "Service",
+
         .init = service_init,
         .done = service_done,
         .load = service_load,