Skip to contentSkip to conversation

libselinux/utils: introduce getpolicyload

PATCH In review Christian Göttsche 2 participants 3 messages Jul 14, 2023 – Aug 4, 2023 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 libselinux/utils: introduce getpolicyload

Introduce a helper binary to print the number of policy reloads on the running system.
Print only a single number to ease the usage by scripts.

---
v2:
- use main() prototype with arguments
- use argv[0] instead of hard coding program name
- fix indentation and spacing issues
- add binary to .gitignore file

---
 libselinux/utils/.gitignore      |  1 +
 libselinux/utils/getpolicyload.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 libselinux/utils/getpolicyload.c
libselinux/utils/.gitignore +1 -0
index b19b94a8..b3311360 100644
@@ -10,6 +10,7 @@ getenforce
 getfilecon
 getpidcon
 getpidprevcon
+getpolicyload
 getsebool
 getseuser
 matchpathcon
libselinux/utils/getpolicyload.c new file +30 -0
new file mode 100644
index 00000000..ce06bb78
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <selinux/avc.h>
+
+
+int main(int argc __attribute__ ((unused)),
+         char* argv[] __attribute__ ((unused))) {
+	int rc;
+
+	/*
+	* Do not use netlink as fallback, since selinux_status_policyload(3)
+	* works only after a first message has been received.
+	*/
+	rc = selinux_status_open(/*fallback=*/0);
+	if (rc < 0) {
+		fprintf(stderr, "%s:  failed to open SELinux status map:  %m\n", argv[0]);
+		return EXIT_FAILURE;
+	}
+
+	rc = selinux_status_policyload();
+	if (rc < 0)
+		fprintf(stderr, "%s:  failed to read policyload from SELinux status page:  %m\n", argv[0]);
+	else
+		printf("%d\n", rc);
+
+	selinux_status_close();
+
+	return (rc < 0) ? EXIT_FAILURE : EXIT_SUCCESS;
+}
Signature · 1 line
2.40.1
Acked-by on v2 1/1
#1 lore raw
Quoted 6 lines · Christian Göttsche

Introduce a helper binary to print the number of policy reloads on the running system.
Print only a single number to ease the usage by scripts.

Quoted 64 lines

---
v2:
- use main() prototype with arguments
- use argv[0] instead of hard coding program name
- fix indentation and spacing issues
- add binary to .gitignore file

---
 libselinux/utils/.gitignore      |  1 +
 libselinux/utils/getpolicyload.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 libselinux/utils/getpolicyload.c
libselinux/utils/.gitignore +1 -0
index b19b94a8..b3311360 100644
@@ -10,6 +10,7 @@ getenforce
 getfilecon
 getpidcon
 getpidprevcon
+getpolicyload
 getsebool
 getseuser
 matchpathcon
libselinux/utils/getpolicyload.c new file +30 -1
new file mode 100644
index 00000000..ce06bb78
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <selinux/avc.h>
+
+
+int main(int argc __attribute__ ((unused)),
+         char* argv[] __attribute__ ((unused))) {
+       int rc;
+
+       /*
+       * Do not use netlink as fallback, since selinux_status_policyload(3)
+       * works only after a first message has been received.
+       */
+       rc = selinux_status_open(/*fallback=*/0);
+       if (rc < 0) {
+               fprintf(stderr, "%s:  failed to open SELinux status map:  %m\n", argv[0]);
+               return EXIT_FAILURE;
+       }
+
+       rc = selinux_status_policyload();
+       if (rc < 0)
+               fprintf(stderr, "%s:  failed to read policyload from SELinux status page:  %m\n", argv[0]);
+       else
+               printf("%d\n", rc);
+
+       selinux_status_close();
+
+       return (rc < 0) ? EXIT_FAILURE : EXIT_SUCCESS;
+}
--

2.40.1

#2 lore raw
Quoted 4 lines · James Carter
Quoted 1 line · Christian Göttsche
Quoted 8 lines
Quoted 5 lines

Introduce a helper binary to print the number of policy reloads on the running system.
Print only a single number to ease the usage by scripts.

Merged.
Thanks,
Jim

Quoted 64 lines
Quoted 64 lines

---
v2:
- use main() prototype with arguments
- use argv[0] instead of hard coding program name
- fix indentation and spacing issues
- add binary to .gitignore file

---
 libselinux/utils/.gitignore      |  1 +
 libselinux/utils/getpolicyload.c | 30 ++++++++++++++++++++++++++++++
 2 files changed, 31 insertions(+)
 create mode 100644 libselinux/utils/getpolicyload.c
libselinux/utils/.gitignore +1 -0
index b19b94a8..b3311360 100644
@@ -10,6 +10,7 @@ getenforce
 getfilecon
 getpidcon
 getpidprevcon
+getpolicyload
 getsebool
 getseuser
 matchpathcon
libselinux/utils/getpolicyload.c new file +30 -1
new file mode 100644
index 00000000..ce06bb78
@@ -0,0 +1,30 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+#include <selinux/avc.h>
+
+
+int main(int argc __attribute__ ((unused)),
+         char* argv[] __attribute__ ((unused))) {
+       int rc;
+
+       /*
+       * Do not use netlink as fallback, since selinux_status_policyload(3)
+       * works only after a first message has been received.
+       */
+       rc = selinux_status_open(/*fallback=*/0);
+       if (rc < 0) {
+               fprintf(stderr, "%s:  failed to open SELinux status map:  %m\n", argv[0]);
+               return EXIT_FAILURE;
+       }
+
+       rc = selinux_status_policyload();
+       if (rc < 0)
+               fprintf(stderr, "%s:  failed to read policyload from SELinux status page:  %m\n", argv[0]);
+       else
+               printf("%d\n", rc);
+
+       selinux_status_close();
+
+       return (rc < 0) ? EXIT_FAILURE : EXIT_SUCCESS;
+}
--

2.40.1