~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/tools/cgroup/cgroup_event_listener.c

Version: ~ [ linux-5.15-rc1 ] ~ [ linux-5.14.5 ] ~ [ linux-5.13.18 ] ~ [ linux-5.12.19 ] ~ [ linux-5.11.22 ] ~ [ linux-5.10.66 ] ~ [ linux-5.9.16 ] ~ [ linux-5.8.18 ] ~ [ linux-5.7.19 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.147 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.206 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.246 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.282 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.283 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.18.140 ] ~ [ linux-3.16.85 ] ~ [ linux-3.14.79 ] ~ [ linux-3.12.74 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

Diff markup

Differences between /tools/cgroup/cgroup_event_listener.c (Version linux-5.15-rc1) and /tools/cgroup/cgroup_event_listener.c (Version linux-4.13.16)


  1 // SPDX-License-Identifier: GPL-2.0            << 
  2 /*                                                  1 /*
  3  * cgroup_event_listener.c - Simple listener o      2  * cgroup_event_listener.c - Simple listener of cgroup events
  4  *                                                  3  *
  5  * Copyright (C) Kirill A. Shutemov <kirill@sh      4  * Copyright (C) Kirill A. Shutemov <kirill@shutemov.name>
  6  */                                                 5  */
  7                                                     6 
  8 #include <assert.h>                                 7 #include <assert.h>
  9 #include <err.h>                                    8 #include <err.h>
 10 #include <errno.h>                                  9 #include <errno.h>
 11 #include <fcntl.h>                                 10 #include <fcntl.h>
 12 #include <libgen.h>                                11 #include <libgen.h>
 13 #include <limits.h>                                12 #include <limits.h>
 14 #include <stdio.h>                                 13 #include <stdio.h>
 15 #include <string.h>                                14 #include <string.h>
 16 #include <unistd.h>                                15 #include <unistd.h>
 17                                                    16 
 18 #include <sys/eventfd.h>                           17 #include <sys/eventfd.h>
 19                                                    18 
 20 #define USAGE_STR "Usage: cgroup_event_listene     19 #define USAGE_STR "Usage: cgroup_event_listener <path-to-control-file> <args>"
 21                                                    20 
 22 int main(int argc, char **argv)                    21 int main(int argc, char **argv)
 23 {                                                  22 {
 24         int efd = -1;                              23         int efd = -1;
 25         int cfd = -1;                              24         int cfd = -1;
 26         int event_control = -1;                    25         int event_control = -1;
 27         char event_control_path[PATH_MAX];         26         char event_control_path[PATH_MAX];
 28         char line[LINE_MAX];                       27         char line[LINE_MAX];
 29         int ret;                                   28         int ret;
 30                                                    29 
 31         if (argc != 3)                             30         if (argc != 3)
 32                 errx(1, "%s", USAGE_STR);          31                 errx(1, "%s", USAGE_STR);
 33                                                    32 
 34         cfd = open(argv[1], O_RDONLY);             33         cfd = open(argv[1], O_RDONLY);
 35         if (cfd == -1)                             34         if (cfd == -1)
 36                 err(1, "Cannot open %s", argv[     35                 err(1, "Cannot open %s", argv[1]);
 37                                                    36 
 38         ret = snprintf(event_control_path, PAT     37         ret = snprintf(event_control_path, PATH_MAX, "%s/cgroup.event_control",
 39                         dirname(argv[1]));         38                         dirname(argv[1]));
 40         if (ret >= PATH_MAX)                       39         if (ret >= PATH_MAX)
 41                 errx(1, "Path to cgroup.event_     40                 errx(1, "Path to cgroup.event_control is too long");
 42                                                    41 
 43         event_control = open(event_control_pat     42         event_control = open(event_control_path, O_WRONLY);
 44         if (event_control == -1)                   43         if (event_control == -1)
 45                 err(1, "Cannot open %s", event     44                 err(1, "Cannot open %s", event_control_path);
 46                                                    45 
 47         efd = eventfd(0, 0);                       46         efd = eventfd(0, 0);
 48         if (efd == -1)                             47         if (efd == -1)
 49                 err(1, "eventfd() failed");        48                 err(1, "eventfd() failed");
 50                                                    49 
 51         ret = snprintf(line, LINE_MAX, "%d %d      50         ret = snprintf(line, LINE_MAX, "%d %d %s", efd, cfd, argv[2]);
 52         if (ret >= LINE_MAX)                       51         if (ret >= LINE_MAX)
 53                 errx(1, "Arguments string is t     52                 errx(1, "Arguments string is too long");
 54                                                    53 
 55         ret = write(event_control, line, strle     54         ret = write(event_control, line, strlen(line) + 1);
 56         if (ret == -1)                             55         if (ret == -1)
 57                 err(1, "Cannot write to cgroup     56                 err(1, "Cannot write to cgroup.event_control");
 58                                                    57 
 59         while (1) {                                58         while (1) {
 60                 uint64_t result;                   59                 uint64_t result;
 61                                                    60 
 62                 ret = read(efd, &result, sizeo     61                 ret = read(efd, &result, sizeof(result));
 63                 if (ret == -1) {                   62                 if (ret == -1) {
 64                         if (errno == EINTR)        63                         if (errno == EINTR)
 65                                 continue;          64                                 continue;
 66                         err(1, "Cannot read fr     65                         err(1, "Cannot read from eventfd");
 67                 }                                  66                 }
 68                 assert(ret == sizeof(result));     67                 assert(ret == sizeof(result));
 69                                                    68 
 70                 ret = access(event_control_pat     69                 ret = access(event_control_path, W_OK);
 71                 if ((ret == -1) && (errno == E     70                 if ((ret == -1) && (errno == ENOENT)) {
 72                         puts("The cgroup seems     71                         puts("The cgroup seems to have removed.");
 73                         break;                     72                         break;
 74                 }                                  73                 }
 75                                                    74 
 76                 if (ret == -1)                     75                 if (ret == -1)
 77                         err(1, "cgroup.event_c     76                         err(1, "cgroup.event_control is not accessible any more");
 78                                                    77 
 79                 printf("%s %s: crossed\n", arg     78                 printf("%s %s: crossed\n", argv[1], argv[2]);
 80         }                                          79         }
 81                                                    80 
 82         return 0;                                  81         return 0;
 83 }                                                  82 }
 84                                                    83 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp