1 [PATCH] Fix adbd for non-Ubuntu systems
3 Remove glib/dbus dependencies and partially restore services.c to be
4 closer to the original source code in order to run on systems without
7 Signed-off-by: Gary Bisson <gary.bisson@boundarydevices.com>
10 core/adbd/services.c | 160 ++++-------------------------------------------
11 debian/makefiles/adbd.mk | 4 +-
12 3 files changed, 14 insertions(+), 151 deletions(-)
14 diff --git a/core/adbd/adb.c b/core/adbd/adb.c
15 index d90e6b8..7fe6445 100644
18 @@ -1165,7 +1165,6 @@ void build_local_name(char* target_str, size_t target_size, int server_port)
21 static int should_drop_privileges() {
23 #ifndef ALLOW_ADBD_ROOT
25 #else /* ALLOW_ADBD_ROOT */
26 diff --git a/core/adbd/services.c b/core/adbd/services.c
27 index 05bd0d0..5adcefe 100644
28 --- a/core/adbd/services.c
29 +++ b/core/adbd/services.c
37 -#define UNITY_SERVICE "com.canonical.UnityGreeter"
38 -#define GREETER_OBJ "/"
39 -#define GREETER_INTERFACE "com.canonical.UnityGreeter"
40 -#define PROPERTIES_INTERFACE "org.freedesktop.DBus.Properties"
41 -#define ACTIVE_PROPERTY "IsActive"
42 -#define UNLOCK_PATH "/userdata/.adb_onlock"
46 @@ -268,11 +259,11 @@ static int create_service_thread(void (*func)(int, void *), void *cookie)
50 -static int create_subprocess(const char *cmd, const char *arg0, const char *arg1, const char *arg2, const char *arg3, const char *arg4, pid_t *pid)
51 +static int create_subprocess(const char *cmd, const char *arg0, const char *arg1, pid_t *pid)
53 #ifdef HAVE_WIN32_PROC
54 - D("create_subprocess(cmd=%s, arg0=%s, arg1=%s, arg2=%s, arg3=%, arg4=%ss)\n", cmd, arg0, arg1, arg2, arg3, arg4);
55 - fprintf(stderr, "error: create_subprocess not implemented on Win32 (%s %s %s %s %s %s)\n", cmd, arg0, arg1, arg2, arg3, arg4);
56 + D("create_subprocess(cmd=%s, arg0=%s, arg1=%s)\n", cmd, arg0, arg1);
57 + fprintf(stderr, "error: create_subprocess not implemented on Win32 (%s %s %s)\n", cmd, arg0, arg1);
59 #else /* !HAVE_WIN32_PROC */
61 @@ -327,7 +318,7 @@ static int create_subprocess(const char *cmd, const char *arg0, const char *arg1
63 D("adb: unable to open %s\n", text);
65 - execl(cmd, cmd, arg0, arg1, arg2, arg3, arg4, NULL);
66 + execl(cmd, cmd, arg0, arg1, NULL);
67 fprintf(stderr, "- exec '%s' failed: %s (%d) -\n",
68 cmd, strerror(errno), errno);
70 @@ -342,7 +333,7 @@ static int create_subprocess(const char *cmd, const char *arg0, const char *arg1
72 #endif /* !ABD_HOST */
75 +#if ADB_HOST || ADBD_NON_ANDROID
76 #define SHELL_COMMAND "/bin/sh"
78 #define SHELL_COMMAND "/system/bin/sh"
79 @@ -380,139 +371,16 @@ static void subproc_waiter_service(int fd, void *cookie)
83 -int is_phone_locked() {
84 - GError *error = NULL;
85 - GVariant *variant = NULL;
86 - GDBusConnection *connection = NULL;
88 - if (g_file_test(UNLOCK_PATH, G_FILE_TEST_EXISTS)) {
89 - D("unlock path present.");
93 - // check if the environment variable is present, if not we grab it from
95 - if (g_getenv("DBUS_SESSION_BUS_ADDRESS") == NULL) {
96 - D("DBUS_SESSION_BUS_ADDRESS missing.\n");
97 - struct passwd *pw = getpwuid(AID_SHELL);
100 - gchar *contents = NULL;
101 - gchar *session_path = NULL;
103 - snprintf(user_id, sizeof user_id, "%d", pw->pw_uid);
105 - path = g_build_filename("/run", "user", user_id, "dbus-session", NULL);
107 - g_file_get_contents(path, &contents, NULL, &error);
108 - session_path = g_strstrip(g_strsplit(contents, "DBUS_SESSION_BUS_ADDRESS=", -1)[1]);
109 - D("Session bus is %s\n", session_path);
111 - // path is not longer used
114 - if (error != NULL) {
115 - g_clear_error(&error);
116 - D("Couldn't set session bus\n");
120 - g_setenv("DBUS_SESSION_BUS_ADDRESS", session_path, TRUE);
124 - // set the uid to be able to connect to the phablet user session bus
126 - connection = g_dbus_connection_new_for_address_sync(g_getenv("DBUS_SESSION_BUS_ADDRESS"),
127 - G_DBUS_CONNECTION_FLAGS_AUTHENTICATION_CLIENT | G_DBUS_CONNECTION_FLAGS_MESSAGE_BUS_CONNECTION,
131 - if (connection == NULL) {
132 - D("session bus not available: %s", error->message);
133 - g_error_free (error);
137 - variant = g_dbus_connection_call_sync(connection,
140 - PROPERTIES_INTERFACE,
142 - g_variant_new("(ss)", GREETER_INTERFACE, ACTIVE_PROPERTY),
143 - g_variant_type_new("(v)"),
144 - G_DBUS_CALL_FLAGS_NONE,
149 - if (error != NULL) {
150 - D("Could not get property: %s", error->message);
151 - g_object_unref(connection);
152 - g_error_free(error);
156 - if (variant == NULL) {
157 - D("Failed to get property '%s': %s", "IsActive", error->message);
158 - g_object_unref(connection);
159 - g_error_free(error);
163 - variant = g_variant_get_variant(g_variant_get_child_value(variant, 0));
166 - if (!g_variant_get_boolean(variant)) {
170 - // get back to be root and return the value
171 - g_object_unref(connection);
172 - g_variant_unref(variant);
177 static int create_subproc_thread(const char *name)
179 - if (is_phone_locked() ) {
180 - fprintf(stderr, "device is locked\n");
189 - struct passwd *user = getpwuid(getuid());
191 - char *shellopts = "-c";
193 - char *sudo = "/usr/bin/sudo";
194 - char useropt[256] = "-u";
197 - strcat(useropt, user->pw_name);
199 - if (user && user->pw_shell) {
200 - shell = user->pw_shell;
203 - shell = SHELL_COMMAND;
207 - home = user->pw_dir;
208 - if(chdir(home) < 0 )
212 - ret_fd = create_subprocess(sudo, useropt, "-i", shell, shellopts, name, &pid);
213 + ret_fd = create_subprocess(SHELL_COMMAND, "-c", name, &pid);
216 - ret_fd = create_subprocess(sudo, useropt, "-i", shell, shellopts, 0, &pid);
217 + ret_fd = create_subprocess(SHELL_COMMAND, "-", 0, &pid);
219 D("create_subprocess() ret_fd=%d pid=%d\n", ret_fd, pid);
221 @@ -585,17 +453,13 @@ int service_to_fd(const char *name)
222 } else if (!strncmp(name, "log:", 4)) {
223 ret = create_service_thread(log_service, get_log_file_path(name + 4));
224 } else if(!HOST && !strncmp(name, "shell:", 6)) {
225 - if (!is_phone_locked() ) {
227 - ret = create_subproc_thread(name + 6);
229 - ret = create_subproc_thread(0);
232 + ret = create_subproc_thread(name + 6);
234 + ret = create_subproc_thread(0);
236 } else if(!strncmp(name, "sync:", 5)) {
237 - if (!is_phone_locked() ) {
238 - ret = create_service_thread(file_sync_service, NULL);
240 + ret = create_service_thread(file_sync_service, NULL);
241 } else if(!strncmp(name, "remount:", 8)) {
242 ret = create_service_thread(remount_service, NULL);
243 } else if(!strncmp(name, "reboot:", 7)) {
244 diff --git a/debian/makefiles/adbd.mk b/debian/makefiles/adbd.mk
245 index 49dab8c..22c1816 100644
246 --- a/debian/makefiles/adbd.mk
247 +++ b/debian/makefiles/adbd.mk
248 @@ -40,11 +40,11 @@ CPPFLAGS+= -O2 -g -Wall -Wno-unused-parameter
249 CPPFLAGS+= -DADB_HOST=0 -DHAVE_FORKEXEC=1 -D_XOPEN_SOURCE -D_GNU_SOURCE -DALLOW_ADBD_ROOT=1
250 CPPFLAGS+= -DHAVE_SYMLINKS -DBOARD_ALWAYS_INSECURE
251 CPPFLAGS+= -DHAVE_TERMIO_H
252 -CPPFLAGS+= `pkg-config --cflags glib-2.0 gio-2.0`
253 +CPPFLAGS+= -DADBD_NON_ANDROID
254 CPPFLAGS+= -I$(SRCDIR)/core/adbd
255 CPPFLAGS+= -I$(SRCDIR)/core/include
257 -LIBS+= -lc -lpthread -lz -lcrypto -lcrypt `pkg-config --libs glib-2.0 gio-2.0`
258 +LIBS+= -lc -lpthread -lz -lcrypto -lcrypt
260 OBJS= $(patsubst %, %.o, $(basename $(SRCS)))