chiark / gitweb /
index 74889b6..27eee8e 100644 (file)
@@ -1082,42 +1082,62 @@ int cg_get_root_path(char **path) {
return 0;
}

-int cg_pid_get_path_shifted(pid_t pid, const char *root, char **cgroup) {
-        _cleanup_free_ char *cg_root = NULL;
-        char *cg_process, *p;
+int cg_shift_path(const char *cgroup, const char *root, const char **shifted) {
+        _cleanup_free_ char *rt = NULL;
+        char *p;
int r;

-        assert(pid >= 0);
assert(cgroup);
+        assert(shifted);

if (!root) {
/* If the root was specified let's use that, otherwise
* let's determine it from PID 1 */

-                r = cg_get_root_path(&cg_root);
+                r = cg_get_root_path(&rt);
if (r < 0)
return r;

-                root = cg_root;
+                root = rt;
}

-        r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &cg_process);
+        p = path_startswith(cgroup, root);
+        if (p)
+                *shifted = p - 1;
+        else
+                *shifted = cgroup;
+
+        return 0;
+}
+
+int cg_pid_get_path_shifted(pid_t pid, const char *root, char **cgroup) {
+        _cleanup_free_ char *raw = NULL;
+        const char *c;
+        int r;
+
+        assert(pid >= 0);
+        assert(cgroup);
+
+        r = cg_pid_get_path(SYSTEMD_CGROUP_CONTROLLER, pid, &raw);
if (r < 0)
return r;

-        p = path_startswith(cg_process, root);
-        if (p) {
-                char *c;
+        r = cg_shift_path(raw, root, &c);
+        if (r < 0)
+                return r;

-                c = strdup(p - 1);
-                free(cg_process);
+        if (c == raw) {
+                *cgroup = raw;
+                raw = NULL;
+        } else {
+                char *n;

-                if (!c)
+                n = strdup(c);
+                if (!n)
return -ENOMEM;

-                *cgroup = c;
-        } else
-                *cgroup = cg_process;
+                *cgroup = n;
+        }

return 0;
}
{"ft_lang_label":"__label__en","ft_lang_prob":0.52628356,"math_prob":0.9531205,"size":1366,"snap":"2020-10-2020-16","text_gpt3_token_len":475,"char_repetition_ratio":0.15271659,"word_repetition_ratio":0.055555556,"special_character_ratio":0.4136164,"punctuation_ratio":0.25,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9977244,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2020-02-18T03:51:38Z\",\"WARC-Record-ID\":\"<urn:uuid:181e7bcb-5b18-4d05-82ff-a679becc0217>\",\"Content-Length\":\"16914\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:e868a7be-7df2-4839-83ab-51ccee8b8ef6>\",\"WARC-Concurrent-To\":\"<urn:uuid:9c73c012-5f76-4f6c-bc7b-b646461e3bc4>\",\"WARC-IP-Address\":\"212.13.197.231\",\"WARC-Target-URI\":\"http://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?p=elogind.git;a=blobdiff;f=src/shared/cgroup-util.c;h=27eee8eacddae52da0f30baab8320f2bd6fb5f3a;hp=74889b636324dea71c0426e05740198a5f21286b;hb=751bc6ac79320bc16e63e8c1bbb713c30a3b7bc9;hpb=4e6a9570b698b335c6f59ec3556dfb3e95817d75\",\"WARC-Payload-Digest\":\"sha1:46WN2S6KETZGTPI6AQSKK2MHPCMJLSAS\",\"WARC-Block-Digest\":\"sha1:XOXH7BR4QWJ2K2JXIPCYZYBGNGIAL2AF\",\"WARC-Identified-Payload-Type\":\"application/xhtml+xml\",\"warc_filename\":\"/cc_download/warc_2020/CC-MAIN-2020-10/CC-MAIN-2020-10_segments_1581875143505.60_warc_CC-MAIN-20200218025323-20200218055323-00100.warc.gz\"}"}