119
132
TEST_EQ (running, TRUE);
136
* session_init_reexec:
138
* @pid: pid of Session Init.
140
* Cause the Session Init running as pid @pid to re-exec.
143
session_init_reexec (pid_t pid)
145
nih_local NihDBusProxy *upstart = NULL;
147
DBusConnection *connection;
148
DBusMessage *method_call;
149
DBusMessageIter iter;
154
TEST_TRUE (set_upstart_session (pid));
155
address = getenv ("UPSTART_SESSION");
159
connection = nih_dbus_connect (address, NULL);
160
TEST_NE_P (connection, NULL);
162
upstart = nih_dbus_proxy_new (NULL, connection,
166
TEST_NE_P (upstart, NULL);
168
method_call = dbus_message_new_method_call (upstart->name,
170
"com.ubuntu.Upstart0_6", "Restart");
171
TEST_NE_P (method_call, NULL);
173
dbus_message_set_auto_start (method_call, upstart->auto_start);
175
dbus_message_iter_init_append (method_call, &iter);
177
/* Send the message, and wait for the reply. */
178
dbus_error_init (&error);
180
/* Don't bother checking reply - Upstart will sever the
183
(void)dbus_connection_send_with_reply_and_block (upstart->connection, method_call, -1, &error);
185
dbus_message_unref (method_call);
186
dbus_connection_unref (connection);
122
189
/* TRUE to denote that Upstart is running in user session mode
123
190
* (FALSE to denote it's using the users D-Bus session bus).
162
229
* within a reasonable period of time.
164
231
for (i = 0; i < loops; i++) {
167
234
RUN_COMMAND (NULL, cmd, &output, &lines);
172
/* Look for the specific session */
173
for (size_t line = 0; line < lines; lines++) {
175
/* No pid in output */
176
if (! isdigit(output[line][0]))
179
pid = (pid_t)atoi(output[line]);
180
nih_assert (pid > 0);
182
if (pid != session_init_pid)
185
/* look for separator between pid and value of
188
value = strstr (output[0], " ");
192
/* jump over space */
197
/* No socket address */
198
if (strstr (value, "unix:abstract") == value) {
239
/* Look for the specific session */
240
for (size_t line = 0; line < lines; lines++) {
242
/* No pid in output */
243
if (! isdigit(output[line][0]))
246
pid = (pid_t)atoi(output[line]);
247
nih_assert (pid > 0);
249
if (pid != session_init_pid)
252
/* look for separator between pid and value of
255
value = strstr (output[0], " ");
259
/* jump over space */
264
/* No socket address */
265
if (strstr (value, "unix:abstract") == value) {
764
862
return ! stat (path, &st);
868
* Perform test setup.
870
* Currently, only needed for those tests which require unique xdg
873
* If called, test must call test_common_cleanup() to cleanup.
876
test_common_setup (void)
878
char *xdg_config_home;
879
char *xdg_runtime_dir;
881
/* Take care to avoid disrupting users environment by saving and
882
* restoring these variable (assuming the tests all pass...).
885
xdg_config_home = getenv ("XDG_CONFIG_HOME");
886
if (xdg_config_home) {
887
nih_info ("Existing XDG_CONFIG_HOME found ('%s') - "
888
"saving for later restore",
891
saved_xdg_config_home = NIH_MUST (nih_strdup (NULL, xdg_config_home));
894
TEST_FILENAME (test_xdg_config_home);
895
assert0 (mkdir (test_xdg_config_home, TEST_DIR_MODE));
896
assert0 (setenv ("XDG_CONFIG_HOME", test_xdg_config_home, 1));
898
nih_info ("Using test XDG_CONFIG_HOME='%s'", test_xdg_config_home);
900
xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR");
901
if (xdg_runtime_dir) {
902
nih_info ("Existing XDG_RUNTIME_DIR found ('%s') - "
903
"saving for later restore",
906
saved_xdg_runtime_dir = NIH_MUST (nih_strdup (NULL, xdg_runtime_dir));
909
TEST_FILENAME (test_xdg_runtime_dir);
910
assert0 (mkdir (test_xdg_runtime_dir, TEST_DIR_MODE));
911
assert0 (setenv ("XDG_RUNTIME_DIR", test_xdg_runtime_dir, 1));
913
nih_info ("Using test XDG_RUNTIME_DIR='%s'", test_xdg_runtime_dir);
915
test_setup_called = TRUE;
919
* test_common_cleanup:
921
* Perform cleanup of test setup.
923
* Currently, only needed for those tests which require unique xdg
926
* If called, test must already have called test_common_setup().
929
test_common_cleanup (void)
931
nih_local char *path = NULL;
932
char *xdg_config_home;
933
char *xdg_runtime_dir;
936
if (! test_setup_called) {
937
nih_error ("BUG: Called %s without first calling %s",
938
__func__, "test_common_setup()");
942
xdg_config_home = getenv ("XDG_CONFIG_HOME");
943
xdg_runtime_dir = getenv ("XDG_RUNTIME_DIR");
945
if (saved_xdg_config_home) {
946
nih_assert (test_xdg_config_home[0]);
947
TEST_EQ_STR (test_xdg_config_home, xdg_config_home);
949
if (stat (test_xdg_config_home, &statbuf)) {
950
nih_error ("A test has removed XDG_CONFIG_HOME '%s'", test_xdg_config_home);
954
if (! S_ISDIR (statbuf.st_mode)) {
955
nih_error ("XDG_CONFIG_HOME '%s' no longer a directory", test_xdg_config_home);
959
assert0 (rmdir (test_xdg_config_home));
961
assert0 (setenv ("XDG_CONFIG_HOME", saved_xdg_config_home, 1));
962
nih_info ("Restoring XDG_RUNTIME_DIR='%s'", saved_xdg_config_home);
963
nih_free (saved_xdg_config_home);
964
saved_xdg_config_home = NULL;
967
if (saved_xdg_runtime_dir) {
968
nih_assert (test_xdg_runtime_dir[0]);
969
TEST_EQ_STR (test_xdg_runtime_dir, xdg_runtime_dir);
971
if (stat (test_xdg_runtime_dir, &statbuf)) {
972
nih_error ("A test has removed XDG_RUNTIME_DIR '%s'", test_xdg_runtime_dir);
976
if (! S_ISDIR (statbuf.st_mode)) {
977
nih_error ("XDG_RUNTIME_DIR '%s' no longer a directory", test_xdg_runtime_dir);
981
path = NIH_MUST (nih_sprintf (NULL, "%s/upstart/sessions", xdg_runtime_dir));
983
if (! stat (path, &statbuf)) {
984
nih_local char *cmd = NULL;
986
/* Clean up if tests forgot to */
987
cmd = NIH_MUST (nih_sprintf (NULL, "rm %s/*.session 2>/dev/null", path));
990
/* Remove the directory tree the first Session Init created */
991
assert0 (rmdir (path));
992
path = NIH_MUST (nih_sprintf (NULL, "%s/upstart", xdg_runtime_dir));
993
assert0 (rmdir (path));
996
assert0 (rmdir (test_xdg_runtime_dir));
998
assert0 (setenv ("XDG_RUNTIME_DIR", saved_xdg_runtime_dir, 1));
999
nih_info ("Restoring XDG_RUNTIME_DIR='%s'", saved_xdg_config_home);
1000
nih_free (saved_xdg_runtime_dir);
1001
saved_xdg_runtime_dir = NULL;