~ubuntu-branches/ubuntu/trusty/systemd/trusty

« back to all changes in this revision

Viewing changes to src/core/swap.c

Tags: upstream-202
ImportĀ upstreamĀ versionĀ 202

Show diffs side-by-side

added added

removed removed

Lines of Context:
125
125
        free(s->parameters_fragment.what);
126
126
        s->parameters_fragment.what = NULL;
127
127
 
128
 
        exec_context_done(&s->exec_context);
 
128
        exec_context_done(&s->exec_context, manager_is_reloading_or_reexecuting(u->manager));
129
129
        exec_command_done_array(s->exec_command, _SWAP_EXEC_COMMAND_MAX);
130
130
        s->control_command = NULL;
131
131
 
214
214
 
215
215
static int swap_verify(Swap *s) {
216
216
        bool b;
217
 
        char _cleanup_free_ *e = NULL;
 
217
        _cleanup_free_ char *e = NULL;
218
218
 
219
219
        if (UNIT(s)->load_state != UNIT_LOADED)
220
220
                  return 0;
315
315
                bool set_flags) {
316
316
 
317
317
        Unit *u = NULL;
318
 
        char _cleanup_free_ *e = NULL;
 
318
        _cleanup_free_ char *e = NULL;
319
319
        char *wp = NULL;
320
320
        bool delete = false;
321
321
        int r;
632
632
        if (f != SWAP_SUCCESS)
633
633
                s->result = f;
634
634
 
 
635
        exec_context_tmp_dirs_done(&s->exec_context);
635
636
        swap_set_state(s, s->result != SWAP_SUCCESS ? SWAP_FAILED : SWAP_DEAD);
636
637
}
637
638
 
831
832
        if (s->control_command_id >= 0)
832
833
                unit_serialize_item(u, f, "control-command", swap_exec_command_to_string(s->control_command_id));
833
834
 
 
835
        exec_context_serialize(&s->exec_context, UNIT(s), f);
 
836
 
834
837
        return 0;
835
838
}
836
839
 
874
877
                        s->control_command_id = id;
875
878
                        s->control_command = s->exec_command + id;
876
879
                }
877
 
 
 
880
        } else if (streq(key, "tmp-dir")) {
 
881
                char *t;
 
882
 
 
883
                t = strdup(value);
 
884
                if (!t)
 
885
                        return log_oom();
 
886
 
 
887
                s->exec_context.tmp_dir = t;
 
888
        } else if (streq(key, "var-tmp-dir")) {
 
889
                char *t;
 
890
 
 
891
                t = strdup(value);
 
892
                if (!t)
 
893
                        return log_oom();
 
894
 
 
895
                s->exec_context.var_tmp_dir = t;
878
896
        } else
879
897
                log_debug_unit(u->id, "Unknown serialization key '%s'", key);
880
898
 
1224
1242
 
1225
1243
static int swap_enumerate(Manager *m) {
1226
1244
        int r;
1227
 
        struct epoll_event ev;
1228
1245
        assert(m);
1229
1246
 
1230
1247
        if (!m->proc_swaps) {
 
1248
                struct epoll_event ev = {
 
1249
                        .events = EPOLLPRI,
 
1250
                        .data.ptr = &m->swap_watch,
 
1251
                };
 
1252
 
1231
1253
                m->proc_swaps = fopen("/proc/swaps", "re");
1232
1254
                if (!m->proc_swaps)
1233
1255
                        return (errno == ENOENT) ? 0 : -errno;
1235
1257
                m->swap_watch.type = WATCH_SWAP;
1236
1258
                m->swap_watch.fd = fileno(m->proc_swaps);
1237
1259
 
1238
 
                zero(ev);
1239
 
                ev.events = EPOLLPRI;
1240
 
                ev.data.ptr = &m->swap_watch;
1241
 
 
1242
1260
                if (epoll_ctl(m->epoll_fd, EPOLL_CTL_ADD, m->swap_watch.fd, &ev) < 0)
1243
1261
                        return -errno;
1244
1262
        }
1262
1280
}
1263
1281
 
1264
1282
static int swap_kill(Unit *u, KillWho who, int signo, DBusError *error) {
1265
 
        Swap *s = SWAP(u);
1266
 
        int r = 0;
1267
 
        Set *pid_set = NULL;
1268
 
 
1269
 
        assert(s);
1270
 
 
1271
 
        if (who == KILL_MAIN) {
1272
 
                dbus_set_error(error, BUS_ERROR_NO_SUCH_PROCESS, "Swap units have no main processes");
1273
 
                return -ESRCH;
1274
 
        }
1275
 
 
1276
 
        if (s->control_pid <= 0 && who == KILL_CONTROL) {
1277
 
                dbus_set_error(error, BUS_ERROR_NO_SUCH_PROCESS, "No control process to kill");
1278
 
                return -ESRCH;
1279
 
        }
1280
 
 
1281
 
        if (who == KILL_CONTROL || who == KILL_ALL)
1282
 
                if (s->control_pid > 0)
1283
 
                        if (kill(s->control_pid, signo) < 0)
1284
 
                                r = -errno;
1285
 
 
1286
 
        if (who == KILL_ALL) {
1287
 
                int q;
1288
 
 
1289
 
                pid_set = set_new(trivial_hash_func, trivial_compare_func);
1290
 
                if (!pid_set)
1291
 
                        return -ENOMEM;
1292
 
 
1293
 
                /* Exclude the control pid from being killed via the cgroup */
1294
 
                if (s->control_pid > 0) {
1295
 
                        q = set_put(pid_set, LONG_TO_PTR(s->control_pid));
1296
 
                        if (q < 0) {
1297
 
                                r = q;
1298
 
                                goto finish;
1299
 
                        }
1300
 
                }
1301
 
 
1302
 
                q = cgroup_bonding_kill_list(UNIT(s)->cgroup_bondings, signo, false, false, pid_set, NULL);
1303
 
                if (q < 0 && q != -EAGAIN && q != -ESRCH && q != -ENOENT)
1304
 
                        r = q;
1305
 
        }
1306
 
 
1307
 
finish:
1308
 
        if (pid_set)
1309
 
                set_free(pid_set);
1310
 
 
1311
 
        return r;
 
1283
        return unit_kill_common(u, who, signo, -1, SWAP(u)->control_pid, error);
1312
1284
}
1313
1285
 
1314
1286
static const char* const swap_state_table[_SWAP_STATE_MAX] = {