python/hypothesis: update to 6.122.3
[oi-userland.git] / components / desktop / lightdm / patches / 15-smf.patch
blob0e2da577fba2521cfe2a84ee752b7a612074c5f9
1 --- lightdm-1.19.3/config.h.in.1 2016-08-11 16:37:18.327488055 +0300
2 +++ lightdm-1.19.3/config.h.in 2016-08-11 16:37:49.333955249 +0300
3 @@ -27,6 +27,9 @@
4 /* libaudit support */
5 #undef HAVE_LIBAUDIT
7 +/* libcontract support */
8 +#undef HAVE_SMF_CONTRACTS
10 /* Define to 1 if you have the <memory.h> header file. */
11 #undef HAVE_MEMORY_H
13 --- lightdm-1.19.3/configure.ac.1 2016-08-11 16:35:29.359045915 +0300
14 +++ lightdm-1.19.3/configure.ac 2016-08-11 16:37:03.732983253 +0300
15 @@ -155,6 +155,15 @@
17 AM_CONDITIONAL(COMPILE_LIBLIGHTDM_QT5, test x"$compile_liblightdm_qt5" != "xno")
19 +dnl ---------------------------------------------------------------------------
20 +dnl check for Solaris SMF contract support
21 +dnl ---------------------------------------------------------------------------
23 +AC_MSG_CHECKING(for Solaris SMF contract support)
24 +AC_CHECK_LIB(contract, ct_tmpl_activate, [
25 + AC_DEFINE(HAVE_SMF_CONTRACTS,1,[lcontract support])
26 + LIGHTDM_LIBS="${LIGHTDM_LIBS} -lcontract" ])
28 AC_ARG_ENABLE([libaudit],
29 AS_HELP_STRING([--enable-libaudit],
30 [Enable libaudit logging of login and logout events [[default=auto]]]),
31 --- lightdm-1.28.0/src/session.c 2018-08-30 02:28:55.000000000 +0000
32 +++ lightdm-1.28.0/src/session.c 2018-12-22 12:13:04.194567557 +0000
33 @@ -21,6 +21,13 @@
34 #include <grp.h>
35 #include <pwd.h>
37 +#ifdef HAVE_SMF_CONTRACTS
38 +#include <sys/ctfs.h>
39 +#include <sys/contract.h>
40 +#include <sys/contract/process.h>
41 +#include <libcontract.h>
42 +#endif
44 #include "session.h"
45 #include "configuration.h"
46 #include "console-kit.h"
47 @@ -131,6 +138,141 @@ G_DEFINE_TYPE_WITH_CODE (Session, sessio
48 G_IMPLEMENT_INTERFACE (
49 LOGGER_TYPE, session_logger_iface_init))
51 +#ifdef HAVE_SMF_CONTRACTS
52 +static int contracts_fd = -1;
54 +void contracts_pre_fork ();
55 +void contracts_post_fork_child ();
56 +void contracts_post_fork_parent (int fork_succeeded);
58 +void
59 +contracts_pre_fork ()
61 + const char *errmsg = "opening process contract template";
63 + /*
64 + * On failure, just continue since it is better to start with
65 + * children in the same contract than to not start them at all.
66 + */
67 + if (contracts_fd == -1) {
68 + if ((contracts_fd = open64 (CTFS_ROOT "/process/template",
69 + O_RDWR)) == -1)
70 + goto exit;
72 + errmsg = "setting contract terms";
73 + if ((errno = ct_pr_tmpl_set_param (contracts_fd, CT_PR_PGRPONLY)))
74 + goto exit;
76 + if ((errno = ct_tmpl_set_informative (contracts_fd, CT_PR_EV_HWERR)))
77 + goto exit;
79 + if ((errno = ct_pr_tmpl_set_fatal (contracts_fd, CT_PR_EV_HWERR)))
80 + goto exit;
82 + if ((errno = ct_tmpl_set_critical (contracts_fd, 0)))
83 + goto exit;
84 + }
86 + errmsg = "setting active template";
87 + if ((errno = ct_tmpl_activate (contracts_fd)))
88 + goto exit;
90 + g_debug ("Set active contract");
91 + return;
93 +exit:
94 + if (contracts_fd != -1)
95 + (void) close (contracts_fd);
97 + contracts_fd = -1;
99 + if (errno) {
100 + g_debug (
101 + "Error setting up active contract template: %s while %s",
102 + strerror (errno), errmsg);
106 +void
107 +contracts_post_fork_child ()
109 + /* Clear active template so no new contracts are created on fork */
110 + if (contracts_fd == -1)
111 + return;
113 + if ((errno = (ct_tmpl_clear (contracts_fd)))) {
114 + g_debug (
115 + "Error clearing active contract template (child): %s",
116 + strerror (errno));
117 + } else {
118 + g_debug ("Cleared active contract template (child)");
121 + (void) close (contracts_fd);
123 + contracts_fd = -1;
126 +void
127 +contracts_post_fork_parent (int fork_succeeded)
129 + char path[PATH_MAX];
130 + int cfd;
131 + ct_stathdl_t status;
132 + ctid_t latest;
134 + /* Clear active template, abandon latest contract. */
135 + if (contracts_fd == -1)
136 + return;
138 + if ((errno = ct_tmpl_clear (contracts_fd)))
139 + g_debug ("Error while clearing active contract template: %s",
140 + strerror (errno));
141 + else
142 + g_debug ("Cleared active contract template (parent)");
144 + if (!fork_succeeded)
145 + return;
147 + if ((cfd = open64 (CTFS_ROOT "/process/latest", O_RDONLY)) == -1) {
148 + g_debug ("Error getting latest contract: %s",
149 + strerror(errno));
150 + return;
153 + if ((errno = ct_status_read (cfd, CTD_COMMON, &status)) != 0) {
154 + g_debug ("Error getting latest contract ID: %s",
155 + strerror(errno));
156 + (void) close (cfd);
157 + return;
160 + latest = ct_status_get_id (status);
161 + ct_status_free (status);
162 + (void) close (cfd);
164 + if ((snprintf (path, PATH_MAX, CTFS_ROOT "/all/%ld/ctl", latest)) >=
165 + PATH_MAX) {
166 + g_debug ("Error opening the latest contract ctl file: %s",
167 + strerror (ENAMETOOLONG));
168 + return;
171 + cfd = open64 (path, O_WRONLY);
172 + if (cfd == -1) {
173 + g_debug ("Error opening the latest contract ctl file: %s",
174 + strerror (errno));
175 + return;
178 + if ((errno = ct_ctl_abandon (cfd)))
179 + g_debug ("Error abandoning latest contract: %s",
180 + strerror (errno));
181 + else
182 + g_debug ("Abandoned latest contract");
184 +#endif
186 Session *
187 session_new (void)
189 @@ -612,10 +754,16 @@ session_real_start (Session *session)
191 /* Run the child */
192 g_autofree gchar *arg0 = g_strdup_printf ("%d", to_child_output);
193 +#ifdef HAVE_SMF_CONTRACTS
194 + contracts_pre_fork ();
195 +#endif
196 g_autofree gchar *arg1 = g_strdup_printf ("%d", from_child_input);
197 priv->pid = fork ();
198 if (priv->pid == 0)
200 +#ifdef HAVE_SMF_CONTRACTS
201 + contracts_post_fork_child ();
202 +#endif
203 /* Run us again in session child mode */
204 execlp ("lightdm",
205 "lightdm",
206 @@ -623,6 +771,10 @@ session_real_start (Session *session)
207 arg0, arg1, NULL);
208 _exit (EXIT_FAILURE);
210 +#ifdef HAVE_SMF_CONTRACTS
211 + /* Child would have already exited */
212 + contracts_post_fork_parent ((priv->pid > 0));
213 +#endif
215 if (priv->pid < 0)